< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
get_Client()-0%100%
GetSettingsWithHttpMessagesAsync()-0%0%
UpdateSettingsWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\EndpointSettings.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    /// EndpointSettings operations.
 27    /// </summary>
 28    public partial class EndpointSettings : IServiceOperations<QnAMakerClient>, IEndpointSettings
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the EndpointSettings 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 EndpointSettings(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 endpoint settings for an endpoint.
 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<EndpointSettingsDTO>> GetSettingsWithHttpMessagesAsync(Dictionary<string
 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, "GetSettings", tracingParameters);
 92            }
 93            // Construct URL
 094            var _baseUrl = Client.BaseUri;
 095            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "endpointSettings";
 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<EndpointSettingsDTO>();
 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<EndpointSettingsDTO>(_responseCo
 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        /// Updates endpoint settings for an endpoint.
 199        /// </summary>
 200        /// <param name='endpointSettingsPayload'>
 201        /// Post body of the request.
 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<string>> UpdateSettingsWithHttpMessagesAsync(EndpointSettingsDTO endpoin
 225        {
 0226            if (Client.Endpoint == null)
 227            {
 0228                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 229            }
 0230            if (endpointSettingsPayload == null)
 231            {
 0232                throw new ValidationException(ValidationRules.CannotBeNull, "endpointSettingsPayload");
 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("endpointSettingsPayload", endpointSettingsPayload);
 0242                tracingParameters.Add("cancellationToken", cancellationToken);
 0243                ServiceClientTracing.Enter(_invocationId, this, "UpdateSettings", tracingParameters);
 244            }
 245            // Construct URL
 0246            var _baseUrl = Client.BaseUri;
 0247            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "endpointSettings";
 0248            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 249            // Create HTTP transport objects
 0250            var _httpRequest = new HttpRequestMessage();
 0251            HttpResponseMessage _httpResponse = null;
 0252            _httpRequest.Method = new HttpMethod("PATCH");
 0253            _httpRequest.RequestUri = new System.Uri(_url);
 254            // Set Headers
 255
 256
 0257            if (customHeaders != null)
 258            {
 0259                foreach(var _header in customHeaders)
 260                {
 0261                    if (_httpRequest.Headers.Contains(_header.Key))
 262                    {
 0263                        _httpRequest.Headers.Remove(_header.Key);
 264                    }
 0265                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 266                }
 267            }
 268
 269            // Serialize Request
 0270            string _requestContent = null;
 0271            if(endpointSettingsPayload != null)
 272            {
 0273                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(endpointSettingsPayload, Client.Ser
 0274                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0275                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 276            }
 277            // Set Credentials
 0278            if (Client.Credentials != null)
 279            {
 0280                cancellationToken.ThrowIfCancellationRequested();
 0281                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 282            }
 283            // Send Request
 0284            if (_shouldTrace)
 285            {
 0286                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 287            }
 0288            cancellationToken.ThrowIfCancellationRequested();
 0289            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0290            if (_shouldTrace)
 291            {
 0292                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 293            }
 0294            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0295            cancellationToken.ThrowIfCancellationRequested();
 0296            string _responseContent = null;
 0297            if ((int)_statusCode != 200)
 298            {
 0299                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 300                try
 301                {
 0302                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0303                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0304                    if (_errorBody != null)
 305                    {
 0306                        ex.Body = _errorBody;
 307                    }
 0308                }
 0309                catch (JsonException)
 310                {
 311                    // Ignore the exception
 0312                }
 0313                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0314                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0315                if (_shouldTrace)
 316                {
 0317                    ServiceClientTracing.Error(_invocationId, ex);
 318                }
 0319                _httpRequest.Dispose();
 0320                if (_httpResponse != null)
 321                {
 0322                    _httpResponse.Dispose();
 323                }
 0324                throw ex;
 325            }
 326            // Create Result
 0327            var _result = new HttpOperationResponse<string>();
 0328            _result.Request = _httpRequest;
 0329            _result.Response = _httpResponse;
 330            // Deserialize Response
 0331            if ((int)_statusCode == 200)
 332            {
 0333                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 334                try
 335                {
 0336                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 0337                }
 0338                catch (JsonException ex)
 339                {
 0340                    _httpRequest.Dispose();
 0341                    if (_httpResponse != null)
 342                    {
 0343                        _httpResponse.Dispose();
 344                    }
 0345                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 346                }
 347            }
 0348            if (_shouldTrace)
 349            {
 0350                ServiceClientTracing.Exit(_invocationId, _result);
 351            }
 0352            return _result;
 0353        }
 354
 355    }
 356}