| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Models; |
| | | 3 | | using Elsa.Workflows.Management; |
| | | 4 | | using Elsa.Workflows.Runtime; |
| | | 5 | | using Elsa.Workflows.Runtime.Contracts; |
| | | 6 | | using Elsa.Workflows.Runtime.Requests; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.BulkDispatch; |
| | | 10 | | |
| | | 11 | | [PublicAPI] |
| | 1 | 12 | | internal class Endpoint(IWorkflowDefinitionService workflowDefinitionService, IWorkflowDispatcher workflowDispatcher, II |
| | | 13 | | : ElsaEndpoint<Request, Response> |
| | | 14 | | { |
| | | 15 | | public override void Configure() |
| | | 16 | | { |
| | 1 | 17 | | Post("/workflow-definitions/{definitionId}/bulk-dispatch"); |
| | 1 | 18 | | ConfigurePermissions("exec:workflow-definitions"); |
| | 1 | 19 | | } |
| | | 20 | | |
| | | 21 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 22 | | { |
| | 0 | 23 | | var definitionId = request.DefinitionId; |
| | 0 | 24 | | var versionOptions = request.VersionOptions ?? VersionOptions.Published; |
| | 0 | 25 | | var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(definitionId, versionOptions, cancell |
| | | 26 | | |
| | 0 | 27 | | if (workflowGraph == null) |
| | | 28 | | { |
| | 0 | 29 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 30 | | return; |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | var instanceIds = new List<string>(); |
| | | 34 | | |
| | 0 | 35 | | for (var i = 0; i < request.Count; i++) |
| | | 36 | | { |
| | 0 | 37 | | var instanceId = identityGenerator.GenerateId(); |
| | 0 | 38 | | var triggerActivityId = request.TriggerActivityId; |
| | 0 | 39 | | var input = (IDictionary<string, object>?)request.Input; |
| | 0 | 40 | | var dispatchRequest = new DispatchWorkflowDefinitionRequest(workflowGraph.Workflow.Identity.Id) |
| | 0 | 41 | | { |
| | 0 | 42 | | Input = input, |
| | 0 | 43 | | InstanceId = instanceId, |
| | 0 | 44 | | TriggerActivityId = triggerActivityId |
| | 0 | 45 | | }; |
| | | 46 | | |
| | 0 | 47 | | await workflowDispatcher.DispatchAsync(dispatchRequest, cancellationToken: cancellationToken); |
| | 0 | 48 | | instanceIds.Add(instanceId); |
| | 0 | 49 | | } |
| | | 50 | | |
| | 0 | 51 | | await Send.OkAsync(new Response(instanceIds), cancellationToken); |
| | 0 | 52 | | } |
| | | 53 | | } |