elsa-core/src/samples/Sample11/Program.cs
Sipke Schoorstra c7c41d10a5
Workflow Registry refresh upon workflow definition updates (#101)
* Fix many things. Few more samples left to fix

* Fix all the samples

* Introduce service configurator

* Implement cache signaling and refreshing workflow registry

* Add Sample16 demonstrating dashboard + workflow host combined

* Bugfix where non-published versions of worklows are triggered
2019-10-23 21:23:25 +02:00

59 lines
2.1 KiB
C#

using System;
using System.Linq;
using System.Threading.Tasks;
using Elsa.Activities.Console.Extensions;
using Elsa.Activities.Workflows;
using Elsa.Extensions;
using Elsa.Models;
using Elsa.Persistence.Memory;
using Elsa.Services;
using Microsoft.Extensions.DependencyInjection;
namespace Sample11
{
/// <summary>
/// Demonstrates workflow correlation.
/// </summary>
public static class Program
{
public static async Task Main(string[] args)
{
var services = BuildServices();
var registry = services.GetService<IWorkflowRegistry>();
var workflowDefinition = await registry.GetWorkflowDefinitionAsync<CorrelationWorkflow>();
var invoker = services.GetRequiredService<IWorkflowInvoker>();
Console.WriteLine("How many workflow instances should be started? Enter a number:");
var instanceCount = int.Parse(Console.ReadLine());
for (var i = 0; i < instanceCount; i++)
await invoker.StartAsync(workflowDefinition, correlationId: $"document {i + 1}");
var retry = true;
while (retry)
{
Console.WriteLine();
Console.WriteLine("Now, enter the correlation ID of the workflow to resume:");
var correlationId = Console.ReadLine();
// Resume one workflow using the specified correlation ID.
var triggeredExecutionContexts = (await invoker.TriggerAsync(nameof(Signaled), new Variables { ["Signal"] = "Proceed" }, correlationId)).ToList();
Console.WriteLine("{0} workflow was resumed. Would you like to trigger another?", triggeredExecutionContexts.Count);
retry = string.Equals("y", Console.ReadLine(), StringComparison.OrdinalIgnoreCase);
}
Console.WriteLine("Bye!");
}
private static IServiceProvider BuildServices()
{
return new ServiceCollection()
.AddWorkflows()
.AddConsoleActivities()
.AddWorkflow<CorrelationWorkflow>()
.BuildServiceProvider();
}
}
}