2020-12-14 16:15:39 +00:00
|
|
|
using System;
|
2020-12-11 20:03:49 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-12-14 16:15:39 +00:00
|
|
|
using Elsa.Models;
|
|
|
|
|
using Elsa.Persistence;
|
|
|
|
|
using Elsa.Persistence.Specifications;
|
|
|
|
|
using Elsa.Persistence.YesSql.Extensions;
|
2020-02-18 21:29:44 +00:00
|
|
|
using Elsa.Services;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Samples.HelloWorldConsole
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2020-11-30 14:21:36 +00:00
|
|
|
private static async Task Main()
|
2020-02-18 21:29:44 +00:00
|
|
|
{
|
|
|
|
|
// Create a service container with Elsa services.
|
2020-10-10 20:14:10 +00:00
|
|
|
var services = new ServiceCollection()
|
2020-12-14 16:15:39 +00:00
|
|
|
.AddElsa(options => options.UseYesSqlPersistence())
|
2020-02-18 21:29:44 +00:00
|
|
|
.AddConsoleActivities()
|
2020-10-18 15:05:48 +00:00
|
|
|
.AddWorkflow<HelloWorld>()
|
2020-11-17 19:12:18 +00:00
|
|
|
.AddAutoMapperProfiles<Program>()
|
2020-02-18 21:29:44 +00:00
|
|
|
.BuildServiceProvider();
|
2020-11-17 19:12:18 +00:00
|
|
|
|
2020-10-10 19:10:09 +00:00
|
|
|
// Run startup actions (not needed when registering Elsa with a Host).
|
|
|
|
|
var startupRunner = services.GetRequiredService<IStartupRunner>();
|
|
|
|
|
await startupRunner.StartupAsync();
|
|
|
|
|
|
2020-11-03 08:46:38 +00:00
|
|
|
// Get a workflow runner.
|
2020-11-30 14:21:36 +00:00
|
|
|
var workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
2020-02-18 21:29:44 +00:00
|
|
|
|
2020-11-03 08:46:38 +00:00
|
|
|
// Run the workflow.
|
2020-10-23 12:22:24 +00:00
|
|
|
await workflowRunner.RunWorkflowAsync<HelloWorld>();
|
2020-12-14 16:15:39 +00:00
|
|
|
|
|
|
|
|
var store = services.GetRequiredService<IWorkflowInstanceStore>();
|
|
|
|
|
|
|
|
|
|
var results = await store.FindManyAsync(
|
2020-12-20 11:12:32 +00:00
|
|
|
new WorkflowInstanceDefinitionIdSpecification(nameof(HelloWorld)),
|
2020-12-17 14:47:21 +00:00
|
|
|
OrderBySpecification.OrderByDescending<WorkflowInstance>(x => x.CreatedAt),
|
2020-12-14 16:15:39 +00:00
|
|
|
Paging.Page(1, 2));
|
|
|
|
|
|
|
|
|
|
var count = await store.CountAsync(
|
2020-12-20 11:12:32 +00:00
|
|
|
new WorkflowInstanceDefinitionIdSpecification(nameof(HelloWorld)),
|
2020-12-17 14:47:21 +00:00
|
|
|
OrderBySpecification.OrderByDescending<WorkflowInstance>(x => x.CreatedAt));
|
2020-12-14 16:15:39 +00:00
|
|
|
|
|
|
|
|
Console.WriteLine(count);
|
|
|
|
|
|
|
|
|
|
foreach (var result in results)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(result.CreatedAt);
|
|
|
|
|
}
|
2020-02-18 21:29:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|