| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Models; |
| | | 3 | | using Elsa.Workflows.Pipelines.WorkflowExecution; |
| | | 4 | | using Elsa.Workflows.Runtime.Middleware.Workflows; |
| | | 5 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 6 | | using Elsa.Workflows.State; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Runtime; |
| | | 9 | | |
| | | 10 | | /// <inheritdoc /> |
| | 141 | 11 | | public class WorkflowCanceler( |
| | 141 | 12 | | IWorkflowExecutionPipeline workflowExecutionPipeline, |
| | 141 | 13 | | IWorkflowStateExtractor workflowStateExtractor, |
| | 141 | 14 | | IMediator mediator, |
| | 141 | 15 | | IServiceProvider serviceProvider) : IWorkflowCanceler |
| | | 16 | | { |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public async Task<WorkflowState> CancelWorkflowAsync(WorkflowGraph workflowGraph, WorkflowState workflowState, Cance |
| | | 19 | | { |
| | 5 | 20 | | var workflowExecutionContext = await WorkflowExecutionContext.CreateAsync(serviceProvider, workflowGraph, workfl |
| | 5 | 21 | | await CancelWorkflowAsync(workflowExecutionContext, cancellationToken); |
| | 5 | 22 | | return workflowStateExtractor.Extract(workflowExecutionContext); |
| | 5 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public async Task CancelWorkflowAsync(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellat |
| | | 27 | | { |
| | 5 | 28 | | await mediator.SendAsync(new WorkflowCancelling(workflowExecutionContext.Id), cancellationToken); |
| | 5 | 29 | | var pipelineBuilder = new WorkflowExecutionPipelineBuilder(serviceProvider); |
| | 5 | 30 | | workflowExecutionPipeline.ConfigurePipelineBuilder(pipelineBuilder); |
| | 5 | 31 | | pipelineBuilder.ReplaceTerminal<CancelWorkflowMiddleware>(); |
| | 5 | 32 | | var pipeline = pipelineBuilder.Build(); |
| | 5 | 33 | | await pipeline(workflowExecutionContext); |
| | 5 | 34 | | await mediator.SendAsync(new WorkflowCancelled(workflowExecutionContext.Id), cancellationToken); |
| | 5 | 35 | | } |
| | | 36 | | } |