2020-06-14 10:33:43 +00:00
|
|
|
using Elsa.Activities.Console;
|
|
|
|
|
using Elsa.Models;
|
|
|
|
|
using Elsa.Services;
|
|
|
|
|
using Elsa.Builders;
|
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Samples.WorkflowDefinition
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
private static async Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
var services = new ServiceCollection()
|
|
|
|
|
.AddElsa()
|
|
|
|
|
.AddLogging(log => log.AddConsole())
|
|
|
|
|
.AddConsoleActivities()
|
|
|
|
|
.AddSingleton(Console.In)
|
|
|
|
|
.BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
var activityResolver = services.GetRequiredService<IActivityResolver>();
|
|
|
|
|
var activity1 = activityResolver.ResolveActivity<WriteLine>()
|
|
|
|
|
.WithId("activity-1")
|
2020-10-03 10:48:25 +00:00
|
|
|
.WithText("Hello world!");
|
2020-06-14 10:33:43 +00:00
|
|
|
|
|
|
|
|
var activity2 = activityResolver.ResolveActivity<WriteLine>()
|
|
|
|
|
.WithId("activity-2")
|
2020-10-03 10:48:25 +00:00
|
|
|
.WithText("Goodbye cruel world...!");
|
2020-06-14 10:33:43 +00:00
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
// Create Workflow Definition.
|
2020-10-09 20:26:19 +00:00
|
|
|
var workflowDefinition = new Models.WorkflowDefinition
|
2020-06-14 10:33:43 +00:00
|
|
|
{
|
2020-10-09 20:26:19 +00:00
|
|
|
WorkflowDefinitionVersionId = "definition-001",
|
2020-06-14 10:33:43 +00:00
|
|
|
IsPublished = true,
|
2020-10-09 20:26:19 +00:00
|
|
|
Activities = new List<ActivityDefinition>
|
2020-06-14 10:33:43 +00:00
|
|
|
{
|
2020-10-09 20:26:19 +00:00
|
|
|
ActivityDefinition.FromActivity(activity1),
|
|
|
|
|
ActivityDefinition.FromActivity(activity2)
|
2020-06-14 10:33:43 +00:00
|
|
|
},
|
|
|
|
|
Connections = new[]
|
|
|
|
|
{
|
|
|
|
|
new ConnectionDefinition("activity-1", "activity-2", OutcomeNames.Done),
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
// Register it.
|
2020-10-09 20:26:19 +00:00
|
|
|
//var workflowDefinitionStore = services.GetService<IWorkflowDefinitionStore>();
|
|
|
|
|
//await workflowDefinitionStore.AddAsync(workflowDefinition);
|
2020-06-14 10:33:43 +00:00
|
|
|
|
2020-10-03 10:48:25 +00:00
|
|
|
// Run it.
|
2020-06-14 10:33:43 +00:00
|
|
|
var invoker = services.GetService<IWorkflowHost>();
|
|
|
|
|
await invoker.RunWorkflowDefinitionAsync("definition-001");
|
|
|
|
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|