< Summary

Information
Class: Elsa.Workflows.ActivityExecutionContextSchedulerStrategy
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/ActivityExecutionContextSchedulerStrategy.cs
Line coverage
41%
Covered lines: 17
Uncovered lines: 24
Coverable lines: 41
Total lines: 72
Line coverage: 41.4%
Branch coverage
32%
Covered branches: 11
Total branches: 34
Branch coverage: 32.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ScheduleActivityAsync()75%44100%
ScheduleActivityAsync()26.66%2973033.33%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/ActivityExecutionContextSchedulerStrategy.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows.Models;
 3using Elsa.Workflows.Options;
 4
 5namespace Elsa.Workflows;
 6
 7/// <inheritdoc />
 8public class ActivityExecutionContextSchedulerStrategy : IActivityExecutionContextSchedulerStrategy
 9{
 10    /// <inheritdoc />
 11    public async Task ScheduleActivityAsync(ActivityExecutionContext context, IActivity? activity, ActivityExecutionCont
 12    {
 282613        var activityNode = activity != null
 282614            ? context.WorkflowExecutionContext.FindNodeByActivity(activity) ?? throw new InvalidOperationException("The 
 282615            : null;
 282616        await ScheduleActivityAsync(context, activityNode, owner, options);
 282617    }
 18
 19    /// <inheritdoc />
 20    public async Task ScheduleActivityAsync(ActivityExecutionContext context, ActivityNode? activityNode, ActivityExecut
 21    {
 282622        var workflowExecutionContext = context.WorkflowExecutionContext;
 282623        if (context.GetIsBackgroundExecution())
 24        {
 25            // Validate that the specified activity is part of the workflow.
 026            if (activityNode != null && !workflowExecutionContext.NodeActivityLookup.ContainsKey(activityNode.Activity))
 027                throw new InvalidOperationException("The specified activity is not part of the workflow.");
 28
 029            var scheduledActivity = new ScheduledActivity
 030            {
 031                ActivityNodeId = activityNode?.NodeId,
 032                OwnerActivityInstanceId = owner?.Id,
 033                Options = options != null
 034                    ? new ScheduledActivityOptions
 035                    {
 036                        CompletionCallback = options.CompletionCallback?.Method.Name,
 037                        Tag = options.Tag,
 038                        ExistingActivityInstanceId = options.ExistingActivityExecutionContext?.Id,
 039                        PreventDuplicateScheduling = options.PreventDuplicateScheduling,
 040                        SchedulingActivityExecutionId = options.SchedulingActivityExecutionId ?? context.Id,
 041                        Variables = options.Variables?.ToList(),
 042                        Input = options.Input
 043                    }
 044                    : null
 045            };
 46
 047            var scheduledActivities = context.GetBackgroundScheduledActivities().ToList();
 048            scheduledActivities.Add(scheduledActivity);
 049            context.SetBackgroundScheduledActivities(scheduledActivities);
 050            return;
 51        }
 52
 282653        var completionCallback = options?.CompletionCallback;
 282654        owner ??= context;
 55
 282656        if (activityNode == null)
 57        {
 1058            if (completionCallback != null)
 59            {
 1060                context.Tag = options?.Tag;
 1061                var completedContext = new ActivityCompletedContext(context, context);
 1062                await completionCallback(completedContext);
 63            }
 64            else
 065                await owner.CompleteActivityAsync();
 66
 1067            return;
 68        }
 69
 281670        workflowExecutionContext.Schedule(activityNode, owner, options);
 282671    }
 72}