/// <summary> /// Updates PollingState from Location header on Post or Delete operations. /// </summary> /// <typeparam name="TBody">Type of the resource body.</typeparam> /// <typeparam name="THeader">Type of the resource header.</typeparam> /// <param name="client">IAzureClient</param> /// <param name="pollingState">Current polling state.</param> /// <param name="customHeaders">Headers that will be added to request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>Task.</returns> private static async Task UpdateStateFromLocationHeaderOnPostOrDelete <TBody, THeader>( IAzureClient client, PollingState <TBody, THeader> pollingState, Dictionary <string, List <string> > customHeaders, CancellationToken cancellationToken) where TBody : class where THeader : class { AzureOperationResponse <TBody, THeader> responseWithResource = await client.GetAsync <TBody, THeader>( pollingState.LocationHeaderLink, customHeaders, cancellationToken).ConfigureAwait(false); pollingState.Response = responseWithResource.Response; pollingState.Request = responseWithResource.Request; pollingState.ResourceHeaders = responseWithResource.Headers; var statusCode = responseWithResource.Response.StatusCode; if (statusCode == HttpStatusCode.Accepted) { pollingState.Status = AzureAsyncOperation.InProgressStatus; } else if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.NoContent) { pollingState.Status = AzureAsyncOperation.SuccessStatus; pollingState.Resource = responseWithResource.Body; } }
public async Task <int> ExecuteAsync() { var response = JsonConvert.DeserializeObject <JObject>(await _azureClient.GetAsync(_urlStore.GetListUrl(_options.Type))); _output.Write(GetOutput(response, _options)); return(0); }
public async Task <int> ExecuteAsync() { var responseText = await _azureClient.GetAsync(_urlStore.GetObjectUrl(_options.Type, _options.Id)); var simplifiedJson = SimplifyJson(responseText); _output.Write(simplifiedJson); return(0); }
public async Task <int> ExecuteAsync() { var url = _urlStore.GetObjectUrl(_options.Type, _options.Id); var existing = await _azureClient.GetAsync(_urlStore.GetObjectUrl(_options.Type, _options.Id)); var response = await _azureClient.PutAsync(url, await TransformObject(existing)); _output.Write(response); return(0); }
/// <summary> /// Updates PollingState from Azure-AsyncOperation header. /// </summary> /// <typeparam name="TBody">Type of the resource body.</typeparam> /// <typeparam name="THeader">Type of the resource header.</typeparam> /// <param name="client">IAzureClient</param> /// <param name="pollingState">Current polling state.</param> /// <param name="customHeaders">Headers that will be added to request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>Task.</returns> private static async Task UpdateStateFromAzureAsyncOperationHeader <TBody, THeader>( IAzureClient client, PollingState <TBody, THeader> pollingState, Dictionary <string, List <string> > customHeaders, CancellationToken cancellationToken, HttpMethod initialRequestMethod) where TBody : class where THeader : class { string errMessage = string.Empty; AzureOperationResponse <AzureAsyncOperation, object> asyncOperationResponse = await client.GetAsync <AzureAsyncOperation, object>( pollingState.AzureAsyncOperationHeaderLink, customHeaders, cancellationToken).ConfigureAwait(false); if (asyncOperationResponse.Body == null || asyncOperationResponse.Body.Status == null) { throw new CloudException(Resources.NoBody); } string responseContent = await asyncOperationResponse.Response.Content.ReadAsStringAsync().ConfigureAwait(false); pollingState.Response = asyncOperationResponse.Response; pollingState.Request = asyncOperationResponse.Request; pollingState.Resource = null; pollingState.Status = asyncOperationResponse.Body.Status; // In LRO with async operation header, we only update polling state if the status is one of the failed one if (AzureAsyncOperation.FailedStatuses.Any( s => s.Equals(pollingState.Status, StringComparison.OrdinalIgnoreCase))) { //As this is for AsyncOperation header, we pass AzureOperationResponse as null pollingState = GetUpdatedPollingStatus <TBody, THeader>(asyncOperationResponse.Body, null, pollingState, responseContent, initialRequestMethod); } //Try to de-serialize to the response model. (Not required for "PutOrPatch" //which has the fallback of invoking generic "resource get".) var responseHeaders = pollingState.Response.Headers.ToJson(); try { pollingState.Resource = JObject.Parse(responseContent) .ToObject <TBody>(JsonSerializer.Create(client.DeserializationSettings)); pollingState.ResourceHeaders = responseHeaders.ToObject <THeader>(JsonSerializer.Create(client.DeserializationSettings)); } catch { }; }
/// <summary> /// Updates PollingState from Azure-AsyncOperation header. /// </summary> /// <typeparam name="TBody">Type of the resource body.</typeparam> /// <typeparam name="THeader">Type of the resource header.</typeparam> /// <param name="client">IAzureClient</param> /// <param name="pollingState">Current polling state.</param> /// <param name="customHeaders">Headers that will be added to request</param> /// <param name="postOrDelete">Headers that will be added to request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>Task.</returns> private static async Task UpdateStateFromAzureAsyncOperationHeader <TBody, THeader>( IAzureClient client, PollingState <TBody, THeader> pollingState, Dictionary <string, List <string> > customHeaders, bool postOrDelete, CancellationToken cancellationToken) where TBody : class where THeader : class { AzureOperationResponse <AzureAsyncOperation, object> asyncOperationResponse = await client.GetAsync <AzureAsyncOperation, object>( pollingState.AzureAsyncOperationHeaderLink, customHeaders, cancellationToken).ConfigureAwait(false); if (asyncOperationResponse.Body == null || asyncOperationResponse.Body.Status == null) { throw new CloudException(Resources.NoBody); } pollingState.Status = asyncOperationResponse.Body.Status; pollingState.Error = asyncOperationResponse.Body.Error; pollingState.Response = asyncOperationResponse.Response; pollingState.Request = asyncOperationResponse.Request; pollingState.Resource = null; if (postOrDelete) { //Try to de-serialize to the response model. (Not required for "PutOrPatch" //which has the fallback of invoking generic "resource get".) string responseContent = await pollingState.Response.Content.ReadAsStringAsync(); var responseHeaders = pollingState.Response.Headers.ToJson(); try { pollingState.Resource = JObject.Parse(responseContent) .ToObject <TBody>(JsonSerializer.Create(client.DeserializationSettings)); pollingState.ResourceHeaders = responseHeaders.ToObject <THeader>(JsonSerializer.Create(client.DeserializationSettings)); } catch { }; } }
/// <summary> /// Updates PollingState from Azure-AsyncOperation header. /// </summary> /// <typeparam name="T">Type of the resource.</typeparam> /// <param name="client">IAzureClient</param> /// <param name="pollingState">Current polling state.</param> /// <param name="customHeaders">Headers that will be added to request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>Task.</returns> private static async Task UpdateStateFromAzureAsyncOperationHeader <T>( IAzureClient client, PollingState <T> pollingState, Dictionary <string, List <string> > customHeaders, CancellationToken cancellationToken) where T : class { var asyncOperationResponse = await client.GetAsync <AzureAsyncOperation>( pollingState.AzureAsyncOperationHeaderLink, customHeaders, cancellationToken).ConfigureAwait(false); if (asyncOperationResponse.Body == null || asyncOperationResponse.Body.Status == null) { throw new CloudException(Resources.NoBody); } pollingState.Status = asyncOperationResponse.Body.Status; pollingState.Error = asyncOperationResponse.Body.Error; pollingState.Response = asyncOperationResponse.Response; pollingState.Request = asyncOperationResponse.Request; pollingState.Resource = null; }
private void SetupDefaultGetAsync(IAzureClient azureClient) { azureClient.GetAsync(Arg.Any <string>()) .Returns(Task.FromResult(CreateValidBuildJson())); }