Exemplo n.º 1
0
        public static void CreateCopyOfSubProcessExecutionForCompensation(IExecutionEntity subProcessExecution)
        {
            IEventSubscriptionEntityManager            eventSubscriptionEntityManager = Context.CommandContext.EventSubscriptionEntityManager;
            IList <ICompensateEventSubscriptionEntity> compensateEventSubscriptions   = eventSubscriptionEntityManager.FindCompensateEventSubscriptionsByExecutionId(subProcessExecution.Id);

            if (CollectionUtil.IsNotEmpty(compensateEventSubscriptions))
            {
                IExecutionEntity processInstanceExecutionEntity = subProcessExecution.ProcessInstance;

                IExecutionEntity eventScopeExecution = Context.CommandContext.ExecutionEntityManager.CreateChildExecution(processInstanceExecutionEntity);
                eventScopeExecution.IsActive           = false;
                eventScopeExecution.IsEventScope       = true;
                eventScopeExecution.CurrentFlowElement = subProcessExecution.CurrentFlowElement;

                // copy local variables to eventScopeExecution by value. This way,
                // the eventScopeExecution references a 'snapshot' of the local variables
                (new SubProcessVariableSnapshotter()).SetVariablesSnapshots(subProcessExecution, eventScopeExecution);

                // set event subscriptions to the event scope execution:
                foreach (ICompensateEventSubscriptionEntity eventSubscriptionEntity in compensateEventSubscriptions)
                {
                    eventSubscriptionEntityManager.Delete(eventSubscriptionEntity);

                    ICompensateEventSubscriptionEntity newSubscription = eventSubscriptionEntityManager.InsertCompensationEvent(eventScopeExecution, eventSubscriptionEntity.ActivityId);
                    newSubscription.Configuration = eventSubscriptionEntity.Configuration;
                    newSubscription.Created       = eventSubscriptionEntity.Created;
                }

                ICompensateEventSubscriptionEntity eventSubscription = eventSubscriptionEntityManager.InsertCompensationEvent(processInstanceExecutionEntity, eventScopeExecution.CurrentFlowElement.Id);
                eventSubscription.Configuration = eventScopeExecution.Id;
            }
        }