public override void Execute(IExecutionEntity execution) { if (!GetLocalLoopVariable(execution, CollectionElementIndexVariable).HasValue) { int nrOfInstances = 0; try { nrOfInstances = CreateInstances(execution); } catch (BpmnError error) { ErrorPropagation.PropagateError(error, execution); } if (nrOfInstances == 0) { base.Leave(execution); } } else { Context.CommandContext.HistoryManager.RecordActivityStart(execution); innerActivityBehavior.Execute(execution); } }
public override void Execute(IExecutionEntity execution) { try { bool isSkipExpressionEnabled = SkipExpressionUtil.IsSkipExpressionEnabled(execution, skipExpression); if (!isSkipExpressionEnabled || (isSkipExpressionEnabled && !SkipExpressionUtil.ShouldSkipFlowElement(execution, skipExpression))) { if (Context.ProcessEngineConfiguration.EnableProcessDefinitionInfoCache) { JToken taskElementProperties = Context.GetBpmnOverrideElementProperties(serviceTaskId, execution.ProcessDefinitionId); if (taskElementProperties != null && taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_EXPRESSION] != null) { string overrideExpression = taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_EXPRESSION].ToString(); if (!string.IsNullOrWhiteSpace(overrideExpression) && !overrideExpression.Equals(expression.ExpressionText)) { expression = Context.ProcessEngineConfiguration.ExpressionManager.CreateExpression(overrideExpression); } } } object value = expression.GetValue(execution); if (!(resultVariable is null)) { execution.SetVariable(resultVariable, value); } } 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 { throw new ActivitiException("Could not execute service task expression", exc); } } }
public override void Execute(IExecutionEntity execution) { ScriptingEngines scriptingEngines = Context.ProcessEngineConfiguration.ScriptingEngines; if (Context.ProcessEngineConfiguration.EnableProcessDefinitionInfoCache) { JToken taskElementProperties = Context.GetBpmnOverrideElementProperties(scriptTaskId, execution.ProcessDefinitionId); if (taskElementProperties != null && taskElementProperties[DynamicBpmnConstants.SCRIPT_TASK_SCRIPT] != null) { string overrideScript = taskElementProperties[DynamicBpmnConstants.SCRIPT_TASK_SCRIPT].ToString(); if (!string.IsNullOrWhiteSpace(overrideScript) && !overrideScript.Equals(script)) { script = overrideScript; } } } bool noErrors = true; try { object result = scriptingEngines.Evaluate(script, execution); if (!(resultVariable is null)) { execution.SetVariable(resultVariable, result); } } catch (ActivitiException e) { logger.LogWarning("Exception while executing " + execution.CurrentFlowElement.Id + " : " + e.Message); noErrors = false; if (e is BpmnError) { ErrorPropagation.PropagateError((BpmnError)e, execution); } else { throw e; } } if (noErrors) { Leave(execution); } }
/// <summary> /// /// </summary> /// <param name="flowNode"></param> protected internal virtual void ExecuteSynchronous(FlowNode flowNode) { // Execution listener if (CollectionUtil.IsNotEmpty(flowNode.ExecutionListeners)) { ExecuteExecutionListeners(flowNode, BaseExecutionListenerFields.EVENTNAME_START); } commandContext.HistoryManager.RecordActivityStart(execution); // Execute actual behavior IActivityBehavior activityBehavior = (IActivityBehavior)flowNode.Behavior; if (activityBehavior != null) { logger.LogDebug($"Executing activityBehavior {activityBehavior.GetType()} on activity '{flowNode.Id}' with execution {execution.Id}"); ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration; if (processEngineConfiguration != null && processEngineConfiguration.EventDispatcher.Enabled) { processEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.Id, flowNode.Name, execution.Id, execution.ProcessInstanceId, execution.ProcessDefinitionId, flowNode)); } try { activityBehavior.Execute(execution); } catch (BpmnError error) { // re-throw business fault so that it can be caught by an Error Intermediate Event or Error Event Sub-Process in the process ErrorPropagation.PropagateError(error, execution); } catch (Exception e) { if (LogMDC.MDCEnabled) { LogMDC.PutMDCExecution(execution); } throw e; } } else { logger.LogDebug($"No activityBehavior on activity '{flowNode.Id}' with execution {execution.Id}"); } }
private void ExecuteDebugMode(IExecutionEntity execution) { execution.CurrentFlowElement.ExtensionElements.TryGetValue(BpmnXMLConstants.ELEMENT_EXTENSIONS_PROPERTY, out IList <ExtensionElement> pElements); if (pElements != null) { var parameter = new WebApiParameter(execution, pElements); string dataObj = parameter.VariableName; if (!string.IsNullOrEmpty(dataObj)) { try { execution.SetVariable(dataObj, parameter.MockData); } catch (Exception ex) { logger.LogError($"调用服务失败MockData=${dataObj}\r\n${ex.Message}${ex.StackTrace}"); string errorCode = execution.CurrentFlowElement.GetExtensionElementAttributeValue("errorCode"); BpmnError error; if (string.IsNullOrWhiteSpace(errorCode) == false) { error = new BpmnError(errorCode, ex.Message); } else { error = new BpmnError(Context.CommandContext.ProcessEngineConfiguration.WebApiErrorCode, ex.Message); } ErrorPropagation.PropagateError(error, execution); } } } }
public override void Execute(IExecutionEntity execution) { ErrorPropagation.PropagateError(errorCode, execution); }
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; } } }
/// <summary> /// /// </summary> /// <param name="execution"></param> public override void Execute(IExecutionEntity execution) { execution.CurrentFlowElement.ExtensionElements.TryGetValue(BpmnXMLConstants.ELEMENT_EXTENSIONS_PROPERTY, out IList <ExtensionElement> pElements); _ = bool.TryParse(execution.GetVariableInstance(DynamicBpmnConstants.PORCESS_DEBUGMODE_VARIABLE)?.Value?.ToString(), out var debugMode); WebApiParameter parameter = new WebApiParameter(execution, pElements); if (parameter.IsMock.HasValue ? parameter.IsMock.Value : debugMode) { ExecuteDebugMode(execution); } else { if (pElements != null) { Stopwatch sw = new Stopwatch(); string url = null; object request = null; try { sw.Start(); url = parameter.Url; string dataObj = parameter.VariableName; request = parameter.Request; string method = parameter.Method; var httpProxy = ProcessEngineServiceProvider.Resolve <IHttpClientProxy>(); HttpContext httpContext = ProcessEngineServiceProvider.Resolve <IHttpContextAccessor>()?.HttpContext; if (httpContext == null) { var uid = string.IsNullOrWhiteSpace(execution.StartUserId) ? Guid.NewGuid().ToString() : execution.StartUserId; httpProxy.SetHttpClientRequestAccessToken(uid, execution.TenantId, isSessionHeader: false); } switch (method?.ToLower()) { default: case "get": ExecuteGet(execution, url, request, dataObj, httpProxy); break; case "post": ExecutePost(execution, url, request, dataObj, httpProxy); break; } sw.Stop(); logger.LogInformation($"调用外部服务共计({sw.ElapsedMilliseconds}ms) url={url} request={(request is null ? "" : JsonConvert.SerializeObject(request))}"); } catch (Exception ex) { sw.Stop(); logger.LogError($"调用外部服务失败({sw.ElapsedMilliseconds}ms) url={url} request={(request is null ? "" : JsonConvert.SerializeObject(request))}:\r\n" + ex.Message + ex.StackTrace); string errorCode = execution.CurrentFlowElement.GetExtensionElementAttributeValue("errorCode"); BpmnError error; if (string.IsNullOrWhiteSpace(errorCode) == false) { error = new BpmnError(errorCode, ex.Message); } else { error = new BpmnError(Context.CommandContext.ProcessEngineConfiguration.WebApiErrorCode, ex.Message); } ErrorPropagation.PropagateError(error, execution); } } } Leave(execution); }
public override void Execute(IExecutionEntity execution) { try { bool isSkipExpressionEnabled = SkipExpressionUtil.IsSkipExpressionEnabled(execution, skipExpression); if (!isSkipExpressionEnabled || (isSkipExpressionEnabled && !SkipExpressionUtil.ShouldSkipFlowElement(execution, skipExpression))) { if (Context.ProcessEngineConfiguration.EnableProcessDefinitionInfoCache) { JToken taskElementProperties = Context.GetBpmnOverrideElementProperties(serviceTaskId, execution.ProcessDefinitionId); if (taskElementProperties != null && taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION] != null) { string overrideExpression = taskElementProperties[DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION].ToString(); if (!string.IsNullOrWhiteSpace(overrideExpression) && !overrideExpression.Equals(expression.ExpressionText)) { expression = Context.ProcessEngineConfiguration.ExpressionManager.CreateExpression(overrideExpression); } } } object @delegate = DelegateExpressionUtil.ResolveDelegateExpression(expression, execution, fieldDeclarations); if (@delegate is IActivityBehavior) { if (@delegate is AbstractBpmnActivityBehavior) { ((AbstractBpmnActivityBehavior)@delegate).MultiInstanceActivityBehavior = MultiInstanceActivityBehavior; } Context.ProcessEngineConfiguration.DelegateInterceptor.HandleInvocation(new ActivityBehaviorInvocation((IActivityBehavior)@delegate, execution)); } else if (@delegate is ICSharpDelegate) { Context.ProcessEngineConfiguration.DelegateInterceptor.HandleInvocation(new CSharpDelegateInvocation((ICSharpDelegate)@delegate, execution)); Leave(execution); } else { throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did neither resolve to an implementation of " + typeof(IActivityBehavior) + " nor " + typeof(ICSharpDelegate)); } } else { 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 { throw new ActivitiException(exc.Message, exc); } } }