2019-07-25 16:10:17 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Elsa.Activities.Console.Extensions;
|
|
|
|
|
|
using Elsa.Activities.Primitives;
|
2019-07-25 19:06:46 +00:00
|
|
|
|
using Elsa.Activities.UserTask.Activities;
|
2019-07-25 16:10:17 +00:00
|
|
|
|
using Elsa.Activities.UserTask.Extensions;
|
|
|
|
|
|
using Elsa.Extensions;
|
|
|
|
|
|
using Elsa.Models;
|
|
|
|
|
|
using Elsa.Persistence.Memory;
|
|
|
|
|
|
using Elsa.Runtime;
|
|
|
|
|
|
using Elsa.Services;
|
|
|
|
|
|
using Elsa.Services.Extensions;
|
2019-07-25 19:06:46 +00:00
|
|
|
|
using Elsa.Services.Models;
|
2019-07-25 16:10:17 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Sample12
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2019-08-07 19:12:47 +00:00
|
|
|
|
/// Demonstrates workflow correlation & user tasks.
|
2019-07-25 16:10:17 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
public static async Task Main(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
var services = BuildServices();
|
|
|
|
|
|
var registry = services.GetService<IWorkflowRegistry>();
|
|
|
|
|
|
var workflowDefinition = registry.RegisterWorkflow<UserTaskWorkflow>();
|
|
|
|
|
|
var invoker = services.GetRequiredService<IWorkflowInvoker>();
|
|
|
|
|
|
|
2019-09-15 10:16:24 +00:00
|
|
|
|
// Start the workflow.
|
2019-07-25 19:06:46 +00:00
|
|
|
|
var correlationId = Guid.NewGuid().ToString("N");
|
2019-09-15 10:16:24 +00:00
|
|
|
|
await invoker.StartAsync(workflowDefinition, correlationId: correlationId);
|
2019-07-25 19:06:46 +00:00
|
|
|
|
WorkflowExecutionContext executionContext;
|
|
|
|
|
|
|
2019-07-25 16:10:17 +00:00
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
// Workflow is now halted on the user task activity. Ask user for input:
|
|
|
|
|
|
Console.WriteLine("What action will you take? Choose one of: Accept, Reject, Needs Work");
|
|
|
|
|
|
var userAction = Console.ReadLine();
|
|
|
|
|
|
|
|
|
|
|
|
// Resume the workflow with the received stimulus.
|
2019-07-25 19:06:46 +00:00
|
|
|
|
var triggeredExecutionContexts = await invoker.TriggerAsync(nameof(UserTask), new Variables { ["UserAction"] = userAction}, correlationId);
|
|
|
|
|
|
executionContext = triggeredExecutionContexts.First();
|
|
|
|
|
|
|
2019-09-15 10:16:24 +00:00
|
|
|
|
} while (executionContext.Workflow.IsExecuting());
|
2019-07-25 16:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static IServiceProvider BuildServices()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ServiceCollection()
|
|
|
|
|
|
.AddWorkflows()
|
|
|
|
|
|
.AddConsoleActivities()
|
|
|
|
|
|
.AddUserTaskActivities()
|
|
|
|
|
|
.AddMemoryWorkflowDefinitionStore()
|
|
|
|
|
|
.AddMemoryWorkflowInstanceStore()
|
|
|
|
|
|
.BuildServiceProvider();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|