|   |  | 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 VirtualMachineRunCommandsRestOperations | 
|   |  | 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 VirtualMachineRunCommandsRestOperations. </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"> Subscription credentials which uniquely identify Microsoft Azure subscription. | 
|   |  | 30 |  |         /// <param name="endpoint"> server parameter. </param> | 
|   |  | 31 |  |         /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception | 
|   | 396 | 32 |  |         public VirtualMachineRunCommandsRestOperations(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, strin | 
|   |  | 33 |  |         { | 
|   | 396 | 34 |  |             if (subscriptionId == null) | 
|   |  | 35 |  |             { | 
|   | 0 | 36 |  |                 throw new ArgumentNullException(nameof(subscriptionId)); | 
|   |  | 37 |  |             } | 
|   | 396 | 38 |  |             endpoint ??= new Uri("https://management.azure.com"); | 
|   |  | 39 |  |  | 
|   | 396 | 40 |  |             this.subscriptionId = subscriptionId; | 
|   | 396 | 41 |  |             this.endpoint = endpoint; | 
|   | 396 | 42 |  |             _clientDiagnostics = clientDiagnostics; | 
|   | 396 | 43 |  |             _pipeline = pipeline; | 
|   | 396 | 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.Compute/locations/", false); | 
|   | 4 | 56 |  |             uri.AppendPath(location, true); | 
|   | 4 | 57 |  |             uri.AppendPath("/runCommands", false); | 
|   | 4 | 58 |  |             uri.AppendQuery("api-version", "2019-12-01", true); | 
|   | 4 | 59 |  |             request.Uri = uri; | 
|   | 4 | 60 |  |             return message; | 
|   |  | 61 |  |         } | 
|   |  | 62 |  |  | 
|   |  | 63 |  |         /// <summary> Lists all available run commands for a subscription in a location. </summary> | 
|   |  | 64 |  |         /// <param name="location"> The location upon which run commands is queried. </param> | 
|   |  | 65 |  |         /// <param name="cancellationToken"> The cancellation token to use. </param> | 
|   |  | 66 |  |         public async Task<Response<RunCommandListResult>> ListAsync(string location, CancellationToken cancellationToken | 
|   |  | 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 |  |                         RunCommandListResult 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 = RunCommandListResult.DeserializeRunCommandListResult(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> Lists all available run commands for a subscription in a location. </summary> | 
|   |  | 97 |  |         /// <param name="location"> The location upon which run commands is queried. </param> | 
|   |  | 98 |  |         /// <param name="cancellationToken"> The cancellation token to use. </param> | 
|   |  | 99 |  |         public Response<RunCommandListResult> 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 |  |                         RunCommandListResult 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 = RunCommandListResult.DeserializeRunCommandListResult(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 CreateGetRequest(string location, string commandId) | 
|   |  | 130 |  |         { | 
|   | 4 | 131 |  |             var message = _pipeline.CreateMessage(); | 
|   | 4 | 132 |  |             var request = message.Request; | 
|   | 4 | 133 |  |             request.Method = RequestMethod.Get; | 
|   | 4 | 134 |  |             var uri = new RawRequestUriBuilder(); | 
|   | 4 | 135 |  |             uri.Reset(endpoint); | 
|   | 4 | 136 |  |             uri.AppendPath("/subscriptions/", false); | 
|   | 4 | 137 |  |             uri.AppendPath(subscriptionId, true); | 
|   | 4 | 138 |  |             uri.AppendPath("/providers/Microsoft.Compute/locations/", false); | 
|   | 4 | 139 |  |             uri.AppendPath(location, true); | 
|   | 4 | 140 |  |             uri.AppendPath("/runCommands/", false); | 
|   | 4 | 141 |  |             uri.AppendPath(commandId, true); | 
|   | 4 | 142 |  |             uri.AppendQuery("api-version", "2019-12-01", true); | 
|   | 4 | 143 |  |             request.Uri = uri; | 
|   | 4 | 144 |  |             return message; | 
|   |  | 145 |  |         } | 
|   |  | 146 |  |  | 
|   |  | 147 |  |         /// <summary> Gets specific run command for a subscription in a location. </summary> | 
|   |  | 148 |  |         /// <param name="location"> The location upon which run commands is queried. </param> | 
|   |  | 149 |  |         /// <param name="commandId"> The command id. </param> | 
|   |  | 150 |  |         /// <param name="cancellationToken"> The cancellation token to use. </param> | 
|   |  | 151 |  |         public async Task<Response<RunCommandDocument>> GetAsync(string location, string commandId, CancellationToken ca | 
|   |  | 152 |  |         { | 
|   | 2 | 153 |  |             if (location == null) | 
|   |  | 154 |  |             { | 
|   | 0 | 155 |  |                 throw new ArgumentNullException(nameof(location)); | 
|   |  | 156 |  |             } | 
|   | 2 | 157 |  |             if (commandId == null) | 
|   |  | 158 |  |             { | 
|   | 0 | 159 |  |                 throw new ArgumentNullException(nameof(commandId)); | 
|   |  | 160 |  |             } | 
|   |  | 161 |  |  | 
|   | 2 | 162 |  |             using var message = CreateGetRequest(location, commandId); | 
|   | 2 | 163 |  |             await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); | 
|   | 2 | 164 |  |             switch (message.Response.Status) | 
|   |  | 165 |  |             { | 
|   |  | 166 |  |                 case 200: | 
|   |  | 167 |  |                     { | 
|   | 2 | 168 |  |                         RunCommandDocument value = default; | 
|   | 2 | 169 |  |                         using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc | 
|   | 2 | 170 |  |                         if (document.RootElement.ValueKind == JsonValueKind.Null) | 
|   |  | 171 |  |                         { | 
|   | 0 | 172 |  |                             value = null; | 
|   |  | 173 |  |                         } | 
|   |  | 174 |  |                         else | 
|   |  | 175 |  |                         { | 
|   | 2 | 176 |  |                             value = RunCommandDocument.DeserializeRunCommandDocument(document.RootElement); | 
|   |  | 177 |  |                         } | 
|   | 2 | 178 |  |                         return Response.FromValue(value, message.Response); | 
|   |  | 179 |  |                     } | 
|   |  | 180 |  |                 default: | 
|   | 0 | 181 |  |                     throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa | 
|   |  | 182 |  |             } | 
|   | 2 | 183 |  |         } | 
|   |  | 184 |  |  | 
|   |  | 185 |  |         /// <summary> Gets specific run command for a subscription in a location. </summary> | 
|   |  | 186 |  |         /// <param name="location"> The location upon which run commands is queried. </param> | 
|   |  | 187 |  |         /// <param name="commandId"> The command id. </param> | 
|   |  | 188 |  |         /// <param name="cancellationToken"> The cancellation token to use. </param> | 
|   |  | 189 |  |         public Response<RunCommandDocument> Get(string location, string commandId, CancellationToken cancellationToken = | 
|   |  | 190 |  |         { | 
|   | 2 | 191 |  |             if (location == null) | 
|   |  | 192 |  |             { | 
|   | 0 | 193 |  |                 throw new ArgumentNullException(nameof(location)); | 
|   |  | 194 |  |             } | 
|   | 2 | 195 |  |             if (commandId == null) | 
|   |  | 196 |  |             { | 
|   | 0 | 197 |  |                 throw new ArgumentNullException(nameof(commandId)); | 
|   |  | 198 |  |             } | 
|   |  | 199 |  |  | 
|   | 2 | 200 |  |             using var message = CreateGetRequest(location, commandId); | 
|   | 2 | 201 |  |             _pipeline.Send(message, cancellationToken); | 
|   | 2 | 202 |  |             switch (message.Response.Status) | 
|   |  | 203 |  |             { | 
|   |  | 204 |  |                 case 200: | 
|   |  | 205 |  |                     { | 
|   | 2 | 206 |  |                         RunCommandDocument value = default; | 
|   | 2 | 207 |  |                         using var document = JsonDocument.Parse(message.Response.ContentStream); | 
|   | 2 | 208 |  |                         if (document.RootElement.ValueKind == JsonValueKind.Null) | 
|   |  | 209 |  |                         { | 
|   | 0 | 210 |  |                             value = null; | 
|   |  | 211 |  |                         } | 
|   |  | 212 |  |                         else | 
|   |  | 213 |  |                         { | 
|   | 2 | 214 |  |                             value = RunCommandDocument.DeserializeRunCommandDocument(document.RootElement); | 
|   |  | 215 |  |                         } | 
|   | 2 | 216 |  |                         return Response.FromValue(value, message.Response); | 
|   |  | 217 |  |                     } | 
|   |  | 218 |  |                 default: | 
|   | 0 | 219 |  |                     throw _clientDiagnostics.CreateRequestFailedException(message.Response); | 
|   |  | 220 |  |             } | 
|   | 2 | 221 |  |         } | 
|   |  | 222 |  |  | 
|   |  | 223 |  |         internal HttpMessage CreateListNextPageRequest(string nextLink, string location) | 
|   |  | 224 |  |         { | 
|   | 0 | 225 |  |             var message = _pipeline.CreateMessage(); | 
|   | 0 | 226 |  |             var request = message.Request; | 
|   | 0 | 227 |  |             request.Method = RequestMethod.Get; | 
|   | 0 | 228 |  |             var uri = new RawRequestUriBuilder(); | 
|   | 0 | 229 |  |             uri.Reset(endpoint); | 
|   | 0 | 230 |  |             uri.AppendRawNextLink(nextLink, false); | 
|   | 0 | 231 |  |             request.Uri = uri; | 
|   | 0 | 232 |  |             return message; | 
|   |  | 233 |  |         } | 
|   |  | 234 |  |  | 
|   |  | 235 |  |         /// <summary> Lists all available run commands for a subscription in a location. </summary> | 
|   |  | 236 |  |         /// <param name="nextLink"> The URL to the next page of results. </param> | 
|   |  | 237 |  |         /// <param name="location"> The location upon which run commands is queried. </param> | 
|   |  | 238 |  |         /// <param name="cancellationToken"> The cancellation token to use. </param> | 
|   |  | 239 |  |         public async Task<Response<RunCommandListResult>> ListNextPageAsync(string nextLink, string location, Cancellati | 
|   |  | 240 |  |         { | 
|   | 0 | 241 |  |             if (nextLink == null) | 
|   |  | 242 |  |             { | 
|   | 0 | 243 |  |                 throw new ArgumentNullException(nameof(nextLink)); | 
|   |  | 244 |  |             } | 
|   | 0 | 245 |  |             if (location == null) | 
|   |  | 246 |  |             { | 
|   | 0 | 247 |  |                 throw new ArgumentNullException(nameof(location)); | 
|   |  | 248 |  |             } | 
|   |  | 249 |  |  | 
|   | 0 | 250 |  |             using var message = CreateListNextPageRequest(nextLink, location); | 
|   | 0 | 251 |  |             await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); | 
|   | 0 | 252 |  |             switch (message.Response.Status) | 
|   |  | 253 |  |             { | 
|   |  | 254 |  |                 case 200: | 
|   |  | 255 |  |                     { | 
|   | 0 | 256 |  |                         RunCommandListResult value = default; | 
|   | 0 | 257 |  |                         using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc | 
|   | 0 | 258 |  |                         if (document.RootElement.ValueKind == JsonValueKind.Null) | 
|   |  | 259 |  |                         { | 
|   | 0 | 260 |  |                             value = null; | 
|   |  | 261 |  |                         } | 
|   |  | 262 |  |                         else | 
|   |  | 263 |  |                         { | 
|   | 0 | 264 |  |                             value = RunCommandListResult.DeserializeRunCommandListResult(document.RootElement); | 
|   |  | 265 |  |                         } | 
|   | 0 | 266 |  |                         return Response.FromValue(value, message.Response); | 
|   |  | 267 |  |                     } | 
|   |  | 268 |  |                 default: | 
|   | 0 | 269 |  |                     throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa | 
|   |  | 270 |  |             } | 
|   | 0 | 271 |  |         } | 
|   |  | 272 |  |  | 
|   |  | 273 |  |         /// <summary> Lists all available run commands for a subscription in a location. </summary> | 
|   |  | 274 |  |         /// <param name="nextLink"> The URL to the next page of results. </param> | 
|   |  | 275 |  |         /// <param name="location"> The location upon which run commands is queried. </param> | 
|   |  | 276 |  |         /// <param name="cancellationToken"> The cancellation token to use. </param> | 
|   |  | 277 |  |         public Response<RunCommandListResult> ListNextPage(string nextLink, string location, CancellationToken cancellat | 
|   |  | 278 |  |         { | 
|   | 0 | 279 |  |             if (nextLink == null) | 
|   |  | 280 |  |             { | 
|   | 0 | 281 |  |                 throw new ArgumentNullException(nameof(nextLink)); | 
|   |  | 282 |  |             } | 
|   | 0 | 283 |  |             if (location == null) | 
|   |  | 284 |  |             { | 
|   | 0 | 285 |  |                 throw new ArgumentNullException(nameof(location)); | 
|   |  | 286 |  |             } | 
|   |  | 287 |  |  | 
|   | 0 | 288 |  |             using var message = CreateListNextPageRequest(nextLink, location); | 
|   | 0 | 289 |  |             _pipeline.Send(message, cancellationToken); | 
|   | 0 | 290 |  |             switch (message.Response.Status) | 
|   |  | 291 |  |             { | 
|   |  | 292 |  |                 case 200: | 
|   |  | 293 |  |                     { | 
|   | 0 | 294 |  |                         RunCommandListResult value = default; | 
|   | 0 | 295 |  |                         using var document = JsonDocument.Parse(message.Response.ContentStream); | 
|   | 0 | 296 |  |                         if (document.RootElement.ValueKind == JsonValueKind.Null) | 
|   |  | 297 |  |                         { | 
|   | 0 | 298 |  |                             value = null; | 
|   |  | 299 |  |                         } | 
|   |  | 300 |  |                         else | 
|   |  | 301 |  |                         { | 
|   | 0 | 302 |  |                             value = RunCommandListResult.DeserializeRunCommandListResult(document.RootElement); | 
|   |  | 303 |  |                         } | 
|   | 0 | 304 |  |                         return Response.FromValue(value, message.Response); | 
|   |  | 305 |  |                     } | 
|   |  | 306 |  |                 default: | 
|   | 0 | 307 |  |                     throw _clientDiagnostics.CreateRequestFailedException(message.Response); | 
|   |  | 308 |  |             } | 
|   | 0 | 309 |  |         } | 
|   |  | 310 |  |     } | 
|   |  | 311 |  | } |