Exemplo n.º 1
0
        /// <summary>
        /// 侦听任务执行完成时接收通知处理
        /// </summary>
        /// <param name="execution"></param>
        public void Notify(IExecutionEntity execution)
        {
            UserTask task = execution.CurrentFlowElement as UserTask;

            if (task.ExtensionElements.TryGetValue(BpmnXMLConstants.ELEMENT_EXTENSIONS_PROPERTY, out IList <ExtensionElement> exts))
            {
                if (bool.TryParse(exts.GetAttributeValue(BpmnXMLConstants.ACTIITI_RUNTIME_ASSIGNEE), out bool result) == false || result == false)
                {
                    return;
                }

                var variable = execution.GetVariableInstance(BpmnXMLConstants.RUNTIME_ASSIGNEE_USER_VARIABLE_NAME);

                RuntimeAssigneeUser user = JToken.FromObject(variable.Value).ToObject <RuntimeAssigneeUser>();

                if ((user?.Users?.Count()).GetValueOrDefault() == 0)
                {
                    return;
                }

                string collection   = task.LoopCharacteristics.GetCollectionVarName();
                string elemVariable = task.LoopCharacteristics.ElementVariable;

                execution.RemoveVariableLocal(collection);
                execution.RemoveVariableLocal(elemVariable);
            }
        }
Exemplo n.º 2
0
        public virtual IVariableInstance Execute(ICommandContext commandContext)
        {
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }
            if (variableName is 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));
            }

            IVariableInstance variableEntity;

            if (isLocal)
            {
                variableEntity = execution.GetVariableInstanceLocal(variableName, false);
            }
            else
            {
                variableEntity = execution.GetVariableInstance(variableName, false);
            }

            return(variableEntity);;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 侦听接收通知处理
        /// </summary>
        /// <param name="execution"></param>
        public void Notify(IExecutionEntity execution)
        {
            UserTask task = execution.CurrentFlowElement as UserTask;

            if (task.ExtensionElements.TryGetValue(BpmnXMLConstants.ELEMENT_EXTENSIONS_PROPERTY, out IList <ExtensionElement> exts))
            {
                if (bool.TryParse(exts.GetAttributeValue(BpmnXMLConstants.ACTIITI_RUNTIME_ASSIGNEE), out bool result) == false || result == false)
                {
                    return;
                }

                var variable = execution.GetVariableInstance(BpmnXMLConstants.RUNTIME_ASSIGNEE_USER_VARIABLE_NAME);

                RuntimeAssigneeUser user = JToken.FromObject(variable.Value).ToObject <RuntimeAssigneeUser>();

                if ((user?.Users?.Count()).GetValueOrDefault() == 0)
                {
                    throw new NotFoundAssigneeException();
                }

                var varName = exts.GetAttributeValue(BpmnXMLConstants.ACTIITI_RUNTIME_ASSIGNEE_VARIABLE);

                if (string.IsNullOrWhiteSpace(varName))
                {
                    varName = user.Field;
                }

                execution.SetLoopVariable(varName, user.Users.Distinct().ToArray());
            }
        }
Exemplo n.º 4
0
        public virtual IDataObject Execute(ICommandContext commandContext)
        {
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }
            if (dataObjectName is null)
            {
                throw new ActivitiIllegalArgumentException("dataObjectName is null");
            }

            IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId);

            if (execution == null)
            {
                throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", typeof(IExecution));
            }

            IDataObject dataObject = null;

            IVariableInstance variableEntity;

            if (isLocal)
            {
                variableEntity = execution.GetVariableInstanceLocal(dataObjectName, false);
            }
            else
            {
                variableEntity = execution.GetVariableInstance(dataObjectName, false);
            }

            string localizedName        = null;
            string localizedDescription = null;

            if (variableEntity != null)
            {
                IExecutionEntity executionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(variableEntity.ExecutionId);
                while (!executionEntity.IsScope)
                {
                    executionEntity = executionEntity.Parent;
                }

                BpmnModel        bpmnModel       = ProcessDefinitionUtil.GetBpmnModel(executionEntity.ProcessDefinitionId);
                ValuedDataObject foundDataObject = null;
                if (executionEntity.ParentId is null)
                {
                    foreach (ValuedDataObject dataObjectDefinition in bpmnModel.MainProcess.DataObjects)
                    {
                        if (dataObjectDefinition.Name.Equals(variableEntity.Name))
                        {
                            foundDataObject = dataObjectDefinition;
                            break;
                        }
                    }
                }
                else
                {
                    SubProcess subProcess = (SubProcess)bpmnModel.GetFlowElement(execution.ActivityId);
                    foreach (ValuedDataObject dataObjectDefinition in subProcess.DataObjects)
                    {
                        if (dataObjectDefinition.Name.Equals(variableEntity.Name))
                        {
                            foundDataObject = dataObjectDefinition;
                            break;
                        }
                    }
                }

                if (!(locale is null) && foundDataObject != null)
                {
                    JToken languageNode = Context.GetLocalizationElementProperties(locale, foundDataObject.Id, execution.ProcessDefinitionId, withLocalizationFallback);

                    if (variableEntity != null && languageNode != null)
                    {
                        JToken nameNode = languageNode[DynamicBpmnConstants.LOCALIZATION_NAME];
                        if (nameNode != null)
                        {
                            localizedName = nameNode.ToString();
                        }
                        JToken descriptionNode = languageNode[DynamicBpmnConstants.LOCALIZATION_DESCRIPTION];
                        if (descriptionNode != null)
                        {
                            localizedDescription = descriptionNode.ToString();
                        }
                    }
                }

                if (foundDataObject != null)
                {
                    dataObject = new DataObjectImpl(variableEntity.Name, variableEntity.Value, foundDataObject.Documentation, foundDataObject.Type, localizedName, localizedDescription, foundDataObject.Id);
                }
            }

            return(dataObject);
        }
Exemplo n.º 5
0
        /// <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);
        }