| | 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.Search |
| | 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.Linq; |
| | 21 | | using System.Net; |
| | 22 | | using System.Net.Http; |
| | 23 | | using System.Threading; |
| | 24 | | using System.Threading.Tasks; |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Client that can be used to manage and query indexes and documents, as |
| | 28 | | /// well as manage other resources, on a search service. |
| | 29 | | /// </summary> |
| | 30 | | public partial class SearchServiceClient : ServiceClient<SearchServiceClient>, ISearchServiceClient, IAzureClient |
| | 31 | | { |
| | 32 | | /// <summary> |
| | 33 | | /// The base URI of the service. |
| | 34 | | /// </summary> |
| 2320 | 35 | | internal string BaseUri {get; set;} |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Gets or sets json serialization settings. |
| | 39 | | /// </summary> |
| 9400 | 40 | | public JsonSerializerSettings SerializationSettings { get; private set; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Gets or sets json deserialization settings. |
| | 44 | | /// </summary> |
| 10344 | 45 | | public JsonSerializerSettings DeserializationSettings { get; private set; } |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Credentials needed for the client to connect to Azure. |
| | 49 | | /// </summary> |
| 5356 | 50 | | public ServiceClientCredentials Credentials { get; private set; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Client Api Version. |
| | 54 | | /// </summary> |
| 5368 | 55 | | public string ApiVersion { get; private set; } |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// The name of the search service. |
| | 59 | | /// </summary> |
| 3808 | 60 | | public string SearchServiceName { get; set; } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// The DNS suffix of the search service. The default is search.windows.net. |
| | 64 | | /// </summary> |
| 4572 | 65 | | public string SearchDnsSuffix { get; set; } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// The preferred language for the response. |
| | 69 | | /// </summary> |
| 3816 | 70 | | public string AcceptLanguage { get; set; } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// The retry timeout in seconds for Long Running Operations. Default value is |
| | 74 | | /// 30. |
| | 75 | | /// </summary> |
| 0 | 76 | | public int? LongRunningOperationRetryTimeout { get; set; } |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// Whether a unique x-ms-client-request-id should be generated. When set to |
| | 80 | | /// true a unique x-ms-client-request-id value is generated and included in |
| | 81 | | /// each request. Default is true. |
| | 82 | | /// </summary> |
| 3816 | 83 | | public bool? GenerateClientRequestId { get; set; } |
| | 84 | |
|
| | 85 | | /// <summary> |
| | 86 | | /// Gets the IDataSourcesOperations. |
| | 87 | | /// </summary> |
| 1080 | 88 | | public virtual IDataSourcesOperations DataSources { get; private set; } |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// Gets the IIndexersOperations. |
| | 92 | | /// </summary> |
| 900 | 93 | | public virtual IIndexersOperations Indexers { get; private set; } |
| | 94 | |
|
| | 95 | | /// <summary> |
| | 96 | | /// Gets the ISkillsetsOperations. |
| | 97 | | /// </summary> |
| 990 | 98 | | public virtual ISkillsetsOperations Skillsets { get; private set; } |
| | 99 | |
|
| | 100 | | /// <summary> |
| | 101 | | /// Gets the ISynonymMapsOperations. |
| | 102 | | /// </summary> |
| 894 | 103 | | public virtual ISynonymMapsOperations SynonymMaps { get; private set; } |
| | 104 | |
|
| | 105 | | /// <summary> |
| | 106 | | /// Gets the IIndexesOperations. |
| | 107 | | /// </summary> |
| 1712 | 108 | | public virtual IIndexesOperations Indexes { get; private set; } |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Initializes a new instance of the SearchServiceClient class. |
| | 112 | | /// </summary> |
| | 113 | | /// <param name='httpClient'> |
| | 114 | | /// HttpClient to be used |
| | 115 | | /// </param> |
| | 116 | | /// <param name='disposeHttpClient'> |
| | 117 | | /// True: will dispose the provided httpClient on calling SearchServiceClient.Dispose(). False: will not dispose |
| 0 | 118 | | protected SearchServiceClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClien |
| | 119 | | { |
| 0 | 120 | | Initialize(); |
| 0 | 121 | | } |
| | 122 | |
|
| | 123 | | /// <summary> |
| | 124 | | /// Initializes a new instance of the SearchServiceClient class. |
| | 125 | | /// </summary> |
| | 126 | | /// <param name='handlers'> |
| | 127 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 128 | | /// </param> |
| 812 | 129 | | protected SearchServiceClient(params DelegatingHandler[] handlers) : base(handlers) |
| | 130 | | { |
| 812 | 131 | | Initialize(); |
| 812 | 132 | | } |
| | 133 | |
|
| | 134 | | /// <summary> |
| | 135 | | /// Initializes a new instance of the SearchServiceClient class. |
| | 136 | | /// </summary> |
| | 137 | | /// <param name='rootHandler'> |
| | 138 | | /// Optional. The http client handler used to handle http transport. |
| | 139 | | /// </param> |
| | 140 | | /// <param name='handlers'> |
| | 141 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 142 | | /// </param> |
| 12 | 143 | | protected SearchServiceClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHan |
| | 144 | | { |
| 12 | 145 | | Initialize(); |
| 12 | 146 | | } |
| | 147 | |
|
| | 148 | | /// <summary> |
| | 149 | | /// Initializes a new instance of the SearchServiceClient class. |
| | 150 | | /// </summary> |
| | 151 | | /// <param name='credentials'> |
| | 152 | | /// Required. Credentials needed for the client to connect to Azure. |
| | 153 | | /// </param> |
| | 154 | | /// <param name='handlers'> |
| | 155 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 156 | | /// </param> |
| | 157 | | /// <exception cref="System.ArgumentNullException"> |
| | 158 | | /// Thrown when a required parameter is null |
| | 159 | | /// </exception> |
| 746 | 160 | | public SearchServiceClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(han |
| | 161 | | { |
| 746 | 162 | | if (credentials == null) |
| | 163 | | { |
| 2 | 164 | | throw new System.ArgumentNullException("credentials"); |
| | 165 | | } |
| 744 | 166 | | Credentials = credentials; |
| 744 | 167 | | if (Credentials != null) |
| | 168 | | { |
| 744 | 169 | | Credentials.InitializeServiceClient(this); |
| | 170 | | } |
| 744 | 171 | | } |
| | 172 | |
|
| | 173 | | /// <summary> |
| | 174 | | /// Initializes a new instance of the SearchServiceClient class. |
| | 175 | | /// </summary> |
| | 176 | | /// <param name='credentials'> |
| | 177 | | /// Required. Credentials needed for the client to connect to Azure. |
| | 178 | | /// </param> |
| | 179 | | /// <param name='httpClient'> |
| | 180 | | /// HttpClient to be used |
| | 181 | | /// </param> |
| | 182 | | /// <param name='disposeHttpClient'> |
| | 183 | | /// True: will dispose the provided httpClient on calling SearchServiceClient.Dispose(). False: will not dispose |
| | 184 | | /// <exception cref="System.ArgumentNullException"> |
| | 185 | | /// Thrown when a required parameter is null |
| | 186 | | /// </exception> |
| 0 | 187 | | public SearchServiceClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient) |
| | 188 | | { |
| 0 | 189 | | if (credentials == null) |
| | 190 | | { |
| 0 | 191 | | throw new System.ArgumentNullException("credentials"); |
| | 192 | | } |
| 0 | 193 | | Credentials = credentials; |
| 0 | 194 | | if (Credentials != null) |
| | 195 | | { |
| 0 | 196 | | Credentials.InitializeServiceClient(this); |
| | 197 | | } |
| 0 | 198 | | } |
| | 199 | |
|
| | 200 | | /// <summary> |
| | 201 | | /// Initializes a new instance of the SearchServiceClient class. |
| | 202 | | /// </summary> |
| | 203 | | /// <param name='credentials'> |
| | 204 | | /// Required. Credentials needed for the client to connect to Azure. |
| | 205 | | /// </param> |
| | 206 | | /// <param name='rootHandler'> |
| | 207 | | /// Optional. The http client handler used to handle http transport. |
| | 208 | | /// </param> |
| | 209 | | /// <param name='handlers'> |
| | 210 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 211 | | /// </param> |
| | 212 | | /// <exception cref="System.ArgumentNullException"> |
| | 213 | | /// Thrown when a required parameter is null |
| | 214 | | /// </exception> |
| 2 | 215 | | public SearchServiceClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params Delegatin |
| | 216 | | { |
| 2 | 217 | | if (credentials == null) |
| | 218 | | { |
| 2 | 219 | | throw new System.ArgumentNullException("credentials"); |
| | 220 | | } |
| 0 | 221 | | Credentials = credentials; |
| 0 | 222 | | if (Credentials != null) |
| | 223 | | { |
| 0 | 224 | | Credentials.InitializeServiceClient(this); |
| | 225 | | } |
| 0 | 226 | | } |
| | 227 | |
|
| | 228 | | /// <summary> |
| | 229 | | /// An optional partial-method to perform custom initialization. |
| | 230 | | /// </summary> |
| | 231 | | partial void CustomInitialize(); |
| | 232 | | /// <summary> |
| | 233 | | /// Initializes client properties. |
| | 234 | | /// </summary> |
| | 235 | | private void Initialize() |
| | 236 | | { |
| 824 | 237 | | DataSources = new DataSourcesOperations(this); |
| 824 | 238 | | Indexers = new IndexersOperations(this); |
| 824 | 239 | | Skillsets = new SkillsetsOperations(this); |
| 824 | 240 | | SynonymMaps = new SynonymMapsOperations(this); |
| 824 | 241 | | Indexes = new IndexesOperations(this); |
| 824 | 242 | | BaseUri = "https://{searchServiceName}.{searchDnsSuffix}"; |
| 824 | 243 | | ApiVersion = "2019-05-06"; |
| 824 | 244 | | SearchDnsSuffix = "search.windows.net"; |
| 824 | 245 | | AcceptLanguage = "en-US"; |
| 824 | 246 | | LongRunningOperationRetryTimeout = 30; |
| 824 | 247 | | GenerateClientRequestId = true; |
| 824 | 248 | | SerializationSettings = new JsonSerializerSettings |
| 824 | 249 | | { |
| 824 | 250 | | Formatting = Newtonsoft.Json.Formatting.Indented, |
| 824 | 251 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 824 | 252 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 824 | 253 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 824 | 254 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 824 | 255 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 824 | 256 | | Converters = new List<JsonConverter> |
| 824 | 257 | | { |
| 824 | 258 | | new Iso8601TimeSpanConverter() |
| 824 | 259 | | } |
| 824 | 260 | | }; |
| 824 | 261 | | DeserializationSettings = new JsonSerializerSettings |
| 824 | 262 | | { |
| 824 | 263 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 824 | 264 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 824 | 265 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 824 | 266 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 824 | 267 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 824 | 268 | | Converters = new List<JsonConverter> |
| 824 | 269 | | { |
| 824 | 270 | | new Iso8601TimeSpanConverter() |
| 824 | 271 | | } |
| 824 | 272 | | }; |
| 824 | 273 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<Analyzer>("@odata.type")); |
| 824 | 274 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<Analyzer>("@odata.type")); |
| 824 | 275 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<Tokenizer>("@odata.type")); |
| 824 | 276 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<Tokenizer>("@odata.type")); |
| 824 | 277 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<TokenFilter>("@odata.type")); |
| 824 | 278 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<TokenFilter>("@odata.type")); |
| 824 | 279 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<CharFilter>("@odata.type")); |
| 824 | 280 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<CharFilter>("@odata.type")); |
| 824 | 281 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<DataChangeDetectionPolicy>("@odat |
| 824 | 282 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<DataChangeDetectionPolicy>("@ |
| 824 | 283 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<DataDeletionDetectionPolicy>("@od |
| 824 | 284 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<DataDeletionDetectionPolicy>( |
| 824 | 285 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<ScoringFunction>("type")); |
| 824 | 286 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<ScoringFunction>("type")); |
| 824 | 287 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<Skill>("@odata.type")); |
| 824 | 288 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<Skill>("@odata.type")); |
| 824 | 289 | | SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<CognitiveServices>("@odata.type") |
| 824 | 290 | | DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter<CognitiveServices>("@odata.ty |
| | 291 | | CustomInitialize(); |
| 824 | 292 | | DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); |
| 824 | 293 | | } |
| | 294 | | /// <summary> |
| | 295 | | /// Gets service level statistics for a search service. |
| | 296 | | /// </summary> |
| | 297 | | /// <param name='searchRequestOptions'> |
| | 298 | | /// Additional parameters for the operation |
| | 299 | | /// </param> |
| | 300 | | /// <param name='customHeaders'> |
| | 301 | | /// Headers that will be added to request. |
| | 302 | | /// </param> |
| | 303 | | /// <param name='cancellationToken'> |
| | 304 | | /// The cancellation token. |
| | 305 | | /// </param> |
| | 306 | | /// <exception cref="CloudException"> |
| | 307 | | /// Thrown when the operation returned an invalid status code |
| | 308 | | /// </exception> |
| | 309 | | /// <exception cref="SerializationException"> |
| | 310 | | /// Thrown when unable to deserialize the response |
| | 311 | | /// </exception> |
| | 312 | | /// <exception cref="ValidationException"> |
| | 313 | | /// Thrown when a required parameter is null |
| | 314 | | /// </exception> |
| | 315 | | /// <exception cref="System.ArgumentNullException"> |
| | 316 | | /// Thrown when a required parameter is null |
| | 317 | | /// </exception> |
| | 318 | | /// <return> |
| | 319 | | /// A response object containing the response body and response headers. |
| | 320 | | /// </return> |
| | 321 | | public async Task<AzureOperationResponse<ServiceStatistics>> GetServiceStatisticsWithHttpMessagesAsync(SearchReq |
| | 322 | | { |
| 2 | 323 | | if (SearchServiceName == null) |
| | 324 | | { |
| 0 | 325 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.SearchServiceName"); |
| | 326 | | } |
| 2 | 327 | | if (SearchDnsSuffix == null) |
| | 328 | | { |
| 0 | 329 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.SearchDnsSuffix"); |
| | 330 | | } |
| 2 | 331 | | if (ApiVersion == null) |
| | 332 | | { |
| 0 | 333 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.ApiVersion"); |
| | 334 | | } |
| 2 | 335 | | System.Guid? clientRequestId = default(System.Guid?); |
| 2 | 336 | | if (searchRequestOptions != null) |
| | 337 | | { |
| 0 | 338 | | clientRequestId = searchRequestOptions.ClientRequestId; |
| | 339 | | } |
| | 340 | | // Tracing |
| 2 | 341 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 342 | | string _invocationId = null; |
| 2 | 343 | | if (_shouldTrace) |
| | 344 | | { |
| 0 | 345 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 346 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 347 | | tracingParameters.Add("clientRequestId", clientRequestId); |
| 0 | 348 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 349 | | ServiceClientTracing.Enter(_invocationId, this, "GetServiceStatistics", tracingParameters); |
| | 350 | | } |
| | 351 | | // Construct URL |
| 2 | 352 | | var _baseUrl = BaseUri; |
| 2 | 353 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "servicestats"; |
| 2 | 354 | | _url = _url.Replace("{searchServiceName}", SearchServiceName); |
| 2 | 355 | | _url = _url.Replace("{searchDnsSuffix}", SearchDnsSuffix); |
| 2 | 356 | | List<string> _queryParameters = new List<string>(); |
| 2 | 357 | | if (ApiVersion != null) |
| | 358 | | { |
| 2 | 359 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(ApiVersion))); |
| | 360 | | } |
| 2 | 361 | | if (_queryParameters.Count > 0) |
| | 362 | | { |
| 2 | 363 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 364 | | } |
| | 365 | | // Create HTTP transport objects |
| 2 | 366 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 367 | | HttpResponseMessage _httpResponse = null; |
| 2 | 368 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 369 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 370 | | // Set Headers |
| 2 | 371 | | if (GenerateClientRequestId != null && GenerateClientRequestId.Value) |
| | 372 | | { |
| 2 | 373 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString()); |
| | 374 | | } |
| 2 | 375 | | if (AcceptLanguage != null) |
| | 376 | | { |
| 2 | 377 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 378 | | { |
| 0 | 379 | | _httpRequest.Headers.Remove("accept-language"); |
| | 380 | | } |
| 2 | 381 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", AcceptLanguage); |
| | 382 | | } |
| 2 | 383 | | if (clientRequestId != null) |
| | 384 | | { |
| 0 | 385 | | if (_httpRequest.Headers.Contains("client-request-id")) |
| | 386 | | { |
| 0 | 387 | | _httpRequest.Headers.Remove("client-request-id"); |
| | 388 | | } |
| 0 | 389 | | _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client |
| | 390 | | } |
| | 391 | |
|
| | 392 | |
|
| 2 | 393 | | if (customHeaders != null) |
| | 394 | | { |
| 0 | 395 | | foreach(var _header in customHeaders) |
| | 396 | | { |
| 0 | 397 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 398 | | { |
| 0 | 399 | | _httpRequest.Headers.Remove(_header.Key); |
| | 400 | | } |
| 0 | 401 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 402 | | } |
| | 403 | | } |
| | 404 | |
|
| | 405 | | // Serialize Request |
| 2 | 406 | | string _requestContent = null; |
| | 407 | | // Set Credentials |
| 2 | 408 | | if (Credentials != null) |
| | 409 | | { |
| 2 | 410 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 411 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 412 | | } |
| | 413 | | // Send Request |
| 2 | 414 | | if (_shouldTrace) |
| | 415 | | { |
| 0 | 416 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 417 | | } |
| 2 | 418 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 419 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 420 | | if (_shouldTrace) |
| | 421 | | { |
| 0 | 422 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 423 | | } |
| 2 | 424 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 425 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 426 | | string _responseContent = null; |
| 2 | 427 | | if ((int)_statusCode != 200) |
| | 428 | | { |
| 0 | 429 | | var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode |
| | 430 | | try |
| | 431 | | { |
| 0 | 432 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 433 | | CloudError _errorBody = SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Deserializa |
| 0 | 434 | | if (_errorBody != null) |
| | 435 | | { |
| 0 | 436 | | ex = new CloudException(_errorBody.Message); |
| 0 | 437 | | ex.Body = _errorBody; |
| | 438 | | } |
| 0 | 439 | | } |
| 0 | 440 | | catch (JsonException) |
| | 441 | | { |
| | 442 | | // Ignore the exception |
| 0 | 443 | | } |
| 0 | 444 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 445 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 446 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 447 | | { |
| 0 | 448 | | ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 449 | | } |
| 0 | 450 | | if (_shouldTrace) |
| | 451 | | { |
| 0 | 452 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 453 | | } |
| 0 | 454 | | _httpRequest.Dispose(); |
| 0 | 455 | | if (_httpResponse != null) |
| | 456 | | { |
| 0 | 457 | | _httpResponse.Dispose(); |
| | 458 | | } |
| 0 | 459 | | throw ex; |
| | 460 | | } |
| | 461 | | // Create Result |
| 2 | 462 | | var _result = new AzureOperationResponse<ServiceStatistics>(); |
| 2 | 463 | | _result.Request = _httpRequest; |
| 2 | 464 | | _result.Response = _httpResponse; |
| 2 | 465 | | if (_httpResponse.Headers.Contains("request-id")) |
| | 466 | | { |
| 2 | 467 | | _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault(); |
| | 468 | | } |
| | 469 | | // Deserialize Response |
| 2 | 470 | | if ((int)_statusCode == 200) |
| | 471 | | { |
| 2 | 472 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 473 | | try |
| | 474 | | { |
| 2 | 475 | | _result.Body = SafeJsonConvert.DeserializeObject<ServiceStatistics>(_responseContent, Deserializatio |
| 2 | 476 | | } |
| 0 | 477 | | catch (JsonException ex) |
| | 478 | | { |
| 0 | 479 | | _httpRequest.Dispose(); |
| 0 | 480 | | if (_httpResponse != null) |
| | 481 | | { |
| 0 | 482 | | _httpResponse.Dispose(); |
| | 483 | | } |
| 0 | 484 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 485 | | } |
| | 486 | | } |
| 2 | 487 | | if (_shouldTrace) |
| | 488 | | { |
| 0 | 489 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 490 | | } |
| 2 | 491 | | return _result; |
| 2 | 492 | | } |
| | 493 | |
|
| | 494 | | } |
| | 495 | | } |