| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Workflows.Models; |
| | | 3 | | using Elsa.Workflows.Runtime; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Api.Endpoints.Events.TriggerAuthenticated; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Triggers all workflows that are waiting for the specified event. |
| | | 10 | | /// </summary> |
| | | 11 | | [PublicAPI] |
| | | 12 | | internal class Trigger : ElsaEndpoint<Request> |
| | | 13 | | { |
| | | 14 | | private readonly IEventPublisher _eventPublisher; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | 1 | 17 | | public Trigger(IEventPublisher eventPublisher) |
| | | 18 | | { |
| | 1 | 19 | | _eventPublisher = eventPublisher; |
| | 1 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override void Configure() |
| | | 24 | | { |
| | 1 | 25 | | Post("/events/{eventName}/trigger"); |
| | 1 | 26 | | ConfigurePermissions("trigger:event"); |
| | 1 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 31 | | { |
| | 0 | 32 | | var input = (IDictionary<string, object>?)request.Input; |
| | 0 | 33 | | var eventName = request.EventName; |
| | 0 | 34 | | var correlationId = request.CorrelationId; |
| | 0 | 35 | | var workflowInstanceId = request.WorkflowInstanceId; |
| | 0 | 36 | | var activityInstanceId = request.ActivityInstanceId; |
| | 0 | 37 | | var workflowExecutionMode = request.WorkflowExecutionMode; |
| | | 38 | | |
| | 0 | 39 | | if (workflowExecutionMode == WorkflowExecutionMode.Asynchronous) |
| | | 40 | | { |
| | 0 | 41 | | await _eventPublisher.PublishAsync(eventName, correlationId, workflowInstanceId, activityInstanceId, input, |
| | 0 | 42 | | await Send.OkAsync(cancellationToken); |
| | | 43 | | } |
| | | 44 | | else |
| | | 45 | | { |
| | 0 | 46 | | await _eventPublisher.PublishAsync(eventName, correlationId, workflowInstanceId, activityInstanceId, input, |
| | | 47 | | |
| | 0 | 48 | | if (!HttpContext.Response.HasStarted) |
| | 0 | 49 | | await Send.OkAsync(cancellationToken); |
| | | 50 | | } |
| | 0 | 51 | | } |
| | | 52 | | } |