< Summary

Information
Class: Elsa.Extensions.ActivityPropertyExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/ActivityPropertyExtensions.cs
Line coverage
75%
Covered lines: 18
Uncovered lines: 6
Coverable lines: 24
Total lines: 108
Line coverage: 75%
Branch coverage
40%
Covered branches: 4
Total branches: 10
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
GetCanStartWorkflow(...)100%11100%
SetCanStartWorkflow(...)100%11100%
GetRunAsynchronously(...)100%11100%
SetRunAsynchronously(...)100%11100%
GetSource(...)100%11100%
SetSource(...)100%11100%
GetCommitStrategy(...)100%11100%
SetCommitStrategy(...)0%620%
SetSource(...)100%44100%
GetDisplayText(...)0%620%
SetDisplayText(...)100%11100%
GetDescription(...)0%620%
SetDescription(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/ActivityPropertyExtensions.cs

#LineLine coverage
 1using Elsa.Workflows;
 2
 3// ReSharper disable once CheckNamespace
 4namespace Elsa.Extensions;
 5
 6/// <summary>
 7/// Provides extension methods for <see cref="IActivity"/>.
 8/// </summary>
 9public static class ActivityPropertyExtensions
 10{
 511    private static readonly string[] CanStartWorkflowPropertyName = ["canStartWorkflow", "CanStartWorkflow"];
 512    private static readonly string[] RunAsynchronouslyPropertyName = ["runAsynchronously", "RunAsynchronously"];
 513    private static readonly string[] SourcePropertyName = ["source", "Source"];
 514    private static readonly string[] CommitStrategyName = ["commitStrategyName", "CommitStrategyName"];
 15
 16    extension(IActivity activity)
 17    {
 18        /// <summary>
 19        /// Gets a flag indicating whether this activity can be used for starting a workflow.
 20        /// Usually used for triggers, but also used to disambiguate between two or more starting activities and no star
 21        /// </summary>
 373222        public bool GetCanStartWorkflow() => activity.CustomProperties.GetValueOrDefault(CanStartWorkflowPropertyName, (
 23
 24        /// <summary>
 25        /// Sets a flag indicating whether this activity can be used for starting a workflow.
 26        /// </summary>
 267027        public void SetCanStartWorkflow(bool value) => activity.CustomProperties[CanStartWorkflowPropertyName[0]] = valu
 28
 29        /// <summary>
 30        /// Gets a flag indicating if this activity should execute synchronously or asynchronously.
 31        /// By default, activities with an <see cref="ActivityKind"/> of <see cref="Action"/>, <see cref="Task"/> or <se
 32        /// will execute synchronously, while activities of the <see cref="ActivityKind.Job"/> kind will execute asynchr
 33        /// </summary>
 34        public bool? GetRunAsynchronously()
 35        {
 4836            return activity.CustomProperties.GetValueOrDefault<bool?>(RunAsynchronouslyPropertyName, defaultValueFactory
 37        }
 38
 39        /// <summary>
 40        /// Sets a flag indicating if this activity should execute synchronously or asynchronously.
 41        /// By default, activities with an <see cref="ActivityKind"/> of <see cref="Action"/>, <see cref="Task"/> or <se
 42        /// will execute synchronously, while activities of the <see cref="ActivityKind.Job"/> kind will execute asynchr
 43        /// </summary>
 366344        public void SetRunAsynchronously(bool? value) => activity.CustomProperties[RunAsynchronouslyPropertyName[0]] = v
 45
 46        /// <summary>
 47        /// Gets the source file and line number where this activity was instantiated, if any.
 48        /// </summary>
 958649        public string? GetSource() => activity.CustomProperties.GetValueOrDefault(SourcePropertyName, () => default(stri
 50
 51        /// <summary>
 52        /// Sets the source file and line number where this activity was instantiated, if any.
 53        /// </summary>
 810854        public void SetSource(string value) => activity.CustomProperties[SourcePropertyName[0]] = value;
 55
 56        /// <summary>
 57        /// Gets the commit state behavior for the specified activity.
 58        /// </summary>
 1206259        public string? GetCommitStrategy() => activity.CustomProperties.GetValueOrDefault<string?>(CommitStrategyName, (
 60    }
 61
 62    /// <summary>
 63    /// Sets the commit state behavior for the specified activity.
 64    /// </summary>
 65    public static TActivity SetCommitStrategy<TActivity>(this TActivity activity, string? name) where TActivity : IActiv
 66    {
 067        if (string.IsNullOrWhiteSpace(name))
 068            activity.CustomProperties.Remove(CommitStrategyName[0]);
 69        else
 070            activity.CustomProperties[CommitStrategyName[0]] = name;
 071        return activity;
 72    }
 73
 74    extension(IActivity activity)
 75    {
 76        /// <summary>
 77        /// Sets the source file and line number where this activity was instantiated, if any.
 78        /// </summary>
 79        public void SetSource(string? sourceFile, int? lineNumber)
 80        {
 1297281            if (sourceFile == null || lineNumber == null)
 486482                return;
 83
 810884            var source = $"{Path.GetFileName(sourceFile)}:{lineNumber}";
 810885            activity.SetSource(source);
 810886        }
 87
 88        /// <summary>
 89        /// Gets the display text for the specified activity.
 90        /// </summary>
 091        public string? GetDisplayText() => activity.Metadata.TryGetValue("displayText", out var value) ? value.ToString(
 92
 93        /// <summary>
 94        /// Sets the display text for the specified activity.
 95        /// </summary>
 796        public void SetDisplayText(string value) => activity.Metadata["displayText"] = value;
 97
 98        /// <summary>
 99        /// Gets the description for the specified activity.
 100        /// </summary>
 0101        public string? GetDescription() => activity.Metadata.TryGetValue("description", out var value) ? value.ToString(
 102
 103        /// <summary>
 104        /// Sets the description for the specified activity.
 105        /// </summary>
 7106        public void SetDescription(string value) => activity.Metadata["description"] = value;
 107    }
 108}