< Summary

Information
Class: Elsa.Workflows.Runtime.Handlers.ResumeDispatchWorkflowActivity
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/ResumeDispatchWorkflowActivity.cs
Line coverage
97%
Covered lines: 42
Uncovered lines: 1
Coverable lines: 43
Total lines: 82
Line coverage: 97.6%
Branch coverage
78%
Covered branches: 11
Total branches: 14
Branch coverage: 78.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
HandleAsync()75%121291.66%
HandleAsync()100%22100%
EnqueueResumeAsync()100%11100%
EnqueueResumeAsync(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Handlers/ResumeDispatchWorkflowActivity.cs

#LineLine coverage
 1using Elsa.Mediator.Contracts;
 2using Elsa.Workflows.Helpers;
 3using Elsa.Workflows.Notifications;
 4using Elsa.Workflows.Runtime.Activities;
 5using Elsa.Workflows.Runtime.Messages;
 6using Elsa.Workflows.Runtime.Notifications;
 7using Elsa.Workflows.Runtime.Stimuli;
 8using JetBrains.Annotations;
 9
 10namespace Elsa.Workflows.Runtime.Handlers;
 11
 12/// <summary>
 13/// Resumes any blocking <see cref="DispatchWorkflow"/> activities when its child workflow completes.
 14/// </summary>
 15[PublicAPI]
 73416internal class ResumeDispatchWorkflowActivity(IBookmarkQueue bookmarkQueue, IStimulusHasher stimulusHasher, IStimulusSen
 17    INotificationHandler<WorkflowExecuted>,
 18    INotificationHandler<DispatchWorkflowActivationDenied>
 19{
 320    private static readonly string ActivityTypeName = ActivityTypeNameHelper.GenerateTypeName<DispatchWorkflow>();
 21
 22    public async Task HandleAsync(WorkflowExecuted notification, CancellationToken cancellationToken)
 23    {
 60524        var workflowState = notification.WorkflowState;
 25
 60526        if (workflowState.Status != WorkflowStatus.Finished)
 9627            return;
 28
 50929        var props = workflowState.Properties;
 50930        var waitForCompletion = props.TryGetValue("WaitForCompletion", out var waitForCompletionValue) && waitForComplet
 31
 50932        if (!waitForCompletion)
 49033            return;
 34
 1935        var parentInstanceId = props.TryGetValue("ParentInstanceId", out var parentInstanceIdValue) ? parentInstanceIdVa
 1936        if (string.IsNullOrWhiteSpace(parentInstanceId))
 037            return;
 38
 1939        await EnqueueResumeAsync(parentInstanceId, workflowState.Id, workflowState.Output, cancellationToken);
 60540    }
 41
 42    public async Task HandleAsync(DispatchWorkflowActivationDenied notification, CancellationToken cancellationToken)
 43    {
 444        if (notification.ActivityTypeName != ActivityTypeName)
 145            return;
 46
 347        var input = new Dictionary<string, object>
 348        {
 349            ["CannotStart"] = true,
 350            ["WorkflowInstanceId"] = notification.WorkflowInstanceId
 351        };
 352        await stimulusSender.SendAsync(notification.StimulusHash, new()
 353        {
 354            WorkflowInstanceId = notification.ParentWorkflowInstanceId,
 355            Input = input
 356        }, cancellationToken);
 457    }
 58
 59    private async Task EnqueueResumeAsync(string parentInstanceId, string workflowInstanceId, IDictionary<string, object
 60    {
 1961        var activityTypeName = ActivityTypeName;
 1962        var stimulus = new DispatchWorkflowStimulus(workflowInstanceId);
 1963        var stimulusHash = stimulusHasher.Hash(activityTypeName, stimulus);
 1964        await EnqueueResumeAsync(parentInstanceId, activityTypeName, stimulusHash, input, cancellationToken);
 1965    }
 66
 67    private Task EnqueueResumeAsync(string parentInstanceId, string activityTypeName, string stimulusHash, IDictionary<s
 68    {
 1969        var bookmarkQueueItem = new NewBookmarkQueueItem
 1970        {
 1971            WorkflowInstanceId = parentInstanceId,
 1972            ActivityTypeName = activityTypeName,
 1973            StimulusHash = stimulusHash,
 1974            Options = new()
 1975            {
 1976                Input = input
 1977            }
 1978        };
 79
 1980        return bookmarkQueue.EnqueueAsync(bookmarkQueueItem, cancellationToken);
 81    }
 82}