コード例 #1
0
        /// <summary>
        /// 完成条件判断,根据signalData传递的数据判断当前提交人是否同意,如果有一个提交同意,该任务就结束.同时记录流程变量为true.
        /// </summary>
        /// <param name="parent">当前任务节点的运行实例</param>
        /// <param name="multiInstanceActivity">多任务活动行为</param>
        /// <param name="signalData">提交的变量数据</param>
        /// <returns></returns>
        public override bool CompletionConditionSatisfied(IExecutionEntity parent, MultiInstanceActivityBehavior multiInstanceActivity, object signalData)
        {
            //bool pass = base.CompletionConditionSatisfied(parent, multiInstanceActivity, signalData);

            object passed = parent.GetVariable(CompleteConditionVarName, true);

            if (passed is null || (bool.TryParse(passed.ToString(), out var p) && p))
            {
                //return pass;
                return(true);
            }

            var tf = (signalData as Dictionary <string, object>)[CompleteConditionVarName];

            bool.TryParse(tf?.ToString(), out bool approvaled);

            if (approvaled)
            {
                parent.SetVariable(CompleteConditionVarName, true);
            }
            else
            {
                parent.SetVariable(CompleteConditionVarName, false);
            }

            //return pass || approvaled;
            return(approvaled);
        }
コード例 #2
0
        /// <summary>
        /// 完成条件判断,根据signalData传递的数据判断当前提交人是否同意,如果有一个提交人不同意,该任务就结束.
        /// </summary>
        /// <param name="parent">当前任务节点的运行实例</param>
        /// <param name="multiInstanceActivity">多任务活动行为</param>
        /// <param name="signalData">提交的变量数据</param>
        /// <returns></returns>
        public override bool CompletionConditionSatisfied(IExecutionEntity parent, MultiInstanceActivityBehavior multiInstanceActivity, object signalData)
        {
            int  nrOfActiveInstances = multiInstanceActivity.GetLoopVariable(parent, MultiInstanceActivityBehavior.NUMBER_OF_ACTIVE_INSTANCES).GetValueOrDefault(0);
            bool pass = base.CompletionConditionSatisfied(parent, multiInstanceActivity, signalData);

            if (pass)
            {
                parent.SetVariable(CompleteConditionVarName, true);
                return(true);
            }

            var tf = (signalData as IDictionary <string, object>)[CompleteConditionVarName];

            if (bool.TryParse(tf?.ToString(), out bool approvaled))
            {
                if (!approvaled)
                {
                    parent.SetVariable(CompleteConditionVarName, false);
                    return(true);
                }

                parent.SetVariable(CompleteConditionVarName, true);
            }

            return(nrOfActiveInstances == 0);
        }
