| | 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.Network.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.ResourceManager.Network |
| | 18 | | { |
| | 19 | | internal partial class UsagesRestOperations |
| | 20 | | { |
| | 21 | | private string subscriptionId; |
| | 22 | | private Uri endpoint; |
| | 23 | | private ClientDiagnostics _clientDiagnostics; |
| | 24 | | private HttpPipeline _pipeline; |
| | 25 | |
|
| | 26 | | /// <summary> Initializes a new instance of UsagesRestOperations. </summary> |
| | 27 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 28 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 29 | | /// <param name="subscriptionId"> The subscription credentials which uniquely identify the Microsoft Azure subsc |
| | 30 | | /// <param name="endpoint"> server parameter. </param> |
| | 31 | | /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception |
| 4 | 32 | | public UsagesRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string subscriptionId, U |
| | 33 | | { |
| 4 | 34 | | if (subscriptionId == null) |
| | 35 | | { |
| 0 | 36 | | throw new ArgumentNullException(nameof(subscriptionId)); |
| | 37 | | } |
| 4 | 38 | | endpoint ??= new Uri("https://management.azure.com"); |
| | 39 | |
|
| 4 | 40 | | this.subscriptionId = subscriptionId; |
| 4 | 41 | | this.endpoint = endpoint; |
| 4 | 42 | | _clientDiagnostics = clientDiagnostics; |
| 4 | 43 | | _pipeline = pipeline; |
| 4 | 44 | | } |
| | 45 | |
|
| | 46 | | internal HttpMessage CreateListRequest(string location) |
| | 47 | | { |
| 4 | 48 | | var message = _pipeline.CreateMessage(); |
| 4 | 49 | | var request = message.Request; |
| 4 | 50 | | request.Method = RequestMethod.Get; |
| 4 | 51 | | var uri = new RawRequestUriBuilder(); |
| 4 | 52 | | uri.Reset(endpoint); |
| 4 | 53 | | uri.AppendPath("/subscriptions/", false); |
| 4 | 54 | | uri.AppendPath(subscriptionId, true); |
| 4 | 55 | | uri.AppendPath("/providers/Microsoft.Network/locations/", false); |
| 4 | 56 | | uri.AppendPath(location, true); |
| 4 | 57 | | uri.AppendPath("/usages", false); |
| 4 | 58 | | uri.AppendQuery("api-version", "2020-04-01", true); |
| 4 | 59 | | request.Uri = uri; |
| 4 | 60 | | return message; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | /// <summary> List network usages for a subscription. </summary> |
| | 64 | | /// <param name="location"> The location where resource usage is queried. </param> |
| | 65 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 66 | | public async Task<Response<UsagesListResult>> ListAsync(string location, CancellationToken cancellationToken = d |
| | 67 | | { |
| 2 | 68 | | if (location == null) |
| | 69 | | { |
| 0 | 70 | | throw new ArgumentNullException(nameof(location)); |
| | 71 | | } |
| | 72 | |
|
| 2 | 73 | | using var message = CreateListRequest(location); |
| 2 | 74 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 75 | | switch (message.Response.Status) |
| | 76 | | { |
| | 77 | | case 200: |
| | 78 | | { |
| 2 | 79 | | UsagesListResult value = default; |
| 2 | 80 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 81 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 82 | | { |
| 0 | 83 | | value = null; |
| | 84 | | } |
| | 85 | | else |
| | 86 | | { |
| 2 | 87 | | value = UsagesListResult.DeserializeUsagesListResult(document.RootElement); |
| | 88 | | } |
| 2 | 89 | | return Response.FromValue(value, message.Response); |
| | 90 | | } |
| | 91 | | default: |
| 0 | 92 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 93 | | } |
| 2 | 94 | | } |
| | 95 | |
|
| | 96 | | /// <summary> List network usages for a subscription. </summary> |
| | 97 | | /// <param name="location"> The location where resource usage is queried. </param> |
| | 98 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 99 | | public Response<UsagesListResult> List(string location, CancellationToken cancellationToken = default) |
| | 100 | | { |
| 2 | 101 | | if (location == null) |
| | 102 | | { |
| 0 | 103 | | throw new ArgumentNullException(nameof(location)); |
| | 104 | | } |
| | 105 | |
|
| 2 | 106 | | using var message = CreateListRequest(location); |
| 2 | 107 | | _pipeline.Send(message, cancellationToken); |
| 2 | 108 | | switch (message.Response.Status) |
| | 109 | | { |
| | 110 | | case 200: |
| | 111 | | { |
| 2 | 112 | | UsagesListResult value = default; |
| 2 | 113 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 114 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 115 | | { |
| 0 | 116 | | value = null; |
| | 117 | | } |
| | 118 | | else |
| | 119 | | { |
| 2 | 120 | | value = UsagesListResult.DeserializeUsagesListResult(document.RootElement); |
| | 121 | | } |
| 2 | 122 | | return Response.FromValue(value, message.Response); |
| | 123 | | } |
| | 124 | | default: |
| 0 | 125 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 126 | | } |
| 2 | 127 | | } |
| | 128 | |
|
| | 129 | | internal HttpMessage CreateListNextPageRequest(string nextLink, string location) |
| | 130 | | { |
| 0 | 131 | | var message = _pipeline.CreateMessage(); |
| 0 | 132 | | var request = message.Request; |
| 0 | 133 | | request.Method = RequestMethod.Get; |
| 0 | 134 | | var uri = new RawRequestUriBuilder(); |
| 0 | 135 | | uri.Reset(endpoint); |
| 0 | 136 | | uri.AppendRawNextLink(nextLink, false); |
| 0 | 137 | | request.Uri = uri; |
| 0 | 138 | | return message; |
| | 139 | | } |
| | 140 | |
|
| | 141 | | /// <summary> List network usages for a subscription. </summary> |
| | 142 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 143 | | /// <param name="location"> The location where resource usage is queried. </param> |
| | 144 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 145 | | public async Task<Response<UsagesListResult>> ListNextPageAsync(string nextLink, string location, CancellationTo |
| | 146 | | { |
| 0 | 147 | | if (nextLink == null) |
| | 148 | | { |
| 0 | 149 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 150 | | } |
| 0 | 151 | | if (location == null) |
| | 152 | | { |
| 0 | 153 | | throw new ArgumentNullException(nameof(location)); |
| | 154 | | } |
| | 155 | |
|
| 0 | 156 | | using var message = CreateListNextPageRequest(nextLink, location); |
| 0 | 157 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 158 | | switch (message.Response.Status) |
| | 159 | | { |
| | 160 | | case 200: |
| | 161 | | { |
| 0 | 162 | | UsagesListResult value = default; |
| 0 | 163 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 164 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 165 | | { |
| 0 | 166 | | value = null; |
| | 167 | | } |
| | 168 | | else |
| | 169 | | { |
| 0 | 170 | | value = UsagesListResult.DeserializeUsagesListResult(document.RootElement); |
| | 171 | | } |
| 0 | 172 | | return Response.FromValue(value, message.Response); |
| | 173 | | } |
| | 174 | | default: |
| 0 | 175 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 176 | | } |
| 0 | 177 | | } |
| | 178 | |
|
| | 179 | | /// <summary> List network usages for a subscription. </summary> |
| | 180 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 181 | | /// <param name="location"> The location where resource usage is queried. </param> |
| | 182 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 183 | | public Response<UsagesListResult> ListNextPage(string nextLink, string location, CancellationToken cancellationT |
| | 184 | | { |
| 0 | 185 | | if (nextLink == null) |
| | 186 | | { |
| 0 | 187 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 188 | | } |
| 0 | 189 | | if (location == null) |
| | 190 | | { |
| 0 | 191 | | throw new ArgumentNullException(nameof(location)); |
| | 192 | | } |
| | 193 | |
|
| 0 | 194 | | using var message = CreateListNextPageRequest(nextLink, location); |
| 0 | 195 | | _pipeline.Send(message, cancellationToken); |
| 0 | 196 | | switch (message.Response.Status) |
| | 197 | | { |
| | 198 | | case 200: |
| | 199 | | { |
| 0 | 200 | | UsagesListResult value = default; |
| 0 | 201 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 202 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 203 | | { |
| 0 | 204 | | value = null; |
| | 205 | | } |
| | 206 | | else |
| | 207 | | { |
| 0 | 208 | | value = UsagesListResult.DeserializeUsagesListResult(document.RootElement); |
| | 209 | | } |
| 0 | 210 | | return Response.FromValue(value, message.Response); |
| | 211 | | } |
| | 212 | | default: |
| 0 | 213 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 214 | | } |
| 0 | 215 | | } |
| | 216 | | } |
| | 217 | | } |