< Summary

Information
Class: Elsa.Workflows.Runtime.Activities.Event
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Activities/Event.cs
Line coverage
61%
Covered lines: 16
Uncovered lines: 10
Coverable lines: 26
Total lines: 86
Line coverage: 61.5%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%11100%
.ctor(...)100%210%
get_EventName()100%11100%
GetTriggerPayload(...)100%11100%
Execute(...)100%11100%
CompleteInternalAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Activities/Event.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2using Elsa.Expressions.Models;
 3using Elsa.Extensions;
 4using Elsa.Workflows.Attributes;
 5using Elsa.Workflows.Memory;
 6using Elsa.Workflows.Models;
 7using JetBrains.Annotations;
 8
 9namespace Elsa.Workflows.Runtime.Activities;
 10
 11/// <summary>
 12/// Wait for an event to be triggered.
 13/// </summary>
 14[Activity("Elsa", "Primitives", "Wait for an event to be published.")]
 15[UsedImplicitly]
 16public class Event : Trigger<object?>
 17{
 18    public const string EventInputWorkflowInputKey = "__EventPayloadWorkflowInput";
 19
 20    /// <inheritdoc />
 12121    internal Event([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 22    {
 12123    }
 24
 25    /// <inheritdoc />
 26    public Event(string eventName, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
 11427        : this(new Literal<string>(eventName), source, line)
 28    {
 11429    }
 30
 31    /// <inheritdoc />
 32    public Event(Func<string> eventName, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
 033        : this(new Input<string>(Expression.DelegateExpression(eventName), new()), source, line)
 34    {
 035    }
 36
 37    /// <inheritdoc />
 38    public Event(Func<ExpressionExecutionContext, string?> eventName, [CallerFilePath] string? source = null, [CallerLin
 039        : this(new Input<string>(Expression.DelegateExpression(eventName), new()), source, line)
 40    {
 041    }
 42
 43    /// <inheritdoc />
 044    public Event(Variable<string> variable, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
 45    {
 046        EventName = new(variable);
 047    }
 48
 49    /// <inheritdoc />
 11450    public Event(Literal<string> literal, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) :
 51    {
 11452        EventName = new(literal);
 11453    }
 54
 55    /// <inheritdoc />
 056    public Event(Input<string> eventName, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) :
 57    {
 058        EventName = eventName;
 059    }
 60
 61    /// <summary>
 62    /// The name of the event to listen for.
 63    /// </summary>
 64    [Input(Description = "The name of the event to listen for.")]
 50765    public Input<string> EventName { get; set; } = null!;
 66
 67    /// <inheritdoc />
 68    protected override object GetTriggerPayload(TriggerIndexingContext context)
 69    {
 1670        var eventName = EventName.Get(context.ExpressionExecutionContext);
 1671        return context.GetEventStimulus(eventName);
 72    }
 73
 74    /// <inheritdoc />
 75    protected override void Execute(ActivityExecutionContext context)
 76    {
 2277        var eventName = context.Get(EventName)!;
 2278        context.WaitForEvent(eventName, CompleteInternalAsync);
 2279    }
 80
 81    private async ValueTask CompleteInternalAsync(ActivityExecutionContext context)
 82    {
 1583        context.SetResult(context.GetEventInput());
 1584        await context.CompleteActivityAsync();
 1585    }
 86}