| | | 1 | | using System.ComponentModel; |
| | | 2 | | using Elsa.Expressions.Models; |
| | | 3 | | using Elsa.Workflows.Attributes; |
| | | 4 | | using Elsa.Workflows.Memory; |
| | | 5 | | using Elsa.Workflows.Models; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | |
| | | 8 | | namespace 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] |
| | | 16 | | public class Workflow : Composite<object>, ICloneable |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="Workflow"/> class. |
| | | 20 | | /// </summary> |
| | 2101 | 21 | | public Workflow( |
| | 2101 | 22 | | WorkflowIdentity identity, |
| | 2101 | 23 | | WorkflowPublication publication, |
| | 2101 | 24 | | WorkflowMetadata workflowMetadata, |
| | 2101 | 25 | | WorkflowOptions options, |
| | 2101 | 26 | | IActivity root, |
| | 2101 | 27 | | ICollection<Variable> variables, |
| | 2101 | 28 | | ICollection<InputDefinition> inputs, |
| | 2101 | 29 | | ICollection<OutputDefinition> outputs, |
| | 2101 | 30 | | ICollection<string> outcomes, |
| | 2101 | 31 | | IDictionary<string, object> customProperties, |
| | 2101 | 32 | | bool isReadonly, |
| | 2101 | 33 | | bool isSystem) |
| | | 34 | | { |
| | 2101 | 35 | | Identity = identity; |
| | 2101 | 36 | | Publication = publication; |
| | 2101 | 37 | | Inputs = inputs; |
| | 2101 | 38 | | Outputs = outputs; |
| | 2101 | 39 | | Outcomes = outcomes; |
| | 2101 | 40 | | WorkflowMetadata = workflowMetadata; |
| | 2101 | 41 | | Options = options; |
| | 2101 | 42 | | Variables = variables; |
| | 2101 | 43 | | CustomProperties = customProperties; |
| | 2101 | 44 | | Root = root; |
| | 2101 | 45 | | IsReadonly = isReadonly; |
| | 2101 | 46 | | IsSystem = isSystem; |
| | 2101 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Initializes a new instance of the <see cref="Workflow"/> class. |
| | | 51 | | /// </summary> |
| | 539 | 52 | | public Workflow(IActivity root) : this() |
| | | 53 | | { |
| | 539 | 54 | | Root = root; |
| | 539 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Initializes a new instance of the <see cref="Workflow"/> class. |
| | | 59 | | /// </summary> |
| | 539 | 60 | | public Workflow() |
| | | 61 | | { |
| | 539 | 62 | | } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets or sets the workflow identity. |
| | | 66 | | /// </summary> |
| | 26851 | 67 | | public WorkflowIdentity Identity { get; set; } = WorkflowIdentity.VersionOne; |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Gets or sets the publication status of the workflow. |
| | | 71 | | /// </summary> |
| | 6545 | 72 | | public WorkflowPublication Publication { get; set; } = WorkflowPublication.LatestAndPublished; |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Gets or sets input definitions. |
| | | 76 | | /// </summary> |
| | 5849 | 77 | | public ICollection<InputDefinition> Inputs { get; set; } = new List<InputDefinition>(); |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Gets or sets output definitions. |
| | | 81 | | /// </summary> |
| | 5422 | 82 | | public ICollection<OutputDefinition> Outputs { get; set; } = new List<OutputDefinition>(); |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Gets or sets possible outcomes for this workflow. |
| | | 86 | | /// </summary> |
| | 5386 | 87 | | public ICollection<string> Outcomes { get; set; } = new List<string>(); |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Gets or sets metadata about the workflow. |
| | | 91 | | /// </summary> |
| | 7471 | 92 | | public WorkflowMetadata WorkflowMetadata { get; set; } = new(); |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Gets or sets options for the workflow. |
| | | 96 | | /// </summary> |
| | 11876 | 97 | | public WorkflowOptions Options { get; set; } = new(); |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// Make workflow definition readonly. |
| | | 101 | | /// </summary> |
| | 2746 | 102 | | public bool IsReadonly { get; set; } |
| | | 103 | | |
| | | 104 | | /// <summary> |
| | | 105 | | /// Gets or sets a value indicating whether the workflow is a system workflow. |
| | | 106 | | /// </summary> |
| | 1170 | 107 | | public bool IsSystem { get; } |
| | | 108 | | |
| | | 109 | | /// <summary> |
| | | 110 | | /// Returns the workflow definition handle. |
| | | 111 | | /// </summary> |
| | 1 | 112 | | 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> |
| | 539 | 117 | | 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 | | { |
| | 916 | 124 | | return new MemoryRegister(); |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | /// <inheritdoc /> |
| | | 128 | | protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) |
| | | 129 | | { |
| | 803 | 130 | | if(ResultVariable != null) |
| | 84 | 131 | | context.WorkflowExecutionContext.MemoryRegister.Declare(ResultVariable); |
| | | 132 | | |
| | 803 | 133 | | await base.ExecuteAsync(context); |
| | 803 | 134 | | } |
| | | 135 | | |
| | | 136 | | /// <summary> |
| | | 137 | | /// Create a shallow copy of this workflow. |
| | | 138 | | /// </summary> |
| | 0 | 139 | | public Workflow Clone() => (Workflow)((ICloneable)this).Clone(); |
| | | 140 | | |
| | 0 | 141 | | object ICloneable.Clone() => MemberwiseClone(); |
| | | 142 | | } |