public async Task Execute(CasePlanInstanceAggregate casePlanInstance, CancellationToken cancellationToken)
        {
            var terminateSub = await _subscriberRepository.TrySubscribe(casePlanInstance.AggregateId, CMMNConstants.ExternalTransitionNames.Terminate, cancellationToken);

            if (casePlanInstance.State == null)
            {
                casePlanInstance.MakeTransition(CMMNTransitions.Create);
            }

            if (casePlanInstance.State == CaseStates.Active)
            {
                var executionContext = new CMMNExecutionContext {
                    Instance = casePlanInstance
                };
                foreach (var fileItem in casePlanInstance.FileItems)
                {
                    await _processorFactory.Execute(executionContext, fileItem, cancellationToken);
                }

                await _processorFactory.Execute(executionContext, casePlanInstance.StageContent, cancellationToken);

                if (casePlanInstance.StageContent.TakeStageState == TaskStageStates.Completed)
                {
                    casePlanInstance.MakeTransition(CMMNTransitions.Complete, false);
                    return;
                }

                if (casePlanInstance.StageContent.TakeStageState == TaskStageStates.Terminated)
                {
                    casePlanInstance.MakeTransition(CMMNTransitions.Terminate, false);
                    return;
                }

                if (terminateSub.IsCaptured)
                {
                    await _subscriberRepository.TryReset(casePlanInstance.AggregateId, null, CMMNConstants.ExternalTransitionNames.Terminate, cancellationToken);

                    casePlanInstance.MakeTransition(CMMNTransitions.Terminate);
                }
            }

            await Publish <CaseInstanceWorkerTaskAddedEvent>(casePlanInstance, cancellationToken);
            await Publish <CaseInstanceWorkerTaskRemovedEvent>(casePlanInstance, cancellationToken);
        }
        private async Task ExecuteNode(CMMNExecutionContext executionContext, CaseEltInstance node, CancellationToken token)
        {
            await _processorFactory.Execute(executionContext, node, token);

            var domainEvts = executionContext.Instance.DomainEvents.Where((evt) =>
            {
                var r = evt as CaseElementTransitionRaisedEvent;
                if (r == null)
                {
                    return(false);
                }

                return(r.ElementId == node.Id);
            }).Cast <CaseElementTransitionRaisedEvent>()
                             .Select(_ => new IncomingTransition(_.Transition, _.IncomingTokens)).ToList();
            var nextNodes = executionContext.Instance.GetNextCasePlanItems(node);

            foreach (var nextNode in nextNodes)
            {
                executionContext.Instance.ConsumeTransitionEvts(nextNode, node.Id, domainEvts);
                await ExecuteNode(executionContext, nextNode, token);
            }
        }