< Summary

Information
Class: Elsa.Workflows.Activities.Inline
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Inline.cs
Line coverage
37%
Covered lines: 11
Uncovered lines: 18
Coverable lines: 29
Total lines: 144
Line coverage: 37.9%
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%1133.33%
.ctor(...)100%11100%
.ctor(...)100%210%
.ctor(...)100%11100%
.ctor(...)100%210%
ExecuteAsync()100%11100%
From(...)100%210%
From(...)100%210%
From(...)100%210%
From(...)100%210%
From(...)100%210%
From(...)100%210%
From(...)100%210%
From(...)100%210%

File(s)

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

#LineLine coverage
 1using System.ComponentModel;
 2using System.Runtime.CompilerServices;
 3using Elsa.Expressions.Models;
 4using Elsa.Workflows.Attributes;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Activities;
 8
 9/// <summary>
 10/// Represents an inline code activity that can be used to execute arbitrary .NET code from a workflow.
 11/// </summary>
 12[Browsable(false)]
 13[Activity("Elsa", "Primitives", "Evaluate a Boolean condition to determine which path to execute next.")]
 14[PublicAPI]
 15public class Inline : CodeActivity
 16{
 317    private readonly Func<ActivityExecutionContext, ValueTask> _activity = _ => default;
 18
 19    /// <inheritdoc />
 020    public Inline([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 21    {
 022    }
 23
 24    /// <inheritdoc />
 325    public Inline(Func<ActivityExecutionContext, ValueTask> activity, [CallerFilePath] string? source = null, [CallerLin
 26    {
 327        _activity = activity;
 328    }
 29
 30    /// <inheritdoc />
 031    public Inline(Func<ValueTask> activity, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
 32    {
 033    }
 34
 35    /// <inheritdoc />
 336    public Inline(Action<ActivityExecutionContext> activity, [CallerFilePath] string? source = null, [CallerLineNumber] 
 337    {
 338        activity(c);
 339        return new ValueTask();
 340    }, source, line)
 41    {
 342    }
 43
 44    /// <inheritdoc />
 045    public Inline(Action activity, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this(c
 046    {
 047        activity();
 048        return new ValueTask();
 049    }, source, line)
 50    {
 051    }
 52
 53    /// <inheritdoc />
 354    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) => await _activity(context);
 55
 56    /// <summary>
 57    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 58    /// </summary>
 059    public static Inline From(Func<ActivityExecutionContext, ValueTask> activity) => new(activity);
 60
 61    /// <summary>
 62    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 63    /// </summary>
 064    public static Inline From(Func<ValueTask> activity) => new(activity);
 65
 66    /// <summary>
 67    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 68    /// </summary>
 069    public static Inline From(Action<ActivityExecutionContext> activity) => new(activity);
 70
 71    /// <summary>
 72    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 73    /// </summary>
 074    public static Inline From(Action activity) => new(activity);
 75
 76    /// <summary>
 77    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 78    /// </summary>
 079    public static Inline<T> From<T>(Func<ActivityExecutionContext, ValueTask<T>> activity) => new(activity);
 80
 81    /// <summary>
 82    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 83    /// </summary>
 084    public static Inline<T> From<T>(Func<ValueTask<T>> activity) => new(activity);
 85
 86    /// <summary>
 87    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 88    /// </summary>
 089    public static Inline<T> From<T>(Func<ActivityExecutionContext, T> activity) => new(activity);
 90
 91    /// <summary>
 92    /// Creates a new <see cref="Inline"/> activity from the specified delegate.
 93    /// </summary>
 094    public static Inline<T> From<T>(Func<T> activity) => new(activity);
 95}
 96
 97/// <summary>
 98/// Represents an inline code activity that can be used to execute arbitrary .NET code from a workflow and return a valu
 99/// </summary>
 100[PublicAPI]
 101public class Inline<T> : CodeActivity<T>
 102{
 103    private readonly Func<ActivityExecutionContext, ValueTask<T>> _activity;
 104
 105    /// <inheritdoc />
 106    public Inline(Func<ActivityExecutionContext, ValueTask<T>> activity, MemoryBlockReference? output = null, [CallerFil
 107        : base(output, source, line)
 108    {
 109        _activity = activity;
 110    }
 111
 112    /// <inheritdoc />
 113    public Inline(Func<ValueTask<T>> activity, MemoryBlockReference? output = null, [CallerFilePath] string? source = nu
 114        : this(_ => activity(), output, source, line)
 115    {
 116    }
 117
 118    /// <inheritdoc />
 119    public Inline(Func<ActivityExecutionContext, T> activity, MemoryBlockReference? output = null, [CallerFilePath] stri
 120        : this(c =>
 121    {
 122        var result = activity(c);
 123        return new ValueTask<T>(result);
 124    }, output, source, line)
 125    {
 126    }
 127
 128    /// <inheritdoc />
 129    public Inline(Func<T> activity, MemoryBlockReference? output = null, [CallerFilePath] string? source = null, [Caller
 130        : this(c =>
 131    {
 132        var result = activity();
 133        return new ValueTask<T>(result);
 134    }, output, source, line)
 135    {
 136    }
 137
 138    /// <inheritdoc />
 139    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 140    {
 141        var result = await _activity(context);
 142        context.Set(Result, result);
 143    }
 144}