< 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>
 221421    public Workflow(
 221422        WorkflowIdentity identity,
 221423        WorkflowPublication publication,
 221424        WorkflowMetadata workflowMetadata,
 221425        WorkflowOptions options,
 221426        IActivity root,
 221427        ICollection<Variable> variables,
 221428        ICollection<InputDefinition> inputs,
 221429        ICollection<OutputDefinition> outputs,
 221430        ICollection<string> outcomes,
 221431        IDictionary<string, object> customProperties,
 221432        bool isReadonly,
 221433        bool isSystem)
 34    {
 221435        Identity = identity;
 221436        Publication = publication;
 221437        Inputs = inputs;
 221438        Outputs = outputs;
 221439        Outcomes = outcomes;
 221440        WorkflowMetadata = workflowMetadata;
 221441        Options = options;
 221442        Variables = variables;
 221443        CustomProperties = customProperties;
 221444        Root = root;
 221445        IsReadonly = isReadonly;
 221446        IsSystem = isSystem;
 221447    }
 48
 49    /// <summary>
 50    /// Initializes a new instance of the <see cref="Workflow"/> class.
 51    /// </summary>
 54052    public Workflow(IActivity root) : this()
 53    {
 54054        Root = root;
 54055    }
 56
 57    /// <summary>
 58    /// Initializes a new instance of the <see cref="Workflow"/> class.
 59    /// </summary>
 54060    public Workflow()
 61    {
 54062    }
 63
 64    /// <summary>
 65    /// Gets or sets the workflow identity.
 66    /// </summary>
 2914867    public WorkflowIdentity Identity { get; set; } = WorkflowIdentity.VersionOne;
 68
 69    /// <summary>
 70    /// Gets or sets the publication status of the workflow.
 71    /// </summary>
 695672    public WorkflowPublication Publication { get; set; } = WorkflowPublication.LatestAndPublished;
 73
 74    /// <summary>
 75    /// Gets or sets input definitions.
 76    /// </summary>
 619177    public ICollection<InputDefinition> Inputs { get; set; } = new List<InputDefinition>();
 78
 79    /// <summary>
 80    /// Gets or sets output definitions.
 81    /// </summary>
 576782    public ICollection<OutputDefinition> Outputs { get; set; } = new List<OutputDefinition>();
 83
 84    /// <summary>
 85    /// Gets or sets possible outcomes for this workflow.
 86    /// </summary>
 567787    public ICollection<string> Outcomes { get; set; } = new List<string>();
 88
 89    /// <summary>
 90    /// Gets or sets metadata about the workflow.
 91    /// </summary>
 795492    public WorkflowMetadata WorkflowMetadata { get; set; } = new();
 93
 94    /// <summary>
 95    /// Gets or sets options for the workflow.
 96    /// </summary>
 1263297    public WorkflowOptions Options { get; set; } = new();
 98
 99    /// <summary>
 100    /// Make workflow definition readonly.
 101    /// </summary>
 2923102    public bool IsReadonly { get; set; }
 103
 104    /// <summary>
 105    /// Gets or sets a value indicating whether the workflow is a system workflow.
 106    /// </summary>
 1285107    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>
 540117    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    {
 1024124        return new MemoryRegister();
 125    }
 126
 127    /// <inheritdoc />
 128    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
 129    {
 854130        if(ResultVariable != null)
 135131            context.WorkflowExecutionContext.MemoryRegister.Declare(ResultVariable);
 132
 854133        await base.ExecuteAsync(context);
 854134    }
 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}