| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Notifications; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | using ActivityCompleted = Elsa.Workflows.Signals.ActivityCompleted; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Behaviors; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Implements a behavior that invokes "child completed" callbacks on parent activities. |
| | | 10 | | /// </summary> |
| | | 11 | | [UsedImplicitly] |
| | | 12 | | public class ScheduledChildCallbackBehavior : Behavior |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | 12972 | 15 | | public ScheduledChildCallbackBehavior(IActivity owner) : base(owner) |
| | | 16 | | { |
| | 12972 | 17 | | OnSignalReceived<ActivityCompleted>(OnActivityCompletedAsync); |
| | 12972 | 18 | | } |
| | | 19 | | |
| | | 20 | | private async ValueTask OnActivityCompletedAsync(ActivityCompleted signal, SignalContext context) |
| | | 21 | | { |
| | 12171 | 22 | | var activityExecutionContext = context.ReceiverActivityExecutionContext; |
| | 12171 | 23 | | var childActivityExecutionContext = context.SenderActivityExecutionContext; |
| | 12171 | 24 | | var childActivityNode = childActivityExecutionContext.ActivityNode; |
| | 12171 | 25 | | var callbackEntry = activityExecutionContext.WorkflowExecutionContext.PopCompletionCallback(activityExecutionCon |
| | | 26 | | |
| | 12171 | 27 | | if (callbackEntry?.CompletionCallback != null) |
| | | 28 | | { |
| | 2539 | 29 | | var completedContext = new ActivityCompletedContext(activityExecutionContext, childActivityExecutionContext, |
| | 2539 | 30 | | var tag = callbackEntry.Tag; |
| | 2539 | 31 | | completedContext.TargetContext.Tag = tag; |
| | | 32 | | |
| | 2539 | 33 | | var mediator = activityExecutionContext.GetRequiredService<IMediator>(); |
| | 2539 | 34 | | var invokingActivityCallbackNotification = new Notifications.InvokingActivityCallback(activityExecutionConte |
| | 2539 | 35 | | await mediator.SendAsync(invokingActivityCallbackNotification, context.CancellationToken); |
| | | 36 | | |
| | 2539 | 37 | | await callbackEntry.CompletionCallback(completedContext); |
| | 2539 | 38 | | } |
| | 12171 | 39 | | } |
| | | 40 | | } |