| | | 1 | | using Elsa.Workflows.Activities; |
| | | 2 | | using Elsa.Workflows.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows.PortResolvers; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Returns a list of outbound activities for a given <see cref="Switch"/> activity's branches. |
| | | 8 | | /// </summary> |
| | | 9 | | public class SwitchActivityResolver : IActivityResolver |
| | | 10 | | { |
| | | 11 | | /// <inheritdoc /> |
| | 851 | 12 | | public int Priority => 0; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | 17443 | 15 | | public bool GetSupportsActivity(IActivity activity) => activity is Switch; |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public ValueTask<IEnumerable<ActivityPort>> GetActivityPortsAsync(IActivity activity, CancellationToken cancellation |
| | | 19 | | { |
| | 13 | 20 | | var ports = GetPortsInternal(activity).ToList(); |
| | 13 | 21 | | return new(ports); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | private static IEnumerable<ActivityPort> GetPortsInternal(IActivity activity) |
| | | 25 | | { |
| | 13 | 26 | | var @switch = (Switch)activity; |
| | 27 | 27 | | var cases = @switch.Cases.Where(x => x.Activity != null); |
| | | 28 | | |
| | 54 | 29 | | foreach (var @case in cases) |
| | 14 | 30 | | yield return ActivityPort.FromActivity(@case.Activity!, @case.Label); |
| | | 31 | | |
| | 13 | 32 | | if (@switch.Default != null) |
| | 6 | 33 | | yield return ActivityPort.FromActivity(@switch.Default, nameof(Switch.Default)); |
| | 13 | 34 | | } |
| | | 35 | | } |