From 07f71a2befd660a181f4ed0b5c18ef3321c7ddd8 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 28 Oct 2020 13:39:07 +0100 Subject: [PATCH] Update UserTask sample retrieving available actions --- src/samples/Sample12/Program.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/samples/Sample12/Program.cs b/src/samples/Sample12/Program.cs index 9c2eb906b..6ef4b55d3 100644 --- a/src/samples/Sample12/Program.cs +++ b/src/samples/Sample12/Program.cs @@ -9,6 +9,7 @@ using Elsa.Services; using Elsa.Services.Extensions; using Elsa.Services.Models; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json.Linq; namespace Sample12 { @@ -29,11 +30,14 @@ namespace Sample12 await invoker.StartAsync(workflowDefinition, correlationId: correlationId); WorkflowExecutionContext executionContext; + // Sample code showing how to get a list of available actions from the workflow definition: + var availableActions = workflowDefinition.Activities.Single(x => x.Name == "WaitUser").State["Actions"].ToObject(); + 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(); + Console.WriteLine($"What action will you take? Choose one of: {string.Join(", ", availableActions)}"); + var userAction = Console.ReadLine(); // Resume the workflow with the received stimulus. var triggeredExecutionContexts = await invoker.TriggerAsync(nameof(UserTask), new Variables { ["UserAction"] = new Variable(userAction)}, correlationId);