< Summary

Class:Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.Versions
Assembly:Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.LUIS.Authoring\src\Generated\Versions.cs
Covered lines:489
Uncovered lines:375
Coverable lines:864
Total lines:1908
Line coverage:56.5% (489 of 864)
Covered branches:201
Total branches:418
Branch coverage:48% (201 of 418)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
CloneWithHttpMessagesAsync()-68.75%57.89%
ListWithHttpMessagesAsync()-72.62%70.45%
GetWithHttpMessagesAsync()-68.49%55.88%
UpdateWithHttpMessagesAsync()-68.75%57.89%
DeleteWithHttpMessagesAsync()-68.49%55.88%
ExportWithHttpMessagesAsync()-50.68%38.24%
ImportWithHttpMessagesAsync()-54.88%47.5%
DeleteUnlabelledUtteranceWithHttpMessagesAsync()-0%0%
ImportV2AppWithHttpMessagesAsync()-54.88%47.5%
ImportLuFormatWithHttpMessagesAsync()-54.88%47.5%
ExportLuFormatWithHttpMessagesAsync()-59.42%47.22%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.LUIS.Authoring\src\Generated\Versions.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    /// Versions operations.
 27    /// </summary>
 28    public partial class Versions : IServiceOperations<LUISAuthoringClient>, IVersions
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Versions 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 Versions(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>
 52051        public LUISAuthoringClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Creates a new version from the selected version.
 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='versionCloneObject'>
 63        /// A model containing the new version ID.
 64        /// </param>
 65        /// <param name='customHeaders'>
 66        /// Headers that will be added to request.
 67        /// </param>
 68        /// <param name='cancellationToken'>
 69        /// The cancellation token.
 70        /// </param>
 71        /// <exception cref="ErrorResponseException">
 72        /// Thrown when the operation returned an invalid status code
 73        /// </exception>
 74        /// <exception cref="SerializationException">
 75        /// Thrown when unable to deserialize the response
 76        /// </exception>
 77        /// <exception cref="ValidationException">
 78        /// Thrown when a required parameter is null
 79        /// </exception>
 80        /// <exception cref="System.ArgumentNullException">
 81        /// Thrown when a required parameter is null
 82        /// </exception>
 83        /// <return>
 84        /// A response object containing the response body and response headers.
 85        /// </return>
 86        public async Task<HttpOperationResponse<string>> CloneWithHttpMessagesAsync(System.Guid appId, string versionId,
 87        {
 388            if (Client.Endpoint == null)
 89            {
 090                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 91            }
 392            if (versionId == null)
 93            {
 094                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 95            }
 396            if (versionCloneObject == null)
 97            {
 098                throw new ValidationException(ValidationRules.CannotBeNull, "versionCloneObject");
 99            }
 100            // Tracing
 3101            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 3102            string _invocationId = null;
 3103            if (_shouldTrace)
 104            {
 0105                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0106                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0107                tracingParameters.Add("appId", appId);
 0108                tracingParameters.Add("versionId", versionId);
 0109                tracingParameters.Add("versionCloneObject", versionCloneObject);
 0110                tracingParameters.Add("cancellationToken", cancellationToken);
 0111                ServiceClientTracing.Enter(_invocationId, this, "Clone", tracingParameters);
 112            }
 113            // Construct URL
 3114            var _baseUrl = Client.BaseUri;
 3115            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/clone";
 3116            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 3117            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 3118            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 119            // Create HTTP transport objects
 3120            var _httpRequest = new HttpRequestMessage();
 3121            HttpResponseMessage _httpResponse = null;
 3122            _httpRequest.Method = new HttpMethod("POST");
 3123            _httpRequest.RequestUri = new System.Uri(_url);
 124            // Set Headers
 125
 126
 3127            if (customHeaders != null)
 128            {
 0129                foreach(var _header in customHeaders)
 130                {
 0131                    if (_httpRequest.Headers.Contains(_header.Key))
 132                    {
 0133                        _httpRequest.Headers.Remove(_header.Key);
 134                    }
 0135                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 136                }
 137            }
 138
 139            // Serialize Request
 3140            string _requestContent = null;
 3141            if(versionCloneObject != null)
 142            {
 3143                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(versionCloneObject, Client.Serializ
 3144                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 3145                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 146            }
 147            // Set Credentials
 3148            if (Client.Credentials != null)
 149            {
 3150                cancellationToken.ThrowIfCancellationRequested();
 3151                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 152            }
 153            // Send Request
 3154            if (_shouldTrace)
 155            {
 0156                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 157            }
 3158            cancellationToken.ThrowIfCancellationRequested();
 3159            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3160            if (_shouldTrace)
 161            {
 0162                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 163            }
 3164            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 3165            cancellationToken.ThrowIfCancellationRequested();
 3166            string _responseContent = null;
 3167            if ((int)_statusCode != 201)
 168            {
 1169                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 170                try
 171                {
 1172                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1173                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 1174                    if (_errorBody != null)
 175                    {
 1176                        ex.Body = _errorBody;
 177                    }
 1178                }
 0179                catch (JsonException)
 180                {
 181                    // Ignore the exception
 0182                }
 1183                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1184                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1185                if (_shouldTrace)
 186                {
 0187                    ServiceClientTracing.Error(_invocationId, ex);
 188                }
 1189                _httpRequest.Dispose();
 1190                if (_httpResponse != null)
 191                {
 1192                    _httpResponse.Dispose();
 193                }
 1194                throw ex;
 195            }
 196            // Create Result
 2197            var _result = new HttpOperationResponse<string>();
 2198            _result.Request = _httpRequest;
 2199            _result.Response = _httpResponse;
 200            // Deserialize Response
 2201            if ((int)_statusCode == 201)
 202            {
 2203                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 204                try
 205                {
 2206                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 2207                }
 0208                catch (JsonException ex)
 209                {
 0210                    _httpRequest.Dispose();
 0211                    if (_httpResponse != null)
 212                    {
 0213                        _httpResponse.Dispose();
 214                    }
 0215                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 216                }
 217            }
 2218            if (_shouldTrace)
 219            {
 0220                ServiceClientTracing.Exit(_invocationId, _result);
 221            }
 2222            return _result;
 2223        }
 224
 225        /// <summary>
 226        /// Gets a list of versions for this application ID.
 227        /// </summary>
 228        /// <param name='appId'>
 229        /// The application ID.
 230        /// </param>
 231        /// <param name='skip'>
 232        /// The number of entries to skip. Default value is 0.
 233        /// </param>
 234        /// <param name='take'>
 235        /// The number of entries to return. Maximum page size is 500. Default is 100.
 236        /// </param>
 237        /// <param name='customHeaders'>
 238        /// Headers that will be added to request.
 239        /// </param>
 240        /// <param name='cancellationToken'>
 241        /// The cancellation token.
 242        /// </param>
 243        /// <exception cref="ErrorResponseException">
 244        /// Thrown when the operation returned an invalid status code
 245        /// </exception>
 246        /// <exception cref="SerializationException">
 247        /// Thrown when unable to deserialize the response
 248        /// </exception>
 249        /// <exception cref="ValidationException">
 250        /// Thrown when a required parameter is null
 251        /// </exception>
 252        /// <exception cref="System.ArgumentNullException">
 253        /// Thrown when a required parameter is null
 254        /// </exception>
 255        /// <return>
 256        /// A response object containing the response body and response headers.
 257        /// </return>
 258        public async Task<HttpOperationResponse<IList<VersionInfo>>> ListWithHttpMessagesAsync(System.Guid appId, int? s
 259        {
 22260            if (Client.Endpoint == null)
 261            {
 0262                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 263            }
 22264            if (skip < 0)
 265            {
 0266                throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0);
 267            }
 22268            if (take > 500)
 269            {
 0270                throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500);
 271            }
 22272            if (take < 0)
 273            {
 0274                throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0);
 275            }
 276            // Tracing
 22277            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 22278            string _invocationId = null;
 22279            if (_shouldTrace)
 280            {
 0281                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0282                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0283                tracingParameters.Add("appId", appId);
 0284                tracingParameters.Add("skip", skip);
 0285                tracingParameters.Add("take", take);
 0286                tracingParameters.Add("cancellationToken", cancellationToken);
 0287                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 288            }
 289            // Construct URL
 22290            var _baseUrl = Client.BaseUri;
 22291            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions";
 22292            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 22293            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 22294            List<string> _queryParameters = new List<string>();
 22295            if (skip != null)
 296            {
 22297                _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 298            }
 22299            if (take != null)
 300            {
 22301                _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 302            }
 22303            if (_queryParameters.Count > 0)
 304            {
 22305                _url += "?" + string.Join("&", _queryParameters);
 306            }
 307            // Create HTTP transport objects
 22308            var _httpRequest = new HttpRequestMessage();
 22309            HttpResponseMessage _httpResponse = null;
 22310            _httpRequest.Method = new HttpMethod("GET");
 22311            _httpRequest.RequestUri = new System.Uri(_url);
 312            // Set Headers
 313
 314
 22315            if (customHeaders != null)
 316            {
 4317                foreach(var _header in customHeaders)
 318                {
 1319                    if (_httpRequest.Headers.Contains(_header.Key))
 320                    {
 0321                        _httpRequest.Headers.Remove(_header.Key);
 322                    }
 1323                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 324                }
 325            }
 326
 327            // Serialize Request
 22328            string _requestContent = null;
 329            // Set Credentials
 22330            if (Client.Credentials != null)
 331            {
 22332                cancellationToken.ThrowIfCancellationRequested();
 22333                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 334            }
 335            // Send Request
 22336            if (_shouldTrace)
 337            {
 0338                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 339            }
 22340            cancellationToken.ThrowIfCancellationRequested();
 22341            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 22342            if (_shouldTrace)
 343            {
 0344                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 345            }
 22346            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 22347            cancellationToken.ThrowIfCancellationRequested();
 22348            string _responseContent = null;
 22349            if ((int)_statusCode != 200)
 350            {
 2351                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 352                try
 353                {
 2354                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2355                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 2356                    if (_errorBody != null)
 357                    {
 1358                        ex.Body = _errorBody;
 359                    }
 2360                }
 0361                catch (JsonException)
 362                {
 363                    // Ignore the exception
 0364                }
 2365                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 2366                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 2367                if (_shouldTrace)
 368                {
 0369                    ServiceClientTracing.Error(_invocationId, ex);
 370                }
 2371                _httpRequest.Dispose();
 2372                if (_httpResponse != null)
 373                {
 2374                    _httpResponse.Dispose();
 375                }
 2376                throw ex;
 377            }
 378            // Create Result
 20379            var _result = new HttpOperationResponse<IList<VersionInfo>>();
 20380            _result.Request = _httpRequest;
 20381            _result.Response = _httpResponse;
 382            // Deserialize Response
 20383            if ((int)_statusCode == 200)
 384            {
 20385                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 386                try
 387                {
 20388                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<VersionInfo>>(_responseCon
 20389                }
 0390                catch (JsonException ex)
 391                {
 0392                    _httpRequest.Dispose();
 0393                    if (_httpResponse != null)
 394                    {
 0395                        _httpResponse.Dispose();
 396                    }
 0397                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 398                }
 399            }
 20400            if (_shouldTrace)
 401            {
 0402                ServiceClientTracing.Exit(_invocationId, _result);
 403            }
 20404            return _result;
 20405        }
 406
 407        /// <summary>
 408        /// Gets the version information such as date created, last modified date,
 409        /// endpoint URL, count of intents and entities, training and publishing
 410        /// status.
 411        /// </summary>
 412        /// <param name='appId'>
 413        /// The application ID.
 414        /// </param>
 415        /// <param name='versionId'>
 416        /// The version ID.
 417        /// </param>
 418        /// <param name='customHeaders'>
 419        /// Headers that will be added to request.
 420        /// </param>
 421        /// <param name='cancellationToken'>
 422        /// The cancellation token.
 423        /// </param>
 424        /// <exception cref="ErrorResponseException">
 425        /// Thrown when the operation returned an invalid status code
 426        /// </exception>
 427        /// <exception cref="SerializationException">
 428        /// Thrown when unable to deserialize the response
 429        /// </exception>
 430        /// <exception cref="ValidationException">
 431        /// Thrown when a required parameter is null
 432        /// </exception>
 433        /// <exception cref="System.ArgumentNullException">
 434        /// Thrown when a required parameter is null
 435        /// </exception>
 436        /// <return>
 437        /// A response object containing the response body and response headers.
 438        /// </return>
 439        public async Task<HttpOperationResponse<VersionInfo>> GetWithHttpMessagesAsync(System.Guid appId, string version
 440        {
 3441            if (Client.Endpoint == null)
 442            {
 0443                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 444            }
 3445            if (versionId == null)
 446            {
 0447                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 448            }
 449            // Tracing
 3450            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 3451            string _invocationId = null;
 3452            if (_shouldTrace)
 453            {
 0454                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0455                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0456                tracingParameters.Add("appId", appId);
 0457                tracingParameters.Add("versionId", versionId);
 0458                tracingParameters.Add("cancellationToken", cancellationToken);
 0459                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 460            }
 461            // Construct URL
 3462            var _baseUrl = Client.BaseUri;
 3463            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/";
 3464            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 3465            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 3466            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 467            // Create HTTP transport objects
 3468            var _httpRequest = new HttpRequestMessage();
 3469            HttpResponseMessage _httpResponse = null;
 3470            _httpRequest.Method = new HttpMethod("GET");
 3471            _httpRequest.RequestUri = new System.Uri(_url);
 472            // Set Headers
 473
 474
 3475            if (customHeaders != null)
 476            {
 0477                foreach(var _header in customHeaders)
 478                {
 0479                    if (_httpRequest.Headers.Contains(_header.Key))
 480                    {
 0481                        _httpRequest.Headers.Remove(_header.Key);
 482                    }
 0483                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 484                }
 485            }
 486
 487            // Serialize Request
 3488            string _requestContent = null;
 489            // Set Credentials
 3490            if (Client.Credentials != null)
 491            {
 3492                cancellationToken.ThrowIfCancellationRequested();
 3493                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 494            }
 495            // Send Request
 3496            if (_shouldTrace)
 497            {
 0498                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 499            }
 3500            cancellationToken.ThrowIfCancellationRequested();
 3501            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3502            if (_shouldTrace)
 503            {
 0504                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 505            }
 3506            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 3507            cancellationToken.ThrowIfCancellationRequested();
 3508            string _responseContent = null;
 3509            if ((int)_statusCode != 200)
 510            {
 1511                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 512                try
 513                {
 1514                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1515                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 1516                    if (_errorBody != null)
 517                    {
 1518                        ex.Body = _errorBody;
 519                    }
 1520                }
 0521                catch (JsonException)
 522                {
 523                    // Ignore the exception
 0524                }
 1525                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1526                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1527                if (_shouldTrace)
 528                {
 0529                    ServiceClientTracing.Error(_invocationId, ex);
 530                }
 1531                _httpRequest.Dispose();
 1532                if (_httpResponse != null)
 533                {
 1534                    _httpResponse.Dispose();
 535                }
 1536                throw ex;
 537            }
 538            // Create Result
 2539            var _result = new HttpOperationResponse<VersionInfo>();
 2540            _result.Request = _httpRequest;
 2541            _result.Response = _httpResponse;
 542            // Deserialize Response
 2543            if ((int)_statusCode == 200)
 544            {
 2545                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 546                try
 547                {
 2548                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<VersionInfo>(_responseContent, C
 2549                }
 0550                catch (JsonException ex)
 551                {
 0552                    _httpRequest.Dispose();
 0553                    if (_httpResponse != null)
 554                    {
 0555                        _httpResponse.Dispose();
 556                    }
 0557                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 558                }
 559            }
 2560            if (_shouldTrace)
 561            {
 0562                ServiceClientTracing.Exit(_invocationId, _result);
 563            }
 2564            return _result;
 2565        }
 566
 567        /// <summary>
 568        /// Updates the name or description of the application version.
 569        /// </summary>
 570        /// <param name='appId'>
 571        /// The application ID.
 572        /// </param>
 573        /// <param name='versionId'>
 574        /// The version ID.
 575        /// </param>
 576        /// <param name='versionUpdateObject'>
 577        /// A model containing Name and Description of the application.
 578        /// </param>
 579        /// <param name='customHeaders'>
 580        /// Headers that will be added to request.
 581        /// </param>
 582        /// <param name='cancellationToken'>
 583        /// The cancellation token.
 584        /// </param>
 585        /// <exception cref="ErrorResponseException">
 586        /// Thrown when the operation returned an invalid status code
 587        /// </exception>
 588        /// <exception cref="SerializationException">
 589        /// Thrown when unable to deserialize the response
 590        /// </exception>
 591        /// <exception cref="ValidationException">
 592        /// Thrown when a required parameter is null
 593        /// </exception>
 594        /// <exception cref="System.ArgumentNullException">
 595        /// Thrown when a required parameter is null
 596        /// </exception>
 597        /// <return>
 598        /// A response object containing the response body and response headers.
 599        /// </return>
 600        public async Task<HttpOperationResponse<OperationStatus>> UpdateWithHttpMessagesAsync(System.Guid appId, string 
 601        {
 3602            if (Client.Endpoint == null)
 603            {
 0604                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 605            }
 3606            if (versionId == null)
 607            {
 0608                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 609            }
 3610            if (versionUpdateObject == null)
 611            {
 0612                throw new ValidationException(ValidationRules.CannotBeNull, "versionUpdateObject");
 613            }
 614            // Tracing
 3615            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 3616            string _invocationId = null;
 3617            if (_shouldTrace)
 618            {
 0619                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0620                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0621                tracingParameters.Add("appId", appId);
 0622                tracingParameters.Add("versionId", versionId);
 0623                tracingParameters.Add("versionUpdateObject", versionUpdateObject);
 0624                tracingParameters.Add("cancellationToken", cancellationToken);
 0625                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 626            }
 627            // Construct URL
 3628            var _baseUrl = Client.BaseUri;
 3629            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/";
 3630            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 3631            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 3632            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 633            // Create HTTP transport objects
 3634            var _httpRequest = new HttpRequestMessage();
 3635            HttpResponseMessage _httpResponse = null;
 3636            _httpRequest.Method = new HttpMethod("PUT");
 3637            _httpRequest.RequestUri = new System.Uri(_url);
 638            // Set Headers
 639
 640
 3641            if (customHeaders != null)
 642            {
 0643                foreach(var _header in customHeaders)
 644                {
 0645                    if (_httpRequest.Headers.Contains(_header.Key))
 646                    {
 0647                        _httpRequest.Headers.Remove(_header.Key);
 648                    }
 0649                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 650                }
 651            }
 652
 653            // Serialize Request
 3654            string _requestContent = null;
 3655            if(versionUpdateObject != null)
 656            {
 3657                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(versionUpdateObject, Client.Seriali
 3658                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 3659                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 660            }
 661            // Set Credentials
 3662            if (Client.Credentials != null)
 663            {
 3664                cancellationToken.ThrowIfCancellationRequested();
 3665                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 666            }
 667            // Send Request
 3668            if (_shouldTrace)
 669            {
 0670                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 671            }
 3672            cancellationToken.ThrowIfCancellationRequested();
 3673            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3674            if (_shouldTrace)
 675            {
 0676                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 677            }
 3678            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 3679            cancellationToken.ThrowIfCancellationRequested();
 3680            string _responseContent = null;
 3681            if ((int)_statusCode != 200)
 682            {
 1683                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 684                try
 685                {
 1686                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1687                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 1688                    if (_errorBody != null)
 689                    {
 1690                        ex.Body = _errorBody;
 691                    }
 1692                }
 0693                catch (JsonException)
 694                {
 695                    // Ignore the exception
 0696                }
 1697                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1698                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1699                if (_shouldTrace)
 700                {
 0701                    ServiceClientTracing.Error(_invocationId, ex);
 702                }
 1703                _httpRequest.Dispose();
 1704                if (_httpResponse != null)
 705                {
 1706                    _httpResponse.Dispose();
 707                }
 1708                throw ex;
 709            }
 710            // Create Result
 2711            var _result = new HttpOperationResponse<OperationStatus>();
 2712            _result.Request = _httpRequest;
 2713            _result.Response = _httpResponse;
 714            // Deserialize Response
 2715            if ((int)_statusCode == 200)
 716            {
 2717                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 718                try
 719                {
 2720                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 2721                }
 0722                catch (JsonException ex)
 723                {
 0724                    _httpRequest.Dispose();
 0725                    if (_httpResponse != null)
 726                    {
 0727                        _httpResponse.Dispose();
 728                    }
 0729                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 730                }
 731            }
 2732            if (_shouldTrace)
 733            {
 0734                ServiceClientTracing.Exit(_invocationId, _result);
 735            }
 2736            return _result;
 2737        }
 738
 739        /// <summary>
 740        /// Deletes an application version.
 741        /// </summary>
 742        /// <param name='appId'>
 743        /// The application ID.
 744        /// </param>
 745        /// <param name='versionId'>
 746        /// The version ID.
 747        /// </param>
 748        /// <param name='customHeaders'>
 749        /// Headers that will be added to request.
 750        /// </param>
 751        /// <param name='cancellationToken'>
 752        /// The cancellation token.
 753        /// </param>
 754        /// <exception cref="ErrorResponseException">
 755        /// Thrown when the operation returned an invalid status code
 756        /// </exception>
 757        /// <exception cref="SerializationException">
 758        /// Thrown when unable to deserialize the response
 759        /// </exception>
 760        /// <exception cref="ValidationException">
 761        /// Thrown when a required parameter is null
 762        /// </exception>
 763        /// <exception cref="System.ArgumentNullException">
 764        /// Thrown when a required parameter is null
 765        /// </exception>
 766        /// <return>
 767        /// A response object containing the response body and response headers.
 768        /// </return>
 769        public async Task<HttpOperationResponse<OperationStatus>> DeleteWithHttpMessagesAsync(System.Guid appId, string 
 770        {
 3771            if (Client.Endpoint == null)
 772            {
 0773                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 774            }
 3775            if (versionId == null)
 776            {
 0777                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 778            }
 779            // Tracing
 3780            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 3781            string _invocationId = null;
 3782            if (_shouldTrace)
 783            {
 0784                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0785                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0786                tracingParameters.Add("appId", appId);
 0787                tracingParameters.Add("versionId", versionId);
 0788                tracingParameters.Add("cancellationToken", cancellationToken);
 0789                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 790            }
 791            // Construct URL
 3792            var _baseUrl = Client.BaseUri;
 3793            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/";
 3794            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 3795            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 3796            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 797            // Create HTTP transport objects
 3798            var _httpRequest = new HttpRequestMessage();
 3799            HttpResponseMessage _httpResponse = null;
 3800            _httpRequest.Method = new HttpMethod("DELETE");
 3801            _httpRequest.RequestUri = new System.Uri(_url);
 802            // Set Headers
 803
 804
 3805            if (customHeaders != null)
 806            {
 0807                foreach(var _header in customHeaders)
 808                {
 0809                    if (_httpRequest.Headers.Contains(_header.Key))
 810                    {
 0811                        _httpRequest.Headers.Remove(_header.Key);
 812                    }
 0813                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 814                }
 815            }
 816
 817            // Serialize Request
 3818            string _requestContent = null;
 819            // Set Credentials
 3820            if (Client.Credentials != null)
 821            {
 3822                cancellationToken.ThrowIfCancellationRequested();
 3823                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 824            }
 825            // Send Request
 3826            if (_shouldTrace)
 827            {
 0828                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 829            }
 3830            cancellationToken.ThrowIfCancellationRequested();
 3831            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3832            if (_shouldTrace)
 833            {
 0834                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 835            }
 3836            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 3837            cancellationToken.ThrowIfCancellationRequested();
 3838            string _responseContent = null;
 3839            if ((int)_statusCode != 200)
 840            {
 1841                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 842                try
 843                {
 1844                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1845                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 1846                    if (_errorBody != null)
 847                    {
 1848                        ex.Body = _errorBody;
 849                    }
 1850                }
 0851                catch (JsonException)
 852                {
 853                    // Ignore the exception
 0854                }
 1855                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1856                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1857                if (_shouldTrace)
 858                {
 0859                    ServiceClientTracing.Error(_invocationId, ex);
 860                }
 1861                _httpRequest.Dispose();
 1862                if (_httpResponse != null)
 863                {
 1864                    _httpResponse.Dispose();
 865                }
 1866                throw ex;
 867            }
 868            // Create Result
 2869            var _result = new HttpOperationResponse<OperationStatus>();
 2870            _result.Request = _httpRequest;
 2871            _result.Response = _httpResponse;
 872            // Deserialize Response
 2873            if ((int)_statusCode == 200)
 874            {
 2875                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 876                try
 877                {
 2878                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 2879                }
 0880                catch (JsonException ex)
 881                {
 0882                    _httpRequest.Dispose();
 0883                    if (_httpResponse != null)
 884                    {
 0885                        _httpResponse.Dispose();
 886                    }
 0887                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 888                }
 889            }
 2890            if (_shouldTrace)
 891            {
 0892                ServiceClientTracing.Exit(_invocationId, _result);
 893            }
 2894            return _result;
 2895        }
 896
 897        /// <summary>
 898        /// Exports a LUIS application to JSON format.
 899        /// </summary>
 900        /// <param name='appId'>
 901        /// The application ID.
 902        /// </param>
 903        /// <param name='versionId'>
 904        /// The version ID.
 905        /// </param>
 906        /// <param name='customHeaders'>
 907        /// Headers that will be added to request.
 908        /// </param>
 909        /// <param name='cancellationToken'>
 910        /// The cancellation token.
 911        /// </param>
 912        /// <exception cref="ErrorResponseException">
 913        /// Thrown when the operation returned an invalid status code
 914        /// </exception>
 915        /// <exception cref="SerializationException">
 916        /// Thrown when unable to deserialize the response
 917        /// </exception>
 918        /// <exception cref="ValidationException">
 919        /// Thrown when a required parameter is null
 920        /// </exception>
 921        /// <exception cref="System.ArgumentNullException">
 922        /// Thrown when a required parameter is null
 923        /// </exception>
 924        /// <return>
 925        /// A response object containing the response body and response headers.
 926        /// </return>
 927        public async Task<HttpOperationResponse<LuisApp>> ExportWithHttpMessagesAsync(System.Guid appId, string versionI
 928        {
 1929            if (Client.Endpoint == null)
 930            {
 0931                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 932            }
 1933            if (versionId == null)
 934            {
 0935                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 936            }
 937            // Tracing
 1938            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 1939            string _invocationId = null;
 1940            if (_shouldTrace)
 941            {
 0942                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0943                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0944                tracingParameters.Add("appId", appId);
 0945                tracingParameters.Add("versionId", versionId);
 0946                tracingParameters.Add("cancellationToken", cancellationToken);
 0947                ServiceClientTracing.Enter(_invocationId, this, "Export", tracingParameters);
 948            }
 949            // Construct URL
 1950            var _baseUrl = Client.BaseUri;
 1951            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/export";
 1952            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 1953            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 1954            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 955            // Create HTTP transport objects
 1956            var _httpRequest = new HttpRequestMessage();
 1957            HttpResponseMessage _httpResponse = null;
 1958            _httpRequest.Method = new HttpMethod("GET");
 1959            _httpRequest.RequestUri = new System.Uri(_url);
 960            // Set Headers
 961
 962
 1963            if (customHeaders != null)
 964            {
 0965                foreach(var _header in customHeaders)
 966                {
 0967                    if (_httpRequest.Headers.Contains(_header.Key))
 968                    {
 0969                        _httpRequest.Headers.Remove(_header.Key);
 970                    }
 0971                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 972                }
 973            }
 974
 975            // Serialize Request
 1976            string _requestContent = null;
 977            // Set Credentials
 1978            if (Client.Credentials != null)
 979            {
 1980                cancellationToken.ThrowIfCancellationRequested();
 1981                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 982            }
 983            // Send Request
 1984            if (_shouldTrace)
 985            {
 0986                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 987            }
 1988            cancellationToken.ThrowIfCancellationRequested();
 1989            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1990            if (_shouldTrace)
 991            {
 0992                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 993            }
 1994            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 1995            cancellationToken.ThrowIfCancellationRequested();
 1996            string _responseContent = null;
 1997            if ((int)_statusCode != 200)
 998            {
 0999                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1000                try
 1001                {
 01002                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01003                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01004                    if (_errorBody != null)
 1005                    {
 01006                        ex.Body = _errorBody;
 1007                    }
 01008                }
 01009                catch (JsonException)
 1010                {
 1011                    // Ignore the exception
 01012                }
 01013                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01014                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01015                if (_shouldTrace)
 1016                {
 01017                    ServiceClientTracing.Error(_invocationId, ex);
 1018                }
 01019                _httpRequest.Dispose();
 01020                if (_httpResponse != null)
 1021                {
 01022                    _httpResponse.Dispose();
 1023                }
 01024                throw ex;
 1025            }
 1026            // Create Result
 11027            var _result = new HttpOperationResponse<LuisApp>();
 11028            _result.Request = _httpRequest;
 11029            _result.Response = _httpResponse;
 1030            // Deserialize Response
 11031            if ((int)_statusCode == 200)
 1032            {
 11033                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1034                try
 1035                {
 11036                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LuisApp>(_responseContent, Clien
 11037                }
 01038                catch (JsonException ex)
 1039                {
 01040                    _httpRequest.Dispose();
 01041                    if (_httpResponse != null)
 1042                    {
 01043                        _httpResponse.Dispose();
 1044                    }
 01045                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1046                }
 1047            }
 11048            if (_shouldTrace)
 1049            {
 01050                ServiceClientTracing.Exit(_invocationId, _result);
 1051            }
 11052            return _result;
 11053        }
 1054
 1055        /// <summary>
 1056        /// Imports a new version into a LUIS application.
 1057        /// </summary>
 1058        /// <param name='appId'>
 1059        /// The application ID.
 1060        /// </param>
 1061        /// <param name='luisApp'>
 1062        /// A LUIS application structure.
 1063        /// </param>
 1064        /// <param name='versionId'>
 1065        /// The new versionId to import. If not specified, the versionId will be read
 1066        /// from the imported object.
 1067        /// </param>
 1068        /// <param name='customHeaders'>
 1069        /// Headers that will be added to request.
 1070        /// </param>
 1071        /// <param name='cancellationToken'>
 1072        /// The cancellation token.
 1073        /// </param>
 1074        /// <exception cref="ErrorResponseException">
 1075        /// Thrown when the operation returned an invalid status code
 1076        /// </exception>
 1077        /// <exception cref="SerializationException">
 1078        /// Thrown when unable to deserialize the response
 1079        /// </exception>
 1080        /// <exception cref="ValidationException">
 1081        /// Thrown when a required parameter is null
 1082        /// </exception>
 1083        /// <exception cref="System.ArgumentNullException">
 1084        /// Thrown when a required parameter is null
 1085        /// </exception>
 1086        /// <return>
 1087        /// A response object containing the response body and response headers.
 1088        /// </return>
 1089        public async Task<HttpOperationResponse<string>> ImportWithHttpMessagesAsync(System.Guid appId, LuisApp luisApp,
 1090        {
 11091            if (Client.Endpoint == null)
 1092            {
 01093                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1094            }
 11095            if (luisApp == null)
 1096            {
 01097                throw new ValidationException(ValidationRules.CannotBeNull, "luisApp");
 1098            }
 1099            // Tracing
 11100            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 11101            string _invocationId = null;
 11102            if (_shouldTrace)
 1103            {
 01104                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01105                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01106                tracingParameters.Add("appId", appId);
 01107                tracingParameters.Add("versionId", versionId);
 01108                tracingParameters.Add("luisApp", luisApp);
 01109                tracingParameters.Add("cancellationToken", cancellationToken);
 01110                ServiceClientTracing.Enter(_invocationId, this, "Import", tracingParameters);
 1111            }
 1112            // Construct URL
 11113            var _baseUrl = Client.BaseUri;
 11114            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/import";
 11115            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 11116            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 11117            List<string> _queryParameters = new List<string>();
 11118            if (versionId != null)
 1119            {
 11120                _queryParameters.Add(string.Format("versionId={0}", System.Uri.EscapeDataString(versionId)));
 1121            }
 11122            if (_queryParameters.Count > 0)
 1123            {
 11124                _url += "?" + string.Join("&", _queryParameters);
 1125            }
 1126            // Create HTTP transport objects
 11127            var _httpRequest = new HttpRequestMessage();
 11128            HttpResponseMessage _httpResponse = null;
 11129            _httpRequest.Method = new HttpMethod("POST");
 11130            _httpRequest.RequestUri = new System.Uri(_url);
 1131            // Set Headers
 1132
 1133
 11134            if (customHeaders != null)
 1135            {
 01136                foreach(var _header in customHeaders)
 1137                {
 01138                    if (_httpRequest.Headers.Contains(_header.Key))
 1139                    {
 01140                        _httpRequest.Headers.Remove(_header.Key);
 1141                    }
 01142                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1143                }
 1144            }
 1145
 1146            // Serialize Request
 11147            string _requestContent = null;
 11148            if(luisApp != null)
 1149            {
 11150                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisApp, Client.SerializationSettin
 11151                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 11152                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1153            }
 1154            // Set Credentials
 11155            if (Client.Credentials != null)
 1156            {
 11157                cancellationToken.ThrowIfCancellationRequested();
 11158                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1159            }
 1160            // Send Request
 11161            if (_shouldTrace)
 1162            {
 01163                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1164            }
 11165            cancellationToken.ThrowIfCancellationRequested();
 11166            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 11167            if (_shouldTrace)
 1168            {
 01169                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1170            }
 11171            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 11172            cancellationToken.ThrowIfCancellationRequested();
 11173            string _responseContent = null;
 11174            if ((int)_statusCode != 201)
 1175            {
 01176                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1177                try
 1178                {
 01179                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01180                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01181                    if (_errorBody != null)
 1182                    {
 01183                        ex.Body = _errorBody;
 1184                    }
 01185                }
 01186                catch (JsonException)
 1187                {
 1188                    // Ignore the exception
 01189                }
 01190                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01191                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01192                if (_shouldTrace)
 1193                {
 01194                    ServiceClientTracing.Error(_invocationId, ex);
 1195                }
 01196                _httpRequest.Dispose();
 01197                if (_httpResponse != null)
 1198                {
 01199                    _httpResponse.Dispose();
 1200                }
 01201                throw ex;
 1202            }
 1203            // Create Result
 11204            var _result = new HttpOperationResponse<string>();
 11205            _result.Request = _httpRequest;
 11206            _result.Response = _httpResponse;
 1207            // Deserialize Response
 11208            if ((int)_statusCode == 201)
 1209            {
 11210                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1211                try
 1212                {
 11213                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 11214                }
 01215                catch (JsonException ex)
 1216                {
 01217                    _httpRequest.Dispose();
 01218                    if (_httpResponse != null)
 1219                    {
 01220                        _httpResponse.Dispose();
 1221                    }
 01222                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1223                }
 1224            }
 11225            if (_shouldTrace)
 1226            {
 01227                ServiceClientTracing.Exit(_invocationId, _result);
 1228            }
 11229            return _result;
 11230        }
 1231
 1232        /// <summary>
 1233        /// Deleted an unlabelled utterance in a version of the application.
 1234        /// </summary>
 1235        /// <param name='appId'>
 1236        /// The application ID.
 1237        /// </param>
 1238        /// <param name='versionId'>
 1239        /// The version ID.
 1240        /// </param>
 1241        /// <param name='utterance'>
 1242        /// The utterance text to delete.
 1243        /// </param>
 1244        /// <param name='customHeaders'>
 1245        /// Headers that will be added to request.
 1246        /// </param>
 1247        /// <param name='cancellationToken'>
 1248        /// The cancellation token.
 1249        /// </param>
 1250        /// <exception cref="ErrorResponseException">
 1251        /// Thrown when the operation returned an invalid status code
 1252        /// </exception>
 1253        /// <exception cref="SerializationException">
 1254        /// Thrown when unable to deserialize the response
 1255        /// </exception>
 1256        /// <exception cref="ValidationException">
 1257        /// Thrown when a required parameter is null
 1258        /// </exception>
 1259        /// <exception cref="System.ArgumentNullException">
 1260        /// Thrown when a required parameter is null
 1261        /// </exception>
 1262        /// <return>
 1263        /// A response object containing the response body and response headers.
 1264        /// </return>
 1265        public async Task<HttpOperationResponse<OperationStatus>> DeleteUnlabelledUtteranceWithHttpMessagesAsync(System.
 1266        {
 01267            if (Client.Endpoint == null)
 1268            {
 01269                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1270            }
 01271            if (versionId == null)
 1272            {
 01273                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 1274            }
 01275            if (utterance == null)
 1276            {
 01277                throw new ValidationException(ValidationRules.CannotBeNull, "utterance");
 1278            }
 1279            // Tracing
 01280            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01281            string _invocationId = null;
 01282            if (_shouldTrace)
 1283            {
 01284                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01285                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01286                tracingParameters.Add("appId", appId);
 01287                tracingParameters.Add("versionId", versionId);
 01288                tracingParameters.Add("utterance", utterance);
 01289                tracingParameters.Add("cancellationToken", cancellationToken);
 01290                ServiceClientTracing.Enter(_invocationId, this, "DeleteUnlabelledUtterance", tracingParameters);
 1291            }
 1292            // Construct URL
 01293            var _baseUrl = Client.BaseUri;
 01294            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/suggest";
 01295            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01296            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 01297            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 1298            // Create HTTP transport objects
 01299            var _httpRequest = new HttpRequestMessage();
 01300            HttpResponseMessage _httpResponse = null;
 01301            _httpRequest.Method = new HttpMethod("DELETE");
 01302            _httpRequest.RequestUri = new System.Uri(_url);
 1303            // Set Headers
 1304
 1305
 01306            if (customHeaders != null)
 1307            {
 01308                foreach(var _header in customHeaders)
 1309                {
 01310                    if (_httpRequest.Headers.Contains(_header.Key))
 1311                    {
 01312                        _httpRequest.Headers.Remove(_header.Key);
 1313                    }
 01314                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1315                }
 1316            }
 1317
 1318            // Serialize Request
 01319            string _requestContent = null;
 01320            if(utterance != null)
 1321            {
 01322                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(utterance, Client.SerializationSett
 01323                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01324                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1325            }
 1326            // Set Credentials
 01327            if (Client.Credentials != null)
 1328            {
 01329                cancellationToken.ThrowIfCancellationRequested();
 01330                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1331            }
 1332            // Send Request
 01333            if (_shouldTrace)
 1334            {
 01335                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1336            }
 01337            cancellationToken.ThrowIfCancellationRequested();
 01338            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01339            if (_shouldTrace)
 1340            {
 01341                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1342            }
 01343            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01344            cancellationToken.ThrowIfCancellationRequested();
 01345            string _responseContent = null;
 01346            if ((int)_statusCode != 200)
 1347            {
 01348                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1349                try
 1350                {
 01351                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01352                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01353                    if (_errorBody != null)
 1354                    {
 01355                        ex.Body = _errorBody;
 1356                    }
 01357                }
 01358                catch (JsonException)
 1359                {
 1360                    // Ignore the exception
 01361                }
 01362                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01363                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01364                if (_shouldTrace)
 1365                {
 01366                    ServiceClientTracing.Error(_invocationId, ex);
 1367                }
 01368                _httpRequest.Dispose();
 01369                if (_httpResponse != null)
 1370                {
 01371                    _httpResponse.Dispose();
 1372                }
 01373                throw ex;
 1374            }
 1375            // Create Result
 01376            var _result = new HttpOperationResponse<OperationStatus>();
 01377            _result.Request = _httpRequest;
 01378            _result.Response = _httpResponse;
 1379            // Deserialize Response
 01380            if ((int)_statusCode == 200)
 1381            {
 01382                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1383                try
 1384                {
 01385                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 01386                }
 01387                catch (JsonException ex)
 1388                {
 01389                    _httpRequest.Dispose();
 01390                    if (_httpResponse != null)
 1391                    {
 01392                        _httpResponse.Dispose();
 1393                    }
 01394                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1395                }
 1396            }
 01397            if (_shouldTrace)
 1398            {
 01399                ServiceClientTracing.Exit(_invocationId, _result);
 1400            }
 01401            return _result;
 01402        }
 1403
 1404        /// <summary>
 1405        /// Imports a new version into a LUIS application.
 1406        /// </summary>
 1407        /// <param name='appId'>
 1408        /// The application ID.
 1409        /// </param>
 1410        /// <param name='luisAppV2'>
 1411        /// A LUIS application structure.
 1412        /// </param>
 1413        /// <param name='versionId'>
 1414        /// The new versionId to import. If not specified, the versionId will be read
 1415        /// from the imported object.
 1416        /// </param>
 1417        /// <param name='customHeaders'>
 1418        /// Headers that will be added to request.
 1419        /// </param>
 1420        /// <param name='cancellationToken'>
 1421        /// The cancellation token.
 1422        /// </param>
 1423        /// <exception cref="ErrorResponseException">
 1424        /// Thrown when the operation returned an invalid status code
 1425        /// </exception>
 1426        /// <exception cref="SerializationException">
 1427        /// Thrown when unable to deserialize the response
 1428        /// </exception>
 1429        /// <exception cref="ValidationException">
 1430        /// Thrown when a required parameter is null
 1431        /// </exception>
 1432        /// <exception cref="System.ArgumentNullException">
 1433        /// Thrown when a required parameter is null
 1434        /// </exception>
 1435        /// <return>
 1436        /// A response object containing the response body and response headers.
 1437        /// </return>
 1438        public async Task<HttpOperationResponse<string>> ImportV2AppWithHttpMessagesAsync(System.Guid appId, LuisAppV2 l
 1439        {
 11440            if (Client.Endpoint == null)
 1441            {
 01442                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1443            }
 11444            if (luisAppV2 == null)
 1445            {
 01446                throw new ValidationException(ValidationRules.CannotBeNull, "luisAppV2");
 1447            }
 1448            // Tracing
 11449            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 11450            string _invocationId = null;
 11451            if (_shouldTrace)
 1452            {
 01453                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01454                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01455                tracingParameters.Add("appId", appId);
 01456                tracingParameters.Add("versionId", versionId);
 01457                tracingParameters.Add("luisAppV2", luisAppV2);
 01458                tracingParameters.Add("cancellationToken", cancellationToken);
 01459                ServiceClientTracing.Enter(_invocationId, this, "ImportV2App", tracingParameters);
 1460            }
 1461            // Construct URL
 11462            var _baseUrl = Client.BaseUri;
 11463            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/import";
 11464            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 11465            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 11466            List<string> _queryParameters = new List<string>();
 11467            if (versionId != null)
 1468            {
 11469                _queryParameters.Add(string.Format("versionId={0}", System.Uri.EscapeDataString(versionId)));
 1470            }
 11471            if (_queryParameters.Count > 0)
 1472            {
 11473                _url += "?" + string.Join("&", _queryParameters);
 1474            }
 1475            // Create HTTP transport objects
 11476            var _httpRequest = new HttpRequestMessage();
 11477            HttpResponseMessage _httpResponse = null;
 11478            _httpRequest.Method = new HttpMethod("POST");
 11479            _httpRequest.RequestUri = new System.Uri(_url);
 1480            // Set Headers
 1481
 1482
 11483            if (customHeaders != null)
 1484            {
 01485                foreach(var _header in customHeaders)
 1486                {
 01487                    if (_httpRequest.Headers.Contains(_header.Key))
 1488                    {
 01489                        _httpRequest.Headers.Remove(_header.Key);
 1490                    }
 01491                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1492                }
 1493            }
 1494
 1495            // Serialize Request
 11496            string _requestContent = null;
 11497            if(luisAppV2 != null)
 1498            {
 11499                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisAppV2, Client.SerializationSett
 11500                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 11501                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1502            }
 1503            // Set Credentials
 11504            if (Client.Credentials != null)
 1505            {
 11506                cancellationToken.ThrowIfCancellationRequested();
 11507                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1508            }
 1509            // Send Request
 11510            if (_shouldTrace)
 1511            {
 01512                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1513            }
 11514            cancellationToken.ThrowIfCancellationRequested();
 11515            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 11516            if (_shouldTrace)
 1517            {
 01518                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1519            }
 11520            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 11521            cancellationToken.ThrowIfCancellationRequested();
 11522            string _responseContent = null;
 11523            if ((int)_statusCode != 201)
 1524            {
 01525                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1526                try
 1527                {
 01528                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01529                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01530                    if (_errorBody != null)
 1531                    {
 01532                        ex.Body = _errorBody;
 1533                    }
 01534                }
 01535                catch (JsonException)
 1536                {
 1537                    // Ignore the exception
 01538                }
 01539                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01540                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01541                if (_shouldTrace)
 1542                {
 01543                    ServiceClientTracing.Error(_invocationId, ex);
 1544                }
 01545                _httpRequest.Dispose();
 01546                if (_httpResponse != null)
 1547                {
 01548                    _httpResponse.Dispose();
 1549                }
 01550                throw ex;
 1551            }
 1552            // Create Result
 11553            var _result = new HttpOperationResponse<string>();
 11554            _result.Request = _httpRequest;
 11555            _result.Response = _httpResponse;
 1556            // Deserialize Response
 11557            if ((int)_statusCode == 201)
 1558            {
 11559                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1560                try
 1561                {
 11562                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 11563                }
 01564                catch (JsonException ex)
 1565                {
 01566                    _httpRequest.Dispose();
 01567                    if (_httpResponse != null)
 1568                    {
 01569                        _httpResponse.Dispose();
 1570                    }
 01571                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1572                }
 1573            }
 11574            if (_shouldTrace)
 1575            {
 01576                ServiceClientTracing.Exit(_invocationId, _result);
 1577            }
 11578            return _result;
 11579        }
 1580
 1581        /// <summary>
 1582        /// Imports a new version into a LUIS application.
 1583        /// </summary>
 1584        /// <param name='appId'>
 1585        /// The application ID.
 1586        /// </param>
 1587        /// <param name='luisAppLu'>
 1588        /// An LU representing the LUIS application structure.
 1589        /// </param>
 1590        /// <param name='versionId'>
 1591        /// The new versionId to import. If not specified, the versionId will be read
 1592        /// from the imported object.
 1593        /// </param>
 1594        /// <param name='customHeaders'>
 1595        /// Headers that will be added to request.
 1596        /// </param>
 1597        /// <param name='cancellationToken'>
 1598        /// The cancellation token.
 1599        /// </param>
 1600        /// <exception cref="ErrorResponseException">
 1601        /// Thrown when the operation returned an invalid status code
 1602        /// </exception>
 1603        /// <exception cref="SerializationException">
 1604        /// Thrown when unable to deserialize the response
 1605        /// </exception>
 1606        /// <exception cref="ValidationException">
 1607        /// Thrown when a required parameter is null
 1608        /// </exception>
 1609        /// <exception cref="System.ArgumentNullException">
 1610        /// Thrown when a required parameter is null
 1611        /// </exception>
 1612        /// <return>
 1613        /// A response object containing the response body and response headers.
 1614        /// </return>
 1615        public async Task<HttpOperationResponse<string>> ImportLuFormatWithHttpMessagesAsync(System.Guid appId, string l
 1616        {
 11617            if (Client.Endpoint == null)
 1618            {
 01619                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1620            }
 11621            if (luisAppLu == null)
 1622            {
 01623                throw new ValidationException(ValidationRules.CannotBeNull, "luisAppLu");
 1624            }
 1625            // Tracing
 11626            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 11627            string _invocationId = null;
 11628            if (_shouldTrace)
 1629            {
 01630                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01631                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01632                tracingParameters.Add("appId", appId);
 01633                tracingParameters.Add("versionId", versionId);
 01634                tracingParameters.Add("luisAppLu", luisAppLu);
 01635                tracingParameters.Add("cancellationToken", cancellationToken);
 01636                ServiceClientTracing.Enter(_invocationId, this, "ImportLuFormat", tracingParameters);
 1637            }
 1638            // Construct URL
 11639            var _baseUrl = Client.BaseUri;
 11640            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/import";
 11641            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 11642            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 11643            List<string> _queryParameters = new List<string>();
 11644            if (versionId != null)
 1645            {
 11646                _queryParameters.Add(string.Format("versionId={0}", System.Uri.EscapeDataString(versionId)));
 1647            }
 11648            if (_queryParameters.Count > 0)
 1649            {
 11650                _url += "?" + string.Join("&", _queryParameters);
 1651            }
 1652            // Create HTTP transport objects
 11653            var _httpRequest = new HttpRequestMessage();
 11654            HttpResponseMessage _httpResponse = null;
 11655            _httpRequest.Method = new HttpMethod("POST");
 11656            _httpRequest.RequestUri = new System.Uri(_url);
 1657            // Set Headers
 1658
 1659
 11660            if (customHeaders != null)
 1661            {
 01662                foreach(var _header in customHeaders)
 1663                {
 01664                    if (_httpRequest.Headers.Contains(_header.Key))
 1665                    {
 01666                        _httpRequest.Headers.Remove(_header.Key);
 1667                    }
 01668                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1669                }
 1670            }
 1671
 1672            // Serialize Request
 11673            string _requestContent = null;
 11674            if(luisAppLu != null)
 1675            {
 11676                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(luisAppLu, Client.SerializationSett
 11677                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 11678                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("text/plain
 1679            }
 1680            // Set Credentials
 11681            if (Client.Credentials != null)
 1682            {
 11683                cancellationToken.ThrowIfCancellationRequested();
 11684                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1685            }
 1686            // Send Request
 11687            if (_shouldTrace)
 1688            {
 01689                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1690            }
 11691            cancellationToken.ThrowIfCancellationRequested();
 11692            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 11693            if (_shouldTrace)
 1694            {
 01695                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1696            }
 11697            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 11698            cancellationToken.ThrowIfCancellationRequested();
 11699            string _responseContent = null;
 11700            if ((int)_statusCode != 201)
 1701            {
 01702                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1703                try
 1704                {
 01705                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01706                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01707                    if (_errorBody != null)
 1708                    {
 01709                        ex.Body = _errorBody;
 1710                    }
 01711                }
 01712                catch (JsonException)
 1713                {
 1714                    // Ignore the exception
 01715                }
 01716                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01717                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01718                if (_shouldTrace)
 1719                {
 01720                    ServiceClientTracing.Error(_invocationId, ex);
 1721                }
 01722                _httpRequest.Dispose();
 01723                if (_httpResponse != null)
 1724                {
 01725                    _httpResponse.Dispose();
 1726                }
 01727                throw ex;
 1728            }
 1729            // Create Result
 11730            var _result = new HttpOperationResponse<string>();
 11731            _result.Request = _httpRequest;
 11732            _result.Response = _httpResponse;
 1733            // Deserialize Response
 11734            if ((int)_statusCode == 201)
 1735            {
 11736                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1737                try
 1738                {
 11739                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client
 11740                }
 01741                catch (JsonException ex)
 1742                {
 01743                    _httpRequest.Dispose();
 01744                    if (_httpResponse != null)
 1745                    {
 01746                        _httpResponse.Dispose();
 1747                    }
 01748                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1749                }
 1750            }
 11751            if (_shouldTrace)
 1752            {
 01753                ServiceClientTracing.Exit(_invocationId, _result);
 1754            }
 11755            return _result;
 11756        }
 1757
 1758        /// <summary>
 1759        /// Exports a LUIS application to text format.
 1760        /// </summary>
 1761        /// <param name='appId'>
 1762        /// The application ID.
 1763        /// </param>
 1764        /// <param name='versionId'>
 1765        /// The version ID.
 1766        /// </param>
 1767        /// <param name='customHeaders'>
 1768        /// Headers that will be added to request.
 1769        /// </param>
 1770        /// <param name='cancellationToken'>
 1771        /// The cancellation token.
 1772        /// </param>
 1773        /// <exception cref="HttpOperationException">
 1774        /// Thrown when the operation returned an invalid status code
 1775        /// </exception>
 1776        /// <exception cref="SerializationException">
 1777        /// Thrown when unable to deserialize the response
 1778        /// </exception>
 1779        /// <exception cref="ValidationException">
 1780        /// Thrown when a required parameter is null
 1781        /// </exception>
 1782        /// <exception cref="System.ArgumentNullException">
 1783        /// Thrown when a required parameter is null
 1784        /// </exception>
 1785        /// <return>
 1786        /// A response object containing the response body and response headers.
 1787        /// </return>
 1788        public async Task<HttpOperationResponse<Stream>> ExportLuFormatWithHttpMessagesAsync(System.Guid appId, string v
 1789        {
 11790            if (Client.Endpoint == null)
 1791            {
 01792                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1793            }
 11794            if (versionId == null)
 1795            {
 01796                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 1797            }
 11798            string format = "lu";
 1799            // Tracing
 11800            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 11801            string _invocationId = null;
 11802            if (_shouldTrace)
 1803            {
 01804                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01805                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01806                tracingParameters.Add("format", format);
 01807                tracingParameters.Add("appId", appId);
 01808                tracingParameters.Add("versionId", versionId);
 01809                tracingParameters.Add("cancellationToken", cancellationToken);
 01810                ServiceClientTracing.Enter(_invocationId, this, "ExportLuFormat", tracingParameters);
 1811            }
 1812            // Construct URL
 11813            var _baseUrl = Client.BaseUri;
 11814            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/export";
 11815            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 11816            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 11817            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 11818            List<string> _queryParameters = new List<string>();
 11819            if (format != null)
 1820            {
 11821                _queryParameters.Add(string.Format("format={0}", System.Uri.EscapeDataString(format)));
 1822            }
 11823            if (_queryParameters.Count > 0)
 1824            {
 11825                _url += "?" + string.Join("&", _queryParameters);
 1826            }
 1827            // Create HTTP transport objects
 11828            var _httpRequest = new HttpRequestMessage();
 11829            HttpResponseMessage _httpResponse = null;
 11830            _httpRequest.Method = new HttpMethod("GET");
 11831            _httpRequest.RequestUri = new System.Uri(_url);
 1832            // Set Headers
 1833
 1834
 11835            if (customHeaders != null)
 1836            {
 01837                foreach(var _header in customHeaders)
 1838                {
 01839                    if (_httpRequest.Headers.Contains(_header.Key))
 1840                    {
 01841                        _httpRequest.Headers.Remove(_header.Key);
 1842                    }
 01843                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1844                }
 1845            }
 1846
 1847            // Serialize Request
 11848            string _requestContent = null;
 1849            // Set Credentials
 11850            if (Client.Credentials != null)
 1851            {
 11852                cancellationToken.ThrowIfCancellationRequested();
 11853                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1854            }
 1855            // Send Request
 11856            if (_shouldTrace)
 1857            {
 01858                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1859            }
 11860            cancellationToken.ThrowIfCancellationRequested();
 11861            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 11862            if (_shouldTrace)
 1863            {
 01864                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1865            }
 11866            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 11867            cancellationToken.ThrowIfCancellationRequested();
 11868            string _responseContent = null;
 11869            if ((int)_statusCode != 200)
 1870            {
 01871                var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st
 01872                if (_httpResponse.Content != null) {
 01873                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1874                }
 1875                else {
 01876                    _responseContent = string.Empty;
 1877                }
 01878                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01879                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01880                if (_shouldTrace)
 1881                {
 01882                    ServiceClientTracing.Error(_invocationId, ex);
 1883                }
 01884                _httpRequest.Dispose();
 01885                if (_httpResponse != null)
 1886                {
 01887                    _httpResponse.Dispose();
 1888                }
 01889                throw ex;
 1890            }
 1891            // Create Result
 11892            var _result = new HttpOperationResponse<Stream>();
 11893            _result.Request = _httpRequest;
 11894            _result.Response = _httpResponse;
 1895            // Deserialize Response
 11896            if ((int)_statusCode == 200)
 1897            {
 11898                _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
 1899            }
 11900            if (_shouldTrace)
 1901            {
 01902                ServiceClientTracing.Exit(_invocationId, _result);
 1903            }
 11904            return _result;
 11905        }
 1906
 1907    }
 1908}