< Summary

Information
Class: Elsa.Workflows.Activities.Sequence
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Sequence.cs
Line coverage
92%
Covered lines: 23
Uncovered lines: 2
Coverable lines: 25
Total lines: 69
Line coverage: 92%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ScheduleChildrenAsync()100%11100%
HandleItemAsync()100%22100%
OnChildCompleted()100%44100%
OnBreakSignalReceived(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Sequence.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.Runtime.CompilerServices;
 3using Elsa.Workflows.Attributes;
 4using Elsa.Workflows.Signals;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Activities;
 8
 9/// <summary>
 10/// Execute a set of activities in sequence.
 11/// </summary>
 12[Category("Workflows")]
 13[Activity("Elsa", "Workflows", "Execute a set of activities in sequence.")]
 14[PublicAPI]
 15[Browsable(false)]
 16public class Sequence : Container
 17{
 18    private const string CurrentIndexProperty = "CurrentIndex";
 19
 20    /// <inheritdoc />
 706321    public Sequence([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 22    {
 706323        OnSignalReceived<BreakSignal>(OnBreakSignalReceived);
 706324    }
 25
 26    /// <inheritdoc />
 27    protected override async ValueTask ScheduleChildrenAsync(ActivityExecutionContext context)
 28    {
 16629        await HandleItemAsync(context);
 16630    }
 31
 32    private async ValueTask HandleItemAsync(ActivityExecutionContext context)
 33    {
 45134        var currentIndex = context.GetProperty<int>(CurrentIndexProperty);
 45135        var childActivities = Activities.ToList();
 36
 45137        if (currentIndex >= childActivities.Count)
 38        {
 12139            await context.CompleteActivityAsync();
 12140            return;
 41        }
 42
 33043        var nextActivity = childActivities.ElementAt(currentIndex);
 33044        await context.ScheduleActivityAsync(nextActivity, OnChildCompleted);
 66045        context.UpdateProperty<int>(CurrentIndexProperty, x => x + 1);
 45146    }
 47
 48    private async ValueTask OnChildCompleted(ActivityCompletedContext context)
 49    {
 29650        var targetContext = context.TargetContext;
 29651        var childContext = context.ChildContext;
 29652        var isBreaking = targetContext.GetIsBreaking();
 29653        var completedActivity = childContext.Activity;
 54
 55        // If the complete activity is a terminal node, complete the sequence immediately.
 29656        if (isBreaking || completedActivity is ITerminalNode)
 57        {
 1158            await targetContext.CompleteActivityAsync();
 1159            return;
 60        }
 61
 28562        await HandleItemAsync(targetContext);
 29663    }
 64
 65    private void OnBreakSignalReceived(BreakSignal signal, SignalContext signalContext)
 66    {
 067        signalContext.ReceiverActivityExecutionContext.SetIsBreaking();
 068    }
 69}