| | | 1 | | using Elsa.Alterations.Activities; |
| | | 2 | | using Elsa.Alterations.Core.Models; |
| | | 3 | | using Elsa.Extensions; |
| | | 4 | | using Elsa.Workflows; |
| | | 5 | | using Elsa.Workflows.Activities; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Alterations.Workflows; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Executes an alteration plan. |
| | | 11 | | /// </summary> |
| | | 12 | | public class ExecuteAlterationPlanWorkflow : WorkflowBase |
| | | 13 | | { |
| | | 14 | | internal const string WorkflowDefinitionId = "Elsa.Alterations.ExecuteAlterationPlan"; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | protected override void Build(IWorkflowBuilder builder) |
| | | 18 | | { |
| | 19 | 19 | | builder.WithDefinitionId(WorkflowDefinitionId); |
| | 19 | 20 | | builder.AsSystemWorkflow(); |
| | 19 | 21 | | var plan = builder.WithInput<AlterationPlanParams>("Plan", "The parameters for the new plan"); |
| | 19 | 22 | | var planId = builder.WithVariable<string>(); |
| | 19 | 23 | | var jobCount = builder.WithVariable<int>(); |
| | | 24 | | |
| | 19 | 25 | | builder.Root = new Sequence |
| | 19 | 26 | | { |
| | 19 | 27 | | Activities = |
| | 19 | 28 | | { |
| | 19 | 29 | | new SubmitAlterationPlan |
| | 19 | 30 | | { |
| | 0 | 31 | | Params = new(context => context.GetInput<AlterationPlanParams>(plan)!), |
| | 19 | 32 | | Result = new(planId) |
| | 19 | 33 | | }, |
| | 19 | 34 | | new Correlate(planId), |
| | 19 | 35 | | new GenerateAlterationJobs(planId) |
| | 19 | 36 | | { |
| | 19 | 37 | | Result = new(jobCount) |
| | 19 | 38 | | }, |
| | 0 | 39 | | new If(context => jobCount.Get(context) > 0) |
| | 19 | 40 | | { |
| | 19 | 41 | | Then = new DispatchAlterationJobs(planId), |
| | 19 | 42 | | Else = new CompleteAlterationPlan(planId) |
| | 19 | 43 | | }, |
| | 19 | 44 | | new AlterationPlanCompleted(planId), |
| | 19 | 45 | | } |
| | 19 | 46 | | }; |
| | 19 | 47 | | } |
| | | 48 | | } |