< Summary

Class:Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.Settings
Assembly:Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.LUIS.Authoring\src\Generated\Settings.cs
Covered lines:4
Uncovered lines:155
Coverable lines:159
Total lines:384
Line coverage:2.5% (4 of 159)
Covered branches:1
Total branches:74
Branch coverage:1.3% (1 of 74)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-0%100%
ListWithHttpMessagesAsync()-0%0%
UpdateWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.LUIS.Authoring\src\Generated\Settings.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.Language.LUIS.Authoring
 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    /// Settings operations.
 27    /// </summary>
 28    public partial class Settings : IServiceOperations<LUISAuthoringClient>, ISettings
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Settings 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>
 15639        public Settings(LUISAuthoringClient client)
 40        {
 15641            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 15645            Client = client;
 15646        }
 47
 48        /// <summary>
 49        /// Gets a reference to the LUISAuthoringClient
 50        /// </summary>
 051        public LUISAuthoringClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Gets the settings in a version of the application.
 55        /// </summary>
 56        /// <param name='appId'>
 57        /// The application ID.
 58        /// </param>
 59        /// <param name='versionId'>
 60        /// The version ID.
 61        /// </param>
 62        /// <param name='customHeaders'>
 63        /// Headers that will be added to request.
 64        /// </param>
 65        /// <param name='cancellationToken'>
 66        /// The cancellation token.
 67        /// </param>
 68        /// <exception cref="ErrorResponseException">
 69        /// Thrown when the operation returned an invalid status code
 70        /// </exception>
 71        /// <exception cref="SerializationException">
 72        /// Thrown when unable to deserialize the response
 73        /// </exception>
 74        /// <exception cref="ValidationException">
 75        /// Thrown when a required parameter is null
 76        /// </exception>
 77        /// <exception cref="System.ArgumentNullException">
 78        /// Thrown when a required parameter is null
 79        /// </exception>
 80        /// <return>
 81        /// A response object containing the response body and response headers.
 82        /// </return>
 83        public async Task<HttpOperationResponse<IList<AppVersionSettingObject>>> ListWithHttpMessagesAsync(System.Guid a
 84        {
 085            if (Client.Endpoint == null)
 86            {
 087                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 88            }
 089            if (versionId == null)
 90            {
 091                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 92            }
 93            // Tracing
 094            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 095            string _invocationId = null;
 096            if (_shouldTrace)
 97            {
 098                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 099                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0100                tracingParameters.Add("appId", appId);
 0101                tracingParameters.Add("versionId", versionId);
 0102                tracingParameters.Add("cancellationToken", cancellationToken);
 0103                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 104            }
 105            // Construct URL
 0106            var _baseUrl = Client.BaseUri;
 0107            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/settings";
 0108            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0109            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 0110            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 111            // Create HTTP transport objects
 0112            var _httpRequest = new HttpRequestMessage();
 0113            HttpResponseMessage _httpResponse = null;
 0114            _httpRequest.Method = new HttpMethod("GET");
 0115            _httpRequest.RequestUri = new System.Uri(_url);
 116            // Set Headers
 117
 118
 0119            if (customHeaders != null)
 120            {
 0121                foreach(var _header in customHeaders)
 122                {
 0123                    if (_httpRequest.Headers.Contains(_header.Key))
 124                    {
 0125                        _httpRequest.Headers.Remove(_header.Key);
 126                    }
 0127                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 128                }
 129            }
 130
 131            // Serialize Request
 0132            string _requestContent = null;
 133            // Set Credentials
 0134            if (Client.Credentials != null)
 135            {
 0136                cancellationToken.ThrowIfCancellationRequested();
 0137                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 138            }
 139            // Send Request
 0140            if (_shouldTrace)
 141            {
 0142                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 143            }
 0144            cancellationToken.ThrowIfCancellationRequested();
 0145            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0146            if (_shouldTrace)
 147            {
 0148                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 149            }
 0150            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0151            cancellationToken.ThrowIfCancellationRequested();
 0152            string _responseContent = null;
 0153            if ((int)_statusCode != 200)
 154            {
 0155                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 156                try
 157                {
 0158                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0159                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0160                    if (_errorBody != null)
 161                    {
 0162                        ex.Body = _errorBody;
 163                    }
 0164                }
 0165                catch (JsonException)
 166                {
 167                    // Ignore the exception
 0168                }
 0169                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0170                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0171                if (_shouldTrace)
 172                {
 0173                    ServiceClientTracing.Error(_invocationId, ex);
 174                }
 0175                _httpRequest.Dispose();
 0176                if (_httpResponse != null)
 177                {
 0178                    _httpResponse.Dispose();
 179                }
 0180                throw ex;
 181            }
 182            // Create Result
 0183            var _result = new HttpOperationResponse<IList<AppVersionSettingObject>>();
 0184            _result.Request = _httpRequest;
 0185            _result.Response = _httpResponse;
 186            // Deserialize Response
 0187            if ((int)_statusCode == 200)
 188            {
 0189                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 190                try
 191                {
 0192                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<AppVersionSettingObject>>(
 0193                }
 0194                catch (JsonException ex)
 195                {
 0196                    _httpRequest.Dispose();
 0197                    if (_httpResponse != null)
 198                    {
 0199                        _httpResponse.Dispose();
 200                    }
 0201                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 202                }
 203            }
 0204            if (_shouldTrace)
 205            {
 0206                ServiceClientTracing.Exit(_invocationId, _result);
 207            }
 0208            return _result;
 0209        }
 210
 211        /// <summary>
 212        /// Updates the settings in a version of the application.
 213        /// </summary>
 214        /// <param name='appId'>
 215        /// The application ID.
 216        /// </param>
 217        /// <param name='versionId'>
 218        /// The version ID.
 219        /// </param>
 220        /// <param name='listOfAppVersionSettingObject'>
 221        /// A list of the updated application version settings.
 222        /// </param>
 223        /// <param name='customHeaders'>
 224        /// Headers that will be added to request.
 225        /// </param>
 226        /// <param name='cancellationToken'>
 227        /// The cancellation token.
 228        /// </param>
 229        /// <exception cref="ErrorResponseException">
 230        /// Thrown when the operation returned an invalid status code
 231        /// </exception>
 232        /// <exception cref="SerializationException">
 233        /// Thrown when unable to deserialize the response
 234        /// </exception>
 235        /// <exception cref="ValidationException">
 236        /// Thrown when a required parameter is null
 237        /// </exception>
 238        /// <exception cref="System.ArgumentNullException">
 239        /// Thrown when a required parameter is null
 240        /// </exception>
 241        /// <return>
 242        /// A response object containing the response body and response headers.
 243        /// </return>
 244        public async Task<HttpOperationResponse<OperationStatus>> UpdateWithHttpMessagesAsync(System.Guid appId, string 
 245        {
 0246            if (Client.Endpoint == null)
 247            {
 0248                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 249            }
 0250            if (versionId == null)
 251            {
 0252                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 253            }
 0254            if (listOfAppVersionSettingObject == null)
 255            {
 0256                throw new ValidationException(ValidationRules.CannotBeNull, "listOfAppVersionSettingObject");
 257            }
 258            // Tracing
 0259            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0260            string _invocationId = null;
 0261            if (_shouldTrace)
 262            {
 0263                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0264                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0265                tracingParameters.Add("appId", appId);
 0266                tracingParameters.Add("versionId", versionId);
 0267                tracingParameters.Add("listOfAppVersionSettingObject", listOfAppVersionSettingObject);
 0268                tracingParameters.Add("cancellationToken", cancellationToken);
 0269                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 270            }
 271            // Construct URL
 0272            var _baseUrl = Client.BaseUri;
 0273            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/settings";
 0274            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0275            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 0276            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 277            // Create HTTP transport objects
 0278            var _httpRequest = new HttpRequestMessage();
 0279            HttpResponseMessage _httpResponse = null;
 0280            _httpRequest.Method = new HttpMethod("PUT");
 0281            _httpRequest.RequestUri = new System.Uri(_url);
 282            // Set Headers
 283
 284
 0285            if (customHeaders != null)
 286            {
 0287                foreach(var _header in customHeaders)
 288                {
 0289                    if (_httpRequest.Headers.Contains(_header.Key))
 290                    {
 0291                        _httpRequest.Headers.Remove(_header.Key);
 292                    }
 0293                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 294                }
 295            }
 296
 297            // Serialize Request
 0298            string _requestContent = null;
 0299            if(listOfAppVersionSettingObject != null)
 300            {
 0301                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(listOfAppVersionSettingObject, Clie
 0302                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0303                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 304            }
 305            // Set Credentials
 0306            if (Client.Credentials != null)
 307            {
 0308                cancellationToken.ThrowIfCancellationRequested();
 0309                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 310            }
 311            // Send Request
 0312            if (_shouldTrace)
 313            {
 0314                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 315            }
 0316            cancellationToken.ThrowIfCancellationRequested();
 0317            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0318            if (_shouldTrace)
 319            {
 0320                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 321            }
 0322            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0323            cancellationToken.ThrowIfCancellationRequested();
 0324            string _responseContent = null;
 0325            if ((int)_statusCode != 200)
 326            {
 0327                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 328                try
 329                {
 0330                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0331                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0332                    if (_errorBody != null)
 333                    {
 0334                        ex.Body = _errorBody;
 335                    }
 0336                }
 0337                catch (JsonException)
 338                {
 339                    // Ignore the exception
 0340                }
 0341                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0342                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0343                if (_shouldTrace)
 344                {
 0345                    ServiceClientTracing.Error(_invocationId, ex);
 346                }
 0347                _httpRequest.Dispose();
 0348                if (_httpResponse != null)
 349                {
 0350                    _httpResponse.Dispose();
 351                }
 0352                throw ex;
 353            }
 354            // Create Result
 0355            var _result = new HttpOperationResponse<OperationStatus>();
 0356            _result.Request = _httpRequest;
 0357            _result.Response = _httpResponse;
 358            // Deserialize Response
 0359            if ((int)_statusCode == 200)
 360            {
 0361                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 362                try
 363                {
 0364                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 0365                }
 0366                catch (JsonException ex)
 367                {
 0368                    _httpRequest.Dispose();
 0369                    if (_httpResponse != null)
 370                    {
 0371                        _httpResponse.Dispose();
 372                    }
 0373                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 374                }
 375            }
 0376            if (_shouldTrace)
 377            {
 0378                ServiceClientTracing.Exit(_invocationId, _result);
 379            }
 0380            return _result;
 0381        }
 382
 383    }
 384}