| | | 1 | | using Elsa.Common.Models; |
| | | 2 | | using Elsa.Workflows.Management.Entities; |
| | | 3 | | using Elsa.Workflows.Management.Filters; |
| | | 4 | | using Elsa.Workflows.Models; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Management.Services; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | 324 | 9 | | public class WorkflowDefinitionService( |
| | 324 | 10 | | IWorkflowDefinitionStore workflowDefinitionStore, |
| | 324 | 11 | | IWorkflowGraphBuilder workflowGraphBuilder, |
| | 324 | 12 | | Func<IEnumerable<IWorkflowMaterializer>> materializers) |
| | | 13 | | : IWorkflowDefinitionService |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public async Task<WorkflowGraph> MaterializeWorkflowAsync(WorkflowDefinition definition, CancellationToken cancellat |
| | | 17 | | { |
| | 1391 | 18 | | var workflowMaterializers = materializers(); |
| | 5098 | 19 | | var materializer = workflowMaterializers.FirstOrDefault(x => x.Name == definition.MaterializerName); |
| | | 20 | | |
| | 1391 | 21 | | if (materializer == null) |
| | 0 | 22 | | throw new("Provider not found"); |
| | | 23 | | |
| | 1391 | 24 | | var workflow = await materializer.MaterializeAsync(definition, cancellationToken); |
| | 1391 | 25 | | return await workflowGraphBuilder.BuildAsync(workflow, cancellationToken); |
| | 1391 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | public Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(string definitionId, VersionOptions versionOptions, Can |
| | | 30 | | { |
| | 20 | 31 | | var handle = WorkflowDefinitionHandle.ByDefinitionId(definitionId, versionOptions); |
| | 20 | 32 | | return FindWorkflowDefinitionAsync(handle, cancellationToken); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <inheritdoc /> |
| | | 36 | | public Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(string definitionVersionId, CancellationToken cancellat |
| | | 37 | | { |
| | 77 | 38 | | var handle = WorkflowDefinitionHandle.ByDefinitionVersionId(definitionVersionId); |
| | 77 | 39 | | return FindWorkflowDefinitionAsync(handle, cancellationToken); |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | public async Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(WorkflowDefinitionHandle handle, CancellationToke |
| | | 44 | | { |
| | 97 | 45 | | var filter = handle.ToFilter(); |
| | 97 | 46 | | return await workflowDefinitionStore.FindAsync(filter, cancellationToken); |
| | 97 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <inheritdoc /> |
| | | 50 | | public async Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(WorkflowDefinitionFilter filter, CancellationToke |
| | | 51 | | { |
| | 423 | 52 | | return await workflowDefinitionStore.FindAsync(filter, cancellationToken); |
| | 423 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <inheritdoc /> |
| | | 56 | | public async Task<WorkflowGraph?> FindWorkflowGraphAsync(string definitionId, VersionOptions versionOptions, Cancell |
| | | 57 | | { |
| | 18 | 58 | | var definition = await FindWorkflowDefinitionAsync(definitionId, versionOptions, cancellationToken); |
| | | 59 | | |
| | 18 | 60 | | if (definition == null) |
| | 1 | 61 | | return null; |
| | | 62 | | |
| | 17 | 63 | | return await MaterializeWorkflowAsync(definition, cancellationToken); |
| | 18 | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <inheritdoc /> |
| | | 67 | | public async Task<WorkflowGraph?> FindWorkflowGraphAsync(string definitionVersionId, CancellationToken cancellationT |
| | | 68 | | { |
| | 77 | 69 | | var definition = await FindWorkflowDefinitionAsync(definitionVersionId, cancellationToken); |
| | | 70 | | |
| | 77 | 71 | | if (definition == null) |
| | 0 | 72 | | return null; |
| | | 73 | | |
| | 77 | 74 | | return await MaterializeWorkflowAsync(definition, cancellationToken); |
| | 77 | 75 | | } |
| | | 76 | | |
| | | 77 | | /// <inheritdoc /> |
| | | 78 | | public async Task<WorkflowGraph?> FindWorkflowGraphAsync(WorkflowDefinitionHandle definitionHandle, CancellationToke |
| | | 79 | | { |
| | 0 | 80 | | var definition = await FindWorkflowDefinitionAsync(definitionHandle, cancellationToken); |
| | | 81 | | |
| | 0 | 82 | | if (definition == null) |
| | 0 | 83 | | return null; |
| | | 84 | | |
| | 0 | 85 | | return await MaterializeWorkflowAsync(definition, cancellationToken); |
| | 0 | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <inheritdoc /> |
| | | 89 | | public async Task<WorkflowGraph?> FindWorkflowGraphAsync(WorkflowDefinitionFilter filter, CancellationToken cancella |
| | | 90 | | { |
| | 283 | 91 | | var definition = await FindWorkflowDefinitionAsync(filter, cancellationToken); |
| | | 92 | | |
| | 283 | 93 | | if (definition == null) |
| | 0 | 94 | | return null; |
| | | 95 | | |
| | 283 | 96 | | return await MaterializeWorkflowAsync(definition, cancellationToken); |
| | 283 | 97 | | } |
| | | 98 | | |
| | | 99 | | /// <inheritdoc /> |
| | | 100 | | public async Task<IEnumerable<WorkflowGraph>> FindWorkflowGraphsAsync(WorkflowDefinitionFilter filter, CancellationT |
| | | 101 | | { |
| | 0 | 102 | | var workflowDefinitions = await workflowDefinitionStore.FindManyAsync(filter, cancellationToken); |
| | 0 | 103 | | var workflowGraphs = new List<WorkflowGraph>(); |
| | 0 | 104 | | foreach (var workflowDefinition in workflowDefinitions) |
| | | 105 | | { |
| | 0 | 106 | | var workflowGraph = await MaterializeWorkflowAsync(workflowDefinition, cancellationToken); |
| | 0 | 107 | | workflowGraphs.Add(workflowGraph); |
| | | 108 | | } |
| | | 109 | | |
| | 0 | 110 | | return workflowGraphs; |
| | 0 | 111 | | } |
| | | 112 | | } |