Пример #1
0
        public ArgumentScript Generate()
        {
            var result = new ArgumentScript()
            {
                TemplateId           = _templateId,
                PlaceholderValueList = _placeholderValueList
            };

            if (_placeholderValueList?.Length > 0)
            {
                var resultBuilder = new StringBuilder();
                foreach (var argumentScriptParameters in _placeholderValueList)
                {
                    if (argumentScriptParameters.Values?.Length > 0)
                    {
                        string singleResult = _templateId;
                        foreach (var argumentScriptParameter in argumentScriptParameters.Values)
                        {
                            // Replacing "<param_name>" with value in the templateId.
                            // Value is represented as on line array of strings
                            singleResult = singleResult.Replace(
                                $"<{argumentScriptParameter.PlaceholderName}>",
                                ("'" + string.Join("','", argumentScriptParameter.Value) + "'"));
                        }

                        resultBuilder.AppendLine(singleResult);
                    }
                }

                result                      = new ArgumentScript(resultBuilder.ToString().Trim());
                result.TemplateId           = _templateId;
                result.PlaceholderValueList = _placeholderValueList;
            }
            return(result);
        }
Пример #2
0
        public ActionResult <ArgumentScript> Create([FromBody] ArgumentScript argumentScript)
        {
            var template = PCLIScriptsReader.GetArgumentTransformationScript(argumentScript.TemplateId);

            if (template == null)
            {
                return(NotFound(
                           new ErrorDetails(
                               ApiErrorCodes.GetErrorCode(nameof(APIGatewayResources.ArgumentScriptsController_ArgumentTransformationScriptNotFound)),
                               string.Format(APIGatewayResources.ArgumentScriptsController_ArgumentTransformationScriptNotFound, argumentScript.TemplateId))));
            }

            return(Ok(
                       new PCLIScriptsGenerator(
                           template.ScriptTemplate,
                           argumentScript.PlaceholderValueList).Generate()));
        }
Пример #3
0
        /// <summary>
        /// Creates scripts for a given script template id and placeholder values ### Creates scripts for a given script template id and placeholder values  Replaces the placeholders in a given argument transformation script template with given values on the placeholder_value_list field  The result script can be provided to a **script execution** parameter that expects specific script runtime type    ### Example  If the template argument transformation script is    Get-VM -Id &lt;vm-id&gt; -Server &lt;server&gt;    The result of this operation with given Id &#x27;vm-1&#x27; and Server &#x27;server-1&#x27; would be    Get-VM -Id &#x27;vm-1&#x27; -Server &#x27;server-1&#x27;
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">The argument script create request (optional)</param>
        /// <returns>Task of ApiResponse (ArgumentScript)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <ArgumentScript> > CreateArgumentScriptsScriptAsyncWithHttpInfo(ArgumentScript body = null)
        {
            var    localVarPath         = "/api/argument-scripts/script";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (body != null && body.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter
            }
            else
            {
                localVarPostBody = body; // byte array
            }
            // authentication (apiKeyAuth) required
            if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("X-SRS-API-KEY")))
            {
                localVarHeaderParams["X-SRS-API-KEY"] = this.Configuration.GetApiKeyWithPrefix("X-SRS-API-KEY");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("CreateArgumentScriptsScript", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <ArgumentScript>(localVarStatusCode,
                                                    localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                                                    (ArgumentScript)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(ArgumentScript))));
        }
Пример #4
0
        /// <summary>
        /// Creates scripts for a given script template id and placeholder values ### Creates scripts for a given script template id and placeholder values  Replaces the placeholders in a given argument transformation script template with given values on the placeholder_value_list field  The result script can be provided to a **script execution** parameter that expects specific script runtime type    ### Example  If the template argument transformation script is    Get-VM -Id &lt;vm-id&gt; -Server &lt;server&gt;    The result of this operation with given Id &#x27;vm-1&#x27; and Server &#x27;server-1&#x27; would be    Get-VM -Id &#x27;vm-1&#x27; -Server &#x27;server-1&#x27;
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">The argument script create request (optional)</param>
        /// <returns>Task of ArgumentScript</returns>
        public async System.Threading.Tasks.Task <ArgumentScript> CreateArgumentScriptsScriptAsync(ArgumentScript body = null)
        {
            ApiResponse <ArgumentScript> localVarResponse = await CreateArgumentScriptsScriptAsyncWithHttpInfo(body);

            return(localVarResponse.Data);
        }
Пример #5
0
        /// <summary>
        /// Creates scripts for a given script template id and placeholder values ### Creates scripts for a given script template id and placeholder values  Replaces the placeholders in a given argument transformation script template with given values on the placeholder_value_list field  The result script can be provided to a **script execution** parameter that expects specific script runtime type    ### Example  If the template argument transformation script is    Get-VM -Id &lt;vm-id&gt; -Server &lt;server&gt;    The result of this operation with given Id &#x27;vm-1&#x27; and Server &#x27;server-1&#x27; would be    Get-VM -Id &#x27;vm-1&#x27; -Server &#x27;server-1&#x27;
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="body">The argument script create request (optional)</param>
        /// <returns>ArgumentScript</returns>
        public ArgumentScript CreateArgumentScriptsScript(ArgumentScript body = null)
        {
            ApiResponse <ArgumentScript> localVarResponse = CreateArgumentScriptsScriptWithHttpInfo(body);

            return(localVarResponse.Data);
        }