< Summary

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

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Knowledge.QnAMaker\src\Generated\Operations.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    /// Operations operations.
 27    /// </summary>
 28    public partial class Operations : IServiceOperations<QnAMakerClient>, IOperations
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Operations 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 Operations(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 details of a specific long running operation.
 55        /// </summary>
 56        /// <param name='operationId'>
 57        /// Operation id.
 58        /// </param>
 59        /// <param name='customHeaders'>
 60        /// Headers that will be added to request.
 61        /// </param>
 62        /// <param name='cancellationToken'>
 63        /// The cancellation token.
 64        /// </param>
 65        /// <exception cref="ErrorResponseException">
 66        /// Thrown when the operation returned an invalid status code
 67        /// </exception>
 68        /// <exception cref="SerializationException">
 69        /// Thrown when unable to deserialize the response
 70        /// </exception>
 71        /// <exception cref="ValidationException">
 72        /// Thrown when a required parameter is null
 73        /// </exception>
 74        /// <exception cref="System.ArgumentNullException">
 75        /// Thrown when a required parameter is null
 76        /// </exception>
 77        /// <return>
 78        /// A response object containing the response body and response headers.
 79        /// </return>
 80        public async Task<HttpOperationResponse<Operation,OperationsGetDetailsHeaders>> GetDetailsWithHttpMessagesAsync(
 81        {
 082            if (Client.Endpoint == null)
 83            {
 084                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 85            }
 086            if (operationId == null)
 87            {
 088                throw new ValidationException(ValidationRules.CannotBeNull, "operationId");
 89            }
 90            // Tracing
 091            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 092            string _invocationId = null;
 093            if (_shouldTrace)
 94            {
 095                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 096                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 097                tracingParameters.Add("operationId", operationId);
 098                tracingParameters.Add("cancellationToken", cancellationToken);
 099                ServiceClientTracing.Enter(_invocationId, this, "GetDetails", tracingParameters);
 100            }
 101            // Construct URL
 0102            var _baseUrl = Client.BaseUri;
 0103            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/{operationId}";
 0104            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0105            _url = _url.Replace("{operationId}", System.Uri.EscapeDataString(operationId));
 106            // Create HTTP transport objects
 0107            var _httpRequest = new HttpRequestMessage();
 0108            HttpResponseMessage _httpResponse = null;
 0109            _httpRequest.Method = new HttpMethod("GET");
 0110            _httpRequest.RequestUri = new System.Uri(_url);
 111            // Set Headers
 112
 113
 0114            if (customHeaders != null)
 115            {
 0116                foreach(var _header in customHeaders)
 117                {
 0118                    if (_httpRequest.Headers.Contains(_header.Key))
 119                    {
 0120                        _httpRequest.Headers.Remove(_header.Key);
 121                    }
 0122                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 123                }
 124            }
 125
 126            // Serialize Request
 0127            string _requestContent = null;
 128            // Set Credentials
 0129            if (Client.Credentials != null)
 130            {
 0131                cancellationToken.ThrowIfCancellationRequested();
 0132                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 133            }
 134            // Send Request
 0135            if (_shouldTrace)
 136            {
 0137                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 138            }
 0139            cancellationToken.ThrowIfCancellationRequested();
 0140            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0141            if (_shouldTrace)
 142            {
 0143                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 144            }
 0145            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0146            cancellationToken.ThrowIfCancellationRequested();
 0147            string _responseContent = null;
 0148            if ((int)_statusCode != 200)
 149            {
 0150                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 151                try
 152                {
 0153                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0154                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0155                    if (_errorBody != null)
 156                    {
 0157                        ex.Body = _errorBody;
 158                    }
 0159                }
 0160                catch (JsonException)
 161                {
 162                    // Ignore the exception
 0163                }
 0164                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0165                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0166                if (_shouldTrace)
 167                {
 0168                    ServiceClientTracing.Error(_invocationId, ex);
 169                }
 0170                _httpRequest.Dispose();
 0171                if (_httpResponse != null)
 172                {
 0173                    _httpResponse.Dispose();
 174                }
 0175                throw ex;
 176            }
 177            // Create Result
 0178            var _result = new HttpOperationResponse<Operation,OperationsGetDetailsHeaders>();
 0179            _result.Request = _httpRequest;
 0180            _result.Response = _httpResponse;
 181            // Deserialize Response
 0182            if ((int)_statusCode == 200)
 183            {
 0184                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 185                try
 186                {
 0187                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Operation>(_responseContent, Cli
 0188                }
 0189                catch (JsonException ex)
 190                {
 0191                    _httpRequest.Dispose();
 0192                    if (_httpResponse != null)
 193                    {
 0194                        _httpResponse.Dispose();
 195                    }
 0196                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 197                }
 198            }
 199            try
 200            {
 0201                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<OperationsGetDetailsHeaders>(JsonSerializer.
 0202            }
 0203            catch (JsonException ex)
 204            {
 0205                _httpRequest.Dispose();
 0206                if (_httpResponse != null)
 207                {
 0208                    _httpResponse.Dispose();
 209                }
 0210                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 211            }
 0212            if (_shouldTrace)
 213            {
 0214                ServiceClientTracing.Exit(_invocationId, _result);
 215            }
 0216            return _result;
 0217        }
 218
 219    }
 220}