< Summary

Class:Microsoft.Azure.Search.IndexesOperations
Assembly:Microsoft.Azure.Search.Service
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Service\src\Customizations\Indexes\IndexesOperations.Customization.cs
C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Service\src\Generated\IndexesOperations.cs
Covered lines:501
Uncovered lines:271
Coverable lines:772
Total lines:1753
Line coverage:64.8% (501 of 772)
Covered branches:297
Total branches:488
Branch coverage:60.8% (297 of 488)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
CreateOrUpdateWithHttpMessagesAsync(...)-100%50%
ExistsWithHttpMessagesAsync(...)-100%100%
.ctor(...)-80%50%
get_Client()-100%100%
CreateWithHttpMessagesAsync()-71.43%65.15%
ListWithHttpMessagesAsync()-58.59%58.06%
CreateOrUpdateWithHttpMessagesAsync()-69.23%68.48%
DeleteWithHttpMessagesAsync()-71.03%65.28%
GetWithHttpMessagesAsync()-70%62.9%
GetStatisticsWithHttpMessagesAsync()-54%50%
AnalyzeWithHttpMessagesAsync()-55.96%52.94%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Service\src\Customizations\Indexes\IndexesOperations.Customization.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for
 3// license information.
 4
 5namespace Microsoft.Azure.Search
 6{
 7    using System.Collections.Generic;
 8    using System.Threading;
 9    using System.Threading.Tasks;
 10    using Microsoft.Azure.Search.Models;
 11    using Microsoft.Rest.Azure;
 12
 13    internal partial class IndexesOperations
 14    {
 15        /// <summary>
 16        /// Creates a new search index or updates an index if it already exists.
 17        /// <see href="https://docs.microsoft.com/rest/api/searchservice/update-index">Update Index</see>
 18        /// </summary>
 19        /// <param name='index'>
 20        /// The definition of the index to create or update.
 21        /// </param>
 22        /// <param name='allowIndexDowntime'>
 23        /// Allows new analyzers, tokenizers, token filters, or char filters to be
 24        /// added to an index by taking the index offline for at least a few seconds.
 25        /// This temporarily causes indexing and query requests to fail. Performance
 26        /// and write availability of the index can be impaired for several minutes
 27        /// after the index is updated, or longer for very large indexes.
 28        /// </param>
 29        /// <param name='searchRequestOptions'>
 30        /// Additional parameters for the operation.
 31        /// </param>
 32        /// <param name='accessCondition'>
 33        /// Additional parameters for the operation.
 34        /// </param>
 35        /// <param name='customHeaders'>
 36        /// Headers that will be added to request.
 37        /// </param>
 38        /// <param name='cancellationToken'>
 39        /// The cancellation token.
 40        /// </param>
 41        /// <exception cref="CloudException">
 42        /// Thrown when the operation returned an invalid status code.
 43        /// </exception>
 44        /// <exception cref="Microsoft.Rest.SerializationException">
 45        /// Thrown when unable to deserialize the response.
 46        /// </exception>
 47        /// <exception cref="Microsoft.Rest.ValidationException">
 48        /// Thrown when a required parameter is null.
 49        /// </exception>
 50        /// <exception cref="System.ArgumentNullException">
 51        /// Thrown when a required parameter is null
 52        /// </exception>
 53        /// <returns>
 54        /// A response object containing the response body and response headers.
 55        /// </returns>
 56        public Task<AzureOperationResponse<Index>> CreateOrUpdateWithHttpMessagesAsync(Index index, bool? allowIndexDown
 57        {
 4458            return CreateOrUpdateWithHttpMessagesAsync(index != null ? index.Name : null, index, allowIndexDowntime, sea
 59        }
 60
 61        /// <summary>
 62        /// Determines whether or not the given index exists in the search service.
 63        /// </summary>
 64        /// <param name="indexName">
 65        /// The name of the index.
 66        /// </param>
 67        /// <param name='searchRequestOptions'>
 68        /// Additional parameters for the operation.
 69        /// </param>
 70        /// <param name='customHeaders'>
 71        /// The headers that will be added to request.
 72        /// </param>
 73        /// <param name='cancellationToken'>
 74        /// The cancellation token.
 75        /// </param>
 76        /// <exception cref="CloudException">
 77        /// Thrown when the operation returned an invalid status code.
 78        /// </exception>
 79        /// <exception cref="Microsoft.Rest.SerializationException">
 80        /// Thrown when unable to deserialize the response.
 81        /// </exception>
 82        /// <exception cref="Microsoft.Rest.ValidationException">
 83        /// Thrown when a required parameter is null.
 84        /// </exception>
 85        /// <exception cref="System.ArgumentNullException">
 86        /// Thrown when a required parameter is null
 87        /// </exception>
 88        /// <returns>
 89        /// A response with the value <c>true</c> if the index exists; <c>false</c> otherwise.
 90        /// </returns>
 91        public Task<AzureOperationResponse<bool>> ExistsWithHttpMessagesAsync(
 92            string indexName,
 93            SearchRequestOptions searchRequestOptions = default(SearchRequestOptions),
 94            Dictionary<string, List<string>> customHeaders = null,
 95            CancellationToken cancellationToken = default(CancellationToken))
 96        {
 697            return ExistsHelper.ExistsFromGetResponse(() =>
 1298                this.GetWithHttpMessagesAsync(indexName, searchRequestOptions, customHeaders, cancellationToken));
 99        }
 100    }
 101}

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Service\src\Generated\IndexesOperations.cs

#LineLine coverage
 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
 11namespace Microsoft.Azure.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    /// IndexesOperations operations.
 27    /// </summary>
 28    internal partial class IndexesOperations : IServiceOperations<SearchServiceClient>, IIndexesOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the IndexesOperations 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>
 82439        internal IndexesOperations(SearchServiceClient client)
 40        {
 82441            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 82445            Client = client;
 82446        }
 47
 48        /// <summary>
 49        /// Gets a reference to the SearchServiceClient
 50        /// </summary>
 1575451        public SearchServiceClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Creates a new search index.
 55        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/create-index">Create 
 56        /// </summary>
 57        /// <param name='index'>
 58        /// The definition of the index to create.
 59        /// </param>
 60        /// <param name='searchRequestOptions'>
 61        /// Additional parameters for the operation
 62        /// </param>
 63        /// <param name='customHeaders'>
 64        /// Headers that will be added to request.
 65        /// </param>
 66        /// <param name='cancellationToken'>
 67        /// The cancellation token.
 68        /// </param>
 69        /// <exception cref="CloudException">
 70        /// Thrown when the operation returned an invalid status code
 71        /// </exception>
 72        /// <exception cref="SerializationException">
 73        /// Thrown when unable to deserialize the response
 74        /// </exception>
 75        /// <exception cref="ValidationException">
 76        /// Thrown when a required parameter is null
 77        /// </exception>
 78        /// <exception cref="System.ArgumentNullException">
 79        /// Thrown when a required parameter is null
 80        /// </exception>
 81        /// <return>
 82        /// A response object containing the response body and response headers.
 83        /// </return>
 84        public async Task<AzureOperationResponse<Index>> CreateWithHttpMessagesAsync(Index index, SearchRequestOptions s
 85        {
 55086            if (Client.SearchServiceName == null)
 87            {
 088                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 89            }
 55090            if (Client.SearchDnsSuffix == null)
 91            {
 092                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 93            }
 55094            if (index == null)
 95            {
 096                throw new ValidationException(ValidationRules.CannotBeNull, "index");
 97            }
 55098            if (index != null)
 99            {
 550100                index.Validate();
 101            }
 550102            if (Client.ApiVersion == null)
 103            {
 0104                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 105            }
 550106            System.Guid? clientRequestId = default(System.Guid?);
 550107            if (searchRequestOptions != null)
 108            {
 0109                clientRequestId = searchRequestOptions.ClientRequestId;
 110            }
 111            // Tracing
 550112            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 550113            string _invocationId = null;
 550114            if (_shouldTrace)
 115            {
 0116                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0117                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0118                tracingParameters.Add("index", index);
 0119                tracingParameters.Add("clientRequestId", clientRequestId);
 0120                tracingParameters.Add("cancellationToken", cancellationToken);
 0121                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 122            }
 123            // Construct URL
 550124            var _baseUrl = Client.BaseUri;
 550125            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes";
 550126            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 550127            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 550128            List<string> _queryParameters = new List<string>();
 550129            if (Client.ApiVersion != null)
 130            {
 550131                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 132            }
 550133            if (_queryParameters.Count > 0)
 134            {
 550135                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 136            }
 137            // Create HTTP transport objects
 550138            var _httpRequest = new HttpRequestMessage();
 550139            HttpResponseMessage _httpResponse = null;
 550140            _httpRequest.Method = new HttpMethod("POST");
 550141            _httpRequest.RequestUri = new System.Uri(_url);
 142            // Set Headers
 550143            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 144            {
 550145                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 146            }
 550147            if (Client.AcceptLanguage != null)
 148            {
 550149                if (_httpRequest.Headers.Contains("accept-language"))
 150                {
 0151                    _httpRequest.Headers.Remove("accept-language");
 152                }
 550153                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 154            }
 550155            if (clientRequestId != null)
 156            {
 0157                if (_httpRequest.Headers.Contains("client-request-id"))
 158                {
 0159                    _httpRequest.Headers.Remove("client-request-id");
 160                }
 0161                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 162            }
 163
 164
 550165            if (customHeaders != null)
 166            {
 0167                foreach(var _header in customHeaders)
 168                {
 0169                    if (_httpRequest.Headers.Contains(_header.Key))
 170                    {
 0171                        _httpRequest.Headers.Remove(_header.Key);
 172                    }
 0173                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 174                }
 175            }
 176
 177            // Serialize Request
 550178            string _requestContent = null;
 550179            if(index != null)
 180            {
 550181                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(index, Client.SerializationSettings
 550182                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 550183                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 184            }
 185            // Set Credentials
 550186            if (Client.Credentials != null)
 187            {
 550188                cancellationToken.ThrowIfCancellationRequested();
 550189                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 190            }
 191            // Send Request
 550192            if (_shouldTrace)
 193            {
 0194                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 195            }
 550196            cancellationToken.ThrowIfCancellationRequested();
 550197            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 550198            if (_shouldTrace)
 199            {
 0200                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 201            }
 550202            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 550203            cancellationToken.ThrowIfCancellationRequested();
 550204            string _responseContent = null;
 550205            if ((int)_statusCode != 201)
 206            {
 2207                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 208                try
 209                {
 2210                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2211                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 2212                    if (_errorBody != null)
 213                    {
 2214                        ex = new CloudException(_errorBody.Message);
 2215                        ex.Body = _errorBody;
 216                    }
 2217                }
 0218                catch (JsonException)
 219                {
 220                    // Ignore the exception
 0221                }
 2222                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 2223                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 2224                if (_httpResponse.Headers.Contains("request-id"))
 225                {
 2226                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 227                }
 2228                if (_shouldTrace)
 229                {
 0230                    ServiceClientTracing.Error(_invocationId, ex);
 231                }
 2232                _httpRequest.Dispose();
 2233                if (_httpResponse != null)
 234                {
 2235                    _httpResponse.Dispose();
 236                }
 2237                throw ex;
 238            }
 239            // Create Result
 548240            var _result = new AzureOperationResponse<Index>();
 548241            _result.Request = _httpRequest;
 548242            _result.Response = _httpResponse;
 548243            if (_httpResponse.Headers.Contains("request-id"))
 244            {
 548245                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 246            }
 247            // Deserialize Response
 548248            if ((int)_statusCode == 201)
 249            {
 548250                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 251                try
 252                {
 548253                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client.
 548254                }
 0255                catch (JsonException ex)
 256                {
 0257                    _httpRequest.Dispose();
 0258                    if (_httpResponse != null)
 259                    {
 0260                        _httpResponse.Dispose();
 261                    }
 0262                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 263                }
 264            }
 548265            if (_shouldTrace)
 266            {
 0267                ServiceClientTracing.Exit(_invocationId, _result);
 268            }
 548269            return _result;
 548270        }
 271
 272        /// <summary>
 273        /// Lists all indexes available for a search service.
 274        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/list-indexes">List In
 275        /// </summary>
 276        /// <param name='select'>
 277        /// Selects which properties of the index definitions to retrieve. Specified as
 278        /// a comma-separated list of JSON property names, or '*' for all properties.
 279        /// The default is all properties.
 280        /// </param>
 281        /// <param name='searchRequestOptions'>
 282        /// Additional parameters for the operation
 283        /// </param>
 284        /// <param name='customHeaders'>
 285        /// Headers that will be added to request.
 286        /// </param>
 287        /// <param name='cancellationToken'>
 288        /// The cancellation token.
 289        /// </param>
 290        /// <exception cref="CloudException">
 291        /// Thrown when the operation returned an invalid status code
 292        /// </exception>
 293        /// <exception cref="SerializationException">
 294        /// Thrown when unable to deserialize the response
 295        /// </exception>
 296        /// <exception cref="ValidationException">
 297        /// Thrown when a required parameter is null
 298        /// </exception>
 299        /// <exception cref="System.ArgumentNullException">
 300        /// Thrown when a required parameter is null
 301        /// </exception>
 302        /// <return>
 303        /// A response object containing the response body and response headers.
 304        /// </return>
 305        public async Task<AzureOperationResponse<IndexListResult>> ListWithHttpMessagesAsync(string select = default(str
 306        {
 6307            if (Client.SearchServiceName == null)
 308            {
 0309                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 310            }
 6311            if (Client.SearchDnsSuffix == null)
 312            {
 0313                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 314            }
 6315            if (Client.ApiVersion == null)
 316            {
 0317                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 318            }
 6319            System.Guid? clientRequestId = default(System.Guid?);
 6320            if (searchRequestOptions != null)
 321            {
 2322                clientRequestId = searchRequestOptions.ClientRequestId;
 323            }
 324            // Tracing
 6325            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 6326            string _invocationId = null;
 6327            if (_shouldTrace)
 328            {
 0329                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0330                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0331                tracingParameters.Add("select", select);
 0332                tracingParameters.Add("clientRequestId", clientRequestId);
 0333                tracingParameters.Add("cancellationToken", cancellationToken);
 0334                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 335            }
 336            // Construct URL
 6337            var _baseUrl = Client.BaseUri;
 6338            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes";
 6339            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 6340            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 6341            List<string> _queryParameters = new List<string>();
 6342            if (select != null)
 343            {
 2344                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select)));
 345            }
 6346            if (Client.ApiVersion != null)
 347            {
 6348                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 349            }
 6350            if (_queryParameters.Count > 0)
 351            {
 6352                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 353            }
 354            // Create HTTP transport objects
 6355            var _httpRequest = new HttpRequestMessage();
 6356            HttpResponseMessage _httpResponse = null;
 6357            _httpRequest.Method = new HttpMethod("GET");
 6358            _httpRequest.RequestUri = new System.Uri(_url);
 359            // Set Headers
 6360            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 361            {
 6362                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 363            }
 6364            if (Client.AcceptLanguage != null)
 365            {
 6366                if (_httpRequest.Headers.Contains("accept-language"))
 367                {
 0368                    _httpRequest.Headers.Remove("accept-language");
 369                }
 6370                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 371            }
 6372            if (clientRequestId != null)
 373            {
 2374                if (_httpRequest.Headers.Contains("client-request-id"))
 375                {
 2376                    _httpRequest.Headers.Remove("client-request-id");
 377                }
 2378                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 379            }
 380
 381
 6382            if (customHeaders != null)
 383            {
 0384                foreach(var _header in customHeaders)
 385                {
 0386                    if (_httpRequest.Headers.Contains(_header.Key))
 387                    {
 0388                        _httpRequest.Headers.Remove(_header.Key);
 389                    }
 0390                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 391                }
 392            }
 393
 394            // Serialize Request
 6395            string _requestContent = null;
 396            // Set Credentials
 6397            if (Client.Credentials != null)
 398            {
 6399                cancellationToken.ThrowIfCancellationRequested();
 6400                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 401            }
 402            // Send Request
 6403            if (_shouldTrace)
 404            {
 0405                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 406            }
 6407            cancellationToken.ThrowIfCancellationRequested();
 6408            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 6409            if (_shouldTrace)
 410            {
 0411                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 412            }
 6413            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 6414            cancellationToken.ThrowIfCancellationRequested();
 6415            string _responseContent = null;
 6416            if ((int)_statusCode != 200)
 417            {
 0418                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 419                try
 420                {
 0421                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0422                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0423                    if (_errorBody != null)
 424                    {
 0425                        ex = new CloudException(_errorBody.Message);
 0426                        ex.Body = _errorBody;
 427                    }
 0428                }
 0429                catch (JsonException)
 430                {
 431                    // Ignore the exception
 0432                }
 0433                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0434                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0435                if (_httpResponse.Headers.Contains("request-id"))
 436                {
 0437                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 438                }
 0439                if (_shouldTrace)
 440                {
 0441                    ServiceClientTracing.Error(_invocationId, ex);
 442                }
 0443                _httpRequest.Dispose();
 0444                if (_httpResponse != null)
 445                {
 0446                    _httpResponse.Dispose();
 447                }
 0448                throw ex;
 449            }
 450            // Create Result
 6451            var _result = new AzureOperationResponse<IndexListResult>();
 6452            _result.Request = _httpRequest;
 6453            _result.Response = _httpResponse;
 6454            if (_httpResponse.Headers.Contains("request-id"))
 455            {
 6456                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 457            }
 458            // Deserialize Response
 6459            if ((int)_statusCode == 200)
 460            {
 6461                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 462                try
 463                {
 6464                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IndexListResult>(_responseConten
 6465                }
 0466                catch (JsonException ex)
 467                {
 0468                    _httpRequest.Dispose();
 0469                    if (_httpResponse != null)
 470                    {
 0471                        _httpResponse.Dispose();
 472                    }
 0473                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 474                }
 475            }
 6476            if (_shouldTrace)
 477            {
 0478                ServiceClientTracing.Exit(_invocationId, _result);
 479            }
 6480            return _result;
 6481        }
 482
 483        /// <summary>
 484        /// Creates a new search index or updates an index if it already exists.
 485        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/update-index">Update 
 486        /// </summary>
 487        /// <param name='indexName'>
 488        /// The definition of the index to create or update.
 489        /// </param>
 490        /// <param name='index'>
 491        /// The definition of the index to create or update.
 492        /// </param>
 493        /// <param name='allowIndexDowntime'>
 494        /// Allows new analyzers, tokenizers, token filters, or char filters to be
 495        /// added to an index by taking the index offline for at least a few seconds.
 496        /// This temporarily causes indexing and query requests to fail. Performance
 497        /// and write availability of the index can be impaired for several minutes
 498        /// after the index is updated, or longer for very large indexes.
 499        /// </param>
 500        /// <param name='searchRequestOptions'>
 501        /// Additional parameters for the operation
 502        /// </param>
 503        /// <param name='accessCondition'>
 504        /// Additional parameters for the operation
 505        /// </param>
 506        /// <param name='customHeaders'>
 507        /// Headers that will be added to request.
 508        /// </param>
 509        /// <param name='cancellationToken'>
 510        /// The cancellation token.
 511        /// </param>
 512        /// <exception cref="CloudException">
 513        /// Thrown when the operation returned an invalid status code
 514        /// </exception>
 515        /// <exception cref="SerializationException">
 516        /// Thrown when unable to deserialize the response
 517        /// </exception>
 518        /// <exception cref="ValidationException">
 519        /// Thrown when a required parameter is null
 520        /// </exception>
 521        /// <exception cref="System.ArgumentNullException">
 522        /// Thrown when a required parameter is null
 523        /// </exception>
 524        /// <return>
 525        /// A response object containing the response body and response headers.
 526        /// </return>
 527        public async Task<AzureOperationResponse<Index>> CreateOrUpdateWithHttpMessagesAsync(string indexName, Index ind
 528        {
 44529            if (Client.SearchServiceName == null)
 530            {
 0531                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 532            }
 44533            if (Client.SearchDnsSuffix == null)
 534            {
 0535                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 536            }
 44537            if (indexName == null)
 538            {
 0539                throw new ValidationException(ValidationRules.CannotBeNull, "indexName");
 540            }
 44541            if (index == null)
 542            {
 0543                throw new ValidationException(ValidationRules.CannotBeNull, "index");
 544            }
 44545            if (index != null)
 546            {
 44547                index.Validate();
 548            }
 44549            if (Client.ApiVersion == null)
 550            {
 0551                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 552            }
 44553            string prefer = "return=representation";
 44554            System.Guid? clientRequestId = default(System.Guid?);
 44555            if (searchRequestOptions != null)
 556            {
 0557                clientRequestId = searchRequestOptions.ClientRequestId;
 558            }
 44559            string ifMatch = default(string);
 44560            if (accessCondition != null)
 561            {
 22562                ifMatch = accessCondition.IfMatch;
 563            }
 44564            string ifNoneMatch = default(string);
 44565            if (accessCondition != null)
 566            {
 22567                ifNoneMatch = accessCondition.IfNoneMatch;
 568            }
 569            // Tracing
 44570            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 44571            string _invocationId = null;
 44572            if (_shouldTrace)
 573            {
 0574                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0575                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0576                tracingParameters.Add("indexName", indexName);
 0577                tracingParameters.Add("index", index);
 0578                tracingParameters.Add("allowIndexDowntime", allowIndexDowntime);
 0579                tracingParameters.Add("prefer", prefer);
 0580                tracingParameters.Add("clientRequestId", clientRequestId);
 0581                tracingParameters.Add("ifMatch", ifMatch);
 0582                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 0583                tracingParameters.Add("cancellationToken", cancellationToken);
 0584                ServiceClientTracing.Enter(_invocationId, this, "CreateOrUpdate", tracingParameters);
 585            }
 586            // Construct URL
 44587            var _baseUrl = Client.BaseUri;
 44588            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')";
 44589            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 44590            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 44591            _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName));
 44592            List<string> _queryParameters = new List<string>();
 44593            if (allowIndexDowntime != null)
 594            {
 2595                _queryParameters.Add(string.Format("allowIndexDowntime={0}", System.Uri.EscapeDataString(Rest.Serializat
 596            }
 44597            if (Client.ApiVersion != null)
 598            {
 44599                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 600            }
 44601            if (_queryParameters.Count > 0)
 602            {
 44603                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 604            }
 605            // Create HTTP transport objects
 44606            var _httpRequest = new HttpRequestMessage();
 44607            HttpResponseMessage _httpResponse = null;
 44608            _httpRequest.Method = new HttpMethod("PUT");
 44609            _httpRequest.RequestUri = new System.Uri(_url);
 610            // Set Headers
 44611            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 612            {
 44613                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 614            }
 44615            if (prefer != null)
 616            {
 44617                if (_httpRequest.Headers.Contains("Prefer"))
 618                {
 0619                    _httpRequest.Headers.Remove("Prefer");
 620                }
 44621                _httpRequest.Headers.TryAddWithoutValidation("Prefer", prefer);
 622            }
 44623            if (Client.AcceptLanguage != null)
 624            {
 44625                if (_httpRequest.Headers.Contains("accept-language"))
 626                {
 0627                    _httpRequest.Headers.Remove("accept-language");
 628                }
 44629                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 630            }
 44631            if (clientRequestId != null)
 632            {
 0633                if (_httpRequest.Headers.Contains("client-request-id"))
 634                {
 0635                    _httpRequest.Headers.Remove("client-request-id");
 636                }
 0637                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 638            }
 44639            if (ifMatch != null)
 640            {
 8641                if (_httpRequest.Headers.Contains("If-Match"))
 642                {
 0643                    _httpRequest.Headers.Remove("If-Match");
 644                }
 8645                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 646            }
 44647            if (ifNoneMatch != null)
 648            {
 4649                if (_httpRequest.Headers.Contains("If-None-Match"))
 650                {
 0651                    _httpRequest.Headers.Remove("If-None-Match");
 652                }
 4653                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 654            }
 655
 656
 44657            if (customHeaders != null)
 658            {
 0659                foreach(var _header in customHeaders)
 660                {
 0661                    if (_httpRequest.Headers.Contains(_header.Key))
 662                    {
 0663                        _httpRequest.Headers.Remove(_header.Key);
 664                    }
 0665                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 666                }
 667            }
 668
 669            // Serialize Request
 44670            string _requestContent = null;
 44671            if(index != null)
 672            {
 44673                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(index, Client.SerializationSettings
 44674                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 44675                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 676            }
 677            // Set Credentials
 44678            if (Client.Credentials != null)
 679            {
 44680                cancellationToken.ThrowIfCancellationRequested();
 44681                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 682            }
 683            // Send Request
 44684            if (_shouldTrace)
 685            {
 0686                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 687            }
 44688            cancellationToken.ThrowIfCancellationRequested();
 44689            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 44690            if (_shouldTrace)
 691            {
 0692                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 693            }
 44694            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 44695            cancellationToken.ThrowIfCancellationRequested();
 44696            string _responseContent = null;
 44697            if ((int)_statusCode != 200 && (int)_statusCode != 201)
 698            {
 8699                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 700                try
 701                {
 8702                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 8703                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 8704                    if (_errorBody != null)
 705                    {
 8706                        ex = new CloudException(_errorBody.Message);
 8707                        ex.Body = _errorBody;
 708                    }
 8709                }
 0710                catch (JsonException)
 711                {
 712                    // Ignore the exception
 0713                }
 8714                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 8715                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 8716                if (_httpResponse.Headers.Contains("request-id"))
 717                {
 8718                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 719                }
 8720                if (_shouldTrace)
 721                {
 0722                    ServiceClientTracing.Error(_invocationId, ex);
 723                }
 8724                _httpRequest.Dispose();
 8725                if (_httpResponse != null)
 726                {
 8727                    _httpResponse.Dispose();
 728                }
 8729                throw ex;
 730            }
 731            // Create Result
 36732            var _result = new AzureOperationResponse<Index>();
 36733            _result.Request = _httpRequest;
 36734            _result.Response = _httpResponse;
 36735            if (_httpResponse.Headers.Contains("request-id"))
 736            {
 36737                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 738            }
 739            // Deserialize Response
 36740            if ((int)_statusCode == 200)
 741            {
 20742                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 743                try
 744                {
 20745                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client.
 20746                }
 0747                catch (JsonException ex)
 748                {
 0749                    _httpRequest.Dispose();
 0750                    if (_httpResponse != null)
 751                    {
 0752                        _httpResponse.Dispose();
 753                    }
 0754                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 755                }
 756            }
 757            // Deserialize Response
 36758            if ((int)_statusCode == 201)
 759            {
 16760                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 761                try
 762                {
 16763                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client.
 16764                }
 0765                catch (JsonException ex)
 766                {
 0767                    _httpRequest.Dispose();
 0768                    if (_httpResponse != null)
 769                    {
 0770                        _httpResponse.Dispose();
 771                    }
 0772                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 773                }
 774            }
 36775            if (_shouldTrace)
 776            {
 0777                ServiceClientTracing.Exit(_invocationId, _result);
 778            }
 36779            return _result;
 36780        }
 781
 782        /// <summary>
 783        /// Deletes a search index and all the documents it contains.
 784        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/delete-index">Delete 
 785        /// </summary>
 786        /// <param name='indexName'>
 787        /// The name of the index to delete.
 788        /// </param>
 789        /// <param name='searchRequestOptions'>
 790        /// Additional parameters for the operation
 791        /// </param>
 792        /// <param name='accessCondition'>
 793        /// Additional parameters for the operation
 794        /// </param>
 795        /// <param name='customHeaders'>
 796        /// Headers that will be added to request.
 797        /// </param>
 798        /// <param name='cancellationToken'>
 799        /// The cancellation token.
 800        /// </param>
 801        /// <exception cref="CloudException">
 802        /// Thrown when the operation returned an invalid status code
 803        /// </exception>
 804        /// <exception cref="ValidationException">
 805        /// Thrown when a required parameter is null
 806        /// </exception>
 807        /// <exception cref="System.ArgumentNullException">
 808        /// Thrown when a required parameter is null
 809        /// </exception>
 810        /// <return>
 811        /// A response object containing the response body and response headers.
 812        /// </return>
 813        public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string indexName, SearchRequestOptions sea
 814        {
 42815            if (Client.SearchServiceName == null)
 816            {
 0817                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 818            }
 42819            if (Client.SearchDnsSuffix == null)
 820            {
 0821                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 822            }
 42823            if (indexName == null)
 824            {
 0825                throw new ValidationException(ValidationRules.CannotBeNull, "indexName");
 826            }
 42827            if (Client.ApiVersion == null)
 828            {
 0829                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 830            }
 42831            System.Guid? clientRequestId = default(System.Guid?);
 42832            if (searchRequestOptions != null)
 833            {
 0834                clientRequestId = searchRequestOptions.ClientRequestId;
 835            }
 42836            string ifMatch = default(string);
 42837            if (accessCondition != null)
 838            {
 8839                ifMatch = accessCondition.IfMatch;
 840            }
 42841            string ifNoneMatch = default(string);
 42842            if (accessCondition != null)
 843            {
 8844                ifNoneMatch = accessCondition.IfNoneMatch;
 845            }
 846            // Tracing
 42847            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 42848            string _invocationId = null;
 42849            if (_shouldTrace)
 850            {
 0851                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0852                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0853                tracingParameters.Add("indexName", indexName);
 0854                tracingParameters.Add("clientRequestId", clientRequestId);
 0855                tracingParameters.Add("ifMatch", ifMatch);
 0856                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 0857                tracingParameters.Add("cancellationToken", cancellationToken);
 0858                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 859            }
 860            // Construct URL
 42861            var _baseUrl = Client.BaseUri;
 42862            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')";
 42863            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 42864            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 42865            _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName));
 42866            List<string> _queryParameters = new List<string>();
 42867            if (Client.ApiVersion != null)
 868            {
 42869                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 870            }
 42871            if (_queryParameters.Count > 0)
 872            {
 42873                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 874            }
 875            // Create HTTP transport objects
 42876            var _httpRequest = new HttpRequestMessage();
 42877            HttpResponseMessage _httpResponse = null;
 42878            _httpRequest.Method = new HttpMethod("DELETE");
 42879            _httpRequest.RequestUri = new System.Uri(_url);
 880            // Set Headers
 42881            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 882            {
 42883                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 884            }
 42885            if (Client.AcceptLanguage != null)
 886            {
 42887                if (_httpRequest.Headers.Contains("accept-language"))
 888                {
 0889                    _httpRequest.Headers.Remove("accept-language");
 890                }
 42891                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 892            }
 42893            if (clientRequestId != null)
 894            {
 0895                if (_httpRequest.Headers.Contains("client-request-id"))
 896                {
 0897                    _httpRequest.Headers.Remove("client-request-id");
 898                }
 0899                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 900            }
 42901            if (ifMatch != null)
 902            {
 8903                if (_httpRequest.Headers.Contains("If-Match"))
 904                {
 0905                    _httpRequest.Headers.Remove("If-Match");
 906                }
 8907                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 908            }
 42909            if (ifNoneMatch != null)
 910            {
 0911                if (_httpRequest.Headers.Contains("If-None-Match"))
 912                {
 0913                    _httpRequest.Headers.Remove("If-None-Match");
 914                }
 0915                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 916            }
 917
 918
 42919            if (customHeaders != null)
 920            {
 0921                foreach(var _header in customHeaders)
 922                {
 0923                    if (_httpRequest.Headers.Contains(_header.Key))
 924                    {
 0925                        _httpRequest.Headers.Remove(_header.Key);
 926                    }
 0927                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 928                }
 929            }
 930
 931            // Serialize Request
 42932            string _requestContent = null;
 933            // Set Credentials
 42934            if (Client.Credentials != null)
 935            {
 42936                cancellationToken.ThrowIfCancellationRequested();
 42937                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 938            }
 939            // Send Request
 42940            if (_shouldTrace)
 941            {
 0942                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 943            }
 42944            cancellationToken.ThrowIfCancellationRequested();
 42945            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 42946            if (_shouldTrace)
 947            {
 0948                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 949            }
 42950            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 42951            cancellationToken.ThrowIfCancellationRequested();
 42952            string _responseContent = null;
 42953            if ((int)_statusCode != 204 && (int)_statusCode != 404)
 954            {
 4955                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 956                try
 957                {
 4958                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4959                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 4960                    if (_errorBody != null)
 961                    {
 4962                        ex = new CloudException(_errorBody.Message);
 4963                        ex.Body = _errorBody;
 964                    }
 4965                }
 0966                catch (JsonException)
 967                {
 968                    // Ignore the exception
 0969                }
 4970                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 4971                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 4972                if (_httpResponse.Headers.Contains("request-id"))
 973                {
 4974                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 975                }
 4976                if (_shouldTrace)
 977                {
 0978                    ServiceClientTracing.Error(_invocationId, ex);
 979                }
 4980                _httpRequest.Dispose();
 4981                if (_httpResponse != null)
 982                {
 4983                    _httpResponse.Dispose();
 984                }
 4985                throw ex;
 986            }
 987            // Create Result
 38988            var _result = new AzureOperationResponse();
 38989            _result.Request = _httpRequest;
 38990            _result.Response = _httpResponse;
 38991            if (_httpResponse.Headers.Contains("request-id"))
 992            {
 38993                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 994            }
 38995            if (_shouldTrace)
 996            {
 0997                ServiceClientTracing.Exit(_invocationId, _result);
 998            }
 38999            return _result;
 381000        }
 1001
 1002        /// <summary>
 1003        /// Retrieves an index definition.
 1004        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/get-index">Get Index<
 1005        /// </summary>
 1006        /// <param name='indexName'>
 1007        /// The name of the index to retrieve.
 1008        /// </param>
 1009        /// <param name='searchRequestOptions'>
 1010        /// Additional parameters for the operation
 1011        /// </param>
 1012        /// <param name='customHeaders'>
 1013        /// Headers that will be added to request.
 1014        /// </param>
 1015        /// <param name='cancellationToken'>
 1016        /// The cancellation token.
 1017        /// </param>
 1018        /// <exception cref="CloudException">
 1019        /// Thrown when the operation returned an invalid status code
 1020        /// </exception>
 1021        /// <exception cref="SerializationException">
 1022        /// Thrown when unable to deserialize the response
 1023        /// </exception>
 1024        /// <exception cref="ValidationException">
 1025        /// Thrown when a required parameter is null
 1026        /// </exception>
 1027        /// <exception cref="System.ArgumentNullException">
 1028        /// Thrown when a required parameter is null
 1029        /// </exception>
 1030        /// <return>
 1031        /// A response object containing the response body and response headers.
 1032        /// </return>
 1033        public async Task<AzureOperationResponse<Index>> GetWithHttpMessagesAsync(string indexName, SearchRequestOptions
 1034        {
 221035            if (Client.SearchServiceName == null)
 1036            {
 01037                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1038            }
 221039            if (Client.SearchDnsSuffix == null)
 1040            {
 01041                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1042            }
 221043            if (indexName == null)
 1044            {
 01045                throw new ValidationException(ValidationRules.CannotBeNull, "indexName");
 1046            }
 221047            if (Client.ApiVersion == null)
 1048            {
 01049                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1050            }
 221051            System.Guid? clientRequestId = default(System.Guid?);
 221052            if (searchRequestOptions != null)
 1053            {
 01054                clientRequestId = searchRequestOptions.ClientRequestId;
 1055            }
 1056            // Tracing
 221057            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 221058            string _invocationId = null;
 221059            if (_shouldTrace)
 1060            {
 01061                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01062                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01063                tracingParameters.Add("indexName", indexName);
 01064                tracingParameters.Add("clientRequestId", clientRequestId);
 01065                tracingParameters.Add("cancellationToken", cancellationToken);
 01066                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 1067            }
 1068            // Construct URL
 221069            var _baseUrl = Client.BaseUri;
 221070            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')";
 221071            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 221072            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 221073            _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName));
 221074            List<string> _queryParameters = new List<string>();
 221075            if (Client.ApiVersion != null)
 1076            {
 221077                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1078            }
 221079            if (_queryParameters.Count > 0)
 1080            {
 221081                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1082            }
 1083            // Create HTTP transport objects
 221084            var _httpRequest = new HttpRequestMessage();
 221085            HttpResponseMessage _httpResponse = null;
 221086            _httpRequest.Method = new HttpMethod("GET");
 221087            _httpRequest.RequestUri = new System.Uri(_url);
 1088            // Set Headers
 221089            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1090            {
 221091                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1092            }
 221093            if (Client.AcceptLanguage != null)
 1094            {
 221095                if (_httpRequest.Headers.Contains("accept-language"))
 1096                {
 01097                    _httpRequest.Headers.Remove("accept-language");
 1098                }
 221099                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1100            }
 221101            if (clientRequestId != null)
 1102            {
 01103                if (_httpRequest.Headers.Contains("client-request-id"))
 1104                {
 01105                    _httpRequest.Headers.Remove("client-request-id");
 1106                }
 01107                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 1108            }
 1109
 1110
 221111            if (customHeaders != null)
 1112            {
 01113                foreach(var _header in customHeaders)
 1114                {
 01115                    if (_httpRequest.Headers.Contains(_header.Key))
 1116                    {
 01117                        _httpRequest.Headers.Remove(_header.Key);
 1118                    }
 01119                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1120                }
 1121            }
 1122
 1123            // Serialize Request
 221124            string _requestContent = null;
 1125            // Set Credentials
 221126            if (Client.Credentials != null)
 1127            {
 221128                cancellationToken.ThrowIfCancellationRequested();
 221129                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1130            }
 1131            // Send Request
 221132            if (_shouldTrace)
 1133            {
 01134                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1135            }
 221136            cancellationToken.ThrowIfCancellationRequested();
 221137            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 221138            if (_shouldTrace)
 1139            {
 01140                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1141            }
 221142            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 221143            cancellationToken.ThrowIfCancellationRequested();
 221144            string _responseContent = null;
 221145            if ((int)_statusCode != 200)
 1146            {
 61147                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1148                try
 1149                {
 61150                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 61151                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 61152                    if (_errorBody != null)
 1153                    {
 61154                        ex = new CloudException(_errorBody.Message);
 61155                        ex.Body = _errorBody;
 1156                    }
 61157                }
 01158                catch (JsonException)
 1159                {
 1160                    // Ignore the exception
 01161                }
 61162                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 61163                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 61164                if (_httpResponse.Headers.Contains("request-id"))
 1165                {
 61166                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1167                }
 61168                if (_shouldTrace)
 1169                {
 01170                    ServiceClientTracing.Error(_invocationId, ex);
 1171                }
 61172                _httpRequest.Dispose();
 61173                if (_httpResponse != null)
 1174                {
 61175                    _httpResponse.Dispose();
 1176                }
 61177                throw ex;
 1178            }
 1179            // Create Result
 161180            var _result = new AzureOperationResponse<Index>();
 161181            _result.Request = _httpRequest;
 161182            _result.Response = _httpResponse;
 161183            if (_httpResponse.Headers.Contains("request-id"))
 1184            {
 161185                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1186            }
 1187            // Deserialize Response
 161188            if ((int)_statusCode == 200)
 1189            {
 161190                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1191                try
 1192                {
 161193                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Index>(_responseContent, Client.
 161194                }
 01195                catch (JsonException ex)
 1196                {
 01197                    _httpRequest.Dispose();
 01198                    if (_httpResponse != null)
 1199                    {
 01200                        _httpResponse.Dispose();
 1201                    }
 01202                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1203                }
 1204            }
 161205            if (_shouldTrace)
 1206            {
 01207                ServiceClientTracing.Exit(_invocationId, _result);
 1208            }
 161209            return _result;
 161210        }
 1211
 1212        /// <summary>
 1213        /// Returns statistics for the given index, including a document count and
 1214        /// storage usage.
 1215        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/get-index-statistics"
 1216        /// </summary>
 1217        /// <param name='indexName'>
 1218        /// The name of the index for which to retrieve statistics.
 1219        /// </param>
 1220        /// <param name='searchRequestOptions'>
 1221        /// Additional parameters for the operation
 1222        /// </param>
 1223        /// <param name='customHeaders'>
 1224        /// Headers that will be added to request.
 1225        /// </param>
 1226        /// <param name='cancellationToken'>
 1227        /// The cancellation token.
 1228        /// </param>
 1229        /// <exception cref="CloudException">
 1230        /// Thrown when the operation returned an invalid status code
 1231        /// </exception>
 1232        /// <exception cref="SerializationException">
 1233        /// Thrown when unable to deserialize the response
 1234        /// </exception>
 1235        /// <exception cref="ValidationException">
 1236        /// Thrown when a required parameter is null
 1237        /// </exception>
 1238        /// <exception cref="System.ArgumentNullException">
 1239        /// Thrown when a required parameter is null
 1240        /// </exception>
 1241        /// <return>
 1242        /// A response object containing the response body and response headers.
 1243        /// </return>
 1244        public async Task<AzureOperationResponse<IndexGetStatisticsResult>> GetStatisticsWithHttpMessagesAsync(string in
 1245        {
 21246            if (Client.SearchServiceName == null)
 1247            {
 01248                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1249            }
 21250            if (Client.SearchDnsSuffix == null)
 1251            {
 01252                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1253            }
 21254            if (indexName == null)
 1255            {
 01256                throw new ValidationException(ValidationRules.CannotBeNull, "indexName");
 1257            }
 21258            if (Client.ApiVersion == null)
 1259            {
 01260                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1261            }
 21262            System.Guid? clientRequestId = default(System.Guid?);
 21263            if (searchRequestOptions != null)
 1264            {
 01265                clientRequestId = searchRequestOptions.ClientRequestId;
 1266            }
 1267            // Tracing
 21268            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 21269            string _invocationId = null;
 21270            if (_shouldTrace)
 1271            {
 01272                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01273                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01274                tracingParameters.Add("indexName", indexName);
 01275                tracingParameters.Add("clientRequestId", clientRequestId);
 01276                tracingParameters.Add("cancellationToken", cancellationToken);
 01277                ServiceClientTracing.Enter(_invocationId, this, "GetStatistics", tracingParameters);
 1278            }
 1279            // Construct URL
 21280            var _baseUrl = Client.BaseUri;
 21281            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')/search.stats";
 21282            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 21283            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 21284            _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName));
 21285            List<string> _queryParameters = new List<string>();
 21286            if (Client.ApiVersion != null)
 1287            {
 21288                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1289            }
 21290            if (_queryParameters.Count > 0)
 1291            {
 21292                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1293            }
 1294            // Create HTTP transport objects
 21295            var _httpRequest = new HttpRequestMessage();
 21296            HttpResponseMessage _httpResponse = null;
 21297            _httpRequest.Method = new HttpMethod("GET");
 21298            _httpRequest.RequestUri = new System.Uri(_url);
 1299            // Set Headers
 21300            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1301            {
 21302                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1303            }
 21304            if (Client.AcceptLanguage != null)
 1305            {
 21306                if (_httpRequest.Headers.Contains("accept-language"))
 1307                {
 01308                    _httpRequest.Headers.Remove("accept-language");
 1309                }
 21310                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1311            }
 21312            if (clientRequestId != null)
 1313            {
 01314                if (_httpRequest.Headers.Contains("client-request-id"))
 1315                {
 01316                    _httpRequest.Headers.Remove("client-request-id");
 1317                }
 01318                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 1319            }
 1320
 1321
 21322            if (customHeaders != null)
 1323            {
 01324                foreach(var _header in customHeaders)
 1325                {
 01326                    if (_httpRequest.Headers.Contains(_header.Key))
 1327                    {
 01328                        _httpRequest.Headers.Remove(_header.Key);
 1329                    }
 01330                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1331                }
 1332            }
 1333
 1334            // Serialize Request
 21335            string _requestContent = null;
 1336            // Set Credentials
 21337            if (Client.Credentials != null)
 1338            {
 21339                cancellationToken.ThrowIfCancellationRequested();
 21340                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1341            }
 1342            // Send Request
 21343            if (_shouldTrace)
 1344            {
 01345                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1346            }
 21347            cancellationToken.ThrowIfCancellationRequested();
 21348            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 21349            if (_shouldTrace)
 1350            {
 01351                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1352            }
 21353            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 21354            cancellationToken.ThrowIfCancellationRequested();
 21355            string _responseContent = null;
 21356            if ((int)_statusCode != 200)
 1357            {
 01358                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1359                try
 1360                {
 01361                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01362                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 01363                    if (_errorBody != null)
 1364                    {
 01365                        ex = new CloudException(_errorBody.Message);
 01366                        ex.Body = _errorBody;
 1367                    }
 01368                }
 01369                catch (JsonException)
 1370                {
 1371                    // Ignore the exception
 01372                }
 01373                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01374                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01375                if (_httpResponse.Headers.Contains("request-id"))
 1376                {
 01377                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1378                }
 01379                if (_shouldTrace)
 1380                {
 01381                    ServiceClientTracing.Error(_invocationId, ex);
 1382                }
 01383                _httpRequest.Dispose();
 01384                if (_httpResponse != null)
 1385                {
 01386                    _httpResponse.Dispose();
 1387                }
 01388                throw ex;
 1389            }
 1390            // Create Result
 21391            var _result = new AzureOperationResponse<IndexGetStatisticsResult>();
 21392            _result.Request = _httpRequest;
 21393            _result.Response = _httpResponse;
 21394            if (_httpResponse.Headers.Contains("request-id"))
 1395            {
 21396                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1397            }
 1398            // Deserialize Response
 21399            if ((int)_statusCode == 200)
 1400            {
 21401                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1402                try
 1403                {
 21404                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IndexGetStatisticsResult>(_respo
 21405                }
 01406                catch (JsonException ex)
 1407                {
 01408                    _httpRequest.Dispose();
 01409                    if (_httpResponse != null)
 1410                    {
 01411                        _httpResponse.Dispose();
 1412                    }
 01413                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1414                }
 1415            }
 21416            if (_shouldTrace)
 1417            {
 01418                ServiceClientTracing.Exit(_invocationId, _result);
 1419            }
 21420            return _result;
 21421        }
 1422
 1423        /// <summary>
 1424        /// Shows how an analyzer breaks text into tokens.
 1425        /// For more information, see <see href="https://docs.microsoft.com/rest/api/searchservice/test-analyzer">Analyz
 1426        /// </summary>
 1427        /// <param name='indexName'>
 1428        /// The name of the index for which to test an analyzer.
 1429        /// </param>
 1430        /// <param name='request'>
 1431        /// The text and analyzer or analysis components to test.
 1432        /// </param>
 1433        /// <param name='searchRequestOptions'>
 1434        /// Additional parameters for the operation
 1435        /// </param>
 1436        /// <param name='customHeaders'>
 1437        /// Headers that will be added to request.
 1438        /// </param>
 1439        /// <param name='cancellationToken'>
 1440        /// The cancellation token.
 1441        /// </param>
 1442        /// <exception cref="CloudException">
 1443        /// Thrown when the operation returned an invalid status code
 1444        /// </exception>
 1445        /// <exception cref="SerializationException">
 1446        /// Thrown when unable to deserialize the response
 1447        /// </exception>
 1448        /// <exception cref="ValidationException">
 1449        /// Thrown when a required parameter is null
 1450        /// </exception>
 1451        /// <exception cref="System.ArgumentNullException">
 1452        /// Thrown when a required parameter is null
 1453        /// </exception>
 1454        /// <return>
 1455        /// A response object containing the response body and response headers.
 1456        /// </return>
 1457        public async Task<AzureOperationResponse<AnalyzeResult>> AnalyzeWithHttpMessagesAsync(string indexName, AnalyzeR
 1458        {
 2181459            if (Client.SearchServiceName == null)
 1460            {
 01461                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1462            }
 2181463            if (Client.SearchDnsSuffix == null)
 1464            {
 01465                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1466            }
 2181467            if (indexName == null)
 1468            {
 01469                throw new ValidationException(ValidationRules.CannotBeNull, "indexName");
 1470            }
 2181471            if (request == null)
 1472            {
 01473                throw new ValidationException(ValidationRules.CannotBeNull, "request");
 1474            }
 2181475            if (request != null)
 1476            {
 2181477                request.Validate();
 1478            }
 2181479            if (Client.ApiVersion == null)
 1480            {
 01481                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1482            }
 2181483            System.Guid? clientRequestId = default(System.Guid?);
 2181484            if (searchRequestOptions != null)
 1485            {
 01486                clientRequestId = searchRequestOptions.ClientRequestId;
 1487            }
 1488            // Tracing
 2181489            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2181490            string _invocationId = null;
 2181491            if (_shouldTrace)
 1492            {
 01493                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01494                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01495                tracingParameters.Add("indexName", indexName);
 01496                tracingParameters.Add("request", request);
 01497                tracingParameters.Add("clientRequestId", clientRequestId);
 01498                tracingParameters.Add("cancellationToken", cancellationToken);
 01499                ServiceClientTracing.Enter(_invocationId, this, "Analyze", tracingParameters);
 1500            }
 1501            // Construct URL
 2181502            var _baseUrl = Client.BaseUri;
 2181503            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "indexes('{indexName}')/search.analyze";
 2181504            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 2181505            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 2181506            _url = _url.Replace("{indexName}", System.Uri.EscapeDataString(indexName));
 2181507            List<string> _queryParameters = new List<string>();
 2181508            if (Client.ApiVersion != null)
 1509            {
 2181510                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1511            }
 2181512            if (_queryParameters.Count > 0)
 1513            {
 2181514                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1515            }
 1516            // Create HTTP transport objects
 2181517            var _httpRequest = new HttpRequestMessage();
 2181518            HttpResponseMessage _httpResponse = null;
 2181519            _httpRequest.Method = new HttpMethod("POST");
 2181520            _httpRequest.RequestUri = new System.Uri(_url);
 1521            // Set Headers
 2181522            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1523            {
 2181524                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1525            }
 2181526            if (Client.AcceptLanguage != null)
 1527            {
 2181528                if (_httpRequest.Headers.Contains("accept-language"))
 1529                {
 01530                    _httpRequest.Headers.Remove("accept-language");
 1531                }
 2181532                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1533            }
 2181534            if (clientRequestId != null)
 1535            {
 01536                if (_httpRequest.Headers.Contains("client-request-id"))
 1537                {
 01538                    _httpRequest.Headers.Remove("client-request-id");
 1539                }
 01540                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 1541            }
 1542
 1543
 2181544            if (customHeaders != null)
 1545            {
 01546                foreach(var _header in customHeaders)
 1547                {
 01548                    if (_httpRequest.Headers.Contains(_header.Key))
 1549                    {
 01550                        _httpRequest.Headers.Remove(_header.Key);
 1551                    }
 01552                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1553                }
 1554            }
 1555
 1556            // Serialize Request
 2181557            string _requestContent = null;
 2181558            if(request != null)
 1559            {
 2181560                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(request, Client.SerializationSettin
 2181561                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 2181562                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1563            }
 1564            // Set Credentials
 2181565            if (Client.Credentials != null)
 1566            {
 2181567                cancellationToken.ThrowIfCancellationRequested();
 2181568                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1569            }
 1570            // Send Request
 2181571            if (_shouldTrace)
 1572            {
 01573                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1574            }
 2181575            cancellationToken.ThrowIfCancellationRequested();
 2181576            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2181577            if (_shouldTrace)
 1578            {
 01579                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1580            }
 2181581            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2181582            cancellationToken.ThrowIfCancellationRequested();
 2181583            string _responseContent = null;
 2181584            if ((int)_statusCode != 200)
 1585            {
 01586                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1587                try
 1588                {
 01589                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01590                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 01591                    if (_errorBody != null)
 1592                    {
 01593                        ex = new CloudException(_errorBody.Message);
 01594                        ex.Body = _errorBody;
 1595                    }
 01596                }
 01597                catch (JsonException)
 1598                {
 1599                    // Ignore the exception
 01600                }
 01601                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01602                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01603                if (_httpResponse.Headers.Contains("request-id"))
 1604                {
 01605                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1606                }
 01607                if (_shouldTrace)
 1608                {
 01609                    ServiceClientTracing.Error(_invocationId, ex);
 1610                }
 01611                _httpRequest.Dispose();
 01612                if (_httpResponse != null)
 1613                {
 01614                    _httpResponse.Dispose();
 1615                }
 01616                throw ex;
 1617            }
 1618            // Create Result
 2181619            var _result = new AzureOperationResponse<AnalyzeResult>();
 2181620            _result.Request = _httpRequest;
 2181621            _result.Response = _httpResponse;
 2181622            if (_httpResponse.Headers.Contains("request-id"))
 1623            {
 2181624                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1625            }
 1626            // Deserialize Response
 2181627            if ((int)_statusCode == 200)
 1628            {
 2181629                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1630                try
 1631                {
 2181632                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AnalyzeResult>(_responseContent,
 2181633                }
 01634                catch (JsonException ex)
 1635                {
 01636                    _httpRequest.Dispose();
 01637                    if (_httpResponse != null)
 1638                    {
 01639                        _httpResponse.Dispose();
 1640                    }
 01641                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1642                }
 1643            }
 2181644            if (_shouldTrace)
 1645            {
 01646                ServiceClientTracing.Exit(_invocationId, _result);
 1647            }
 2181648            return _result;
 2181649        }
 1650
 1651    }
 1652}