< Summary

Class:Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring.Pattern
Assembly:Microsoft.Azure.CognitiveServices.Language.LUIS.Authoring
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.LUIS.Authoring\src\Generated\Pattern.cs
Covered lines:349
Uncovered lines:312
Coverable lines:661
Total lines:1470
Line coverage:52.7% (349 of 661)
Covered branches:138
Total branches:318
Branch coverage:43.3% (138 of 318)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
AddPatternWithHttpMessagesAsync()-52.5%42.11%
ListPatternsWithHttpMessagesAsync()-53.41%47.83%
UpdatePatternsWithHttpMessagesAsync()-52.5%42.11%
BatchAddPatternsWithHttpMessagesAsync()-52.5%42.11%
DeletePatternsWithHttpMessagesAsync()-52.5%42.11%
UpdatePatternWithHttpMessagesAsync()-52.44%42.11%
DeletePatternWithHttpMessagesAsync()-50.67%38.24%
ListIntentPatternsWithHttpMessagesAsync()-53.33%47.83%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Language.LUIS.Authoring\src\Generated\Pattern.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    /// Pattern operations.
 27    /// </summary>
 28    public partial class Pattern : IServiceOperations<LUISAuthoringClient>, IPattern
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the Pattern 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 Pattern(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>
 36051        public LUISAuthoringClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Adds a pattern to a version of the application.
 55        /// </summary>
 56        /// <param name='appId'>
 57        /// The application ID.
 58        /// </param>
 59        /// <param name='versionId'>
 60        /// The version ID.
 61        /// </param>
 62        /// <param name='pattern'>
 63        /// The input pattern.
 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<PatternRuleInfo>> AddPatternWithHttpMessagesAsync(System.Guid appId, str
 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 (pattern == null)
 97            {
 098                throw new ValidationException(ValidationRules.CannotBeNull, "pattern");
 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("pattern", pattern);
 0110                tracingParameters.Add("cancellationToken", cancellationToken);
 0111                ServiceClientTracing.Enter(_invocationId, this, "AddPattern", tracingParameters);
 112            }
 113            // Construct URL
 3114            var _baseUrl = Client.BaseUri;
 3115            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrule";
 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(pattern != null)
 142            {
 3143                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(pattern, Client.SerializationSettin
 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            {
 0169                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 170                try
 171                {
 0172                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0173                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0174                    if (_errorBody != null)
 175                    {
 0176                        ex.Body = _errorBody;
 177                    }
 0178                }
 0179                catch (JsonException)
 180                {
 181                    // Ignore the exception
 0182                }
 0183                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0184                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0185                if (_shouldTrace)
 186                {
 0187                    ServiceClientTracing.Error(_invocationId, ex);
 188                }
 0189                _httpRequest.Dispose();
 0190                if (_httpResponse != null)
 191                {
 0192                    _httpResponse.Dispose();
 193                }
 0194                throw ex;
 195            }
 196            // Create Result
 3197            var _result = new HttpOperationResponse<PatternRuleInfo>();
 3198            _result.Request = _httpRequest;
 3199            _result.Response = _httpResponse;
 200            // Deserialize Response
 3201            if ((int)_statusCode == 201)
 202            {
 3203                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 204                try
 205                {
 3206                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PatternRuleInfo>(_responseConten
 3207                }
 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            }
 3218            if (_shouldTrace)
 219            {
 0220                ServiceClientTracing.Exit(_invocationId, _result);
 221            }
 3222            return _result;
 3223        }
 224
 225        /// <summary>
 226        /// Gets patterns in a version of the application.
 227        /// </summary>
 228        /// <param name='appId'>
 229        /// The application ID.
 230        /// </param>
 231        /// <param name='versionId'>
 232        /// The version ID.
 233        /// </param>
 234        /// <param name='skip'>
 235        /// The number of entries to skip. Default value is 0.
 236        /// </param>
 237        /// <param name='take'>
 238        /// The number of entries to return. Maximum page size is 500. Default is 100.
 239        /// </param>
 240        /// <param name='customHeaders'>
 241        /// Headers that will be added to request.
 242        /// </param>
 243        /// <param name='cancellationToken'>
 244        /// The cancellation token.
 245        /// </param>
 246        /// <exception cref="ErrorResponseException">
 247        /// Thrown when the operation returned an invalid status code
 248        /// </exception>
 249        /// <exception cref="SerializationException">
 250        /// Thrown when unable to deserialize the response
 251        /// </exception>
 252        /// <exception cref="ValidationException">
 253        /// Thrown when a required parameter is null
 254        /// </exception>
 255        /// <exception cref="System.ArgumentNullException">
 256        /// Thrown when a required parameter is null
 257        /// </exception>
 258        /// <return>
 259        /// A response object containing the response body and response headers.
 260        /// </return>
 261        public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> ListPatternsWithHttpMessagesAsync(System.Guid a
 262        {
 3263            if (Client.Endpoint == null)
 264            {
 0265                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 266            }
 3267            if (versionId == null)
 268            {
 0269                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 270            }
 3271            if (skip < 0)
 272            {
 0273                throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0);
 274            }
 3275            if (take > 500)
 276            {
 0277                throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500);
 278            }
 3279            if (take < 0)
 280            {
 0281                throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0);
 282            }
 283            // Tracing
 3284            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 3285            string _invocationId = null;
 3286            if (_shouldTrace)
 287            {
 0288                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0289                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0290                tracingParameters.Add("appId", appId);
 0291                tracingParameters.Add("versionId", versionId);
 0292                tracingParameters.Add("skip", skip);
 0293                tracingParameters.Add("take", take);
 0294                tracingParameters.Add("cancellationToken", cancellationToken);
 0295                ServiceClientTracing.Enter(_invocationId, this, "ListPatterns", tracingParameters);
 296            }
 297            // Construct URL
 3298            var _baseUrl = Client.BaseUri;
 3299            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules"
 3300            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 3301            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 3302            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 3303            List<string> _queryParameters = new List<string>();
 3304            if (skip != null)
 305            {
 3306                _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 307            }
 3308            if (take != null)
 309            {
 3310                _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 311            }
 3312            if (_queryParameters.Count > 0)
 313            {
 3314                _url += "?" + string.Join("&", _queryParameters);
 315            }
 316            // Create HTTP transport objects
 3317            var _httpRequest = new HttpRequestMessage();
 3318            HttpResponseMessage _httpResponse = null;
 3319            _httpRequest.Method = new HttpMethod("GET");
 3320            _httpRequest.RequestUri = new System.Uri(_url);
 321            // Set Headers
 322
 323
 3324            if (customHeaders != null)
 325            {
 0326                foreach(var _header in customHeaders)
 327                {
 0328                    if (_httpRequest.Headers.Contains(_header.Key))
 329                    {
 0330                        _httpRequest.Headers.Remove(_header.Key);
 331                    }
 0332                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 333                }
 334            }
 335
 336            // Serialize Request
 3337            string _requestContent = null;
 338            // Set Credentials
 3339            if (Client.Credentials != null)
 340            {
 3341                cancellationToken.ThrowIfCancellationRequested();
 3342                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 343            }
 344            // Send Request
 3345            if (_shouldTrace)
 346            {
 0347                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 348            }
 3349            cancellationToken.ThrowIfCancellationRequested();
 3350            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3351            if (_shouldTrace)
 352            {
 0353                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 354            }
 3355            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 3356            cancellationToken.ThrowIfCancellationRequested();
 3357            string _responseContent = null;
 3358            if ((int)_statusCode != 200)
 359            {
 0360                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 361                try
 362                {
 0363                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0364                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0365                    if (_errorBody != null)
 366                    {
 0367                        ex.Body = _errorBody;
 368                    }
 0369                }
 0370                catch (JsonException)
 371                {
 372                    // Ignore the exception
 0373                }
 0374                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0375                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0376                if (_shouldTrace)
 377                {
 0378                    ServiceClientTracing.Error(_invocationId, ex);
 379                }
 0380                _httpRequest.Dispose();
 0381                if (_httpResponse != null)
 382                {
 0383                    _httpResponse.Dispose();
 384                }
 0385                throw ex;
 386            }
 387            // Create Result
 3388            var _result = new HttpOperationResponse<IList<PatternRuleInfo>>();
 3389            _result.Request = _httpRequest;
 3390            _result.Response = _httpResponse;
 391            // Deserialize Response
 3392            if ((int)_statusCode == 200)
 393            {
 3394                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 395                try
 396                {
 3397                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons
 3398                }
 0399                catch (JsonException ex)
 400                {
 0401                    _httpRequest.Dispose();
 0402                    if (_httpResponse != null)
 403                    {
 0404                        _httpResponse.Dispose();
 405                    }
 0406                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 407                }
 408            }
 3409            if (_shouldTrace)
 410            {
 0411                ServiceClientTracing.Exit(_invocationId, _result);
 412            }
 3413            return _result;
 3414        }
 415
 416        /// <summary>
 417        /// Updates patterns in a version of the application.
 418        /// </summary>
 419        /// <param name='appId'>
 420        /// The application ID.
 421        /// </param>
 422        /// <param name='versionId'>
 423        /// The version ID.
 424        /// </param>
 425        /// <param name='patterns'>
 426        /// An array represents the patterns.
 427        /// </param>
 428        /// <param name='customHeaders'>
 429        /// Headers that will be added to request.
 430        /// </param>
 431        /// <param name='cancellationToken'>
 432        /// The cancellation token.
 433        /// </param>
 434        /// <exception cref="ErrorResponseException">
 435        /// Thrown when the operation returned an invalid status code
 436        /// </exception>
 437        /// <exception cref="SerializationException">
 438        /// Thrown when unable to deserialize the response
 439        /// </exception>
 440        /// <exception cref="ValidationException">
 441        /// Thrown when a required parameter is null
 442        /// </exception>
 443        /// <exception cref="System.ArgumentNullException">
 444        /// Thrown when a required parameter is null
 445        /// </exception>
 446        /// <return>
 447        /// A response object containing the response body and response headers.
 448        /// </return>
 449        public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> UpdatePatternsWithHttpMessagesAsync(System.Guid
 450        {
 1451            if (Client.Endpoint == null)
 452            {
 0453                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 454            }
 1455            if (versionId == null)
 456            {
 0457                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 458            }
 1459            if (patterns == null)
 460            {
 0461                throw new ValidationException(ValidationRules.CannotBeNull, "patterns");
 462            }
 463            // Tracing
 1464            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 1465            string _invocationId = null;
 1466            if (_shouldTrace)
 467            {
 0468                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0469                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0470                tracingParameters.Add("appId", appId);
 0471                tracingParameters.Add("versionId", versionId);
 0472                tracingParameters.Add("patterns", patterns);
 0473                tracingParameters.Add("cancellationToken", cancellationToken);
 0474                ServiceClientTracing.Enter(_invocationId, this, "UpdatePatterns", tracingParameters);
 475            }
 476            // Construct URL
 1477            var _baseUrl = Client.BaseUri;
 1478            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules"
 1479            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 1480            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 1481            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 482            // Create HTTP transport objects
 1483            var _httpRequest = new HttpRequestMessage();
 1484            HttpResponseMessage _httpResponse = null;
 1485            _httpRequest.Method = new HttpMethod("PUT");
 1486            _httpRequest.RequestUri = new System.Uri(_url);
 487            // Set Headers
 488
 489
 1490            if (customHeaders != null)
 491            {
 0492                foreach(var _header in customHeaders)
 493                {
 0494                    if (_httpRequest.Headers.Contains(_header.Key))
 495                    {
 0496                        _httpRequest.Headers.Remove(_header.Key);
 497                    }
 0498                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 499                }
 500            }
 501
 502            // Serialize Request
 1503            string _requestContent = null;
 1504            if(patterns != null)
 505            {
 1506                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(patterns, Client.SerializationSetti
 1507                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 1508                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 509            }
 510            // Set Credentials
 1511            if (Client.Credentials != null)
 512            {
 1513                cancellationToken.ThrowIfCancellationRequested();
 1514                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 515            }
 516            // Send Request
 1517            if (_shouldTrace)
 518            {
 0519                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 520            }
 1521            cancellationToken.ThrowIfCancellationRequested();
 1522            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1523            if (_shouldTrace)
 524            {
 0525                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 526            }
 1527            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 1528            cancellationToken.ThrowIfCancellationRequested();
 1529            string _responseContent = null;
 1530            if ((int)_statusCode != 200)
 531            {
 0532                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 533                try
 534                {
 0535                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0536                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0537                    if (_errorBody != null)
 538                    {
 0539                        ex.Body = _errorBody;
 540                    }
 0541                }
 0542                catch (JsonException)
 543                {
 544                    // Ignore the exception
 0545                }
 0546                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0547                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0548                if (_shouldTrace)
 549                {
 0550                    ServiceClientTracing.Error(_invocationId, ex);
 551                }
 0552                _httpRequest.Dispose();
 0553                if (_httpResponse != null)
 554                {
 0555                    _httpResponse.Dispose();
 556                }
 0557                throw ex;
 558            }
 559            // Create Result
 1560            var _result = new HttpOperationResponse<IList<PatternRuleInfo>>();
 1561            _result.Request = _httpRequest;
 1562            _result.Response = _httpResponse;
 563            // Deserialize Response
 1564            if ((int)_statusCode == 200)
 565            {
 1566                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 567                try
 568                {
 1569                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons
 1570                }
 0571                catch (JsonException ex)
 572                {
 0573                    _httpRequest.Dispose();
 0574                    if (_httpResponse != null)
 575                    {
 0576                        _httpResponse.Dispose();
 577                    }
 0578                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 579                }
 580            }
 1581            if (_shouldTrace)
 582            {
 0583                ServiceClientTracing.Exit(_invocationId, _result);
 584            }
 1585            return _result;
 1586        }
 587
 588        /// <summary>
 589        /// Adds a batch of patterns in a version of the application.
 590        /// </summary>
 591        /// <param name='appId'>
 592        /// The application ID.
 593        /// </param>
 594        /// <param name='versionId'>
 595        /// The version ID.
 596        /// </param>
 597        /// <param name='patterns'>
 598        /// A JSON array containing patterns.
 599        /// </param>
 600        /// <param name='customHeaders'>
 601        /// Headers that will be added to request.
 602        /// </param>
 603        /// <param name='cancellationToken'>
 604        /// The cancellation token.
 605        /// </param>
 606        /// <exception cref="ErrorResponseException">
 607        /// Thrown when the operation returned an invalid status code
 608        /// </exception>
 609        /// <exception cref="SerializationException">
 610        /// Thrown when unable to deserialize the response
 611        /// </exception>
 612        /// <exception cref="ValidationException">
 613        /// Thrown when a required parameter is null
 614        /// </exception>
 615        /// <exception cref="System.ArgumentNullException">
 616        /// Thrown when a required parameter is null
 617        /// </exception>
 618        /// <return>
 619        /// A response object containing the response body and response headers.
 620        /// </return>
 621        public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> BatchAddPatternsWithHttpMessagesAsync(System.Gu
 622        {
 5623            if (Client.Endpoint == null)
 624            {
 0625                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 626            }
 5627            if (versionId == null)
 628            {
 0629                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 630            }
 5631            if (patterns == null)
 632            {
 0633                throw new ValidationException(ValidationRules.CannotBeNull, "patterns");
 634            }
 635            // Tracing
 5636            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 5637            string _invocationId = null;
 5638            if (_shouldTrace)
 639            {
 0640                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0641                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0642                tracingParameters.Add("appId", appId);
 0643                tracingParameters.Add("versionId", versionId);
 0644                tracingParameters.Add("patterns", patterns);
 0645                tracingParameters.Add("cancellationToken", cancellationToken);
 0646                ServiceClientTracing.Enter(_invocationId, this, "BatchAddPatterns", tracingParameters);
 647            }
 648            // Construct URL
 5649            var _baseUrl = Client.BaseUri;
 5650            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules"
 5651            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 5652            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 5653            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 654            // Create HTTP transport objects
 5655            var _httpRequest = new HttpRequestMessage();
 5656            HttpResponseMessage _httpResponse = null;
 5657            _httpRequest.Method = new HttpMethod("POST");
 5658            _httpRequest.RequestUri = new System.Uri(_url);
 659            // Set Headers
 660
 661
 5662            if (customHeaders != null)
 663            {
 0664                foreach(var _header in customHeaders)
 665                {
 0666                    if (_httpRequest.Headers.Contains(_header.Key))
 667                    {
 0668                        _httpRequest.Headers.Remove(_header.Key);
 669                    }
 0670                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 671                }
 672            }
 673
 674            // Serialize Request
 5675            string _requestContent = null;
 5676            if(patterns != null)
 677            {
 5678                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(patterns, Client.SerializationSetti
 5679                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 5680                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 681            }
 682            // Set Credentials
 5683            if (Client.Credentials != null)
 684            {
 5685                cancellationToken.ThrowIfCancellationRequested();
 5686                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 687            }
 688            // Send Request
 5689            if (_shouldTrace)
 690            {
 0691                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 692            }
 5693            cancellationToken.ThrowIfCancellationRequested();
 5694            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 5695            if (_shouldTrace)
 696            {
 0697                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 698            }
 5699            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 5700            cancellationToken.ThrowIfCancellationRequested();
 5701            string _responseContent = null;
 5702            if ((int)_statusCode != 201)
 703            {
 0704                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 705                try
 706                {
 0707                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0708                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0709                    if (_errorBody != null)
 710                    {
 0711                        ex.Body = _errorBody;
 712                    }
 0713                }
 0714                catch (JsonException)
 715                {
 716                    // Ignore the exception
 0717                }
 0718                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0719                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0720                if (_shouldTrace)
 721                {
 0722                    ServiceClientTracing.Error(_invocationId, ex);
 723                }
 0724                _httpRequest.Dispose();
 0725                if (_httpResponse != null)
 726                {
 0727                    _httpResponse.Dispose();
 728                }
 0729                throw ex;
 730            }
 731            // Create Result
 5732            var _result = new HttpOperationResponse<IList<PatternRuleInfo>>();
 5733            _result.Request = _httpRequest;
 5734            _result.Response = _httpResponse;
 735            // Deserialize Response
 5736            if ((int)_statusCode == 201)
 737            {
 5738                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 739                try
 740                {
 5741                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons
 5742                }
 0743                catch (JsonException ex)
 744                {
 0745                    _httpRequest.Dispose();
 0746                    if (_httpResponse != null)
 747                    {
 0748                        _httpResponse.Dispose();
 749                    }
 0750                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 751                }
 752            }
 5753            if (_shouldTrace)
 754            {
 0755                ServiceClientTracing.Exit(_invocationId, _result);
 756            }
 5757            return _result;
 5758        }
 759
 760        /// <summary>
 761        /// Deletes a list of patterns in a version of the application.
 762        /// </summary>
 763        /// <param name='appId'>
 764        /// The application ID.
 765        /// </param>
 766        /// <param name='versionId'>
 767        /// The version ID.
 768        /// </param>
 769        /// <param name='patternIds'>
 770        /// The patterns IDs.
 771        /// </param>
 772        /// <param name='customHeaders'>
 773        /// Headers that will be added to request.
 774        /// </param>
 775        /// <param name='cancellationToken'>
 776        /// The cancellation token.
 777        /// </param>
 778        /// <exception cref="ErrorResponseException">
 779        /// Thrown when the operation returned an invalid status code
 780        /// </exception>
 781        /// <exception cref="SerializationException">
 782        /// Thrown when unable to deserialize the response
 783        /// </exception>
 784        /// <exception cref="ValidationException">
 785        /// Thrown when a required parameter is null
 786        /// </exception>
 787        /// <exception cref="System.ArgumentNullException">
 788        /// Thrown when a required parameter is null
 789        /// </exception>
 790        /// <return>
 791        /// A response object containing the response body and response headers.
 792        /// </return>
 793        public async Task<HttpOperationResponse<OperationStatus>> DeletePatternsWithHttpMessagesAsync(System.Guid appId,
 794        {
 5795            if (Client.Endpoint == null)
 796            {
 0797                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 798            }
 5799            if (versionId == null)
 800            {
 0801                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 802            }
 5803            if (patternIds == null)
 804            {
 0805                throw new ValidationException(ValidationRules.CannotBeNull, "patternIds");
 806            }
 807            // Tracing
 5808            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 5809            string _invocationId = null;
 5810            if (_shouldTrace)
 811            {
 0812                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0813                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0814                tracingParameters.Add("appId", appId);
 0815                tracingParameters.Add("versionId", versionId);
 0816                tracingParameters.Add("patternIds", patternIds);
 0817                tracingParameters.Add("cancellationToken", cancellationToken);
 0818                ServiceClientTracing.Enter(_invocationId, this, "DeletePatterns", tracingParameters);
 819            }
 820            // Construct URL
 5821            var _baseUrl = Client.BaseUri;
 5822            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules"
 5823            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 5824            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 5825            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 826            // Create HTTP transport objects
 5827            var _httpRequest = new HttpRequestMessage();
 5828            HttpResponseMessage _httpResponse = null;
 5829            _httpRequest.Method = new HttpMethod("DELETE");
 5830            _httpRequest.RequestUri = new System.Uri(_url);
 831            // Set Headers
 832
 833
 5834            if (customHeaders != null)
 835            {
 0836                foreach(var _header in customHeaders)
 837                {
 0838                    if (_httpRequest.Headers.Contains(_header.Key))
 839                    {
 0840                        _httpRequest.Headers.Remove(_header.Key);
 841                    }
 0842                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 843                }
 844            }
 845
 846            // Serialize Request
 5847            string _requestContent = null;
 5848            if(patternIds != null)
 849            {
 5850                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(patternIds, Client.SerializationSet
 5851                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 5852                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 853            }
 854            // Set Credentials
 5855            if (Client.Credentials != null)
 856            {
 5857                cancellationToken.ThrowIfCancellationRequested();
 5858                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 859            }
 860            // Send Request
 5861            if (_shouldTrace)
 862            {
 0863                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 864            }
 5865            cancellationToken.ThrowIfCancellationRequested();
 5866            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 5867            if (_shouldTrace)
 868            {
 0869                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 870            }
 5871            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 5872            cancellationToken.ThrowIfCancellationRequested();
 5873            string _responseContent = null;
 5874            if ((int)_statusCode != 200)
 875            {
 0876                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 877                try
 878                {
 0879                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0880                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 0881                    if (_errorBody != null)
 882                    {
 0883                        ex.Body = _errorBody;
 884                    }
 0885                }
 0886                catch (JsonException)
 887                {
 888                    // Ignore the exception
 0889                }
 0890                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0891                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0892                if (_shouldTrace)
 893                {
 0894                    ServiceClientTracing.Error(_invocationId, ex);
 895                }
 0896                _httpRequest.Dispose();
 0897                if (_httpResponse != null)
 898                {
 0899                    _httpResponse.Dispose();
 900                }
 0901                throw ex;
 902            }
 903            // Create Result
 5904            var _result = new HttpOperationResponse<OperationStatus>();
 5905            _result.Request = _httpRequest;
 5906            _result.Response = _httpResponse;
 907            // Deserialize Response
 5908            if ((int)_statusCode == 200)
 909            {
 5910                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 911                try
 912                {
 5913                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 5914                }
 0915                catch (JsonException ex)
 916                {
 0917                    _httpRequest.Dispose();
 0918                    if (_httpResponse != null)
 919                    {
 0920                        _httpResponse.Dispose();
 921                    }
 0922                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 923                }
 924            }
 5925            if (_shouldTrace)
 926            {
 0927                ServiceClientTracing.Exit(_invocationId, _result);
 928            }
 5929            return _result;
 5930        }
 931
 932        /// <summary>
 933        /// Updates a pattern in a version of the application.
 934        /// </summary>
 935        /// <param name='appId'>
 936        /// The application ID.
 937        /// </param>
 938        /// <param name='versionId'>
 939        /// The version ID.
 940        /// </param>
 941        /// <param name='patternId'>
 942        /// The pattern ID.
 943        /// </param>
 944        /// <param name='pattern'>
 945        /// An object representing a pattern.
 946        /// </param>
 947        /// <param name='customHeaders'>
 948        /// Headers that will be added to request.
 949        /// </param>
 950        /// <param name='cancellationToken'>
 951        /// The cancellation token.
 952        /// </param>
 953        /// <exception cref="ErrorResponseException">
 954        /// Thrown when the operation returned an invalid status code
 955        /// </exception>
 956        /// <exception cref="SerializationException">
 957        /// Thrown when unable to deserialize the response
 958        /// </exception>
 959        /// <exception cref="ValidationException">
 960        /// Thrown when a required parameter is null
 961        /// </exception>
 962        /// <exception cref="System.ArgumentNullException">
 963        /// Thrown when a required parameter is null
 964        /// </exception>
 965        /// <return>
 966        /// A response object containing the response body and response headers.
 967        /// </return>
 968        public async Task<HttpOperationResponse<PatternRuleInfo>> UpdatePatternWithHttpMessagesAsync(System.Guid appId, 
 969        {
 1970            if (Client.Endpoint == null)
 971            {
 0972                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 973            }
 1974            if (versionId == null)
 975            {
 0976                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 977            }
 1978            if (pattern == null)
 979            {
 0980                throw new ValidationException(ValidationRules.CannotBeNull, "pattern");
 981            }
 982            // Tracing
 1983            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 1984            string _invocationId = null;
 1985            if (_shouldTrace)
 986            {
 0987                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0988                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0989                tracingParameters.Add("appId", appId);
 0990                tracingParameters.Add("versionId", versionId);
 0991                tracingParameters.Add("patternId", patternId);
 0992                tracingParameters.Add("pattern", pattern);
 0993                tracingParameters.Add("cancellationToken", cancellationToken);
 0994                ServiceClientTracing.Enter(_invocationId, this, "UpdatePattern", tracingParameters);
 995            }
 996            // Construct URL
 1997            var _baseUrl = Client.BaseUri;
 1998            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules/
 1999            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 11000            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 11001            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 11002            _url = _url.Replace("{patternId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 1003            // Create HTTP transport objects
 11004            var _httpRequest = new HttpRequestMessage();
 11005            HttpResponseMessage _httpResponse = null;
 11006            _httpRequest.Method = new HttpMethod("PUT");
 11007            _httpRequest.RequestUri = new System.Uri(_url);
 1008            // Set Headers
 1009
 1010
 11011            if (customHeaders != null)
 1012            {
 01013                foreach(var _header in customHeaders)
 1014                {
 01015                    if (_httpRequest.Headers.Contains(_header.Key))
 1016                    {
 01017                        _httpRequest.Headers.Remove(_header.Key);
 1018                    }
 01019                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1020                }
 1021            }
 1022
 1023            // Serialize Request
 11024            string _requestContent = null;
 11025            if(pattern != null)
 1026            {
 11027                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(pattern, Client.SerializationSettin
 11028                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 11029                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1030            }
 1031            // Set Credentials
 11032            if (Client.Credentials != null)
 1033            {
 11034                cancellationToken.ThrowIfCancellationRequested();
 11035                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1036            }
 1037            // Send Request
 11038            if (_shouldTrace)
 1039            {
 01040                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1041            }
 11042            cancellationToken.ThrowIfCancellationRequested();
 11043            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 11044            if (_shouldTrace)
 1045            {
 01046                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1047            }
 11048            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 11049            cancellationToken.ThrowIfCancellationRequested();
 11050            string _responseContent = null;
 11051            if ((int)_statusCode != 200)
 1052            {
 01053                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1054                try
 1055                {
 01056                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01057                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01058                    if (_errorBody != null)
 1059                    {
 01060                        ex.Body = _errorBody;
 1061                    }
 01062                }
 01063                catch (JsonException)
 1064                {
 1065                    // Ignore the exception
 01066                }
 01067                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01068                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01069                if (_shouldTrace)
 1070                {
 01071                    ServiceClientTracing.Error(_invocationId, ex);
 1072                }
 01073                _httpRequest.Dispose();
 01074                if (_httpResponse != null)
 1075                {
 01076                    _httpResponse.Dispose();
 1077                }
 01078                throw ex;
 1079            }
 1080            // Create Result
 11081            var _result = new HttpOperationResponse<PatternRuleInfo>();
 11082            _result.Request = _httpRequest;
 11083            _result.Response = _httpResponse;
 1084            // Deserialize Response
 11085            if ((int)_statusCode == 200)
 1086            {
 11087                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1088                try
 1089                {
 11090                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PatternRuleInfo>(_responseConten
 11091                }
 01092                catch (JsonException ex)
 1093                {
 01094                    _httpRequest.Dispose();
 01095                    if (_httpResponse != null)
 1096                    {
 01097                        _httpResponse.Dispose();
 1098                    }
 01099                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1100                }
 1101            }
 11102            if (_shouldTrace)
 1103            {
 01104                ServiceClientTracing.Exit(_invocationId, _result);
 1105            }
 11106            return _result;
 11107        }
 1108
 1109        /// <summary>
 1110        /// Deletes the pattern with the specified ID from a version of the
 1111        /// application..
 1112        /// </summary>
 1113        /// <param name='appId'>
 1114        /// The application ID.
 1115        /// </param>
 1116        /// <param name='versionId'>
 1117        /// The version ID.
 1118        /// </param>
 1119        /// <param name='patternId'>
 1120        /// The pattern ID.
 1121        /// </param>
 1122        /// <param name='customHeaders'>
 1123        /// Headers that will be added to request.
 1124        /// </param>
 1125        /// <param name='cancellationToken'>
 1126        /// The cancellation token.
 1127        /// </param>
 1128        /// <exception cref="ErrorResponseException">
 1129        /// Thrown when the operation returned an invalid status code
 1130        /// </exception>
 1131        /// <exception cref="SerializationException">
 1132        /// Thrown when unable to deserialize the response
 1133        /// </exception>
 1134        /// <exception cref="ValidationException">
 1135        /// Thrown when a required parameter is null
 1136        /// </exception>
 1137        /// <exception cref="System.ArgumentNullException">
 1138        /// Thrown when a required parameter is null
 1139        /// </exception>
 1140        /// <return>
 1141        /// A response object containing the response body and response headers.
 1142        /// </return>
 1143        public async Task<HttpOperationResponse<OperationStatus>> DeletePatternWithHttpMessagesAsync(System.Guid appId, 
 1144        {
 31145            if (Client.Endpoint == null)
 1146            {
 01147                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1148            }
 31149            if (versionId == null)
 1150            {
 01151                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 1152            }
 1153            // Tracing
 31154            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 31155            string _invocationId = null;
 31156            if (_shouldTrace)
 1157            {
 01158                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01159                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01160                tracingParameters.Add("appId", appId);
 01161                tracingParameters.Add("versionId", versionId);
 01162                tracingParameters.Add("patternId", patternId);
 01163                tracingParameters.Add("cancellationToken", cancellationToken);
 01164                ServiceClientTracing.Enter(_invocationId, this, "DeletePattern", tracingParameters);
 1165            }
 1166            // Construct URL
 31167            var _baseUrl = Client.BaseUri;
 31168            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/patternrules/
 31169            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 31170            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 31171            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 31172            _url = _url.Replace("{patternId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO
 1173            // Create HTTP transport objects
 31174            var _httpRequest = new HttpRequestMessage();
 31175            HttpResponseMessage _httpResponse = null;
 31176            _httpRequest.Method = new HttpMethod("DELETE");
 31177            _httpRequest.RequestUri = new System.Uri(_url);
 1178            // Set Headers
 1179
 1180
 31181            if (customHeaders != null)
 1182            {
 01183                foreach(var _header in customHeaders)
 1184                {
 01185                    if (_httpRequest.Headers.Contains(_header.Key))
 1186                    {
 01187                        _httpRequest.Headers.Remove(_header.Key);
 1188                    }
 01189                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1190                }
 1191            }
 1192
 1193            // Serialize Request
 31194            string _requestContent = null;
 1195            // Set Credentials
 31196            if (Client.Credentials != null)
 1197            {
 31198                cancellationToken.ThrowIfCancellationRequested();
 31199                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1200            }
 1201            // Send Request
 31202            if (_shouldTrace)
 1203            {
 01204                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1205            }
 31206            cancellationToken.ThrowIfCancellationRequested();
 31207            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 31208            if (_shouldTrace)
 1209            {
 01210                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1211            }
 31212            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 31213            cancellationToken.ThrowIfCancellationRequested();
 31214            string _responseContent = null;
 31215            if ((int)_statusCode != 200)
 1216            {
 01217                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1218                try
 1219                {
 01220                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01221                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01222                    if (_errorBody != null)
 1223                    {
 01224                        ex.Body = _errorBody;
 1225                    }
 01226                }
 01227                catch (JsonException)
 1228                {
 1229                    // Ignore the exception
 01230                }
 01231                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01232                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01233                if (_shouldTrace)
 1234                {
 01235                    ServiceClientTracing.Error(_invocationId, ex);
 1236                }
 01237                _httpRequest.Dispose();
 01238                if (_httpResponse != null)
 1239                {
 01240                    _httpResponse.Dispose();
 1241                }
 01242                throw ex;
 1243            }
 1244            // Create Result
 31245            var _result = new HttpOperationResponse<OperationStatus>();
 31246            _result.Request = _httpRequest;
 31247            _result.Response = _httpResponse;
 1248            // Deserialize Response
 31249            if ((int)_statusCode == 200)
 1250            {
 31251                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1252                try
 1253                {
 31254                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten
 31255                }
 01256                catch (JsonException ex)
 1257                {
 01258                    _httpRequest.Dispose();
 01259                    if (_httpResponse != null)
 1260                    {
 01261                        _httpResponse.Dispose();
 1262                    }
 01263                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1264                }
 1265            }
 31266            if (_shouldTrace)
 1267            {
 01268                ServiceClientTracing.Exit(_invocationId, _result);
 1269            }
 31270            return _result;
 31271        }
 1272
 1273        /// <summary>
 1274        /// Returns patterns for the specific intent in a version of the application.
 1275        /// </summary>
 1276        /// <param name='appId'>
 1277        /// The application ID.
 1278        /// </param>
 1279        /// <param name='versionId'>
 1280        /// The version ID.
 1281        /// </param>
 1282        /// <param name='intentId'>
 1283        /// The intent classifier ID.
 1284        /// </param>
 1285        /// <param name='skip'>
 1286        /// The number of entries to skip. Default value is 0.
 1287        /// </param>
 1288        /// <param name='take'>
 1289        /// The number of entries to return. Maximum page size is 500. Default is 100.
 1290        /// </param>
 1291        /// <param name='customHeaders'>
 1292        /// Headers that will be added to request.
 1293        /// </param>
 1294        /// <param name='cancellationToken'>
 1295        /// The cancellation token.
 1296        /// </param>
 1297        /// <exception cref="ErrorResponseException">
 1298        /// Thrown when the operation returned an invalid status code
 1299        /// </exception>
 1300        /// <exception cref="SerializationException">
 1301        /// Thrown when unable to deserialize the response
 1302        /// </exception>
 1303        /// <exception cref="ValidationException">
 1304        /// Thrown when a required parameter is null
 1305        /// </exception>
 1306        /// <exception cref="System.ArgumentNullException">
 1307        /// Thrown when a required parameter is null
 1308        /// </exception>
 1309        /// <return>
 1310        /// A response object containing the response body and response headers.
 1311        /// </return>
 1312        public async Task<HttpOperationResponse<IList<PatternRuleInfo>>> ListIntentPatternsWithHttpMessagesAsync(System.
 1313        {
 11314            if (Client.Endpoint == null)
 1315            {
 01316                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1317            }
 11318            if (versionId == null)
 1319            {
 01320                throw new ValidationException(ValidationRules.CannotBeNull, "versionId");
 1321            }
 11322            if (skip < 0)
 1323            {
 01324                throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0);
 1325            }
 11326            if (take > 500)
 1327            {
 01328                throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500);
 1329            }
 11330            if (take < 0)
 1331            {
 01332                throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0);
 1333            }
 1334            // Tracing
 11335            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 11336            string _invocationId = null;
 11337            if (_shouldTrace)
 1338            {
 01339                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01340                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01341                tracingParameters.Add("appId", appId);
 01342                tracingParameters.Add("versionId", versionId);
 01343                tracingParameters.Add("intentId", intentId);
 01344                tracingParameters.Add("skip", skip);
 01345                tracingParameters.Add("take", take);
 01346                tracingParameters.Add("cancellationToken", cancellationToken);
 01347                ServiceClientTracing.Enter(_invocationId, this, "ListIntentPatterns", tracingParameters);
 1348            }
 1349            // Construct URL
 11350            var _baseUrl = Client.BaseUri;
 11351            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/intents/{inte
 11352            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 11353            _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec
 11354            _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId));
 11355            _url = _url.Replace("{intentId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb
 11356            List<string> _queryParameters = new List<string>();
 11357            if (skip != null)
 1358            {
 11359                _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 1360            }
 11361            if (take != null)
 1362            {
 11363                _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo
 1364            }
 11365            if (_queryParameters.Count > 0)
 1366            {
 11367                _url += "?" + string.Join("&", _queryParameters);
 1368            }
 1369            // Create HTTP transport objects
 11370            var _httpRequest = new HttpRequestMessage();
 11371            HttpResponseMessage _httpResponse = null;
 11372            _httpRequest.Method = new HttpMethod("GET");
 11373            _httpRequest.RequestUri = new System.Uri(_url);
 1374            // Set Headers
 1375
 1376
 11377            if (customHeaders != null)
 1378            {
 01379                foreach(var _header in customHeaders)
 1380                {
 01381                    if (_httpRequest.Headers.Contains(_header.Key))
 1382                    {
 01383                        _httpRequest.Headers.Remove(_header.Key);
 1384                    }
 01385                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1386                }
 1387            }
 1388
 1389            // Serialize Request
 11390            string _requestContent = null;
 1391            // Set Credentials
 11392            if (Client.Credentials != null)
 1393            {
 11394                cancellationToken.ThrowIfCancellationRequested();
 11395                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1396            }
 1397            // Send Request
 11398            if (_shouldTrace)
 1399            {
 01400                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1401            }
 11402            cancellationToken.ThrowIfCancellationRequested();
 11403            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 11404            if (_shouldTrace)
 1405            {
 01406                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1407            }
 11408            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 11409            cancellationToken.ThrowIfCancellationRequested();
 11410            string _responseContent = null;
 11411            if ((int)_statusCode != 200)
 1412            {
 01413                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1414                try
 1415                {
 01416                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01417                    ErrorResponse _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res
 01418                    if (_errorBody != null)
 1419                    {
 01420                        ex.Body = _errorBody;
 1421                    }
 01422                }
 01423                catch (JsonException)
 1424                {
 1425                    // Ignore the exception
 01426                }
 01427                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01428                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01429                if (_shouldTrace)
 1430                {
 01431                    ServiceClientTracing.Error(_invocationId, ex);
 1432                }
 01433                _httpRequest.Dispose();
 01434                if (_httpResponse != null)
 1435                {
 01436                    _httpResponse.Dispose();
 1437                }
 01438                throw ex;
 1439            }
 1440            // Create Result
 11441            var _result = new HttpOperationResponse<IList<PatternRuleInfo>>();
 11442            _result.Request = _httpRequest;
 11443            _result.Response = _httpResponse;
 1444            // Deserialize Response
 11445            if ((int)_statusCode == 200)
 1446            {
 11447                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1448                try
 1449                {
 11450                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PatternRuleInfo>>(_respons
 11451                }
 01452                catch (JsonException ex)
 1453                {
 01454                    _httpRequest.Dispose();
 01455                    if (_httpResponse != null)
 1456                    {
 01457                        _httpResponse.Dispose();
 1458                    }
 01459                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1460                }
 1461            }
 11462            if (_shouldTrace)
 1463            {
 01464                ServiceClientTracing.Exit(_invocationId, _result);
 1465            }
 11466            return _result;
 11467        }
 1468
 1469    }
 1470}