/// <summary> /// Handles emulated <see cref="WorkflowExecuteRequest"/> messages. /// </summary> /// <param name="request">The received message.</param> /// <returns>The tracking <see cref="Task"/>.</returns> private async Task OnEmulatedWorkflowExecuteRequestAsync(WorkflowExecuteRequest request) { var contextId = Interlocked.Increment(ref nextEmulatedContextId); var workflow = new EmulatedWorkflow() { Id = request.Options?.ID ?? Guid.NewGuid().ToString("D"), RunId = Guid.NewGuid().ToString("D"), ContextId = contextId, Args = request.Args, Domain = ResolveDomain(request.Domain), TaskList = ResolveTaskList(request.Options.TaskList), Name = request.Workflow, Options = request.Options, IsGlobal = true }; using (await emulationMutex.AcquireAsync()) { // Add the workflow to the list of pending workflows so that // the emulation thread can pick them up. emulatedPendingWorkflows.Add(workflow); } await EmulatedLibraryClient.SendReplyAsync(request, new WorkflowExecuteReply() { Execution = new InternalWorkflowExecution() { ID = workflow.Id, RunID = workflow.RunId } }); }
/// <summary> /// Cancels a workflow along with and decendant workflows and activities. /// </summary> /// <param name="workflow">The workflow being canceled.</param> /// <returns>The tracking <see cref="Task"/>.</returns> private async Task CancelWorkflowAsync(EmulatedWorkflow workflow) { foreach (var childWorkflow in workflow.ChildWorkflows) { await CancelWorkflowAsync(childWorkflow); } workflow.ChildWorkflows.Clear(); foreach (var childActivity in workflow.ChildActivities) { await CancelActivityAsync(childActivity); } workflow.ChildActivities.Clear(); }