< Summary

Class:Microsoft.Azure.Search.DocumentsProxyOperations
Assembly:Microsoft.Azure.Search.Data
File(s):C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Generated\DocumentsOperations.cs
Covered lines:855
Uncovered lines:314
Coverable lines:1169
Total lines:2420
Line coverage:73.1% (855 of 1169)
Covered branches:596
Total branches:832
Branch coverage:71.6% (596 of 832)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
CountWithHttpMessagesAsync()-58.59%57.35%
SearchGetWithHttpMessagesAsync()-78.2%87.74%
ContinueSearchGetWithHttpMessagesAsync()-77.14%68.75%
SearchPostWithHttpMessagesAsync()-64.71%59.09%
ContinueSearchPostWithHttpMessagesAsync()-85.14%75%
GetWithHttpMessagesAsync()-70.75%63.89%
SuggestGetWithHttpMessagesAsync()-75.93%78.45%
SuggestPostWithHttpMessagesAsync()-73.58%67.57%
IndexWithHttpMessagesAsync()-71.79%70.24%
AutocompleteGetWithHttpMessagesAsync()-73.08%73.68%
AutocompletePostWithHttpMessagesAsync()-70.75%64.86%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Microsoft.Azure.Search.Data\src\Generated\DocumentsOperations.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    /// DocumentsProxyOperations operations.
 27    /// </summary>
 28    internal partial class DocumentsProxyOperations : IServiceOperations<SearchIndexClient>, IDocumentsProxyOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the DocumentsProxyOperations 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>
 68839        internal DocumentsProxyOperations(SearchIndexClient client)
 40        {
 68841            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 68845            Client = client;
 68846        }
 47
 48        /// <summary>
 49        /// Gets a reference to the SearchIndexClient
 50        /// </summary>
 1644451        public SearchIndexClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Queries the number of documents in the index.
 55        /// <see href="https://docs.microsoft.com/rest/api/searchservice/Count-Documents" />
 56        /// </summary>
 57        /// <param name='searchRequestOptions'>
 58        /// Additional parameters for the operation
 59        /// </param>
 60        /// <param name='customHeaders'>
 61        /// Headers that will be added to request.
 62        /// </param>
 63        /// <param name='cancellationToken'>
 64        /// The cancellation token.
 65        /// </param>
 66        /// <exception cref="CloudException">
 67        /// Thrown when the operation returned an invalid status code
 68        /// </exception>
 69        /// <exception cref="SerializationException">
 70        /// Thrown when unable to deserialize the response
 71        /// </exception>
 72        /// <exception cref="ValidationException">
 73        /// Thrown when a required parameter is null
 74        /// </exception>
 75        /// <exception cref="System.ArgumentNullException">
 76        /// Thrown when a required parameter is null
 77        /// </exception>
 78        /// <return>
 79        /// A response object containing the response body and response headers.
 80        /// </return>
 81        public async Task<AzureOperationResponse<long?>> CountWithHttpMessagesAsync(SearchRequestOptions searchRequestOp
 82        {
 3883            if (Client.SearchServiceName == null)
 84            {
 085                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 86            }
 3887            if (Client.SearchDnsSuffix == null)
 88            {
 089                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 90            }
 3891            if (Client.IndexName == null)
 92            {
 093                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 94            }
 3895            if (Client.ApiVersion == null)
 96            {
 097                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 98            }
 3899            System.Guid? clientRequestId = default(System.Guid?);
 38100            if (searchRequestOptions != null)
 101            {
 2102                clientRequestId = searchRequestOptions.ClientRequestId;
 103            }
 104            // Tracing
 38105            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 38106            string _invocationId = null;
 38107            if (_shouldTrace)
 108            {
 0109                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0110                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0111                tracingParameters.Add("clientRequestId", clientRequestId);
 0112                tracingParameters.Add("cancellationToken", cancellationToken);
 0113                ServiceClientTracing.Enter(_invocationId, this, "Count", tracingParameters);
 114            }
 115            // Construct URL
 38116            var _baseUrl = Client.BaseUri;
 38117            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/$count";
 38118            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 38119            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 38120            _url = _url.Replace("{indexName}", Client.IndexName);
 38121            List<string> _queryParameters = new List<string>();
 38122            if (Client.ApiVersion != null)
 123            {
 38124                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 125            }
 38126            if (_queryParameters.Count > 0)
 127            {
 38128                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 129            }
 130            // Create HTTP transport objects
 38131            var _httpRequest = new HttpRequestMessage();
 38132            HttpResponseMessage _httpResponse = null;
 38133            _httpRequest.Method = new HttpMethod("GET");
 38134            _httpRequest.RequestUri = new System.Uri(_url);
 135            // Set Headers
 38136            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 137            {
 38138                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 139            }
 38140            if (Client.AcceptLanguage != null)
 141            {
 38142                if (_httpRequest.Headers.Contains("accept-language"))
 143                {
 0144                    _httpRequest.Headers.Remove("accept-language");
 145                }
 38146                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 147            }
 38148            if (clientRequestId != null)
 149            {
 2150                if (_httpRequest.Headers.Contains("client-request-id"))
 151                {
 2152                    _httpRequest.Headers.Remove("client-request-id");
 153                }
 2154                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 155            }
 156
 157
 38158            if (customHeaders != null)
 159            {
 0160                foreach(var _header in customHeaders)
 161                {
 0162                    if (_httpRequest.Headers.Contains(_header.Key))
 163                    {
 0164                        _httpRequest.Headers.Remove(_header.Key);
 165                    }
 0166                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 167                }
 168            }
 169
 170            // Serialize Request
 38171            string _requestContent = null;
 172            // Set Credentials
 38173            if (Client.Credentials != null)
 174            {
 38175                cancellationToken.ThrowIfCancellationRequested();
 38176                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 177            }
 178            // Send Request
 38179            if (_shouldTrace)
 180            {
 0181                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 182            }
 38183            cancellationToken.ThrowIfCancellationRequested();
 38184            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 38185            if (_shouldTrace)
 186            {
 0187                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 188            }
 38189            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 38190            cancellationToken.ThrowIfCancellationRequested();
 38191            string _responseContent = null;
 38192            if ((int)_statusCode != 200)
 193            {
 0194                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 195                try
 196                {
 0197                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0198                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0199                    if (_errorBody != null)
 200                    {
 0201                        ex = new CloudException(_errorBody.Message);
 0202                        ex.Body = _errorBody;
 203                    }
 0204                }
 0205                catch (JsonException)
 206                {
 207                    // Ignore the exception
 0208                }
 0209                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0210                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0211                if (_httpResponse.Headers.Contains("request-id"))
 212                {
 0213                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 214                }
 0215                if (_shouldTrace)
 216                {
 0217                    ServiceClientTracing.Error(_invocationId, ex);
 218                }
 0219                _httpRequest.Dispose();
 0220                if (_httpResponse != null)
 221                {
 0222                    _httpResponse.Dispose();
 223                }
 0224                throw ex;
 225            }
 226            // Create Result
 38227            var _result = new AzureOperationResponse<long?>();
 38228            _result.Request = _httpRequest;
 38229            _result.Response = _httpResponse;
 38230            if (_httpResponse.Headers.Contains("request-id"))
 231            {
 38232                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 233            }
 234            // Deserialize Response
 38235            if ((int)_statusCode == 200)
 236            {
 38237                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 238                try
 239                {
 38240                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<long?>(_responseContent, respons
 38241                }
 0242                catch (JsonException ex)
 243                {
 0244                    _httpRequest.Dispose();
 0245                    if (_httpResponse != null)
 246                    {
 0247                        _httpResponse.Dispose();
 248                    }
 0249                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 250                }
 251            }
 38252            if (_shouldTrace)
 253            {
 0254                ServiceClientTracing.Exit(_invocationId, _result);
 255            }
 38256            return _result;
 38257        }
 258
 259        /// <summary>
 260        /// Searches for documents in the index.
 261        /// <see href="https://docs.microsoft.com/rest/api/searchservice/Search-Documents" />
 262        /// </summary>
 263        /// <param name='searchText'>
 264        /// A full-text search query expression; Use "*" or omit this parameter to
 265        /// match all documents.
 266        /// </param>
 267        /// <param name='searchParameters'>
 268        /// Additional parameters for the operation
 269        /// </param>
 270        /// <param name='searchRequestOptions'>
 271        /// Additional parameters for the operation
 272        /// </param>
 273        /// <param name='customHeaders'>
 274        /// Headers that will be added to request.
 275        /// </param>
 276        /// <param name='cancellationToken'>
 277        /// The cancellation token.
 278        /// </param>
 279        /// <exception cref="CloudException">
 280        /// Thrown when the operation returned an invalid status code
 281        /// </exception>
 282        /// <exception cref="SerializationException">
 283        /// Thrown when unable to deserialize the response
 284        /// </exception>
 285        /// <exception cref="ValidationException">
 286        /// Thrown when a required parameter is null
 287        /// </exception>
 288        /// <exception cref="System.ArgumentNullException">
 289        /// Thrown when a required parameter is null
 290        /// </exception>
 291        /// <return>
 292        /// A response object containing the response body and response headers.
 293        /// </return>
 294        public async Task<AzureOperationResponse<DocumentSearchResult<T>>> SearchGetWithHttpMessagesAsync<T>(string sear
 295        {
 56296            if (Client.SearchServiceName == null)
 297            {
 0298                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 299            }
 56300            if (Client.SearchDnsSuffix == null)
 301            {
 0302                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 303            }
 56304            if (Client.IndexName == null)
 305            {
 0306                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 307            }
 56308            if (Client.ApiVersion == null)
 309            {
 0310                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 311            }
 56312            bool includeTotalResultCount = default(bool);
 56313            if (searchParameters != null)
 314            {
 56315                includeTotalResultCount = searchParameters.IncludeTotalResultCount;
 316            }
 56317            IList<string> facets = default(IList<string>);
 56318            if (searchParameters != null)
 319            {
 56320                facets = searchParameters.Facets;
 321            }
 56322            string filter = default(string);
 56323            if (searchParameters != null)
 324            {
 56325                filter = searchParameters.Filter;
 326            }
 56327            IList<string> highlightFields = default(IList<string>);
 56328            if (searchParameters != null)
 329            {
 56330                highlightFields = searchParameters.HighlightFields;
 331            }
 56332            string highlightPostTag = default(string);
 56333            if (searchParameters != null)
 334            {
 56335                highlightPostTag = searchParameters.HighlightPostTag;
 336            }
 56337            string highlightPreTag = default(string);
 56338            if (searchParameters != null)
 339            {
 56340                highlightPreTag = searchParameters.HighlightPreTag;
 341            }
 56342            double? minimumCoverage = default(double?);
 56343            if (searchParameters != null)
 344            {
 56345                minimumCoverage = searchParameters.MinimumCoverage;
 346            }
 56347            IList<string> orderBy = default(IList<string>);
 56348            if (searchParameters != null)
 349            {
 56350                orderBy = searchParameters.OrderBy;
 351            }
 56352            QueryType queryType = default(QueryType);
 56353            if (searchParameters != null)
 354            {
 56355                queryType = searchParameters.QueryType;
 356            }
 56357            IList<ScoringParameter> scoringParameters = default(IList<ScoringParameter>);
 56358            if (searchParameters != null)
 359            {
 56360                scoringParameters = searchParameters.ScoringParameters;
 361            }
 56362            string scoringProfile = default(string);
 56363            if (searchParameters != null)
 364            {
 56365                scoringProfile = searchParameters.ScoringProfile;
 366            }
 56367            IList<string> searchFields = default(IList<string>);
 56368            if (searchParameters != null)
 369            {
 56370                searchFields = searchParameters.SearchFields;
 371            }
 56372            SearchMode searchMode = default(SearchMode);
 56373            if (searchParameters != null)
 374            {
 56375                searchMode = searchParameters.SearchMode;
 376            }
 56377            IList<string> select = default(IList<string>);
 56378            if (searchParameters != null)
 379            {
 56380                select = searchParameters.Select;
 381            }
 56382            int? skip = default(int?);
 56383            if (searchParameters != null)
 384            {
 56385                skip = searchParameters.Skip;
 386            }
 56387            int? top = default(int?);
 56388            if (searchParameters != null)
 389            {
 56390                top = searchParameters.Top;
 391            }
 56392            System.Guid? clientRequestId = default(System.Guid?);
 56393            if (searchRequestOptions != null)
 394            {
 0395                clientRequestId = searchRequestOptions.ClientRequestId;
 396            }
 397            // Tracing
 56398            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 56399            string _invocationId = null;
 56400            if (_shouldTrace)
 401            {
 0402                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0403                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0404                tracingParameters.Add("searchText", searchText);
 0405                tracingParameters.Add("includeTotalResultCount", includeTotalResultCount);
 0406                tracingParameters.Add("facets", facets);
 0407                tracingParameters.Add("filter", filter);
 0408                tracingParameters.Add("highlightFields", highlightFields);
 0409                tracingParameters.Add("highlightPostTag", highlightPostTag);
 0410                tracingParameters.Add("highlightPreTag", highlightPreTag);
 0411                tracingParameters.Add("minimumCoverage", minimumCoverage);
 0412                tracingParameters.Add("orderBy", orderBy);
 0413                tracingParameters.Add("queryType", queryType);
 0414                tracingParameters.Add("scoringParameters", scoringParameters);
 0415                tracingParameters.Add("scoringProfile", scoringProfile);
 0416                tracingParameters.Add("searchFields", searchFields);
 0417                tracingParameters.Add("searchMode", searchMode);
 0418                tracingParameters.Add("select", select);
 0419                tracingParameters.Add("skip", skip);
 0420                tracingParameters.Add("top", top);
 0421                tracingParameters.Add("clientRequestId", clientRequestId);
 0422                tracingParameters.Add("cancellationToken", cancellationToken);
 0423                ServiceClientTracing.Enter(_invocationId, this, "SearchGet", tracingParameters);
 424            }
 425            // Construct URL
 56426            var _baseUrl = Client.BaseUri;
 56427            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs";
 56428            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 56429            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 56430            _url = _url.Replace("{indexName}", Client.IndexName);
 56431            List<string> _queryParameters = new List<string>();
 56432            if (searchText != null)
 433            {
 56434                _queryParameters.Add(string.Format("search={0}", System.Uri.EscapeDataString(searchText)));
 435            }
 56436            if (Client.ApiVersion != null)
 437            {
 56438                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 439            }
 56440            _queryParameters.Add(string.Format("$count={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConv
 56441            if (facets != null)
 442            {
 4443                if (facets.Count == 0)
 444                {
 0445                    _queryParameters.Add(string.Format("facet={0}", System.Uri.EscapeDataString(string.Empty)));
 446                }
 447                else
 448                {
 40449                    foreach (var _item in facets)
 450                    {
 16451                        _queryParameters.Add(string.Format("facet={0}", System.Uri.EscapeDataString("" + _item)));
 452                    }
 453                }
 454            }
 56455            if (filter != null)
 456            {
 10457                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 458            }
 56459            if (highlightFields != null)
 460            {
 2461                _queryParameters.Add(string.Format("highlight={0}", System.Uri.EscapeDataString(string.Join(",", highlig
 462            }
 56463            if (highlightPostTag != null)
 464            {
 2465                _queryParameters.Add(string.Format("highlightPostTag={0}", System.Uri.EscapeDataString(highlightPostTag)
 466            }
 56467            if (highlightPreTag != null)
 468            {
 2469                _queryParameters.Add(string.Format("highlightPreTag={0}", System.Uri.EscapeDataString(highlightPreTag)))
 470            }
 56471            if (minimumCoverage != null)
 472            {
 2473                _queryParameters.Add(string.Format("minimumCoverage={0}", System.Uri.EscapeDataString(Rest.Serialization
 474            }
 56475            if (orderBy != null)
 476            {
 12477                _queryParameters.Add(string.Format("$orderby={0}", System.Uri.EscapeDataString(string.Join(",", orderBy)
 478            }
 56479            _queryParameters.Add(string.Format("queryType={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC
 56480            if (scoringParameters != null)
 481            {
 2482                if (scoringParameters.Count == 0)
 483                {
 0484                    _queryParameters.Add(string.Format("scoringParameter={0}", System.Uri.EscapeDataString(string.Empty)
 485                }
 486                else
 487                {
 8488                    foreach (var _item in scoringParameters)
 489                    {
 2490                        _queryParameters.Add(string.Format("scoringParameter={0}", System.Uri.EscapeDataString("" + _ite
 491                    }
 492                }
 493            }
 56494            if (scoringProfile != null)
 495            {
 2496                _queryParameters.Add(string.Format("scoringProfile={0}", System.Uri.EscapeDataString(scoringProfile)));
 497            }
 56498            if (searchFields != null)
 499            {
 4500                _queryParameters.Add(string.Format("searchFields={0}", System.Uri.EscapeDataString(string.Join(",", sear
 501            }
 56502            _queryParameters.Add(string.Format("searchMode={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJson
 56503            if (select != null)
 504            {
 14505                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(string.Join(",", select)))
 506            }
 56507            if (skip != null)
 508            {
 4509                _queryParameters.Add(string.Format("$skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC
 510            }
 56511            if (top != null)
 512            {
 10513                _queryParameters.Add(string.Format("$top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 514            }
 56515            if (_queryParameters.Count > 0)
 516            {
 56517                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 518            }
 56519            return await ContinueSearchGetWithHttpMessagesAsync<T>(_url, clientRequestId, customHeaders, _shouldTrace, _
 52520        }
 521
 522        public async Task<AzureOperationResponse<DocumentSearchResult<T>>> ContinueSearchGetWithHttpMessagesAsync<T>(str
 523        {
 524            // Create HTTP transport objects
 72525            var _httpRequest = new HttpRequestMessage();
 72526            HttpResponseMessage _httpResponse = null;
 72527            _httpRequest.Method = new HttpMethod("GET");
 72528            _httpRequest.RequestUri = new System.Uri(_url);
 529            // Set Headers
 72530            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 531            {
 72532                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 533            }
 72534            if (Client.AcceptLanguage != null)
 535            {
 72536                if (_httpRequest.Headers.Contains("accept-language"))
 537                {
 0538                    _httpRequest.Headers.Remove("accept-language");
 539                }
 72540                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 541            }
 72542            if (clientRequestId != null)
 543            {
 0544                if (_httpRequest.Headers.Contains("client-request-id"))
 545                {
 0546                    _httpRequest.Headers.Remove("client-request-id");
 547                }
 0548                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 549            }
 550
 551
 72552            if (customHeaders != null)
 553            {
 288554                foreach(var _header in customHeaders)
 555                {
 72556                    if (_httpRequest.Headers.Contains(_header.Key))
 557                    {
 0558                        _httpRequest.Headers.Remove(_header.Key);
 559                    }
 72560                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 561                }
 562            }
 563
 564            // Serialize Request
 72565            string _requestContent = null;
 566            // Set Credentials
 72567            if (Client.Credentials != null)
 568            {
 72569                cancellationToken.ThrowIfCancellationRequested();
 72570                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 571            }
 572            // Send Request
 72573            if (_shouldTrace)
 574            {
 0575                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 576            }
 72577            cancellationToken.ThrowIfCancellationRequested();
 72578            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 72579            if (_shouldTrace)
 580            {
 0581                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 582            }
 72583            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 72584            cancellationToken.ThrowIfCancellationRequested();
 72585            string _responseContent = null;
 72586            if ((int)_statusCode != 200)
 587            {
 4588                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 589                try
 590                {
 4591                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4592                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 4593                    if (_errorBody != null)
 594                    {
 4595                        ex = new CloudException(_errorBody.Message);
 4596                        ex.Body = _errorBody;
 597                    }
 4598                }
 0599                catch (JsonException)
 600                {
 601                    // Ignore the exception
 0602                }
 4603                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 4604                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 4605                if (_httpResponse.Headers.Contains("request-id"))
 606                {
 4607                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 608                }
 4609                if (_shouldTrace)
 610                {
 0611                    ServiceClientTracing.Error(_invocationId, ex);
 612                }
 4613                _httpRequest.Dispose();
 4614                if (_httpResponse != null)
 615                {
 4616                    _httpResponse.Dispose();
 617                }
 4618                throw ex;
 619            }
 620            // Create Result
 68621            var _result = new AzureOperationResponse<DocumentSearchResult<T>>();
 68622            _result.Request = _httpRequest;
 68623            _result.Response = _httpResponse;
 68624            if (_httpResponse.Headers.Contains("request-id"))
 625            {
 68626                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 627            }
 628            // Deserialize Response
 68629            if ((int)_statusCode == 200)
 630            {
 68631                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 632                try
 633                {
 68634                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<DocumentSearchResult<T>>(_respon
 68635                }
 0636                catch (JsonException ex)
 637                {
 0638                    _httpRequest.Dispose();
 0639                    if (_httpResponse != null)
 640                    {
 0641                        _httpResponse.Dispose();
 642                    }
 0643                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 644                }
 645            }
 68646            if (_shouldTrace)
 647            {
 0648                ServiceClientTracing.Exit(_invocationId, _result);
 649            }
 68650            return _result;
 68651        }
 652
 653        /// <summary>
 654        /// Searches for documents in the index.
 655        /// <see href="https://docs.microsoft.com/rest/api/searchservice/Search-Documents" />
 656        /// </summary>
 657        /// <param name='searchRequest'>
 658        /// The definition of the Search request.
 659        /// </param>
 660        /// <param name='searchRequestOptions'>
 661        /// Additional parameters for the operation
 662        /// </param>
 663        /// <param name='customHeaders'>
 664        /// Headers that will be added to request.
 665        /// </param>
 666        /// <param name='cancellationToken'>
 667        /// The cancellation token.
 668        /// </param>
 669        /// <exception cref="CloudException">
 670        /// Thrown when the operation returned an invalid status code
 671        /// </exception>
 672        /// <exception cref="SerializationException">
 673        /// Thrown when unable to deserialize the response
 674        /// </exception>
 675        /// <exception cref="ValidationException">
 676        /// Thrown when a required parameter is null
 677        /// </exception>
 678        /// <exception cref="System.ArgumentNullException">
 679        /// Thrown when a required parameter is null
 680        /// </exception>
 681        /// <return>
 682        /// A response object containing the response body and response headers.
 683        /// </return>
 684        public async Task<AzureOperationResponse<DocumentSearchResult<T>>> SearchPostWithHttpMessagesAsync<T>(SearchRequ
 685        {
 86686            if (Client.SearchServiceName == null)
 687            {
 0688                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 689            }
 86690            if (Client.SearchDnsSuffix == null)
 691            {
 0692                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 693            }
 86694            if (Client.IndexName == null)
 695            {
 0696                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 697            }
 86698            if (searchRequest == null)
 699            {
 0700                throw new ValidationException(ValidationRules.CannotBeNull, "searchRequest");
 701            }
 86702            if (Client.ApiVersion == null)
 703            {
 0704                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 705            }
 86706            System.Guid? clientRequestId = default(System.Guid?);
 86707            if (searchRequestOptions != null)
 708            {
 0709                clientRequestId = searchRequestOptions.ClientRequestId;
 710            }
 711            // Tracing
 86712            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 86713            string _invocationId = null;
 86714            if (_shouldTrace)
 715            {
 0716                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0717                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0718                tracingParameters.Add("searchRequest", searchRequest);
 0719                tracingParameters.Add("clientRequestId", clientRequestId);
 0720                tracingParameters.Add("cancellationToken", cancellationToken);
 0721                ServiceClientTracing.Enter(_invocationId, this, "SearchPost", tracingParameters);
 722            }
 723            // Construct URL
 86724            var _baseUrl = Client.BaseUri;
 86725            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/search.post.search";
 86726            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 86727            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 86728            _url = _url.Replace("{indexName}", Client.IndexName);
 86729            List<string> _queryParameters = new List<string>();
 86730            if (Client.ApiVersion != null)
 731            {
 86732                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 733            }
 86734            if (_queryParameters.Count > 0)
 735            {
 86736                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 737            }
 86738            return await ContinueSearchPostWithHttpMessagesAsync<T>(_url, searchRequest, clientRequestId, customHeaders,
 74739        }
 740
 741        public async Task<AzureOperationResponse<DocumentSearchResult<T>>> ContinueSearchPostWithHttpMessagesAsync<T>(st
 742        {
 743            // Create HTTP transport objects
 102744            var _httpRequest = new HttpRequestMessage();
 102745            HttpResponseMessage _httpResponse = null;
 102746            _httpRequest.Method = new HttpMethod("POST");
 102747            _httpRequest.RequestUri = new System.Uri(_url);
 748            // Set Headers
 102749            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 750            {
 102751                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 752            }
 102753            if (Client.AcceptLanguage != null)
 754            {
 102755                if (_httpRequest.Headers.Contains("accept-language"))
 756                {
 0757                    _httpRequest.Headers.Remove("accept-language");
 758                }
 102759                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 760            }
 102761            if (clientRequestId != null)
 762            {
 0763                if (_httpRequest.Headers.Contains("client-request-id"))
 764                {
 0765                    _httpRequest.Headers.Remove("client-request-id");
 766                }
 0767                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 768            }
 769
 770
 102771            if (customHeaders != null)
 772            {
 408773                foreach(var _header in customHeaders)
 774                {
 102775                    if (_httpRequest.Headers.Contains(_header.Key))
 776                    {
 0777                        _httpRequest.Headers.Remove(_header.Key);
 778                    }
 102779                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 780                }
 781            }
 782
 783            // Serialize Request
 102784            string _requestContent = null;
 102785            if(searchRequest != null)
 786            {
 102787                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(searchRequest, requestSerializerSet
 102788                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 102789                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 790            }
 791            // Set Credentials
 102792            if (Client.Credentials != null)
 793            {
 102794                cancellationToken.ThrowIfCancellationRequested();
 102795                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 796            }
 797            // Send Request
 102798            if (_shouldTrace)
 799            {
 0800                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 801            }
 102802            cancellationToken.ThrowIfCancellationRequested();
 102803            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 102804            if (_shouldTrace)
 805            {
 0806                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 807            }
 102808            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 102809            cancellationToken.ThrowIfCancellationRequested();
 102810            string _responseContent = null;
 102811            if ((int)_statusCode != 200)
 812            {
 4813                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 814                try
 815                {
 4816                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4817                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 4818                    if (_errorBody != null)
 819                    {
 4820                        ex = new CloudException(_errorBody.Message);
 4821                        ex.Body = _errorBody;
 822                    }
 4823                }
 0824                catch (JsonException)
 825                {
 826                    // Ignore the exception
 0827                }
 4828                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 4829                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 4830                if (_httpResponse.Headers.Contains("request-id"))
 831                {
 4832                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 833                }
 4834                if (_shouldTrace)
 835                {
 0836                    ServiceClientTracing.Error(_invocationId, ex);
 837                }
 4838                _httpRequest.Dispose();
 4839                if (_httpResponse != null)
 840                {
 4841                    _httpResponse.Dispose();
 842                }
 4843                throw ex;
 844            }
 845            // Create Result
 98846            var _result = new AzureOperationResponse<DocumentSearchResult<T>>();
 98847            _result.Request = _httpRequest;
 98848            _result.Response = _httpResponse;
 98849            if (_httpResponse.Headers.Contains("request-id"))
 850            {
 98851                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 852            }
 853            // Deserialize Response
 98854            if ((int)_statusCode == 200)
 855            {
 98856                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 857                try
 858                {
 98859                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<DocumentSearchResult<T>>(_respon
 90860                }
 8861                catch (JsonException ex)
 862                {
 8863                    _httpRequest.Dispose();
 8864                    if (_httpResponse != null)
 865                    {
 8866                        _httpResponse.Dispose();
 867                    }
 8868                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 869                }
 870            }
 90871            if (_shouldTrace)
 872            {
 0873                ServiceClientTracing.Exit(_invocationId, _result);
 874            }
 90875            return _result;
 90876        }
 877
 878        /// <summary>
 879        /// Retrieves a document from the index.
 880        /// <see href="https://docs.microsoft.com/rest/api/searchservice/lookup-document" />
 881        /// </summary>
 882        /// <param name='key'>
 883        /// The key of the document to retrieve.
 884        /// </param>
 885        /// <param name='selectedFields'>
 886        /// List of field names to retrieve for the document; Any field not retrieved
 887        /// will be missing from the returned document.
 888        /// </param>
 889        /// <param name='searchRequestOptions'>
 890        /// Additional parameters for the operation
 891        /// </param>
 892        /// <param name='customHeaders'>
 893        /// Headers that will be added to request.
 894        /// </param>
 895        /// <param name='cancellationToken'>
 896        /// The cancellation token.
 897        /// </param>
 898        /// <exception cref="CloudException">
 899        /// Thrown when the operation returned an invalid status code
 900        /// </exception>
 901        /// <exception cref="SerializationException">
 902        /// Thrown when unable to deserialize the response
 903        /// </exception>
 904        /// <exception cref="ValidationException">
 905        /// Thrown when a required parameter is null
 906        /// </exception>
 907        /// <exception cref="System.ArgumentNullException">
 908        /// Thrown when a required parameter is null
 909        /// </exception>
 910        /// <return>
 911        /// A response object containing the response body and response headers.
 912        /// </return>
 913        public async Task<AzureOperationResponse<T>> GetWithHttpMessagesAsync<T>(string key, IList<string> selectedField
 914        {
 80915            if (Client.SearchServiceName == null)
 916            {
 0917                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 918            }
 80919            if (Client.SearchDnsSuffix == null)
 920            {
 0921                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 922            }
 80923            if (Client.IndexName == null)
 924            {
 0925                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 926            }
 80927            if (key == null)
 928            {
 0929                throw new ValidationException(ValidationRules.CannotBeNull, "key");
 930            }
 80931            if (Client.ApiVersion == null)
 932            {
 0933                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 934            }
 80935            System.Guid? clientRequestId = default(System.Guid?);
 80936            if (searchRequestOptions != null)
 937            {
 0938                clientRequestId = searchRequestOptions.ClientRequestId;
 939            }
 940            // Tracing
 80941            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 80942            string _invocationId = null;
 80943            if (_shouldTrace)
 944            {
 0945                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0946                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0947                tracingParameters.Add("key", key);
 0948                tracingParameters.Add("selectedFields", selectedFields);
 0949                tracingParameters.Add("clientRequestId", clientRequestId);
 0950                tracingParameters.Add("cancellationToken", cancellationToken);
 0951                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 952            }
 953            // Construct URL
 80954            var _baseUrl = Client.BaseUri;
 80955            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs('{key}')";
 80956            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 80957            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 80958            _url = _url.Replace("{indexName}", Client.IndexName);
 80959            _url = _url.Replace("{key}", System.Uri.EscapeDataString(key));
 80960            List<string> _queryParameters = new List<string>();
 80961            if (selectedFields != null)
 962            {
 80963                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(string.Join(",", selectedF
 964            }
 80965            if (Client.ApiVersion != null)
 966            {
 80967                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 968            }
 80969            if (_queryParameters.Count > 0)
 970            {
 80971                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 972            }
 973            // Create HTTP transport objects
 80974            var _httpRequest = new HttpRequestMessage();
 80975            HttpResponseMessage _httpResponse = null;
 80976            _httpRequest.Method = new HttpMethod("GET");
 80977            _httpRequest.RequestUri = new System.Uri(_url);
 978            // Set Headers
 80979            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 980            {
 80981                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 982            }
 80983            if (Client.AcceptLanguage != null)
 984            {
 80985                if (_httpRequest.Headers.Contains("accept-language"))
 986                {
 0987                    _httpRequest.Headers.Remove("accept-language");
 988                }
 80989                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 990            }
 80991            if (clientRequestId != null)
 992            {
 0993                if (_httpRequest.Headers.Contains("client-request-id"))
 994                {
 0995                    _httpRequest.Headers.Remove("client-request-id");
 996                }
 0997                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 998            }
 999
 1000
 801001            if (customHeaders != null)
 1002            {
 3201003                foreach(var _header in customHeaders)
 1004                {
 801005                    if (_httpRequest.Headers.Contains(_header.Key))
 1006                    {
 01007                        _httpRequest.Headers.Remove(_header.Key);
 1008                    }
 801009                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1010                }
 1011            }
 1012
 1013            // Serialize Request
 801014            string _requestContent = null;
 1015            // Set Credentials
 801016            if (Client.Credentials != null)
 1017            {
 801018                cancellationToken.ThrowIfCancellationRequested();
 801019                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1020            }
 1021            // Send Request
 801022            if (_shouldTrace)
 1023            {
 01024                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1025            }
 801026            cancellationToken.ThrowIfCancellationRequested();
 801027            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 801028            if (_shouldTrace)
 1029            {
 01030                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1031            }
 801032            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 801033            cancellationToken.ThrowIfCancellationRequested();
 801034            string _responseContent = null;
 801035            if ((int)_statusCode != 200)
 1036            {
 41037                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1038                try
 1039                {
 41040                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 41041                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 41042                    if (_errorBody != null)
 1043                    {
 21044                        ex = new CloudException(_errorBody.Message);
 21045                        ex.Body = _errorBody;
 1046                    }
 41047                }
 01048                catch (JsonException)
 1049                {
 1050                    // Ignore the exception
 01051                }
 41052                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 41053                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 41054                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1055                {
 01056                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1057                }
 41058                if (_shouldTrace)
 1059                {
 01060                    ServiceClientTracing.Error(_invocationId, ex);
 1061                }
 41062                _httpRequest.Dispose();
 41063                if (_httpResponse != null)
 1064                {
 41065                    _httpResponse.Dispose();
 1066                }
 41067                throw ex;
 1068            }
 1069            // Create Result
 761070            var _result = new AzureOperationResponse<T>();
 761071            _result.Request = _httpRequest;
 761072            _result.Response = _httpResponse;
 761073            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1074            {
 01075                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1076            }
 1077            // Deserialize Response
 761078            if ((int)_statusCode == 200)
 1079            {
 761080                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1081                try
 1082                {
 761083                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<T>(_responseContent, responseDes
 761084                }
 01085                catch (JsonException ex)
 1086                {
 01087                    _httpRequest.Dispose();
 01088                    if (_httpResponse != null)
 1089                    {
 01090                        _httpResponse.Dispose();
 1091                    }
 01092                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1093                }
 1094            }
 761095            if (_shouldTrace)
 1096            {
 01097                ServiceClientTracing.Exit(_invocationId, _result);
 1098            }
 761099            return _result;
 761100        }
 1101
 1102        /// <summary>
 1103        /// Suggests documents in the index that match the given partial query text.
 1104        /// <see href="https://docs.microsoft.com/rest/api/searchservice/suggestions" />
 1105        /// </summary>
 1106        /// <param name='searchText'>
 1107        /// The search text to use to suggest documents. Must be at least 1 character,
 1108        /// and no more than 100 characters.
 1109        /// </param>
 1110        /// <param name='suggesterName'>
 1111        /// The name of the suggester as specified in the suggesters collection that's
 1112        /// part of the index definition.
 1113        /// </param>
 1114        /// <param name='suggestParameters'>
 1115        /// Additional parameters for the operation
 1116        /// </param>
 1117        /// <param name='searchRequestOptions'>
 1118        /// Additional parameters for the operation
 1119        /// </param>
 1120        /// <param name='customHeaders'>
 1121        /// Headers that will be added to request.
 1122        /// </param>
 1123        /// <param name='cancellationToken'>
 1124        /// The cancellation token.
 1125        /// </param>
 1126        /// <exception cref="CloudException">
 1127        /// Thrown when the operation returned an invalid status code
 1128        /// </exception>
 1129        /// <exception cref="SerializationException">
 1130        /// Thrown when unable to deserialize the response
 1131        /// </exception>
 1132        /// <exception cref="ValidationException">
 1133        /// Thrown when a required parameter is null
 1134        /// </exception>
 1135        /// <exception cref="System.ArgumentNullException">
 1136        /// Thrown when a required parameter is null
 1137        /// </exception>
 1138        /// <return>
 1139        /// A response object containing the response body and response headers.
 1140        /// </return>
 1141        public async Task<AzureOperationResponse<DocumentSuggestResult<T>>> SuggestGetWithHttpMessagesAsync<T>(string se
 1142        {
 301143            if (Client.SearchServiceName == null)
 1144            {
 01145                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1146            }
 301147            if (Client.SearchDnsSuffix == null)
 1148            {
 01149                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1150            }
 301151            if (Client.IndexName == null)
 1152            {
 01153                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 1154            }
 301155            if (searchText == null)
 1156            {
 01157                throw new ValidationException(ValidationRules.CannotBeNull, "searchText");
 1158            }
 301159            if (suggesterName == null)
 1160            {
 01161                throw new ValidationException(ValidationRules.CannotBeNull, "suggesterName");
 1162            }
 301163            if (Client.ApiVersion == null)
 1164            {
 01165                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1166            }
 301167            string filter = default(string);
 301168            if (suggestParameters != null)
 1169            {
 301170                filter = suggestParameters.Filter;
 1171            }
 301172            bool useFuzzyMatching = default(bool);
 301173            if (suggestParameters != null)
 1174            {
 301175                useFuzzyMatching = suggestParameters.UseFuzzyMatching;
 1176            }
 301177            string highlightPostTag = default(string);
 301178            if (suggestParameters != null)
 1179            {
 301180                highlightPostTag = suggestParameters.HighlightPostTag;
 1181            }
 301182            string highlightPreTag = default(string);
 301183            if (suggestParameters != null)
 1184            {
 301185                highlightPreTag = suggestParameters.HighlightPreTag;
 1186            }
 301187            double? minimumCoverage = default(double?);
 301188            if (suggestParameters != null)
 1189            {
 301190                minimumCoverage = suggestParameters.MinimumCoverage;
 1191            }
 301192            IList<string> orderBy = default(IList<string>);
 301193            if (suggestParameters != null)
 1194            {
 301195                orderBy = suggestParameters.OrderBy;
 1196            }
 301197            IList<string> searchFields = default(IList<string>);
 301198            if (suggestParameters != null)
 1199            {
 301200                searchFields = suggestParameters.SearchFields;
 1201            }
 301202            IList<string> select = default(IList<string>);
 301203            if (suggestParameters != null)
 1204            {
 301205                select = suggestParameters.Select;
 1206            }
 301207            int? top = default(int?);
 301208            if (suggestParameters != null)
 1209            {
 301210                top = suggestParameters.Top;
 1211            }
 301212            System.Guid? clientRequestId = default(System.Guid?);
 301213            if (searchRequestOptions != null)
 1214            {
 01215                clientRequestId = searchRequestOptions.ClientRequestId;
 1216            }
 1217            // Tracing
 301218            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 301219            string _invocationId = null;
 301220            if (_shouldTrace)
 1221            {
 01222                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01223                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01224                tracingParameters.Add("searchText", searchText);
 01225                tracingParameters.Add("suggesterName", suggesterName);
 01226                tracingParameters.Add("filter", filter);
 01227                tracingParameters.Add("useFuzzyMatching", useFuzzyMatching);
 01228                tracingParameters.Add("highlightPostTag", highlightPostTag);
 01229                tracingParameters.Add("highlightPreTag", highlightPreTag);
 01230                tracingParameters.Add("minimumCoverage", minimumCoverage);
 01231                tracingParameters.Add("orderBy", orderBy);
 01232                tracingParameters.Add("searchFields", searchFields);
 01233                tracingParameters.Add("select", select);
 01234                tracingParameters.Add("top", top);
 01235                tracingParameters.Add("clientRequestId", clientRequestId);
 01236                tracingParameters.Add("cancellationToken", cancellationToken);
 01237                ServiceClientTracing.Enter(_invocationId, this, "SuggestGet", tracingParameters);
 1238            }
 1239            // Construct URL
 301240            var _baseUrl = Client.BaseUri;
 301241            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/search.suggest";
 301242            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 301243            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 301244            _url = _url.Replace("{indexName}", Client.IndexName);
 301245            List<string> _queryParameters = new List<string>();
 301246            if (searchText != null)
 1247            {
 301248                _queryParameters.Add(string.Format("search={0}", System.Uri.EscapeDataString(searchText)));
 1249            }
 301250            if (suggesterName != null)
 1251            {
 301252                _queryParameters.Add(string.Format("suggesterName={0}", System.Uri.EscapeDataString(suggesterName)));
 1253            }
 301254            if (Client.ApiVersion != null)
 1255            {
 301256                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1257            }
 301258            if (filter != null)
 1259            {
 41260                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 1261            }
 301262            _queryParameters.Add(string.Format("fuzzy={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConve
 301263            if (highlightPostTag != null)
 1264            {
 21265                _queryParameters.Add(string.Format("highlightPostTag={0}", System.Uri.EscapeDataString(highlightPostTag)
 1266            }
 301267            if (highlightPreTag != null)
 1268            {
 21269                _queryParameters.Add(string.Format("highlightPreTag={0}", System.Uri.EscapeDataString(highlightPreTag)))
 1270            }
 301271            if (minimumCoverage != null)
 1272            {
 21273                _queryParameters.Add(string.Format("minimumCoverage={0}", System.Uri.EscapeDataString(Rest.Serialization
 1274            }
 301275            if (orderBy != null)
 1276            {
 121277                _queryParameters.Add(string.Format("$orderby={0}", System.Uri.EscapeDataString(string.Join(",", orderBy)
 1278            }
 301279            if (searchFields != null)
 1280            {
 21281                _queryParameters.Add(string.Format("searchFields={0}", System.Uri.EscapeDataString(string.Join(",", sear
 1282            }
 301283            if (select != null)
 1284            {
 301285                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(string.Join(",", select)))
 1286            }
 301287            if (top != null)
 1288            {
 41289                _queryParameters.Add(string.Format("$top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 1290            }
 301291            if (_queryParameters.Count > 0)
 1292            {
 301293                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1294            }
 1295            // Create HTTP transport objects
 301296            var _httpRequest = new HttpRequestMessage();
 301297            HttpResponseMessage _httpResponse = null;
 301298            _httpRequest.Method = new HttpMethod("GET");
 301299            _httpRequest.RequestUri = new System.Uri(_url);
 1300            // Set Headers
 301301            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1302            {
 301303                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1304            }
 301305            if (Client.AcceptLanguage != null)
 1306            {
 301307                if (_httpRequest.Headers.Contains("accept-language"))
 1308                {
 01309                    _httpRequest.Headers.Remove("accept-language");
 1310                }
 301311                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1312            }
 301313            if (clientRequestId != null)
 1314            {
 01315                if (_httpRequest.Headers.Contains("client-request-id"))
 1316                {
 01317                    _httpRequest.Headers.Remove("client-request-id");
 1318                }
 01319                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 1320            }
 1321
 1322
 301323            if (customHeaders != null)
 1324            {
 1201325                foreach(var _header in customHeaders)
 1326                {
 301327                    if (_httpRequest.Headers.Contains(_header.Key))
 1328                    {
 01329                        _httpRequest.Headers.Remove(_header.Key);
 1330                    }
 301331                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1332                }
 1333            }
 1334
 1335            // Serialize Request
 301336            string _requestContent = null;
 1337            // Set Credentials
 301338            if (Client.Credentials != null)
 1339            {
 301340                cancellationToken.ThrowIfCancellationRequested();
 301341                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1342            }
 1343            // Send Request
 301344            if (_shouldTrace)
 1345            {
 01346                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1347            }
 301348            cancellationToken.ThrowIfCancellationRequested();
 301349            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 301350            if (_shouldTrace)
 1351            {
 01352                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1353            }
 301354            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 301355            cancellationToken.ThrowIfCancellationRequested();
 301356            string _responseContent = null;
 301357            if ((int)_statusCode != 200)
 1358            {
 41359                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1360                try
 1361                {
 41362                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 41363                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 41364                    if (_errorBody != null)
 1365                    {
 41366                        ex = new CloudException(_errorBody.Message);
 41367                        ex.Body = _errorBody;
 1368                    }
 41369                }
 01370                catch (JsonException)
 1371                {
 1372                    // Ignore the exception
 01373                }
 41374                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 41375                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 41376                if (_httpResponse.Headers.Contains("request-id"))
 1377                {
 41378                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1379                }
 41380                if (_shouldTrace)
 1381                {
 01382                    ServiceClientTracing.Error(_invocationId, ex);
 1383                }
 41384                _httpRequest.Dispose();
 41385                if (_httpResponse != null)
 1386                {
 41387                    _httpResponse.Dispose();
 1388                }
 41389                throw ex;
 1390            }
 1391            // Create Result
 261392            var _result = new AzureOperationResponse<DocumentSuggestResult<T>>();
 261393            _result.Request = _httpRequest;
 261394            _result.Response = _httpResponse;
 261395            if (_httpResponse.Headers.Contains("request-id"))
 1396            {
 261397                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1398            }
 1399            // Deserialize Response
 261400            if ((int)_statusCode == 200)
 1401            {
 261402                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1403                try
 1404                {
 261405                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<DocumentSuggestResult<T>>(_respo
 261406                }
 01407                catch (JsonException ex)
 1408                {
 01409                    _httpRequest.Dispose();
 01410                    if (_httpResponse != null)
 1411                    {
 01412                        _httpResponse.Dispose();
 1413                    }
 01414                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1415                }
 1416            }
 261417            if (_shouldTrace)
 1418            {
 01419                ServiceClientTracing.Exit(_invocationId, _result);
 1420            }
 261421            return _result;
 261422        }
 1423
 1424        /// <summary>
 1425        /// Suggests documents in the index that match the given partial query text.
 1426        /// <see href="https://docs.microsoft.com/rest/api/searchservice/suggestions" />
 1427        /// </summary>
 1428        /// <param name='suggestRequest'>
 1429        /// The Suggest request.
 1430        /// </param>
 1431        /// <param name='searchRequestOptions'>
 1432        /// Additional parameters for the operation
 1433        /// </param>
 1434        /// <param name='customHeaders'>
 1435        /// Headers that will be added to request.
 1436        /// </param>
 1437        /// <param name='cancellationToken'>
 1438        /// The cancellation token.
 1439        /// </param>
 1440        /// <exception cref="CloudException">
 1441        /// Thrown when the operation returned an invalid status code
 1442        /// </exception>
 1443        /// <exception cref="SerializationException">
 1444        /// Thrown when unable to deserialize the response
 1445        /// </exception>
 1446        /// <exception cref="ValidationException">
 1447        /// Thrown when a required parameter is null
 1448        /// </exception>
 1449        /// <exception cref="System.ArgumentNullException">
 1450        /// Thrown when a required parameter is null
 1451        /// </exception>
 1452        /// <return>
 1453        /// A response object containing the response body and response headers.
 1454        /// </return>
 1455        public async Task<AzureOperationResponse<DocumentSuggestResult<T>>> SuggestPostWithHttpMessagesAsync<T>(SuggestR
 1456        {
 421457            if (Client.SearchServiceName == null)
 1458            {
 01459                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1460            }
 421461            if (Client.SearchDnsSuffix == null)
 1462            {
 01463                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1464            }
 421465            if (Client.IndexName == null)
 1466            {
 01467                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 1468            }
 421469            if (suggestRequest == null)
 1470            {
 01471                throw new ValidationException(ValidationRules.CannotBeNull, "suggestRequest");
 1472            }
 421473            if (Client.ApiVersion == null)
 1474            {
 01475                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1476            }
 421477            System.Guid? clientRequestId = default(System.Guid?);
 421478            if (searchRequestOptions != null)
 1479            {
 01480                clientRequestId = searchRequestOptions.ClientRequestId;
 1481            }
 1482            // Tracing
 421483            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 421484            string _invocationId = null;
 421485            if (_shouldTrace)
 1486            {
 01487                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01488                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01489                tracingParameters.Add("suggestRequest", suggestRequest);
 01490                tracingParameters.Add("clientRequestId", clientRequestId);
 01491                tracingParameters.Add("cancellationToken", cancellationToken);
 01492                ServiceClientTracing.Enter(_invocationId, this, "SuggestPost", tracingParameters);
 1493            }
 1494            // Construct URL
 421495            var _baseUrl = Client.BaseUri;
 421496            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/search.post.suggest";
 421497            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 421498            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 421499            _url = _url.Replace("{indexName}", Client.IndexName);
 421500            List<string> _queryParameters = new List<string>();
 421501            if (Client.ApiVersion != null)
 1502            {
 421503                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1504            }
 421505            if (_queryParameters.Count > 0)
 1506            {
 421507                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1508            }
 1509            // Create HTTP transport objects
 421510            var _httpRequest = new HttpRequestMessage();
 421511            HttpResponseMessage _httpResponse = null;
 421512            _httpRequest.Method = new HttpMethod("POST");
 421513            _httpRequest.RequestUri = new System.Uri(_url);
 1514            // Set Headers
 421515            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1516            {
 421517                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1518            }
 421519            if (Client.AcceptLanguage != null)
 1520            {
 421521                if (_httpRequest.Headers.Contains("accept-language"))
 1522                {
 01523                    _httpRequest.Headers.Remove("accept-language");
 1524                }
 421525                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1526            }
 421527            if (clientRequestId != null)
 1528            {
 01529                if (_httpRequest.Headers.Contains("client-request-id"))
 1530                {
 01531                    _httpRequest.Headers.Remove("client-request-id");
 1532                }
 01533                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 1534            }
 1535
 1536
 421537            if (customHeaders != null)
 1538            {
 1681539                foreach(var _header in customHeaders)
 1540                {
 421541                    if (_httpRequest.Headers.Contains(_header.Key))
 1542                    {
 01543                        _httpRequest.Headers.Remove(_header.Key);
 1544                    }
 421545                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1546                }
 1547            }
 1548
 1549            // Serialize Request
 421550            string _requestContent = null;
 421551            if(suggestRequest != null)
 1552            {
 421553                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(suggestRequest, requestSerializerSe
 421554                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 421555                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1556            }
 1557            // Set Credentials
 421558            if (Client.Credentials != null)
 1559            {
 421560                cancellationToken.ThrowIfCancellationRequested();
 421561                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1562            }
 1563            // Send Request
 421564            if (_shouldTrace)
 1565            {
 01566                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1567            }
 421568            cancellationToken.ThrowIfCancellationRequested();
 421569            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 421570            if (_shouldTrace)
 1571            {
 01572                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1573            }
 421574            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 421575            cancellationToken.ThrowIfCancellationRequested();
 421576            string _responseContent = null;
 421577            if ((int)_statusCode != 200)
 1578            {
 41579                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1580                try
 1581                {
 41582                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 41583                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 41584                    if (_errorBody != null)
 1585                    {
 41586                        ex = new CloudException(_errorBody.Message);
 41587                        ex.Body = _errorBody;
 1588                    }
 41589                }
 01590                catch (JsonException)
 1591                {
 1592                    // Ignore the exception
 01593                }
 41594                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 41595                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 41596                if (_httpResponse.Headers.Contains("request-id"))
 1597                {
 41598                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1599                }
 41600                if (_shouldTrace)
 1601                {
 01602                    ServiceClientTracing.Error(_invocationId, ex);
 1603                }
 41604                _httpRequest.Dispose();
 41605                if (_httpResponse != null)
 1606                {
 41607                    _httpResponse.Dispose();
 1608                }
 41609                throw ex;
 1610            }
 1611            // Create Result
 381612            var _result = new AzureOperationResponse<DocumentSuggestResult<T>>();
 381613            _result.Request = _httpRequest;
 381614            _result.Response = _httpResponse;
 381615            if (_httpResponse.Headers.Contains("request-id"))
 1616            {
 381617                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1618            }
 1619            // Deserialize Response
 381620            if ((int)_statusCode == 200)
 1621            {
 381622                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1623                try
 1624                {
 381625                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<DocumentSuggestResult<T>>(_respo
 381626                }
 01627                catch (JsonException ex)
 1628                {
 01629                    _httpRequest.Dispose();
 01630                    if (_httpResponse != null)
 1631                    {
 01632                        _httpResponse.Dispose();
 1633                    }
 01634                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1635                }
 1636            }
 381637            if (_shouldTrace)
 1638            {
 01639                ServiceClientTracing.Exit(_invocationId, _result);
 1640            }
 381641            return _result;
 381642        }
 1643
 1644        /// <summary>
 1645        /// Sends a batch of document write actions to the index.
 1646        /// <see href="https://docs.microsoft.com/rest/api/searchservice/addupdate-or-delete-documents" />
 1647        /// </summary>
 1648        /// <param name='batch'>
 1649        /// The batch of index actions.
 1650        /// </param>
 1651        /// <param name='searchRequestOptions'>
 1652        /// Additional parameters for the operation
 1653        /// </param>
 1654        /// <param name='customHeaders'>
 1655        /// Headers that will be added to request.
 1656        /// </param>
 1657        /// <param name='cancellationToken'>
 1658        /// The cancellation token.
 1659        /// </param>
 1660        /// <exception cref="CloudException">
 1661        /// Thrown when the operation returned an invalid status code
 1662        /// </exception>
 1663        /// <exception cref="SerializationException">
 1664        /// Thrown when unable to deserialize the response
 1665        /// </exception>
 1666        /// <exception cref="ValidationException">
 1667        /// Thrown when a required parameter is null
 1668        /// </exception>
 1669        /// <exception cref="System.ArgumentNullException">
 1670        /// Thrown when a required parameter is null
 1671        /// </exception>
 1672        /// <return>
 1673        /// A response object containing the response body and response headers.
 1674        /// </return>
 1675        public async Task<AzureOperationResponse<DocumentIndexResult>> IndexWithHttpMessagesAsync<T>(IndexBatch<T> batch
 1676        {
 4461677            if (Client.SearchServiceName == null)
 1678            {
 01679                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1680            }
 4461681            if (Client.SearchDnsSuffix == null)
 1682            {
 01683                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1684            }
 4461685            if (Client.IndexName == null)
 1686            {
 01687                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 1688            }
 4461689            if (batch == null)
 1690            {
 01691                throw new ValidationException(ValidationRules.CannotBeNull, "batch");
 1692            }
 4461693            if (batch != null)
 1694            {
 4461695                batch.Validate();
 1696            }
 4461697            if (Client.ApiVersion == null)
 1698            {
 01699                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1700            }
 4461701            System.Guid? clientRequestId = default(System.Guid?);
 4461702            if (searchRequestOptions != null)
 1703            {
 01704                clientRequestId = searchRequestOptions.ClientRequestId;
 1705            }
 1706            // Tracing
 4461707            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 4461708            string _invocationId = null;
 4461709            if (_shouldTrace)
 1710            {
 01711                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01712                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01713                tracingParameters.Add("batch", batch);
 01714                tracingParameters.Add("clientRequestId", clientRequestId);
 01715                tracingParameters.Add("cancellationToken", cancellationToken);
 01716                ServiceClientTracing.Enter(_invocationId, this, "Index", tracingParameters);
 1717            }
 1718            // Construct URL
 4461719            var _baseUrl = Client.BaseUri;
 4461720            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/search.index";
 4461721            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 4461722            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 4461723            _url = _url.Replace("{indexName}", Client.IndexName);
 4461724            List<string> _queryParameters = new List<string>();
 4461725            if (Client.ApiVersion != null)
 1726            {
 4461727                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1728            }
 4461729            if (_queryParameters.Count > 0)
 1730            {
 4461731                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1732            }
 1733            // Create HTTP transport objects
 4461734            var _httpRequest = new HttpRequestMessage();
 4461735            HttpResponseMessage _httpResponse = null;
 4461736            _httpRequest.Method = new HttpMethod("POST");
 4461737            _httpRequest.RequestUri = new System.Uri(_url);
 1738            // Set Headers
 4461739            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1740            {
 4461741                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1742            }
 4461743            if (Client.AcceptLanguage != null)
 1744            {
 4461745                if (_httpRequest.Headers.Contains("accept-language"))
 1746                {
 01747                    _httpRequest.Headers.Remove("accept-language");
 1748                }
 4461749                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1750            }
 4461751            if (clientRequestId != null)
 1752            {
 01753                if (_httpRequest.Headers.Contains("client-request-id"))
 1754                {
 01755                    _httpRequest.Headers.Remove("client-request-id");
 1756                }
 01757                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 1758            }
 1759
 1760
 4461761            if (customHeaders != null)
 1762            {
 17841763                foreach(var _header in customHeaders)
 1764                {
 4461765                    if (_httpRequest.Headers.Contains(_header.Key))
 1766                    {
 01767                        _httpRequest.Headers.Remove(_header.Key);
 1768                    }
 4461769                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1770                }
 1771            }
 1772
 1773            // Serialize Request
 4461774            string _requestContent = null;
 4461775            if(batch != null)
 1776            {
 4461777                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(batch, requestSerializerSettings ??
 4461778                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 4461779                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1780            }
 1781            // Set Credentials
 4461782            if (Client.Credentials != null)
 1783            {
 4461784                cancellationToken.ThrowIfCancellationRequested();
 4461785                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1786            }
 1787            // Send Request
 4461788            if (_shouldTrace)
 1789            {
 01790                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1791            }
 4461792            cancellationToken.ThrowIfCancellationRequested();
 4461793            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4461794            if (_shouldTrace)
 1795            {
 01796                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1797            }
 4461798            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 4461799            cancellationToken.ThrowIfCancellationRequested();
 4461800            string _responseContent = null;
 4461801            if ((int)_statusCode != 200 && (int)_statusCode != 207)
 1802            {
 21803                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 1804                try
 1805                {
 21806                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 21807                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 21808                    if (_errorBody != null)
 1809                    {
 21810                        ex = new CloudException(_errorBody.Message);
 21811                        ex.Body = _errorBody;
 1812                    }
 21813                }
 01814                catch (JsonException)
 1815                {
 1816                    // Ignore the exception
 01817                }
 21818                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 21819                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 21820                if (_httpResponse.Headers.Contains("request-id"))
 1821                {
 21822                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1823                }
 21824                if (_shouldTrace)
 1825                {
 01826                    ServiceClientTracing.Error(_invocationId, ex);
 1827                }
 21828                _httpRequest.Dispose();
 21829                if (_httpResponse != null)
 1830                {
 21831                    _httpResponse.Dispose();
 1832                }
 21833                throw ex;
 1834            }
 1835            // Create Result
 4441836            var _result = new AzureOperationResponse<DocumentIndexResult>();
 4441837            _result.Request = _httpRequest;
 4441838            _result.Response = _httpResponse;
 4441839            if (_httpResponse.Headers.Contains("request-id"))
 1840            {
 4441841                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1842            }
 1843            // Deserialize Response
 4441844            if ((int)_statusCode == 200)
 1845            {
 4361846                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1847                try
 1848                {
 4361849                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<DocumentIndexResult>(_responseCo
 4361850                }
 01851                catch (JsonException ex)
 1852                {
 01853                    _httpRequest.Dispose();
 01854                    if (_httpResponse != null)
 1855                    {
 01856                        _httpResponse.Dispose();
 1857                    }
 01858                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1859                }
 1860            }
 1861            // Deserialize Response
 4441862            if ((int)_statusCode == 207)
 1863            {
 81864                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1865                try
 1866                {
 81867                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<DocumentIndexResult>(_responseCo
 81868                }
 01869                catch (JsonException ex)
 1870                {
 01871                    _httpRequest.Dispose();
 01872                    if (_httpResponse != null)
 1873                    {
 01874                        _httpResponse.Dispose();
 1875                    }
 01876                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1877                }
 1878            }
 4441879            if (_shouldTrace)
 1880            {
 01881                ServiceClientTracing.Exit(_invocationId, _result);
 1882            }
 4441883            return _result;
 4441884        }
 1885
 1886        /// <summary>
 1887        /// Autocompletes incomplete query terms based on input text and matching terms
 1888        /// in the index.
 1889        /// <see href="https://docs.microsoft.com/rest/api/searchservice/autocomplete" />
 1890        /// </summary>
 1891        /// <param name='searchText'>
 1892        /// The incomplete term which should be auto-completed.
 1893        /// </param>
 1894        /// <param name='suggesterName'>
 1895        /// The name of the suggester as specified in the suggesters collection that's
 1896        /// part of the index definition.
 1897        /// </param>
 1898        /// <param name='searchRequestOptions'>
 1899        /// Additional parameters for the operation
 1900        /// </param>
 1901        /// <param name='autocompleteParameters'>
 1902        /// Additional parameters for the operation
 1903        /// </param>
 1904        /// <param name='customHeaders'>
 1905        /// Headers that will be added to request.
 1906        /// </param>
 1907        /// <param name='cancellationToken'>
 1908        /// The cancellation token.
 1909        /// </param>
 1910        /// <exception cref="CloudException">
 1911        /// Thrown when the operation returned an invalid status code
 1912        /// </exception>
 1913        /// <exception cref="SerializationException">
 1914        /// Thrown when unable to deserialize the response
 1915        /// </exception>
 1916        /// <exception cref="ValidationException">
 1917        /// Thrown when a required parameter is null
 1918        /// </exception>
 1919        /// <exception cref="System.ArgumentNullException">
 1920        /// Thrown when a required parameter is null
 1921        /// </exception>
 1922        /// <return>
 1923        /// A response object containing the response body and response headers.
 1924        /// </return>
 1925        public async Task<AzureOperationResponse<AutocompleteResult>> AutocompleteGetWithHttpMessagesAsync(string search
 1926        {
 381927            if (Client.SearchServiceName == null)
 1928            {
 01929                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 1930            }
 381931            if (Client.SearchDnsSuffix == null)
 1932            {
 01933                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 1934            }
 381935            if (Client.IndexName == null)
 1936            {
 01937                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 1938            }
 381939            if (Client.ApiVersion == null)
 1940            {
 01941                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1942            }
 381943            if (searchText == null)
 1944            {
 01945                throw new ValidationException(ValidationRules.CannotBeNull, "searchText");
 1946            }
 381947            if (suggesterName == null)
 1948            {
 01949                throw new ValidationException(ValidationRules.CannotBeNull, "suggesterName");
 1950            }
 381951            System.Guid? clientRequestId = default(System.Guid?);
 381952            if (searchRequestOptions != null)
 1953            {
 01954                clientRequestId = searchRequestOptions.ClientRequestId;
 1955            }
 381956            AutocompleteMode autocompleteMode = default(AutocompleteMode);
 381957            if (autocompleteParameters != null)
 1958            {
 321959                autocompleteMode = autocompleteParameters.AutocompleteMode;
 1960            }
 381961            string filter = default(string);
 381962            if (autocompleteParameters != null)
 1963            {
 321964                filter = autocompleteParameters.Filter;
 1965            }
 381966            bool? useFuzzyMatching = default(bool?);
 381967            if (autocompleteParameters != null)
 1968            {
 321969                useFuzzyMatching = autocompleteParameters.UseFuzzyMatching;
 1970            }
 381971            string highlightPostTag = default(string);
 381972            if (autocompleteParameters != null)
 1973            {
 321974                highlightPostTag = autocompleteParameters.HighlightPostTag;
 1975            }
 381976            string highlightPreTag = default(string);
 381977            if (autocompleteParameters != null)
 1978            {
 321979                highlightPreTag = autocompleteParameters.HighlightPreTag;
 1980            }
 381981            double? minimumCoverage = default(double?);
 381982            if (autocompleteParameters != null)
 1983            {
 321984                minimumCoverage = autocompleteParameters.MinimumCoverage;
 1985            }
 381986            IList<string> searchFields = default(IList<string>);
 381987            if (autocompleteParameters != null)
 1988            {
 321989                searchFields = autocompleteParameters.SearchFields;
 1990            }
 381991            int? top = default(int?);
 381992            if (autocompleteParameters != null)
 1993            {
 321994                top = autocompleteParameters.Top;
 1995            }
 1996            // Tracing
 381997            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 381998            string _invocationId = null;
 381999            if (_shouldTrace)
 2000            {
 02001                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02002                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02003                tracingParameters.Add("searchText", searchText);
 02004                tracingParameters.Add("suggesterName", suggesterName);
 02005                tracingParameters.Add("clientRequestId", clientRequestId);
 02006                tracingParameters.Add("autocompleteMode", autocompleteMode);
 02007                tracingParameters.Add("filter", filter);
 02008                tracingParameters.Add("useFuzzyMatching", useFuzzyMatching);
 02009                tracingParameters.Add("highlightPostTag", highlightPostTag);
 02010                tracingParameters.Add("highlightPreTag", highlightPreTag);
 02011                tracingParameters.Add("minimumCoverage", minimumCoverage);
 02012                tracingParameters.Add("searchFields", searchFields);
 02013                tracingParameters.Add("top", top);
 02014                tracingParameters.Add("cancellationToken", cancellationToken);
 02015                ServiceClientTracing.Enter(_invocationId, this, "AutocompleteGet", tracingParameters);
 2016            }
 2017            // Construct URL
 382018            var _baseUrl = Client.BaseUri;
 382019            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/search.autocomplete";
 382020            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 382021            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 382022            _url = _url.Replace("{indexName}", Client.IndexName);
 382023            List<string> _queryParameters = new List<string>();
 382024            if (Client.ApiVersion != null)
 2025            {
 382026                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2027            }
 382028            if (searchText != null)
 2029            {
 382030                _queryParameters.Add(string.Format("search={0}", System.Uri.EscapeDataString(searchText)));
 2031            }
 382032            if (suggesterName != null)
 2033            {
 382034                _queryParameters.Add(string.Format("suggesterName={0}", System.Uri.EscapeDataString(suggesterName)));
 2035            }
 382036            _queryParameters.Add(string.Format("autocompleteMode={0}", System.Uri.EscapeDataString(Rest.Serialization.Sa
 382037            if (filter != null)
 2038            {
 82039                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 2040            }
 382041            if (useFuzzyMatching != null)
 2042            {
 102043                _queryParameters.Add(string.Format("fuzzy={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC
 2044            }
 382045            if (highlightPostTag != null)
 2046            {
 22047                _queryParameters.Add(string.Format("highlightPostTag={0}", System.Uri.EscapeDataString(highlightPostTag)
 2048            }
 382049            if (highlightPreTag != null)
 2050            {
 22051                _queryParameters.Add(string.Format("highlightPreTag={0}", System.Uri.EscapeDataString(highlightPreTag)))
 2052            }
 382053            if (minimumCoverage != null)
 2054            {
 02055                _queryParameters.Add(string.Format("minimumCoverage={0}", System.Uri.EscapeDataString(Rest.Serialization
 2056            }
 382057            if (searchFields != null)
 2058            {
 62059                _queryParameters.Add(string.Format("searchFields={0}", System.Uri.EscapeDataString(string.Join(",", sear
 2060            }
 382061            if (top != null)
 2062            {
 22063                _queryParameters.Add(string.Format("$top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 2064            }
 382065            if (_queryParameters.Count > 0)
 2066            {
 382067                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2068            }
 2069            // Create HTTP transport objects
 382070            var _httpRequest = new HttpRequestMessage();
 382071            HttpResponseMessage _httpResponse = null;
 382072            _httpRequest.Method = new HttpMethod("GET");
 382073            _httpRequest.RequestUri = new System.Uri(_url);
 2074            // Set Headers
 382075            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2076            {
 382077                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2078            }
 382079            if (Client.AcceptLanguage != null)
 2080            {
 382081                if (_httpRequest.Headers.Contains("accept-language"))
 2082                {
 02083                    _httpRequest.Headers.Remove("accept-language");
 2084                }
 382085                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2086            }
 382087            if (clientRequestId != null)
 2088            {
 02089                if (_httpRequest.Headers.Contains("client-request-id"))
 2090                {
 02091                    _httpRequest.Headers.Remove("client-request-id");
 2092                }
 02093                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 2094            }
 2095
 2096
 382097            if (customHeaders != null)
 2098            {
 02099                foreach(var _header in customHeaders)
 2100                {
 02101                    if (_httpRequest.Headers.Contains(_header.Key))
 2102                    {
 02103                        _httpRequest.Headers.Remove(_header.Key);
 2104                    }
 02105                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2106                }
 2107            }
 2108
 2109            // Serialize Request
 382110            string _requestContent = null;
 2111            // Set Credentials
 382112            if (Client.Credentials != null)
 2113            {
 382114                cancellationToken.ThrowIfCancellationRequested();
 382115                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2116            }
 2117            // Send Request
 382118            if (_shouldTrace)
 2119            {
 02120                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2121            }
 382122            cancellationToken.ThrowIfCancellationRequested();
 382123            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 382124            if (_shouldTrace)
 2125            {
 02126                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2127            }
 382128            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 382129            cancellationToken.ThrowIfCancellationRequested();
 382130            string _responseContent = null;
 382131            if ((int)_statusCode != 200)
 2132            {
 42133                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2134                try
 2135                {
 42136                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 42137                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 42138                    if (_errorBody != null)
 2139                    {
 42140                        ex = new CloudException(_errorBody.Message);
 42141                        ex.Body = _errorBody;
 2142                    }
 42143                }
 02144                catch (JsonException)
 2145                {
 2146                    // Ignore the exception
 02147                }
 42148                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 42149                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 42150                if (_httpResponse.Headers.Contains("request-id"))
 2151                {
 42152                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2153                }
 42154                if (_shouldTrace)
 2155                {
 02156                    ServiceClientTracing.Error(_invocationId, ex);
 2157                }
 42158                _httpRequest.Dispose();
 42159                if (_httpResponse != null)
 2160                {
 42161                    _httpResponse.Dispose();
 2162                }
 42163                throw ex;
 2164            }
 2165            // Create Result
 342166            var _result = new AzureOperationResponse<AutocompleteResult>();
 342167            _result.Request = _httpRequest;
 342168            _result.Response = _httpResponse;
 342169            if (_httpResponse.Headers.Contains("request-id"))
 2170            {
 342171                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2172            }
 2173            // Deserialize Response
 342174            if ((int)_statusCode == 200)
 2175            {
 342176                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2177                try
 2178                {
 342179                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AutocompleteResult>(_responseCon
 342180                }
 02181                catch (JsonException ex)
 2182                {
 02183                    _httpRequest.Dispose();
 02184                    if (_httpResponse != null)
 2185                    {
 02186                        _httpResponse.Dispose();
 2187                    }
 02188                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2189                }
 2190            }
 342191            if (_shouldTrace)
 2192            {
 02193                ServiceClientTracing.Exit(_invocationId, _result);
 2194            }
 342195            return _result;
 342196        }
 2197
 2198        /// <summary>
 2199        /// Autocompletes incomplete query terms based on input text and matching terms
 2200        /// in the index.
 2201        /// <see href="https://docs.microsoft.com/rest/api/searchservice/autocomplete" />
 2202        /// </summary>
 2203        /// <param name='autocompleteRequest'>
 2204        /// The definition of the Autocomplete request.
 2205        /// </param>
 2206        /// <param name='searchRequestOptions'>
 2207        /// Additional parameters for the operation
 2208        /// </param>
 2209        /// <param name='customHeaders'>
 2210        /// Headers that will be added to request.
 2211        /// </param>
 2212        /// <param name='cancellationToken'>
 2213        /// The cancellation token.
 2214        /// </param>
 2215        /// <exception cref="CloudException">
 2216        /// Thrown when the operation returned an invalid status code
 2217        /// </exception>
 2218        /// <exception cref="SerializationException">
 2219        /// Thrown when unable to deserialize the response
 2220        /// </exception>
 2221        /// <exception cref="ValidationException">
 2222        /// Thrown when a required parameter is null
 2223        /// </exception>
 2224        /// <exception cref="System.ArgumentNullException">
 2225        /// Thrown when a required parameter is null
 2226        /// </exception>
 2227        /// <return>
 2228        /// A response object containing the response body and response headers.
 2229        /// </return>
 2230        public async Task<AzureOperationResponse<AutocompleteResult>> AutocompletePostWithHttpMessagesAsync(Autocomplete
 2231        {
 382232            if (Client.SearchServiceName == null)
 2233            {
 02234                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchServiceName");
 2235            }
 382236            if (Client.SearchDnsSuffix == null)
 2237            {
 02238                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SearchDnsSuffix");
 2239            }
 382240            if (Client.IndexName == null)
 2241            {
 02242                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.IndexName");
 2243            }
 382244            if (Client.ApiVersion == null)
 2245            {
 02246                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2247            }
 382248            if (autocompleteRequest == null)
 2249            {
 02250                throw new ValidationException(ValidationRules.CannotBeNull, "autocompleteRequest");
 2251            }
 382252            System.Guid? clientRequestId = default(System.Guid?);
 382253            if (searchRequestOptions != null)
 2254            {
 02255                clientRequestId = searchRequestOptions.ClientRequestId;
 2256            }
 2257            // Tracing
 382258            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 382259            string _invocationId = null;
 382260            if (_shouldTrace)
 2261            {
 02262                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02263                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02264                tracingParameters.Add("autocompleteRequest", autocompleteRequest);
 02265                tracingParameters.Add("clientRequestId", clientRequestId);
 02266                tracingParameters.Add("cancellationToken", cancellationToken);
 02267                ServiceClientTracing.Enter(_invocationId, this, "AutocompletePost", tracingParameters);
 2268            }
 2269            // Construct URL
 382270            var _baseUrl = Client.BaseUri;
 382271            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "docs/search.post.autocomplete";
 382272            _url = _url.Replace("{searchServiceName}", Client.SearchServiceName);
 382273            _url = _url.Replace("{searchDnsSuffix}", Client.SearchDnsSuffix);
 382274            _url = _url.Replace("{indexName}", Client.IndexName);
 382275            List<string> _queryParameters = new List<string>();
 382276            if (Client.ApiVersion != null)
 2277            {
 382278                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2279            }
 382280            if (_queryParameters.Count > 0)
 2281            {
 382282                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2283            }
 2284            // Create HTTP transport objects
 382285            var _httpRequest = new HttpRequestMessage();
 382286            HttpResponseMessage _httpResponse = null;
 382287            _httpRequest.Method = new HttpMethod("POST");
 382288            _httpRequest.RequestUri = new System.Uri(_url);
 2289            // Set Headers
 382290            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2291            {
 382292                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2293            }
 382294            if (Client.AcceptLanguage != null)
 2295            {
 382296                if (_httpRequest.Headers.Contains("accept-language"))
 2297                {
 02298                    _httpRequest.Headers.Remove("accept-language");
 2299                }
 382300                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2301            }
 382302            if (clientRequestId != null)
 2303            {
 02304                if (_httpRequest.Headers.Contains("client-request-id"))
 2305                {
 02306                    _httpRequest.Headers.Remove("client-request-id");
 2307                }
 02308                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", Rest.Serialization.SafeJsonConvert.Ser
 2309            }
 2310
 2311
 382312            if (customHeaders != null)
 2313            {
 02314                foreach(var _header in customHeaders)
 2315                {
 02316                    if (_httpRequest.Headers.Contains(_header.Key))
 2317                    {
 02318                        _httpRequest.Headers.Remove(_header.Key);
 2319                    }
 02320                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2321                }
 2322            }
 2323
 2324            // Serialize Request
 382325            string _requestContent = null;
 382326            if(autocompleteRequest != null)
 2327            {
 382328                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(autocompleteRequest, requestSeriali
 382329                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 382330                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2331            }
 2332            // Set Credentials
 382333            if (Client.Credentials != null)
 2334            {
 382335                cancellationToken.ThrowIfCancellationRequested();
 382336                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2337            }
 2338            // Send Request
 382339            if (_shouldTrace)
 2340            {
 02341                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2342            }
 382343            cancellationToken.ThrowIfCancellationRequested();
 382344            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 382345            if (_shouldTrace)
 2346            {
 02347                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2348            }
 382349            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 382350            cancellationToken.ThrowIfCancellationRequested();
 382351            string _responseContent = null;
 382352            if ((int)_statusCode != 200)
 2353            {
 42354                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 2355                try
 2356                {
 42357                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 42358                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 42359                    if (_errorBody != null)
 2360                    {
 42361                        ex = new CloudException(_errorBody.Message);
 42362                        ex.Body = _errorBody;
 2363                    }
 42364                }
 02365                catch (JsonException)
 2366                {
 2367                    // Ignore the exception
 02368                }
 42369                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 42370                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 42371                if (_httpResponse.Headers.Contains("request-id"))
 2372                {
 42373                    ex.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2374                }
 42375                if (_shouldTrace)
 2376                {
 02377                    ServiceClientTracing.Error(_invocationId, ex);
 2378                }
 42379                _httpRequest.Dispose();
 42380                if (_httpResponse != null)
 2381                {
 42382                    _httpResponse.Dispose();
 2383                }
 42384                throw ex;
 2385            }
 2386            // Create Result
 342387            var _result = new AzureOperationResponse<AutocompleteResult>();
 342388            _result.Request = _httpRequest;
 342389            _result.Response = _httpResponse;
 342390            if (_httpResponse.Headers.Contains("request-id"))
 2391            {
 342392                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2393            }
 2394            // Deserialize Response
 342395            if ((int)_statusCode == 200)
 2396            {
 342397                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2398                try
 2399                {
 342400                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<AutocompleteResult>(_responseCon
 342401                }
 02402                catch (JsonException ex)
 2403                {
 02404                    _httpRequest.Dispose();
 02405                    if (_httpResponse != null)
 2406                    {
 02407                        _httpResponse.Dispose();
 2408                    }
 02409                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2410                }
 2411            }
 342412            if (_shouldTrace)
 2413            {
 02414                ServiceClientTracing.Exit(_invocationId, _result);
 2415            }
 342416            return _result;
 342417        }
 2418
 2419    }
 2420}