コード例 #1
0
        private async Task PulseToParentWorkflow(WorkflowContext workflowContext, WorkflowHierarchyEventType hierarchyEventType, string code, CancellationToken cancellationToken = default)
        {
            Guard.ArgumentNotNullOrEmpty(code, nameof(code));
            if (workflowContext.WorkflowInstance.Id == workflowContext.WorkflowInstance.ParentWorkflowInstanceId)
            {
                return;
            }

            var parentWorkflowInstance = await GetWorkflowInstanceWithNoLock(workflowContext.WorkflowInstance.ParentWorkflowInstanceId, cancellationToken).ConfigureAwait(false);

            Guard.ArgumentNotNull(parentWorkflowInstance, nameof(parentWorkflowInstance));

            // [Assumption #1] Failed event should be propagated with no additional checks for validity
            if (hierarchyEventType == WorkflowHierarchyEventType.Failed)
            {
                var parentToNestedFailedEvent = new NestedToParentEvent(code, hierarchyEventType, parentWorkflowInstance.ParentWorkflowInstanceId, workflowContext.WorkflowInstance.Id);
                await((IWorkflowEngine)this).ProcessEvent(parentWorkflowInstance.WorkflowId, parentToNestedFailedEvent, cancellationToken);
                return;
            }

            // [Assumption #2] Parent workflow instance must be in [AwaitingEvent] state for application scope events to pass through
            if (parentWorkflowInstance.CurrentStateProgress != StateExecutionProgress.AwaitingEvent)
            {
                throw new WorkflowException(string.Format(CultureInfo.InvariantCulture,
                                                          "Parent Workflow instance [ID={0:D}] must be waiting for an event from nested workflow instance [ID={1:D}], but it is in [State={2}..{3:G}]",
                                                          parentWorkflowInstance.Id, workflowContext.WorkflowInstance.Id, parentWorkflowInstance.CurrentStateCode,
                                                          parentWorkflowInstance.CurrentStateProgress));
            }

            var nestedToParentEvent = new NestedToParentEvent(code, hierarchyEventType, parentWorkflowInstance.ParentWorkflowInstanceId, workflowContext.WorkflowInstance.Id);

            await((IWorkflowEngine)this).ProcessEvent(parentWorkflowInstance.WorkflowId, nestedToParentEvent, cancellationToken).ConfigureAwait(false);
        }
コード例 #2
0
        public NestedToParentEvent(string code, WorkflowHierarchyEventType hierarchyEventType, Guid workflowInstanceId, Guid nestedWorkflowInstanceId)
        {
            Guard.ArgumentNotNull(code, nameof(code));

            Code = code;
            HierarchyEventType       = hierarchyEventType;
            WorkflowInstanceId       = workflowInstanceId;
            NestedWorkflowInstanceId = nestedWorkflowInstanceId;
        }
コード例 #3
0
        public ParentToNestedEntityEvent(string code, WorkflowHierarchyEventType hierarchyEventType,
                                         Guid rootWorkflowInstanceId, Guid parentWorkflowInstanceId, Guid workflowInstanceId, IEntity nestedEntity)
        {
            Guard.ArgumentNotNull(code, nameof(code));

            Code                     = code;
            Entity                   = nestedEntity;
            HierarchyEventType       = hierarchyEventType;
            ParentWorkflowInstanceId = parentWorkflowInstanceId;
            RootWorkflowInstanceId   = rootWorkflowInstanceId;
            WorkflowInstanceId       = workflowInstanceId;
        }