< Summary

Information
Class: Elsa.Workflows.Activities.Workflow
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Workflow.cs
Line coverage
95%
Covered lines: 47
Uncovered lines: 2
Coverable lines: 49
Total lines: 142
Line coverage: 95.9%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
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%11100%
get_Identity()100%11100%
get_Publication()100%11100%
get_Inputs()100%11100%
get_Outputs()100%11100%
get_Outcomes()100%11100%
get_WorkflowMetadata()100%11100%
get_Options()100%11100%
get_IsReadonly()100%11100%
get_IsSystem()100%11100%
get_DefinitionHandle()100%11100%
FromActivity(...)100%22100%
CreateRegister()100%11100%
ExecuteAsync()100%22100%
Clone()100%210%
System.ICloneable.Clone()100%210%

File(s)

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

#LineLine coverage
 1using System.ComponentModel;
 2using Elsa.Expressions.Models;
 3using Elsa.Workflows.Attributes;
 4using Elsa.Workflows.Memory;
 5using Elsa.Workflows.Models;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Workflows.Activities;
 9
 10/// <summary>
 11/// Represents an executable process.
 12/// </summary>
 13[Browsable(false)]
 14[Activity("Elsa", "Workflows", "A workflow is an activity that executes its Root activity.")]
 15[PublicAPI]
 16public class Workflow : Composite<object>, ICloneable
 17{
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="Workflow"/> class.
 20    /// </summary>
 210121    public Workflow(
 210122        WorkflowIdentity identity,
 210123        WorkflowPublication publication,
 210124        WorkflowMetadata workflowMetadata,
 210125        WorkflowOptions options,
 210126        IActivity root,
 210127        ICollection<Variable> variables,
 210128        ICollection<InputDefinition> inputs,
 210129        ICollection<OutputDefinition> outputs,
 210130        ICollection<string> outcomes,
 210131        IDictionary<string, object> customProperties,
 210132        bool isReadonly,
 210133        bool isSystem)
 34    {
 210135        Identity = identity;
 210136        Publication = publication;
 210137        Inputs = inputs;
 210138        Outputs = outputs;
 210139        Outcomes = outcomes;
 210140        WorkflowMetadata = workflowMetadata;
 210141        Options = options;
 210142        Variables = variables;
 210143        CustomProperties = customProperties;
 210144        Root = root;
 210145        IsReadonly = isReadonly;
 210146        IsSystem = isSystem;
 210147    }
 48
 49    /// <summary>
 50    /// Initializes a new instance of the <see cref="Workflow"/> class.
 51    /// </summary>
 53952    public Workflow(IActivity root) : this()
 53    {
 53954        Root = root;
 53955    }
 56
 57    /// <summary>
 58    /// Initializes a new instance of the <see cref="Workflow"/> class.
 59    /// </summary>
 53960    public Workflow()
 61    {
 53962    }
 63
 64    /// <summary>
 65    /// Gets or sets the workflow identity.
 66    /// </summary>
 2685167    public WorkflowIdentity Identity { get; set; } = WorkflowIdentity.VersionOne;
 68
 69    /// <summary>
 70    /// Gets or sets the publication status of the workflow.
 71    /// </summary>
 654572    public WorkflowPublication Publication { get; set; } = WorkflowPublication.LatestAndPublished;
 73
 74    /// <summary>
 75    /// Gets or sets input definitions.
 76    /// </summary>
 584977    public ICollection<InputDefinition> Inputs { get; set; } = new List<InputDefinition>();
 78
 79    /// <summary>
 80    /// Gets or sets output definitions.
 81    /// </summary>
 542282    public ICollection<OutputDefinition> Outputs { get; set; } = new List<OutputDefinition>();
 83
 84    /// <summary>
 85    /// Gets or sets possible outcomes for this workflow.
 86    /// </summary>
 538687    public ICollection<string> Outcomes { get; set; } = new List<string>();
 88
 89    /// <summary>
 90    /// Gets or sets metadata about the workflow.
 91    /// </summary>
 747192    public WorkflowMetadata WorkflowMetadata { get; set; } = new();
 93
 94    /// <summary>
 95    /// Gets or sets options for the workflow.
 96    /// </summary>
 1187697    public WorkflowOptions Options { get; set; } = new();
 98
 99    /// <summary>
 100    /// Make workflow definition readonly.
 101    /// </summary>
 2746102    public bool IsReadonly { get; set; }
 103
 104    /// <summary>
 105    /// Gets or sets a value indicating whether the workflow is a system workflow.
 106    /// </summary>
 1170107    public bool IsSystem { get; }
 108
 109    /// <summary>
 110    /// Returns the workflow definition handle.
 111    /// </summary>
 1112    public WorkflowDefinitionHandle DefinitionHandle => WorkflowDefinitionHandle.ByDefinitionVersionId(Identity.Id);
 113
 114    /// <summary>
 115    /// Constructs a new <see cref="Workflow"/> from the specified <see cref="IActivity"/>.
 116    /// </summary>
 539117    public static Workflow FromActivity(IActivity root) => root as Workflow ?? new(root);
 118
 119    /// <summary>
 120    /// Creates a new memory register initialized with this workflow's variables.
 121    /// </summary>
 122    public MemoryRegister CreateRegister()
 123    {
 916124        return new MemoryRegister();
 125    }
 126
 127    /// <inheritdoc />
 128    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 129    {
 803130        if(ResultVariable != null)
 84131            context.WorkflowExecutionContext.MemoryRegister.Declare(ResultVariable);
 132
 803133        await base.ExecuteAsync(context);
 803134    }
 135
 136    /// <summary>
 137    /// Create a shallow copy of this workflow.
 138    /// </summary>
 0139    public Workflow Clone() => (Workflow)((ICloneable)this).Clone();
 140
 0141    object ICloneable.Clone() => MemberwiseClone();
 142}