| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.Batch.Protocol |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Microsoft.Rest.Serialization; |
| | 16 | | using Models; |
| | 17 | | using Newtonsoft.Json; |
| | 18 | | using System.Collections; |
| | 19 | | using System.Collections.Generic; |
| | 20 | | using System.IO; |
| | 21 | | using System.Linq; |
| | 22 | | using System.Net; |
| | 23 | | using System.Net.Http; |
| | 24 | | using System.Threading; |
| | 25 | | using System.Threading.Tasks; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// ComputeNodeOperations operations. |
| | 29 | | /// </summary> |
| | 30 | | internal partial class ComputeNodeOperations : IServiceOperations<BatchServiceClient>, IComputeNodeOperations |
| | 31 | | { |
| | 32 | | /// <summary> |
| | 33 | | /// Initializes a new instance of the ComputeNodeOperations class. |
| | 34 | | /// </summary> |
| | 35 | | /// <param name='client'> |
| | 36 | | /// Reference to the service client. |
| | 37 | | /// </param> |
| | 38 | | /// <exception cref="System.ArgumentNullException"> |
| | 39 | | /// Thrown when a required parameter is null |
| | 40 | | /// </exception> |
| 148 | 41 | | internal ComputeNodeOperations(BatchServiceClient client) |
| | 42 | | { |
| 148 | 43 | | if (client == null) |
| | 44 | | { |
| 0 | 45 | | throw new System.ArgumentNullException("client"); |
| | 46 | | } |
| 148 | 47 | | Client = client; |
| 148 | 48 | | } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Gets a reference to the BatchServiceClient |
| | 52 | | /// </summary> |
| 0 | 53 | | public BatchServiceClient Client { get; private set; } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Adds a user Account to the specified Compute Node. |
| | 57 | | /// </summary> |
| | 58 | | /// <remarks> |
| | 59 | | /// You can add a user Account to a Compute Node only when it is in the idle or |
| | 60 | | /// running state. |
| | 61 | | /// </remarks> |
| | 62 | | /// <param name='poolId'> |
| | 63 | | /// The ID of the Pool that contains the Compute Node. |
| | 64 | | /// </param> |
| | 65 | | /// <param name='nodeId'> |
| | 66 | | /// The ID of the machine on which you want to create a user Account. |
| | 67 | | /// </param> |
| | 68 | | /// <param name='user'> |
| | 69 | | /// The user Account to be created. |
| | 70 | | /// </param> |
| | 71 | | /// <param name='computeNodeAddUserOptions'> |
| | 72 | | /// Additional parameters for the operation |
| | 73 | | /// </param> |
| | 74 | | /// <param name='customHeaders'> |
| | 75 | | /// Headers that will be added to request. |
| | 76 | | /// </param> |
| | 77 | | /// <param name='cancellationToken'> |
| | 78 | | /// The cancellation token. |
| | 79 | | /// </param> |
| | 80 | | /// <exception cref="BatchErrorException"> |
| | 81 | | /// Thrown when the operation returned an invalid status code |
| | 82 | | /// </exception> |
| | 83 | | /// <exception cref="ValidationException"> |
| | 84 | | /// Thrown when a required parameter is null |
| | 85 | | /// </exception> |
| | 86 | | /// <exception cref="System.ArgumentNullException"> |
| | 87 | | /// Thrown when a required parameter is null |
| | 88 | | /// </exception> |
| | 89 | | /// <return> |
| | 90 | | /// A response object containing the response body and response headers. |
| | 91 | | /// </return> |
| | 92 | | public async Task<AzureOperationHeaderResponse<ComputeNodeAddUserHeaders>> AddUserWithHttpMessagesAsync(string p |
| | 93 | | { |
| 0 | 94 | | if (Client.BatchUrl == null) |
| | 95 | | { |
| 0 | 96 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 97 | | } |
| 0 | 98 | | if (poolId == null) |
| | 99 | | { |
| 0 | 100 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 101 | | } |
| 0 | 102 | | if (nodeId == null) |
| | 103 | | { |
| 0 | 104 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 105 | | } |
| 0 | 106 | | if (user == null) |
| | 107 | | { |
| 0 | 108 | | throw new ValidationException(ValidationRules.CannotBeNull, "user"); |
| | 109 | | } |
| 0 | 110 | | if (Client.ApiVersion == null) |
| | 111 | | { |
| 0 | 112 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 113 | | } |
| 0 | 114 | | int? timeout = default(int?); |
| 0 | 115 | | if (computeNodeAddUserOptions != null) |
| | 116 | | { |
| 0 | 117 | | timeout = computeNodeAddUserOptions.Timeout; |
| | 118 | | } |
| 0 | 119 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 120 | | if (computeNodeAddUserOptions != null) |
| | 121 | | { |
| 0 | 122 | | clientRequestId = computeNodeAddUserOptions.ClientRequestId; |
| | 123 | | } |
| 0 | 124 | | bool? returnClientRequestId = default(bool?); |
| 0 | 125 | | if (computeNodeAddUserOptions != null) |
| | 126 | | { |
| 0 | 127 | | returnClientRequestId = computeNodeAddUserOptions.ReturnClientRequestId; |
| | 128 | | } |
| 0 | 129 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 130 | | if (computeNodeAddUserOptions != null) |
| | 131 | | { |
| 0 | 132 | | ocpDate = computeNodeAddUserOptions.OcpDate; |
| | 133 | | } |
| | 134 | | // Tracing |
| 0 | 135 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 136 | | string _invocationId = null; |
| 0 | 137 | | if (_shouldTrace) |
| | 138 | | { |
| 0 | 139 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 140 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 141 | | tracingParameters.Add("poolId", poolId); |
| 0 | 142 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 143 | | tracingParameters.Add("user", user); |
| 0 | 144 | | tracingParameters.Add("timeout", timeout); |
| 0 | 145 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 146 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 147 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 148 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 149 | | ServiceClientTracing.Enter(_invocationId, this, "AddUser", tracingParameters); |
| | 150 | | } |
| | 151 | | // Construct URL |
| 0 | 152 | | var _baseUrl = Client.BaseUri; |
| 0 | 153 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/users"; |
| 0 | 154 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 155 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 156 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 157 | | List<string> _queryParameters = new List<string>(); |
| 0 | 158 | | if (Client.ApiVersion != null) |
| | 159 | | { |
| 0 | 160 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 161 | | } |
| 0 | 162 | | if (timeout != null) |
| | 163 | | { |
| 0 | 164 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 165 | | } |
| 0 | 166 | | if (_queryParameters.Count > 0) |
| | 167 | | { |
| 0 | 168 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 169 | | } |
| | 170 | | // Create HTTP transport objects |
| 0 | 171 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 172 | | HttpResponseMessage _httpResponse = null; |
| 0 | 173 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 174 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 175 | | // Set Headers |
| 0 | 176 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 177 | | { |
| 0 | 178 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 179 | | } |
| 0 | 180 | | if (Client.AcceptLanguage != null) |
| | 181 | | { |
| 0 | 182 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 183 | | { |
| 0 | 184 | | _httpRequest.Headers.Remove("accept-language"); |
| | 185 | | } |
| 0 | 186 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 187 | | } |
| 0 | 188 | | if (clientRequestId != null) |
| | 189 | | { |
| 0 | 190 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 191 | | { |
| 0 | 192 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 193 | | } |
| 0 | 194 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 195 | | } |
| 0 | 196 | | if (returnClientRequestId != null) |
| | 197 | | { |
| 0 | 198 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 199 | | { |
| 0 | 200 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 201 | | } |
| 0 | 202 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 203 | | } |
| 0 | 204 | | if (ocpDate != null) |
| | 205 | | { |
| 0 | 206 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 207 | | { |
| 0 | 208 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 209 | | } |
| 0 | 210 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 211 | | } |
| | 212 | |
|
| | 213 | |
|
| 0 | 214 | | if (customHeaders != null) |
| | 215 | | { |
| 0 | 216 | | foreach(var _header in customHeaders) |
| | 217 | | { |
| 0 | 218 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 219 | | { |
| 0 | 220 | | _httpRequest.Headers.Remove(_header.Key); |
| | 221 | | } |
| 0 | 222 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 223 | | } |
| | 224 | | } |
| | 225 | |
|
| | 226 | | // Serialize Request |
| 0 | 227 | | string _requestContent = null; |
| 0 | 228 | | if(user != null) |
| | 229 | | { |
| 0 | 230 | | _requestContent = SafeJsonConvert.SerializeObject(user, Client.SerializationSettings); |
| 0 | 231 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 232 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 233 | | } |
| | 234 | | // Set Credentials |
| 0 | 235 | | if (Client.Credentials != null) |
| | 236 | | { |
| 0 | 237 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 238 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 239 | | } |
| | 240 | | // Send Request |
| 0 | 241 | | if (_shouldTrace) |
| | 242 | | { |
| 0 | 243 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 244 | | } |
| 0 | 245 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 246 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 247 | | if (_shouldTrace) |
| | 248 | | { |
| 0 | 249 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 250 | | } |
| 0 | 251 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 252 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 253 | | string _responseContent = null; |
| 0 | 254 | | if ((int)_statusCode != 201) |
| | 255 | | { |
| 0 | 256 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 257 | | try |
| | 258 | | { |
| 0 | 259 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 260 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 261 | | if (_errorBody != null) |
| | 262 | | { |
| 0 | 263 | | ex.Body = _errorBody; |
| | 264 | | } |
| 0 | 265 | | } |
| 0 | 266 | | catch (JsonException) |
| | 267 | | { |
| | 268 | | // Ignore the exception |
| 0 | 269 | | } |
| 0 | 270 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 271 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 272 | | if (_shouldTrace) |
| | 273 | | { |
| 0 | 274 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 275 | | } |
| 0 | 276 | | _httpRequest.Dispose(); |
| 0 | 277 | | if (_httpResponse != null) |
| | 278 | | { |
| 0 | 279 | | _httpResponse.Dispose(); |
| | 280 | | } |
| 0 | 281 | | throw ex; |
| | 282 | | } |
| | 283 | | // Create Result |
| 0 | 284 | | var _result = new AzureOperationHeaderResponse<ComputeNodeAddUserHeaders>(); |
| 0 | 285 | | _result.Request = _httpRequest; |
| 0 | 286 | | _result.Response = _httpResponse; |
| 0 | 287 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 288 | | { |
| 0 | 289 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 290 | | } |
| | 291 | | try |
| | 292 | | { |
| 0 | 293 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeAddUserHeaders>(JsonSerializer.Cr |
| 0 | 294 | | } |
| 0 | 295 | | catch (JsonException ex) |
| | 296 | | { |
| 0 | 297 | | _httpRequest.Dispose(); |
| 0 | 298 | | if (_httpResponse != null) |
| | 299 | | { |
| 0 | 300 | | _httpResponse.Dispose(); |
| | 301 | | } |
| 0 | 302 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 303 | | } |
| 0 | 304 | | if (_shouldTrace) |
| | 305 | | { |
| 0 | 306 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 307 | | } |
| 0 | 308 | | return _result; |
| 0 | 309 | | } |
| | 310 | |
|
| | 311 | | /// <summary> |
| | 312 | | /// Deletes a user Account from the specified Compute Node. |
| | 313 | | /// </summary> |
| | 314 | | /// <remarks> |
| | 315 | | /// You can delete a user Account to a Compute Node only when it is in the idle |
| | 316 | | /// or running state. |
| | 317 | | /// </remarks> |
| | 318 | | /// <param name='poolId'> |
| | 319 | | /// The ID of the Pool that contains the Compute Node. |
| | 320 | | /// </param> |
| | 321 | | /// <param name='nodeId'> |
| | 322 | | /// The ID of the machine on which you want to delete a user Account. |
| | 323 | | /// </param> |
| | 324 | | /// <param name='userName'> |
| | 325 | | /// The name of the user Account to delete. |
| | 326 | | /// </param> |
| | 327 | | /// <param name='computeNodeDeleteUserOptions'> |
| | 328 | | /// Additional parameters for the operation |
| | 329 | | /// </param> |
| | 330 | | /// <param name='customHeaders'> |
| | 331 | | /// Headers that will be added to request. |
| | 332 | | /// </param> |
| | 333 | | /// <param name='cancellationToken'> |
| | 334 | | /// The cancellation token. |
| | 335 | | /// </param> |
| | 336 | | /// <exception cref="BatchErrorException"> |
| | 337 | | /// Thrown when the operation returned an invalid status code |
| | 338 | | /// </exception> |
| | 339 | | /// <exception cref="ValidationException"> |
| | 340 | | /// Thrown when a required parameter is null |
| | 341 | | /// </exception> |
| | 342 | | /// <exception cref="System.ArgumentNullException"> |
| | 343 | | /// Thrown when a required parameter is null |
| | 344 | | /// </exception> |
| | 345 | | /// <return> |
| | 346 | | /// A response object containing the response body and response headers. |
| | 347 | | /// </return> |
| | 348 | | public async Task<AzureOperationHeaderResponse<ComputeNodeDeleteUserHeaders>> DeleteUserWithHttpMessagesAsync(st |
| | 349 | | { |
| 0 | 350 | | if (Client.BatchUrl == null) |
| | 351 | | { |
| 0 | 352 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 353 | | } |
| 0 | 354 | | if (poolId == null) |
| | 355 | | { |
| 0 | 356 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 357 | | } |
| 0 | 358 | | if (nodeId == null) |
| | 359 | | { |
| 0 | 360 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 361 | | } |
| 0 | 362 | | if (userName == null) |
| | 363 | | { |
| 0 | 364 | | throw new ValidationException(ValidationRules.CannotBeNull, "userName"); |
| | 365 | | } |
| 0 | 366 | | if (Client.ApiVersion == null) |
| | 367 | | { |
| 0 | 368 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 369 | | } |
| 0 | 370 | | int? timeout = default(int?); |
| 0 | 371 | | if (computeNodeDeleteUserOptions != null) |
| | 372 | | { |
| 0 | 373 | | timeout = computeNodeDeleteUserOptions.Timeout; |
| | 374 | | } |
| 0 | 375 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 376 | | if (computeNodeDeleteUserOptions != null) |
| | 377 | | { |
| 0 | 378 | | clientRequestId = computeNodeDeleteUserOptions.ClientRequestId; |
| | 379 | | } |
| 0 | 380 | | bool? returnClientRequestId = default(bool?); |
| 0 | 381 | | if (computeNodeDeleteUserOptions != null) |
| | 382 | | { |
| 0 | 383 | | returnClientRequestId = computeNodeDeleteUserOptions.ReturnClientRequestId; |
| | 384 | | } |
| 0 | 385 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 386 | | if (computeNodeDeleteUserOptions != null) |
| | 387 | | { |
| 0 | 388 | | ocpDate = computeNodeDeleteUserOptions.OcpDate; |
| | 389 | | } |
| | 390 | | // Tracing |
| 0 | 391 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 392 | | string _invocationId = null; |
| 0 | 393 | | if (_shouldTrace) |
| | 394 | | { |
| 0 | 395 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 396 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 397 | | tracingParameters.Add("poolId", poolId); |
| 0 | 398 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 399 | | tracingParameters.Add("userName", userName); |
| 0 | 400 | | tracingParameters.Add("timeout", timeout); |
| 0 | 401 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 402 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 403 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 404 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 405 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteUser", tracingParameters); |
| | 406 | | } |
| | 407 | | // Construct URL |
| 0 | 408 | | var _baseUrl = Client.BaseUri; |
| 0 | 409 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/users/{userName}" |
| 0 | 410 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 411 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 412 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 413 | | _url = _url.Replace("{userName}", System.Uri.EscapeDataString(userName)); |
| 0 | 414 | | List<string> _queryParameters = new List<string>(); |
| 0 | 415 | | if (Client.ApiVersion != null) |
| | 416 | | { |
| 0 | 417 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 418 | | } |
| 0 | 419 | | if (timeout != null) |
| | 420 | | { |
| 0 | 421 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 422 | | } |
| 0 | 423 | | if (_queryParameters.Count > 0) |
| | 424 | | { |
| 0 | 425 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 426 | | } |
| | 427 | | // Create HTTP transport objects |
| 0 | 428 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 429 | | HttpResponseMessage _httpResponse = null; |
| 0 | 430 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 431 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 432 | | // Set Headers |
| 0 | 433 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 434 | | { |
| 0 | 435 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 436 | | } |
| 0 | 437 | | if (Client.AcceptLanguage != null) |
| | 438 | | { |
| 0 | 439 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 440 | | { |
| 0 | 441 | | _httpRequest.Headers.Remove("accept-language"); |
| | 442 | | } |
| 0 | 443 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 444 | | } |
| 0 | 445 | | if (clientRequestId != null) |
| | 446 | | { |
| 0 | 447 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 448 | | { |
| 0 | 449 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 450 | | } |
| 0 | 451 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 452 | | } |
| 0 | 453 | | if (returnClientRequestId != null) |
| | 454 | | { |
| 0 | 455 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 456 | | { |
| 0 | 457 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 458 | | } |
| 0 | 459 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 460 | | } |
| 0 | 461 | | if (ocpDate != null) |
| | 462 | | { |
| 0 | 463 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 464 | | { |
| 0 | 465 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 466 | | } |
| 0 | 467 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 468 | | } |
| | 469 | |
|
| | 470 | |
|
| 0 | 471 | | if (customHeaders != null) |
| | 472 | | { |
| 0 | 473 | | foreach(var _header in customHeaders) |
| | 474 | | { |
| 0 | 475 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 476 | | { |
| 0 | 477 | | _httpRequest.Headers.Remove(_header.Key); |
| | 478 | | } |
| 0 | 479 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 480 | | } |
| | 481 | | } |
| | 482 | |
|
| | 483 | | // Serialize Request |
| 0 | 484 | | string _requestContent = null; |
| | 485 | | // Set Credentials |
| 0 | 486 | | if (Client.Credentials != null) |
| | 487 | | { |
| 0 | 488 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 489 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 490 | | } |
| | 491 | | // Send Request |
| 0 | 492 | | if (_shouldTrace) |
| | 493 | | { |
| 0 | 494 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 495 | | } |
| 0 | 496 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 497 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 498 | | if (_shouldTrace) |
| | 499 | | { |
| 0 | 500 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 501 | | } |
| 0 | 502 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 503 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 504 | | string _responseContent = null; |
| 0 | 505 | | if ((int)_statusCode != 200) |
| | 506 | | { |
| 0 | 507 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 508 | | try |
| | 509 | | { |
| 0 | 510 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 511 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 512 | | if (_errorBody != null) |
| | 513 | | { |
| 0 | 514 | | ex.Body = _errorBody; |
| | 515 | | } |
| 0 | 516 | | } |
| 0 | 517 | | catch (JsonException) |
| | 518 | | { |
| | 519 | | // Ignore the exception |
| 0 | 520 | | } |
| 0 | 521 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 522 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 523 | | if (_shouldTrace) |
| | 524 | | { |
| 0 | 525 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 526 | | } |
| 0 | 527 | | _httpRequest.Dispose(); |
| 0 | 528 | | if (_httpResponse != null) |
| | 529 | | { |
| 0 | 530 | | _httpResponse.Dispose(); |
| | 531 | | } |
| 0 | 532 | | throw ex; |
| | 533 | | } |
| | 534 | | // Create Result |
| 0 | 535 | | var _result = new AzureOperationHeaderResponse<ComputeNodeDeleteUserHeaders>(); |
| 0 | 536 | | _result.Request = _httpRequest; |
| 0 | 537 | | _result.Response = _httpResponse; |
| 0 | 538 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 539 | | { |
| 0 | 540 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 541 | | } |
| | 542 | | try |
| | 543 | | { |
| 0 | 544 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeDeleteUserHeaders>(JsonSerializer |
| 0 | 545 | | } |
| 0 | 546 | | catch (JsonException ex) |
| | 547 | | { |
| 0 | 548 | | _httpRequest.Dispose(); |
| 0 | 549 | | if (_httpResponse != null) |
| | 550 | | { |
| 0 | 551 | | _httpResponse.Dispose(); |
| | 552 | | } |
| 0 | 553 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 554 | | } |
| 0 | 555 | | if (_shouldTrace) |
| | 556 | | { |
| 0 | 557 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 558 | | } |
| 0 | 559 | | return _result; |
| 0 | 560 | | } |
| | 561 | |
|
| | 562 | | /// <summary> |
| | 563 | | /// Updates the password and expiration time of a user Account on the specified |
| | 564 | | /// Compute Node. |
| | 565 | | /// </summary> |
| | 566 | | /// <remarks> |
| | 567 | | /// This operation replaces of all the updatable properties of the Account. For |
| | 568 | | /// example, if the expiryTime element is not specified, the current value is |
| | 569 | | /// replaced with the default value, not left unmodified. You can update a user |
| | 570 | | /// Account on a Compute Node only when it is in the idle or running state. |
| | 571 | | /// </remarks> |
| | 572 | | /// <param name='poolId'> |
| | 573 | | /// The ID of the Pool that contains the Compute Node. |
| | 574 | | /// </param> |
| | 575 | | /// <param name='nodeId'> |
| | 576 | | /// The ID of the machine on which you want to update a user Account. |
| | 577 | | /// </param> |
| | 578 | | /// <param name='userName'> |
| | 579 | | /// The name of the user Account to update. |
| | 580 | | /// </param> |
| | 581 | | /// <param name='nodeUpdateUserParameter'> |
| | 582 | | /// The parameters for the request. |
| | 583 | | /// </param> |
| | 584 | | /// <param name='computeNodeUpdateUserOptions'> |
| | 585 | | /// Additional parameters for the operation |
| | 586 | | /// </param> |
| | 587 | | /// <param name='customHeaders'> |
| | 588 | | /// Headers that will be added to request. |
| | 589 | | /// </param> |
| | 590 | | /// <param name='cancellationToken'> |
| | 591 | | /// The cancellation token. |
| | 592 | | /// </param> |
| | 593 | | /// <exception cref="BatchErrorException"> |
| | 594 | | /// Thrown when the operation returned an invalid status code |
| | 595 | | /// </exception> |
| | 596 | | /// <exception cref="ValidationException"> |
| | 597 | | /// Thrown when a required parameter is null |
| | 598 | | /// </exception> |
| | 599 | | /// <exception cref="System.ArgumentNullException"> |
| | 600 | | /// Thrown when a required parameter is null |
| | 601 | | /// </exception> |
| | 602 | | /// <return> |
| | 603 | | /// A response object containing the response body and response headers. |
| | 604 | | /// </return> |
| | 605 | | public async Task<AzureOperationHeaderResponse<ComputeNodeUpdateUserHeaders>> UpdateUserWithHttpMessagesAsync(st |
| | 606 | | { |
| 0 | 607 | | if (Client.BatchUrl == null) |
| | 608 | | { |
| 0 | 609 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 610 | | } |
| 0 | 611 | | if (poolId == null) |
| | 612 | | { |
| 0 | 613 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 614 | | } |
| 0 | 615 | | if (nodeId == null) |
| | 616 | | { |
| 0 | 617 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 618 | | } |
| 0 | 619 | | if (userName == null) |
| | 620 | | { |
| 0 | 621 | | throw new ValidationException(ValidationRules.CannotBeNull, "userName"); |
| | 622 | | } |
| 0 | 623 | | if (nodeUpdateUserParameter == null) |
| | 624 | | { |
| 0 | 625 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeUpdateUserParameter"); |
| | 626 | | } |
| 0 | 627 | | if (Client.ApiVersion == null) |
| | 628 | | { |
| 0 | 629 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 630 | | } |
| 0 | 631 | | int? timeout = default(int?); |
| 0 | 632 | | if (computeNodeUpdateUserOptions != null) |
| | 633 | | { |
| 0 | 634 | | timeout = computeNodeUpdateUserOptions.Timeout; |
| | 635 | | } |
| 0 | 636 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 637 | | if (computeNodeUpdateUserOptions != null) |
| | 638 | | { |
| 0 | 639 | | clientRequestId = computeNodeUpdateUserOptions.ClientRequestId; |
| | 640 | | } |
| 0 | 641 | | bool? returnClientRequestId = default(bool?); |
| 0 | 642 | | if (computeNodeUpdateUserOptions != null) |
| | 643 | | { |
| 0 | 644 | | returnClientRequestId = computeNodeUpdateUserOptions.ReturnClientRequestId; |
| | 645 | | } |
| 0 | 646 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 647 | | if (computeNodeUpdateUserOptions != null) |
| | 648 | | { |
| 0 | 649 | | ocpDate = computeNodeUpdateUserOptions.OcpDate; |
| | 650 | | } |
| | 651 | | // Tracing |
| 0 | 652 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 653 | | string _invocationId = null; |
| 0 | 654 | | if (_shouldTrace) |
| | 655 | | { |
| 0 | 656 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 657 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 658 | | tracingParameters.Add("poolId", poolId); |
| 0 | 659 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 660 | | tracingParameters.Add("userName", userName); |
| 0 | 661 | | tracingParameters.Add("nodeUpdateUserParameter", nodeUpdateUserParameter); |
| 0 | 662 | | tracingParameters.Add("timeout", timeout); |
| 0 | 663 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 664 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 665 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 666 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 667 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateUser", tracingParameters); |
| | 668 | | } |
| | 669 | | // Construct URL |
| 0 | 670 | | var _baseUrl = Client.BaseUri; |
| 0 | 671 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/users/{userName}" |
| 0 | 672 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 673 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 674 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 675 | | _url = _url.Replace("{userName}", System.Uri.EscapeDataString(userName)); |
| 0 | 676 | | List<string> _queryParameters = new List<string>(); |
| 0 | 677 | | if (Client.ApiVersion != null) |
| | 678 | | { |
| 0 | 679 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 680 | | } |
| 0 | 681 | | if (timeout != null) |
| | 682 | | { |
| 0 | 683 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 684 | | } |
| 0 | 685 | | if (_queryParameters.Count > 0) |
| | 686 | | { |
| 0 | 687 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 688 | | } |
| | 689 | | // Create HTTP transport objects |
| 0 | 690 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 691 | | HttpResponseMessage _httpResponse = null; |
| 0 | 692 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 0 | 693 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 694 | | // Set Headers |
| 0 | 695 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 696 | | { |
| 0 | 697 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 698 | | } |
| 0 | 699 | | if (Client.AcceptLanguage != null) |
| | 700 | | { |
| 0 | 701 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 702 | | { |
| 0 | 703 | | _httpRequest.Headers.Remove("accept-language"); |
| | 704 | | } |
| 0 | 705 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 706 | | } |
| 0 | 707 | | if (clientRequestId != null) |
| | 708 | | { |
| 0 | 709 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 710 | | { |
| 0 | 711 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 712 | | } |
| 0 | 713 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 714 | | } |
| 0 | 715 | | if (returnClientRequestId != null) |
| | 716 | | { |
| 0 | 717 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 718 | | { |
| 0 | 719 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 720 | | } |
| 0 | 721 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 722 | | } |
| 0 | 723 | | if (ocpDate != null) |
| | 724 | | { |
| 0 | 725 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 726 | | { |
| 0 | 727 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 728 | | } |
| 0 | 729 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 730 | | } |
| | 731 | |
|
| | 732 | |
|
| 0 | 733 | | if (customHeaders != null) |
| | 734 | | { |
| 0 | 735 | | foreach(var _header in customHeaders) |
| | 736 | | { |
| 0 | 737 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 738 | | { |
| 0 | 739 | | _httpRequest.Headers.Remove(_header.Key); |
| | 740 | | } |
| 0 | 741 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 742 | | } |
| | 743 | | } |
| | 744 | |
|
| | 745 | | // Serialize Request |
| 0 | 746 | | string _requestContent = null; |
| 0 | 747 | | if(nodeUpdateUserParameter != null) |
| | 748 | | { |
| 0 | 749 | | _requestContent = SafeJsonConvert.SerializeObject(nodeUpdateUserParameter, Client.SerializationSettings) |
| 0 | 750 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 751 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 752 | | } |
| | 753 | | // Set Credentials |
| 0 | 754 | | if (Client.Credentials != null) |
| | 755 | | { |
| 0 | 756 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 757 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 758 | | } |
| | 759 | | // Send Request |
| 0 | 760 | | if (_shouldTrace) |
| | 761 | | { |
| 0 | 762 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 763 | | } |
| 0 | 764 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 765 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 766 | | if (_shouldTrace) |
| | 767 | | { |
| 0 | 768 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 769 | | } |
| 0 | 770 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 771 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 772 | | string _responseContent = null; |
| 0 | 773 | | if ((int)_statusCode != 200) |
| | 774 | | { |
| 0 | 775 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 776 | | try |
| | 777 | | { |
| 0 | 778 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 779 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 780 | | if (_errorBody != null) |
| | 781 | | { |
| 0 | 782 | | ex.Body = _errorBody; |
| | 783 | | } |
| 0 | 784 | | } |
| 0 | 785 | | catch (JsonException) |
| | 786 | | { |
| | 787 | | // Ignore the exception |
| 0 | 788 | | } |
| 0 | 789 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 790 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 791 | | if (_shouldTrace) |
| | 792 | | { |
| 0 | 793 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 794 | | } |
| 0 | 795 | | _httpRequest.Dispose(); |
| 0 | 796 | | if (_httpResponse != null) |
| | 797 | | { |
| 0 | 798 | | _httpResponse.Dispose(); |
| | 799 | | } |
| 0 | 800 | | throw ex; |
| | 801 | | } |
| | 802 | | // Create Result |
| 0 | 803 | | var _result = new AzureOperationHeaderResponse<ComputeNodeUpdateUserHeaders>(); |
| 0 | 804 | | _result.Request = _httpRequest; |
| 0 | 805 | | _result.Response = _httpResponse; |
| 0 | 806 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 807 | | { |
| 0 | 808 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 809 | | } |
| | 810 | | try |
| | 811 | | { |
| 0 | 812 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeUpdateUserHeaders>(JsonSerializer |
| 0 | 813 | | } |
| 0 | 814 | | catch (JsonException ex) |
| | 815 | | { |
| 0 | 816 | | _httpRequest.Dispose(); |
| 0 | 817 | | if (_httpResponse != null) |
| | 818 | | { |
| 0 | 819 | | _httpResponse.Dispose(); |
| | 820 | | } |
| 0 | 821 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 822 | | } |
| 0 | 823 | | if (_shouldTrace) |
| | 824 | | { |
| 0 | 825 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 826 | | } |
| 0 | 827 | | return _result; |
| 0 | 828 | | } |
| | 829 | |
|
| | 830 | | /// <summary> |
| | 831 | | /// Gets information about the specified Compute Node. |
| | 832 | | /// </summary> |
| | 833 | | /// <param name='poolId'> |
| | 834 | | /// The ID of the Pool that contains the Compute Node. |
| | 835 | | /// </param> |
| | 836 | | /// <param name='nodeId'> |
| | 837 | | /// The ID of the Compute Node that you want to get information about. |
| | 838 | | /// </param> |
| | 839 | | /// <param name='computeNodeGetOptions'> |
| | 840 | | /// Additional parameters for the operation |
| | 841 | | /// </param> |
| | 842 | | /// <param name='customHeaders'> |
| | 843 | | /// Headers that will be added to request. |
| | 844 | | /// </param> |
| | 845 | | /// <param name='cancellationToken'> |
| | 846 | | /// The cancellation token. |
| | 847 | | /// </param> |
| | 848 | | /// <exception cref="BatchErrorException"> |
| | 849 | | /// Thrown when the operation returned an invalid status code |
| | 850 | | /// </exception> |
| | 851 | | /// <exception cref="SerializationException"> |
| | 852 | | /// Thrown when unable to deserialize the response |
| | 853 | | /// </exception> |
| | 854 | | /// <exception cref="ValidationException"> |
| | 855 | | /// Thrown when a required parameter is null |
| | 856 | | /// </exception> |
| | 857 | | /// <exception cref="System.ArgumentNullException"> |
| | 858 | | /// Thrown when a required parameter is null |
| | 859 | | /// </exception> |
| | 860 | | /// <return> |
| | 861 | | /// A response object containing the response body and response headers. |
| | 862 | | /// </return> |
| | 863 | | public async Task<AzureOperationResponse<ComputeNode,ComputeNodeGetHeaders>> GetWithHttpMessagesAsync(string poo |
| | 864 | | { |
| 0 | 865 | | if (Client.BatchUrl == null) |
| | 866 | | { |
| 0 | 867 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 868 | | } |
| 0 | 869 | | if (poolId == null) |
| | 870 | | { |
| 0 | 871 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 872 | | } |
| 0 | 873 | | if (nodeId == null) |
| | 874 | | { |
| 0 | 875 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 876 | | } |
| 0 | 877 | | if (Client.ApiVersion == null) |
| | 878 | | { |
| 0 | 879 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 880 | | } |
| 0 | 881 | | string select = default(string); |
| 0 | 882 | | if (computeNodeGetOptions != null) |
| | 883 | | { |
| 0 | 884 | | select = computeNodeGetOptions.Select; |
| | 885 | | } |
| 0 | 886 | | int? timeout = default(int?); |
| 0 | 887 | | if (computeNodeGetOptions != null) |
| | 888 | | { |
| 0 | 889 | | timeout = computeNodeGetOptions.Timeout; |
| | 890 | | } |
| 0 | 891 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 892 | | if (computeNodeGetOptions != null) |
| | 893 | | { |
| 0 | 894 | | clientRequestId = computeNodeGetOptions.ClientRequestId; |
| | 895 | | } |
| 0 | 896 | | bool? returnClientRequestId = default(bool?); |
| 0 | 897 | | if (computeNodeGetOptions != null) |
| | 898 | | { |
| 0 | 899 | | returnClientRequestId = computeNodeGetOptions.ReturnClientRequestId; |
| | 900 | | } |
| 0 | 901 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 902 | | if (computeNodeGetOptions != null) |
| | 903 | | { |
| 0 | 904 | | ocpDate = computeNodeGetOptions.OcpDate; |
| | 905 | | } |
| | 906 | | // Tracing |
| 0 | 907 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 908 | | string _invocationId = null; |
| 0 | 909 | | if (_shouldTrace) |
| | 910 | | { |
| 0 | 911 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 912 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 913 | | tracingParameters.Add("poolId", poolId); |
| 0 | 914 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 915 | | tracingParameters.Add("select", select); |
| 0 | 916 | | tracingParameters.Add("timeout", timeout); |
| 0 | 917 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 918 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 919 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 920 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 921 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 922 | | } |
| | 923 | | // Construct URL |
| 0 | 924 | | var _baseUrl = Client.BaseUri; |
| 0 | 925 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}"; |
| 0 | 926 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 927 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 928 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 929 | | List<string> _queryParameters = new List<string>(); |
| 0 | 930 | | if (Client.ApiVersion != null) |
| | 931 | | { |
| 0 | 932 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 933 | | } |
| 0 | 934 | | if (select != null) |
| | 935 | | { |
| 0 | 936 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 937 | | } |
| 0 | 938 | | if (timeout != null) |
| | 939 | | { |
| 0 | 940 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 941 | | } |
| 0 | 942 | | if (_queryParameters.Count > 0) |
| | 943 | | { |
| 0 | 944 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 945 | | } |
| | 946 | | // Create HTTP transport objects |
| 0 | 947 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 948 | | HttpResponseMessage _httpResponse = null; |
| 0 | 949 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 950 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 951 | | // Set Headers |
| 0 | 952 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 953 | | { |
| 0 | 954 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 955 | | } |
| 0 | 956 | | if (Client.AcceptLanguage != null) |
| | 957 | | { |
| 0 | 958 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 959 | | { |
| 0 | 960 | | _httpRequest.Headers.Remove("accept-language"); |
| | 961 | | } |
| 0 | 962 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 963 | | } |
| 0 | 964 | | if (clientRequestId != null) |
| | 965 | | { |
| 0 | 966 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 967 | | { |
| 0 | 968 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 969 | | } |
| 0 | 970 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 971 | | } |
| 0 | 972 | | if (returnClientRequestId != null) |
| | 973 | | { |
| 0 | 974 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 975 | | { |
| 0 | 976 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 977 | | } |
| 0 | 978 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 979 | | } |
| 0 | 980 | | if (ocpDate != null) |
| | 981 | | { |
| 0 | 982 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 983 | | { |
| 0 | 984 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 985 | | } |
| 0 | 986 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 987 | | } |
| | 988 | |
|
| | 989 | |
|
| 0 | 990 | | if (customHeaders != null) |
| | 991 | | { |
| 0 | 992 | | foreach(var _header in customHeaders) |
| | 993 | | { |
| 0 | 994 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 995 | | { |
| 0 | 996 | | _httpRequest.Headers.Remove(_header.Key); |
| | 997 | | } |
| 0 | 998 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 999 | | } |
| | 1000 | | } |
| | 1001 | |
|
| | 1002 | | // Serialize Request |
| 0 | 1003 | | string _requestContent = null; |
| | 1004 | | // Set Credentials |
| 0 | 1005 | | if (Client.Credentials != null) |
| | 1006 | | { |
| 0 | 1007 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1008 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1009 | | } |
| | 1010 | | // Send Request |
| 0 | 1011 | | if (_shouldTrace) |
| | 1012 | | { |
| 0 | 1013 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1014 | | } |
| 0 | 1015 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1016 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1017 | | if (_shouldTrace) |
| | 1018 | | { |
| 0 | 1019 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1020 | | } |
| 0 | 1021 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1022 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1023 | | string _responseContent = null; |
| 0 | 1024 | | if ((int)_statusCode != 200) |
| | 1025 | | { |
| 0 | 1026 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1027 | | try |
| | 1028 | | { |
| 0 | 1029 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1030 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1031 | | if (_errorBody != null) |
| | 1032 | | { |
| 0 | 1033 | | ex.Body = _errorBody; |
| | 1034 | | } |
| 0 | 1035 | | } |
| 0 | 1036 | | catch (JsonException) |
| | 1037 | | { |
| | 1038 | | // Ignore the exception |
| 0 | 1039 | | } |
| 0 | 1040 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1041 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1042 | | if (_shouldTrace) |
| | 1043 | | { |
| 0 | 1044 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1045 | | } |
| 0 | 1046 | | _httpRequest.Dispose(); |
| 0 | 1047 | | if (_httpResponse != null) |
| | 1048 | | { |
| 0 | 1049 | | _httpResponse.Dispose(); |
| | 1050 | | } |
| 0 | 1051 | | throw ex; |
| | 1052 | | } |
| | 1053 | | // Create Result |
| 0 | 1054 | | var _result = new AzureOperationResponse<ComputeNode,ComputeNodeGetHeaders>(); |
| 0 | 1055 | | _result.Request = _httpRequest; |
| 0 | 1056 | | _result.Response = _httpResponse; |
| 0 | 1057 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1058 | | { |
| 0 | 1059 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1060 | | } |
| | 1061 | | // Deserialize Response |
| 0 | 1062 | | if ((int)_statusCode == 200) |
| | 1063 | | { |
| 0 | 1064 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1065 | | try |
| | 1066 | | { |
| 0 | 1067 | | _result.Body = SafeJsonConvert.DeserializeObject<ComputeNode>(_responseContent, Client.Deserializati |
| 0 | 1068 | | } |
| 0 | 1069 | | catch (JsonException ex) |
| | 1070 | | { |
| 0 | 1071 | | _httpRequest.Dispose(); |
| 0 | 1072 | | if (_httpResponse != null) |
| | 1073 | | { |
| 0 | 1074 | | _httpResponse.Dispose(); |
| | 1075 | | } |
| 0 | 1076 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1077 | | } |
| | 1078 | | } |
| | 1079 | | try |
| | 1080 | | { |
| 0 | 1081 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeGetHeaders>(JsonSerializer.Create |
| 0 | 1082 | | } |
| 0 | 1083 | | catch (JsonException ex) |
| | 1084 | | { |
| 0 | 1085 | | _httpRequest.Dispose(); |
| 0 | 1086 | | if (_httpResponse != null) |
| | 1087 | | { |
| 0 | 1088 | | _httpResponse.Dispose(); |
| | 1089 | | } |
| 0 | 1090 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1091 | | } |
| 0 | 1092 | | if (_shouldTrace) |
| | 1093 | | { |
| 0 | 1094 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1095 | | } |
| 0 | 1096 | | return _result; |
| 0 | 1097 | | } |
| | 1098 | |
|
| | 1099 | | /// <summary> |
| | 1100 | | /// Restarts the specified Compute Node. |
| | 1101 | | /// </summary> |
| | 1102 | | /// <remarks> |
| | 1103 | | /// You can restart a Compute Node only if it is in an idle or running state. |
| | 1104 | | /// </remarks> |
| | 1105 | | /// <param name='poolId'> |
| | 1106 | | /// The ID of the Pool that contains the Compute Node. |
| | 1107 | | /// </param> |
| | 1108 | | /// <param name='nodeId'> |
| | 1109 | | /// The ID of the Compute Node that you want to restart. |
| | 1110 | | /// </param> |
| | 1111 | | /// <param name='nodeRebootOption'> |
| | 1112 | | /// When to reboot the Compute Node and what to do with currently running |
| | 1113 | | /// Tasks. The default value is requeue. Possible values include: 'requeue', |
| | 1114 | | /// 'terminate', 'taskCompletion', 'retainedData' |
| | 1115 | | /// </param> |
| | 1116 | | /// <param name='computeNodeRebootOptions'> |
| | 1117 | | /// Additional parameters for the operation |
| | 1118 | | /// </param> |
| | 1119 | | /// <param name='customHeaders'> |
| | 1120 | | /// Headers that will be added to request. |
| | 1121 | | /// </param> |
| | 1122 | | /// <param name='cancellationToken'> |
| | 1123 | | /// The cancellation token. |
| | 1124 | | /// </param> |
| | 1125 | | /// <exception cref="BatchErrorException"> |
| | 1126 | | /// Thrown when the operation returned an invalid status code |
| | 1127 | | /// </exception> |
| | 1128 | | /// <exception cref="ValidationException"> |
| | 1129 | | /// Thrown when a required parameter is null |
| | 1130 | | /// </exception> |
| | 1131 | | /// <exception cref="System.ArgumentNullException"> |
| | 1132 | | /// Thrown when a required parameter is null |
| | 1133 | | /// </exception> |
| | 1134 | | /// <return> |
| | 1135 | | /// A response object containing the response body and response headers. |
| | 1136 | | /// </return> |
| | 1137 | | public async Task<AzureOperationHeaderResponse<ComputeNodeRebootHeaders>> RebootWithHttpMessagesAsync(string poo |
| | 1138 | | { |
| 0 | 1139 | | if (Client.BatchUrl == null) |
| | 1140 | | { |
| 0 | 1141 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1142 | | } |
| 0 | 1143 | | if (poolId == null) |
| | 1144 | | { |
| 0 | 1145 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 1146 | | } |
| 0 | 1147 | | if (nodeId == null) |
| | 1148 | | { |
| 0 | 1149 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 1150 | | } |
| 0 | 1151 | | if (Client.ApiVersion == null) |
| | 1152 | | { |
| 0 | 1153 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1154 | | } |
| 0 | 1155 | | int? timeout = default(int?); |
| 0 | 1156 | | if (computeNodeRebootOptions != null) |
| | 1157 | | { |
| 0 | 1158 | | timeout = computeNodeRebootOptions.Timeout; |
| | 1159 | | } |
| 0 | 1160 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1161 | | if (computeNodeRebootOptions != null) |
| | 1162 | | { |
| 0 | 1163 | | clientRequestId = computeNodeRebootOptions.ClientRequestId; |
| | 1164 | | } |
| 0 | 1165 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1166 | | if (computeNodeRebootOptions != null) |
| | 1167 | | { |
| 0 | 1168 | | returnClientRequestId = computeNodeRebootOptions.ReturnClientRequestId; |
| | 1169 | | } |
| 0 | 1170 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1171 | | if (computeNodeRebootOptions != null) |
| | 1172 | | { |
| 0 | 1173 | | ocpDate = computeNodeRebootOptions.OcpDate; |
| | 1174 | | } |
| 0 | 1175 | | NodeRebootParameter nodeRebootParameter = default(NodeRebootParameter); |
| 0 | 1176 | | if (nodeRebootOption != null) |
| | 1177 | | { |
| 0 | 1178 | | nodeRebootParameter = new NodeRebootParameter(); |
| 0 | 1179 | | nodeRebootParameter.NodeRebootOption = nodeRebootOption; |
| | 1180 | | } |
| | 1181 | | // Tracing |
| 0 | 1182 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1183 | | string _invocationId = null; |
| 0 | 1184 | | if (_shouldTrace) |
| | 1185 | | { |
| 0 | 1186 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1187 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1188 | | tracingParameters.Add("poolId", poolId); |
| 0 | 1189 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 1190 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1191 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1192 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1193 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1194 | | tracingParameters.Add("nodeRebootParameter", nodeRebootParameter); |
| 0 | 1195 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1196 | | ServiceClientTracing.Enter(_invocationId, this, "Reboot", tracingParameters); |
| | 1197 | | } |
| | 1198 | | // Construct URL |
| 0 | 1199 | | var _baseUrl = Client.BaseUri; |
| 0 | 1200 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/reboot"; |
| 0 | 1201 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1202 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 1203 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 1204 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1205 | | if (Client.ApiVersion != null) |
| | 1206 | | { |
| 0 | 1207 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1208 | | } |
| 0 | 1209 | | if (timeout != null) |
| | 1210 | | { |
| 0 | 1211 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1212 | | } |
| 0 | 1213 | | if (_queryParameters.Count > 0) |
| | 1214 | | { |
| 0 | 1215 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1216 | | } |
| | 1217 | | // Create HTTP transport objects |
| 0 | 1218 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1219 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1220 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1221 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1222 | | // Set Headers |
| 0 | 1223 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1224 | | { |
| 0 | 1225 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1226 | | } |
| 0 | 1227 | | if (Client.AcceptLanguage != null) |
| | 1228 | | { |
| 0 | 1229 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1230 | | { |
| 0 | 1231 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1232 | | } |
| 0 | 1233 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1234 | | } |
| 0 | 1235 | | if (clientRequestId != null) |
| | 1236 | | { |
| 0 | 1237 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1238 | | { |
| 0 | 1239 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1240 | | } |
| 0 | 1241 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1242 | | } |
| 0 | 1243 | | if (returnClientRequestId != null) |
| | 1244 | | { |
| 0 | 1245 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1246 | | { |
| 0 | 1247 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1248 | | } |
| 0 | 1249 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1250 | | } |
| 0 | 1251 | | if (ocpDate != null) |
| | 1252 | | { |
| 0 | 1253 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1254 | | { |
| 0 | 1255 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1256 | | } |
| 0 | 1257 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1258 | | } |
| | 1259 | |
|
| | 1260 | |
|
| 0 | 1261 | | if (customHeaders != null) |
| | 1262 | | { |
| 0 | 1263 | | foreach(var _header in customHeaders) |
| | 1264 | | { |
| 0 | 1265 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1266 | | { |
| 0 | 1267 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1268 | | } |
| 0 | 1269 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1270 | | } |
| | 1271 | | } |
| | 1272 | |
|
| | 1273 | | // Serialize Request |
| 0 | 1274 | | string _requestContent = null; |
| 0 | 1275 | | if(nodeRebootParameter != null) |
| | 1276 | | { |
| 0 | 1277 | | _requestContent = SafeJsonConvert.SerializeObject(nodeRebootParameter, Client.SerializationSettings); |
| 0 | 1278 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1279 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1280 | | } |
| | 1281 | | // Set Credentials |
| 0 | 1282 | | if (Client.Credentials != null) |
| | 1283 | | { |
| 0 | 1284 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1285 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1286 | | } |
| | 1287 | | // Send Request |
| 0 | 1288 | | if (_shouldTrace) |
| | 1289 | | { |
| 0 | 1290 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1291 | | } |
| 0 | 1292 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1293 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1294 | | if (_shouldTrace) |
| | 1295 | | { |
| 0 | 1296 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1297 | | } |
| 0 | 1298 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1299 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1300 | | string _responseContent = null; |
| 0 | 1301 | | if ((int)_statusCode != 202) |
| | 1302 | | { |
| 0 | 1303 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1304 | | try |
| | 1305 | | { |
| 0 | 1306 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1307 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1308 | | if (_errorBody != null) |
| | 1309 | | { |
| 0 | 1310 | | ex.Body = _errorBody; |
| | 1311 | | } |
| 0 | 1312 | | } |
| 0 | 1313 | | catch (JsonException) |
| | 1314 | | { |
| | 1315 | | // Ignore the exception |
| 0 | 1316 | | } |
| 0 | 1317 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1318 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1319 | | if (_shouldTrace) |
| | 1320 | | { |
| 0 | 1321 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1322 | | } |
| 0 | 1323 | | _httpRequest.Dispose(); |
| 0 | 1324 | | if (_httpResponse != null) |
| | 1325 | | { |
| 0 | 1326 | | _httpResponse.Dispose(); |
| | 1327 | | } |
| 0 | 1328 | | throw ex; |
| | 1329 | | } |
| | 1330 | | // Create Result |
| 0 | 1331 | | var _result = new AzureOperationHeaderResponse<ComputeNodeRebootHeaders>(); |
| 0 | 1332 | | _result.Request = _httpRequest; |
| 0 | 1333 | | _result.Response = _httpResponse; |
| 0 | 1334 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1335 | | { |
| 0 | 1336 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1337 | | } |
| | 1338 | | try |
| | 1339 | | { |
| 0 | 1340 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeRebootHeaders>(JsonSerializer.Cre |
| 0 | 1341 | | } |
| 0 | 1342 | | catch (JsonException ex) |
| | 1343 | | { |
| 0 | 1344 | | _httpRequest.Dispose(); |
| 0 | 1345 | | if (_httpResponse != null) |
| | 1346 | | { |
| 0 | 1347 | | _httpResponse.Dispose(); |
| | 1348 | | } |
| 0 | 1349 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1350 | | } |
| 0 | 1351 | | if (_shouldTrace) |
| | 1352 | | { |
| 0 | 1353 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1354 | | } |
| 0 | 1355 | | return _result; |
| 0 | 1356 | | } |
| | 1357 | |
|
| | 1358 | | /// <summary> |
| | 1359 | | /// Reinstalls the operating system on the specified Compute Node. |
| | 1360 | | /// </summary> |
| | 1361 | | /// <remarks> |
| | 1362 | | /// You can reinstall the operating system on a Compute Node only if it is in |
| | 1363 | | /// an idle or running state. This API can be invoked only on Pools created |
| | 1364 | | /// with the cloud service configuration property. |
| | 1365 | | /// </remarks> |
| | 1366 | | /// <param name='poolId'> |
| | 1367 | | /// The ID of the Pool that contains the Compute Node. |
| | 1368 | | /// </param> |
| | 1369 | | /// <param name='nodeId'> |
| | 1370 | | /// The ID of the Compute Node that you want to restart. |
| | 1371 | | /// </param> |
| | 1372 | | /// <param name='nodeReimageOption'> |
| | 1373 | | /// When to reimage the Compute Node and what to do with currently running |
| | 1374 | | /// Tasks. The default value is requeue. Possible values include: 'requeue', |
| | 1375 | | /// 'terminate', 'taskCompletion', 'retainedData' |
| | 1376 | | /// </param> |
| | 1377 | | /// <param name='computeNodeReimageOptions'> |
| | 1378 | | /// Additional parameters for the operation |
| | 1379 | | /// </param> |
| | 1380 | | /// <param name='customHeaders'> |
| | 1381 | | /// Headers that will be added to request. |
| | 1382 | | /// </param> |
| | 1383 | | /// <param name='cancellationToken'> |
| | 1384 | | /// The cancellation token. |
| | 1385 | | /// </param> |
| | 1386 | | /// <exception cref="BatchErrorException"> |
| | 1387 | | /// Thrown when the operation returned an invalid status code |
| | 1388 | | /// </exception> |
| | 1389 | | /// <exception cref="ValidationException"> |
| | 1390 | | /// Thrown when a required parameter is null |
| | 1391 | | /// </exception> |
| | 1392 | | /// <exception cref="System.ArgumentNullException"> |
| | 1393 | | /// Thrown when a required parameter is null |
| | 1394 | | /// </exception> |
| | 1395 | | /// <return> |
| | 1396 | | /// A response object containing the response body and response headers. |
| | 1397 | | /// </return> |
| | 1398 | | public async Task<AzureOperationHeaderResponse<ComputeNodeReimageHeaders>> ReimageWithHttpMessagesAsync(string p |
| | 1399 | | { |
| 0 | 1400 | | if (Client.BatchUrl == null) |
| | 1401 | | { |
| 0 | 1402 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1403 | | } |
| 0 | 1404 | | if (poolId == null) |
| | 1405 | | { |
| 0 | 1406 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 1407 | | } |
| 0 | 1408 | | if (nodeId == null) |
| | 1409 | | { |
| 0 | 1410 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 1411 | | } |
| 0 | 1412 | | if (Client.ApiVersion == null) |
| | 1413 | | { |
| 0 | 1414 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1415 | | } |
| 0 | 1416 | | int? timeout = default(int?); |
| 0 | 1417 | | if (computeNodeReimageOptions != null) |
| | 1418 | | { |
| 0 | 1419 | | timeout = computeNodeReimageOptions.Timeout; |
| | 1420 | | } |
| 0 | 1421 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1422 | | if (computeNodeReimageOptions != null) |
| | 1423 | | { |
| 0 | 1424 | | clientRequestId = computeNodeReimageOptions.ClientRequestId; |
| | 1425 | | } |
| 0 | 1426 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1427 | | if (computeNodeReimageOptions != null) |
| | 1428 | | { |
| 0 | 1429 | | returnClientRequestId = computeNodeReimageOptions.ReturnClientRequestId; |
| | 1430 | | } |
| 0 | 1431 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1432 | | if (computeNodeReimageOptions != null) |
| | 1433 | | { |
| 0 | 1434 | | ocpDate = computeNodeReimageOptions.OcpDate; |
| | 1435 | | } |
| 0 | 1436 | | NodeReimageParameter nodeReimageParameter = default(NodeReimageParameter); |
| 0 | 1437 | | if (nodeReimageOption != null) |
| | 1438 | | { |
| 0 | 1439 | | nodeReimageParameter = new NodeReimageParameter(); |
| 0 | 1440 | | nodeReimageParameter.NodeReimageOption = nodeReimageOption; |
| | 1441 | | } |
| | 1442 | | // Tracing |
| 0 | 1443 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1444 | | string _invocationId = null; |
| 0 | 1445 | | if (_shouldTrace) |
| | 1446 | | { |
| 0 | 1447 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1448 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1449 | | tracingParameters.Add("poolId", poolId); |
| 0 | 1450 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 1451 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1452 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1453 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1454 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1455 | | tracingParameters.Add("nodeReimageParameter", nodeReimageParameter); |
| 0 | 1456 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1457 | | ServiceClientTracing.Enter(_invocationId, this, "Reimage", tracingParameters); |
| | 1458 | | } |
| | 1459 | | // Construct URL |
| 0 | 1460 | | var _baseUrl = Client.BaseUri; |
| 0 | 1461 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/reimage"; |
| 0 | 1462 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1463 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 1464 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 1465 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1466 | | if (Client.ApiVersion != null) |
| | 1467 | | { |
| 0 | 1468 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1469 | | } |
| 0 | 1470 | | if (timeout != null) |
| | 1471 | | { |
| 0 | 1472 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1473 | | } |
| 0 | 1474 | | if (_queryParameters.Count > 0) |
| | 1475 | | { |
| 0 | 1476 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1477 | | } |
| | 1478 | | // Create HTTP transport objects |
| 0 | 1479 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1480 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1481 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1482 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1483 | | // Set Headers |
| 0 | 1484 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1485 | | { |
| 0 | 1486 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1487 | | } |
| 0 | 1488 | | if (Client.AcceptLanguage != null) |
| | 1489 | | { |
| 0 | 1490 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1491 | | { |
| 0 | 1492 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1493 | | } |
| 0 | 1494 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1495 | | } |
| 0 | 1496 | | if (clientRequestId != null) |
| | 1497 | | { |
| 0 | 1498 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1499 | | { |
| 0 | 1500 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1501 | | } |
| 0 | 1502 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1503 | | } |
| 0 | 1504 | | if (returnClientRequestId != null) |
| | 1505 | | { |
| 0 | 1506 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1507 | | { |
| 0 | 1508 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1509 | | } |
| 0 | 1510 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1511 | | } |
| 0 | 1512 | | if (ocpDate != null) |
| | 1513 | | { |
| 0 | 1514 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1515 | | { |
| 0 | 1516 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1517 | | } |
| 0 | 1518 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1519 | | } |
| | 1520 | |
|
| | 1521 | |
|
| 0 | 1522 | | if (customHeaders != null) |
| | 1523 | | { |
| 0 | 1524 | | foreach(var _header in customHeaders) |
| | 1525 | | { |
| 0 | 1526 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1527 | | { |
| 0 | 1528 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1529 | | } |
| 0 | 1530 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1531 | | } |
| | 1532 | | } |
| | 1533 | |
|
| | 1534 | | // Serialize Request |
| 0 | 1535 | | string _requestContent = null; |
| 0 | 1536 | | if(nodeReimageParameter != null) |
| | 1537 | | { |
| 0 | 1538 | | _requestContent = SafeJsonConvert.SerializeObject(nodeReimageParameter, Client.SerializationSettings); |
| 0 | 1539 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1540 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1541 | | } |
| | 1542 | | // Set Credentials |
| 0 | 1543 | | if (Client.Credentials != null) |
| | 1544 | | { |
| 0 | 1545 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1546 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1547 | | } |
| | 1548 | | // Send Request |
| 0 | 1549 | | if (_shouldTrace) |
| | 1550 | | { |
| 0 | 1551 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1552 | | } |
| 0 | 1553 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1554 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1555 | | if (_shouldTrace) |
| | 1556 | | { |
| 0 | 1557 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1558 | | } |
| 0 | 1559 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1560 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1561 | | string _responseContent = null; |
| 0 | 1562 | | if ((int)_statusCode != 202) |
| | 1563 | | { |
| 0 | 1564 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1565 | | try |
| | 1566 | | { |
| 0 | 1567 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1568 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1569 | | if (_errorBody != null) |
| | 1570 | | { |
| 0 | 1571 | | ex.Body = _errorBody; |
| | 1572 | | } |
| 0 | 1573 | | } |
| 0 | 1574 | | catch (JsonException) |
| | 1575 | | { |
| | 1576 | | // Ignore the exception |
| 0 | 1577 | | } |
| 0 | 1578 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1579 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1580 | | if (_shouldTrace) |
| | 1581 | | { |
| 0 | 1582 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1583 | | } |
| 0 | 1584 | | _httpRequest.Dispose(); |
| 0 | 1585 | | if (_httpResponse != null) |
| | 1586 | | { |
| 0 | 1587 | | _httpResponse.Dispose(); |
| | 1588 | | } |
| 0 | 1589 | | throw ex; |
| | 1590 | | } |
| | 1591 | | // Create Result |
| 0 | 1592 | | var _result = new AzureOperationHeaderResponse<ComputeNodeReimageHeaders>(); |
| 0 | 1593 | | _result.Request = _httpRequest; |
| 0 | 1594 | | _result.Response = _httpResponse; |
| 0 | 1595 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1596 | | { |
| 0 | 1597 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1598 | | } |
| | 1599 | | try |
| | 1600 | | { |
| 0 | 1601 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeReimageHeaders>(JsonSerializer.Cr |
| 0 | 1602 | | } |
| 0 | 1603 | | catch (JsonException ex) |
| | 1604 | | { |
| 0 | 1605 | | _httpRequest.Dispose(); |
| 0 | 1606 | | if (_httpResponse != null) |
| | 1607 | | { |
| 0 | 1608 | | _httpResponse.Dispose(); |
| | 1609 | | } |
| 0 | 1610 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1611 | | } |
| 0 | 1612 | | if (_shouldTrace) |
| | 1613 | | { |
| 0 | 1614 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1615 | | } |
| 0 | 1616 | | return _result; |
| 0 | 1617 | | } |
| | 1618 | |
|
| | 1619 | | /// <summary> |
| | 1620 | | /// Disables Task scheduling on the specified Compute Node. |
| | 1621 | | /// </summary> |
| | 1622 | | /// <remarks> |
| | 1623 | | /// You can disable Task scheduling on a Compute Node only if its current |
| | 1624 | | /// scheduling state is enabled. |
| | 1625 | | /// </remarks> |
| | 1626 | | /// <param name='poolId'> |
| | 1627 | | /// The ID of the Pool that contains the Compute Node. |
| | 1628 | | /// </param> |
| | 1629 | | /// <param name='nodeId'> |
| | 1630 | | /// The ID of the Compute Node on which you want to disable Task scheduling. |
| | 1631 | | /// </param> |
| | 1632 | | /// <param name='nodeDisableSchedulingOption'> |
| | 1633 | | /// What to do with currently running Tasks when disabling Task scheduling on |
| | 1634 | | /// the Compute Node. The default value is requeue. Possible values include: |
| | 1635 | | /// 'requeue', 'terminate', 'taskCompletion' |
| | 1636 | | /// </param> |
| | 1637 | | /// <param name='computeNodeDisableSchedulingOptions'> |
| | 1638 | | /// Additional parameters for the operation |
| | 1639 | | /// </param> |
| | 1640 | | /// <param name='customHeaders'> |
| | 1641 | | /// Headers that will be added to request. |
| | 1642 | | /// </param> |
| | 1643 | | /// <param name='cancellationToken'> |
| | 1644 | | /// The cancellation token. |
| | 1645 | | /// </param> |
| | 1646 | | /// <exception cref="BatchErrorException"> |
| | 1647 | | /// Thrown when the operation returned an invalid status code |
| | 1648 | | /// </exception> |
| | 1649 | | /// <exception cref="ValidationException"> |
| | 1650 | | /// Thrown when a required parameter is null |
| | 1651 | | /// </exception> |
| | 1652 | | /// <exception cref="System.ArgumentNullException"> |
| | 1653 | | /// Thrown when a required parameter is null |
| | 1654 | | /// </exception> |
| | 1655 | | /// <return> |
| | 1656 | | /// A response object containing the response body and response headers. |
| | 1657 | | /// </return> |
| | 1658 | | public async Task<AzureOperationHeaderResponse<ComputeNodeDisableSchedulingHeaders>> DisableSchedulingWithHttpMe |
| | 1659 | | { |
| 0 | 1660 | | if (Client.BatchUrl == null) |
| | 1661 | | { |
| 0 | 1662 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1663 | | } |
| 0 | 1664 | | if (poolId == null) |
| | 1665 | | { |
| 0 | 1666 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 1667 | | } |
| 0 | 1668 | | if (nodeId == null) |
| | 1669 | | { |
| 0 | 1670 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 1671 | | } |
| 0 | 1672 | | if (Client.ApiVersion == null) |
| | 1673 | | { |
| 0 | 1674 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1675 | | } |
| 0 | 1676 | | int? timeout = default(int?); |
| 0 | 1677 | | if (computeNodeDisableSchedulingOptions != null) |
| | 1678 | | { |
| 0 | 1679 | | timeout = computeNodeDisableSchedulingOptions.Timeout; |
| | 1680 | | } |
| 0 | 1681 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1682 | | if (computeNodeDisableSchedulingOptions != null) |
| | 1683 | | { |
| 0 | 1684 | | clientRequestId = computeNodeDisableSchedulingOptions.ClientRequestId; |
| | 1685 | | } |
| 0 | 1686 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1687 | | if (computeNodeDisableSchedulingOptions != null) |
| | 1688 | | { |
| 0 | 1689 | | returnClientRequestId = computeNodeDisableSchedulingOptions.ReturnClientRequestId; |
| | 1690 | | } |
| 0 | 1691 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1692 | | if (computeNodeDisableSchedulingOptions != null) |
| | 1693 | | { |
| 0 | 1694 | | ocpDate = computeNodeDisableSchedulingOptions.OcpDate; |
| | 1695 | | } |
| 0 | 1696 | | NodeDisableSchedulingParameter nodeDisableSchedulingParameter = default(NodeDisableSchedulingParameter); |
| 0 | 1697 | | if (nodeDisableSchedulingOption != null) |
| | 1698 | | { |
| 0 | 1699 | | nodeDisableSchedulingParameter = new NodeDisableSchedulingParameter(); |
| 0 | 1700 | | nodeDisableSchedulingParameter.NodeDisableSchedulingOption = nodeDisableSchedulingOption; |
| | 1701 | | } |
| | 1702 | | // Tracing |
| 0 | 1703 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1704 | | string _invocationId = null; |
| 0 | 1705 | | if (_shouldTrace) |
| | 1706 | | { |
| 0 | 1707 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1708 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1709 | | tracingParameters.Add("poolId", poolId); |
| 0 | 1710 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 1711 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1712 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1713 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1714 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1715 | | tracingParameters.Add("nodeDisableSchedulingParameter", nodeDisableSchedulingParameter); |
| 0 | 1716 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1717 | | ServiceClientTracing.Enter(_invocationId, this, "DisableScheduling", tracingParameters); |
| | 1718 | | } |
| | 1719 | | // Construct URL |
| 0 | 1720 | | var _baseUrl = Client.BaseUri; |
| 0 | 1721 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/disablescheduling |
| 0 | 1722 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1723 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 1724 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 1725 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1726 | | if (Client.ApiVersion != null) |
| | 1727 | | { |
| 0 | 1728 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1729 | | } |
| 0 | 1730 | | if (timeout != null) |
| | 1731 | | { |
| 0 | 1732 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1733 | | } |
| 0 | 1734 | | if (_queryParameters.Count > 0) |
| | 1735 | | { |
| 0 | 1736 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1737 | | } |
| | 1738 | | // Create HTTP transport objects |
| 0 | 1739 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1740 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1741 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1742 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1743 | | // Set Headers |
| 0 | 1744 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1745 | | { |
| 0 | 1746 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1747 | | } |
| 0 | 1748 | | if (Client.AcceptLanguage != null) |
| | 1749 | | { |
| 0 | 1750 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1751 | | { |
| 0 | 1752 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1753 | | } |
| 0 | 1754 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1755 | | } |
| 0 | 1756 | | if (clientRequestId != null) |
| | 1757 | | { |
| 0 | 1758 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 1759 | | { |
| 0 | 1760 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 1761 | | } |
| 0 | 1762 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 1763 | | } |
| 0 | 1764 | | if (returnClientRequestId != null) |
| | 1765 | | { |
| 0 | 1766 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 1767 | | { |
| 0 | 1768 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 1769 | | } |
| 0 | 1770 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 1771 | | } |
| 0 | 1772 | | if (ocpDate != null) |
| | 1773 | | { |
| 0 | 1774 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 1775 | | { |
| 0 | 1776 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 1777 | | } |
| 0 | 1778 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 1779 | | } |
| | 1780 | |
|
| | 1781 | |
|
| 0 | 1782 | | if (customHeaders != null) |
| | 1783 | | { |
| 0 | 1784 | | foreach(var _header in customHeaders) |
| | 1785 | | { |
| 0 | 1786 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1787 | | { |
| 0 | 1788 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1789 | | } |
| 0 | 1790 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1791 | | } |
| | 1792 | | } |
| | 1793 | |
|
| | 1794 | | // Serialize Request |
| 0 | 1795 | | string _requestContent = null; |
| 0 | 1796 | | if(nodeDisableSchedulingParameter != null) |
| | 1797 | | { |
| 0 | 1798 | | _requestContent = SafeJsonConvert.SerializeObject(nodeDisableSchedulingParameter, Client.SerializationSe |
| 0 | 1799 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1800 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1801 | | } |
| | 1802 | | // Set Credentials |
| 0 | 1803 | | if (Client.Credentials != null) |
| | 1804 | | { |
| 0 | 1805 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1806 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1807 | | } |
| | 1808 | | // Send Request |
| 0 | 1809 | | if (_shouldTrace) |
| | 1810 | | { |
| 0 | 1811 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1812 | | } |
| 0 | 1813 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1814 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1815 | | if (_shouldTrace) |
| | 1816 | | { |
| 0 | 1817 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1818 | | } |
| 0 | 1819 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1820 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1821 | | string _responseContent = null; |
| 0 | 1822 | | if ((int)_statusCode != 200) |
| | 1823 | | { |
| 0 | 1824 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1825 | | try |
| | 1826 | | { |
| 0 | 1827 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1828 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 1829 | | if (_errorBody != null) |
| | 1830 | | { |
| 0 | 1831 | | ex.Body = _errorBody; |
| | 1832 | | } |
| 0 | 1833 | | } |
| 0 | 1834 | | catch (JsonException) |
| | 1835 | | { |
| | 1836 | | // Ignore the exception |
| 0 | 1837 | | } |
| 0 | 1838 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1839 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1840 | | if (_shouldTrace) |
| | 1841 | | { |
| 0 | 1842 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1843 | | } |
| 0 | 1844 | | _httpRequest.Dispose(); |
| 0 | 1845 | | if (_httpResponse != null) |
| | 1846 | | { |
| 0 | 1847 | | _httpResponse.Dispose(); |
| | 1848 | | } |
| 0 | 1849 | | throw ex; |
| | 1850 | | } |
| | 1851 | | // Create Result |
| 0 | 1852 | | var _result = new AzureOperationHeaderResponse<ComputeNodeDisableSchedulingHeaders>(); |
| 0 | 1853 | | _result.Request = _httpRequest; |
| 0 | 1854 | | _result.Response = _httpResponse; |
| 0 | 1855 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 1856 | | { |
| 0 | 1857 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 1858 | | } |
| | 1859 | | try |
| | 1860 | | { |
| 0 | 1861 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeDisableSchedulingHeaders>(JsonSer |
| 0 | 1862 | | } |
| 0 | 1863 | | catch (JsonException ex) |
| | 1864 | | { |
| 0 | 1865 | | _httpRequest.Dispose(); |
| 0 | 1866 | | if (_httpResponse != null) |
| | 1867 | | { |
| 0 | 1868 | | _httpResponse.Dispose(); |
| | 1869 | | } |
| 0 | 1870 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 1871 | | } |
| 0 | 1872 | | if (_shouldTrace) |
| | 1873 | | { |
| 0 | 1874 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1875 | | } |
| 0 | 1876 | | return _result; |
| 0 | 1877 | | } |
| | 1878 | |
|
| | 1879 | | /// <summary> |
| | 1880 | | /// Enables Task scheduling on the specified Compute Node. |
| | 1881 | | /// </summary> |
| | 1882 | | /// <remarks> |
| | 1883 | | /// You can enable Task scheduling on a Compute Node only if its current |
| | 1884 | | /// scheduling state is disabled |
| | 1885 | | /// </remarks> |
| | 1886 | | /// <param name='poolId'> |
| | 1887 | | /// The ID of the Pool that contains the Compute Node. |
| | 1888 | | /// </param> |
| | 1889 | | /// <param name='nodeId'> |
| | 1890 | | /// The ID of the Compute Node on which you want to enable Task scheduling. |
| | 1891 | | /// </param> |
| | 1892 | | /// <param name='computeNodeEnableSchedulingOptions'> |
| | 1893 | | /// Additional parameters for the operation |
| | 1894 | | /// </param> |
| | 1895 | | /// <param name='customHeaders'> |
| | 1896 | | /// Headers that will be added to request. |
| | 1897 | | /// </param> |
| | 1898 | | /// <param name='cancellationToken'> |
| | 1899 | | /// The cancellation token. |
| | 1900 | | /// </param> |
| | 1901 | | /// <exception cref="BatchErrorException"> |
| | 1902 | | /// Thrown when the operation returned an invalid status code |
| | 1903 | | /// </exception> |
| | 1904 | | /// <exception cref="ValidationException"> |
| | 1905 | | /// Thrown when a required parameter is null |
| | 1906 | | /// </exception> |
| | 1907 | | /// <exception cref="System.ArgumentNullException"> |
| | 1908 | | /// Thrown when a required parameter is null |
| | 1909 | | /// </exception> |
| | 1910 | | /// <return> |
| | 1911 | | /// A response object containing the response body and response headers. |
| | 1912 | | /// </return> |
| | 1913 | | public async Task<AzureOperationHeaderResponse<ComputeNodeEnableSchedulingHeaders>> EnableSchedulingWithHttpMess |
| | 1914 | | { |
| 0 | 1915 | | if (Client.BatchUrl == null) |
| | 1916 | | { |
| 0 | 1917 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 1918 | | } |
| 0 | 1919 | | if (poolId == null) |
| | 1920 | | { |
| 0 | 1921 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 1922 | | } |
| 0 | 1923 | | if (nodeId == null) |
| | 1924 | | { |
| 0 | 1925 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 1926 | | } |
| 0 | 1927 | | if (Client.ApiVersion == null) |
| | 1928 | | { |
| 0 | 1929 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1930 | | } |
| 0 | 1931 | | int? timeout = default(int?); |
| 0 | 1932 | | if (computeNodeEnableSchedulingOptions != null) |
| | 1933 | | { |
| 0 | 1934 | | timeout = computeNodeEnableSchedulingOptions.Timeout; |
| | 1935 | | } |
| 0 | 1936 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 1937 | | if (computeNodeEnableSchedulingOptions != null) |
| | 1938 | | { |
| 0 | 1939 | | clientRequestId = computeNodeEnableSchedulingOptions.ClientRequestId; |
| | 1940 | | } |
| 0 | 1941 | | bool? returnClientRequestId = default(bool?); |
| 0 | 1942 | | if (computeNodeEnableSchedulingOptions != null) |
| | 1943 | | { |
| 0 | 1944 | | returnClientRequestId = computeNodeEnableSchedulingOptions.ReturnClientRequestId; |
| | 1945 | | } |
| 0 | 1946 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 1947 | | if (computeNodeEnableSchedulingOptions != null) |
| | 1948 | | { |
| 0 | 1949 | | ocpDate = computeNodeEnableSchedulingOptions.OcpDate; |
| | 1950 | | } |
| | 1951 | | // Tracing |
| 0 | 1952 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1953 | | string _invocationId = null; |
| 0 | 1954 | | if (_shouldTrace) |
| | 1955 | | { |
| 0 | 1956 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1957 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1958 | | tracingParameters.Add("poolId", poolId); |
| 0 | 1959 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 1960 | | tracingParameters.Add("timeout", timeout); |
| 0 | 1961 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 1962 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 1963 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 1964 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1965 | | ServiceClientTracing.Enter(_invocationId, this, "EnableScheduling", tracingParameters); |
| | 1966 | | } |
| | 1967 | | // Construct URL |
| 0 | 1968 | | var _baseUrl = Client.BaseUri; |
| 0 | 1969 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/enablescheduling" |
| 0 | 1970 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 1971 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 1972 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 1973 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1974 | | if (Client.ApiVersion != null) |
| | 1975 | | { |
| 0 | 1976 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1977 | | } |
| 0 | 1978 | | if (timeout != null) |
| | 1979 | | { |
| 0 | 1980 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1981 | | } |
| 0 | 1982 | | if (_queryParameters.Count > 0) |
| | 1983 | | { |
| 0 | 1984 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1985 | | } |
| | 1986 | | // Create HTTP transport objects |
| 0 | 1987 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1988 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1989 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1990 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1991 | | // Set Headers |
| 0 | 1992 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1993 | | { |
| 0 | 1994 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 1995 | | } |
| 0 | 1996 | | if (Client.AcceptLanguage != null) |
| | 1997 | | { |
| 0 | 1998 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1999 | | { |
| 0 | 2000 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2001 | | } |
| 0 | 2002 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2003 | | } |
| 0 | 2004 | | if (clientRequestId != null) |
| | 2005 | | { |
| 0 | 2006 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2007 | | { |
| 0 | 2008 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2009 | | } |
| 0 | 2010 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2011 | | } |
| 0 | 2012 | | if (returnClientRequestId != null) |
| | 2013 | | { |
| 0 | 2014 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2015 | | { |
| 0 | 2016 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2017 | | } |
| 0 | 2018 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2019 | | } |
| 0 | 2020 | | if (ocpDate != null) |
| | 2021 | | { |
| 0 | 2022 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2023 | | { |
| 0 | 2024 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2025 | | } |
| 0 | 2026 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2027 | | } |
| | 2028 | |
|
| | 2029 | |
|
| 0 | 2030 | | if (customHeaders != null) |
| | 2031 | | { |
| 0 | 2032 | | foreach(var _header in customHeaders) |
| | 2033 | | { |
| 0 | 2034 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2035 | | { |
| 0 | 2036 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2037 | | } |
| 0 | 2038 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2039 | | } |
| | 2040 | | } |
| | 2041 | |
|
| | 2042 | | // Serialize Request |
| 0 | 2043 | | string _requestContent = null; |
| | 2044 | | // Set Credentials |
| 0 | 2045 | | if (Client.Credentials != null) |
| | 2046 | | { |
| 0 | 2047 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2048 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2049 | | } |
| | 2050 | | // Send Request |
| 0 | 2051 | | if (_shouldTrace) |
| | 2052 | | { |
| 0 | 2053 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2054 | | } |
| 0 | 2055 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2056 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2057 | | if (_shouldTrace) |
| | 2058 | | { |
| 0 | 2059 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2060 | | } |
| 0 | 2061 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2062 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2063 | | string _responseContent = null; |
| 0 | 2064 | | if ((int)_statusCode != 200) |
| | 2065 | | { |
| 0 | 2066 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2067 | | try |
| | 2068 | | { |
| 0 | 2069 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2070 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2071 | | if (_errorBody != null) |
| | 2072 | | { |
| 0 | 2073 | | ex.Body = _errorBody; |
| | 2074 | | } |
| 0 | 2075 | | } |
| 0 | 2076 | | catch (JsonException) |
| | 2077 | | { |
| | 2078 | | // Ignore the exception |
| 0 | 2079 | | } |
| 0 | 2080 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2081 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2082 | | if (_shouldTrace) |
| | 2083 | | { |
| 0 | 2084 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2085 | | } |
| 0 | 2086 | | _httpRequest.Dispose(); |
| 0 | 2087 | | if (_httpResponse != null) |
| | 2088 | | { |
| 0 | 2089 | | _httpResponse.Dispose(); |
| | 2090 | | } |
| 0 | 2091 | | throw ex; |
| | 2092 | | } |
| | 2093 | | // Create Result |
| 0 | 2094 | | var _result = new AzureOperationHeaderResponse<ComputeNodeEnableSchedulingHeaders>(); |
| 0 | 2095 | | _result.Request = _httpRequest; |
| 0 | 2096 | | _result.Response = _httpResponse; |
| 0 | 2097 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2098 | | { |
| 0 | 2099 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2100 | | } |
| | 2101 | | try |
| | 2102 | | { |
| 0 | 2103 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeEnableSchedulingHeaders>(JsonSeri |
| 0 | 2104 | | } |
| 0 | 2105 | | catch (JsonException ex) |
| | 2106 | | { |
| 0 | 2107 | | _httpRequest.Dispose(); |
| 0 | 2108 | | if (_httpResponse != null) |
| | 2109 | | { |
| 0 | 2110 | | _httpResponse.Dispose(); |
| | 2111 | | } |
| 0 | 2112 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2113 | | } |
| 0 | 2114 | | if (_shouldTrace) |
| | 2115 | | { |
| 0 | 2116 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2117 | | } |
| 0 | 2118 | | return _result; |
| 0 | 2119 | | } |
| | 2120 | |
|
| | 2121 | | /// <summary> |
| | 2122 | | /// Gets the settings required for remote login to a Compute Node. |
| | 2123 | | /// </summary> |
| | 2124 | | /// <remarks> |
| | 2125 | | /// Before you can remotely login to a Compute Node using the remote login |
| | 2126 | | /// settings, you must create a user Account on the Compute Node. This API can |
| | 2127 | | /// be invoked only on Pools created with the virtual machine configuration |
| | 2128 | | /// property. For Pools created with a cloud service configuration, see the |
| | 2129 | | /// GetRemoteDesktop API. |
| | 2130 | | /// </remarks> |
| | 2131 | | /// <param name='poolId'> |
| | 2132 | | /// The ID of the Pool that contains the Compute Node. |
| | 2133 | | /// </param> |
| | 2134 | | /// <param name='nodeId'> |
| | 2135 | | /// The ID of the Compute Node for which to obtain the remote login settings. |
| | 2136 | | /// </param> |
| | 2137 | | /// <param name='computeNodeGetRemoteLoginSettingsOptions'> |
| | 2138 | | /// Additional parameters for the operation |
| | 2139 | | /// </param> |
| | 2140 | | /// <param name='customHeaders'> |
| | 2141 | | /// Headers that will be added to request. |
| | 2142 | | /// </param> |
| | 2143 | | /// <param name='cancellationToken'> |
| | 2144 | | /// The cancellation token. |
| | 2145 | | /// </param> |
| | 2146 | | /// <exception cref="BatchErrorException"> |
| | 2147 | | /// Thrown when the operation returned an invalid status code |
| | 2148 | | /// </exception> |
| | 2149 | | /// <exception cref="SerializationException"> |
| | 2150 | | /// Thrown when unable to deserialize the response |
| | 2151 | | /// </exception> |
| | 2152 | | /// <exception cref="ValidationException"> |
| | 2153 | | /// Thrown when a required parameter is null |
| | 2154 | | /// </exception> |
| | 2155 | | /// <exception cref="System.ArgumentNullException"> |
| | 2156 | | /// Thrown when a required parameter is null |
| | 2157 | | /// </exception> |
| | 2158 | | /// <return> |
| | 2159 | | /// A response object containing the response body and response headers. |
| | 2160 | | /// </return> |
| | 2161 | | public async Task<AzureOperationResponse<ComputeNodeGetRemoteLoginSettingsResult,ComputeNodeGetRemoteLoginSettin |
| | 2162 | | { |
| 0 | 2163 | | if (Client.BatchUrl == null) |
| | 2164 | | { |
| 0 | 2165 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2166 | | } |
| 0 | 2167 | | if (poolId == null) |
| | 2168 | | { |
| 0 | 2169 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 2170 | | } |
| 0 | 2171 | | if (nodeId == null) |
| | 2172 | | { |
| 0 | 2173 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 2174 | | } |
| 0 | 2175 | | if (Client.ApiVersion == null) |
| | 2176 | | { |
| 0 | 2177 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2178 | | } |
| 0 | 2179 | | int? timeout = default(int?); |
| 0 | 2180 | | if (computeNodeGetRemoteLoginSettingsOptions != null) |
| | 2181 | | { |
| 0 | 2182 | | timeout = computeNodeGetRemoteLoginSettingsOptions.Timeout; |
| | 2183 | | } |
| 0 | 2184 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2185 | | if (computeNodeGetRemoteLoginSettingsOptions != null) |
| | 2186 | | { |
| 0 | 2187 | | clientRequestId = computeNodeGetRemoteLoginSettingsOptions.ClientRequestId; |
| | 2188 | | } |
| 0 | 2189 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2190 | | if (computeNodeGetRemoteLoginSettingsOptions != null) |
| | 2191 | | { |
| 0 | 2192 | | returnClientRequestId = computeNodeGetRemoteLoginSettingsOptions.ReturnClientRequestId; |
| | 2193 | | } |
| 0 | 2194 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2195 | | if (computeNodeGetRemoteLoginSettingsOptions != null) |
| | 2196 | | { |
| 0 | 2197 | | ocpDate = computeNodeGetRemoteLoginSettingsOptions.OcpDate; |
| | 2198 | | } |
| | 2199 | | // Tracing |
| 0 | 2200 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2201 | | string _invocationId = null; |
| 0 | 2202 | | if (_shouldTrace) |
| | 2203 | | { |
| 0 | 2204 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2205 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2206 | | tracingParameters.Add("poolId", poolId); |
| 0 | 2207 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 2208 | | tracingParameters.Add("timeout", timeout); |
| 0 | 2209 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 2210 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 2211 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 2212 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2213 | | ServiceClientTracing.Enter(_invocationId, this, "GetRemoteLoginSettings", tracingParameters); |
| | 2214 | | } |
| | 2215 | | // Construct URL |
| 0 | 2216 | | var _baseUrl = Client.BaseUri; |
| 0 | 2217 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/remoteloginsettin |
| 0 | 2218 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 2219 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 2220 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 2221 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2222 | | if (Client.ApiVersion != null) |
| | 2223 | | { |
| 0 | 2224 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2225 | | } |
| 0 | 2226 | | if (timeout != null) |
| | 2227 | | { |
| 0 | 2228 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 2229 | | } |
| 0 | 2230 | | if (_queryParameters.Count > 0) |
| | 2231 | | { |
| 0 | 2232 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2233 | | } |
| | 2234 | | // Create HTTP transport objects |
| 0 | 2235 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2236 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2237 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2238 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2239 | | // Set Headers |
| 0 | 2240 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2241 | | { |
| 0 | 2242 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 2243 | | } |
| 0 | 2244 | | if (Client.AcceptLanguage != null) |
| | 2245 | | { |
| 0 | 2246 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2247 | | { |
| 0 | 2248 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2249 | | } |
| 0 | 2250 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2251 | | } |
| 0 | 2252 | | if (clientRequestId != null) |
| | 2253 | | { |
| 0 | 2254 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2255 | | { |
| 0 | 2256 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2257 | | } |
| 0 | 2258 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2259 | | } |
| 0 | 2260 | | if (returnClientRequestId != null) |
| | 2261 | | { |
| 0 | 2262 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2263 | | { |
| 0 | 2264 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2265 | | } |
| 0 | 2266 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2267 | | } |
| 0 | 2268 | | if (ocpDate != null) |
| | 2269 | | { |
| 0 | 2270 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2271 | | { |
| 0 | 2272 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2273 | | } |
| 0 | 2274 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2275 | | } |
| | 2276 | |
|
| | 2277 | |
|
| 0 | 2278 | | if (customHeaders != null) |
| | 2279 | | { |
| 0 | 2280 | | foreach(var _header in customHeaders) |
| | 2281 | | { |
| 0 | 2282 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2283 | | { |
| 0 | 2284 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2285 | | } |
| 0 | 2286 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2287 | | } |
| | 2288 | | } |
| | 2289 | |
|
| | 2290 | | // Serialize Request |
| 0 | 2291 | | string _requestContent = null; |
| | 2292 | | // Set Credentials |
| 0 | 2293 | | if (Client.Credentials != null) |
| | 2294 | | { |
| 0 | 2295 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2296 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2297 | | } |
| | 2298 | | // Send Request |
| 0 | 2299 | | if (_shouldTrace) |
| | 2300 | | { |
| 0 | 2301 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2302 | | } |
| 0 | 2303 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2304 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2305 | | if (_shouldTrace) |
| | 2306 | | { |
| 0 | 2307 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2308 | | } |
| 0 | 2309 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2310 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2311 | | string _responseContent = null; |
| 0 | 2312 | | if ((int)_statusCode != 200) |
| | 2313 | | { |
| 0 | 2314 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2315 | | try |
| | 2316 | | { |
| 0 | 2317 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2318 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2319 | | if (_errorBody != null) |
| | 2320 | | { |
| 0 | 2321 | | ex.Body = _errorBody; |
| | 2322 | | } |
| 0 | 2323 | | } |
| 0 | 2324 | | catch (JsonException) |
| | 2325 | | { |
| | 2326 | | // Ignore the exception |
| 0 | 2327 | | } |
| 0 | 2328 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2329 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2330 | | if (_shouldTrace) |
| | 2331 | | { |
| 0 | 2332 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2333 | | } |
| 0 | 2334 | | _httpRequest.Dispose(); |
| 0 | 2335 | | if (_httpResponse != null) |
| | 2336 | | { |
| 0 | 2337 | | _httpResponse.Dispose(); |
| | 2338 | | } |
| 0 | 2339 | | throw ex; |
| | 2340 | | } |
| | 2341 | | // Create Result |
| 0 | 2342 | | var _result = new AzureOperationResponse<ComputeNodeGetRemoteLoginSettingsResult,ComputeNodeGetRemoteLoginSe |
| 0 | 2343 | | _result.Request = _httpRequest; |
| 0 | 2344 | | _result.Response = _httpResponse; |
| 0 | 2345 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2346 | | { |
| 0 | 2347 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2348 | | } |
| | 2349 | | // Deserialize Response |
| 0 | 2350 | | if ((int)_statusCode == 200) |
| | 2351 | | { |
| 0 | 2352 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2353 | | try |
| | 2354 | | { |
| 0 | 2355 | | _result.Body = SafeJsonConvert.DeserializeObject<ComputeNodeGetRemoteLoginSettingsResult>(_responseC |
| 0 | 2356 | | } |
| 0 | 2357 | | catch (JsonException ex) |
| | 2358 | | { |
| 0 | 2359 | | _httpRequest.Dispose(); |
| 0 | 2360 | | if (_httpResponse != null) |
| | 2361 | | { |
| 0 | 2362 | | _httpResponse.Dispose(); |
| | 2363 | | } |
| 0 | 2364 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2365 | | } |
| | 2366 | | } |
| | 2367 | | try |
| | 2368 | | { |
| 0 | 2369 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeGetRemoteLoginSettingsHeaders>(Js |
| 0 | 2370 | | } |
| 0 | 2371 | | catch (JsonException ex) |
| | 2372 | | { |
| 0 | 2373 | | _httpRequest.Dispose(); |
| 0 | 2374 | | if (_httpResponse != null) |
| | 2375 | | { |
| 0 | 2376 | | _httpResponse.Dispose(); |
| | 2377 | | } |
| 0 | 2378 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2379 | | } |
| 0 | 2380 | | if (_shouldTrace) |
| | 2381 | | { |
| 0 | 2382 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2383 | | } |
| 0 | 2384 | | return _result; |
| 0 | 2385 | | } |
| | 2386 | |
|
| | 2387 | | /// <summary> |
| | 2388 | | /// Gets the Remote Desktop Protocol file for the specified Compute Node. |
| | 2389 | | /// </summary> |
| | 2390 | | /// <remarks> |
| | 2391 | | /// Before you can access a Compute Node by using the RDP file, you must create |
| | 2392 | | /// a user Account on the Compute Node. This API can only be invoked on Pools |
| | 2393 | | /// created with a cloud service configuration. For Pools created with a |
| | 2394 | | /// virtual machine configuration, see the GetRemoteLoginSettings API. |
| | 2395 | | /// </remarks> |
| | 2396 | | /// <param name='poolId'> |
| | 2397 | | /// The ID of the Pool that contains the Compute Node. |
| | 2398 | | /// </param> |
| | 2399 | | /// <param name='nodeId'> |
| | 2400 | | /// The ID of the Compute Node for which you want to get the Remote Desktop |
| | 2401 | | /// Protocol file. |
| | 2402 | | /// </param> |
| | 2403 | | /// <param name='computeNodeGetRemoteDesktopOptions'> |
| | 2404 | | /// Additional parameters for the operation |
| | 2405 | | /// </param> |
| | 2406 | | /// <param name='customHeaders'> |
| | 2407 | | /// Headers that will be added to request. |
| | 2408 | | /// </param> |
| | 2409 | | /// <param name='cancellationToken'> |
| | 2410 | | /// The cancellation token. |
| | 2411 | | /// </param> |
| | 2412 | | /// <exception cref="BatchErrorException"> |
| | 2413 | | /// Thrown when the operation returned an invalid status code |
| | 2414 | | /// </exception> |
| | 2415 | | /// <exception cref="SerializationException"> |
| | 2416 | | /// Thrown when unable to deserialize the response |
| | 2417 | | /// </exception> |
| | 2418 | | /// <exception cref="ValidationException"> |
| | 2419 | | /// Thrown when a required parameter is null |
| | 2420 | | /// </exception> |
| | 2421 | | /// <exception cref="System.ArgumentNullException"> |
| | 2422 | | /// Thrown when a required parameter is null |
| | 2423 | | /// </exception> |
| | 2424 | | /// <return> |
| | 2425 | | /// A response object containing the response body and response headers. |
| | 2426 | | /// </return> |
| | 2427 | | public async Task<AzureOperationResponse<Stream,ComputeNodeGetRemoteDesktopHeaders>> GetRemoteDesktopWithHttpMes |
| | 2428 | | { |
| 0 | 2429 | | if (Client.BatchUrl == null) |
| | 2430 | | { |
| 0 | 2431 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2432 | | } |
| 0 | 2433 | | if (poolId == null) |
| | 2434 | | { |
| 0 | 2435 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 2436 | | } |
| 0 | 2437 | | if (nodeId == null) |
| | 2438 | | { |
| 0 | 2439 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 2440 | | } |
| 0 | 2441 | | if (Client.ApiVersion == null) |
| | 2442 | | { |
| 0 | 2443 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2444 | | } |
| 0 | 2445 | | int? timeout = default(int?); |
| 0 | 2446 | | if (computeNodeGetRemoteDesktopOptions != null) |
| | 2447 | | { |
| 0 | 2448 | | timeout = computeNodeGetRemoteDesktopOptions.Timeout; |
| | 2449 | | } |
| 0 | 2450 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2451 | | if (computeNodeGetRemoteDesktopOptions != null) |
| | 2452 | | { |
| 0 | 2453 | | clientRequestId = computeNodeGetRemoteDesktopOptions.ClientRequestId; |
| | 2454 | | } |
| 0 | 2455 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2456 | | if (computeNodeGetRemoteDesktopOptions != null) |
| | 2457 | | { |
| 0 | 2458 | | returnClientRequestId = computeNodeGetRemoteDesktopOptions.ReturnClientRequestId; |
| | 2459 | | } |
| 0 | 2460 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2461 | | if (computeNodeGetRemoteDesktopOptions != null) |
| | 2462 | | { |
| 0 | 2463 | | ocpDate = computeNodeGetRemoteDesktopOptions.OcpDate; |
| | 2464 | | } |
| | 2465 | | // Tracing |
| 0 | 2466 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2467 | | string _invocationId = null; |
| 0 | 2468 | | if (_shouldTrace) |
| | 2469 | | { |
| 0 | 2470 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2471 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2472 | | tracingParameters.Add("poolId", poolId); |
| 0 | 2473 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 2474 | | tracingParameters.Add("timeout", timeout); |
| 0 | 2475 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 2476 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 2477 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 2478 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2479 | | ServiceClientTracing.Enter(_invocationId, this, "GetRemoteDesktop", tracingParameters); |
| | 2480 | | } |
| | 2481 | | // Construct URL |
| 0 | 2482 | | var _baseUrl = Client.BaseUri; |
| 0 | 2483 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/rdp"; |
| 0 | 2484 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 2485 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 2486 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 2487 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2488 | | if (Client.ApiVersion != null) |
| | 2489 | | { |
| 0 | 2490 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2491 | | } |
| 0 | 2492 | | if (timeout != null) |
| | 2493 | | { |
| 0 | 2494 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 2495 | | } |
| 0 | 2496 | | if (_queryParameters.Count > 0) |
| | 2497 | | { |
| 0 | 2498 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2499 | | } |
| | 2500 | | // Create HTTP transport objects |
| 0 | 2501 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2502 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2503 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2504 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2505 | | // Set Headers |
| 0 | 2506 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2507 | | { |
| 0 | 2508 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 2509 | | } |
| 0 | 2510 | | if (Client.AcceptLanguage != null) |
| | 2511 | | { |
| 0 | 2512 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2513 | | { |
| 0 | 2514 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2515 | | } |
| 0 | 2516 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2517 | | } |
| 0 | 2518 | | if (clientRequestId != null) |
| | 2519 | | { |
| 0 | 2520 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2521 | | { |
| 0 | 2522 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2523 | | } |
| 0 | 2524 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2525 | | } |
| 0 | 2526 | | if (returnClientRequestId != null) |
| | 2527 | | { |
| 0 | 2528 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2529 | | { |
| 0 | 2530 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2531 | | } |
| 0 | 2532 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2533 | | } |
| 0 | 2534 | | if (ocpDate != null) |
| | 2535 | | { |
| 0 | 2536 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2537 | | { |
| 0 | 2538 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2539 | | } |
| 0 | 2540 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2541 | | } |
| | 2542 | |
|
| | 2543 | |
|
| 0 | 2544 | | if (customHeaders != null) |
| | 2545 | | { |
| 0 | 2546 | | foreach(var _header in customHeaders) |
| | 2547 | | { |
| 0 | 2548 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2549 | | { |
| 0 | 2550 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2551 | | } |
| 0 | 2552 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2553 | | } |
| | 2554 | | } |
| | 2555 | |
|
| | 2556 | | // Serialize Request |
| 0 | 2557 | | string _requestContent = null; |
| | 2558 | | // Set Credentials |
| 0 | 2559 | | if (Client.Credentials != null) |
| | 2560 | | { |
| 0 | 2561 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2562 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2563 | | } |
| | 2564 | | // Send Request |
| 0 | 2565 | | if (_shouldTrace) |
| | 2566 | | { |
| 0 | 2567 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2568 | | } |
| 0 | 2569 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2570 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 0 | 2571 | | if (_shouldTrace) |
| | 2572 | | { |
| 0 | 2573 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2574 | | } |
| 0 | 2575 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2576 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2577 | | string _responseContent = null; |
| 0 | 2578 | | if ((int)_statusCode != 200) |
| | 2579 | | { |
| 0 | 2580 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2581 | | try |
| | 2582 | | { |
| 0 | 2583 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2584 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2585 | | if (_errorBody != null) |
| | 2586 | | { |
| 0 | 2587 | | ex.Body = _errorBody; |
| | 2588 | | } |
| 0 | 2589 | | } |
| 0 | 2590 | | catch (JsonException) |
| | 2591 | | { |
| | 2592 | | // Ignore the exception |
| 0 | 2593 | | } |
| 0 | 2594 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2595 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2596 | | if (_shouldTrace) |
| | 2597 | | { |
| 0 | 2598 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2599 | | } |
| 0 | 2600 | | _httpRequest.Dispose(); |
| 0 | 2601 | | if (_httpResponse != null) |
| | 2602 | | { |
| 0 | 2603 | | _httpResponse.Dispose(); |
| | 2604 | | } |
| 0 | 2605 | | throw ex; |
| | 2606 | | } |
| | 2607 | | // Create Result |
| 0 | 2608 | | var _result = new AzureOperationResponse<Stream,ComputeNodeGetRemoteDesktopHeaders>(); |
| 0 | 2609 | | _result.Request = _httpRequest; |
| 0 | 2610 | | _result.Response = _httpResponse; |
| 0 | 2611 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2612 | | { |
| 0 | 2613 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2614 | | } |
| | 2615 | | // Deserialize Response |
| 0 | 2616 | | if ((int)_statusCode == 200) |
| | 2617 | | { |
| 0 | 2618 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 2619 | | } |
| | 2620 | | try |
| | 2621 | | { |
| 0 | 2622 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeGetRemoteDesktopHeaders>(JsonSeri |
| 0 | 2623 | | } |
| 0 | 2624 | | catch (JsonException ex) |
| | 2625 | | { |
| 0 | 2626 | | _httpRequest.Dispose(); |
| 0 | 2627 | | if (_httpResponse != null) |
| | 2628 | | { |
| 0 | 2629 | | _httpResponse.Dispose(); |
| | 2630 | | } |
| 0 | 2631 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2632 | | } |
| 0 | 2633 | | if (_shouldTrace) |
| | 2634 | | { |
| 0 | 2635 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2636 | | } |
| 0 | 2637 | | return _result; |
| 0 | 2638 | | } |
| | 2639 | |
|
| | 2640 | | /// <summary> |
| | 2641 | | /// Upload Azure Batch service log files from the specified Compute Node to |
| | 2642 | | /// Azure Blob Storage. |
| | 2643 | | /// </summary> |
| | 2644 | | /// <remarks> |
| | 2645 | | /// This is for gathering Azure Batch service log files in an automated fashion |
| | 2646 | | /// from Compute Nodes if you are experiencing an error and wish to escalate to |
| | 2647 | | /// Azure support. The Azure Batch service log files should be shared with |
| | 2648 | | /// Azure support to aid in debugging issues with the Batch service. |
| | 2649 | | /// </remarks> |
| | 2650 | | /// <param name='poolId'> |
| | 2651 | | /// The ID of the Pool that contains the Compute Node. |
| | 2652 | | /// </param> |
| | 2653 | | /// <param name='nodeId'> |
| | 2654 | | /// The ID of the Compute Node from which you want to upload the Azure Batch |
| | 2655 | | /// service log files. |
| | 2656 | | /// </param> |
| | 2657 | | /// <param name='uploadBatchServiceLogsConfiguration'> |
| | 2658 | | /// The Azure Batch service log files upload configuration. |
| | 2659 | | /// </param> |
| | 2660 | | /// <param name='computeNodeUploadBatchServiceLogsOptions'> |
| | 2661 | | /// Additional parameters for the operation |
| | 2662 | | /// </param> |
| | 2663 | | /// <param name='customHeaders'> |
| | 2664 | | /// Headers that will be added to request. |
| | 2665 | | /// </param> |
| | 2666 | | /// <param name='cancellationToken'> |
| | 2667 | | /// The cancellation token. |
| | 2668 | | /// </param> |
| | 2669 | | /// <exception cref="BatchErrorException"> |
| | 2670 | | /// Thrown when the operation returned an invalid status code |
| | 2671 | | /// </exception> |
| | 2672 | | /// <exception cref="SerializationException"> |
| | 2673 | | /// Thrown when unable to deserialize the response |
| | 2674 | | /// </exception> |
| | 2675 | | /// <exception cref="ValidationException"> |
| | 2676 | | /// Thrown when a required parameter is null |
| | 2677 | | /// </exception> |
| | 2678 | | /// <exception cref="System.ArgumentNullException"> |
| | 2679 | | /// Thrown when a required parameter is null |
| | 2680 | | /// </exception> |
| | 2681 | | /// <return> |
| | 2682 | | /// A response object containing the response body and response headers. |
| | 2683 | | /// </return> |
| | 2684 | | public async Task<AzureOperationResponse<UploadBatchServiceLogsResult,ComputeNodeUploadBatchServiceLogsHeaders>> |
| | 2685 | | { |
| 0 | 2686 | | if (Client.BatchUrl == null) |
| | 2687 | | { |
| 0 | 2688 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2689 | | } |
| 0 | 2690 | | if (poolId == null) |
| | 2691 | | { |
| 0 | 2692 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 2693 | | } |
| 0 | 2694 | | if (nodeId == null) |
| | 2695 | | { |
| 0 | 2696 | | throw new ValidationException(ValidationRules.CannotBeNull, "nodeId"); |
| | 2697 | | } |
| 0 | 2698 | | if (uploadBatchServiceLogsConfiguration == null) |
| | 2699 | | { |
| 0 | 2700 | | throw new ValidationException(ValidationRules.CannotBeNull, "uploadBatchServiceLogsConfiguration"); |
| | 2701 | | } |
| 0 | 2702 | | if (Client.ApiVersion == null) |
| | 2703 | | { |
| 0 | 2704 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2705 | | } |
| 0 | 2706 | | int? timeout = default(int?); |
| 0 | 2707 | | if (computeNodeUploadBatchServiceLogsOptions != null) |
| | 2708 | | { |
| 0 | 2709 | | timeout = computeNodeUploadBatchServiceLogsOptions.Timeout; |
| | 2710 | | } |
| 0 | 2711 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2712 | | if (computeNodeUploadBatchServiceLogsOptions != null) |
| | 2713 | | { |
| 0 | 2714 | | clientRequestId = computeNodeUploadBatchServiceLogsOptions.ClientRequestId; |
| | 2715 | | } |
| 0 | 2716 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2717 | | if (computeNodeUploadBatchServiceLogsOptions != null) |
| | 2718 | | { |
| 0 | 2719 | | returnClientRequestId = computeNodeUploadBatchServiceLogsOptions.ReturnClientRequestId; |
| | 2720 | | } |
| 0 | 2721 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2722 | | if (computeNodeUploadBatchServiceLogsOptions != null) |
| | 2723 | | { |
| 0 | 2724 | | ocpDate = computeNodeUploadBatchServiceLogsOptions.OcpDate; |
| | 2725 | | } |
| | 2726 | | // Tracing |
| 0 | 2727 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2728 | | string _invocationId = null; |
| 0 | 2729 | | if (_shouldTrace) |
| | 2730 | | { |
| 0 | 2731 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2732 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2733 | | tracingParameters.Add("poolId", poolId); |
| 0 | 2734 | | tracingParameters.Add("nodeId", nodeId); |
| 0 | 2735 | | tracingParameters.Add("uploadBatchServiceLogsConfiguration", uploadBatchServiceLogsConfiguration); |
| 0 | 2736 | | tracingParameters.Add("timeout", timeout); |
| 0 | 2737 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 2738 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 2739 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 2740 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2741 | | ServiceClientTracing.Enter(_invocationId, this, "UploadBatchServiceLogs", tracingParameters); |
| | 2742 | | } |
| | 2743 | | // Construct URL |
| 0 | 2744 | | var _baseUrl = Client.BaseUri; |
| 0 | 2745 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes/{nodeId}/uploadbatchservic |
| 0 | 2746 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 2747 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 2748 | | _url = _url.Replace("{nodeId}", System.Uri.EscapeDataString(nodeId)); |
| 0 | 2749 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2750 | | if (Client.ApiVersion != null) |
| | 2751 | | { |
| 0 | 2752 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2753 | | } |
| 0 | 2754 | | if (timeout != null) |
| | 2755 | | { |
| 0 | 2756 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 2757 | | } |
| 0 | 2758 | | if (_queryParameters.Count > 0) |
| | 2759 | | { |
| 0 | 2760 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2761 | | } |
| | 2762 | | // Create HTTP transport objects |
| 0 | 2763 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2764 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2765 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 2766 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2767 | | // Set Headers |
| 0 | 2768 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2769 | | { |
| 0 | 2770 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 2771 | | } |
| 0 | 2772 | | if (Client.AcceptLanguage != null) |
| | 2773 | | { |
| 0 | 2774 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2775 | | { |
| 0 | 2776 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2777 | | } |
| 0 | 2778 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2779 | | } |
| 0 | 2780 | | if (clientRequestId != null) |
| | 2781 | | { |
| 0 | 2782 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 2783 | | { |
| 0 | 2784 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 2785 | | } |
| 0 | 2786 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 2787 | | } |
| 0 | 2788 | | if (returnClientRequestId != null) |
| | 2789 | | { |
| 0 | 2790 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 2791 | | { |
| 0 | 2792 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 2793 | | } |
| 0 | 2794 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 2795 | | } |
| 0 | 2796 | | if (ocpDate != null) |
| | 2797 | | { |
| 0 | 2798 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 2799 | | { |
| 0 | 2800 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 2801 | | } |
| 0 | 2802 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 2803 | | } |
| | 2804 | |
|
| | 2805 | |
|
| 0 | 2806 | | if (customHeaders != null) |
| | 2807 | | { |
| 0 | 2808 | | foreach(var _header in customHeaders) |
| | 2809 | | { |
| 0 | 2810 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2811 | | { |
| 0 | 2812 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2813 | | } |
| 0 | 2814 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2815 | | } |
| | 2816 | | } |
| | 2817 | |
|
| | 2818 | | // Serialize Request |
| 0 | 2819 | | string _requestContent = null; |
| 0 | 2820 | | if(uploadBatchServiceLogsConfiguration != null) |
| | 2821 | | { |
| 0 | 2822 | | _requestContent = SafeJsonConvert.SerializeObject(uploadBatchServiceLogsConfiguration, Client.Serializat |
| 0 | 2823 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 2824 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2825 | | } |
| | 2826 | | // Set Credentials |
| 0 | 2827 | | if (Client.Credentials != null) |
| | 2828 | | { |
| 0 | 2829 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2830 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2831 | | } |
| | 2832 | | // Send Request |
| 0 | 2833 | | if (_shouldTrace) |
| | 2834 | | { |
| 0 | 2835 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2836 | | } |
| 0 | 2837 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2838 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2839 | | if (_shouldTrace) |
| | 2840 | | { |
| 0 | 2841 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2842 | | } |
| 0 | 2843 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2844 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2845 | | string _responseContent = null; |
| 0 | 2846 | | if ((int)_statusCode != 200) |
| | 2847 | | { |
| 0 | 2848 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2849 | | try |
| | 2850 | | { |
| 0 | 2851 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2852 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 2853 | | if (_errorBody != null) |
| | 2854 | | { |
| 0 | 2855 | | ex.Body = _errorBody; |
| | 2856 | | } |
| 0 | 2857 | | } |
| 0 | 2858 | | catch (JsonException) |
| | 2859 | | { |
| | 2860 | | // Ignore the exception |
| 0 | 2861 | | } |
| 0 | 2862 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2863 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2864 | | if (_shouldTrace) |
| | 2865 | | { |
| 0 | 2866 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2867 | | } |
| 0 | 2868 | | _httpRequest.Dispose(); |
| 0 | 2869 | | if (_httpResponse != null) |
| | 2870 | | { |
| 0 | 2871 | | _httpResponse.Dispose(); |
| | 2872 | | } |
| 0 | 2873 | | throw ex; |
| | 2874 | | } |
| | 2875 | | // Create Result |
| 0 | 2876 | | var _result = new AzureOperationResponse<UploadBatchServiceLogsResult,ComputeNodeUploadBatchServiceLogsHeade |
| 0 | 2877 | | _result.Request = _httpRequest; |
| 0 | 2878 | | _result.Response = _httpResponse; |
| 0 | 2879 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 2880 | | { |
| 0 | 2881 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 2882 | | } |
| | 2883 | | // Deserialize Response |
| 0 | 2884 | | if ((int)_statusCode == 200) |
| | 2885 | | { |
| 0 | 2886 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2887 | | try |
| | 2888 | | { |
| 0 | 2889 | | _result.Body = SafeJsonConvert.DeserializeObject<UploadBatchServiceLogsResult>(_responseContent, Cli |
| 0 | 2890 | | } |
| 0 | 2891 | | catch (JsonException ex) |
| | 2892 | | { |
| 0 | 2893 | | _httpRequest.Dispose(); |
| 0 | 2894 | | if (_httpResponse != null) |
| | 2895 | | { |
| 0 | 2896 | | _httpResponse.Dispose(); |
| | 2897 | | } |
| 0 | 2898 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2899 | | } |
| | 2900 | | } |
| | 2901 | | try |
| | 2902 | | { |
| 0 | 2903 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeUploadBatchServiceLogsHeaders>(Js |
| 0 | 2904 | | } |
| 0 | 2905 | | catch (JsonException ex) |
| | 2906 | | { |
| 0 | 2907 | | _httpRequest.Dispose(); |
| 0 | 2908 | | if (_httpResponse != null) |
| | 2909 | | { |
| 0 | 2910 | | _httpResponse.Dispose(); |
| | 2911 | | } |
| 0 | 2912 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 2913 | | } |
| 0 | 2914 | | if (_shouldTrace) |
| | 2915 | | { |
| 0 | 2916 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2917 | | } |
| 0 | 2918 | | return _result; |
| 0 | 2919 | | } |
| | 2920 | |
|
| | 2921 | | /// <summary> |
| | 2922 | | /// Lists the Compute Nodes in the specified Pool. |
| | 2923 | | /// </summary> |
| | 2924 | | /// <param name='poolId'> |
| | 2925 | | /// The ID of the Pool from which you want to list Compute Nodes. |
| | 2926 | | /// </param> |
| | 2927 | | /// <param name='computeNodeListOptions'> |
| | 2928 | | /// Additional parameters for the operation |
| | 2929 | | /// </param> |
| | 2930 | | /// <param name='customHeaders'> |
| | 2931 | | /// Headers that will be added to request. |
| | 2932 | | /// </param> |
| | 2933 | | /// <param name='cancellationToken'> |
| | 2934 | | /// The cancellation token. |
| | 2935 | | /// </param> |
| | 2936 | | /// <exception cref="BatchErrorException"> |
| | 2937 | | /// Thrown when the operation returned an invalid status code |
| | 2938 | | /// </exception> |
| | 2939 | | /// <exception cref="SerializationException"> |
| | 2940 | | /// Thrown when unable to deserialize the response |
| | 2941 | | /// </exception> |
| | 2942 | | /// <exception cref="ValidationException"> |
| | 2943 | | /// Thrown when a required parameter is null |
| | 2944 | | /// </exception> |
| | 2945 | | /// <exception cref="System.ArgumentNullException"> |
| | 2946 | | /// Thrown when a required parameter is null |
| | 2947 | | /// </exception> |
| | 2948 | | /// <return> |
| | 2949 | | /// A response object containing the response body and response headers. |
| | 2950 | | /// </return> |
| | 2951 | | public async Task<AzureOperationResponse<IPage<ComputeNode>,ComputeNodeListHeaders>> ListWithHttpMessagesAsync(s |
| | 2952 | | { |
| 0 | 2953 | | if (Client.BatchUrl == null) |
| | 2954 | | { |
| 0 | 2955 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl"); |
| | 2956 | | } |
| 0 | 2957 | | if (poolId == null) |
| | 2958 | | { |
| 0 | 2959 | | throw new ValidationException(ValidationRules.CannotBeNull, "poolId"); |
| | 2960 | | } |
| 0 | 2961 | | if (Client.ApiVersion == null) |
| | 2962 | | { |
| 0 | 2963 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2964 | | } |
| 0 | 2965 | | string filter = default(string); |
| 0 | 2966 | | if (computeNodeListOptions != null) |
| | 2967 | | { |
| 0 | 2968 | | filter = computeNodeListOptions.Filter; |
| | 2969 | | } |
| 0 | 2970 | | string select = default(string); |
| 0 | 2971 | | if (computeNodeListOptions != null) |
| | 2972 | | { |
| 0 | 2973 | | select = computeNodeListOptions.Select; |
| | 2974 | | } |
| 0 | 2975 | | int? maxResults = default(int?); |
| 0 | 2976 | | if (computeNodeListOptions != null) |
| | 2977 | | { |
| 0 | 2978 | | maxResults = computeNodeListOptions.MaxResults; |
| | 2979 | | } |
| 0 | 2980 | | int? timeout = default(int?); |
| 0 | 2981 | | if (computeNodeListOptions != null) |
| | 2982 | | { |
| 0 | 2983 | | timeout = computeNodeListOptions.Timeout; |
| | 2984 | | } |
| 0 | 2985 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 2986 | | if (computeNodeListOptions != null) |
| | 2987 | | { |
| 0 | 2988 | | clientRequestId = computeNodeListOptions.ClientRequestId; |
| | 2989 | | } |
| 0 | 2990 | | bool? returnClientRequestId = default(bool?); |
| 0 | 2991 | | if (computeNodeListOptions != null) |
| | 2992 | | { |
| 0 | 2993 | | returnClientRequestId = computeNodeListOptions.ReturnClientRequestId; |
| | 2994 | | } |
| 0 | 2995 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 2996 | | if (computeNodeListOptions != null) |
| | 2997 | | { |
| 0 | 2998 | | ocpDate = computeNodeListOptions.OcpDate; |
| | 2999 | | } |
| | 3000 | | // Tracing |
| 0 | 3001 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3002 | | string _invocationId = null; |
| 0 | 3003 | | if (_shouldTrace) |
| | 3004 | | { |
| 0 | 3005 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3006 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3007 | | tracingParameters.Add("poolId", poolId); |
| 0 | 3008 | | tracingParameters.Add("filter", filter); |
| 0 | 3009 | | tracingParameters.Add("select", select); |
| 0 | 3010 | | tracingParameters.Add("maxResults", maxResults); |
| 0 | 3011 | | tracingParameters.Add("timeout", timeout); |
| 0 | 3012 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 3013 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 3014 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 3015 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3016 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 3017 | | } |
| | 3018 | | // Construct URL |
| 0 | 3019 | | var _baseUrl = Client.BaseUri; |
| 0 | 3020 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/nodes"; |
| 0 | 3021 | | _url = _url.Replace("{batchUrl}", Client.BatchUrl); |
| 0 | 3022 | | _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId)); |
| 0 | 3023 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3024 | | if (Client.ApiVersion != null) |
| | 3025 | | { |
| 0 | 3026 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 3027 | | } |
| 0 | 3028 | | if (filter != null) |
| | 3029 | | { |
| 0 | 3030 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 3031 | | } |
| 0 | 3032 | | if (select != null) |
| | 3033 | | { |
| 0 | 3034 | | _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select))); |
| | 3035 | | } |
| 0 | 3036 | | if (maxResults != null) |
| | 3037 | | { |
| 0 | 3038 | | _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 3039 | | } |
| 0 | 3040 | | if (timeout != null) |
| | 3041 | | { |
| 0 | 3042 | | _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 3043 | | } |
| 0 | 3044 | | if (_queryParameters.Count > 0) |
| | 3045 | | { |
| 0 | 3046 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3047 | | } |
| | 3048 | | // Create HTTP transport objects |
| 0 | 3049 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3050 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3051 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3052 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3053 | | // Set Headers |
| 0 | 3054 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3055 | | { |
| 0 | 3056 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 3057 | | } |
| 0 | 3058 | | if (Client.AcceptLanguage != null) |
| | 3059 | | { |
| 0 | 3060 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3061 | | { |
| 0 | 3062 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3063 | | } |
| 0 | 3064 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3065 | | } |
| 0 | 3066 | | if (clientRequestId != null) |
| | 3067 | | { |
| 0 | 3068 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 3069 | | { |
| 0 | 3070 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 3071 | | } |
| 0 | 3072 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 3073 | | } |
| 0 | 3074 | | if (returnClientRequestId != null) |
| | 3075 | | { |
| 0 | 3076 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 3077 | | { |
| 0 | 3078 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 3079 | | } |
| 0 | 3080 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 3081 | | } |
| 0 | 3082 | | if (ocpDate != null) |
| | 3083 | | { |
| 0 | 3084 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 3085 | | { |
| 0 | 3086 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 3087 | | } |
| 0 | 3088 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 3089 | | } |
| | 3090 | |
|
| | 3091 | |
|
| 0 | 3092 | | if (customHeaders != null) |
| | 3093 | | { |
| 0 | 3094 | | foreach(var _header in customHeaders) |
| | 3095 | | { |
| 0 | 3096 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3097 | | { |
| 0 | 3098 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3099 | | } |
| 0 | 3100 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3101 | | } |
| | 3102 | | } |
| | 3103 | |
|
| | 3104 | | // Serialize Request |
| 0 | 3105 | | string _requestContent = null; |
| | 3106 | | // Set Credentials |
| 0 | 3107 | | if (Client.Credentials != null) |
| | 3108 | | { |
| 0 | 3109 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3110 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3111 | | } |
| | 3112 | | // Send Request |
| 0 | 3113 | | if (_shouldTrace) |
| | 3114 | | { |
| 0 | 3115 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3116 | | } |
| 0 | 3117 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3118 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3119 | | if (_shouldTrace) |
| | 3120 | | { |
| 0 | 3121 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3122 | | } |
| 0 | 3123 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3124 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3125 | | string _responseContent = null; |
| 0 | 3126 | | if ((int)_statusCode != 200) |
| | 3127 | | { |
| 0 | 3128 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 3129 | | try |
| | 3130 | | { |
| 0 | 3131 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3132 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 3133 | | if (_errorBody != null) |
| | 3134 | | { |
| 0 | 3135 | | ex.Body = _errorBody; |
| | 3136 | | } |
| 0 | 3137 | | } |
| 0 | 3138 | | catch (JsonException) |
| | 3139 | | { |
| | 3140 | | // Ignore the exception |
| 0 | 3141 | | } |
| 0 | 3142 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3143 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3144 | | if (_shouldTrace) |
| | 3145 | | { |
| 0 | 3146 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3147 | | } |
| 0 | 3148 | | _httpRequest.Dispose(); |
| 0 | 3149 | | if (_httpResponse != null) |
| | 3150 | | { |
| 0 | 3151 | | _httpResponse.Dispose(); |
| | 3152 | | } |
| 0 | 3153 | | throw ex; |
| | 3154 | | } |
| | 3155 | | // Create Result |
| 0 | 3156 | | var _result = new AzureOperationResponse<IPage<ComputeNode>,ComputeNodeListHeaders>(); |
| 0 | 3157 | | _result.Request = _httpRequest; |
| 0 | 3158 | | _result.Response = _httpResponse; |
| 0 | 3159 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 3160 | | { |
| 0 | 3161 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 3162 | | } |
| | 3163 | | // Deserialize Response |
| 0 | 3164 | | if ((int)_statusCode == 200) |
| | 3165 | | { |
| 0 | 3166 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3167 | | try |
| | 3168 | | { |
| 0 | 3169 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<ComputeNode>>(_responseContent, Client.Deseria |
| 0 | 3170 | | } |
| 0 | 3171 | | catch (JsonException ex) |
| | 3172 | | { |
| 0 | 3173 | | _httpRequest.Dispose(); |
| 0 | 3174 | | if (_httpResponse != null) |
| | 3175 | | { |
| 0 | 3176 | | _httpResponse.Dispose(); |
| | 3177 | | } |
| 0 | 3178 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3179 | | } |
| | 3180 | | } |
| | 3181 | | try |
| | 3182 | | { |
| 0 | 3183 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeListHeaders>(JsonSerializer.Creat |
| 0 | 3184 | | } |
| 0 | 3185 | | catch (JsonException ex) |
| | 3186 | | { |
| 0 | 3187 | | _httpRequest.Dispose(); |
| 0 | 3188 | | if (_httpResponse != null) |
| | 3189 | | { |
| 0 | 3190 | | _httpResponse.Dispose(); |
| | 3191 | | } |
| 0 | 3192 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 3193 | | } |
| 0 | 3194 | | if (_shouldTrace) |
| | 3195 | | { |
| 0 | 3196 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3197 | | } |
| 0 | 3198 | | return _result; |
| 0 | 3199 | | } |
| | 3200 | |
|
| | 3201 | | /// <summary> |
| | 3202 | | /// Lists the Compute Nodes in the specified Pool. |
| | 3203 | | /// </summary> |
| | 3204 | | /// <param name='nextPageLink'> |
| | 3205 | | /// The NextLink from the previous successful call to List operation. |
| | 3206 | | /// </param> |
| | 3207 | | /// <param name='computeNodeListNextOptions'> |
| | 3208 | | /// Additional parameters for the operation |
| | 3209 | | /// </param> |
| | 3210 | | /// <param name='customHeaders'> |
| | 3211 | | /// Headers that will be added to request. |
| | 3212 | | /// </param> |
| | 3213 | | /// <param name='cancellationToken'> |
| | 3214 | | /// The cancellation token. |
| | 3215 | | /// </param> |
| | 3216 | | /// <exception cref="BatchErrorException"> |
| | 3217 | | /// Thrown when the operation returned an invalid status code |
| | 3218 | | /// </exception> |
| | 3219 | | /// <exception cref="SerializationException"> |
| | 3220 | | /// Thrown when unable to deserialize the response |
| | 3221 | | /// </exception> |
| | 3222 | | /// <exception cref="ValidationException"> |
| | 3223 | | /// Thrown when a required parameter is null |
| | 3224 | | /// </exception> |
| | 3225 | | /// <exception cref="System.ArgumentNullException"> |
| | 3226 | | /// Thrown when a required parameter is null |
| | 3227 | | /// </exception> |
| | 3228 | | /// <return> |
| | 3229 | | /// A response object containing the response body and response headers. |
| | 3230 | | /// </return> |
| | 3231 | | public async Task<AzureOperationResponse<IPage<ComputeNode>,ComputeNodeListHeaders>> ListNextWithHttpMessagesAsy |
| | 3232 | | { |
| 0 | 3233 | | if (nextPageLink == null) |
| | 3234 | | { |
| 0 | 3235 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 3236 | | } |
| 0 | 3237 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 3238 | | if (computeNodeListNextOptions != null) |
| | 3239 | | { |
| 0 | 3240 | | clientRequestId = computeNodeListNextOptions.ClientRequestId; |
| | 3241 | | } |
| 0 | 3242 | | bool? returnClientRequestId = default(bool?); |
| 0 | 3243 | | if (computeNodeListNextOptions != null) |
| | 3244 | | { |
| 0 | 3245 | | returnClientRequestId = computeNodeListNextOptions.ReturnClientRequestId; |
| | 3246 | | } |
| 0 | 3247 | | System.DateTime? ocpDate = default(System.DateTime?); |
| 0 | 3248 | | if (computeNodeListNextOptions != null) |
| | 3249 | | { |
| 0 | 3250 | | ocpDate = computeNodeListNextOptions.OcpDate; |
| | 3251 | | } |
| | 3252 | | // Tracing |
| 0 | 3253 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 3254 | | string _invocationId = null; |
| 0 | 3255 | | if (_shouldTrace) |
| | 3256 | | { |
| 0 | 3257 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3258 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3259 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 3260 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 3261 | | tracingParameters.Add("returnClientRequestId", returnClientRequestId); |
| 0 | 3262 | | tracingParameters.Add("ocpDate", ocpDate); |
| 0 | 3263 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3264 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 3265 | | } |
| | 3266 | | // Construct URL |
| 0 | 3267 | | string _url = "{nextLink}"; |
| 0 | 3268 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 3269 | | List<string> _queryParameters = new List<string>(); |
| 0 | 3270 | | if (_queryParameters.Count > 0) |
| | 3271 | | { |
| 0 | 3272 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 3273 | | } |
| | 3274 | | // Create HTTP transport objects |
| 0 | 3275 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 3276 | | HttpResponseMessage _httpResponse = null; |
| 0 | 3277 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 3278 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3279 | | // Set Headers |
| 0 | 3280 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 3281 | | { |
| 0 | 3282 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 3283 | | } |
| 0 | 3284 | | if (Client.AcceptLanguage != null) |
| | 3285 | | { |
| 0 | 3286 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 3287 | | { |
| 0 | 3288 | | _httpRequest.Headers.Remove("accept-language"); |
| | 3289 | | } |
| 0 | 3290 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 3291 | | } |
| 0 | 3292 | | if (clientRequestId != null) |
| | 3293 | | { |
| 0 | 3294 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 3295 | | { |
| 0 | 3296 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 3297 | | } |
| 0 | 3298 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 3299 | | } |
| 0 | 3300 | | if (returnClientRequestId != null) |
| | 3301 | | { |
| 0 | 3302 | | if (_httpRequest.Headers.Contains("return-client-request-id")) |
| | 3303 | | { |
| 0 | 3304 | | _httpRequest.Headers.Remove("return-client-request-id"); |
| | 3305 | | } |
| 0 | 3306 | | _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject |
| | 3307 | | } |
| 0 | 3308 | | if (ocpDate != null) |
| | 3309 | | { |
| 0 | 3310 | | if (_httpRequest.Headers.Contains("ocp-date")) |
| | 3311 | | { |
| 0 | 3312 | | _httpRequest.Headers.Remove("ocp-date"); |
| | 3313 | | } |
| 0 | 3314 | | _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da |
| | 3315 | | } |
| | 3316 | |
|
| | 3317 | |
|
| 0 | 3318 | | if (customHeaders != null) |
| | 3319 | | { |
| 0 | 3320 | | foreach(var _header in customHeaders) |
| | 3321 | | { |
| 0 | 3322 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3323 | | { |
| 0 | 3324 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3325 | | } |
| 0 | 3326 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3327 | | } |
| | 3328 | | } |
| | 3329 | |
|
| | 3330 | | // Serialize Request |
| 0 | 3331 | | string _requestContent = null; |
| | 3332 | | // Set Credentials |
| 0 | 3333 | | if (Client.Credentials != null) |
| | 3334 | | { |
| 0 | 3335 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3336 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3337 | | } |
| | 3338 | | // Send Request |
| 0 | 3339 | | if (_shouldTrace) |
| | 3340 | | { |
| 0 | 3341 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3342 | | } |
| 0 | 3343 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3344 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 3345 | | if (_shouldTrace) |
| | 3346 | | { |
| 0 | 3347 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3348 | | } |
| 0 | 3349 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 3350 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 3351 | | string _responseContent = null; |
| 0 | 3352 | | if ((int)_statusCode != 200) |
| | 3353 | | { |
| 0 | 3354 | | var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 3355 | | try |
| | 3356 | | { |
| 0 | 3357 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3358 | | BatchError _errorBody = SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese |
| 0 | 3359 | | if (_errorBody != null) |
| | 3360 | | { |
| 0 | 3361 | | ex.Body = _errorBody; |
| | 3362 | | } |
| 0 | 3363 | | } |
| 0 | 3364 | | catch (JsonException) |
| | 3365 | | { |
| | 3366 | | // Ignore the exception |
| 0 | 3367 | | } |
| 0 | 3368 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3369 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3370 | | if (_shouldTrace) |
| | 3371 | | { |
| 0 | 3372 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3373 | | } |
| 0 | 3374 | | _httpRequest.Dispose(); |
| 0 | 3375 | | if (_httpResponse != null) |
| | 3376 | | { |
| 0 | 3377 | | _httpResponse.Dispose(); |
| | 3378 | | } |
| 0 | 3379 | | throw ex; |
| | 3380 | | } |
| | 3381 | | // Create Result |
| 0 | 3382 | | var _result = new AzureOperationResponse<IPage<ComputeNode>,ComputeNodeListHeaders>(); |
| 0 | 3383 | | _result.Request = _httpRequest; |
| 0 | 3384 | | _result.Response = _httpResponse; |
| 0 | 3385 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 3386 | | { |
| 0 | 3387 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 3388 | | } |
| | 3389 | | // Deserialize Response |
| 0 | 3390 | | if ((int)_statusCode == 200) |
| | 3391 | | { |
| 0 | 3392 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3393 | | try |
| | 3394 | | { |
| 0 | 3395 | | _result.Body = SafeJsonConvert.DeserializeObject<Page<ComputeNode>>(_responseContent, Client.Deseria |
| 0 | 3396 | | } |
| 0 | 3397 | | catch (JsonException ex) |
| | 3398 | | { |
| 0 | 3399 | | _httpRequest.Dispose(); |
| 0 | 3400 | | if (_httpResponse != null) |
| | 3401 | | { |
| 0 | 3402 | | _httpResponse.Dispose(); |
| | 3403 | | } |
| 0 | 3404 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3405 | | } |
| | 3406 | | } |
| | 3407 | | try |
| | 3408 | | { |
| 0 | 3409 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ComputeNodeListHeaders>(JsonSerializer.Creat |
| 0 | 3410 | | } |
| 0 | 3411 | | catch (JsonException ex) |
| | 3412 | | { |
| 0 | 3413 | | _httpRequest.Dispose(); |
| 0 | 3414 | | if (_httpResponse != null) |
| | 3415 | | { |
| 0 | 3416 | | _httpResponse.Dispose(); |
| | 3417 | | } |
| 0 | 3418 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 3419 | | } |
| 0 | 3420 | | if (_shouldTrace) |
| | 3421 | | { |
| 0 | 3422 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3423 | | } |
| 0 | 3424 | | return _result; |
| 0 | 3425 | | } |
| | 3426 | |
|
| | 3427 | | } |
| | 3428 | | } |