diff --git a/src/modules/Elsa.Workflows.Core/Activities/ForEachT.cs b/src/modules/Elsa.Workflows.Core/Activities/ForEachT.cs index 1ef5e49ea..c954f50b7 100644 --- a/src/modules/Elsa.Workflows.Core/Activities/ForEachT.cs +++ b/src/modules/Elsa.Workflows.Core/Activities/ForEachT.cs @@ -47,13 +47,7 @@ public class ForEach : Activity /// The set of values to iterate. /// [Input(Description = "The set of values to iterate.")] - public Input>? Items { get; set; } - - /// - /// The source of values to iterate. - /// - [Input(Description = "The set of values to iterate.")] - public Input>? ItemSource { get; set; } + public Input> Items { get; set; } = new(Array.Empty()); /// /// The activity to execute for each iteration. @@ -85,16 +79,15 @@ public class ForEach : Activity } var currentIndex = context.GetProperty(CurrentIndexProperty); - var currentValueTuple = await GetCurrentValueAsync(context, currentIndex); + var items = context.Get(Items)!.ToList(); - if (!currentValueTuple.Exists) + if (currentIndex >= items.Count) { await context.CompleteActivityAsync(); return; } - - var currentValue = currentValueTuple.Value; - + + var currentValue = items[currentIndex]; context.Set(CurrentValue, currentValue); if (Body != null) @@ -113,36 +106,6 @@ public class ForEach : Activity context.UpdateProperty(CurrentIndexProperty, x => x + 1); } - private async Task<(T Value, bool Exists)> GetCurrentValueAsync(ActivityExecutionContext context, int currentIndex) - { - var items = context.Get(Items)?.ToList(); - - if (items != null) - { - return (currentIndex >= items.Count ? (default, false) : (items[currentIndex], true))!; - } - - var itemSource = context.Get(ItemSource); - - if(itemSource != null) - { - await using var enumerator = itemSource.GetAsyncEnumerator(); - - // Move the cursor to the current index. - for (var i = 0; i < currentIndex; i++) - await enumerator.MoveNextAsync(); - - var hasNext = await enumerator.MoveNextAsync(); - - if(!hasNext) - return (default, false)!; - - return (enumerator.Current, true); - } - - return (default, false)!; - } - private async ValueTask OnChildCompleted(ActivityCompletedContext context) { await HandleIteration(context.TargetContext);