< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%0%
get_Client()-0%100%
GetKeysWithHttpMessagesAsync()-0%0%
RefreshKeysWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\EndpointKeys.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    /// EndpointKeys operations.
 27    /// </summary>
 28    public partial class EndpointKeys : IServiceOperations<QnAMakerClient>, IEndpointKeys
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the EndpointKeys 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 EndpointKeys(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 keys 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<EndpointKeysDTO>> GetKeysWithHttpMessagesAsync(Dictionary<string, List<s
 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, "GetKeys", tracingParameters);
 92            }
 93            // Construct URL
 094            var _baseUrl = Client.BaseUri;
 095            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "endpointkeys";
 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<EndpointKeysDTO>();
 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<EndpointKeysDTO>(_responseConten
 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        /// Re-generates an endpoint key.
 199        /// </summary>
 200        /// <param name='keyType'>
 201        /// Type of Key
 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<EndpointKeysDTO>> RefreshKeysWithHttpMessagesAsync(string keyType, Dicti
 225        {
 0226            if (Client.Endpoint == null)
 227            {
 0228                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 229            }
 0230            if (keyType == null)
 231            {
 0232                throw new ValidationException(ValidationRules.CannotBeNull, "keyType");
 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("keyType", keyType);
 0242                tracingParameters.Add("cancellationToken", cancellationToken);
 0243                ServiceClientTracing.Enter(_invocationId, this, "RefreshKeys", tracingParameters);
 244            }
 245            // Construct URL
 0246            var _baseUrl = Client.BaseUri;
 0247            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "endpointkeys/{keyType}";
 0248            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0249            _url = _url.Replace("{keyType}", System.Uri.EscapeDataString(keyType));
 250            // Create HTTP transport objects
 0251            var _httpRequest = new HttpRequestMessage();
 0252            HttpResponseMessage _httpResponse = null;
 0253            _httpRequest.Method = new HttpMethod("PATCH");
 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<EndpointKeysDTO>();
 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<EndpointKeysDTO>(_responseConten
 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    }
 351}