custom/CommvaultPowerShell.cs
// Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.0.6262, generator: {generator})
// Changes may cause incorrect behavior and will be lost if the code is regenerated. namespace Commvault.Powershell { using static Commvault.Powershell.Runtime.Extensions; /// <summary> /// Low-level API implementation for the Commvault REST API service. /// </summary> public partial class CommvaultPowerShell { /// <summary> /// Add your QSDK Authenticated token to your Postman Environment by providing the details in the pre-request script. /// You only need to run this one time because these values are stored in your Postman Environment. /// </summary> /// <param name="body">EnvironmentSetupRequest</param> /// <param name="onOk">a delegate that is called when the remote service returns 200 (OK).</param> /// <param name="eventListener">an <see cref="Commvault.Powershell.Runtime.IEventListener" /> instance that will receive events.</param> /// <param name="sender">an instance of an Commvault.Powershell.Runtime.ISendAsync pipeline to use to make the request.</param> /// <returns> /// A <see cref="global::System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed. /// </returns> public async global::System.Threading.Tasks.Task LoginPost(Commvault.Powershell.Models.IEnvironmentSetupRequest body, global::System.Func<global::System.Net.Http.HttpResponseMessage, global::System.Threading.Tasks.Task<Commvault.Powershell.Models.ILoginResponse>, global::System.Threading.Tasks.Task> onOk, Commvault.Powershell.Runtime.IEventListener eventListener, Commvault.Powershell.Runtime.ISendAsync sender) { // Constant Parameters using( NoSynchronizationContext ) { // construct URL var _url = new global::System.Uri(global::System.Text.RegularExpressions.Regex.Replace( "http://WebserverUrl.Commvault.com/webconsole/api/Login" ,"\\?&*$|&*$|(\\?)&+|(&)&+","$1$2")); await eventListener.Signal(Commvault.Powershell.Runtime.Events.URLCreated, _url); if( eventListener.Token.IsCancellationRequested ) { return; } // generate request object var request = new global::System.Net.Http.HttpRequestMessage(Commvault.Powershell.Runtime.Method.Post, _url); await eventListener.Signal(Commvault.Powershell.Runtime.Events.RequestCreated, _url); if( eventListener.Token.IsCancellationRequested ) { return; } await eventListener.Signal(Commvault.Powershell.Runtime.Events.HeaderParametersAdded, _url); if( eventListener.Token.IsCancellationRequested ) { return; } //Setting WebServerURL according to CV System.Environment.SetEnvironmentVariable("WebServerURL", body.WebServerUrl); // set body content request.Content = new global::System.Net.Http.StringContent(null != body ? body.ToJson(null).ToString() : @"{}", global::System.Text.Encoding.UTF8); request.Content.Headers.ContentType = global::System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); await eventListener.Signal(Commvault.Powershell.Runtime.Events.BodyContentSet, _url); if( eventListener.Token.IsCancellationRequested ) { return; } // make the call await this.LoginPost_Call(request,onOk,eventListener,sender); } } /// <summary>Actual wire call for <see cref="LoginPost" /> method.</summary> /// <param name="request">the prepared HttpRequestMessage to send.</param> /// <param name="onOk">a delegate that is called when the remote service returns 200 (OK).</param> /// <param name="eventListener">an <see cref="Commvault.Powershell.Runtime.IEventListener" /> instance that will receive events.</param> /// <param name="sender">an instance of an Commvault.Powershell.Runtime.ISendAsync pipeline to use to make the request.</param> /// <returns> /// A <see cref="global::System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed. /// </returns> internal async global::System.Threading.Tasks.Task LoginPost_Call(global::System.Net.Http.HttpRequestMessage request, global::System.Func<global::System.Net.Http.HttpResponseMessage, global::System.Threading.Tasks.Task<Commvault.Powershell.Models.ILoginResponse>, global::System.Threading.Tasks.Task> onOk, Commvault.Powershell.Runtime.IEventListener eventListener, Commvault.Powershell.Runtime.ISendAsync sender) { using( NoSynchronizationContext ) { global::System.Net.Http.HttpResponseMessage _response = null; try { await eventListener.Signal(Commvault.Powershell.Runtime.Events.BeforeCall, request); if( eventListener.Token.IsCancellationRequested ) { return; } _response = await sender.SendAsync(request, eventListener); await eventListener.Signal(Commvault.Powershell.Runtime.Events.ResponseCreated, _response); if( eventListener.Token.IsCancellationRequested ) { return; } var _contentType = _response.Content.Headers.ContentType?.MediaType; switch ( _response.StatusCode ) { case global::System.Net.HttpStatusCode.OK: { await eventListener.Signal(Commvault.Powershell.Runtime.Events.BeforeResponseDispatch, _response); if( eventListener.Token.IsCancellationRequested ) { return; } await onOk(_response,_response.Content.ReadAsStringAsync().ContinueWith( body => Commvault.Powershell.Models.LoginResponse.FromJson(Commvault.Powershell.Runtime.Json.JsonNode.Parse(body.Result)) )); break; } default: { throw new Commvault.Powershell.Runtime.UndeclaredResponseException(_response); } } } finally { // finally statements await eventListener.Signal(Commvault.Powershell.Runtime.Events.Finally, request, _response); _response?.Dispose(); request?.Dispose(); } } } /// <summary> /// Validation method for <see cref="LoginPost" /> method. Call this like the actual call, but you will get validation events /// back. /// </summary> /// <param name="body">EnvironmentSetupRequest</param> /// <param name="eventListener">an <see cref="Commvault.Powershell.Runtime.IEventListener" /> instance that will receive events.</param> /// <returns> /// A <see cref="global::System.Threading.Tasks.Task" /> that will be complete when handling of the response is completed. /// </returns> internal async global::System.Threading.Tasks.Task LoginPost_Validate(Commvault.Powershell.Models.IEnvironmentSetupRequest body, Commvault.Powershell.Runtime.IEventListener eventListener) { using( NoSynchronizationContext ) { await eventListener.AssertNotNull(nameof(body), body); await eventListener.AssertObjectIsValid(nameof(body), body); } } } } |