| | | 1 | | using Elsa.Extensions; |
| | | 2 | | using Elsa.Workflows; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Bpmn.Hosting; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Stops a unit of work and everything it in turn started. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// Both places that tear work down go through here: the interpreter's <c>CancelWorkSubtree</c> command, and a scope |
| | | 11 | | /// terminalizing the unit of work whose fault it just claimed. The mechanism is the same in either case. |
| | | 12 | | /// </remarks> |
| | | 13 | | internal static class BpmnWorkTeardown |
| | | 14 | | { |
| | | 15 | | /// <summary>The activity execution with the given id, or <c>null</c> when it has already gone.</summary> |
| | | 16 | | public static ActivityExecutionContext? FindContext(WorkflowExecutionContext workflowExecutionContext, string activi |
| | 43 | 17 | | workflowExecutionContext.ActivityExecutionContexts.FirstOrDefault(x => string.Equals(x.Id, activityExecutionCont |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Tears down a unit of work and everything underneath it. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <remarks> |
| | | 23 | | /// Cancellation itself needs no BPMN-specific code: the public <c>CancelActivityAsync</c> extension walks the |
| | | 24 | | /// child subtree recursively, which is exactly what "and everything it in turn started" means, and it withdraws |
| | | 25 | | /// the scheduled-but-not-yet-invoked work items in that subtree so nothing from the destroyed branch runs |
| | | 26 | | /// afterwards. The only thing this method adds is the reason, recorded on the torn-down activity's journal |
| | | 27 | | /// before it goes, so the workflow's execution log says which BPMN element destroyed the branch and why. |
| | | 28 | | /// </remarks> |
| | | 29 | | public static async ValueTask CancelSubtreeAsync(ActivityExecutionContext childContext, string reason) |
| | | 30 | | { |
| | 17 | 31 | | childContext.AddExecutionLogEntry("Torn down by BPMN", reason); |
| | 17 | 32 | | await childContext.CancelActivityAsync(); |
| | 17 | 33 | | } |
| | | 34 | | } |