| | | 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 | | /// QueryKeysOperations operations. |
| | | 27 | | /// </summary> |
| | | 28 | | internal partial class QueryKeysOperations : IServiceOperations<SearchManagementClient>, IQueryKeysOperations |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// Initializes a new instance of the QueryKeysOperations 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 QueryKeysOperations(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 | | /// Generates a new query key for the specified Search service. You can create |
| | | 55 | | /// up to 50 query keys per 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='name'> |
| | | 67 | | /// The name of the new query API key. |
| | | 68 | | /// </param> |
| | | 69 | | /// <param name='searchManagementRequestOptions'> |
| | | 70 | | /// Additional parameters for the operation |
| | | 71 | | /// </param> |
| | | 72 | | /// <param name='customHeaders'> |
| | | 73 | | /// Headers that will be added to request. |
| | | 74 | | /// </param> |
| | | 75 | | /// <param name='cancellationToken'> |
| | | 76 | | /// The cancellation token. |
| | | 77 | | /// </param> |
| | | 78 | | /// <exception cref="CloudException"> |
| | | 79 | | /// Thrown when the operation returned an invalid status code |
| | | 80 | | /// </exception> |
| | | 81 | | /// <exception cref="SerializationException"> |
| | | 82 | | /// Thrown when unable to deserialize the response |
| | | 83 | | /// </exception> |
| | | 84 | | /// <exception cref="ValidationException"> |
| | | 85 | | /// Thrown when a required parameter is null |
| | | 86 | | /// </exception> |
| | | 87 | | /// <exception cref="System.ArgumentNullException"> |
| | | 88 | | /// Thrown when a required parameter is null |
| | | 89 | | /// </exception> |
| | | 90 | | /// <return> |
| | | 91 | | /// A response object containing the response body and response headers. |
| | | 92 | | /// </return> |
| | | 93 | | public async Task<AzureOperationResponse<QueryKey>> CreateWithHttpMessagesAsync(string resourceGroupName, string |
| | | 94 | | { |
| | 0 | 95 | | if (resourceGroupName == null) |
| | | 96 | | { |
| | 0 | 97 | | throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); |
| | | 98 | | } |
| | 0 | 99 | | if (searchServiceName == null) |
| | | 100 | | { |
| | 0 | 101 | | throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName"); |
| | | 102 | | } |
| | 0 | 103 | | if (name == null) |
| | | 104 | | { |
| | 0 | 105 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | | 106 | | } |
| | 0 | 107 | | if (Client.ApiVersion == null) |
| | | 108 | | { |
| | 0 | 109 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 110 | | } |
| | 0 | 111 | | if (Client.SubscriptionId == null) |
| | | 112 | | { |
| | 0 | 113 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); |
| | | 114 | | } |
| | 0 | 115 | | System.Guid? clientRequestId = default(System.Guid?); |
| | 0 | 116 | | if (searchManagementRequestOptions != null) |
| | | 117 | | { |
| | 0 | 118 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | | 119 | | } |
| | | 120 | | // Tracing |
| | 0 | 121 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 122 | | string _invocationId = null; |
| | 0 | 123 | | if (_shouldTrace) |
| | | 124 | | { |
| | 0 | 125 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 126 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 127 | | tracingParameters.Add("resourceGroupName", resourceGroupName); |
| | 0 | 128 | | tracingParameters.Add("searchServiceName", searchServiceName); |
| | 0 | 129 | | tracingParameters.Add("name", name); |
| | 0 | 130 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| | 0 | 131 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 132 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | | 133 | | } |
| | | 134 | | // Construct URL |
| | 0 | 135 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 0 | 136 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su |
| | 0 | 137 | | _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); |
| | 0 | 138 | | _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName)); |
| | 0 | 139 | | _url = _url.Replace("{name}", System.Uri.EscapeDataString(name)); |
| | 0 | 140 | | _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); |
| | 0 | 141 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 142 | | if (Client.ApiVersion != null) |
| | | 143 | | { |
| | 0 | 144 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 145 | | } |
| | 0 | 146 | | if (_queryParameters.Count > 0) |
| | | 147 | | { |
| | 0 | 148 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 149 | | } |
| | | 150 | | // Create HTTP transport objects |
| | 0 | 151 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 152 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 153 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 0 | 154 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 155 | | // Set Headers |
| | 0 | 156 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 157 | | { |
| | 0 | 158 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 159 | | } |
| | 0 | 160 | | if (Client.AcceptLanguage != null) |
| | | 161 | | { |
| | 0 | 162 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 163 | | { |
| | 0 | 164 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 165 | | } |
| | 0 | 166 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 167 | | } |
| | 0 | 168 | | if (clientRequestId != null) |
| | | 169 | | { |
| | 0 | 170 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | | 171 | | { |
| | 0 | 172 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | | 173 | | } |
| | 0 | 174 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | |
| | 0 | 178 | | if (customHeaders != null) |
| | | 179 | | { |
| | 0 | 180 | | foreach(var _header in customHeaders) |
| | | 181 | | { |
| | 0 | 182 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 183 | | { |
| | 0 | 184 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 185 | | } |
| | 0 | 186 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 187 | | } |
| | | 188 | | } |
| | | 189 | | |
| | | 190 | | // Serialize Request |
| | 0 | 191 | | string _requestContent = null; |
| | | 192 | | // Set Credentials |
| | 0 | 193 | | if (Client.Credentials != null) |
| | | 194 | | { |
| | 0 | 195 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 196 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 197 | | } |
| | | 198 | | // Send Request |
| | 0 | 199 | | if (_shouldTrace) |
| | | 200 | | { |
| | 0 | 201 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 202 | | } |
| | 0 | 203 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 204 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 205 | | if (_shouldTrace) |
| | | 206 | | { |
| | 0 | 207 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 208 | | } |
| | 0 | 209 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 210 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 211 | | string _responseContent = null; |
| | 0 | 212 | | if ((int)_statusCode != 200) |
| | | 213 | | { |
| | 0 | 214 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 215 | | try |
| | | 216 | | { |
| | 0 | 217 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 218 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| | 0 | 219 | | if (_errorBody != null) |
| | | 220 | | { |
| | 0 | 221 | | ex = new CloudException(_errorBody.Message); |
| | 0 | 222 | | ex.Body = _errorBody; |
| | | 223 | | } |
| | 0 | 224 | | } |
| | 0 | 225 | | catch (JsonException) |
| | | 226 | | { |
| | | 227 | | // Ignore the exception |
| | 0 | 228 | | } |
| | 0 | 229 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 230 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 231 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 232 | | { |
| | 0 | 233 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 234 | | } |
| | 0 | 235 | | if (_shouldTrace) |
| | | 236 | | { |
| | 0 | 237 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 238 | | } |
| | 0 | 239 | | _httpRequest.Dispose(); |
| | 0 | 240 | | if (_httpResponse != null) |
| | | 241 | | { |
| | 0 | 242 | | _httpResponse.Dispose(); |
| | | 243 | | } |
| | 0 | 244 | | throw ex; |
| | | 245 | | } |
| | | 246 | | // Create Result |
| | 0 | 247 | | var _result = new AzureOperationResponse<QueryKey>(); |
| | 0 | 248 | | _result.Request = _httpRequest; |
| | 0 | 249 | | _result.Response = _httpResponse; |
| | 0 | 250 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 251 | | { |
| | 0 | 252 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 253 | | } |
| | | 254 | | // Deserialize Response |
| | 0 | 255 | | if ((int)_statusCode == 200) |
| | | 256 | | { |
| | 0 | 257 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 258 | | try |
| | | 259 | | { |
| | 0 | 260 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<QueryKey>(_responseContent, Clie |
| | 0 | 261 | | } |
| | 0 | 262 | | catch (JsonException ex) |
| | | 263 | | { |
| | 0 | 264 | | _httpRequest.Dispose(); |
| | 0 | 265 | | if (_httpResponse != null) |
| | | 266 | | { |
| | 0 | 267 | | _httpResponse.Dispose(); |
| | | 268 | | } |
| | 0 | 269 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 270 | | } |
| | | 271 | | } |
| | 0 | 272 | | if (_shouldTrace) |
| | | 273 | | { |
| | 0 | 274 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 275 | | } |
| | 0 | 276 | | return _result; |
| | 0 | 277 | | } |
| | | 278 | | |
| | | 279 | | /// <summary> |
| | | 280 | | /// Returns the list of query API keys for the given Azure Cognitive Search |
| | | 281 | | /// service. |
| | | 282 | | /// <see href="https://aka.ms/search-manage" /> |
| | | 283 | | /// </summary> |
| | | 284 | | /// <param name='resourceGroupName'> |
| | | 285 | | /// The name of the resource group within the current subscription. You can |
| | | 286 | | /// obtain this value from the Azure Resource Manager API or the portal. |
| | | 287 | | /// </param> |
| | | 288 | | /// <param name='searchServiceName'> |
| | | 289 | | /// The name of the Azure Cognitive Search service associated with the |
| | | 290 | | /// specified resource group. |
| | | 291 | | /// </param> |
| | | 292 | | /// <param name='searchManagementRequestOptions'> |
| | | 293 | | /// Additional parameters for the operation |
| | | 294 | | /// </param> |
| | | 295 | | /// <param name='customHeaders'> |
| | | 296 | | /// Headers that will be added to request. |
| | | 297 | | /// </param> |
| | | 298 | | /// <param name='cancellationToken'> |
| | | 299 | | /// The cancellation token. |
| | | 300 | | /// </param> |
| | | 301 | | /// <exception cref="CloudException"> |
| | | 302 | | /// Thrown when the operation returned an invalid status code |
| | | 303 | | /// </exception> |
| | | 304 | | /// <exception cref="SerializationException"> |
| | | 305 | | /// Thrown when unable to deserialize the response |
| | | 306 | | /// </exception> |
| | | 307 | | /// <exception cref="ValidationException"> |
| | | 308 | | /// Thrown when a required parameter is null |
| | | 309 | | /// </exception> |
| | | 310 | | /// <exception cref="System.ArgumentNullException"> |
| | | 311 | | /// Thrown when a required parameter is null |
| | | 312 | | /// </exception> |
| | | 313 | | /// <return> |
| | | 314 | | /// A response object containing the response body and response headers. |
| | | 315 | | /// </return> |
| | | 316 | | public async Task<AzureOperationResponse<IPage<QueryKey>>> ListBySearchServiceWithHttpMessagesAsync(string resou |
| | | 317 | | { |
| | 602 | 318 | | if (resourceGroupName == null) |
| | | 319 | | { |
| | 0 | 320 | | throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); |
| | | 321 | | } |
| | 602 | 322 | | if (searchServiceName == null) |
| | | 323 | | { |
| | 0 | 324 | | throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName"); |
| | | 325 | | } |
| | 602 | 326 | | if (Client.ApiVersion == null) |
| | | 327 | | { |
| | 0 | 328 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 329 | | } |
| | 602 | 330 | | if (Client.SubscriptionId == null) |
| | | 331 | | { |
| | 0 | 332 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); |
| | | 333 | | } |
| | 602 | 334 | | System.Guid? clientRequestId = default(System.Guid?); |
| | 602 | 335 | | if (searchManagementRequestOptions != null) |
| | | 336 | | { |
| | 0 | 337 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | | 338 | | } |
| | | 339 | | // Tracing |
| | 602 | 340 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 602 | 341 | | string _invocationId = null; |
| | 602 | 342 | | if (_shouldTrace) |
| | | 343 | | { |
| | 0 | 344 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 345 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 346 | | tracingParameters.Add("resourceGroupName", resourceGroupName); |
| | 0 | 347 | | tracingParameters.Add("searchServiceName", searchServiceName); |
| | 0 | 348 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| | 0 | 349 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 350 | | ServiceClientTracing.Enter(_invocationId, this, "ListBySearchService", tracingParameters); |
| | | 351 | | } |
| | | 352 | | // Construct URL |
| | 602 | 353 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 602 | 354 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su |
| | 602 | 355 | | _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); |
| | 602 | 356 | | _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName)); |
| | 602 | 357 | | _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); |
| | 602 | 358 | | List<string> _queryParameters = new List<string>(); |
| | 602 | 359 | | if (Client.ApiVersion != null) |
| | | 360 | | { |
| | 602 | 361 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 362 | | } |
| | 602 | 363 | | if (_queryParameters.Count > 0) |
| | | 364 | | { |
| | 602 | 365 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 366 | | } |
| | | 367 | | // Create HTTP transport objects |
| | 602 | 368 | | var _httpRequest = new HttpRequestMessage(); |
| | 602 | 369 | | HttpResponseMessage _httpResponse = null; |
| | 602 | 370 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 602 | 371 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 372 | | // Set Headers |
| | 602 | 373 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 374 | | { |
| | 602 | 375 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 376 | | } |
| | 602 | 377 | | if (Client.AcceptLanguage != null) |
| | | 378 | | { |
| | 602 | 379 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 380 | | { |
| | 0 | 381 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 382 | | } |
| | 602 | 383 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 384 | | } |
| | 602 | 385 | | if (clientRequestId != null) |
| | | 386 | | { |
| | 0 | 387 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | | 388 | | { |
| | 0 | 389 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | | 390 | | } |
| | 0 | 391 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | | 392 | | } |
| | | 393 | | |
| | | 394 | | |
| | 602 | 395 | | if (customHeaders != null) |
| | | 396 | | { |
| | 0 | 397 | | foreach(var _header in customHeaders) |
| | | 398 | | { |
| | 0 | 399 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 400 | | { |
| | 0 | 401 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 402 | | } |
| | 0 | 403 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 404 | | } |
| | | 405 | | } |
| | | 406 | | |
| | | 407 | | // Serialize Request |
| | 602 | 408 | | string _requestContent = null; |
| | | 409 | | // Set Credentials |
| | 602 | 410 | | if (Client.Credentials != null) |
| | | 411 | | { |
| | 602 | 412 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 602 | 413 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 414 | | } |
| | | 415 | | // Send Request |
| | 602 | 416 | | if (_shouldTrace) |
| | | 417 | | { |
| | 0 | 418 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 419 | | } |
| | 602 | 420 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 602 | 421 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 602 | 422 | | if (_shouldTrace) |
| | | 423 | | { |
| | 0 | 424 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 425 | | } |
| | 602 | 426 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 602 | 427 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 602 | 428 | | string _responseContent = null; |
| | 602 | 429 | | if ((int)_statusCode != 200) |
| | | 430 | | { |
| | 0 | 431 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 432 | | try |
| | | 433 | | { |
| | 0 | 434 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 435 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| | 0 | 436 | | if (_errorBody != null) |
| | | 437 | | { |
| | 0 | 438 | | ex = new CloudException(_errorBody.Message); |
| | 0 | 439 | | ex.Body = _errorBody; |
| | | 440 | | } |
| | 0 | 441 | | } |
| | 0 | 442 | | catch (JsonException) |
| | | 443 | | { |
| | | 444 | | // Ignore the exception |
| | 0 | 445 | | } |
| | 0 | 446 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 447 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 448 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 449 | | { |
| | 0 | 450 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 451 | | } |
| | 0 | 452 | | if (_shouldTrace) |
| | | 453 | | { |
| | 0 | 454 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 455 | | } |
| | 0 | 456 | | _httpRequest.Dispose(); |
| | 0 | 457 | | if (_httpResponse != null) |
| | | 458 | | { |
| | 0 | 459 | | _httpResponse.Dispose(); |
| | | 460 | | } |
| | 0 | 461 | | throw ex; |
| | | 462 | | } |
| | | 463 | | // Create Result |
| | 602 | 464 | | var _result = new AzureOperationResponse<IPage<QueryKey>>(); |
| | 602 | 465 | | _result.Request = _httpRequest; |
| | 602 | 466 | | _result.Response = _httpResponse; |
| | 602 | 467 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 468 | | { |
| | 602 | 469 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 470 | | } |
| | | 471 | | // Deserialize Response |
| | 602 | 472 | | if ((int)_statusCode == 200) |
| | | 473 | | { |
| | 602 | 474 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 475 | | try |
| | | 476 | | { |
| | 602 | 477 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<QueryKey>>(_responseConten |
| | 602 | 478 | | } |
| | 0 | 479 | | catch (JsonException ex) |
| | | 480 | | { |
| | 0 | 481 | | _httpRequest.Dispose(); |
| | 0 | 482 | | if (_httpResponse != null) |
| | | 483 | | { |
| | 0 | 484 | | _httpResponse.Dispose(); |
| | | 485 | | } |
| | 0 | 486 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 487 | | } |
| | | 488 | | } |
| | 602 | 489 | | if (_shouldTrace) |
| | | 490 | | { |
| | 0 | 491 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 492 | | } |
| | 602 | 493 | | return _result; |
| | 602 | 494 | | } |
| | | 495 | | |
| | | 496 | | /// <summary> |
| | | 497 | | /// Deletes the specified query key. Unlike admin keys, query keys are not |
| | | 498 | | /// regenerated. The process for regenerating a query key is to delete and then |
| | | 499 | | /// recreate it. |
| | | 500 | | /// <see href="https://aka.ms/search-manage" /> |
| | | 501 | | /// </summary> |
| | | 502 | | /// <param name='resourceGroupName'> |
| | | 503 | | /// The name of the resource group within the current subscription. You can |
| | | 504 | | /// obtain this value from the Azure Resource Manager API or the portal. |
| | | 505 | | /// </param> |
| | | 506 | | /// <param name='searchServiceName'> |
| | | 507 | | /// The name of the Azure Cognitive Search service associated with the |
| | | 508 | | /// specified resource group. |
| | | 509 | | /// </param> |
| | | 510 | | /// <param name='key'> |
| | | 511 | | /// The query key to be deleted. Query keys are identified by value, not by |
| | | 512 | | /// name. |
| | | 513 | | /// </param> |
| | | 514 | | /// <param name='searchManagementRequestOptions'> |
| | | 515 | | /// Additional parameters for the operation |
| | | 516 | | /// </param> |
| | | 517 | | /// <param name='customHeaders'> |
| | | 518 | | /// Headers that will be added to request. |
| | | 519 | | /// </param> |
| | | 520 | | /// <param name='cancellationToken'> |
| | | 521 | | /// The cancellation token. |
| | | 522 | | /// </param> |
| | | 523 | | /// <exception cref="CloudException"> |
| | | 524 | | /// Thrown when the operation returned an invalid status code |
| | | 525 | | /// </exception> |
| | | 526 | | /// <exception cref="ValidationException"> |
| | | 527 | | /// Thrown when a required parameter is null |
| | | 528 | | /// </exception> |
| | | 529 | | /// <exception cref="System.ArgumentNullException"> |
| | | 530 | | /// Thrown when a required parameter is null |
| | | 531 | | /// </exception> |
| | | 532 | | /// <return> |
| | | 533 | | /// A response object containing the response body and response headers. |
| | | 534 | | /// </return> |
| | | 535 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string resourceGroupName, string searchSer |
| | | 536 | | { |
| | 0 | 537 | | if (resourceGroupName == null) |
| | | 538 | | { |
| | 0 | 539 | | throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); |
| | | 540 | | } |
| | 0 | 541 | | if (searchServiceName == null) |
| | | 542 | | { |
| | 0 | 543 | | throw new ValidationException(ValidationRules.CannotBeNull, "searchServiceName"); |
| | | 544 | | } |
| | 0 | 545 | | if (key == null) |
| | | 546 | | { |
| | 0 | 547 | | throw new ValidationException(ValidationRules.CannotBeNull, "key"); |
| | | 548 | | } |
| | 0 | 549 | | if (Client.ApiVersion == null) |
| | | 550 | | { |
| | 0 | 551 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | | 552 | | } |
| | 0 | 553 | | if (Client.SubscriptionId == null) |
| | | 554 | | { |
| | 0 | 555 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); |
| | | 556 | | } |
| | 0 | 557 | | System.Guid? clientRequestId = default(System.Guid?); |
| | 0 | 558 | | if (searchManagementRequestOptions != null) |
| | | 559 | | { |
| | 0 | 560 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | | 561 | | } |
| | | 562 | | // Tracing |
| | 0 | 563 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 564 | | string _invocationId = null; |
| | 0 | 565 | | if (_shouldTrace) |
| | | 566 | | { |
| | 0 | 567 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 568 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 569 | | tracingParameters.Add("resourceGroupName", resourceGroupName); |
| | 0 | 570 | | tracingParameters.Add("searchServiceName", searchServiceName); |
| | 0 | 571 | | tracingParameters.Add("key", key); |
| | 0 | 572 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| | 0 | 573 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 574 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | | 575 | | } |
| | | 576 | | // Construct URL |
| | 0 | 577 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| | 0 | 578 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{su |
| | 0 | 579 | | _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); |
| | 0 | 580 | | _url = _url.Replace("{searchServiceName}", System.Uri.EscapeDataString(searchServiceName)); |
| | 0 | 581 | | _url = _url.Replace("{key}", System.Uri.EscapeDataString(key)); |
| | 0 | 582 | | _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); |
| | 0 | 583 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 584 | | if (Client.ApiVersion != null) |
| | | 585 | | { |
| | 0 | 586 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | | 587 | | } |
| | 0 | 588 | | if (_queryParameters.Count > 0) |
| | | 589 | | { |
| | 0 | 590 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 591 | | } |
| | | 592 | | // Create HTTP transport objects |
| | 0 | 593 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 594 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 595 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| | 0 | 596 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 597 | | // Set Headers |
| | 0 | 598 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 599 | | { |
| | 0 | 600 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 601 | | } |
| | 0 | 602 | | if (Client.AcceptLanguage != null) |
| | | 603 | | { |
| | 0 | 604 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 605 | | { |
| | 0 | 606 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 607 | | } |
| | 0 | 608 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 609 | | } |
| | 0 | 610 | | if (clientRequestId != null) |
| | | 611 | | { |
| | 0 | 612 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | | 613 | | { |
| | 0 | 614 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | | 615 | | } |
| | 0 | 616 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | | 617 | | } |
| | | 618 | | |
| | | 619 | | |
| | 0 | 620 | | if (customHeaders != null) |
| | | 621 | | { |
| | 0 | 622 | | foreach(var _header in customHeaders) |
| | | 623 | | { |
| | 0 | 624 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 625 | | { |
| | 0 | 626 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 627 | | } |
| | 0 | 628 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 629 | | } |
| | | 630 | | } |
| | | 631 | | |
| | | 632 | | // Serialize Request |
| | 0 | 633 | | string _requestContent = null; |
| | | 634 | | // Set Credentials |
| | 0 | 635 | | if (Client.Credentials != null) |
| | | 636 | | { |
| | 0 | 637 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 638 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 639 | | } |
| | | 640 | | // Send Request |
| | 0 | 641 | | if (_shouldTrace) |
| | | 642 | | { |
| | 0 | 643 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 644 | | } |
| | 0 | 645 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 646 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 647 | | if (_shouldTrace) |
| | | 648 | | { |
| | 0 | 649 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 650 | | } |
| | 0 | 651 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 652 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 653 | | string _responseContent = null; |
| | 0 | 654 | | if ((int)_statusCode != 200 && (int)_statusCode != 204 && (int)_statusCode != 404) |
| | | 655 | | { |
| | 0 | 656 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 657 | | try |
| | | 658 | | { |
| | 0 | 659 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 660 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| | 0 | 661 | | if (_errorBody != null) |
| | | 662 | | { |
| | 0 | 663 | | ex = new CloudException(_errorBody.Message); |
| | 0 | 664 | | ex.Body = _errorBody; |
| | | 665 | | } |
| | 0 | 666 | | } |
| | 0 | 667 | | catch (JsonException) |
| | | 668 | | { |
| | | 669 | | // Ignore the exception |
| | 0 | 670 | | } |
| | 0 | 671 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 672 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 673 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 674 | | { |
| | 0 | 675 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 676 | | } |
| | 0 | 677 | | if (_shouldTrace) |
| | | 678 | | { |
| | 0 | 679 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 680 | | } |
| | 0 | 681 | | _httpRequest.Dispose(); |
| | 0 | 682 | | if (_httpResponse != null) |
| | | 683 | | { |
| | 0 | 684 | | _httpResponse.Dispose(); |
| | | 685 | | } |
| | 0 | 686 | | throw ex; |
| | | 687 | | } |
| | | 688 | | // Create Result |
| | 0 | 689 | | var _result = new AzureOperationResponse(); |
| | 0 | 690 | | _result.Request = _httpRequest; |
| | 0 | 691 | | _result.Response = _httpResponse; |
| | 0 | 692 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 693 | | { |
| | 0 | 694 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 695 | | } |
| | 0 | 696 | | if (_shouldTrace) |
| | | 697 | | { |
| | 0 | 698 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 699 | | } |
| | 0 | 700 | | return _result; |
| | 0 | 701 | | } |
| | | 702 | | |
| | | 703 | | /// <summary> |
| | | 704 | | /// Returns the list of query API keys for the given Azure Cognitive Search |
| | | 705 | | /// service. |
| | | 706 | | /// <see href="https://aka.ms/search-manage" /> |
| | | 707 | | /// </summary> |
| | | 708 | | /// <param name='nextPageLink'> |
| | | 709 | | /// The NextLink from the previous successful call to List operation. |
| | | 710 | | /// </param> |
| | | 711 | | /// <param name='searchManagementRequestOptions'> |
| | | 712 | | /// Additional parameters for the operation |
| | | 713 | | /// </param> |
| | | 714 | | /// <param name='customHeaders'> |
| | | 715 | | /// Headers that will be added to request. |
| | | 716 | | /// </param> |
| | | 717 | | /// <param name='cancellationToken'> |
| | | 718 | | /// The cancellation token. |
| | | 719 | | /// </param> |
| | | 720 | | /// <exception cref="CloudException"> |
| | | 721 | | /// Thrown when the operation returned an invalid status code |
| | | 722 | | /// </exception> |
| | | 723 | | /// <exception cref="SerializationException"> |
| | | 724 | | /// Thrown when unable to deserialize the response |
| | | 725 | | /// </exception> |
| | | 726 | | /// <exception cref="ValidationException"> |
| | | 727 | | /// Thrown when a required parameter is null |
| | | 728 | | /// </exception> |
| | | 729 | | /// <exception cref="System.ArgumentNullException"> |
| | | 730 | | /// Thrown when a required parameter is null |
| | | 731 | | /// </exception> |
| | | 732 | | /// <return> |
| | | 733 | | /// A response object containing the response body and response headers. |
| | | 734 | | /// </return> |
| | | 735 | | public async Task<AzureOperationResponse<IPage<QueryKey>>> ListBySearchServiceNextWithHttpMessagesAsync(string n |
| | | 736 | | { |
| | 0 | 737 | | if (nextPageLink == null) |
| | | 738 | | { |
| | 0 | 739 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | | 740 | | } |
| | 0 | 741 | | System.Guid? clientRequestId = default(System.Guid?); |
| | 0 | 742 | | if (searchManagementRequestOptions != null) |
| | | 743 | | { |
| | 0 | 744 | | clientRequestId = searchManagementRequestOptions.ClientRequestId; |
| | | 745 | | } |
| | | 746 | | // Tracing |
| | 0 | 747 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 0 | 748 | | string _invocationId = null; |
| | 0 | 749 | | if (_shouldTrace) |
| | | 750 | | { |
| | 0 | 751 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 752 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 753 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| | 0 | 754 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| | 0 | 755 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 756 | | ServiceClientTracing.Enter(_invocationId, this, "ListBySearchServiceNext", tracingParameters); |
| | | 757 | | } |
| | | 758 | | // Construct URL |
| | 0 | 759 | | string _url = "{nextLink}"; |
| | 0 | 760 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| | 0 | 761 | | List<string> _queryParameters = new List<string>(); |
| | 0 | 762 | | if (_queryParameters.Count > 0) |
| | | 763 | | { |
| | 0 | 764 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | | 765 | | } |
| | | 766 | | // Create HTTP transport objects |
| | 0 | 767 | | var _httpRequest = new HttpRequestMessage(); |
| | 0 | 768 | | HttpResponseMessage _httpResponse = null; |
| | 0 | 769 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 0 | 770 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 771 | | // Set Headers |
| | 0 | 772 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | | 773 | | { |
| | 0 | 774 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | | 775 | | } |
| | 0 | 776 | | if (Client.AcceptLanguage != null) |
| | | 777 | | { |
| | 0 | 778 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | | 779 | | { |
| | 0 | 780 | | _httpRequest.Headers.Remove("accept-language"); |
| | | 781 | | } |
| | 0 | 782 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | | 783 | | } |
| | 0 | 784 | | if (clientRequestId != null) |
| | | 785 | | { |
| | 0 | 786 | | if (_httpRequest.Headers.Contains("x-ms-client-request-id")) |
| | | 787 | | { |
| | 0 | 788 | | _httpRequest.Headers.Remove("x-ms-client-request-id"); |
| | | 789 | | } |
| | 0 | 790 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Rest.Serialization.SafeJsonConver |
| | | 791 | | } |
| | | 792 | | |
| | | 793 | | |
| | 0 | 794 | | if (customHeaders != null) |
| | | 795 | | { |
| | 0 | 796 | | foreach(var _header in customHeaders) |
| | | 797 | | { |
| | 0 | 798 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 799 | | { |
| | 0 | 800 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 801 | | } |
| | 0 | 802 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 803 | | } |
| | | 804 | | } |
| | | 805 | | |
| | | 806 | | // Serialize Request |
| | 0 | 807 | | string _requestContent = null; |
| | | 808 | | // Set Credentials |
| | 0 | 809 | | if (Client.Credentials != null) |
| | | 810 | | { |
| | 0 | 811 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 812 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 813 | | } |
| | | 814 | | // Send Request |
| | 0 | 815 | | if (_shouldTrace) |
| | | 816 | | { |
| | 0 | 817 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 818 | | } |
| | 0 | 819 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 820 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 0 | 821 | | if (_shouldTrace) |
| | | 822 | | { |
| | 0 | 823 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 824 | | } |
| | 0 | 825 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 0 | 826 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 0 | 827 | | string _responseContent = null; |
| | 0 | 828 | | if ((int)_statusCode != 200) |
| | | 829 | | { |
| | 0 | 830 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | | 831 | | try |
| | | 832 | | { |
| | 0 | 833 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 834 | | CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC |
| | 0 | 835 | | if (_errorBody != null) |
| | | 836 | | { |
| | 0 | 837 | | ex = new CloudException(_errorBody.Message); |
| | 0 | 838 | | ex.Body = _errorBody; |
| | | 839 | | } |
| | 0 | 840 | | } |
| | 0 | 841 | | catch (JsonException) |
| | | 842 | | { |
| | | 843 | | // Ignore the exception |
| | 0 | 844 | | } |
| | 0 | 845 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 846 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 847 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 848 | | { |
| | 0 | 849 | | ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 850 | | } |
| | 0 | 851 | | if (_shouldTrace) |
| | | 852 | | { |
| | 0 | 853 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 854 | | } |
| | 0 | 855 | | _httpRequest.Dispose(); |
| | 0 | 856 | | if (_httpResponse != null) |
| | | 857 | | { |
| | 0 | 858 | | _httpResponse.Dispose(); |
| | | 859 | | } |
| | 0 | 860 | | throw ex; |
| | | 861 | | } |
| | | 862 | | // Create Result |
| | 0 | 863 | | var _result = new AzureOperationResponse<IPage<QueryKey>>(); |
| | 0 | 864 | | _result.Request = _httpRequest; |
| | 0 | 865 | | _result.Response = _httpResponse; |
| | 0 | 866 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | | 867 | | { |
| | 0 | 868 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | | 869 | | } |
| | | 870 | | // Deserialize Response |
| | 0 | 871 | | if ((int)_statusCode == 200) |
| | | 872 | | { |
| | 0 | 873 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 874 | | try |
| | | 875 | | { |
| | 0 | 876 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<QueryKey>>(_responseConten |
| | 0 | 877 | | } |
| | 0 | 878 | | catch (JsonException ex) |
| | | 879 | | { |
| | 0 | 880 | | _httpRequest.Dispose(); |
| | 0 | 881 | | if (_httpResponse != null) |
| | | 882 | | { |
| | 0 | 883 | | _httpResponse.Dispose(); |
| | | 884 | | } |
| | 0 | 885 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 886 | | } |
| | | 887 | | } |
| | 0 | 888 | | if (_shouldTrace) |
| | | 889 | | { |
| | 0 | 890 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 891 | | } |
| | 0 | 892 | | return _result; |
| | 0 | 893 | | } |
| | | 894 | | |
| | | 895 | | } |
| | | 896 | | } |