| | | 1 | | using Elsa.Workflows.Management; |
| | | 2 | | using Elsa.Workflows.Management.Filters; |
| | | 3 | | using Elsa.Workflows.Models; |
| | | 4 | | using Elsa.Workflows.Runtime; |
| | | 5 | | using Elsa.Workflows.Runtime.Entities; |
| | | 6 | | using Elsa.Workflows.Runtime.Filters; |
| | | 7 | | using Open.Linq.AsyncExtensions; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Http.Services; |
| | | 10 | | |
| | | 11 | | /// <inheritdoc /> |
| | 215 | 12 | | public class HttpWorkflowLookupService(ITriggerStore triggerStore, IWorkflowDefinitionService workflowDefinitionService) |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async Task<HttpWorkflowLookupResult?> FindWorkflowAsync(string bookmarkHash, CancellationToken cancellationTo |
| | | 16 | | { |
| | 209 | 17 | | var triggers = await FindTriggersAsync(bookmarkHash, cancellationToken).ToList(); |
| | | 18 | | |
| | 209 | 19 | | if (triggers.Count > 1) |
| | 0 | 20 | | return new(null, triggers); |
| | | 21 | | |
| | 209 | 22 | | var trigger = triggers.SingleOrDefault(); |
| | | 23 | | |
| | 209 | 24 | | if (trigger == null) |
| | 2 | 25 | | return default; |
| | | 26 | | |
| | 207 | 27 | | var workflowGraph = await FindWorkflowGraphAsync(trigger, cancellationToken); |
| | | 28 | | |
| | 207 | 29 | | if (workflowGraph == null) |
| | 0 | 30 | | return default; |
| | | 31 | | |
| | 207 | 32 | | return new(workflowGraph, triggers); |
| | 209 | 33 | | } |
| | | 34 | | |
| | | 35 | | private async Task<IEnumerable<StoredTrigger>> FindTriggersAsync(string bookmarkHash, CancellationToken cancellation |
| | | 36 | | { |
| | 209 | 37 | | var triggerFilter = new TriggerFilter |
| | 209 | 38 | | { |
| | 209 | 39 | | Hash = bookmarkHash |
| | 209 | 40 | | }; |
| | 209 | 41 | | return await triggerStore.FindManyAsync(triggerFilter, cancellationToken); |
| | 209 | 42 | | } |
| | | 43 | | |
| | | 44 | | private async Task<WorkflowGraph?> FindWorkflowGraphAsync(StoredTrigger trigger, CancellationToken cancellationToken |
| | | 45 | | { |
| | 207 | 46 | | var workflowDefinitionVersionId = trigger.WorkflowDefinitionVersionId; |
| | 207 | 47 | | var filter = new WorkflowDefinitionFilter |
| | 207 | 48 | | { |
| | 207 | 49 | | Id = workflowDefinitionVersionId |
| | 207 | 50 | | }; |
| | 207 | 51 | | return await workflowDefinitionService.FindWorkflowGraphAsync(filter, cancellationToken); |
| | 207 | 52 | | } |
| | | 53 | | } |