< Summary

Class:Microsoft.Azure.CognitiveServices.FormRecognizer.FormRecognizerClient
Assembly:Microsoft.Azure.CognitiveServices.Vision.FormRecognizer
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Customizations\FormRecognizerClient2.cs
C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Generated\FormRecognizerClient.cs
Covered lines:45
Uncovered lines:675
Coverable lines:720
Total lines:1837
Line coverage:6.2% (45 of 720)
Covered branches:3
Total branches:326
Branch coverage:0.9% (3 of 326)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
CustomInitialize()-100%100%
AnalyzeWithCustomModelWithHttpMessagesAsync2()-0%0%
get_BaseUri()-0%100%
get_SerializationSettings()-100%100%
get_DeserializationSettings()-100%100%
get_Endpoint()-0%100%
get_Credentials()-100%100%
.ctor(...)-0%100%
.ctor(...)-100%100%
.ctor(...)-0%100%
.ctor(...)-85.71%75%
.ctor(...)-0%0%
.ctor(...)-0%0%
Initialize()-100%100%
TrainCustomModelWithHttpMessagesAsync()-0%0%
GetExtractedKeysWithHttpMessagesAsync()-0%0%
GetCustomModelsWithHttpMessagesAsync()-0%0%
GetCustomModelWithHttpMessagesAsync()-0%0%
DeleteCustomModelWithHttpMessagesAsync()-0%0%
BatchReadReceiptWithHttpMessagesAsync()-0%0%
GetReadReceiptResultWithHttpMessagesAsync()-0%0%
BatchReadReceiptInStreamWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Customizations\FormRecognizerClient2.cs

