| | | 1 | | using Elsa.Workflows.Models; |
| | | 2 | | using Elsa.Workflows.Options; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows; |
| | | 5 | | |
| | | 6 | | /// <inheritdoc /> |
| | | 7 | | public class WorkflowExecutionContextSchedulerStrategy : IWorkflowExecutionContextSchedulerStrategy |
| | | 8 | | { |
| | | 9 | | /// <inheritdoc /> |
| | | 10 | | public ActivityWorkItem Schedule(WorkflowExecutionContext context, ActivityNode activityNode, ActivityExecutionConte |
| | | 11 | | { |
| | | 12 | | // Validate that the specified activity is part of the workflow. |
| | 2583 | 13 | | if (!context.NodeActivityLookup.ContainsKey(activityNode.Activity)) |
| | 0 | 14 | | throw new InvalidOperationException("The specified activity is not part of the workflow."); |
| | | 15 | | |
| | 2583 | 16 | | var scheduler = context.Scheduler; |
| | | 17 | | |
| | 2583 | 18 | | if (options?.PreventDuplicateScheduling == true) |
| | | 19 | | { |
| | | 20 | | // Check if the activity is already scheduled for the specified owner. |
| | 0 | 21 | | var existingWorkItem = scheduler.Find(x => x.Activity.NodeId == activityNode.NodeId && x.Owner == owner); |
| | | 22 | | |
| | 0 | 23 | | if (existingWorkItem != null) |
| | 0 | 24 | | return existingWorkItem; |
| | | 25 | | } |
| | | 26 | | |
| | 2583 | 27 | | var activity = activityNode.Activity; |
| | 2583 | 28 | | var tag = options?.Tag; |
| | 2583 | 29 | | var workItem = new ActivityWorkItem(activity, owner, tag, options?.Variables, options?.ExistingActivityExecution |
| | 2583 | 30 | | var completionCallback = options?.CompletionCallback; |
| | | 31 | | |
| | 2583 | 32 | | context.AddCompletionCallback(owner, activityNode, completionCallback, tag); |
| | 2583 | 33 | | scheduler.Schedule(workItem); |
| | | 34 | | |
| | 2583 | 35 | | return workItem; |
| | | 36 | | } |
| | | 37 | | } |