| | 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.Management.Search |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Azure; |
| | 15 | | using Models; |
| | 16 | | using Newtonsoft.Json; |
| | 17 | | using System.Collections; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.Linq; |
| | 20 | | using System.Net; |
| | 21 | | using System.Net.Http; |
| | 22 | | using System.Threading; |
| | 23 | | using System.Threading.Tasks; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// AdminKeysOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | internal partial class AdminKeysOperations : IServiceOperations<SearchManagementClient>, IAdminKeysOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the AdminKeysOperations class. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name='client'> |
| | 34 | | /// Reference to the service client. |
| | 35 | | /// </param> |
| | 36 | | /// <exception cref="System.ArgumentNullException"> |
| | 37 | | /// Thrown when a required parameter is null |
| | 38 | | /// </exception> |
| 1204 | 39 | | internal AdminKeysOperations(SearchManagementClient client) |
| | 40 | | { |
| 1204 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 1204 | 45 | | Client = client; |
| 1204 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the SearchManagementClient |
| | 50 | | /// </summary> |
| 9632 | 51 | | public SearchManagementClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Gets the primary and secondary admin API keys for the specified Azure |
| | 55 | | /// Cognitive Search service. |
| | 56 | | /// <see href="https://aka.ms/search-manage" /> |
| | 57 | | /// </summary> |
| | 58 | | /// <param name='resourceGroupName'> |
| | 59 | | /// The name of the resource group within the current subscription. You can |
| | 60 | | /// obtain this value from the Azure Resource Manager API or the portal. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='searchServiceName'> |
| | 63 | | /// The name of the Azure Cognitive Search service associated with the |
| | 64 | | /// specified resource group. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='searchManagementRequestOptions'> |
| | 67 | | /// Additional parameters for the operation |
| | 68 | | /// </param> |
| | 69 | | /// <param name='customHeaders'> |
| | 70 | | /// Headers that will be added to request. |
| | 71 | | /// </param> |
| | 72 | | /// <param name='cancellationToken'> |
| | 73 | | /// The cancellation token. |
| | 74 | | /// </param> |
| | 75 | | /// <exception cref="CloudException"> |
| | 76 | | /// Thrown when the operation returned an invalid status code |
| | 77 | | /// </exception> |
| | 78 | | /// <exception cref="SerializationException"> |
| | 79 | | /// Thrown when unable to deserialize the response |
| | 80 | | /// </exception> |
| | 81 | | /// <exception cref="ValidationException"> |
| | 82 | | /// Thrown when a required parameter is null |
| | 83 | | /// </exception> |
| | 84 | | /// <exception cref="System.ArgumentNullException"> |
| | 85 | | /// Thrown when a required parameter is null |
| | 86 | | /// </exception> |
| | 87 | | /// <return> |
| | 88 | | /// A response object containing the response body and response headers. |
| | 89 | | /// </return> |
| | 90 | | public async Task<AzureOperationResponse<AdminKeyResult>> GetWithHttpMessagesAsync(string resourceGroupName, str |
| | 91 | | { |
| 602 | 92 | | if (resourceGroupName == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); |
| | 95 | | } |
| 602 | 96 | | if (searchServiceName == null) |
| | 97 | | { |
| 0 | 98 | | throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName"); |
| | 99 | | } |
| 602 | 100 | | if (Client.ApiVersion == null) |
| | 101 | | { |
| 0 | 102 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 103 | | } |
| 602 | 104 | | if (Client.SubscriptionId == null) |
| | 105 | | { |
| 0 | 106 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); |
| | 107 | | } |
| 602 | 108 | | System.Guid? clientRequestId = default(System.Guid?); |
| 602 | 109 | | if (searchManagementRequestOptions != null) |
| | 110 | | { |
| 0 | 111 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | 112 | | } |
| | 113 | | // Tracing |
| 602 | 114 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 602 | 115 | | string _invocationId = null; |
| 602 | 116 | | if (_shouldTrace) |
| | 117 | | { |
| 0 | 118 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 119 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 120 | | tracingParameters.Add("resourceGroupName", resourceGroupName); |
| 0 | 121 | | tracingParameters.Add("searchServiceName", searchServiceName); |
| 0 | 122 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 123 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 124 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 125 | | } |
| | 126 | | // Construct URL |
| 602 | 127 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 602 | 128 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su |
| 602 | 129 | | _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); |
| 602 | 130 | | _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName)); |
| 602 | 131 | | _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); |
| 602 | 132 | | List<string> _queryParameters = new List<string>(); |
| 602 | 133 | | if (Client.ApiVersion != null) |
| | 134 | | { |
| 602 | 135 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 136 | | } |
| 602 | 137 | | if (_queryParameters.Count > 0) |
| | 138 | | { |
| 602 | 139 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 140 | | } |
| | 141 | | // Create HTTP transport objects |
| 602 | 142 | | var _httpRequest = new HttpRequestMessage(); |
| 602 | 143 | | HttpResponseMessage _httpResponse = null; |
| 602 | 144 | | _httpRequest.Method = new HttpMethod("POST"); |
| 602 | 145 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 146 | | // Set Headers |
| 602 | 147 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 148 | | { |
| 602 | 149 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 150 | | } |
| 602 | 151 | | if (Client.AcceptLanguage != null) |
| | 152 | | { |
| 602 | 153 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 154 | | { |
| 0 | 155 | | _httpRequest.Headers.Remove("accept-language"); |
| | 156 | | } |
| 602 | 157 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 158 | | } |
| 602 | 159 | | if (clientRequestId != null) |
| | 160 | | { |
| 0 | 161 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | 162 | | { |
| 0 | 163 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | 164 | | } |
| 0 | 165 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | 166 | | } |
| | 167 | |
|
| | 168 | |
|
| 602 | 169 | | if (customHeaders != null) |
| | 170 | | { |
| 0 | 171 | | foreach(var _header in customHeaders) |
| | 172 | | { |
| 0 | 173 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 174 | | { |
| 0 | 175 | | _httpRequest.Headers.Remove(_header.Key); |
| | 176 | | } |
| 0 | 177 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 178 | | } |
| | 179 | | } |
| | 180 | |
|
| | 181 | | // Serialize Request |
| 602 | 182 | | string _requestContent = null; |
| | 183 | | // Set Credentials |
| 602 | 184 | | if (Client.Credentials != null) |
| | 185 | | { |
| 602 | 186 | | cancellationToken.ThrowIfCancellationRequested(); |
| 602 | 187 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 188 | | } |
| | 189 | | // Send Request |
| 602 | 190 | | if (_shouldTrace) |
| | 191 | | { |
| 0 | 192 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 193 | | } |
| 602 | 194 | | cancellationToken.ThrowIfCancellationRequested(); |
| 602 | 195 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 602 | 196 | | if (_shouldTrace) |
| | 197 | | { |
| 0 | 198 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 199 | | } |
| 602 | 200 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 602 | 201 | | cancellationToken.ThrowIfCancellationRequested(); |
| 602 | 202 | | string _responseContent = null; |
| 602 | 203 | | if ((int)_statusCode != 200) |
| | 204 | | { |
| 0 | 205 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 206 | | try |
| | 207 | | { |
| 0 | 208 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 209 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 210 | | if (_errorBody != null) |
| | 211 | | { |
| 0 | 212 | | ex = new CloudException(_errorBody.Message); |
| 0 | 213 | | ex.Body = _errorBody; |
| | 214 | | } |
| 0 | 215 | | } |
| 0 | 216 | | catch (JsonException) |
| | 217 | | { |
| | 218 | | // Ignore the exception |
| 0 | 219 | | } |
| 0 | 220 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 221 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 222 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 223 | | { |
| 0 | 224 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 225 | | } |
| 0 | 226 | | if (_shouldTrace) |
| | 227 | | { |
| 0 | 228 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 229 | | } |
| 0 | 230 | | _httpRequest.Dispose(); |
| 0 | 231 | | if (_httpResponse != null) |
| | 232 | | { |
| 0 | 233 | | _httpResponse.Dispose(); |
| | 234 | | } |
| 0 | 235 | | throw ex; |
| | 236 | | } |
| | 237 | | // Create Result |
| 602 | 238 | | var _result = new AzureOperationResponse<AdminKeyResult>(); |
| 602 | 239 | | _result.Request = _httpRequest; |
| 602 | 240 | | _result.Response = _httpResponse; |
| 602 | 241 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 242 | | { |
| 602 | 243 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 244 | | } |
| | 245 | | // Deserialize Response |
| 602 | 246 | | if ((int)_statusCode == 200) |
| | 247 | | { |
| 602 | 248 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 249 | | try |
| | 250 | | { |
| 602 | 251 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AdminKeyResult>(_responseContent |
| 602 | 252 | | } |
| 0 | 253 | | catch (JsonException ex) |
| | 254 | | { |
| 0 | 255 | | _httpRequest.Dispose(); |
| 0 | 256 | | if (_httpResponse != null) |
| | 257 | | { |
| 0 | 258 | | _httpResponse.Dispose(); |
| | 259 | | } |
| 0 | 260 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 261 | | } |
| | 262 | | } |
| 602 | 263 | | if (_shouldTrace) |
| | 264 | | { |
| 0 | 265 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 266 | | } |
| 602 | 267 | | return _result; |
| 602 | 268 | | } |
| | 269 | |
|
| | 270 | | /// <summary> |
| | 271 | | /// Regenerates either the primary or secondary admin API key. You can only |
| | 272 | | /// regenerate one key at a time. |
| | 273 | | /// <see href="https://aka.ms/search-manage" /> |
| | 274 | | /// </summary> |
| | 275 | | /// <param name='resourceGroupName'> |
| | 276 | | /// The name of the resource group within the current subscription. You can |
| | 277 | | /// obtain this value from the Azure Resource Manager API or the portal. |
| | 278 | | /// </param> |
| | 279 | | /// <param name='searchServiceName'> |
| | 280 | | /// The name of the Azure Cognitive Search service associated with the |
| | 281 | | /// specified resource group. |
| | 282 | | /// </param> |
| | 283 | | /// <param name='keyKind'> |
| | 284 | | /// Specifies which key to regenerate. Valid values include 'primary' and |
| | 285 | | /// 'secondary'. Possible values include: 'primary', 'secondary' |
| | 286 | | /// </param> |
| | 287 | | /// <param name='searchManagementRequestOptions'> |
| | 288 | | /// Additional parameters for the operation |
| | 289 | | /// </param> |
| | 290 | | /// <param name='customHeaders'> |
| | 291 | | /// Headers that will be added to request. |
| | 292 | | /// </param> |
| | 293 | | /// <param name='cancellationToken'> |
| | 294 | | /// The cancellation token. |
| | 295 | | /// </param> |
| | 296 | | /// <exception cref="CloudException"> |
| | 297 | | /// Thrown when the operation returned an invalid status code |
| | 298 | | /// </exception> |
| | 299 | | /// <exception cref="SerializationException"> |
| | 300 | | /// Thrown when unable to deserialize the response |
| | 301 | | /// </exception> |
| | 302 | | /// <exception cref="ValidationException"> |
| | 303 | | /// Thrown when a required parameter is null |
| | 304 | | /// </exception> |
| | 305 | | /// <exception cref="System.ArgumentNullException"> |
| | 306 | | /// Thrown when a required parameter is null |
| | 307 | | /// </exception> |
| | 308 | | /// <return> |
| | 309 | | /// A response object containing the response body and response headers. |
| | 310 | | /// </return> |
| | 311 | | public async Task<AzureOperationResponse<AdminKeyResult>> RegenerateWithHttpMessagesAsync(string resourceGroupNa |
| | 312 | | { |
| 0 | 313 | | if (resourceGroupName == null) |
| | 314 | | { |
| 0 | 315 | | throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); |
| | 316 | | } |
| 0 | 317 | | if (searchServiceName == null) |
| | 318 | | { |
| 0 | 319 | | throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName"); |
| | 320 | | } |
| 0 | 321 | | if (Client.ApiVersion == null) |
| | 322 | | { |
| 0 | 323 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 324 | | } |
| 0 | 325 | | if (Client.SubscriptionId == null) |
| | 326 | | { |
| 0 | 327 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); |
| | 328 | | } |
| 0 | 329 | | System.Guid? clientRequestId = default(System.Guid?); |
| 0 | 330 | | if (searchManagementRequestOptions != null) |
| | 331 | | { |
| 0 | 332 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | 333 | | } |
| | 334 | | // Tracing |
| 0 | 335 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 336 | | string _invocationId = null; |
| 0 | 337 | | if (_shouldTrace) |
| | 338 | | { |
| 0 | 339 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 340 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 341 | | tracingParameters.Add("resourceGroupName", resourceGroupName); |
| 0 | 342 | | tracingParameters.Add("searchServiceName", searchServiceName); |
| 0 | 343 | | tracingParameters.Add("keyKind", keyKind); |
| 0 | 344 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 345 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 346 | | ServiceClientTracing.Enter(_invocationId, this, "Regenerate", tracingParameters); |
| | 347 | | } |
| | 348 | | // Construct URL |
| 0 | 349 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 350 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su |
| 0 | 351 | | _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); |
| 0 | 352 | | _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName)); |
| 0 | 353 | | _url = _url.Replace("{keyKind}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObj |
| 0 | 354 | | _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); |
| 0 | 355 | | List<string> _queryParameters = new List<string>(); |
| 0 | 356 | | if (Client.ApiVersion != null) |
| | 357 | | { |
| 0 | 358 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 359 | | } |
| 0 | 360 | | if (_queryParameters.Count > 0) |
| | 361 | | { |
| 0 | 362 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 363 | | } |
| | 364 | | // Create HTTP transport objects |
| 0 | 365 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 366 | | HttpResponseMessage _httpResponse = null; |
| 0 | 367 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 368 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 369 | | // Set Headers |
| 0 | 370 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 371 | | { |
| 0 | 372 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 373 | | } |
| 0 | 374 | | if (Client.AcceptLanguage != null) |
| | 375 | | { |
| 0 | 376 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 377 | | { |
| 0 | 378 | | _httpRequest.Headers.Remove("accept-language"); |
| | 379 | | } |
| 0 | 380 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 381 | | } |
| 0 | 382 | | if (clientRequestId != null) |
| | 383 | | { |
| 0 | 384 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | 385 | | { |
| 0 | 386 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | 387 | | } |
| 0 | 388 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | 389 | | } |
| | 390 | |
|
| | 391 | |
|
| 0 | 392 | | if (customHeaders != null) |
| | 393 | | { |
| 0 | 394 | | foreach(var _header in customHeaders) |
| | 395 | | { |
| 0 | 396 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 397 | | { |
| 0 | 398 | | _httpRequest.Headers.Remove(_header.Key); |
| | 399 | | } |
| 0 | 400 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 401 | | } |
| | 402 | | } |
| | 403 | |
|
| | 404 | | // Serialize Request |
| 0 | 405 | | string _requestContent = null; |
| | 406 | | // Set Credentials |
| 0 | 407 | | if (Client.Credentials != null) |
| | 408 | | { |
| 0 | 409 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 410 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 411 | | } |
| | 412 | | // Send Request |
| 0 | 413 | | if (_shouldTrace) |
| | 414 | | { |
| 0 | 415 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 416 | | } |
| 0 | 417 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 418 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 419 | | if (_shouldTrace) |
| | 420 | | { |
| 0 | 421 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 422 | | } |
| 0 | 423 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 424 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 425 | | string _responseContent = null; |
| 0 | 426 | | if ((int)_statusCode != 200) |
| | 427 | | { |
| 0 | 428 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 429 | | try |
| | 430 | | { |
| 0 | 431 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 432 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| 0 | 433 | | if (_errorBody != null) |
| | 434 | | { |
| 0 | 435 | | ex = new CloudException(_errorBody.Message); |
| 0 | 436 | | ex.Body = _errorBody; |
| | 437 | | } |
| 0 | 438 | | } |
| 0 | 439 | | catch (JsonException) |
| | 440 | | { |
| | 441 | | // Ignore the exception |
| 0 | 442 | | } |
| 0 | 443 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 444 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 445 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 446 | | { |
| 0 | 447 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 448 | | } |
| 0 | 449 | | if (_shouldTrace) |
| | 450 | | { |
| 0 | 451 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 452 | | } |
| 0 | 453 | | _httpRequest.Dispose(); |
| 0 | 454 | | if (_httpResponse != null) |
| | 455 | | { |
| 0 | 456 | | _httpResponse.Dispose(); |
| | 457 | | } |
| 0 | 458 | | throw ex; |
| | 459 | | } |
| | 460 | | // Create Result |
| 0 | 461 | | var _result = new AzureOperationResponse<AdminKeyResult>(); |
| 0 | 462 | | _result.Request = _httpRequest; |
| 0 | 463 | | _result.Response = _httpResponse; |
| 0 | 464 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 465 | | { |
| 0 | 466 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 467 | | } |
| | 468 | | // Deserialize Response |
| 0 | 469 | | if ((int)_statusCode == 200) |
| | 470 | | { |
| 0 | 471 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 472 | | try |
| | 473 | | { |
| 0 | 474 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AdminKeyResult>(_responseContent |
| 0 | 475 | | } |
| 0 | 476 | | catch (JsonException ex) |
| | 477 | | { |
| 0 | 478 | | _httpRequest.Dispose(); |
| 0 | 479 | | if (_httpResponse != null) |
| | 480 | | { |
| 0 | 481 | | _httpResponse.Dispose(); |
| | 482 | | } |
| 0 | 483 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 484 | | } |
| | 485 | | } |
| 0 | 486 | | if (_shouldTrace) |
| | 487 | | { |
| 0 | 488 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 489 | | } |
| 0 | 490 | | return _result; |
| 0 | 491 | | } |
| | 492 | |
|
| | 493 | | } |
| | 494 | | } |