< Summary

Information
Class: Elsa.Workflows.Runtime.ActivityExecutionStoreExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/ActivityExecutionStoreExtensions.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 60
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetExecutionChainAsync()100%1616100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/ActivityExecutionStoreExtensions.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Workflows.Runtime.Entities;
 3
 4namespace Elsa.Workflows.Runtime;
 5
 6/// <summary>
 7/// Provides extension methods for <see cref="IActivityExecutionStore"/>.
 8/// </summary>
 9public static class ActivityExecutionStoreExtensions
 10{
 11    /// <summary>
 12    /// Retrieves the execution chain for the specified activity execution record by traversing the SchedulingActivityEx
 13    /// Returns records ordered from root (depth 0) to the specified record.
 14    /// </summary>
 15    public static async Task<Page<ActivityExecutionRecord>> GetExecutionChainAsync(
 16        this IActivityExecutionStore store,
 17        string activityExecutionId,
 18        bool includeCrossWorkflowChain = true,
 19        int? skip = null,
 20        int? take = null,
 21        CancellationToken cancellationToken = default)
 22    {
 1023        var chain = new List<ActivityExecutionRecord>();
 1024        var visited = new HashSet<string>();
 1025        var loadedRecords = new Dictionary<string, ActivityExecutionRecord>();
 1026        var currentId = activityExecutionId;
 27
 3628        while (currentId != null && visited.Add(currentId))
 29        {
 2830            if (!loadedRecords.TryGetValue(currentId, out var record))
 31            {
 2832                record = await store.FindAsync(new() { Id = currentId }, cancellationToken);
 33
 2834                if (record == null)
 35                    break;
 36
 2737                loadedRecords.TryAdd(currentId, record);
 38            }
 39
 2740            chain.Add(record);
 41
 2742            if (!includeCrossWorkflowChain && record.SchedulingWorkflowInstanceId != null)
 43                break;
 44
 2645            currentId = record.SchedulingActivityExecutionId;
 46        }
 47
 1048        chain.Reverse();
 49
 1050        var totalCount = chain.Count;
 51
 1052        if (skip.HasValue)
 853            chain = chain.Skip(skip.Value).ToList();
 54
 1055        if (take.HasValue)
 256            chain = chain.Take(take.Value).ToList();
 57
 1058        return Page.Of(chain, totalCount);
 1059    }
 60}

Methods/Properties

GetExecutionChainAsync()