public virtual IDictionary <string, IVariableInstance> Execute(ICommandContext commandContext)
        {
            // Verify existance of execution
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }

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

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

            IDictionary <string, IVariableInstance> variables;

            if ((variableNames?.Count()).GetValueOrDefault(0) == 0)
            {
                // Fetch all
                if (isLocal)
                {
                    variables = execution.VariableInstancesLocal;
                }
                else
                {
                    variables = execution.VariableInstances;
                }
            }
            else
            {
                // Fetch specific collection of variables
                if (isLocal)
                {
                    variables = execution.GetVariableInstancesLocal(variableNames, false);
                }
                else
                {
                    variables = execution.GetVariableInstances(variableNames, false);
                }
            }

            return(variables);
        }
Пример #2
0
        public virtual IDictionary <string, IDataObject> Execute(ICommandContext commandContext)
        {
            // Verify existance of execution
            if (executionId is null)
            {
                throw new ActivitiIllegalArgumentException("executionId is null");
            }

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

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

            IDictionary <string, IVariableInstance> variables;

            if ((dataObjectNames?.Count()).GetValueOrDefault(0) == 0)
            {
                // Fetch all
                if (isLocal)
                {
                    variables = execution.VariableInstancesLocal;
                }
                else
                {
                    variables = execution.VariableInstances;
                }
            }
            else
            {
                // Fetch specific collection of variables
                if (isLocal)
                {
                    variables = execution.GetVariableInstancesLocal(dataObjectNames, false);
                }
                else
                {
                    variables = execution.GetVariableInstances(dataObjectNames, false);
                }
            }

            IDictionary <string, IDataObject> dataObjects = null;

            if (variables != null)
            {
                dataObjects = new Dictionary <string, IDataObject>(variables.Count);

                foreach (KeyValuePair <string, IVariableInstance> entry in variables.SetOfKeyValuePairs())
                {
                    string            name           = entry.Key;
                    IVariableInstance variableEntity = entry.Value;

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

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

                    string localizedName        = null;
                    string localizedDescription = null;

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

                        if (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)
                    {
                        dataObjects[name] = new DataObjectImpl(variableEntity.Name, variableEntity.Value, foundDataObject.Documentation, foundDataObject.Type, localizedName, localizedDescription, foundDataObject.Id);
                    }
                }
            }

            return(dataObjects);
        }