public override void Evaluate(IExecutionEntity execution) { if (!string.IsNullOrWhiteSpace(this.source)) { object value = execution.GetVariable(this.source); MessageInstance message = (MessageInstance)execution.GetVariable(WebServiceActivityBehavior.CURRENT_MESSAGE); if (message.StructureInstance is FieldBaseStructureInstance structure) { structure.SetFieldValue(this.target, value); } } }
public virtual object Execute(ICommandContext commandContext) { if (ReferenceEquals(executionId, null)) { throw new ActivitiIllegalArgumentException("executionId is null"); } if (ReferenceEquals(variableName, null)) { throw new ActivitiIllegalArgumentException("variableName is null"); } IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId); if (execution == null) { throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", typeof(IExecution)); } object value; if (isLocal) { value = execution.GetVariableLocal(variableName, false); } else { value = execution.GetVariable(variableName, false); } return(value); }
/// <summary> /// 侦听接收通知处理 /// </summary> /// <param name="execution"></param> public void Notify(IExecutionEntity execution) { if (execution.CurrentFlowElement is UserTask userTask && userTask.HasMultiInstanceLoopCharacteristics()) { var varName = userTask.LoopCharacteristics.GetCollectionVarName(); if (execution.GetVariable(varName) == null) { List <IUserInfo> users = new List <IUserInfo>(); string getUserPolicy = userTask.GetUsersPolicy(); if (string.IsNullOrWhiteSpace(getUserPolicy) == false) { QueryBookmark[] actors = JsonConvert.DeserializeObject <QueryBookmark[]>(getUserPolicy); IGetBookmarkRuleProvider ruleProvider = ProcessEngineServiceProvider.Resolve <IGetBookmarkRuleProvider>(); foreach (QueryBookmark query in actors) { IGetBookmarkRule rule = ruleProvider.CreateBookmarkRule(query.RuleType.ToString()); rule.Execution = execution; rule.Condition = query; users.AddRange(Context.ProcessEngineConfiguration.CommandExecutor.Execute(rule)); } } //if (users.Count == 0) //{ // throw new NoneCountersignUsersException(execution.CurrentFlowElement.Name); //} execution.SetVariable(varName, users.Count == 0 ? new string[] { "" } : users.Select(x => x.Id).Distinct().ToArray()); } } }
/// <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); }
public void Notify(IExecutionEntity execution) { SubProcess subProcess = GetSubProcessFromExecution(execution); if (subProcess.HasMultiInstanceLoopCharacteristics()) { var varName = subProcess.LoopCharacteristics.GetCollectionVarName(); if (string.IsNullOrWhiteSpace(varName) == false) { IExecutionEntity miRoot = GetMiRootExecution(execution); if (miRoot is null) { return; } string varBusiKey = string.Format(SUBPROCESS_BUSINESS_KEY, execution.Id); if (GetVariable <object>(miRoot, varBusiKey) != null) { return; } int nrOfExecInstances = GetVariable <int?>(execution, NUMBER_OF_EXECUTION_INSTANCES).GetValueOrDefault(0); miRoot.SetVariableLocal(NUMBER_OF_EXECUTION_INSTANCES, nrOfExecInstances + 1); string[] ids = JsonConvert.DeserializeObject <string[]>(execution.GetVariable(varName).ToString()); execution.BusinessKey = ids[nrOfExecInstances]; miRoot.SetVariableLocal(varBusiKey, execution.BusinessKey); } } }
/// <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); }
public override void Evaluate(IExecutionEntity execution) { MessageInstance message = (MessageInstance)execution.GetVariable(WebServiceActivityBehavior.CURRENT_MESSAGE); if (message.StructureInstance is FieldBaseStructureInstance) { FieldBaseStructureInstance structure = (FieldBaseStructureInstance)message.StructureInstance; execution.SetVariable(this.Target, structure.GetFieldValue(this.Source)); } }
protected internal virtual object ResolveCollection(IExecutionEntity execution) { if (collectionExpression != null) { return(collectionExpression.GetValue(execution)); } else if (collectionVariable is object) { return(execution.GetVariable(collectionVariable)); } return(null); }
/// <summary> /// 侦听接收通知处理 /// </summary> /// <param name="execution"></param> public void Notify(IExecutionEntity execution) { if (execution.CurrentFlowElement is UserTask userTask && userTask.HasMultiInstanceLoopCharacteristics()) { var varName = userTask.LoopCharacteristics.GetCollectionVarName(); if (execution.GetVariable(varName) == null) { List <IUserInfo> users = new List <IUserInfo>(); string getUserPolicy = userTask.GetUsersPolicy(); if (string.IsNullOrWhiteSpace(getUserPolicy) == false) { if (EXPR_PATTERN.IsMatch(getUserPolicy)) { getUserPolicy = EXPR_PATTERN.Replace(getUserPolicy, (m) => { var value = m.Groups[1].Value; var variables = execution.Variables; object roles = ExpressionManager.GetValue(variables, value, variables); return(roles.ToString()); }); } QueryBookmark[] actors = JsonConvert.DeserializeObject <QueryBookmark[]>(getUserPolicy); IGetBookmarkRuleProvider ruleProvider = ProcessEngineServiceProvider.Resolve <IGetBookmarkRuleProvider>(); foreach (QueryBookmark query in actors) { IGetBookmarkRule rule = ruleProvider.CreateBookmarkRule(query.RuleType.ToString()); rule.Execution = execution; rule.Condition = query; var us = Context.ProcessEngineConfiguration.CommandExecutor.Execute(rule); users.AddRange(us); } } if (users.Count == 0) { users.Add(Authentication.AuthenticatedUser); logger.LogWarning($"调用查询人员服务失败,分组没有人,重新指到当前提交人,Duty={getUserPolicy}"); //throw new NoneCountersignUsersException(execution.CurrentFlowElement.Name); } execution.SetVariable(varName, users.Count == 0 ? new string[] { "" } : users.Select(x => x.Id).Distinct().ToArray()); } } }
private static bool CheckSkipExpressionVariable(IExecutionEntity execution) { const string skipExpressionEnabledVariable = "_ACTIVITI_SKIP_EXPRESSION_ENABLED"; object isSkipExpressionEnabled = execution.GetVariable(skipExpressionEnabledVariable); if (isSkipExpressionEnabled == null) { return(false); } else if (isSkipExpressionEnabled is bool?) { return(((bool?)isSkipExpressionEnabled).Value); } else { throw new ActivitiIllegalArgumentException(skipExpressionEnabledVariable + " variable does not resolve to a boolean. " + isSkipExpressionEnabled); } }
public void Notify(IExecutionEntity execution) { IExecutionEntity miRoot = execution.Parent; if (miRoot.IsMultiInstanceRoot && execution.CurrentFlowElement is CallActivity callActivity) { int nrOfExecInstances = ((int?)miRoot.GetVariableLocal(NUMBER_OF_EXECUTION_INSTANCES)).GetValueOrDefault(0); miRoot.SetVariableLocal(NUMBER_OF_EXECUTION_INSTANCES, nrOfExecInstances + 1); string collectionVarName = callActivity.LoopCharacteristics.GetCollectionVarName(); string[] businessKeys = miRoot.GetVariable <JArray>(collectionVarName).ToObject <string[]>(); execution.BusinessKey = businessKeys[nrOfExecInstances]; } }
public virtual void Completing(IExecutionEntity execution, IExecutionEntity subProcessInstance) { // only data. no control flow available on this execution. ExpressionManager expressionManager = Context.ProcessEngineConfiguration.ExpressionManager; // copy process variables CallActivity callActivity = (CallActivity)execution.CurrentFlowElement; foreach (IOParameter ioParameter in callActivity.OutParameters) { object value = null; if (!string.IsNullOrWhiteSpace(ioParameter.SourceExpression)) { IExpression expression = expressionManager.CreateExpression(ioParameter.SourceExpression.Trim()); value = expression.GetValue(subProcessInstance); } else { value = subProcessInstance.GetVariable(ioParameter.Source); } execution.SetVariable(ioParameter.Target, value); } }
public override void Execute(IExecutionEntity execution) { BpmnModel bpmnModel = ProcessDefinitionUtil.GetBpmnModel(execution.ProcessDefinitionId); FlowElement flowElement = execution.CurrentFlowElement; IOSpecification ioSpecification; string operationRef; IList <DataAssociation> dataInputAssociations; IList <DataAssociation> dataOutputAssociations; if (flowElement is SendTask sendTask) { ioSpecification = sendTask.IoSpecification; operationRef = sendTask.OperationRef; dataInputAssociations = sendTask.DataInputAssociations; dataOutputAssociations = sendTask.DataOutputAssociations; } else if (flowElement is ServiceTask serviceTask) { ioSpecification = serviceTask.IoSpecification; operationRef = serviceTask.OperationRef; dataInputAssociations = serviceTask.DataInputAssociations; dataOutputAssociations = serviceTask.DataOutputAssociations; } else { throw new ActivitiException("Unsupported flow element type " + flowElement); } MessageInstance message = null; FillDefinitionMaps(bpmnModel); Webservice.Operation operation = operationMap[operationRef]; try { if (ioSpecification != null) { InitializeIoSpecification(ioSpecification, execution, bpmnModel); if (ioSpecification.DataInputRefs.Count > 0) { string firstDataInputName = ioSpecification.DataInputRefs[0]; ItemInstance inputItem = (ItemInstance)execution.GetVariable(firstDataInputName); message = new MessageInstance(operation.InMessage, inputItem); } } else { message = operation.InMessage.CreateInstance(); } execution.SetVariable(CURRENT_MESSAGE, message); FillMessage(dataInputAssociations, execution); ProcessEngineConfigurationImpl processEngineConfig = Context.ProcessEngineConfiguration; MessageInstance receivedMessage = operation.SendMessage(message, processEngineConfig.WsOverridenEndpointAddresses); execution.SetVariable(CURRENT_MESSAGE, receivedMessage); if (ioSpecification != null && ioSpecification.DataOutputRefs.Count > 0) { string firstDataOutputName = ioSpecification.DataOutputRefs[0]; if (!(firstDataOutputName is null)) { ItemInstance outputItem = (ItemInstance)execution.GetVariable(firstDataOutputName); outputItem.StructureInstance.LoadFrom(receivedMessage.StructureInstance.ToArray()); } } ReturnMessage(dataOutputAssociations, execution); execution.SetVariable(CURRENT_MESSAGE, null); Leave(execution); } catch (Exception exc) { Exception cause = exc; BpmnError error = null; while (cause != null) { if (cause is BpmnError) { error = (BpmnError)cause; break; } cause = cause.InnerException; } if (error != null) { ErrorPropagation.PropagateError(error, execution); } else if (exc is Exception) { throw (Exception)exc; } } }
public override void Execute(IExecutionEntity execution) { string finalProcessDefinitonKey; if (processDefinitionExpression != null) { finalProcessDefinitonKey = (string)processDefinitionExpression.GetValue(execution); } else { finalProcessDefinitonKey = processDefinitonKey; } IProcessDefinition processDefinition = FindProcessDefinition(finalProcessDefinitonKey, execution.TenantId); // Get model from cache Process subProcess = ProcessDefinitionUtil.GetProcess(processDefinition.Id); if (subProcess == null) { throw new ActivitiException("Cannot start a sub process instance. Process model " + processDefinition.Name + " (id = " + processDefinition.Id + ") could not be found"); } FlowElement initialFlowElement = subProcess.InitialFlowElement; if (initialFlowElement == null) { throw new ActivitiException("No start element found for process definition " + processDefinition.Id); } // Do not start a process instance if the process definition is suspended if (ProcessDefinitionUtil.IsProcessDefinitionSuspended(processDefinition.Id)) { throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.Name + " (id = " + processDefinition.Id + ") is suspended"); } ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration; IExecutionEntityManager executionEntityManager = Context.CommandContext.ExecutionEntityManager; ExpressionManager expressionManager = processEngineConfiguration.ExpressionManager; CallActivity callActivity = (CallActivity)execution.CurrentFlowElement; string businessKey = null; if (!string.IsNullOrWhiteSpace(callActivity.BusinessKey)) { IExpression expression = expressionManager.CreateExpression(callActivity.BusinessKey); businessKey = expression.GetValue(execution).ToString(); } else if (callActivity.InheritBusinessKey) { IExecutionEntity processInstance = executionEntityManager.FindById <IExecutionEntity>(execution.ProcessInstanceId); businessKey = processInstance.BusinessKey; } IExecutionEntity subProcessInstance = Context.CommandContext.ExecutionEntityManager.CreateSubprocessInstance(processDefinition, execution, businessKey); Context.CommandContext.HistoryManager.RecordSubProcessInstanceStart(execution, subProcessInstance, initialFlowElement); // process template-defined data objects IDictionary <string, object> variables = ProcessDataObjects(subProcess.DataObjects); if (callActivity.InheritVariables) { IDictionary <string, object> executionVariables = execution.Variables; foreach (KeyValuePair <string, object> entry in executionVariables.SetOfKeyValuePairs()) { variables[entry.Key] = entry.Value; } } // copy process variables foreach (IOParameter ioParameter in callActivity.InParameters) { object value = null; if (!string.IsNullOrWhiteSpace(ioParameter.SourceExpression)) { IExpression expression = expressionManager.CreateExpression(ioParameter.SourceExpression.Trim()); value = expression.GetValue(execution); } else { value = execution.GetVariable(ioParameter.Source); } variables[ioParameter.Target] = value; } if (variables.Count > 0) { InitializeVariables(subProcessInstance, variables); } // Create the first execution that will visit all the process definition elements IExecutionEntity subProcessInitialExecution = executionEntityManager.CreateChildExecution(subProcessInstance); subProcessInitialExecution.CurrentFlowElement = initialFlowElement; Context.Agenda.PlanContinueProcessOperation(subProcessInitialExecution); Context.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateProcessStartedEvent(subProcessInitialExecution, variables, false)); }