| | | 1 | | using Elsa.Common; |
| | | 2 | | using Elsa.Workflows.Activities; |
| | | 3 | | using Elsa.Workflows.Management.Contracts; |
| | | 4 | | using Elsa.Workflows.Management.Entities; |
| | | 5 | | using Elsa.Workflows.Management.Options; |
| | | 6 | | using Elsa.Workflows.State; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Management.Services; |
| | | 9 | | |
| | | 10 | | /// <inheritdoc /> |
| | 321 | 11 | | public class WorkflowInstanceFactory(IIdentityGenerator identityGenerator, ISystemClock systemClock) : IWorkflowInstance |
| | | 12 | | { |
| | | 13 | | /// <inheritdoc /> |
| | | 14 | | public WorkflowState CreateWorkflowState(Workflow workflow, WorkflowInstanceOptions? options = null) |
| | | 15 | | { |
| | 72 | 16 | | var now = systemClock.UtcNow; |
| | 72 | 17 | | return new() |
| | 72 | 18 | | { |
| | 72 | 19 | | Id = string.IsNullOrEmpty(options?.WorkflowInstanceId) ? identityGenerator.GenerateId() : options.WorkflowIn |
| | 72 | 20 | | DefinitionId = workflow.Identity.DefinitionId, |
| | 72 | 21 | | DefinitionVersionId = workflow.Identity.Id, |
| | 72 | 22 | | DefinitionVersion = workflow.Identity.Version, |
| | 72 | 23 | | CorrelationId = options?.CorrelationId, |
| | 72 | 24 | | Name = options?.Name, |
| | 72 | 25 | | Input = options?.Input ?? new Dictionary<string, object>(), |
| | 72 | 26 | | Properties = options?.Properties ?? new Dictionary<string, object>(), |
| | 72 | 27 | | Status = WorkflowStatus.Running, |
| | 72 | 28 | | SubStatus = WorkflowSubStatus.Pending, |
| | 72 | 29 | | CreatedAt = now, |
| | 72 | 30 | | UpdatedAt = now, |
| | 72 | 31 | | ParentWorkflowInstanceId = options?.ParentWorkflowInstanceId, |
| | 72 | 32 | | IsSystem = workflow.IsSystem |
| | 72 | 33 | | }; |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | | 37 | | public WorkflowInstance CreateWorkflowInstance(Workflow workflow, WorkflowInstanceOptions? options = null) |
| | | 38 | | { |
| | 72 | 39 | | var workflowState = CreateWorkflowState(workflow, options); |
| | 72 | 40 | | return new() |
| | 72 | 41 | | { |
| | 72 | 42 | | Id = workflowState.Id, |
| | 72 | 43 | | ParentWorkflowInstanceId = workflowState.ParentWorkflowInstanceId, |
| | 72 | 44 | | WorkflowState = workflowState, |
| | 72 | 45 | | DefinitionId = workflowState.DefinitionId, |
| | 72 | 46 | | DefinitionVersionId = workflowState.DefinitionVersionId, |
| | 72 | 47 | | Version = workflowState.DefinitionVersion, |
| | 72 | 48 | | CorrelationId = workflowState.CorrelationId, |
| | 72 | 49 | | Name = workflowState.Name, |
| | 72 | 50 | | Status = workflowState.Status, |
| | 72 | 51 | | SubStatus = workflowState.SubStatus, |
| | 72 | 52 | | IncidentCount = workflowState.Incidents.Count, |
| | 72 | 53 | | IsSystem = workflowState.IsSystem, |
| | 72 | 54 | | CreatedAt = workflowState.CreatedAt, |
| | 72 | 55 | | UpdatedAt = workflowState.UpdatedAt, |
| | 72 | 56 | | FinishedAt = workflowState.FinishedAt, |
| | 72 | 57 | | }; |
| | | 58 | | } |
| | | 59 | | } |