elsa-core/samples/Sample03/Program.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2019-07-22 16:55:02 +00:00
using System;
using System.Threading.Tasks;
using Elsa;
using Elsa.Activities.Console.Activities;
using Elsa.Activities.Console.Extensions;
using Elsa.Expressions;
using Elsa.Extensions;
using Elsa.Models;
using Elsa.Persistence.Memory;
2019-07-22 16:55:02 +00:00
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Sample03
{
/// <summary>
/// A minimal workflows program defined as data (workflow definition) and Console activities.
/// </summary>
class Program
{
static async Task Main(string[] args)
{
// Setup a service collection.
var services = new ServiceCollection()
.AddWorkflows()
.AddMemoryWorkflowInstanceStore()
.AddConsoleActivities()
.BuildServiceProvider();
// Define a workflow as data so we can store it somewhere (file, database, etc.).
var workflowDefinition = new WorkflowDefinitionVersion
2019-07-22 16:55:02 +00:00
{
Activities = new[]
{
2019-09-17 14:32:09 +00:00
new ActivityDefinition<WriteLine>("activity-1", new { TextExpression = new LiteralExpression("Hello world!")}),
new ActivityDefinition<WriteLine>("activity-2", new { TextExpression = new LiteralExpression("Goodbye cruel world...")})
2019-07-22 16:55:02 +00:00
},
Connections = new []
{
new ConnectionDefinition("activity-1", "activity-2", OutcomeNames.Done),
}
};
// Run the workflow.
2019-07-22 16:55:02 +00:00
var invoker = services.GetService<IWorkflowInvoker>();
await invoker.StartAsync(workflowDefinition);
2019-07-22 16:55:02 +00:00
Console.ReadLine();
}
}
}