< Summary

Class:Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker.Knowledgebase
Assembly:Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\Knowledgebase.cs
Covered lines:0
Uncovered lines:575
Coverable lines:575
Total lines:1270
Line coverage:0% (0 of 575)
Covered branches:0
Total branches:278
Branch coverage:0% (0 of 278)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
get_Client()-0%100%
ListAllWithHttpMessagesAsync()-0%0%
GetDetailsWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-0%0%
PublishWithHttpMessagesAsync()-0%0%
ReplaceWithHttpMessagesAsync()-0%0%
UpdateWithHttpMessagesAsync()-0%0%
CreateWithHttpMessagesAsync()-0%0%
DownloadWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\Knowledgebase.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.CognitiveServices.Knowledge.QnAMaker
 12{
 13    using Microsoft.Rest;
 14    using Models;
 15    using Newtonsoft.Json;
 16    using System.Collections;
 17    using System.Collections.Generic;
 18    using System.IO;
 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    /// Knowledgebase operations.
 27    /// </summary>
 28    public partial class Knowledgebase : IServiceOperations<QnAMakerClient>, IKnowledgebase
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Knowledgebase 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>
 039        public Knowledgebase(QnAMakerClient client)
 40        {
 041            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 045            Client = client;
 046        }
 47
 48        /// <summary>
 49        /// Gets a reference to the QnAMakerClient
 50        /// </summary>
 051        public QnAMakerClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Gets all knowledgebases for a user.
 55        /// </summary>
 56        /// <param name='customHeaders'>
 57        /// Headers that will be added to request.
 58        /// </param>
 59        /// <param name='cancellationToken'>
 60        /// The cancellation token.
 61        /// </param>
 62        /// <exception cref="ErrorResponseException">
 63        /// Thrown when the operation returned an invalid status code
 64        /// </exception>
 65        /// <exception cref="SerializationException">
 66        /// Thrown when unable to deserialize the response
 67        /// </exception>
 68        /// <exception cref="ValidationException">
 69        /// Thrown when a required parameter is null
 70        /// </exception>
 71        /// <exception cref="System.ArgumentNullException">
 72        /// Thrown when a required parameter is null
 73        /// </exception>
 74        /// <return>
 75        /// A response object containing the response body and response headers.
 76        /// </return>
 77        public async Task<HttpOperationResponse<KnowledgebasesDTO>> ListAllWithHttpMessagesAsync(Dictionary<string, List
 78        {
 079            if (Client.Endpoint == null)
 80            {
 081                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 82            }
 83            // Tracing
 084            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 085            string _invocationId = null;
 086            if (_shouldTrace)
 87            {
 088                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 089                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 090                tracingParameters.Add("cancellationToken", cancellationToken);
 091                ServiceClientTracing.Enter(_invocationId, this, "ListAll", tracingParameters);
 92            }
 93            // Construct URL
 094            var _baseUrl = Client.BaseUri;
 095            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases";
 096            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 97            // Create HTTP transport objects
 098            var _httpRequest = new HttpRequestMessage();
 099            HttpResponseMessage _httpResponse = null;
 0100            _httpRequest.Method = new HttpMethod("GET");
 0101            _httpRequest.RequestUri = new System.Uri(_url);
 102            // Set Headers
 103
 104
 0105            if (customHeaders != null)
 106            {
 0107                foreach(var _header in customHeaders)
 108                {
 0109                    if (_httpRequest.Headers.Contains(_header.Key))
 110                    {
 0111                        _httpRequest.Headers.Remove(_header.Key);
 112                    }
 0113                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 114                }
 115            }
 116
 117            // Serialize Request
 0118            string _requestContent = null;
 119            // Set Credentials
 0120            if (Client.Credentials != null)
 121            {
 0122                cancellationToken.ThrowIfCancellationRequested();
 0123                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 124            }
 125            // Send Request
 0126            if (_shouldTrace)
 127            {
 0128                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 129            }
 0130            cancellationToken.ThrowIfCancellationRequested();
 0131            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0132            if (_shouldTrace)
 133            {
 0134                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 135            }
 0136            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0137            cancellationToken.ThrowIfCancellationRequested();
 0138            string _responseContent = null;
 0139            if ((int)_statusCode != 200)
 140            {
 0141                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 142                try
 143                {
 0144                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0145                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0146                    if (_errorBody != null)
 147                    {
 0148                        ex.Body = _errorBody;
 149                    }
 0150                }
 0151                catch (JsonException)
 152                {
 153                    // Ignore the exception
 0154                }
 0155                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0156                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0157                if (_shouldTrace)
 158                {
 0159                    ServiceClientTracing.Error(_invocationId, ex);
 160                }
 0161                _httpRequest.Dispose();
 0162                if (_httpResponse != null)
 163                {
 0164                    _httpResponse.Dispose();
 165                }
 0166                throw ex;
 167            }
 168            // Create Result
 0169            var _result = new HttpOperationResponse<KnowledgebasesDTO>();
 0170            _result.Request = _httpRequest;
 0171            _result.Response = _httpResponse;
 172            // Deserialize Response
 0173            if ((int)_statusCode == 200)
 174            {
 0175                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 176                try
 177                {
 0178                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<KnowledgebasesDTO>(_responseCont
 0179                }
 0180                catch (JsonException ex)
 181                {
 0182                    _httpRequest.Dispose();
 0183                    if (_httpResponse != null)
 184                    {
 0185                        _httpResponse.Dispose();
 186                    }
 0187                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 188                }
 189            }
 0190            if (_shouldTrace)
 191            {
 0192                ServiceClientTracing.Exit(_invocationId, _result);
 193            }
 0194            return _result;
 0195        }
 196
 197        /// <summary>
 198        /// Gets details of a specific knowledgebase.
 199        /// </summary>
 200        /// <param name='kbId'>
 201        /// Knowledgebase id.
 202        /// </param>
 203        /// <param name='customHeaders'>
 204        /// Headers that will be added to request.
 205        /// </param>
 206        /// <param name='cancellationToken'>
 207        /// The cancellation token.
 208        /// </param>
 209        /// <exception cref="ErrorResponseException">
 210        /// Thrown when the operation returned an invalid status code
 211        /// </exception>
 212        /// <exception cref="SerializationException">
 213        /// Thrown when unable to deserialize the response
 214        /// </exception>
 215        /// <exception cref="ValidationException">
 216        /// Thrown when a required parameter is null
 217        /// </exception>
 218        /// <exception cref="System.ArgumentNullException">
 219        /// Thrown when a required parameter is null
 220        /// </exception>
 221        /// <return>
 222        /// A response object containing the response body and response headers.
 223        /// </return>
 224        public async Task<HttpOperationResponse<KnowledgebaseDTO>> GetDetailsWithHttpMessagesAsync(string kbId, Dictiona
 225        {
 0226            if (Client.Endpoint == null)
 227            {
 0228                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 229            }
 0230            if (kbId == null)
 231            {
 0232                throw new ValidationException(ValidationRules.CannotBeNull, "kbId");
 233            }
 234            // Tracing
 0235            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0236            string _invocationId = null;
 0237            if (_shouldTrace)
 238            {
 0239                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0240                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0241                tracingParameters.Add("kbId", kbId);
 0242                tracingParameters.Add("cancellationToken", cancellationToken);
 0243                ServiceClientTracing.Enter(_invocationId, this, "GetDetails", tracingParameters);
 244            }
 245            // Construct URL
 0246            var _baseUrl = Client.BaseUri;
 0247            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}";
 0248            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0249            _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId));
 250            // Create HTTP transport objects
 0251            var _httpRequest = new HttpRequestMessage();
 0252            HttpResponseMessage _httpResponse = null;
 0253            _httpRequest.Method = new HttpMethod("GET");
 0254            _httpRequest.RequestUri = new System.Uri(_url);
 255            // Set Headers
 256
 257
 0258            if (customHeaders != null)
 259            {
 0260                foreach(var _header in customHeaders)
 261                {
 0262                    if (_httpRequest.Headers.Contains(_header.Key))
 263                    {
 0264                        _httpRequest.Headers.Remove(_header.Key);
 265                    }
 0266                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 267                }
 268            }
 269
 270            // Serialize Request
 0271            string _requestContent = null;
 272            // Set Credentials
 0273            if (Client.Credentials != null)
 274            {
 0275                cancellationToken.ThrowIfCancellationRequested();
 0276                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 277            }
 278            // Send Request
 0279            if (_shouldTrace)
 280            {
 0281                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 282            }
 0283            cancellationToken.ThrowIfCancellationRequested();
 0284            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0285            if (_shouldTrace)
 286            {
 0287                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 288            }
 0289            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0290            cancellationToken.ThrowIfCancellationRequested();
 0291            string _responseContent = null;
 0292            if ((int)_statusCode != 200)
 293            {
 0294                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 295                try
 296                {
 0297                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0298                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0299                    if (_errorBody != null)
 300                    {
 0301                        ex.Body = _errorBody;
 302                    }
 0303                }
 0304                catch (JsonException)
 305                {
 306                    // Ignore the exception
 0307                }
 0308                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0309                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0310                if (_shouldTrace)
 311                {
 0312                    ServiceClientTracing.Error(_invocationId, ex);
 313                }
 0314                _httpRequest.Dispose();
 0315                if (_httpResponse != null)
 316                {
 0317                    _httpResponse.Dispose();
 318                }
 0319                throw ex;
 320            }
 321            // Create Result
 0322            var _result = new HttpOperationResponse<KnowledgebaseDTO>();
 0323            _result.Request = _httpRequest;
 0324            _result.Response = _httpResponse;
 325            // Deserialize Response
 0326            if ((int)_statusCode == 200)
 327            {
 0328                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 329                try
 330                {
 0331                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<KnowledgebaseDTO>(_responseConte
 0332                }
 0333                catch (JsonException ex)
 334                {
 0335                    _httpRequest.Dispose();
 0336                    if (_httpResponse != null)
 337                    {
 0338                        _httpResponse.Dispose();
 339                    }
 0340                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 341                }
 342            }
 0343            if (_shouldTrace)
 344            {
 0345                ServiceClientTracing.Exit(_invocationId, _result);
 346            }
 0347            return _result;
 0348        }
 349
 350        /// <summary>
 351        /// Deletes the knowledgebase and all its data.
 352        /// </summary>
 353        /// <param name='kbId'>
 354        /// Knowledgebase id.
 355        /// </param>
 356        /// <param name='customHeaders'>
 357        /// Headers that will be added to request.
 358        /// </param>
 359        /// <param name='cancellationToken'>
 360        /// The cancellation token.
 361        /// </param>
 362        /// <exception cref="ErrorResponseException">
 363        /// Thrown when the operation returned an invalid status code
 364        /// </exception>
 365        /// <exception cref="ValidationException">
 366        /// Thrown when a required parameter is null
 367        /// </exception>
 368        /// <exception cref="System.ArgumentNullException">
 369        /// Thrown when a required parameter is null
 370        /// </exception>
 371        /// <return>
 372        /// A response object containing the response body and response headers.
 373        /// </return>
 374        public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string kbId, Dictionary<string, List<string
 375        {
 0376            if (Client.Endpoint == null)
 377            {
 0378                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 379            }
 0380            if (kbId == null)
 381            {
 0382                throw new ValidationException(ValidationRules.CannotBeNull, "kbId");
 383            }
 384            // Tracing
 0385            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0386            string _invocationId = null;
 0387            if (_shouldTrace)
 388            {
 0389                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0390                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0391                tracingParameters.Add("kbId", kbId);
 0392                tracingParameters.Add("cancellationToken", cancellationToken);
 0393                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 394            }
 395            // Construct URL
 0396            var _baseUrl = Client.BaseUri;
 0397            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}";
 0398            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0399            _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId));
 400            // Create HTTP transport objects
 0401            var _httpRequest = new HttpRequestMessage();
 0402            HttpResponseMessage _httpResponse = null;
 0403            _httpRequest.Method = new HttpMethod("DELETE");
 0404            _httpRequest.RequestUri = new System.Uri(_url);
 405            // Set Headers
 406
 407
 0408            if (customHeaders != null)
 409            {
 0410                foreach(var _header in customHeaders)
 411                {
 0412                    if (_httpRequest.Headers.Contains(_header.Key))
 413                    {
 0414                        _httpRequest.Headers.Remove(_header.Key);
 415                    }
 0416                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 417                }
 418            }
 419
 420            // Serialize Request
 0421            string _requestContent = null;
 422            // Set Credentials
 0423            if (Client.Credentials != null)
 424            {
 0425                cancellationToken.ThrowIfCancellationRequested();
 0426                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 427            }
 428            // Send Request
 0429            if (_shouldTrace)
 430            {
 0431                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 432            }
 0433            cancellationToken.ThrowIfCancellationRequested();
 0434            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0435            if (_shouldTrace)
 436            {
 0437                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 438            }
 0439            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0440            cancellationToken.ThrowIfCancellationRequested();
 0441            string _responseContent = null;
 0442            if ((int)_statusCode != 204)
 443            {
 0444                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 445                try
 446                {
 0447                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0448                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0449                    if (_errorBody != null)
 450                    {
 0451                        ex.Body = _errorBody;
 452                    }
 0453                }
 0454                catch (JsonException)
 455                {
 456                    // Ignore the exception
 0457                }
 0458                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0459                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0460                if (_shouldTrace)
 461                {
 0462                    ServiceClientTracing.Error(_invocationId, ex);
 463                }
 0464                _httpRequest.Dispose();
 0465                if (_httpResponse != null)
 466                {
 0467                    _httpResponse.Dispose();
 468                }
 0469                throw ex;
 470            }
 471            // Create Result
 0472            var _result = new HttpOperationResponse();
 0473            _result.Request = _httpRequest;
 0474            _result.Response = _httpResponse;
 0475            if (_shouldTrace)
 476            {
 0477                ServiceClientTracing.Exit(_invocationId, _result);
 478            }
 0479            return _result;
 0480        }
 481
 482        /// <summary>
 483        /// Publishes all changes in test index of a knowledgebase to its prod index.
 484        /// </summary>
 485        /// <param name='kbId'>
 486        /// Knowledgebase id.
 487        /// </param>
 488        /// <param name='customHeaders'>
 489        /// Headers that will be added to request.
 490        /// </param>
 491        /// <param name='cancellationToken'>
 492        /// The cancellation token.
 493        /// </param>
 494        /// <exception cref="ErrorResponseException">
 495        /// Thrown when the operation returned an invalid status code
 496        /// </exception>
 497        /// <exception cref="ValidationException">
 498        /// Thrown when a required parameter is null
 499        /// </exception>
 500        /// <exception cref="System.ArgumentNullException">
 501        /// Thrown when a required parameter is null
 502        /// </exception>
 503        /// <return>
 504        /// A response object containing the response body and response headers.
 505        /// </return>
 506        public async Task<HttpOperationResponse> PublishWithHttpMessagesAsync(string kbId, Dictionary<string, List<strin
 507        {
 0508            if (Client.Endpoint == null)
 509            {
 0510                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 511            }
 0512            if (kbId == null)
 513            {
 0514                throw new ValidationException(ValidationRules.CannotBeNull, "kbId");
 515            }
 516            // Tracing
 0517            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0518            string _invocationId = null;
 0519            if (_shouldTrace)
 520            {
 0521                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0522                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0523                tracingParameters.Add("kbId", kbId);
 0524                tracingParameters.Add("cancellationToken", cancellationToken);
 0525                ServiceClientTracing.Enter(_invocationId, this, "Publish", tracingParameters);
 526            }
 527            // Construct URL
 0528            var _baseUrl = Client.BaseUri;
 0529            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}";
 0530            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0531            _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId));
 532            // Create HTTP transport objects
 0533            var _httpRequest = new HttpRequestMessage();
 0534            HttpResponseMessage _httpResponse = null;
 0535            _httpRequest.Method = new HttpMethod("POST");
 0536            _httpRequest.RequestUri = new System.Uri(_url);
 537            // Set Headers
 538
 539
 0540            if (customHeaders != null)
 541            {
 0542                foreach(var _header in customHeaders)
 543                {
 0544                    if (_httpRequest.Headers.Contains(_header.Key))
 545                    {
 0546                        _httpRequest.Headers.Remove(_header.Key);
 547                    }
 0548                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 549                }
 550            }
 551
 552            // Serialize Request
 0553            string _requestContent = null;
 554            // Set Credentials
 0555            if (Client.Credentials != null)
 556            {
 0557                cancellationToken.ThrowIfCancellationRequested();
 0558                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 559            }
 560            // Send Request
 0561            if (_shouldTrace)
 562            {
 0563                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 564            }
 0565            cancellationToken.ThrowIfCancellationRequested();
 0566            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0567            if (_shouldTrace)
 568            {
 0569                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 570            }
 0571            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0572            cancellationToken.ThrowIfCancellationRequested();
 0573            string _responseContent = null;
 0574            if ((int)_statusCode != 204)
 575            {
 0576                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 577                try
 578                {
 0579                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0580                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0581                    if (_errorBody != null)
 582                    {
 0583                        ex.Body = _errorBody;
 584                    }
 0585                }
 0586                catch (JsonException)
 587                {
 588                    // Ignore the exception
 0589                }
 0590                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0591                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0592                if (_shouldTrace)
 593                {
 0594                    ServiceClientTracing.Error(_invocationId, ex);
 595                }
 0596                _httpRequest.Dispose();
 0597                if (_httpResponse != null)
 598                {
 0599                    _httpResponse.Dispose();
 600                }
 0601                throw ex;
 602            }
 603            // Create Result
 0604            var _result = new HttpOperationResponse();
 0605            _result.Request = _httpRequest;
 0606            _result.Response = _httpResponse;
 0607            if (_shouldTrace)
 608            {
 0609                ServiceClientTracing.Exit(_invocationId, _result);
 610            }
 0611            return _result;
 0612        }
 613
 614        /// <summary>
 615        /// Replace knowledgebase contents.
 616        /// </summary>
 617        /// <param name='kbId'>
 618        /// Knowledgebase id.
 619        /// </param>
 620        /// <param name='replaceKb'>
 621        /// An instance of ReplaceKbDTO which contains list of qnas to be uploaded
 622        /// </param>
 623        /// <param name='customHeaders'>
 624        /// Headers that will be added to request.
 625        /// </param>
 626        /// <param name='cancellationToken'>
 627        /// The cancellation token.
 628        /// </param>
 629        /// <exception cref="ErrorResponseException">
 630        /// Thrown when the operation returned an invalid status code
 631        /// </exception>
 632        /// <exception cref="ValidationException">
 633        /// Thrown when a required parameter is null
 634        /// </exception>
 635        /// <exception cref="System.ArgumentNullException">
 636        /// Thrown when a required parameter is null
 637        /// </exception>
 638        /// <return>
 639        /// A response object containing the response body and response headers.
 640        /// </return>
 641        public async Task<HttpOperationResponse> ReplaceWithHttpMessagesAsync(string kbId, ReplaceKbDTO replaceKb, Dicti
 642        {
 0643            if (Client.Endpoint == null)
 644            {
 0645                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 646            }
 0647            if (kbId == null)
 648            {
 0649                throw new ValidationException(ValidationRules.CannotBeNull, "kbId");
 650            }
 0651            if (replaceKb == null)
 652            {
 0653                throw new ValidationException(ValidationRules.CannotBeNull, "replaceKb");
 654            }
 0655            if (replaceKb != null)
 656            {
 0657                replaceKb.Validate();
 658            }
 659            // Tracing
 0660            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0661            string _invocationId = null;
 0662            if (_shouldTrace)
 663            {
 0664                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0665                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0666                tracingParameters.Add("kbId", kbId);
 0667                tracingParameters.Add("replaceKb", replaceKb);
 0668                tracingParameters.Add("cancellationToken", cancellationToken);
 0669                ServiceClientTracing.Enter(_invocationId, this, "Replace", tracingParameters);
 670            }
 671            // Construct URL
 0672            var _baseUrl = Client.BaseUri;
 0673            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}";
 0674            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0675            _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId));
 676            // Create HTTP transport objects
 0677            var _httpRequest = new HttpRequestMessage();
 0678            HttpResponseMessage _httpResponse = null;
 0679            _httpRequest.Method = new HttpMethod("PUT");
 0680            _httpRequest.RequestUri = new System.Uri(_url);
 681            // Set Headers
 682
 683
 0684            if (customHeaders != null)
 685            {
 0686                foreach(var _header in customHeaders)
 687                {
 0688                    if (_httpRequest.Headers.Contains(_header.Key))
 689                    {
 0690                        _httpRequest.Headers.Remove(_header.Key);
 691                    }
 0692                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 693                }
 694            }
 695
 696            // Serialize Request
 0697            string _requestContent = null;
 0698            if(replaceKb != null)
 699            {
 0700                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(replaceKb, Client.SerializationSett
 0701                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0702                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 703            }
 704            // Set Credentials
 0705            if (Client.Credentials != null)
 706            {
 0707                cancellationToken.ThrowIfCancellationRequested();
 0708                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 709            }
 710            // Send Request
 0711            if (_shouldTrace)
 712            {
 0713                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 714            }
 0715            cancellationToken.ThrowIfCancellationRequested();
 0716            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0717            if (_shouldTrace)
 718            {
 0719                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 720            }
 0721            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0722            cancellationToken.ThrowIfCancellationRequested();
 0723            string _responseContent = null;
 0724            if ((int)_statusCode != 204)
 725            {
 0726                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 727                try
 728                {
 0729                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0730                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0731                    if (_errorBody != null)
 732                    {
 0733                        ex.Body = _errorBody;
 734                    }
 0735                }
 0736                catch (JsonException)
 737                {
 738                    // Ignore the exception
 0739                }
 0740                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0741                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0742                if (_shouldTrace)
 743                {
 0744                    ServiceClientTracing.Error(_invocationId, ex);
 745                }
 0746                _httpRequest.Dispose();
 0747                if (_httpResponse != null)
 748                {
 0749                    _httpResponse.Dispose();
 750                }
 0751                throw ex;
 752            }
 753            // Create Result
 0754            var _result = new HttpOperationResponse();
 0755            _result.Request = _httpRequest;
 0756            _result.Response = _httpResponse;
 0757            if (_shouldTrace)
 758            {
 0759                ServiceClientTracing.Exit(_invocationId, _result);
 760            }
 0761            return _result;
 0762        }
 763
 764        /// <summary>
 765        /// Asynchronous operation to modify a knowledgebase.
 766        /// </summary>
 767        /// <param name='kbId'>
 768        /// Knowledgebase id.
 769        /// </param>
 770        /// <param name='updateKb'>
 771        /// Post body of the request.
 772        /// </param>
 773        /// <param name='customHeaders'>
 774        /// Headers that will be added to request.
 775        /// </param>
 776        /// <param name='cancellationToken'>
 777        /// The cancellation token.
 778        /// </param>
 779        /// <exception cref="ErrorResponseException">
 780        /// Thrown when the operation returned an invalid status code
 781        /// </exception>
 782        /// <exception cref="SerializationException">
 783        /// Thrown when unable to deserialize the response
 784        /// </exception>
 785        /// <exception cref="ValidationException">
 786        /// Thrown when a required parameter is null
 787        /// </exception>
 788        /// <exception cref="System.ArgumentNullException">
 789        /// Thrown when a required parameter is null
 790        /// </exception>
 791        /// <return>
 792        /// A response object containing the response body and response headers.
 793        /// </return>
 794        public async Task<HttpOperationResponse<Operation,KnowledgebaseUpdateHeaders>> UpdateWithHttpMessagesAsync(strin
 795        {
 0796            if (Client.Endpoint == null)
 797            {
 0798                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 799            }
 0800            if (kbId == null)
 801            {
 0802                throw new ValidationException(ValidationRules.CannotBeNull, "kbId");
 803            }
 0804            if (updateKb == null)
 805            {
 0806                throw new ValidationException(ValidationRules.CannotBeNull, "updateKb");
 807            }
 808            // Tracing
 0809            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0810            string _invocationId = null;
 0811            if (_shouldTrace)
 812            {
 0813                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0814                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0815                tracingParameters.Add("kbId", kbId);
 0816                tracingParameters.Add("updateKb", updateKb);
 0817                tracingParameters.Add("cancellationToken", cancellationToken);
 0818                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 819            }
 820            // Construct URL
 0821            var _baseUrl = Client.BaseUri;
 0822            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}";
 0823            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0824            _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId));
 825            // Create HTTP transport objects
 0826            var _httpRequest = new HttpRequestMessage();
 0827            HttpResponseMessage _httpResponse = null;
 0828            _httpRequest.Method = new HttpMethod("PATCH");
 0829            _httpRequest.RequestUri = new System.Uri(_url);
 830            // Set Headers
 831
 832
 0833            if (customHeaders != null)
 834            {
 0835                foreach(var _header in customHeaders)
 836                {
 0837                    if (_httpRequest.Headers.Contains(_header.Key))
 838                    {
 0839                        _httpRequest.Headers.Remove(_header.Key);
 840                    }
 0841                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 842                }
 843            }
 844
 845            // Serialize Request
 0846            string _requestContent = null;
 0847            if(updateKb != null)
 848            {
 0849                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(updateKb, Client.SerializationSetti
 0850                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0851                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 852            }
 853            // Set Credentials
 0854            if (Client.Credentials != null)
 855            {
 0856                cancellationToken.ThrowIfCancellationRequested();
 0857                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 858            }
 859            // Send Request
 0860            if (_shouldTrace)
 861            {
 0862                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 863            }
 0864            cancellationToken.ThrowIfCancellationRequested();
 0865            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0866            if (_shouldTrace)
 867            {
 0868                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 869            }
 0870            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0871            cancellationToken.ThrowIfCancellationRequested();
 0872            string _responseContent = null;
 0873            if ((int)_statusCode != 202)
 874            {
 0875                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 876                try
 877                {
 0878                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0879                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0880                    if (_errorBody != null)
 881                    {
 0882                        ex.Body = _errorBody;
 883                    }
 0884                }
 0885                catch (JsonException)
 886                {
 887                    // Ignore the exception
 0888                }
 0889                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0890                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0891                if (_shouldTrace)
 892                {
 0893                    ServiceClientTracing.Error(_invocationId, ex);
 894                }
 0895                _httpRequest.Dispose();
 0896                if (_httpResponse != null)
 897                {
 0898                    _httpResponse.Dispose();
 899                }
 0900                throw ex;
 901            }
 902            // Create Result
 0903            var _result = new HttpOperationResponse<Operation,KnowledgebaseUpdateHeaders>();
 0904            _result.Request = _httpRequest;
 0905            _result.Response = _httpResponse;
 906            // Deserialize Response
 0907            if ((int)_statusCode == 202)
 908            {
 0909                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 910                try
 911                {
 0912                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Operation>(_responseContent, Cli
 0913                }
 0914                catch (JsonException ex)
 915                {
 0916                    _httpRequest.Dispose();
 0917                    if (_httpResponse != null)
 918                    {
 0919                        _httpResponse.Dispose();
 920                    }
 0921                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 922                }
 923            }
 924            try
 925            {
 0926                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<KnowledgebaseUpdateHeaders>(JsonSerializer.C
 0927            }
 0928            catch (JsonException ex)
 929            {
 0930                _httpRequest.Dispose();
 0931                if (_httpResponse != null)
 932                {
 0933                    _httpResponse.Dispose();
 934                }
 0935                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 936            }
 0937            if (_shouldTrace)
 938            {
 0939                ServiceClientTracing.Exit(_invocationId, _result);
 940            }
 0941            return _result;
 0942        }
 943
 944        /// <summary>
 945        /// Asynchronous operation to create a new knowledgebase.
 946        /// </summary>
 947        /// <param name='createKbPayload'>
 948        /// Post body of the request.
 949        /// </param>
 950        /// <param name='customHeaders'>
 951        /// Headers that will be added to request.
 952        /// </param>
 953        /// <param name='cancellationToken'>
 954        /// The cancellation token.
 955        /// </param>
 956        /// <exception cref="ErrorResponseException">
 957        /// Thrown when the operation returned an invalid status code
 958        /// </exception>
 959        /// <exception cref="SerializationException">
 960        /// Thrown when unable to deserialize the response
 961        /// </exception>
 962        /// <exception cref="ValidationException">
 963        /// Thrown when a required parameter is null
 964        /// </exception>
 965        /// <exception cref="System.ArgumentNullException">
 966        /// Thrown when a required parameter is null
 967        /// </exception>
 968        /// <return>
 969        /// A response object containing the response body and response headers.
 970        /// </return>
 971        public async Task<HttpOperationResponse<Operation>> CreateWithHttpMessagesAsync(CreateKbDTO createKbPayload, Dic
 972        {
 0973            if (Client.Endpoint == null)
 974            {
 0975                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 976            }
 0977            if (createKbPayload == null)
 978            {
 0979                throw new ValidationException(ValidationRules.CannotBeNull, "createKbPayload");
 980            }
 0981            if (createKbPayload != null)
 982            {
 0983                createKbPayload.Validate();
 984            }
 985            // Tracing
 0986            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0987            string _invocationId = null;
 0988            if (_shouldTrace)
 989            {
 0990                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0991                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0992                tracingParameters.Add("createKbPayload", createKbPayload);
 0993                tracingParameters.Add("cancellationToken", cancellationToken);
 0994                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 995            }
 996            // Construct URL
 0997            var _baseUrl = Client.BaseUri;
 0998            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/create";
 0999            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 1000            // Create HTTP transport objects
 01001            var _httpRequest = new HttpRequestMessage();
 01002            HttpResponseMessage _httpResponse = null;
 01003            _httpRequest.Method = new HttpMethod("POST");
 01004            _httpRequest.RequestUri = new System.Uri(_url);
 1005            // Set Headers
 1006
 1007
 01008            if (customHeaders != null)
 1009            {
 01010                foreach(var _header in customHeaders)
 1011                {
 01012                    if (_httpRequest.Headers.Contains(_header.Key))
 1013                    {
 01014                        _httpRequest.Headers.Remove(_header.Key);
 1015                    }
 01016                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1017                }
 1018            }
 1019
 1020            // Serialize Request
 01021            string _requestContent = null;
 01022            if(createKbPayload != null)
 1023            {
 01024                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(createKbPayload, Client.Serializati
 01025                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01026                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1027            }
 1028            // Set Credentials
 01029            if (Client.Credentials != null)
 1030            {
 01031                cancellationToken.ThrowIfCancellationRequested();
 01032                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1033            }
 1034            // Send Request
 01035            if (_shouldTrace)
 1036            {
 01037                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1038            }
 01039            cancellationToken.ThrowIfCancellationRequested();
 01040            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01041            if (_shouldTrace)
 1042            {
 01043                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1044            }
 01045            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01046            cancellationToken.ThrowIfCancellationRequested();
 01047            string _responseContent = null;
 01048            if ((int)_statusCode != 202)
 1049            {
 01050                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1051                try
 1052                {
 01053                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01054                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01055                    if (_errorBody != null)
 1056                    {
 01057                        ex.Body = _errorBody;
 1058                    }
 01059                }
 01060                catch (JsonException)
 1061                {
 1062                    // Ignore the exception
 01063                }
 01064                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01065                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01066                if (_shouldTrace)
 1067                {
 01068                    ServiceClientTracing.Error(_invocationId, ex);
 1069                }
 01070                _httpRequest.Dispose();
 01071                if (_httpResponse != null)
 1072                {
 01073                    _httpResponse.Dispose();
 1074                }
 01075                throw ex;
 1076            }
 1077            // Create Result
 01078            var _result = new HttpOperationResponse<Operation>();
 01079            _result.Request = _httpRequest;
 01080            _result.Response = _httpResponse;
 1081            // Deserialize Response
 01082            if ((int)_statusCode == 202)
 1083            {
 01084                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1085                try
 1086                {
 01087                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Operation>(_responseContent, Cli
 01088                }
 01089                catch (JsonException ex)
 1090                {
 01091                    _httpRequest.Dispose();
 01092                    if (_httpResponse != null)
 1093                    {
 01094                        _httpResponse.Dispose();
 1095                    }
 01096                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1097                }
 1098            }
 01099            if (_shouldTrace)
 1100            {
 01101                ServiceClientTracing.Exit(_invocationId, _result);
 1102            }
 01103            return _result;
 01104        }
 1105
 1106        /// <summary>
 1107        /// Download the knowledgebase.
 1108        /// </summary>
 1109        /// <param name='kbId'>
 1110        /// Knowledgebase id.
 1111        /// </param>
 1112        /// <param name='environment'>
 1113        /// Specifies whether environment is Test or Prod. Possible values include:
 1114        /// 'Prod', 'Test'
 1115        /// </param>
 1116        /// <param name='customHeaders'>
 1117        /// Headers that will be added to request.
 1118        /// </param>
 1119        /// <param name='cancellationToken'>
 1120        /// The cancellation token.
 1121        /// </param>
 1122        /// <exception cref="ErrorResponseException">
 1123        /// Thrown when the operation returned an invalid status code
 1124        /// </exception>
 1125        /// <exception cref="SerializationException">
 1126        /// Thrown when unable to deserialize the response
 1127        /// </exception>
 1128        /// <exception cref="ValidationException">
 1129        /// Thrown when a required parameter is null
 1130        /// </exception>
 1131        /// <exception cref="System.ArgumentNullException">
 1132        /// Thrown when a required parameter is null
 1133        /// </exception>
 1134        /// <return>
 1135        /// A response object containing the response body and response headers.
 1136        /// </return>
 1137        public async Task<HttpOperationResponse<QnADocumentsDTO>> DownloadWithHttpMessagesAsync(string kbId, string envi
 1138        {
 01139            if (Client.Endpoint == null)
 1140            {
 01141                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1142            }
 01143            if (kbId == null)
 1144            {
 01145                throw new ValidationException(ValidationRules.CannotBeNull, "kbId");
 1146            }
 01147            if (environment == null)
 1148            {
 01149                throw new ValidationException(ValidationRules.CannotBeNull, "environment");
 1150            }
 1151            // Tracing
 01152            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01153            string _invocationId = null;
 01154            if (_shouldTrace)
 1155            {
 01156                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01157                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01158                tracingParameters.Add("kbId", kbId);
 01159                tracingParameters.Add("environment", environment);
 01160                tracingParameters.Add("cancellationToken", cancellationToken);
 01161                ServiceClientTracing.Enter(_invocationId, this, "Download", tracingParameters);
 1162            }
 1163            // Construct URL
 01164            var _baseUrl = Client.BaseUri;
 01165            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "knowledgebases/{kbId}/{environment}/qna";
 01166            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01167            _url = _url.Replace("{kbId}", System.Uri.EscapeDataString(kbId));
 01168            _url = _url.Replace("{environment}", System.Uri.EscapeDataString(environment));
 1169            // Create HTTP transport objects
 01170            var _httpRequest = new HttpRequestMessage();
 01171            HttpResponseMessage _httpResponse = null;
 01172            _httpRequest.Method = new HttpMethod("GET");
 01173            _httpRequest.RequestUri = new System.Uri(_url);
 1174            // Set Headers
 1175
 1176
 01177            if (customHeaders != null)
 1178            {
 01179                foreach(var _header in customHeaders)
 1180                {
 01181                    if (_httpRequest.Headers.Contains(_header.Key))
 1182                    {
 01183                        _httpRequest.Headers.Remove(_header.Key);
 1184                    }
 01185                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1186                }
 1187            }
 1188
 1189            // Serialize Request
 01190            string _requestContent = null;
 1191            // Set Credentials
 01192            if (Client.Credentials != null)
 1193            {
 01194                cancellationToken.ThrowIfCancellationRequested();
 01195                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1196            }
 1197            // Send Request
 01198            if (_shouldTrace)
 1199            {
 01200                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1201            }
 01202            cancellationToken.ThrowIfCancellationRequested();
 01203            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01204            if (_shouldTrace)
 1205            {
 01206                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1207            }
 01208            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01209            cancellationToken.ThrowIfCancellationRequested();
 01210            string _responseContent = null;
 01211            if ((int)_statusCode != 200)
 1212            {
 01213                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1214                try
 1215                {
 01216                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01217                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01218                    if (_errorBody != null)
 1219                    {
 01220                        ex.Body = _errorBody;
 1221                    }
 01222                }
 01223                catch (JsonException)
 1224                {
 1225                    // Ignore the exception
 01226                }
 01227                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01228                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01229                if (_shouldTrace)
 1230                {
 01231                    ServiceClientTracing.Error(_invocationId, ex);
 1232                }
 01233                _httpRequest.Dispose();
 01234                if (_httpResponse != null)
 1235                {
 01236                    _httpResponse.Dispose();
 1237                }
 01238                throw ex;
 1239            }
 1240            // Create Result
 01241            var _result = new HttpOperationResponse<QnADocumentsDTO>();
 01242            _result.Request = _httpRequest;
 01243            _result.Response = _httpResponse;
 1244            // Deserialize Response
 01245            if ((int)_statusCode == 200)
 1246            {
 01247                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1248                try
 1249                {
 01250                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<QnADocumentsDTO>(_responseConten
 01251                }
 01252                catch (JsonException ex)
 1253                {
 01254                    _httpRequest.Dispose();
 01255                    if (_httpResponse != null)
 1256                    {
 01257                        _httpResponse.Dispose();
 1258                    }
 01259                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1260                }
 1261            }
 01262            if (_shouldTrace)
 1263            {
 01264                ServiceClientTracing.Exit(_invocationId, _result);
 1265            }
 01266            return _result;
 01267        }
 1268
 1269    }
 1270}