| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | // <auto-generated/> |
| | | 5 | | |
| | | 6 | | #nullable disable |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Text.Json; |
| | | 10 | | using System.Threading; |
| | | 11 | | using System.Threading.Tasks; |
| | | 12 | | using Azure; |
| | | 13 | | using Azure.Core; |
| | | 14 | | using Azure.Core.Pipeline; |
| | | 15 | | using Azure.ResourceManager.Compute.Models; |
| | | 16 | | |
| | | 17 | | namespace Azure.ResourceManager.Compute |
| | | 18 | | { |
| | | 19 | | internal partial class RestOperations |
| | | 20 | | { |
| | | 21 | | private Uri endpoint; |
| | | 22 | | private ClientDiagnostics _clientDiagnostics; |
| | | 23 | | private HttpPipeline _pipeline; |
| | | 24 | | |
| | | 25 | | /// <summary> Initializes a new instance of RestOperations. </summary> |
| | | 26 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | | 27 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | | 28 | | /// <param name="endpoint"> server parameter. </param> |
| | 396 | 29 | | public RestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null) |
| | | 30 | | { |
| | 396 | 31 | | endpoint ??= new Uri("https://management.azure.com"); |
| | | 32 | | |
| | 396 | 33 | | this.endpoint = endpoint; |
| | 396 | 34 | | _clientDiagnostics = clientDiagnostics; |
| | 396 | 35 | | _pipeline = pipeline; |
| | 396 | 36 | | } |
| | | 37 | | |
| | | 38 | | internal HttpMessage CreateListRequest() |
| | | 39 | | { |
| | 4 | 40 | | var message = _pipeline.CreateMessage(); |
| | 4 | 41 | | var request = message.Request; |
| | 4 | 42 | | request.Method = RequestMethod.Get; |
| | 4 | 43 | | var uri = new RawRequestUriBuilder(); |
| | 4 | 44 | | uri.Reset(endpoint); |
| | 4 | 45 | | uri.AppendPath("/providers/Microsoft.Compute/operations", false); |
| | 4 | 46 | | uri.AppendQuery("api-version", "2019-12-01", true); |
| | 4 | 47 | | request.Uri = uri; |
| | 4 | 48 | | return message; |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> Gets a list of compute operations. </summary> |
| | | 52 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | | 53 | | public async Task<Response<ComputeOperationListResult>> ListAsync(CancellationToken cancellationToken = default) |
| | | 54 | | { |
| | 2 | 55 | | using var message = CreateListRequest(); |
| | 2 | 56 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| | 2 | 57 | | switch (message.Response.Status) |
| | | 58 | | { |
| | | 59 | | case 200: |
| | | 60 | | { |
| | 2 | 61 | | ComputeOperationListResult value = default; |
| | 2 | 62 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| | 2 | 63 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | | 64 | | { |
| | 0 | 65 | | value = null; |
| | | 66 | | } |
| | | 67 | | else |
| | | 68 | | { |
| | 2 | 69 | | value = ComputeOperationListResult.DeserializeComputeOperationListResult(document.RootElemen |
| | | 70 | | } |
| | 2 | 71 | | return Response.FromValue(value, message.Response); |
| | | 72 | | } |
| | | 73 | | default: |
| | 0 | 74 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | | 75 | | } |
| | 2 | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <summary> Gets a list of compute operations. </summary> |
| | | 79 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | | 80 | | public Response<ComputeOperationListResult> List(CancellationToken cancellationToken = default) |
| | | 81 | | { |
| | 2 | 82 | | using var message = CreateListRequest(); |
| | 2 | 83 | | _pipeline.Send(message, cancellationToken); |
| | 2 | 84 | | switch (message.Response.Status) |
| | | 85 | | { |
| | | 86 | | case 200: |
| | | 87 | | { |
| | 2 | 88 | | ComputeOperationListResult value = default; |
| | 2 | 89 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| | 2 | 90 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | | 91 | | { |
| | 0 | 92 | | value = null; |
| | | 93 | | } |
| | | 94 | | else |
| | | 95 | | { |
| | 2 | 96 | | value = ComputeOperationListResult.DeserializeComputeOperationListResult(document.RootElemen |
| | | 97 | | } |
| | 2 | 98 | | return Response.FromValue(value, message.Response); |
| | | 99 | | } |
| | | 100 | | default: |
| | 0 | 101 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | | 102 | | } |
| | 2 | 103 | | } |
| | | 104 | | } |
| | | 105 | | } |