#LineLine coverage
 1namespace Microsoft.Azure.CognitiveServices.FormRecognizer
 2{
 3    using Microsoft.Rest;
 4    using Microsoft.Rest.Serialization;
 5    using Models;
 6    using Newtonsoft.Json;
 7    using System.Collections;
 8    using System.Collections.Generic;
 9    using System.IO;
 10    using System.Net;
 11    using System.Net.Http;
 12    using System.Net.Http.Headers;
 13    using System.Threading;
 14    using System.Threading.Tasks;
 15
 16    public partial interface IFormRecognizerClient : System.IDisposable
 17    {
 18        Task<HttpOperationResponse<AnalyzeResult>> AnalyzeWithCustomModelWithHttpMessagesAsync2(System.Guid id, Stream f
 19    }
 20
 21    public static partial class FormRecognizerClientExtensions
 22    {
 23        public static async Task<AnalyzeResult> AnalyzeWithCustomModelAsync(this IFormRecognizerClient operations, Syste
 24        {
 25            using (var _result = await operations.AnalyzeWithCustomModelWithHttpMessagesAsync2(id, formStream, keys, nul
 26            {
 27                return _result.Body;
 28            }
 29        }
 30    }
 31
 32    public partial class FormRecognizerClient : ServiceClient<FormRecognizerClient>, IFormRecognizerClient
 33    {
 34        partial void CustomInitialize()
 35        {
 36            // Disable metadata property handling when de/serializing models so we can properly support "$ref" in Elemen
 237            SerializationSettings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;
 238            DeserializationSettings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;
 239        }
 40
 41        public async Task<HttpOperationResponse<AnalyzeResult>> AnalyzeWithCustomModelWithHttpMessagesAsync2(System.Guid
 42        {
 043            if (Endpoint == null)
 44            {
 045                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 46            }
 047            if (formStream == null)
 48            {
 049                throw new ValidationException(ValidationRules.CannotBeNull, "formStream");
 50            }
 51            // Tracing
 052            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 053            string _invocationId = null;
 054            if (_shouldTrace)
 55            {
 056                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 057                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 058                tracingParameters.Add("id", id);
 059                tracingParameters.Add("keys", keys);
 060                tracingParameters.Add("formStream", formStream);
 061                tracingParameters.Add("cancellationToken", cancellationToken);
 062                ServiceClientTracing.Enter(_invocationId, this, "AnalyzeWithCustomModel", tracingParameters);
 63            }
 64            // Construct URL
 065            var _baseUrl = BaseUri;
 066            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/models/{id}/analyze";
 067            _url = _url.Replace("{Endpoint}", Endpoint);
 068            _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSet
 069            List<string> _queryParameters = new List<string>();
 070            if (keys != null)
 71            {
 072                _queryParameters.Add(string.Format("keys={0}", System.Uri.EscapeDataString(string.Join(",", keys))));
 73            }
 074            if (_queryParameters.Count > 0)
 75            {
 076                _url += "?" + string.Join("&", _queryParameters);
 77            }
 78            // Create HTTP transport objects
 079            var _httpRequest = new HttpRequestMessage();
 080            HttpResponseMessage _httpResponse = null;
 081            _httpRequest.Method = new HttpMethod("POST");
 082            _httpRequest.RequestUri = new System.Uri(_url);
 83            // Set Headers
 84
 85
 086            if (customHeaders != null)
 87            {
 088                foreach (var _header in customHeaders)
 89                {
 090                    if (_httpRequest.Headers.Contains(_header.Key))
 91                    {
 092                        _httpRequest.Headers.Remove(_header.Key);
 93                    }
 094                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 95                }
 96            }
 97
 98            // Serialize Request
 099            string _requestContent = null;
 0100            MultipartFormDataContent _multiPartContent = new MultipartFormDataContent();
 0101            if (formStream != null)
 102            {
 0103                StreamContent _formStream = new StreamContent(formStream);
 0104                FileStream _formStreamAsFileStream = formStream as FileStream;
 0105                if (_formStreamAsFileStream != null)
 106                {
 0107                    _formStream.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
 0108                    {
 0109                        Name = "form_stream",
 0110                        FileName = _formStreamAsFileStream.Name
 0111                    };
 0112                    _formStream.Headers.Add("Content-Type", contentType);
 113                }
 0114                _multiPartContent.Add(_formStream, "form_stream");
 115            }
 0116            _httpRequest.Content = _multiPartContent;
 117            // Set Credentials
 0118            if (Credentials != null)
 119            {
 0120                cancellationToken.ThrowIfCancellationRequested();
 0121                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 122            }
 123            // Send Request
 0124            if (_shouldTrace)
 125            {
 0126                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 127            }
 0128            cancellationToken.ThrowIfCancellationRequested();
 129
 0130            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0131            if (_shouldTrace)
 132            {
 0133                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 134            }
 0135            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0136            cancellationToken.ThrowIfCancellationRequested();
 0137            string _responseContent = null;
 0138            if ((int)_statusCode != 200)
 139            {
 0140                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 141                try
 142                {
 0143                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0144                    ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deseri
 0145                    if (_errorBody != null)
 146                    {
 0147                        ex.Body = _errorBody;
 148                    }
 0149                }
 0150                catch (JsonException)
 151                {
 152                    // Ignore the exception
 0153                }
 0154                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0155                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0156                if (_shouldTrace)
 157                {
 0158                    ServiceClientTracing.Error(_invocationId, ex);
 159                }
 0160                _httpRequest.Dispose();
 0161                if (_httpResponse != null)
 162                {
 0163                    _httpResponse.Dispose();
 164                }
 0165                throw ex;
 166            }
 167            // Create Result
 0168            var _result = new HttpOperationResponse<AnalyzeResult>();
 0169            _result.Request = _httpRequest;
 0170            _result.Response = _httpResponse;
 171            // Deserialize Response
 0172            if ((int)_statusCode == 200)
 173            {
 0174                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 175                try
 176                {
 0177                    _result.Body = SafeJsonConvert.DeserializeObject<AnalyzeResult>(_responseContent, DeserializationSet
 0178                }
 0179                catch (JsonException ex)
 180                {
 0181                    _httpRequest.Dispose();
 0182                    if (_httpResponse != null)
 183                    {
 0184                        _httpResponse.Dispose();
 185                    }
 0186                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 187                }
 188            }
 0189            if (_shouldTrace)
 190            {
 0191                ServiceClientTracing.Exit(_invocationId, _result);
 192            }
 0193            return _result;
 0194        }
 195    }
 196}

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\FormRecognizer\src\Generated\FormRecognizerClient.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.FormRecognizer
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Serialization;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.IO;
 20    using System.Net;
 21    using System.Net.Http;
 22    using System.Net.Http.Headers;
 23    using System.Threading;
 24    using System.Threading.Tasks;
 25
 26    public partial class FormRecognizerClient : ServiceClient<FormRecognizerClient>, IFormRecognizerClient
 27    {
 28        /// <summary>
 29        /// The base URI of the service.
 30        /// </summary>
 031        internal string BaseUri {get; set;}
 32
 33        /// <summary>
 34        /// Gets or sets json serialization settings.
 35        /// </summary>
 636        public JsonSerializerSettings SerializationSettings { get; private set; }
 37
 38        /// <summary>
 39        /// Gets or sets json deserialization settings.
 40        /// </summary>
 641        public JsonSerializerSettings DeserializationSettings { get; private set; }
 42
 43        /// <summary>
 44        /// Supported Cognitive Services endpoints (protocol and hostname, for example:
 45        /// https://westus2.api.cognitive.microsoft.com).
 46        /// </summary>
 047        public string Endpoint { get; set; }
 48
 49        /// <summary>
 50        /// Subscription credentials which uniquely identify client subscription.
 51        /// </summary>
 652        public ServiceClientCredentials Credentials { get; private set; }
 53
 54        /// <summary>
 55        /// Initializes a new instance of the FormRecognizerClient class.
 56        /// </summary>
 57        /// <param name='httpClient'>
 58        /// HttpClient to be used
 59        /// </param>
 60        /// <param name='disposeHttpClient'>
 61        /// True: will dispose the provided httpClient on calling FormRecognizerClient.Dispose(). False: will not dispos
 062        protected FormRecognizerClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClie
 63        {
 064            Initialize();
 065        }
 66
 67        /// <summary>
 68        /// Initializes a new instance of the FormRecognizerClient class.
 69        /// </summary>
 70        /// <param name='handlers'>
 71        /// Optional. The delegating handlers to add to the http client pipeline.
 72        /// </param>
 273        protected FormRecognizerClient(params DelegatingHandler[] handlers) : base(handlers)
 74        {
 275            Initialize();
 276        }
 77
 78        /// <summary>
 79        /// Initializes a new instance of the FormRecognizerClient class.
 80        /// </summary>
 81        /// <param name='rootHandler'>
 82        /// Optional. The http client handler used to handle http transport.
 83        /// </param>
 84        /// <param name='handlers'>
 85        /// Optional. The delegating handlers to add to the http client pipeline.
 86        /// </param>
 087        protected FormRecognizerClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHa
 88        {
 089            Initialize();
 090        }
 91
 92        /// <summary>
 93        /// Initializes a new instance of the FormRecognizerClient class.
 94        /// </summary>
 95        /// <param name='credentials'>
 96        /// Required. Subscription credentials which uniquely identify client subscription.
 97        /// </param>
 98        /// <param name='handlers'>
 99        /// Optional. The delegating handlers to add to the http client pipeline.
 100        /// </param>
 101        /// <exception cref="System.ArgumentNullException">
 102        /// Thrown when a required parameter is null
 103        /// </exception>
 2104        public FormRecognizerClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(ha
 105        {
 2106            if (credentials == null)
 107            {
 0108                throw new System.ArgumentNullException("credentials");
 109            }
 2110            Credentials = credentials;
 2111            if (Credentials != null)
 112            {
 2113                Credentials.InitializeServiceClient(this);
 114            }
 2115        }
 116
 117        /// <summary>
 118        /// Initializes a new instance of the FormRecognizerClient class.
 119        /// </summary>
 120        /// <param name='credentials'>
 121        /// Required. Subscription credentials which uniquely identify client subscription.
 122        /// </param>
 123        /// <param name='httpClient'>
 124        /// HttpClient to be used
 125        /// </param>
 126        /// <param name='disposeHttpClient'>
 127        /// True: will dispose the provided httpClient on calling FormRecognizerClient.Dispose(). False: will not dispos
 128        /// <exception cref="System.ArgumentNullException">
 129        /// Thrown when a required parameter is null
 130        /// </exception>
 0131        public FormRecognizerClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpClient)
 132        {
 0133            if (credentials == null)
 134            {
 0135                throw new System.ArgumentNullException("credentials");
 136            }
 0137            Credentials = credentials;
 0138            if (Credentials != null)
 139            {
 0140                Credentials.InitializeServiceClient(this);
 141            }
 0142        }
 143
 144        /// <summary>
 145        /// Initializes a new instance of the FormRecognizerClient class.
 146        /// </summary>
 147        /// <param name='credentials'>
 148        /// Required. Subscription credentials which uniquely identify client subscription.
 149        /// </param>
 150        /// <param name='rootHandler'>
 151        /// Optional. The http client handler used to handle http transport.
 152        /// </param>
 153        /// <param name='handlers'>
 154        /// Optional. The delegating handlers to add to the http client pipeline.
 155        /// </param>
 156        /// <exception cref="System.ArgumentNullException">
 157        /// Thrown when a required parameter is null
 158        /// </exception>
 0159        public FormRecognizerClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params Delegati
 160        {
 0161            if (credentials == null)
 162            {
 0163                throw new System.ArgumentNullException("credentials");
 164            }
 0165            Credentials = credentials;
 0166            if (Credentials != null)
 167            {
 0168                Credentials.InitializeServiceClient(this);
 169            }
 0170        }
 171
 172        /// <summary>
 173        /// An optional partial-method to perform custom initialization.
 174        ///</summary>
 175        partial void CustomInitialize();
 176        /// <summary>
 177        /// Initializes client properties.
 178        /// </summary>
 179        private void Initialize()
 180        {
 2181            BaseUri = "{Endpoint}/formrecognizer/v1.0-preview";
 2182            SerializationSettings = new JsonSerializerSettings
 2183            {
 2184                Formatting = Newtonsoft.Json.Formatting.Indented,
 2185                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 2186                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 2187                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 2188                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 2189                ContractResolver = new ReadOnlyJsonContractResolver(),
 2190                Converters = new  List<JsonConverter>
 2191                    {
 2192                        new Iso8601TimeSpanConverter()
 2193                    }
 2194            };
 2195            DeserializationSettings = new JsonSerializerSettings
 2196            {
 2197                DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
 2198                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
 2199                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
 2200                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
 2201                ContractResolver = new ReadOnlyJsonContractResolver(),
 2202                Converters = new List<JsonConverter>
 2203                    {
 2204                        new Iso8601TimeSpanConverter()
 2205                    }
 2206            };
 2207            SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter<FieldValue>("valueType"));
 2208            DeserializationSettings.Converters.Add(new  PolymorphicDeserializeJsonConverter<FieldValue>("valueType"));
 2209            CustomInitialize();
 2210        }
 211        /// <summary>
 212        /// Train Model
 213        /// </summary>
 214        /// <remarks>
 215        /// Create and train a custom model. The train request must include a source
 216        /// parameter that is either an externally accessible Azure Storage blob
 217        /// container Uri (preferably a Shared Access Signature Uri) or valid path to a
 218        /// data folder in a locally mounted drive. When local paths are specified,
 219        /// they must follow the Linux/Unix path format and be an absolute path rooted
 220        /// to the input mount configuration
 221        /// setting value e.g., if '{Mounts:Input}' configuration setting value is
 222        /// '/input' then a valid source path would be '/input/contosodataset'. All
 223        /// data to be trained is expected to be directly under the source folder.
 224        /// Subfolders are not supported. Models are trained using documents that are
 225        /// of the following content type - 'application/pdf', 'image/jpeg' and
 226        /// 'image/png'."
 227        /// Other type of content is ignored.
 228        /// </remarks>
 229        /// <param name='trainRequest'>
 230        /// Request object for training.
 231        /// </param>
 232        /// <param name='customHeaders'>
 233        /// Headers that will be added to request.
 234        /// </param>
 235        /// <param name='cancellationToken'>
 236        /// The cancellation token.
 237        /// </param>
 238        /// <exception cref="ErrorResponseException">
 239        /// Thrown when the operation returned an invalid status code
 240        /// </exception>
 241        /// <exception cref="SerializationException">
 242        /// Thrown when unable to deserialize the response
 243        /// </exception>
 244        /// <exception cref="ValidationException">
 245        /// Thrown when a required parameter is null
 246        /// </exception>
 247        /// <exception cref="System.ArgumentNullException">
 248        /// Thrown when a required parameter is null
 249        /// </exception>
 250        /// <return>
 251        /// A response object containing the response body and response headers.
 252        /// </return>
 253        public async Task<HttpOperationResponse<TrainResult>> TrainCustomModelWithHttpMessagesAsync(TrainRequest trainRe
 254        {
 0255            if (Endpoint == null)
 256            {
 0257                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 258            }
 0259            if (trainRequest == null)
 260            {
 0261                throw new ValidationException(ValidationRules.CannotBeNull, "trainRequest");
 262            }
 0263            if (trainRequest != null)
 264            {
 0265                trainRequest.Validate();
 266            }
 267            // Tracing
 0268            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0269            string _invocationId = null;
 0270            if (_shouldTrace)
 271            {
 0272                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0273                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0274                tracingParameters.Add("trainRequest", trainRequest);
 0275                tracingParameters.Add("cancellationToken", cancellationToken);
 0276                ServiceClientTracing.Enter(_invocationId, this, "TrainCustomModel", tracingParameters);
 277            }
 278            // Construct URL
 0279            var _baseUrl = BaseUri;
 0280            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/train";
 0281            _url = _url.Replace("{Endpoint}", Endpoint);
 282            // Create HTTP transport objects
 0283            var _httpRequest = new HttpRequestMessage();
 0284            HttpResponseMessage _httpResponse = null;
 0285            _httpRequest.Method = new HttpMethod("POST");
 0286            _httpRequest.RequestUri = new System.Uri(_url);
 287            // Set Headers
 288
 289
 0290            if (customHeaders != null)
 291            {
 0292                foreach(var _header in customHeaders)
 293                {
 0294                    if (_httpRequest.Headers.Contains(_header.Key))
 295                    {
 0296                        _httpRequest.Headers.Remove(_header.Key);
 297                    }
 0298                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 299                }
 300            }
 301
 302            // Serialize Request
 0303            string _requestContent = null;
 0304            if(trainRequest != null)
 305            {
 0306                _requestContent = SafeJsonConvert.SerializeObject(trainRequest, SerializationSettings);
 0307                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0308                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
 309            }
 310            // Set Credentials
 0311            if (Credentials != null)
 312            {
 0313                cancellationToken.ThrowIfCancellationRequested();
 0314                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 315            }
 316            // Send Request
 0317            if (_shouldTrace)
 318            {
 0319                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 320            }
 0321            cancellationToken.ThrowIfCancellationRequested();
 0322            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0323            if (_shouldTrace)
 324            {
 0325                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 326            }
 0327            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0328            cancellationToken.ThrowIfCancellationRequested();
 0329            string _responseContent = null;
 0330            if ((int)_statusCode != 200)
 331            {
 0332                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 333                try
 334                {
 0335                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0336                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 0337                    if (_errorBody != null)
 338                    {
 0339                        ex.Body = _errorBody;
 340                    }
 0341                }
 0342                catch (JsonException)
 343                {
 344                    // Ignore the exception
 0345                }
 0346                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0347                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0348                if (_shouldTrace)
 349                {
 0350                    ServiceClientTracing.Error(_invocationId, ex);
 351                }
 0352                _httpRequest.Dispose();
 0353                if (_httpResponse != null)
 354                {
 0355                    _httpResponse.Dispose();
 356                }
 0357                throw ex;
 358            }
 359            // Create Result
 0360            var _result = new HttpOperationResponse<TrainResult>();
 0361            _result.Request = _httpRequest;
 0362            _result.Response = _httpResponse;
 363            // Deserialize Response
 0364            if ((int)_statusCode == 200)
 365            {
 0366                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 367                try
 368                {
 0369                    _result.Body = SafeJsonConvert.DeserializeObject<TrainResult>(_responseContent, DeserializationSetti
 0370                }
 0371                catch (JsonException ex)
 372                {
 0373                    _httpRequest.Dispose();
 0374                    if (_httpResponse != null)
 375                    {
 0376                        _httpResponse.Dispose();
 377                    }
 0378                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 379                }
 380            }
 0381            if (_shouldTrace)
 382            {
 0383                ServiceClientTracing.Exit(_invocationId, _result);
 384            }
 0385            return _result;
 0386        }
 387
 388        /// <summary>
 389        /// Get Keys
 390        /// </summary>
 391        /// <remarks>
 392        /// Retrieve the keys that were
 393        /// extracted during the training of the specified model.
 394        /// </remarks>
 395        /// <param name='id'>
 396        /// Model identifier.
 397        /// </param>
 398        /// <param name='customHeaders'>
 399        /// Headers that will be added to request.
 400        /// </param>
 401        /// <param name='cancellationToken'>
 402        /// The cancellation token.
 403        /// </param>
 404        /// <exception cref="ErrorResponseException">
 405        /// Thrown when the operation returned an invalid status code
 406        /// </exception>
 407        /// <exception cref="SerializationException">
 408        /// Thrown when unable to deserialize the response
 409        /// </exception>
 410        /// <exception cref="ValidationException">
 411        /// Thrown when a required parameter is null
 412        /// </exception>
 413        /// <exception cref="System.ArgumentNullException">
 414        /// Thrown when a required parameter is null
 415        /// </exception>
 416        /// <return>
 417        /// A response object containing the response body and response headers.
 418        /// </return>
 419        public async Task<HttpOperationResponse<KeysResult>> GetExtractedKeysWithHttpMessagesAsync(System.Guid id, Dicti
 420        {
 0421            if (Endpoint == null)
 422            {
 0423                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 424            }
 425            // Tracing
 0426            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0427            string _invocationId = null;
 0428            if (_shouldTrace)
 429            {
 0430                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0431                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0432                tracingParameters.Add("id", id);
 0433                tracingParameters.Add("cancellationToken", cancellationToken);
 0434                ServiceClientTracing.Enter(_invocationId, this, "GetExtractedKeys", tracingParameters);
 435            }
 436            // Construct URL
 0437            var _baseUrl = BaseUri;
 0438            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/models/{id}/keys";
 0439            _url = _url.Replace("{Endpoint}", Endpoint);
 0440            _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSet
 441            // Create HTTP transport objects
 0442            var _httpRequest = new HttpRequestMessage();
 0443            HttpResponseMessage _httpResponse = null;
 0444            _httpRequest.Method = new HttpMethod("GET");
 0445            _httpRequest.RequestUri = new System.Uri(_url);
 446            // Set Headers
 447
 448
 0449            if (customHeaders != null)
 450            {
 0451                foreach(var _header in customHeaders)
 452                {
 0453                    if (_httpRequest.Headers.Contains(_header.Key))
 454                    {
 0455                        _httpRequest.Headers.Remove(_header.Key);
 456                    }
 0457                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 458                }
 459            }
 460
 461            // Serialize Request
 0462            string _requestContent = null;
 463            // Set Credentials
 0464            if (Credentials != null)
 465            {
 0466                cancellationToken.ThrowIfCancellationRequested();
 0467                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 468            }
 469            // Send Request
 0470            if (_shouldTrace)
 471            {
 0472                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 473            }
 0474            cancellationToken.ThrowIfCancellationRequested();
 0475            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0476            if (_shouldTrace)
 477            {
 0478                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 479            }
 0480            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0481            cancellationToken.ThrowIfCancellationRequested();
 0482            string _responseContent = null;
 0483            if ((int)_statusCode != 200)
 484            {
 0485                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 486                try
 487                {
 0488                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0489                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 0490                    if (_errorBody != null)
 491                    {
 0492                        ex.Body = _errorBody;
 493                    }
 0494                }
 0495                catch (JsonException)
 496                {
 497                    // Ignore the exception
 0498                }
 0499                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0500                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0501                if (_shouldTrace)
 502                {
 0503                    ServiceClientTracing.Error(_invocationId, ex);
 504                }
 0505                _httpRequest.Dispose();
 0506                if (_httpResponse != null)
 507                {
 0508                    _httpResponse.Dispose();
 509                }
 0510                throw ex;
 511            }
 512            // Create Result
 0513            var _result = new HttpOperationResponse<KeysResult>();
 0514            _result.Request = _httpRequest;
 0515            _result.Response = _httpResponse;
 516            // Deserialize Response
 0517            if ((int)_statusCode == 200)
 518            {
 0519                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 520                try
 521                {
 0522                    _result.Body = SafeJsonConvert.DeserializeObject<KeysResult>(_responseContent, DeserializationSettin
 0523                }
 0524                catch (JsonException ex)
 525                {
 0526                    _httpRequest.Dispose();
 0527                    if (_httpResponse != null)
 528                    {
 0529                        _httpResponse.Dispose();
 530                    }
 0531                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 532                }
 533            }
 0534            if (_shouldTrace)
 535            {
 0536                ServiceClientTracing.Exit(_invocationId, _result);
 537            }
 0538            return _result;
 0539        }
 540
 541        /// <summary>
 542        /// Get Models
 543        /// </summary>
 544        /// <remarks>
 545        /// Get information about all trained custom models
 546        /// </remarks>
 547        /// <param name='customHeaders'>
 548        /// Headers that will be added to request.
 549        /// </param>
 550        /// <param name='cancellationToken'>
 551        /// The cancellation token.
 552        /// </param>
 553        /// <exception cref="ErrorResponseException">
 554        /// Thrown when the operation returned an invalid status code
 555        /// </exception>
 556        /// <exception cref="SerializationException">
 557        /// Thrown when unable to deserialize the response
 558        /// </exception>
 559        /// <exception cref="ValidationException">
 560        /// Thrown when a required parameter is null
 561        /// </exception>
 562        /// <exception cref="System.ArgumentNullException">
 563        /// Thrown when a required parameter is null
 564        /// </exception>
 565        /// <return>
 566        /// A response object containing the response body and response headers.
 567        /// </return>
 568        public async Task<HttpOperationResponse<ModelsResult>> GetCustomModelsWithHttpMessagesAsync(Dictionary<string, L
 569        {
 0570            if (Endpoint == null)
 571            {
 0572                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 573            }
 574            // Tracing
 0575            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0576            string _invocationId = null;
 0577            if (_shouldTrace)
 578            {
 0579                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0580                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0581                tracingParameters.Add("cancellationToken", cancellationToken);
 0582                ServiceClientTracing.Enter(_invocationId, this, "GetCustomModels", tracingParameters);
 583            }
 584            // Construct URL
 0585            var _baseUrl = BaseUri;
 0586            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/models";
 0587            _url = _url.Replace("{Endpoint}", Endpoint);
 588            // Create HTTP transport objects
 0589            var _httpRequest = new HttpRequestMessage();
 0590            HttpResponseMessage _httpResponse = null;
 0591            _httpRequest.Method = new HttpMethod("GET");
 0592            _httpRequest.RequestUri = new System.Uri(_url);
 593            // Set Headers
 594
 595
 0596            if (customHeaders != null)
 597            {
 0598                foreach(var _header in customHeaders)
 599                {
 0600                    if (_httpRequest.Headers.Contains(_header.Key))
 601                    {
 0602                        _httpRequest.Headers.Remove(_header.Key);
 603                    }
 0604                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 605                }
 606            }
 607
 608            // Serialize Request
 0609            string _requestContent = null;
 610            // Set Credentials
 0611            if (Credentials != null)
 612            {
 0613                cancellationToken.ThrowIfCancellationRequested();
 0614                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 615            }
 616            // Send Request
 0617            if (_shouldTrace)
 618            {
 0619                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 620            }
 0621            cancellationToken.ThrowIfCancellationRequested();
 0622            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0623            if (_shouldTrace)
 624            {
 0625                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 626            }
 0627            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0628            cancellationToken.ThrowIfCancellationRequested();
 0629            string _responseContent = null;
 0630            if ((int)_statusCode != 200)
 631            {
 0632                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 633                try
 634                {
 0635                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0636                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 0637                    if (_errorBody != null)
 638                    {
 0639                        ex.Body = _errorBody;
 640                    }
 0641                }
 0642                catch (JsonException)
 643                {
 644                    // Ignore the exception
 0645                }
 0646                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0647                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0648                if (_shouldTrace)
 649                {
 0650                    ServiceClientTracing.Error(_invocationId, ex);
 651                }
 0652                _httpRequest.Dispose();
 0653                if (_httpResponse != null)
 654                {
 0655                    _httpResponse.Dispose();
 656                }
 0657                throw ex;
 658            }
 659            // Create Result
 0660            var _result = new HttpOperationResponse<ModelsResult>();
 0661            _result.Request = _httpRequest;
 0662            _result.Response = _httpResponse;
 663            // Deserialize Response
 0664            if ((int)_statusCode == 200)
 665            {
 0666                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 667                try
 668                {
 0669                    _result.Body = SafeJsonConvert.DeserializeObject<ModelsResult>(_responseContent, DeserializationSett
 0670                }
 0671                catch (JsonException ex)
 672                {
 0673                    _httpRequest.Dispose();
 0674                    if (_httpResponse != null)
 675                    {
 0676                        _httpResponse.Dispose();
 677                    }
 0678                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 679                }
 680            }
 0681            if (_shouldTrace)
 682            {
 0683                ServiceClientTracing.Exit(_invocationId, _result);
 684            }
 0685            return _result;
 0686        }
 687
 688        /// <summary>
 689        /// Get Model
 690        /// </summary>
 691        /// <remarks>
 692        /// Get information about a model.
 693        /// </remarks>
 694        /// <param name='id'>
 695        /// Model identifier.
 696        /// </param>
 697        /// <param name='customHeaders'>
 698        /// Headers that will be added to request.
 699        /// </param>
 700        /// <param name='cancellationToken'>
 701        /// The cancellation token.
 702        /// </param>
 703        /// <exception cref="ErrorResponseException">
 704        /// Thrown when the operation returned an invalid status code
 705        /// </exception>
 706        /// <exception cref="SerializationException">
 707        /// Thrown when unable to deserialize the response
 708        /// </exception>
 709        /// <exception cref="ValidationException">
 710        /// Thrown when a required parameter is null
 711        /// </exception>
 712        /// <exception cref="System.ArgumentNullException">
 713        /// Thrown when a required parameter is null
 714        /// </exception>
 715        /// <return>
 716        /// A response object containing the response body and response headers.
 717        /// </return>
 718        public async Task<HttpOperationResponse<ModelResult>> GetCustomModelWithHttpMessagesAsync(System.Guid id, Dictio
 719        {
 0720            if (Endpoint == null)
 721            {
 0722                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 723            }
 724            // Tracing
 0725            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0726            string _invocationId = null;
 0727            if (_shouldTrace)
 728            {
 0729                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0730                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0731                tracingParameters.Add("id", id);
 0732                tracingParameters.Add("cancellationToken", cancellationToken);
 0733                ServiceClientTracing.Enter(_invocationId, this, "GetCustomModel", tracingParameters);
 734            }
 735            // Construct URL
 0736            var _baseUrl = BaseUri;
 0737            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/models/{id}";
 0738            _url = _url.Replace("{Endpoint}", Endpoint);
 0739            _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSet
 740            // Create HTTP transport objects
 0741            var _httpRequest = new HttpRequestMessage();
 0742            HttpResponseMessage _httpResponse = null;
 0743            _httpRequest.Method = new HttpMethod("GET");
 0744            _httpRequest.RequestUri = new System.Uri(_url);
 745            // Set Headers
 746
 747
 0748            if (customHeaders != null)
 749            {
 0750                foreach(var _header in customHeaders)
 751                {
 0752                    if (_httpRequest.Headers.Contains(_header.Key))
 753                    {
 0754                        _httpRequest.Headers.Remove(_header.Key);
 755                    }
 0756                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 757                }
 758            }
 759
 760            // Serialize Request
 0761            string _requestContent = null;
 762            // Set Credentials
 0763            if (Credentials != null)
 764            {
 0765                cancellationToken.ThrowIfCancellationRequested();
 0766                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 767            }
 768            // Send Request
 0769            if (_shouldTrace)
 770            {
 0771                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 772            }
 0773            cancellationToken.ThrowIfCancellationRequested();
 0774            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0775            if (_shouldTrace)
 776            {
 0777                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 778            }
 0779            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0780            cancellationToken.ThrowIfCancellationRequested();
 0781            string _responseContent = null;
 0782            if ((int)_statusCode != 200)
 783            {
 0784                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 785                try
 786                {
 0787                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0788                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 0789                    if (_errorBody != null)
 790                    {
 0791                        ex.Body = _errorBody;
 792                    }
 0793                }
 0794                catch (JsonException)
 795                {
 796                    // Ignore the exception
 0797                }
 0798                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0799                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0800                if (_shouldTrace)
 801                {
 0802                    ServiceClientTracing.Error(_invocationId, ex);
 803                }
 0804                _httpRequest.Dispose();
 0805                if (_httpResponse != null)
 806                {
 0807                    _httpResponse.Dispose();
 808                }
 0809                throw ex;
 810            }
 811            // Create Result
 0812            var _result = new HttpOperationResponse<ModelResult>();
 0813            _result.Request = _httpRequest;
 0814            _result.Response = _httpResponse;
 815            // Deserialize Response
 0816            if ((int)_statusCode == 200)
 817            {
 0818                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 819                try
 820                {
 0821                    _result.Body = SafeJsonConvert.DeserializeObject<ModelResult>(_responseContent, DeserializationSetti
 0822                }
 0823                catch (JsonException ex)
 824                {
 0825                    _httpRequest.Dispose();
 0826                    if (_httpResponse != null)
 827                    {
 0828                        _httpResponse.Dispose();
 829                    }
 0830                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 831                }
 832            }
 0833            if (_shouldTrace)
 834            {
 0835                ServiceClientTracing.Exit(_invocationId, _result);
 836            }
 0837            return _result;
 0838        }
 839
 840        /// <summary>
 841        /// Delete Model
 842        /// </summary>
 843        /// <remarks>
 844        /// Delete model artifacts.
 845        /// </remarks>
 846        /// <param name='id'>
 847        /// The identifier of the model to delete.
 848        /// </param>
 849        /// <param name='customHeaders'>
 850        /// Headers that will be added to request.
 851        /// </param>
 852        /// <param name='cancellationToken'>
 853        /// The cancellation token.
 854        /// </param>
 855        /// <exception cref="ErrorResponseException">
 856        /// Thrown when the operation returned an invalid status code
 857        /// </exception>
 858        /// <exception cref="ValidationException">
 859        /// Thrown when a required parameter is null
 860        /// </exception>
 861        /// <exception cref="System.ArgumentNullException">
 862        /// Thrown when a required parameter is null
 863        /// </exception>
 864        /// <return>
 865        /// A response object containing the response body and response headers.
 866        /// </return>
 867        public async Task<HttpOperationResponse> DeleteCustomModelWithHttpMessagesAsync(System.Guid id, Dictionary<strin
 868        {
 0869            if (Endpoint == null)
 870            {
 0871                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 872            }
 873            // Tracing
 0874            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0875            string _invocationId = null;
 0876            if (_shouldTrace)
 877            {
 0878                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0879                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0880                tracingParameters.Add("id", id);
 0881                tracingParameters.Add("cancellationToken", cancellationToken);
 0882                ServiceClientTracing.Enter(_invocationId, this, "DeleteCustomModel", tracingParameters);
 883            }
 884            // Construct URL
 0885            var _baseUrl = BaseUri;
 0886            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/models/{id}";
 0887            _url = _url.Replace("{Endpoint}", Endpoint);
 0888            _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSet
 889            // Create HTTP transport objects
 0890            var _httpRequest = new HttpRequestMessage();
 0891            HttpResponseMessage _httpResponse = null;
 0892            _httpRequest.Method = new HttpMethod("DELETE");
 0893            _httpRequest.RequestUri = new System.Uri(_url);
 894            // Set Headers
 895
 896
 0897            if (customHeaders != null)
 898            {
 0899                foreach(var _header in customHeaders)
 900                {
 0901                    if (_httpRequest.Headers.Contains(_header.Key))
 902                    {
 0903                        _httpRequest.Headers.Remove(_header.Key);
 904                    }
 0905                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 906                }
 907            }
 908
 909            // Serialize Request
 0910            string _requestContent = null;
 911            // Set Credentials
 0912            if (Credentials != null)
 913            {
 0914                cancellationToken.ThrowIfCancellationRequested();
 0915                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 916            }
 917            // Send Request
 0918            if (_shouldTrace)
 919            {
 0920                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 921            }
 0922            cancellationToken.ThrowIfCancellationRequested();
 0923            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0924            if (_shouldTrace)
 925            {
 0926                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 927            }
 0928            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0929            cancellationToken.ThrowIfCancellationRequested();
 0930            string _responseContent = null;
 0931            if ((int)_statusCode != 204)
 932            {
 0933                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 934                try
 935                {
 0936                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0937                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 0938                    if (_errorBody != null)
 939                    {
 0940                        ex.Body = _errorBody;
 941                    }
 0942                }
 0943                catch (JsonException)
 944                {
 945                    // Ignore the exception
 0946                }
 0947                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0948                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0949                if (_shouldTrace)
 950                {
 0951                    ServiceClientTracing.Error(_invocationId, ex);
 952                }
 0953                _httpRequest.Dispose();
 0954                if (_httpResponse != null)
 955                {
 0956                    _httpResponse.Dispose();
 957                }
 0958                throw ex;
 959            }
 960            // Create Result
 0961            var _result = new HttpOperationResponse();
 0962            _result.Request = _httpRequest;
 0963            _result.Response = _httpResponse;
 0964            if (_shouldTrace)
 965            {
 0966                ServiceClientTracing.Exit(_invocationId, _result);
 967            }
 0968            return _result;
 0969        }
 970
 971        /// <summary>
 972        /// Analyze Form
 973        /// </summary>
 974        /// <remarks>
 975        /// Extract key-value pairs from a given document. The input document must be
 976        /// of one of the supported content types - 'application/pdf', 'image/jpeg' or
 977        /// 'image/png'. A success response is returned in JSON.
 978        /// </remarks>
 979        /// <param name='id'>
 980        /// Model Identifier to analyze the document with.
 981        /// </param>
 982        /// <param name='formStream'>
 983        /// A pdf document or image (jpg,png) file to analyze.
 984        /// </param>
 985        /// <param name='keys'>
 986        /// An optional list of known keys to extract the values for.
 987        /// </param>
 988        /// <param name='customHeaders'>
 989        /// Headers that will be added to request.
 990        /// </param>
 991        /// <param name='cancellationToken'>
 992        /// The cancellation token.
 993        /// </param>
 994        /// <exception cref="ErrorResponseException">
 995        /// Thrown when the operation returned an invalid status code
 996        /// </exception>
 997        /// <exception cref="SerializationException">
 998        /// Thrown when unable to deserialize the response
 999        /// </exception>
 1000        /// <exception cref="ValidationException">
 1001        /// Thrown when a required parameter is null
 1002        /// </exception>
 1003        /// <exception cref="System.ArgumentNullException">
 1004        /// Thrown when a required parameter is null
 1005        /// </exception>
 1006        /// <return>
 1007        /// A response object containing the response body and response headers.
 1008        /// </return>
 1009        public async Task<HttpOperationResponse<AnalyzeResult>> AnalyzeWithCustomModelWithHttpMessagesAsync(System.Guid 
 1010        {
 1011            if (Endpoint == null)
 1012            {
 1013                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1014            }
 1015            if (formStream == null)
 1016            {
 1017                throw new ValidationException(ValidationRules.CannotBeNull, "formStream");
 1018            }
 1019            // Tracing
 1020            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 1021            string _invocationId = null;
 1022            if (_shouldTrace)
 1023            {
 1024                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 1025                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 1026                tracingParameters.Add("id", id);
 1027                tracingParameters.Add("keys", keys);
 1028                tracingParameters.Add("formStream", formStream);
 1029                tracingParameters.Add("cancellationToken", cancellationToken);
 1030                ServiceClientTracing.Enter(_invocationId, this, "AnalyzeWithCustomModel", tracingParameters);
 1031            }
 1032            // Construct URL
 1033            var _baseUrl = BaseUri;
 1034            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "custom/models/{id}/analyze";
 1035            _url = _url.Replace("{Endpoint}", Endpoint);
 1036            _url = _url.Replace("{id}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(id, SerializationSet
 1037            List<string> _queryParameters = new List<string>();
 1038            if (keys != null)
 1039            {
 1040                _queryParameters.Add(string.Format("keys={0}", System.Uri.EscapeDataString(string.Join(",", keys))));
 1041            }
 1042            if (_queryParameters.Count > 0)
 1043            {
 1044                _url += "?" + string.Join("&", _queryParameters);
 1045            }
 1046            // Create HTTP transport objects
 1047            var _httpRequest = new HttpRequestMessage();
 1048            HttpResponseMessage _httpResponse = null;
 1049            _httpRequest.Method = new HttpMethod("POST");
 1050            _httpRequest.RequestUri = new System.Uri(_url);
 1051            // Set Headers
 1052
 1053
 1054            if (customHeaders != null)
 1055            {
 1056                foreach(var _header in customHeaders)
 1057                {
 1058                    if (_httpRequest.Headers.Contains(_header.Key))
 1059                    {
 1060                        _httpRequest.Headers.Remove(_header.Key);
 1061                    }
 1062                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1063                }
 1064            }
 1065
 1066            // Serialize Request
 1067            string _requestContent = null;
 1068            MultipartFormDataContent _multiPartContent = new MultipartFormDataContent();
 1069            if (formStream != null)
 1070            {
 1071                StreamContent _formStream = new StreamContent(formStream);
 1072                _formStream.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
 1073                ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d
 1074                _contentDispositionHeaderValue.Name = "form_stream";
 1075                // get filename from stream if it's a file otherwise, just use  'unknown'
 1076                var _fileStream = formStream as FileStream;
 1077                var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown";
 01078                if(System.Linq.Enumerable.Any(_fileName, c => c > 127) )
 1079                {
 1080                    // non ASCII chars detected, need UTF encoding:
 1081                    _contentDispositionHeaderValue.FileNameStar = _fileName;
 1082                }
 1083                else
 1084                {
 1085                    // ASCII only
 1086                    _contentDispositionHeaderValue.FileName = _fileName;
 1087                }
 1088                _formStream.Headers.ContentDisposition = _contentDispositionHeaderValue;
 1089                _multiPartContent.Add(_formStream, "form_stream");
 1090            }
 1091            _httpRequest.Content = _multiPartContent;
 1092            // Set Credentials
 1093            if (Credentials != null)
 1094            {
 1095                cancellationToken.ThrowIfCancellationRequested();
 1096                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1097            }
 1098            // Send Request
 1099            if (_shouldTrace)
 1100            {
 1101                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1102            }
 1103            cancellationToken.ThrowIfCancellationRequested();
 1104            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1105            if (_shouldTrace)
 1106            {
 1107                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1108            }
 1109            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 1110            cancellationToken.ThrowIfCancellationRequested();
 1111            string _responseContent = null;
 1112            if ((int)_statusCode != 200)
 1113            {
 1114                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st
 1115                try
 1116                {
 1117                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1118                    ErrorResponse _errorBody =  SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Deser
 1119                    if (_errorBody != null)
 1120                    {
 1121                        ex.Body = _errorBody;
 1122                    }
 1123                }
 1124                catch (JsonException)
 1125                {
 1126                    // Ignore the exception
 1127                }
 1128                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 1129                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 1130                if (_shouldTrace)
 1131                {
 1132                    ServiceClientTracing.Error(_invocationId, ex);
 1133                }
 1134                _httpRequest.Dispose();
 1135                if (_httpResponse != null)
 1136                {
 1137                    _httpResponse.Dispose();
 1138                }
 1139                throw ex;
 1140            }
 1141            // Create Result
 1142            var _result = new HttpOperationResponse<AnalyzeResult>();
 1143            _result.Request = _httpRequest;
 1144            _result.Response = _httpResponse;
 1145            // Deserialize Response
 1146            if ((int)_statusCode == 200)
 1147            {
 1148                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1149                try
 1150                {
 1151                    _result.Body = SafeJsonConvert.DeserializeObject<AnalyzeResult>(_responseContent, DeserializationSet
 1152                }
 1153                catch (JsonException ex)
 1154                {
 1155                    _httpRequest.Dispose();
 1156                    if (_httpResponse != null)
 1157                    {
 1158                        _httpResponse.Dispose();
 1159                    }
 1160                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1161                }
 1162            }
 1163            if (_shouldTrace)
 1164            {
 1165                ServiceClientTracing.Exit(_invocationId, _result);
 1166            }
 1167            return _result;
 1168        }
 1169
 1170        /// <summary>
 1171        /// Batch Read Receipt operation. The response contains a field called
 1172        /// 'Operation-Location', which contains the URL that you must use for your
 1173        /// 'Get Read Receipt Result' operation.
 1174        /// </summary>
 1175        /// <param name='url'>
 1176        /// Publicly reachable URL of an image.
 1177        /// </param>
 1178        /// <param name='customHeaders'>
 1179        /// Headers that will be added to request.
 1180        /// </param>
 1181        /// <param name='cancellationToken'>
 1182        /// The cancellation token.
 1183        /// </param>
 1184        /// <exception cref="ComputerVisionErrorException">
 1185        /// Thrown when the operation returned an invalid status code
 1186        /// </exception>
 1187        /// <exception cref="ValidationException">
 1188        /// Thrown when a required parameter is null
 1189        /// </exception>
 1190        /// <exception cref="System.ArgumentNullException">
 1191        /// Thrown when a required parameter is null
 1192        /// </exception>
 1193        /// <return>
 1194        /// A response object containing the response body and response headers.
 1195        /// </return>
 1196        public async Task<HttpOperationHeaderResponse<BatchReadReceiptHeaders>> BatchReadReceiptWithHttpMessagesAsync(st
 1197        {
 01198            if (Endpoint == null)
 1199            {
 01200                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1201            }
 01202            if (url == null)
 1203            {
 01204                throw new ValidationException(ValidationRules.CannotBeNull, "url");
 1205            }
 01206            ImageUrl imageUrl = new ImageUrl();
 01207            if (url != null)
 1208            {
 01209                imageUrl.Url = url;
 1210            }
 1211            // Tracing
 01212            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01213            string _invocationId = null;
 01214            if (_shouldTrace)
 1215            {
 01216                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01217                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01218                tracingParameters.Add("imageUrl", imageUrl);
 01219                tracingParameters.Add("cancellationToken", cancellationToken);
 01220                ServiceClientTracing.Enter(_invocationId, this, "BatchReadReceipt", tracingParameters);
 1221            }
 1222            // Construct URL
 01223            var _baseUrl = BaseUri;
 01224            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "prebuilt/receipt/asyncBatchAnalyze";
 01225            _url = _url.Replace("{Endpoint}", Endpoint);
 1226            // Create HTTP transport objects
 01227            var _httpRequest = new HttpRequestMessage();
 01228            HttpResponseMessage _httpResponse = null;
 01229            _httpRequest.Method = new HttpMethod("POST");
 01230            _httpRequest.RequestUri = new System.Uri(_url);
 1231            // Set Headers
 1232
 1233
 01234            if (customHeaders != null)
 1235            {
 01236                foreach(var _header in customHeaders)
 1237                {
 01238                    if (_httpRequest.Headers.Contains(_header.Key))
 1239                    {
 01240                        _httpRequest.Headers.Remove(_header.Key);
 1241                    }
 01242                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1243                }
 1244            }
 1245
 1246            // Serialize Request
 01247            string _requestContent = null;
 01248            if(imageUrl != null)
 1249            {
 01250                _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings);
 01251                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01252                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
 1253            }
 1254            // Set Credentials
 01255            if (Credentials != null)
 1256            {
 01257                cancellationToken.ThrowIfCancellationRequested();
 01258                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1259            }
 1260            // Send Request
 01261            if (_shouldTrace)
 1262            {
 01263                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1264            }
 01265            cancellationToken.ThrowIfCancellationRequested();
 01266            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01267            if (_shouldTrace)
 1268            {
 01269                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1270            }
 01271            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01272            cancellationToken.ThrowIfCancellationRequested();
 01273            string _responseContent = null;
 01274            if ((int)_statusCode != 202)
 1275            {
 01276                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1277                try
 1278                {
 01279                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01280                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01281                    if (_errorBody != null)
 1282                    {
 01283                        ex.Body = _errorBody;
 1284                    }
 01285                }
 01286                catch (JsonException)
 1287                {
 1288                    // Ignore the exception
 01289                }
 01290                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01291                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01292                if (_shouldTrace)
 1293                {
 01294                    ServiceClientTracing.Error(_invocationId, ex);
 1295                }
 01296                _httpRequest.Dispose();
 01297                if (_httpResponse != null)
 1298                {
 01299                    _httpResponse.Dispose();
 1300                }
 01301                throw ex;
 1302            }
 1303            // Create Result
 01304            var _result = new HttpOperationHeaderResponse<BatchReadReceiptHeaders>();
 01305            _result.Request = _httpRequest;
 01306            _result.Response = _httpResponse;
 1307            try
 1308            {
 01309                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BatchReadReceiptHeaders>(JsonSerializer.Crea
 01310            }
 01311            catch (JsonException ex)
 1312            {
 01313                _httpRequest.Dispose();
 01314                if (_httpResponse != null)
 1315                {
 01316                    _httpResponse.Dispose();
 1317                }
 01318                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1319            }
 01320            if (_shouldTrace)
 1321            {
 01322                ServiceClientTracing.Exit(_invocationId, _result);
 1323            }
 01324            return _result;
 01325        }
 1326
 1327        /// <summary>
 1328        /// This interface is used for getting the analysis results of a 'Batch Read
 1329        /// Receipt' operation. The URL to this interface should be retrieved from the
 1330        /// 'Operation-Location' field returned from the 'Batch Read Receipt'
 1331        /// operation.
 1332        /// </summary>
 1333        /// <param name='operationId'>
 1334        /// Id of read operation returned in the response of a 'Batch Read Receipt'
 1335        /// operation.
 1336        /// </param>
 1337        /// <param name='customHeaders'>
 1338        /// Headers that will be added to request.
 1339        /// </param>
 1340        /// <param name='cancellationToken'>
 1341        /// The cancellation token.
 1342        /// </param>
 1343        /// <exception cref="ComputerVisionErrorException">
 1344        /// Thrown when the operation returned an invalid status code
 1345        /// </exception>
 1346        /// <exception cref="SerializationException">
 1347        /// Thrown when unable to deserialize the response
 1348        /// </exception>
 1349        /// <exception cref="ValidationException">
 1350        /// Thrown when a required parameter is null
 1351        /// </exception>
 1352        /// <exception cref="System.ArgumentNullException">
 1353        /// Thrown when a required parameter is null
 1354        /// </exception>
 1355        /// <return>
 1356        /// A response object containing the response body and response headers.
 1357        /// </return>
 1358        public async Task<HttpOperationResponse<ReadReceiptResult>> GetReadReceiptResultWithHttpMessagesAsync(string ope
 1359        {
 01360            if (Endpoint == null)
 1361            {
 01362                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1363            }
 01364            if (operationId == null)
 1365            {
 01366                throw new ValidationException(ValidationRules.CannotBeNull, "operationId");
 1367            }
 1368            // Tracing
 01369            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01370            string _invocationId = null;
 01371            if (_shouldTrace)
 1372            {
 01373                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01374                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01375                tracingParameters.Add("operationId", operationId);
 01376                tracingParameters.Add("cancellationToken", cancellationToken);
 01377                ServiceClientTracing.Enter(_invocationId, this, "GetReadReceiptResult", tracingParameters);
 1378            }
 1379            // Construct URL
 01380            var _baseUrl = BaseUri;
 01381            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "prebuilt/receipt/operations/{operationId}";
 01382            _url = _url.Replace("{Endpoint}", Endpoint);
 01383            _url = _url.Replace("{operationId}", System.Uri.EscapeDataString(operationId));
 1384            // Create HTTP transport objects
 01385            var _httpRequest = new HttpRequestMessage();
 01386            HttpResponseMessage _httpResponse = null;
 01387            _httpRequest.Method = new HttpMethod("GET");
 01388            _httpRequest.RequestUri = new System.Uri(_url);
 1389            // Set Headers
 1390
 1391
 01392            if (customHeaders != null)
 1393            {
 01394                foreach(var _header in customHeaders)
 1395                {
 01396                    if (_httpRequest.Headers.Contains(_header.Key))
 1397                    {
 01398                        _httpRequest.Headers.Remove(_header.Key);
 1399                    }
 01400                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1401                }
 1402            }
 1403
 1404            // Serialize Request
 01405            string _requestContent = null;
 1406            // Set Credentials
 01407            if (Credentials != null)
 1408            {
 01409                cancellationToken.ThrowIfCancellationRequested();
 01410                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1411            }
 1412            // Send Request
 01413            if (_shouldTrace)
 1414            {
 01415                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1416            }
 01417            cancellationToken.ThrowIfCancellationRequested();
 01418            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01419            if (_shouldTrace)
 1420            {
 01421                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1422            }
 01423            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01424            cancellationToken.ThrowIfCancellationRequested();
 01425            string _responseContent = null;
 01426            if ((int)_statusCode != 200)
 1427            {
 01428                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1429                try
 1430                {
 01431                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01432                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01433                    if (_errorBody != null)
 1434                    {
 01435                        ex.Body = _errorBody;
 1436                    }
 01437                }
 01438                catch (JsonException)
 1439                {
 1440                    // Ignore the exception
 01441                }
 01442                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01443                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01444                if (_shouldTrace)
 1445                {
 01446                    ServiceClientTracing.Error(_invocationId, ex);
 1447                }
 01448                _httpRequest.Dispose();
 01449                if (_httpResponse != null)
 1450                {
 01451                    _httpResponse.Dispose();
 1452                }
 01453                throw ex;
 1454            }
 1455            // Create Result
 01456            var _result = new HttpOperationResponse<ReadReceiptResult>();
 01457            _result.Request = _httpRequest;
 01458            _result.Response = _httpResponse;
 1459            // Deserialize Response
 01460            if ((int)_statusCode == 200)
 1461            {
 01462                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1463                try
 1464                {
 01465                    _result.Body = SafeJsonConvert.DeserializeObject<ReadReceiptResult>(_responseContent, Deserializatio
 01466                }
 01467                catch (JsonException ex)
 1468                {
 01469                    _httpRequest.Dispose();
 01470                    if (_httpResponse != null)
 1471                    {
 01472                        _httpResponse.Dispose();
 1473                    }
 01474                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1475                }
 1476            }
 01477            if (_shouldTrace)
 1478            {
 01479                ServiceClientTracing.Exit(_invocationId, _result);
 1480            }
 01481            return _result;
 01482        }
 1483
 1484        /// <summary>
 1485        /// Read Receipt operation. When you use the 'Batch Read Receipt' interface,
 1486        /// the response contains a field called 'Operation-Location'. The
 1487        /// 'Operation-Location' field contains the URL that you must use for your 'Get
 1488        /// Read Receipt Result' operation.
 1489        /// </summary>
 1490        /// <param name='image'>
 1491        /// An image stream.
 1492        /// </param>
 1493        /// <param name='customHeaders'>
 1494        /// Headers that will be added to request.
 1495        /// </param>
 1496        /// <param name='cancellationToken'>
 1497        /// The cancellation token.
 1498        /// </param>
 1499        /// <exception cref="ComputerVisionErrorException">
 1500        /// Thrown when the operation returned an invalid status code
 1501        /// </exception>
 1502        /// <exception cref="ValidationException">
 1503        /// Thrown when a required parameter is null
 1504        /// </exception>
 1505        /// <exception cref="System.ArgumentNullException">
 1506        /// Thrown when a required parameter is null
 1507        /// </exception>
 1508        /// <return>
 1509        /// A response object containing the response body and response headers.
 1510        /// </return>
 1511        public async Task<HttpOperationHeaderResponse<BatchReadReceiptInStreamHeaders>> BatchReadReceiptInStreamWithHttp
 1512        {
 01513            if (Endpoint == null)
 1514            {
 01515                throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint");
 1516            }
 01517            if (image == null)
 1518            {
 01519                throw new ValidationException(ValidationRules.CannotBeNull, "image");
 1520            }
 1521            // Tracing
 01522            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01523            string _invocationId = null;
 01524            if (_shouldTrace)
 1525            {
 01526                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01527                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01528                tracingParameters.Add("image", image);
 01529                tracingParameters.Add("cancellationToken", cancellationToken);
 01530                ServiceClientTracing.Enter(_invocationId, this, "BatchReadReceiptInStream", tracingParameters);
 1531            }
 1532            // Construct URL
 01533            var _baseUrl = BaseUri;
 01534            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "prebuilt/receipt/asyncBatchAnalyze";
 01535            _url = _url.Replace("{Endpoint}", Endpoint);
 1536            // Create HTTP transport objects
 01537            var _httpRequest = new HttpRequestMessage();
 01538            HttpResponseMessage _httpResponse = null;
 01539            _httpRequest.Method = new HttpMethod("POST");
 01540            _httpRequest.RequestUri = new System.Uri(_url);
 1541            // Set Headers
 1542
 1543
 01544            if (customHeaders != null)
 1545            {
 01546                foreach(var _header in customHeaders)
 1547                {
 01548                    if (_httpRequest.Headers.Contains(_header.Key))
 1549                    {
 01550                        _httpRequest.Headers.Remove(_header.Key);
 1551                    }
 01552                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1553                }
 1554            }
 1555
 1556            // Serialize Request
 01557            string _requestContent = null;
 01558            if(image == null)
 1559            {
 01560              throw new System.ArgumentNullException("image");
 1561            }
 01562            if (image != null && image != Stream.Null)
 1563            {
 01564                _httpRequest.Content = new StreamContent(image);
 01565                _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/octet-stream");
 1566            }
 1567            // Set Credentials
 01568            if (Credentials != null)
 1569            {
 01570                cancellationToken.ThrowIfCancellationRequested();
 01571                await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1572            }
 1573            // Send Request
 01574            if (_shouldTrace)
 1575            {
 01576                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1577            }
 01578            cancellationToken.ThrowIfCancellationRequested();
 01579            _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01580            if (_shouldTrace)
 1581            {
 01582                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1583            }
 01584            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01585            cancellationToken.ThrowIfCancellationRequested();
 01586            string _responseContent = null;
 01587            if ((int)_statusCode != 202)
 1588            {
 01589                var ex = new ComputerVisionErrorException(string.Format("Operation returned an invalid status code '{0}'
 1590                try
 1591                {
 01592                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01593                    ComputerVisionError _errorBody =  SafeJsonConvert.DeserializeObject<ComputerVisionError>(_responseCo
 01594                    if (_errorBody != null)
 1595                    {
 01596                        ex.Body = _errorBody;
 1597                    }
 01598                }
 01599                catch (JsonException)
 1600                {
 1601                    // Ignore the exception
 01602                }
 01603                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01604                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01605                if (_shouldTrace)
 1606                {
 01607                    ServiceClientTracing.Error(_invocationId, ex);
 1608                }
 01609                _httpRequest.Dispose();
 01610                if (_httpResponse != null)
 1611                {
 01612                    _httpResponse.Dispose();
 1613                }
 01614                throw ex;
 1615            }
 1616            // Create Result
 01617            var _result = new HttpOperationHeaderResponse<BatchReadReceiptInStreamHeaders>();
 01618            _result.Request = _httpRequest;
 01619            _result.Response = _httpResponse;
 1620            try
 1621            {
 01622                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<BatchReadReceiptInStreamHeaders>(JsonSeriali
 01623            }
 01624            catch (JsonException ex)
 1625            {
 01626                _httpRequest.Dispose();
 01627                if (_httpResponse != null)
 1628                {
 01629                    _httpResponse.Dispose();
 1630                }
 01631                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1632            }
 01633            if (_shouldTrace)
 1634            {
 01635                ServiceClientTracing.Exit(_invocationId, _result);
 1636            }
 01637            return _result;
 01638        }
 1639
 1640    }
 1641}