2021-01-07 12:01:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Elsa.Persistence;
|
|
|
|
|
|
using Elsa.Persistence.EntityFramework.Core.Extensions;
|
|
|
|
|
|
using Elsa.Persistence.EntityFramework.Sqlite;
|
2021-01-29 15:16:45 +00:00
|
|
|
|
using Elsa.Persistence.Specifications.WorkflowInstances;
|
2021-01-07 12:01:19 +00:00
|
|
|
|
using Elsa.Services;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Samples.Persistence.EntityFramework
|
|
|
|
|
|
{
|
|
|
|
|
|
class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
private static async Task Main()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create a service container with Elsa services.
|
|
|
|
|
|
var services = new ServiceCollection()
|
|
|
|
|
|
.AddElsa(options => options
|
|
|
|
|
|
// Configure Elsa to use the Entity Framework Core persistence provider using Sqlite.
|
2021-02-11 09:23:00 +00:00
|
|
|
|
.UseEntityFrameworkPersistence(ef => ef.UseSqlite())
|
2021-01-07 12:01:19 +00:00
|
|
|
|
.AddConsoleActivities()
|
|
|
|
|
|
.AddWorkflow<HelloWorld>())
|
|
|
|
|
|
.AddAutoMapperProfiles<Program>()
|
|
|
|
|
|
.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
|
|
// Run startup actions (not needed when registering Elsa with a Host).
|
|
|
|
|
|
var startupRunner = services.GetRequiredService<IStartupRunner>();
|
|
|
|
|
|
await startupRunner.StartupAsync();
|
|
|
|
|
|
|
|
|
|
|
|
// Get a workflow runner.
|
|
|
|
|
|
var workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
|
|
|
|
|
|
|
|
|
|
|
// Run the workflow.
|
|
|
|
|
|
var workflowInstance = await workflowRunner.RunWorkflowAsync<HelloWorld>();
|
|
|
|
|
|
|
|
|
|
|
|
// Get a reference to the workflow instance store.
|
|
|
|
|
|
var store = services.GetRequiredService<IWorkflowInstanceStore>();
|
|
|
|
|
|
|
|
|
|
|
|
// Count the number of workflow instances of HelloWorld.
|
2021-01-29 15:16:45 +00:00
|
|
|
|
var count = await store.CountAsync(new WorkflowDefinitionIdSpecification(nameof(HelloWorld)));
|
2021-01-07 12:01:19 +00:00
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(count);
|
|
|
|
|
|
|
|
|
|
|
|
var loadedWorkflowInstance = await store.FindByIdAsync(workflowInstance.Id);
|
|
|
|
|
|
Console.WriteLine(loadedWorkflowInstance);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|