< Summary

Information
Class: Elsa.Workflows.Activities.Inline<T>
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Inline.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 144
Line coverage: 0%
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%210%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%210%
ExecuteAsync()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{
 17    private readonly Func<ActivityExecutionContext, ValueTask> _activity = _ => default;
 18
 19    /// <inheritdoc />
 20    public Inline([CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : base(source, line)
 21    {
 22    }
 23
 24    /// <inheritdoc />
 25    public Inline(Func<ActivityExecutionContext, ValueTask> activity, [CallerFilePath] string? source = null, [CallerLin
 26    {
 27        _activity = activity;
 28    }
 29
 30    /// <inheritdoc />
 31    public Inline(Func<ValueTask> activity, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null)
 32    {
 33    }
 34
 35    /// <inheritdoc />
 36    public Inline(Action<ActivityExecutionContext> activity, [CallerFilePath] string? source = null, [CallerLineNumber] 
 37    {
 38        activity(c);
 39        return new ValueTask();
 40    }, source, line)
 41    {
 42    }
 43
 44    /// <inheritdoc />
 45    public Inline(Action activity, [CallerFilePath] string? source = null, [CallerLineNumber] int? line = null) : this(c
 46    {
 47        activity();
 48        return new ValueTask();
 49    }, source, line)
 50    {
 51    }
 52
 53    /// <inheritdoc />
 54    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>
 59    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>
 64    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>
 69    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>
 74    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>
 79    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>
 84    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>
 89    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>
 94    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
 0107        : base(output, source, line)
 108    {
 0109        _activity = activity;
 0110    }
 111
 112    /// <inheritdoc />
 113    public Inline(Func<ValueTask<T>> activity, MemoryBlockReference? output = null, [CallerFilePath] string? source = nu
 0114        : this(_ => activity(), output, source, line)
 115    {
 0116    }
 117
 118    /// <inheritdoc />
 119    public Inline(Func<ActivityExecutionContext, T> activity, MemoryBlockReference? output = null, [CallerFilePath] stri
 0120        : this(c =>
 0121    {
 0122        var result = activity(c);
 0123        return new ValueTask<T>(result);
 0124    }, output, source, line)
 125    {
 0126    }
 127
 128    /// <inheritdoc />
 129    public Inline(Func<T> activity, MemoryBlockReference? output = null, [CallerFilePath] string? source = null, [Caller
 0130        : this(c =>
 0131    {
 0132        var result = activity();
 0133        return new ValueTask<T>(result);
 0134    }, output, source, line)
 135    {
 0136    }
 137
 138    /// <inheritdoc />
 139    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 140    {
 0141        var result = await _activity(context);
 0142        context.Set(Result, result);
 0143    }
 144}