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);
        }
        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 {
                    CasePlanInstance = casePlanInstance
                };
                foreach (var child in casePlanInstance.Children)
                {
                    await _processorFactory.Execute(executionContext, child, child.GetType(), cancellationToken);
                }

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

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

                if (terminateSub.IsCaptured)
                {
                    casePlanInstance.MakeTransition(CMMNTransitions.Terminate);
                }
            }
        }