Beispiel #1
0
        private async Task <string> ReplacePlaceholders(WorkflowPluginLinkContext context, string queryText)
        {
            var queryVariables = ExtractPlaceholders(queryText);

            if (!queryVariables.Any())
            {
                await Task.FromResult(queryText);                  // query without variables
            }

            var processInputVariables = await GetProcessVariables(context, queryVariables);

            var newQuery = string.Copy(queryText);

            if (queryVariables.Count != processInputVariables.Count)
            {
                throw new ArgumentException($"Unable to find one or more process variable specified into the query");
            }

            foreach (var variable in queryVariables)
            {
                var processVariable = processInputVariables.First(x => x.VariableDefinition.Configuration.Name == variable);
                newQuery = newQuery.Replace($"#@{variable}@#", GetValueFromProcessVariable(processVariable));
            }

            return(await Task.FromResult(newQuery));
        }
Beispiel #2
0
        private async Task SetOutputVariable(WorkflowPluginLinkContext context, object[,] matrix)
        {
            var diagramVariables = await DiagramsApi.ApiV1DiagramsIdVariablesGetAsync(context.Diagram.Id);

            var outputVariable = diagramVariables.FirstOrDefault(x => x.Configuration.Name == OutputVariableName);

            if (outputVariable == null)
            {
                throw new ArgumentException($"Unable to find diagram variable {OutputVariableName}");
            }

            var processVariable = (await GetProcessVariables(context, new List <string> {
                OutputVariableName
            })).First();

            if (processVariable == null)
            {
                throw new ArgumentException($"Unable to find process variable {OutputVariableName}");
            }

            var variables = new List <ProcessSetVariableRm>
            {
                new ProcessSetMatrixVariableRm
                (
                    ConvertMatrixToList(matrix),
                    processVariable.Id,
                    outputVariable.Id,
                    context.Process.Id,
                    processVariable.VariableType
                )
            };

            await ProcessVariablesApi.ApiV1ProcessVariablesSetPostAsync(variables);
        }
Beispiel #3
0
 public override async Task ExecuteAsync(WorkflowPluginLinkContext context)
 {
     if (AdvancedConfigurationEnabled)
     {
         await ExecuteAdvancedConfiguration(context);
     }
     else
     {
         await ExecuteStandardConfiguration(context);
     }
 }
Beispiel #4
0
        private async Task ExecuteAdvancedConfiguration(WorkflowPluginLinkContext context)
        {
            ApplyTokenToApiConfiguration();

            var mongoQuery  = GetMongoClient();
            var actualQuery = await ReplacePlaceholders(context, QueryText);

            var jsonResult = await mongoQuery.ExecuteQuery(actualQuery);

            var matrix = await ParseOutputParameter(jsonResult);

            await SetOutputVariable(context, matrix);
        }
Beispiel #5
0
        private async Task ExecuteStandardConfiguration(WorkflowPluginLinkContext context)
        {
            try
            {
                var mongoQuery = GetMongoClient();
                Result = await mongoQuery.ExecuteQuery(QueryText);

                Success = true;
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                Success      = false;
            }
        }
Beispiel #6
0
        private async Task <List <ProcessVariableRm> > GetProcessVariables(WorkflowPluginLinkContext context, List <string> variableNames)
        {
            List <ProcessVariableRm> allVariables = new List <ProcessVariableRm>();
            int  pageIndex  = 0;
            int  pageSize   = 5;
            long totalCount = 0;

            do
            {
                // We need to be sure to load all the process variables in order to match all the required variables
                var pageVariables = await ProcessApi.ApiV1ProcessesProcessIdVariablesGetAsync(context.Process.Id, pageIndex ++ *pageSize, pageSize);

                allVariables.AddRange(pageVariables.Items);
                totalCount = pageVariables.ResultCount.TotalResultCount.Value;
            } while (allVariables.Count < totalCount);

            return(allVariables.Where(x => variableNames.Contains(x.VariableDefinition.Configuration.Name)).ToList());
        }