| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Elsa.Workflows.Activities; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Testing.Shared.Activities; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Concrete implementation of Container for testing that schedules children sequentially. |
| | | 8 | | /// </summary> |
| | | 9 | | public class TestContainer : Container |
| | | 10 | | { |
| | | 11 | | private const string CurrentIndexProperty = "CurrentIndex"; |
| | | 12 | | |
| | | 13 | | protected override async ValueTask ScheduleChildrenAsync(ActivityExecutionContext context) |
| | | 14 | | { |
| | 0 | 15 | | await HandleItemAsync(context); |
| | 0 | 16 | | } |
| | | 17 | | |
| | | 18 | | private async ValueTask HandleItemAsync(ActivityExecutionContext context) |
| | | 19 | | { |
| | 0 | 20 | | var currentIndex = context.GetProperty<int>(CurrentIndexProperty); |
| | 0 | 21 | | var childActivities = Activities.ToList(); |
| | | 22 | | |
| | 0 | 23 | | if (currentIndex >= childActivities.Count) |
| | | 24 | | { |
| | 0 | 25 | | await context.CompleteActivityAsync(); |
| | 0 | 26 | | return; |
| | | 27 | | } |
| | | 28 | | |
| | 0 | 29 | | var nextActivity = childActivities.ElementAt(currentIndex); |
| | 0 | 30 | | await context.ScheduleActivityAsync(nextActivity, OnChildCompleted); |
| | 0 | 31 | | context.UpdateProperty<int>(CurrentIndexProperty, x => x + 1); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | private async ValueTask OnChildCompleted(ActivityCompletedContext context) |
| | | 35 | | { |
| | 0 | 36 | | await HandleItemAsync(context.TargetContext); |
| | 0 | 37 | | } |
| | | 38 | | } |