| | 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.Storage.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.ResourceManager.Storage |
| | 18 | | { |
| | 19 | | internal partial class UsagesRestOperations |
| | 20 | | { |
| | 21 | | private string subscriptionId; |
| | 22 | | private Uri endpoint; |
| | 23 | | private string apiVersion; |
| | 24 | | private ClientDiagnostics _clientDiagnostics; |
| | 25 | | private HttpPipeline _pipeline; |
| | 26 | |
|
| | 27 | | /// <summary> Initializes a new instance of UsagesRestOperations. </summary> |
| | 28 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 29 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 30 | | /// <param name="subscriptionId"> The ID of the target subscription. </param> |
| | 31 | | /// <param name="endpoint"> server parameter. </param> |
| | 32 | | /// <param name="apiVersion"> Api Version. </param> |
| | 33 | | /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception |
| 240 | 34 | | public UsagesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscriptionId, U |
| | 35 | | { |
| 240 | 36 | | if (subscriptionId == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(subscriptionId)); |
| | 39 | | } |
| 240 | 40 | | endpoint ??= new Uri("https://management.azure.com"); |
| 240 | 41 | | if (apiVersion == null) |
| | 42 | | { |
| 0 | 43 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 44 | | } |
| | 45 | |
|
| 240 | 46 | | this.subscriptionId = subscriptionId; |
| 240 | 47 | | this.endpoint = endpoint; |
| 240 | 48 | | this.apiVersion = apiVersion; |
| 240 | 49 | | _clientDiagnostics = clientDiagnostics; |
| 240 | 50 | | _pipeline = pipeline; |
| 240 | 51 | | } |
| | 52 | |
|
| | 53 | | internal HttpMessage CreateListByLocationRequest(string location) |
| | 54 | | { |
| 4 | 55 | | var message = _pipeline.CreateMessage(); |
| 4 | 56 | | var request = message.Request; |
| 4 | 57 | | request.Method = RequestMethod.Get; |
| 4 | 58 | | var uri = new RawRequestUriBuilder(); |
| 4 | 59 | | uri.Reset(endpoint); |
| 4 | 60 | | uri.AppendPath("/subscriptions/", false); |
| 4 | 61 | | uri.AppendPath(subscriptionId, true); |
| 4 | 62 | | uri.AppendPath("/providers/Microsoft.Storage/locations/", false); |
| 4 | 63 | | uri.AppendPath(location, true); |
| 4 | 64 | | uri.AppendPath("/usages", false); |
| 4 | 65 | | uri.AppendQuery("api-version", apiVersion, true); |
| 4 | 66 | | request.Uri = uri; |
| 4 | 67 | | return message; |
| | 68 | | } |
| | 69 | |
|
| | 70 | | /// <summary> Gets the current usage count and the limit for the resources of the location under the subscriptio |
| | 71 | | /// <param name="location"> The location of the Azure Storage resource. </param> |
| | 72 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 73 | | public async Task<Response<UsageListResult>> ListByLocationAsync(string location, CancellationToken cancellation |
| | 74 | | { |
| 2 | 75 | | if (location == null) |
| | 76 | | { |
| 0 | 77 | | throw new ArgumentNullException(nameof(location)); |
| | 78 | | } |
| | 79 | |
|
| 2 | 80 | | using var message = CreateListByLocationRequest(location); |
| 2 | 81 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 82 | | switch (message.Response.Status) |
| | 83 | | { |
| | 84 | | case 200: |
| | 85 | | { |
| 2 | 86 | | UsageListResult value = default; |
| 2 | 87 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 88 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 89 | | { |
| 0 | 90 | | value = null; |
| | 91 | | } |
| | 92 | | else |
| | 93 | | { |
| 2 | 94 | | value = UsageListResult.DeserializeUsageListResult(document.RootElement); |
| | 95 | | } |
| 2 | 96 | | return Response.FromValue(value, message.Response); |
| | 97 | | } |
| | 98 | | default: |
| 0 | 99 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 100 | | } |
| 2 | 101 | | } |
| | 102 | |
|
| | 103 | | /// <summary> Gets the current usage count and the limit for the resources of the location under the subscriptio |
| | 104 | | /// <param name="location"> The location of the Azure Storage resource. </param> |
| | 105 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 106 | | public Response<UsageListResult> ListByLocation(string location, CancellationToken cancellationToken = default) |
| | 107 | | { |
| 2 | 108 | | if (location == null) |
| | 109 | | { |
| 0 | 110 | | throw new ArgumentNullException(nameof(location)); |
| | 111 | | } |
| | 112 | |
|
| 2 | 113 | | using var message = CreateListByLocationRequest(location); |
| 2 | 114 | | _pipeline.Send(message, cancellationToken); |
| 2 | 115 | | switch (message.Response.Status) |
| | 116 | | { |
| | 117 | | case 200: |
| | 118 | | { |
| 2 | 119 | | UsageListResult value = default; |
| 2 | 120 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 121 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 122 | | { |
| 0 | 123 | | value = null; |
| | 124 | | } |
| | 125 | | else |
| | 126 | | { |
| 2 | 127 | | value = UsageListResult.DeserializeUsageListResult(document.RootElement); |
| | 128 | | } |
| 2 | 129 | | return Response.FromValue(value, message.Response); |
| | 130 | | } |
| | 131 | | default: |
| 0 | 132 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 133 | | } |
| 2 | 134 | | } |
| | 135 | | } |
| | 136 | | } |