| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Workflows.Activities.Flowchart.Activities; |
| | | 3 | | using Elsa.Workflows.Activities.Flowchart.Models; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Activities.Flowchart.Extensions; |
| | | 6 | | |
| | | 7 | | public static class ActivityExtensions |
| | | 8 | | { |
| | | 9 | | extension(IActivity activity) |
| | | 10 | | { |
| | | 11 | | public MergeMode? GetMergeMode() |
| | | 12 | | { |
| | 329 | 13 | | if (!activity.CustomProperties.TryGetValue("mergeMode", out var value)) |
| | 310 | 14 | | return null; |
| | | 15 | | |
| | | 16 | | // Handle both string and enum values for backwards compatibility |
| | 19 | 17 | | var result = value switch |
| | 19 | 18 | | { |
| | 0 | 19 | | MergeMode mode => mode, |
| | 38 | 20 | | string str when Enum.TryParse<MergeMode>(str, true, out var mode) => mode, |
| | 0 | 21 | | _ => (MergeMode?)null |
| | 19 | 22 | | }; |
| | | 23 | | |
| | | 24 | | // Treat MergeMode.None as equivalent to null (no merge mode set) |
| | 19 | 25 | | return result == MergeMode.None ? null : result; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public void SetMergeMode(MergeMode? value) |
| | | 29 | | { |
| | | 30 | | // Treat MergeMode.None as equivalent to null (no merge mode set) |
| | 11 | 31 | | if (value == null || value == MergeMode.None) |
| | 1 | 32 | | activity.CustomProperties.Remove("mergeMode"); |
| | | 33 | | else |
| | 10 | 34 | | activity.CustomProperties["mergeMode"] = value.ToString()!; |
| | 10 | 35 | | } |
| | | 36 | | |
| | | 37 | | public async Task<MergeMode?> GetMergeModeAsync(ActivityExecutionContext context) |
| | | 38 | | { |
| | 343 | 39 | | if (activity.Type != "Elsa.FlowJoin") |
| | | 40 | | { |
| | 329 | 41 | | return activity.GetMergeMode(); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | // Handle deprecated FlowJoin activity by evaluating its JoinMode property and mapping it to the appropriate |
| | 14 | 45 | | var joinActivityExecutionContext = await context.WorkflowExecutionContext.CreateActivityExecutionContextAsyn |
| | 14 | 46 | | var joinMode = await joinActivityExecutionContext.EvaluateInputPropertyAsync<FlowJoin, FlowJoinMode>(x => x. |
| | | 47 | | |
| | 14 | 48 | | return joinMode switch |
| | 14 | 49 | | { |
| | 7 | 50 | | FlowJoinMode.WaitAny => MergeMode.Race, |
| | 7 | 51 | | _ => MergeMode.Merge // WaitAll maps to Merge (wait for all activated branches) |
| | 14 | 52 | | }; |
| | 343 | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |