| | | 1 | | using Elsa.Workflows.Models; |
| | | 2 | | using Elsa.Workflows.Runtime.Options; |
| | | 3 | | using Elsa.Workflows.State; |
| | | 4 | | using Microsoft.Extensions.DependencyInjection; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Runtime; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | | 9 | | [Obsolete("Use IWorkflowRuntime, IWorkflowRunner and IWorkflowInvoker services instead.")] |
| | | 10 | | public class WorkflowHostFactory : IWorkflowHostFactory |
| | | 11 | | { |
| | | 12 | | private readonly IIdentityGenerator _identityGenerator; |
| | | 13 | | private readonly IServiceProvider _serviceProvider; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="WorkflowHostFactory"/> class. |
| | | 17 | | /// </summary> |
| | 0 | 18 | | public WorkflowHostFactory(IIdentityGenerator identityGenerator, IServiceProvider serviceProvider) |
| | | 19 | | { |
| | 0 | 20 | | _identityGenerator = identityGenerator; |
| | 0 | 21 | | _serviceProvider = serviceProvider; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public async Task<IWorkflowHost> CreateAsync(WorkflowGraph workflowGraph, WorkflowHostOptions? options = null, Cance |
| | | 26 | | { |
| | 0 | 27 | | var workflow = workflowGraph.Workflow; |
| | 0 | 28 | | var newWorkflowInstanceId = options?.NewWorkflowInstanceId ?? _identityGenerator.GenerateId(); |
| | 0 | 29 | | var workflowState = new WorkflowState |
| | 0 | 30 | | { |
| | 0 | 31 | | Id = newWorkflowInstanceId, |
| | 0 | 32 | | DefinitionId = workflow.Identity.DefinitionId, |
| | 0 | 33 | | DefinitionVersion = workflow.Identity.Version |
| | 0 | 34 | | }; |
| | | 35 | | |
| | 0 | 36 | | return await CreateAsync(workflowGraph, workflowState, cancellationToken); |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public Task<IWorkflowHost> CreateAsync(WorkflowGraph workflowGraph, WorkflowState workflowState, CancellationToken c |
| | | 41 | | { |
| | 0 | 42 | | var workflowHost = (IWorkflowHost)ActivatorUtilities.CreateInstance<WorkflowHost>(_serviceProvider, workflowGrap |
| | 0 | 43 | | return Task.FromResult(workflowHost); |
| | | 44 | | } |
| | | 45 | | } |