Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="processInstanceExecution"></param>
        protected internal virtual void HandleProcessInstanceExecution(IExecutionEntity processInstanceExecution)
        {
            IExecutionEntityManager executionEntityManager = commandContext.ExecutionEntityManager;

            string processInstanceId = processInstanceExecution.Id;

            // No parent execution == process instance id
            logger.LogDebug($"No parent execution found. Verifying if process instance {processInstanceId} can be stopped.");

            IExecutionEntity            superExecution             = processInstanceExecution.SuperExecution;
            ISubProcessActivityBehavior subProcessActivityBehavior = null;

            // copy variables before destroying the ended sub process instance (call activity)
            if (superExecution != null)
            {
                FlowNode superExecutionElement = (FlowNode)superExecution.CurrentFlowElement;
                subProcessActivityBehavior = (ISubProcessActivityBehavior)superExecutionElement.Behavior;
                try
                {
                    subProcessActivityBehavior.Completing(superExecution, processInstanceExecution);
                }
                //catch (Exception e)
                //{
                //    //logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
                //    throw e;
                //}
                catch (Exception e)
                {
                    logger.LogError($"Error while completing sub process of execution {processInstanceExecution}.Exception Message: {e.Message}");
                    throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
                }
            }

            int activeExecutions = GetNumberOfActiveChildExecutionsForProcessInstance(executionEntityManager, processInstanceId, superExecution);

            if (activeExecutions == 0)
            {
                logger.LogDebug($"No active executions found. Ending process instance {processInstanceId} ");

                // note the use of execution here vs processinstance execution for getting the flowelement
                executionEntityManager.DeleteProcessInstanceExecutionEntity(processInstanceId, execution.CurrentFlowElement?.Id, null, false, false);
            }
            else
            {
                logger.LogDebug($"Active executions found. Process instance {processInstanceId} will not be ended.");
            }

            Process process = ProcessDefinitionUtil.GetProcess(processInstanceExecution.ProcessDefinitionId);

            // Execute execution listeners for process end.
            if (CollectionUtil.IsNotEmpty(process.ExecutionListeners))
            {
                ExecuteExecutionListeners(process, processInstanceExecution, BaseExecutionListenerFields.EVENTNAME_END);
            }

            // and trigger execution afterwards if doing a call activity
            if (superExecution != null)
            {
                superExecution.SubProcessInstance = null;
                try
                {
                    subProcessActivityBehavior.Completed(superExecution);
                }
                //catch (Exception e)
                //{
                //    logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
                //    throw e;
                //}
                catch (Exception e)
                {
                    logger.LogError($"Error while completing sub process of execution {processInstanceExecution}. Exception Messgae: {e.Message}.");
                    throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
                }
            }
        }
Пример #2
0
        protected internal override void EventNotificationsCompleted(PvmExecutionImpl execution)
        {
            execution.LeaveActivityInstance();

            PvmExecutionImpl superExecution = (PvmExecutionImpl)execution.SuperExecution;

            ISubProcessActivityBehavior subProcessActivityBehavior = null;

            // copy variables before destroying the ended sub process instance
            if (superExecution != null)
            {
                IPvmActivity activity = superExecution.Activity;
                Log.LogDebug("-----------------ActivityBehavior类型异常", activity.GetType().Name);
                subProcessActivityBehavior = (ISubProcessActivityBehavior)activity.ActivityBehavior;

                try
                {
                    subProcessActivityBehavior.PassOutputVariables(superExecution, execution);
                }
                catch (System.Exception e)
                {
                    Log.ExceptionWhileCompletingSupProcess(execution, e);
                    throw new ProcessEngineException("Error while completing sub process of execution " + execution, e);
                }
            }
            //else if (superCaseExecution != null)
            //{
            //    CmmnActivity activity = superCaseExecution.Activity;
            //    transferVariablesBehavior = (TransferVariablesActivityBehavior)activity.ActivityBehavior;
            //    try
            //    {
            //        transferVariablesBehavior.transferVariables(execution, superCaseExecution);
            //    }
            //    catch (Exception e)
            //    {
            //        LOG.exceptionWhileCompletingSupProcess(execution, e);
            //        throw e;
            //    }
            //    catch (Exception e)
            //    {
            //        LOG.exceptionWhileCompletingSupProcess(execution, e);
            //        throw new ProcessEngineException("Error while completing sub process of execution " + execution, e);
            //    }
            //}

            execution.Destroy();
            execution.Remove();

            // and trigger execution afterwards
            if (superExecution != null)
            {
                superExecution.SubProcessInstance = null;
                try
                {
                    subProcessActivityBehavior.Completed(superExecution);
                }
                catch (System.Exception e)
                {
                    Log.ExceptionWhileCompletingSupProcess(execution, e);
                    throw new ProcessEngineException("Error while completing sub process of execution " + execution, e);
                }
            }
            //else if (superCaseExecution != null)
            //{
            //    superCaseExecution.complete();
            //}
        }