2019-07-22 16:55:02 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Elsa.Activities.Console.Activities;
|
|
|
|
|
|
using Elsa.Activities.Console.Extensions;
|
|
|
|
|
|
using Elsa.Expressions;
|
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
|
using Elsa.Services;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Sample02
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A minimal workflows program defined in code using fluent workflow builder and Console activities.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
static async Task Main(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Setup a service collection.
|
|
|
|
|
|
var services = new ServiceCollection()
|
|
|
|
|
|
.AddWorkflows()
|
|
|
|
|
|
.AddConsoleActivities()
|
|
|
|
|
|
.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
|
|
// Define a workflow.
|
|
|
|
|
|
var workflowBuilder = services.GetRequiredService<IWorkflowBuilder>();
|
|
|
|
|
|
var workflowDefinition = workflowBuilder
|
2019-09-17 14:32:09 +00:00
|
|
|
|
.StartWith<WriteLine>(x => x.TextExpression = new LiteralExpression("Hello world!"))
|
|
|
|
|
|
.Then<WriteLine>(x => x.TextExpression = new LiteralExpression("Goodbye cruel world..."))
|
2019-07-22 16:55:02 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
2019-09-16 13:23:16 +00:00
|
|
|
|
// Start the workflow.
|
2019-07-22 16:55:02 +00:00
|
|
|
|
var invoker = services.GetService<IWorkflowInvoker>();
|
2019-09-15 10:16:24 +00:00
|
|
|
|
await invoker.StartAsync(workflowDefinition);
|
2019-07-22 16:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-06-27 20:55:55 +00:00
|
|
|
|
}
|