/// <summary> /// /// </summary> /// <param name="flowNode"></param> protected internal virtual void HandleAdhocSubProcess(FlowNode flowNode) { bool completeAdhocSubProcess = false; AdhocSubProcess adhocSubProcess = (AdhocSubProcess)flowNode.ParentContainer; if (adhocSubProcess.CompletionCondition is object) { IExpression expr = Context.ProcessEngineConfiguration.ExpressionManager.CreateExpression(adhocSubProcess.CompletionCondition); bool adHoc = (bool)expr.GetValue(execution); if (adHoc) { completeAdhocSubProcess = true; } //ICondition condition = new UelExpressionCondition(expression); //if (condition.evaluate(adhocSubProcess.Id, execution)) //{ // completeAdhocSubProcess = true; //} } if (flowNode.OutgoingFlows.Count > 0) { LeaveFlowNode(flowNode); } else { commandContext.ExecutionEntityManager.DeleteExecutionAndRelatedData(execution, null, false); } if (completeAdhocSubProcess) { bool endAdhocSubProcess = true; if (!adhocSubProcess.CancelRemainingInstances) { IList <IExecutionEntity> childExecutions = commandContext.ExecutionEntityManager.FindChildExecutionsByParentExecutionId(execution.ParentId); foreach (IExecutionEntity executionEntity in childExecutions) { if (!executionEntity.Id.Equals(execution.Id)) { endAdhocSubProcess = false; break; } } } if (endAdhocSubProcess) { Context.Agenda.PlanEndExecutionOperation(execution.Parent); } } }
public virtual IExecution Execute(ICommandContext commandContext) { IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId); if (execution == null) { throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", typeof(IExecutionEntity)); } if (!(execution.CurrentFlowElement is AdhocSubProcess)) { throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process"); } FlowNode foundNode = null; AdhocSubProcess adhocSubProcess = (AdhocSubProcess)execution.CurrentFlowElement; // if sequential ordering, only one child execution can be active if (adhocSubProcess.HasSequentialOrdering()) { if (execution.Executions.Count > 0) { throw new ActivitiException("Sequential ad-hoc sub process already has an active execution"); } } foreach (FlowElement flowElement in adhocSubProcess.FlowElements) { if (activityId.Equals(flowElement.Id) && flowElement is FlowNode) { FlowNode flowNode = (FlowNode)flowElement; if (flowNode.IncomingFlows.Count == 0) { foundNode = flowNode; } } } IExecutionEntity activityExecution = Context.CommandContext.ExecutionEntityManager.CreateChildExecution(execution); activityExecution.CurrentFlowElement = foundNode ?? throw new ActivitiException("The requested activity with id " + activityId + " can not be enabled"); Context.Agenda.PlanContinueProcessOperation(activityExecution); return(activityExecution); }
public virtual IList <FlowNode> Execute(ICommandContext commandContext) { IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId); if (execution == null) { throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", typeof(IExecutionEntity)); } if (!(execution.CurrentFlowElement is AdhocSubProcess)) { throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process"); } IList <FlowNode> enabledFlowNodes = new List <FlowNode>(); AdhocSubProcess adhocSubProcess = (AdhocSubProcess)execution.CurrentFlowElement; // if sequential ordering, only one child execution can be active, so no enabled activities if (adhocSubProcess.HasSequentialOrdering()) { if (execution.Executions.Count > 0) { return(enabledFlowNodes); } } foreach (FlowElement flowElement in adhocSubProcess.FlowElements) { if (flowElement is FlowNode flowNode) { if (flowNode.IncomingFlows.Count == 0) { enabledFlowNodes.Add(flowNode); } } } return(enabledFlowNodes); }
public virtual void Parse(XMLStreamReader xtr, IList <SubProcess> activeSubProcessList, Process activeProcess) { SubProcess subProcess; if (BpmnXMLConstants.ELEMENT_TRANSACTION.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase)) { subProcess = new Transaction(); } else if (BpmnXMLConstants.ELEMENT_ADHOC_SUBPROCESS.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase)) { AdhocSubProcess adhocSubProcess = new AdhocSubProcess(); string orderingAttributeValue = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ORDERING); if (!string.IsNullOrWhiteSpace(orderingAttributeValue)) { adhocSubProcess.Ordering = orderingAttributeValue; } if (BpmnXMLConstants.ATTRIBUTE_VALUE_FALSE.Equals(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_CANCEL_REMAINING_INSTANCES), StringComparison.CurrentCultureIgnoreCase)) { adhocSubProcess.CancelRemainingInstances = false; } subProcess = adhocSubProcess; } else if (BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE.Equals(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_TRIGGERED_BY), StringComparison.CurrentCultureIgnoreCase)) { subProcess = new EventSubProcess(); } else { subProcess = new SubProcess(); } BpmnXMLUtil.AddXMLLocation(subProcess, xtr); activeSubProcessList.Add(subProcess); subProcess.Id = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ID); subProcess.Name = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_NAME); bool async = false; string asyncString = xtr.GetAttributeValue(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_ACTIVITY_ASYNCHRONOUS); if (BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE.Equals(asyncString, StringComparison.CurrentCultureIgnoreCase)) { async = true; } bool notExclusive = false; string exclusiveString = xtr.GetAttributeValue(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_ACTIVITY_EXCLUSIVE); if (BpmnXMLConstants.ATTRIBUTE_VALUE_FALSE.Equals(exclusiveString, StringComparison.CurrentCultureIgnoreCase)) { notExclusive = true; } bool forCompensation = false; string compensationString = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION); if (BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE.Equals(compensationString, StringComparison.CurrentCultureIgnoreCase)) { forCompensation = true; } subProcess.Asynchronous = async; subProcess.NotExclusive = notExclusive; subProcess.ForCompensation = forCompensation; if (!string.IsNullOrWhiteSpace(xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_DEFAULT))) { subProcess.DefaultFlow = xtr.GetAttributeValue(BpmnXMLConstants.ATTRIBUTE_DEFAULT); } if (activeSubProcessList.Count > 1) { SubProcess parentSubProcess = activeSubProcessList[activeSubProcessList.Count - 2]; parentSubProcess.AddFlowElement(subProcess); } else { activeProcess.AddFlowElement(subProcess); } }