| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | using Elsa.Workflows.Activities.Flowchart.Contracts; |
| | | 3 | | using Elsa.Workflows.Activities.Flowchart.Extensions; |
| | | 4 | | using Elsa.Workflows.Activities.Flowchart.Models; |
| | | 5 | | using Elsa.Workflows.Attributes; |
| | | 6 | | using Elsa.Workflows.Models; |
| | | 7 | | using Elsa.Workflows.UIHints; |
| | | 8 | | using JetBrains.Annotations; |
| | | 9 | | |
| | | 10 | | namespace Elsa.Workflows.Activities.Flowchart.Activities; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Merge multiple branches into a single branch of execution. |
| | | 14 | | /// Note that this activity is no longer necessary for either AND or OR merges, because all activities inherit the Join |
| | | 15 | | /// Use this activity if an explicit join step is desired. |
| | | 16 | | /// </summary> |
| | | 17 | | [Activity("Elsa", "Branching", "Explicitly merge multiple branches into a single branch of execution.", DisplayName = "J |
| | | 18 | | [UsedImplicitly] |
| | | 19 | | public class FlowJoin : Activity, IJoinNode |
| | | 20 | | { |
| | | 21 | | /// <inheritdoc /> |
| | 48 | 22 | | public FlowJoin([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line) |
| | | 23 | | { |
| | 48 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// The join mode determines whether this activity should continue as soon as one inbound path comes in (Wait Any), |
| | | 28 | | /// </summary> |
| | | 29 | | [Input( |
| | | 30 | | Description = "The join mode determines whether this activity should continue as soon as one inbound path comes |
| | | 31 | | DefaultValue = FlowJoinMode.WaitAny, |
| | | 32 | | UIHint = InputUIHints.DropDown |
| | | 33 | | )] |
| | 203 | 34 | | public Input<FlowJoinMode> Mode { get; set; } = new(FlowJoinMode.WaitAny); |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | | 37 | | protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) |
| | | 38 | | { |
| | 28 | 39 | | if(!Flowchart.UseTokenFlow) |
| | 16 | 40 | | if (context.ParentActivityExecutionContext != null) |
| | 13 | 41 | | await context.ParentActivityExecutionContext.CancelInboundAncestorsAsync(this); |
| | | 42 | | |
| | 28 | 43 | | await context.CompleteActivityAsync(); |
| | 28 | 44 | | } |
| | | 45 | | |
| | | 46 | | protected override bool CanExecute(ActivityExecutionContext context) |
| | | 47 | | { |
| | 22 | 48 | | if(Flowchart.UseTokenFlow) |
| | 9 | 49 | | return true; |
| | | 50 | | |
| | 13 | 51 | | return context.Get(Mode) switch |
| | 13 | 52 | | { |
| | 5 | 53 | | FlowJoinMode.WaitAny => true, |
| | 8 | 54 | | FlowJoinMode.WaitAll => Flowchart.CanWaitAllProceed(context), |
| | 0 | 55 | | _ => true |
| | 13 | 56 | | }; |
| | | 57 | | } |
| | | 58 | | } |