コード例 #3
0
        protected internal virtual void DefaultTerminateEndEventBehaviour(IExecutionEntity execution, ICommandContext commandContext, IExecutionEntityManager executionEntityManager)
        {
            IExecutionEntity scopeExecutionEntity = executionEntityManager.FindFirstScope(execution);

            SendProcessInstanceCancelledEvent(scopeExecutionEntity, execution.CurrentFlowElement);

            // If the scope is the process instance, we can just terminate it all
            // Special treatment is needed when the terminated activity is a subprocess (embedded/callactivity/..)
            // The subprocess is destroyed, but the execution calling it, continues further on.
            // In case of a multi-instance subprocess, only one instance is terminated, the other instances continue to exist.

            string deleteReason = CreateDeleteReason(execution.CurrentActivityId);

            if (scopeExecutionEntity.ProcessInstanceType && scopeExecutionEntity.SuperExecutionId is null)
            {
                EndAllHistoricActivities(scopeExecutionEntity.Id, deleteReason);
                DeleteExecutionEntities(executionEntityManager, scopeExecutionEntity, deleteReason);
                commandContext.HistoryManager.RecordProcessInstanceEnd(scopeExecutionEntity.Id, deleteReason, execution.CurrentActivityId);
            }
            else if (scopeExecutionEntity.CurrentFlowElement != null && scopeExecutionEntity.CurrentFlowElement is SubProcess)
            { // SubProcess
                SubProcess subProcess = (SubProcess)scopeExecutionEntity.CurrentFlowElement;

                scopeExecutionEntity.DeleteReason = deleteReason;
                if (subProcess.HasMultiInstanceLoopCharacteristics())
                {
                    Context.Agenda.PlanDestroyScopeOperation(scopeExecutionEntity);
                    MultiInstanceActivityBehavior multiInstanceBehavior = (MultiInstanceActivityBehavior)subProcess.Behavior;
                    multiInstanceBehavior.Leave(scopeExecutionEntity);
                }
                else
                {
                    Context.Agenda.PlanDestroyScopeOperation(scopeExecutionEntity);
                    IExecutionEntity outgoingFlowExecution = executionEntityManager.CreateChildExecution(scopeExecutionEntity.Parent);
                    outgoingFlowExecution.CurrentFlowElement = scopeExecutionEntity.CurrentFlowElement;
                    Context.Agenda.PlanTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);
                }
            }
            else if (scopeExecutionEntity.ParentId is null && scopeExecutionEntity.SuperExecutionId is object)
            { // CallActivity
                IExecutionEntity callActivityExecution = scopeExecutionEntity.SuperExecution;
                CallActivity     callActivity          = (CallActivity)callActivityExecution.CurrentFlowElement;

                if (callActivity.HasMultiInstanceLoopCharacteristics())
                {
                    MultiInstanceActivityBehavior multiInstanceBehavior = (MultiInstanceActivityBehavior)callActivity.Behavior;
                    multiInstanceBehavior.Leave(callActivityExecution);
                    executionEntityManager.DeleteProcessInstanceExecutionEntity(scopeExecutionEntity.Id, execution.CurrentFlowElement.Id, "terminate end event", false, false);
                }
                else
                {
                    executionEntityManager.DeleteProcessInstanceExecutionEntity(scopeExecutionEntity.Id, execution.CurrentFlowElement.Id, "terminate end event", false, false);
                    IExecutionEntity superExecutionEntity = executionEntityManager.FindById <IExecutionEntity>(scopeExecutionEntity.SuperExecutionId);
                    Context.Agenda.PlanTakeOutgoingSequenceFlowsOperation(superExecutionEntity, true);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// 完成条件判断,根据signalData传递的数据加上历史数据判断当半数人员同意就流程就结束,同时记录该流程的终值,半数通过记true否则false.
        /// </summary>
        /// <param name="parent">当前任务节点的运行实例</param>
        /// <param name="multiInstanceActivity">多任务活动行为</param>
        /// <param name="signalData">提交的变量数据</param>
        /// <returns></returns>
        public override bool CompletionConditionSatisfied(IExecutionEntity parent, MultiInstanceActivityBehavior multiInstanceActivity, object signalData)
        {
            bool pass = base.CompletionConditionSatisfied(parent, multiInstanceActivity, signalData);

            if (pass)
            {
                parent.SetVariable(CompleteConditionVarName, true);
                return(true);
            }

            var    config = Context.CommandContext.ProcessEngineConfiguration;
            object passed = parent.GetVariable(CompleteConditionVarName, true);

            if (passed is null || (bool.TryParse(passed.ToString(), out var p) && p))
            {
                return(true);
            }

            var tf = (signalData as IDictionary <string, object>)[CompleteConditionVarName];

            bool.TryParse(tf?.ToString(), out bool approvaled);

            int nrOfInstances = multiInstanceActivity.GetLoopVariable(parent, MultiInstanceActivityBehavior.NUMBER_OF_INSTANCES).GetValueOrDefault(0);

            int nrOfActiveInstances = multiInstanceActivity.GetLoopVariable(parent, MultiInstanceActivityBehavior.NUMBER_OF_ACTIVE_INSTANCES).GetValueOrDefault(0);

            int nrOfCompletedInstances = multiInstanceActivity.GetLoopVariable(parent, MultiInstanceActivityBehavior.NUMBER_OF_COMPLETED_INSTANCES).GetValueOrDefault(0);

            var assigneeType = (LeaveExection.CurrentFlowElement as UserTask).AssigneeType;

            bool halfPassed = AssigneeType.HALF_PASSED.Equals(assigneeType?.Value, StringComparison.OrdinalIgnoreCase);

            int votes = config.HistoryService.CreateHistoricVariableInstanceQuery()
                        .SetProcessInstanceId(LeaveExection.ProcessInstanceId)
                        .VariableValueEquals(CompleteConditionVarName, halfPassed)
                        .List()
                        .Where(x => string.IsNullOrWhiteSpace(x.TaskId) == false)
                        .Count();

            if ((votes + (approvaled & halfPassed ? 1 : !approvaled ? 1 : 0)) >= Math.Ceiling(nrOfInstances / 2M))
            {
                parent.SetVariable(CompleteConditionVarName, true);
                return(true);
            }
            else if (votes + nrOfActiveInstances < Math.Ceiling(nrOfInstances / 2M))
            {
                parent.SetVariable(CompleteConditionVarName, false);
                return(true);
            }
            else if (nrOfActiveInstances == 0)
            {
                parent.SetVariable(CompleteConditionVarName, false);
                return(true);
            }

            return(false);
        }
コード例 #5
0
        public virtual bool CompletionConditionSatisfied(IExecutionEntity execution, MultiInstanceActivityBehavior multiInstanceActivity, object signalData)
        {
            if (multiInstanceActivity.CompletionConditionExpression is object)
            {
                object value = multiInstanceActivity.CompletionConditionExpression.GetValue(execution);
                if (!(value is bool booleanValue))
                {
                    throw new ActivitiIllegalArgumentException("completionCondition '" + multiInstanceActivity.CompletionConditionExpression.ExpressionText + "' does not evaluate to a boolean value");
                }

                if (log.IsEnabled(LogLevel.Debug))
                {
                    log.LogDebug($"Completion condition of multi-instance satisfied: {booleanValue}");
                }
                return(booleanValue);
            }

            return(false);
        }
コード例 #6
0
 /// <summary>
 /// 只要有人提交了,该任务就完成.
 /// </summary>
 /// <param name="parent">当前任务节点的运行实例</param>
 /// <param name="multiInstanceActivity">多任务活动行为</param>
 /// <param name="signalData">提交的变量数据</param>
 /// <returns></returns>
 public override bool CompletionConditionSatisfied(IExecutionEntity parent, MultiInstanceActivityBehavior multiInstanceActivity, object signalData)
 {
     return(true);
 }