public async Task <ProcessModel> RunScriptById(int id, ScriptParamArray paramArray)
        {
            Script script = await _context.Scripts.FindAsync(id);

            if (script == null)
            {
                throw new AppException($"Script with id {id} not found in database");
            }

            ScriptType scriptType = await _scriptService.GetTypeByIdAsync(script.Type);

            string scriptFilePath = CreateScriptFileWithContent(script.Content, scriptType.FileExtension);

            string processArgs = PrepareScriptArguments(scriptType, scriptFilePath, paramArray);

            _logger.LogDebug("Process arguments : {args}", processArgs);

            try
            {
                ProcessModel processModel = await RunProcessAsync(processArgs, scriptType.Runner);

                _logger.LogDebug("Process result : {@model}", processModel);
                return(processModel);
            }
            finally {
                await DeleteScriptFileAsync(scriptFilePath);
            }
        }
        private string PrepareScriptArguments(ScriptType ScriptType, string scriptFilePath, ScriptParamArray paramArray)
        {
            _logger.LogDebug("Preparing script arguments");
            StringBuilder stringBuilder = new StringBuilder();

            if (ScriptType.ScriptArgument != null)
            {
                stringBuilder.AppendFormat(" {0} {1}", ScriptType.ScriptArgument, scriptFilePath);
            }
            else
            {
                stringBuilder.AppendFormat(" {0}", scriptFilePath);
            }

            if (paramArray == null)
            {
                return(stringBuilder.ToString());
            }

            if (paramArray.Parameters.Count > 0)
            {
                foreach (ScriptParamModel paramModel in paramArray.Parameters)
                {
                    string decodedValue = Base64.DecodeBase64(paramModel.EncodedValue);
                    stringBuilder.Append(string.Format(" -{0} {1}", paramModel.Name, decodedValue));
                }
            }
            return(stringBuilder.ToString());
        }