< Summary

Class:Microsoft.Azure.CognitiveServices.ContentModerator.ImageModeration
Assembly:Microsoft.Azure.CognitiveServices.Vision.ContentModerator
File(s):C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.ContentModerator\src\Generated\ImageModeration.cs
Covered lines:4
Uncovered lines:983
Coverable lines:987
Total lines:2228
Line coverage:0.4% (4 of 987)
Covered branches:1
Total branches:514
Branch coverage:0.1% (1 of 514)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-0%100%
FindFacesWithHttpMessagesAsync()-0%0%
OCRMethodWithHttpMessagesAsync()-0%0%
EvaluateMethodWithHttpMessagesAsync()-0%0%
MatchMethodWithHttpMessagesAsync()-0%0%
FindFacesFileInputWithHttpMessagesAsync()-0%0%
FindFacesUrlInputWithHttpMessagesAsync()-0%0%
OCRUrlInputWithHttpMessagesAsync()-0%0%
OCRFileInputWithHttpMessagesAsync()-0%0%
EvaluateFileInputWithHttpMessagesAsync()-0%0%
EvaluateUrlInputWithHttpMessagesAsync()-0%0%
MatchUrlInputWithHttpMessagesAsync()-0%0%
MatchFileInputWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\cognitiveservices\Vision.ContentModerator\src\Generated\ImageModeration.cs

#LineLine coverage
 1// <auto-generated>
 2// Code generated by Microsoft (R) AutoRest Code Generator.
 3// Changes may cause incorrect behavior and will be lost if the code is
 4// regenerated.
 5// </auto-generated>
 6
 7namespace Microsoft.Azure.CognitiveServices.ContentModerator
 8{
 9    using Microsoft.Rest;
 10    using Models;
 11    using Newtonsoft.Json;
 12    using System.Collections;
 13    using System.Collections.Generic;
 14    using System.IO;
 15    using System.Linq;
 16    using System.Net;
 17    using System.Net.Http;
 18    using System.Threading;
 19    using System.Threading.Tasks;
 20
 21    /// <summary>
 22    /// ImageModeration operations.
 23    /// </summary>
 24    public partial class ImageModeration : IServiceOperations<ContentModeratorClient>, IImageModeration
 25    {
 26        /// <summary>
 27        /// Initializes a new instance of the ImageModeration class.
 28        /// </summary>
 29        /// <param name='client'>
 30        /// Reference to the service client.
 31        /// </param>
 32        /// <exception cref="System.ArgumentNullException">
 33        /// Thrown when a required parameter is null
 34        /// </exception>
 535        public ImageModeration(ContentModeratorClient client)
 36        {
 537            if (client == null)
 38            {
 039                throw new System.ArgumentNullException("client");
 40            }
 541            Client = client;
 542        }
 43
 44        /// <summary>
 45        /// Gets a reference to the ContentModeratorClient
 46        /// </summary>
 047        public ContentModeratorClient Client { get; private set; }
 48
 49        /// <summary>
 50        /// Returns the list of faces found.
 51        /// </summary>
 52        /// <param name='cacheImage'>
 53        /// Whether to retain the submitted image for future use; defaults to false if
 54        /// omitted.
 55        /// </param>
 56        /// <param name='customHeaders'>
 57        /// Headers that will be added to request.
 58        /// </param>
 59        /// <param name='cancellationToken'>
 60        /// The cancellation token.
 61        /// </param>
 62        /// <exception cref="APIErrorException">
 63        /// Thrown when the operation returned an invalid status code
 64        /// </exception>
 65        /// <exception cref="SerializationException">
 66        /// Thrown when unable to deserialize the response
 67        /// </exception>
 68        /// <exception cref="ValidationException">
 69        /// Thrown when a required parameter is null
 70        /// </exception>
 71        /// <exception cref="System.ArgumentNullException">
 72        /// Thrown when a required parameter is null
 73        /// </exception>
 74        /// <return>
 75        /// A response object containing the response body and response headers.
 76        /// </return>
 77        public async Task<HttpOperationResponse<FoundFaces>> FindFacesWithHttpMessagesAsync(bool? cacheImage = default(b
 78        {
 079            if (Client.Endpoint == null)
 80            {
 081                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 82            }
 83            // Tracing
 084            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 085            string _invocationId = null;
 086            if (_shouldTrace)
 87            {
 088                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 089                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 090                tracingParameters.Add("cacheImage", cacheImage);
 091                tracingParameters.Add("cancellationToken", cancellationToken);
 092                ServiceClientTracing.Enter(_invocationId, this, "FindFaces", tracingParameters);
 93            }
 94            // Construct URL
 095            var _baseUrl = Client.BaseUri;
 096            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Fin
 097            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 098            List<string> _queryParameters = new List<string>();
 099            if (cacheImage != null)
 100            {
 0101                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 102            }
 0103            if (_queryParameters.Count > 0)
 104            {
 0105                _url += "?" + string.Join("&", _queryParameters);
 106            }
 107            // Create HTTP transport objects
 0108            var _httpRequest = new HttpRequestMessage();
 0109            HttpResponseMessage _httpResponse = null;
 0110            _httpRequest.Method = new HttpMethod("POST");
 0111            _httpRequest.RequestUri = new System.Uri(_url);
 112            // Set Headers
 113
 114
 0115            if (customHeaders != null)
 116            {
 0117                foreach(var _header in customHeaders)
 118                {
 0119                    if (_httpRequest.Headers.Contains(_header.Key))
 120                    {
 0121                        _httpRequest.Headers.Remove(_header.Key);
 122                    }
 0123                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 124                }
 125            }
 126
 127            // Serialize Request
 0128            string _requestContent = null;
 129            // Set Credentials
 0130            if (Client.Credentials != null)
 131            {
 0132                cancellationToken.ThrowIfCancellationRequested();
 0133                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 134            }
 135            // Send Request
 0136            if (_shouldTrace)
 137            {
 0138                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 139            }
 0140            cancellationToken.ThrowIfCancellationRequested();
 0141            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0142            if (_shouldTrace)
 143            {
 0144                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 145            }
 0146            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0147            cancellationToken.ThrowIfCancellationRequested();
 0148            string _responseContent = null;
 0149            if ((int)_statusCode != 200)
 150            {
 0151                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 152                try
 153                {
 0154                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0155                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0156                    if (_errorBody != null)
 157                    {
 0158                        ex.Body = _errorBody;
 159                    }
 0160                }
 0161                catch (JsonException)
 162                {
 163                    // Ignore the exception
 0164                }
 0165                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0166                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0167                if (_shouldTrace)
 168                {
 0169                    ServiceClientTracing.Error(_invocationId, ex);
 170                }
 0171                _httpRequest.Dispose();
 0172                if (_httpResponse != null)
 173                {
 0174                    _httpResponse.Dispose();
 175                }
 0176                throw ex;
 177            }
 178            // Create Result
 0179            var _result = new HttpOperationResponse<FoundFaces>();
 0180            _result.Request = _httpRequest;
 0181            _result.Response = _httpResponse;
 182            // Deserialize Response
 0183            if ((int)_statusCode == 200)
 184            {
 0185                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 186                try
 187                {
 0188                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FoundFaces>(_responseContent, Cl
 0189                }
 0190                catch (JsonException ex)
 191                {
 0192                    _httpRequest.Dispose();
 0193                    if (_httpResponse != null)
 194                    {
 0195                        _httpResponse.Dispose();
 196                    }
 0197                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 198                }
 199            }
 0200            if (_shouldTrace)
 201            {
 0202                ServiceClientTracing.Exit(_invocationId, _result);
 203            }
 0204            return _result;
 0205        }
 206
 207        /// <summary>
 208        /// Returns any text found in the image for the language specified. If no
 209        /// language is specified in input then the detection defaults to English.
 210        /// </summary>
 211        /// <param name='language'>
 212        /// Language of the terms.
 213        /// </param>
 214        /// <param name='cacheImage'>
 215        /// Whether to retain the submitted image for future use; defaults to false if
 216        /// omitted.
 217        /// </param>
 218        /// <param name='enhanced'>
 219        /// When set to True, the image goes through additional processing to come with
 220        /// additional candidates.
 221        ///
 222        /// image/tiff is not supported when enhanced is set to true
 223        ///
 224        /// Note: This impacts the response time.
 225        /// </param>
 226        /// <param name='customHeaders'>
 227        /// Headers that will be added to request.
 228        /// </param>
 229        /// <param name='cancellationToken'>
 230        /// The cancellation token.
 231        /// </param>
 232        /// <exception cref="APIErrorException">
 233        /// Thrown when the operation returned an invalid status code
 234        /// </exception>
 235        /// <exception cref="SerializationException">
 236        /// Thrown when unable to deserialize the response
 237        /// </exception>
 238        /// <exception cref="ValidationException">
 239        /// Thrown when a required parameter is null
 240        /// </exception>
 241        /// <exception cref="System.ArgumentNullException">
 242        /// Thrown when a required parameter is null
 243        /// </exception>
 244        /// <return>
 245        /// A response object containing the response body and response headers.
 246        /// </return>
 247        public async Task<HttpOperationResponse<OCR>> OCRMethodWithHttpMessagesAsync(string language, bool? cacheImage =
 248        {
 0249            if (Client.Endpoint == null)
 250            {
 0251                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 252            }
 0253            if (language == null)
 254            {
 0255                throw new ValidationException(ValidationRules.CannotBeNull, "language");
 256            }
 257            // Tracing
 0258            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0259            string _invocationId = null;
 0260            if (_shouldTrace)
 261            {
 0262                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0263                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0264                tracingParameters.Add("language", language);
 0265                tracingParameters.Add("cacheImage", cacheImage);
 0266                tracingParameters.Add("enhanced", enhanced);
 0267                tracingParameters.Add("cancellationToken", cancellationToken);
 0268                ServiceClientTracing.Enter(_invocationId, this, "OCRMethod", tracingParameters);
 269            }
 270            // Construct URL
 0271            var _baseUrl = Client.BaseUri;
 0272            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/OCR
 0273            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0274            List<string> _queryParameters = new List<string>();
 0275            if (language != null)
 276            {
 0277                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language)));
 278            }
 0279            if (cacheImage != null)
 280            {
 0281                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 282            }
 0283            if (enhanced != null)
 284            {
 0285                _queryParameters.Add(string.Format("enhanced={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs
 286            }
 0287            if (_queryParameters.Count > 0)
 288            {
 0289                _url += "?" + string.Join("&", _queryParameters);
 290            }
 291            // Create HTTP transport objects
 0292            var _httpRequest = new HttpRequestMessage();
 0293            HttpResponseMessage _httpResponse = null;
 0294            _httpRequest.Method = new HttpMethod("POST");
 0295            _httpRequest.RequestUri = new System.Uri(_url);
 296            // Set Headers
 297
 298
 0299            if (customHeaders != null)
 300            {
 0301                foreach(var _header in customHeaders)
 302                {
 0303                    if (_httpRequest.Headers.Contains(_header.Key))
 304                    {
 0305                        _httpRequest.Headers.Remove(_header.Key);
 306                    }
 0307                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 308                }
 309            }
 310
 311            // Serialize Request
 0312            string _requestContent = null;
 313            // Set Credentials
 0314            if (Client.Credentials != null)
 315            {
 0316                cancellationToken.ThrowIfCancellationRequested();
 0317                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 318            }
 319            // Send Request
 0320            if (_shouldTrace)
 321            {
 0322                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 323            }
 0324            cancellationToken.ThrowIfCancellationRequested();
 0325            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0326            if (_shouldTrace)
 327            {
 0328                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 329            }
 0330            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0331            cancellationToken.ThrowIfCancellationRequested();
 0332            string _responseContent = null;
 0333            if ((int)_statusCode != 200)
 334            {
 0335                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 336                try
 337                {
 0338                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0339                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0340                    if (_errorBody != null)
 341                    {
 0342                        ex.Body = _errorBody;
 343                    }
 0344                }
 0345                catch (JsonException)
 346                {
 347                    // Ignore the exception
 0348                }
 0349                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0350                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0351                if (_shouldTrace)
 352                {
 0353                    ServiceClientTracing.Error(_invocationId, ex);
 354                }
 0355                _httpRequest.Dispose();
 0356                if (_httpResponse != null)
 357                {
 0358                    _httpResponse.Dispose();
 359                }
 0360                throw ex;
 361            }
 362            // Create Result
 0363            var _result = new HttpOperationResponse<OCR>();
 0364            _result.Request = _httpRequest;
 0365            _result.Response = _httpResponse;
 366            // Deserialize Response
 0367            if ((int)_statusCode == 200)
 368            {
 0369                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 370                try
 371                {
 0372                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OCR>(_responseContent, Client.De
 0373                }
 0374                catch (JsonException ex)
 375                {
 0376                    _httpRequest.Dispose();
 0377                    if (_httpResponse != null)
 378                    {
 0379                        _httpResponse.Dispose();
 380                    }
 0381                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 382                }
 383            }
 0384            if (_shouldTrace)
 385            {
 0386                ServiceClientTracing.Exit(_invocationId, _result);
 387            }
 0388            return _result;
 0389        }
 390
 391        /// <summary>
 392        /// Returns probabilities of the image containing racy or adult content.
 393        /// </summary>
 394        /// <param name='cacheImage'>
 395        /// Whether to retain the submitted image for future use; defaults to false if
 396        /// omitted.
 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="APIErrorException">
 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<Evaluate>> EvaluateMethodWithHttpMessagesAsync(bool? cacheImage = defaul
 420        {
 0421            if (Client.Endpoint == null)
 422            {
 0423                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.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("cacheImage", cacheImage);
 0433                tracingParameters.Add("cancellationToken", cancellationToken);
 0434                ServiceClientTracing.Enter(_invocationId, this, "EvaluateMethod", tracingParameters);
 435            }
 436            // Construct URL
 0437            var _baseUrl = Client.BaseUri;
 0438            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Eva
 0439            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0440            List<string> _queryParameters = new List<string>();
 0441            if (cacheImage != null)
 442            {
 0443                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 444            }
 0445            if (_queryParameters.Count > 0)
 446            {
 0447                _url += "?" + string.Join("&", _queryParameters);
 448            }
 449            // Create HTTP transport objects
 0450            var _httpRequest = new HttpRequestMessage();
 0451            HttpResponseMessage _httpResponse = null;
 0452            _httpRequest.Method = new HttpMethod("POST");
 0453            _httpRequest.RequestUri = new System.Uri(_url);
 454            // Set Headers
 455
 456
 0457            if (customHeaders != null)
 458            {
 0459                foreach(var _header in customHeaders)
 460                {
 0461                    if (_httpRequest.Headers.Contains(_header.Key))
 462                    {
 0463                        _httpRequest.Headers.Remove(_header.Key);
 464                    }
 0465                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 466                }
 467            }
 468
 469            // Serialize Request
 0470            string _requestContent = null;
 471            // Set Credentials
 0472            if (Client.Credentials != null)
 473            {
 0474                cancellationToken.ThrowIfCancellationRequested();
 0475                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 476            }
 477            // Send Request
 0478            if (_shouldTrace)
 479            {
 0480                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 481            }
 0482            cancellationToken.ThrowIfCancellationRequested();
 0483            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0484            if (_shouldTrace)
 485            {
 0486                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 487            }
 0488            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0489            cancellationToken.ThrowIfCancellationRequested();
 0490            string _responseContent = null;
 0491            if ((int)_statusCode != 200)
 492            {
 0493                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 494                try
 495                {
 0496                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0497                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0498                    if (_errorBody != null)
 499                    {
 0500                        ex.Body = _errorBody;
 501                    }
 0502                }
 0503                catch (JsonException)
 504                {
 505                    // Ignore the exception
 0506                }
 0507                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0508                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0509                if (_shouldTrace)
 510                {
 0511                    ServiceClientTracing.Error(_invocationId, ex);
 512                }
 0513                _httpRequest.Dispose();
 0514                if (_httpResponse != null)
 515                {
 0516                    _httpResponse.Dispose();
 517                }
 0518                throw ex;
 519            }
 520            // Create Result
 0521            var _result = new HttpOperationResponse<Evaluate>();
 0522            _result.Request = _httpRequest;
 0523            _result.Response = _httpResponse;
 524            // Deserialize Response
 0525            if ((int)_statusCode == 200)
 526            {
 0527                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 528                try
 529                {
 0530                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Evaluate>(_responseContent, Clie
 0531                }
 0532                catch (JsonException ex)
 533                {
 0534                    _httpRequest.Dispose();
 0535                    if (_httpResponse != null)
 536                    {
 0537                        _httpResponse.Dispose();
 538                    }
 0539                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 540                }
 541            }
 0542            if (_shouldTrace)
 543            {
 0544                ServiceClientTracing.Exit(_invocationId, _result);
 545            }
 0546            return _result;
 0547        }
 548
 549        /// <summary>
 550        /// Fuzzily match an image against one of your custom Image Lists. You can
 551        /// create and manage your custom image lists using &lt;a
 552        /// href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe"&gt;this&lt;/a&gt;
 553        /// API.
 554        ///
 555        /// Returns ID and tags of matching image.&lt;br/&gt;
 556        /// &lt;br/&gt;
 557        /// Note: Refresh Index must be run on the corresponding Image List before
 558        /// additions and removals are reflected in the response.
 559        /// </summary>
 560        /// <param name='listId'>
 561        /// The list Id.
 562        /// </param>
 563        /// <param name='cacheImage'>
 564        /// Whether to retain the submitted image for future use; defaults to false if
 565        /// omitted.
 566        /// </param>
 567        /// <param name='customHeaders'>
 568        /// Headers that will be added to request.
 569        /// </param>
 570        /// <param name='cancellationToken'>
 571        /// The cancellation token.
 572        /// </param>
 573        /// <exception cref="APIErrorException">
 574        /// Thrown when the operation returned an invalid status code
 575        /// </exception>
 576        /// <exception cref="SerializationException">
 577        /// Thrown when unable to deserialize the response
 578        /// </exception>
 579        /// <exception cref="ValidationException">
 580        /// Thrown when a required parameter is null
 581        /// </exception>
 582        /// <exception cref="System.ArgumentNullException">
 583        /// Thrown when a required parameter is null
 584        /// </exception>
 585        /// <return>
 586        /// A response object containing the response body and response headers.
 587        /// </return>
 588        public async Task<HttpOperationResponse<MatchResponse>> MatchMethodWithHttpMessagesAsync(string listId = default
 589        {
 0590            if (Client.Endpoint == null)
 591            {
 0592                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 593            }
 594            // Tracing
 0595            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0596            string _invocationId = null;
 0597            if (_shouldTrace)
 598            {
 0599                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0600                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0601                tracingParameters.Add("listId", listId);
 0602                tracingParameters.Add("cacheImage", cacheImage);
 0603                tracingParameters.Add("cancellationToken", cancellationToken);
 0604                ServiceClientTracing.Enter(_invocationId, this, "MatchMethod", tracingParameters);
 605            }
 606            // Construct URL
 0607            var _baseUrl = Client.BaseUri;
 0608            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Mat
 0609            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0610            List<string> _queryParameters = new List<string>();
 0611            if (listId != null)
 612            {
 0613                _queryParameters.Add(string.Format("listId={0}", System.Uri.EscapeDataString(listId)));
 614            }
 0615            if (cacheImage != null)
 616            {
 0617                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 618            }
 0619            if (_queryParameters.Count > 0)
 620            {
 0621                _url += "?" + string.Join("&", _queryParameters);
 622            }
 623            // Create HTTP transport objects
 0624            var _httpRequest = new HttpRequestMessage();
 0625            HttpResponseMessage _httpResponse = null;
 0626            _httpRequest.Method = new HttpMethod("POST");
 0627            _httpRequest.RequestUri = new System.Uri(_url);
 628            // Set Headers
 629
 630
 0631            if (customHeaders != null)
 632            {
 0633                foreach(var _header in customHeaders)
 634                {
 0635                    if (_httpRequest.Headers.Contains(_header.Key))
 636                    {
 0637                        _httpRequest.Headers.Remove(_header.Key);
 638                    }
 0639                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 640                }
 641            }
 642
 643            // Serialize Request
 0644            string _requestContent = null;
 645            // Set Credentials
 0646            if (Client.Credentials != null)
 647            {
 0648                cancellationToken.ThrowIfCancellationRequested();
 0649                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 650            }
 651            // Send Request
 0652            if (_shouldTrace)
 653            {
 0654                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 655            }
 0656            cancellationToken.ThrowIfCancellationRequested();
 0657            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0658            if (_shouldTrace)
 659            {
 0660                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 661            }
 0662            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0663            cancellationToken.ThrowIfCancellationRequested();
 0664            string _responseContent = null;
 0665            if ((int)_statusCode != 200)
 666            {
 0667                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 668                try
 669                {
 0670                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0671                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0672                    if (_errorBody != null)
 673                    {
 0674                        ex.Body = _errorBody;
 675                    }
 0676                }
 0677                catch (JsonException)
 678                {
 679                    // Ignore the exception
 0680                }
 0681                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0682                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0683                if (_shouldTrace)
 684                {
 0685                    ServiceClientTracing.Error(_invocationId, ex);
 686                }
 0687                _httpRequest.Dispose();
 0688                if (_httpResponse != null)
 689                {
 0690                    _httpResponse.Dispose();
 691                }
 0692                throw ex;
 693            }
 694            // Create Result
 0695            var _result = new HttpOperationResponse<MatchResponse>();
 0696            _result.Request = _httpRequest;
 0697            _result.Response = _httpResponse;
 698            // Deserialize Response
 0699            if ((int)_statusCode == 200)
 700            {
 0701                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 702                try
 703                {
 0704                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<MatchResponse>(_responseContent,
 0705                }
 0706                catch (JsonException ex)
 707                {
 0708                    _httpRequest.Dispose();
 0709                    if (_httpResponse != null)
 710                    {
 0711                        _httpResponse.Dispose();
 712                    }
 0713                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 714                }
 715            }
 0716            if (_shouldTrace)
 717            {
 0718                ServiceClientTracing.Exit(_invocationId, _result);
 719            }
 0720            return _result;
 0721        }
 722
 723        /// <summary>
 724        /// Returns the list of faces found.
 725        /// </summary>
 726        /// <param name='imageStream'>
 727        /// The image file.
 728        /// </param>
 729        /// <param name='cacheImage'>
 730        /// Whether to retain the submitted image for future use; defaults to false if
 731        /// omitted.
 732        /// </param>
 733        /// <param name='customHeaders'>
 734        /// Headers that will be added to request.
 735        /// </param>
 736        /// <param name='cancellationToken'>
 737        /// The cancellation token.
 738        /// </param>
 739        /// <exception cref="APIErrorException">
 740        /// Thrown when the operation returned an invalid status code
 741        /// </exception>
 742        /// <exception cref="SerializationException">
 743        /// Thrown when unable to deserialize the response
 744        /// </exception>
 745        /// <exception cref="ValidationException">
 746        /// Thrown when a required parameter is null
 747        /// </exception>
 748        /// <exception cref="System.ArgumentNullException">
 749        /// Thrown when a required parameter is null
 750        /// </exception>
 751        /// <return>
 752        /// A response object containing the response body and response headers.
 753        /// </return>
 754        public async Task<HttpOperationResponse<FoundFaces>> FindFacesFileInputWithHttpMessagesAsync(Stream imageStream,
 755        {
 0756            if (Client.Endpoint == null)
 757            {
 0758                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 759            }
 0760            if (imageStream == null)
 761            {
 0762                throw new ValidationException(ValidationRules.CannotBeNull, "imageStream");
 763            }
 764            // Tracing
 0765            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0766            string _invocationId = null;
 0767            if (_shouldTrace)
 768            {
 0769                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0770                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0771                tracingParameters.Add("cacheImage", cacheImage);
 0772                tracingParameters.Add("imageStream", imageStream);
 0773                tracingParameters.Add("cancellationToken", cancellationToken);
 0774                ServiceClientTracing.Enter(_invocationId, this, "FindFacesFileInput", tracingParameters);
 775            }
 776            // Construct URL
 0777            var _baseUrl = Client.BaseUri;
 0778            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Fin
 0779            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0780            List<string> _queryParameters = new List<string>();
 0781            if (cacheImage != null)
 782            {
 0783                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 784            }
 0785            if (_queryParameters.Count > 0)
 786            {
 0787                _url += "?" + string.Join("&", _queryParameters);
 788            }
 789            // Create HTTP transport objects
 0790            var _httpRequest = new HttpRequestMessage();
 0791            HttpResponseMessage _httpResponse = null;
 0792            _httpRequest.Method = new HttpMethod("POST");
 0793            _httpRequest.RequestUri = new System.Uri(_url);
 794            // Set Headers
 795
 796
 0797            if (customHeaders != null)
 798            {
 0799                foreach(var _header in customHeaders)
 800                {
 0801                    if (_httpRequest.Headers.Contains(_header.Key))
 802                    {
 0803                        _httpRequest.Headers.Remove(_header.Key);
 804                    }
 0805                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 806                }
 807            }
 808
 809            // Serialize Request
 0810            string _requestContent = null;
 0811            if(imageStream == null)
 812            {
 0813              throw new System.ArgumentNullException("imageStream");
 814            }
 0815            if (imageStream != null && imageStream != Stream.Null)
 816            {
 0817                _httpRequest.Content = new StreamContent(imageStream);
 0818                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif"
 819            }
 820            // Set Credentials
 0821            if (Client.Credentials != null)
 822            {
 0823                cancellationToken.ThrowIfCancellationRequested();
 0824                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 825            }
 826            // Send Request
 0827            if (_shouldTrace)
 828            {
 0829                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 830            }
 0831            cancellationToken.ThrowIfCancellationRequested();
 0832            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0833            if (_shouldTrace)
 834            {
 0835                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 836            }
 0837            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0838            cancellationToken.ThrowIfCancellationRequested();
 0839            string _responseContent = null;
 0840            if ((int)_statusCode != 200)
 841            {
 0842                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 843                try
 844                {
 0845                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0846                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 0847                    if (_errorBody != null)
 848                    {
 0849                        ex.Body = _errorBody;
 850                    }
 0851                }
 0852                catch (JsonException)
 853                {
 854                    // Ignore the exception
 0855                }
 0856                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0857                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0858                if (_shouldTrace)
 859                {
 0860                    ServiceClientTracing.Error(_invocationId, ex);
 861                }
 0862                _httpRequest.Dispose();
 0863                if (_httpResponse != null)
 864                {
 0865                    _httpResponse.Dispose();
 866                }
 0867                throw ex;
 868            }
 869            // Create Result
 0870            var _result = new HttpOperationResponse<FoundFaces>();
 0871            _result.Request = _httpRequest;
 0872            _result.Response = _httpResponse;
 873            // Deserialize Response
 0874            if ((int)_statusCode == 200)
 875            {
 0876                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 877                try
 878                {
 0879                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FoundFaces>(_responseContent, Cl
 0880                }
 0881                catch (JsonException ex)
 882                {
 0883                    _httpRequest.Dispose();
 0884                    if (_httpResponse != null)
 885                    {
 0886                        _httpResponse.Dispose();
 887                    }
 0888                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 889                }
 890            }
 0891            if (_shouldTrace)
 892            {
 0893                ServiceClientTracing.Exit(_invocationId, _result);
 894            }
 0895            return _result;
 0896        }
 897
 898        /// <summary>
 899        /// Returns the list of faces found.
 900        /// </summary>
 901        /// <param name='contentType'>
 902        /// The content type.
 903        /// </param>
 904        /// <param name='imageUrl'>
 905        /// The image url.
 906        /// </param>
 907        /// <param name='cacheImage'>
 908        /// Whether to retain the submitted image for future use; defaults to false if
 909        /// omitted.
 910        /// </param>
 911        /// <param name='customHeaders'>
 912        /// Headers that will be added to request.
 913        /// </param>
 914        /// <param name='cancellationToken'>
 915        /// The cancellation token.
 916        /// </param>
 917        /// <exception cref="APIErrorException">
 918        /// Thrown when the operation returned an invalid status code
 919        /// </exception>
 920        /// <exception cref="SerializationException">
 921        /// Thrown when unable to deserialize the response
 922        /// </exception>
 923        /// <exception cref="ValidationException">
 924        /// Thrown when a required parameter is null
 925        /// </exception>
 926        /// <exception cref="System.ArgumentNullException">
 927        /// Thrown when a required parameter is null
 928        /// </exception>
 929        /// <return>
 930        /// A response object containing the response body and response headers.
 931        /// </return>
 932        public async Task<HttpOperationResponse<FoundFaces>> FindFacesUrlInputWithHttpMessagesAsync(string contentType, 
 933        {
 0934            if (Client.Endpoint == null)
 935            {
 0936                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 937            }
 0938            if (contentType == null)
 939            {
 0940                throw new ValidationException(ValidationRules.CannotBeNull, "contentType");
 941            }
 0942            if (imageUrl == null)
 943            {
 0944                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 945            }
 946            // Tracing
 0947            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0948            string _invocationId = null;
 0949            if (_shouldTrace)
 950            {
 0951                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0952                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0953                tracingParameters.Add("cacheImage", cacheImage);
 0954                tracingParameters.Add("contentType", contentType);
 0955                tracingParameters.Add("imageUrl", imageUrl);
 0956                tracingParameters.Add("cancellationToken", cancellationToken);
 0957                ServiceClientTracing.Enter(_invocationId, this, "FindFacesUrlInput", tracingParameters);
 958            }
 959            // Construct URL
 0960            var _baseUrl = Client.BaseUri;
 0961            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Fin
 0962            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 0963            List<string> _queryParameters = new List<string>();
 0964            if (cacheImage != null)
 965            {
 0966                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 967            }
 0968            if (_queryParameters.Count > 0)
 969            {
 0970                _url += "?" + string.Join("&", _queryParameters);
 971            }
 972            // Create HTTP transport objects
 0973            var _httpRequest = new HttpRequestMessage();
 0974            HttpResponseMessage _httpResponse = null;
 0975            _httpRequest.Method = new HttpMethod("POST");
 0976            _httpRequest.RequestUri = new System.Uri(_url);
 977            // Set Headers
 978
 979
 0980            if (customHeaders != null)
 981            {
 0982                foreach(var _header in customHeaders)
 983                {
 0984                    if (_httpRequest.Headers.Contains(_header.Key))
 985                    {
 0986                        _httpRequest.Headers.Remove(_header.Key);
 987                    }
 0988                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 989                }
 990            }
 991
 992            // Serialize Request
 0993            string _requestContent = null;
 0994            if(imageUrl != null)
 995            {
 0996                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 0997                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0998                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 999            }
 1000            // Set Credentials
 01001            if (Client.Credentials != null)
 1002            {
 01003                cancellationToken.ThrowIfCancellationRequested();
 01004                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1005            }
 1006            // Send Request
 01007            if (_shouldTrace)
 1008            {
 01009                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1010            }
 01011            cancellationToken.ThrowIfCancellationRequested();
 01012            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01013            if (_shouldTrace)
 1014            {
 01015                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1016            }
 01017            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01018            cancellationToken.ThrowIfCancellationRequested();
 01019            string _responseContent = null;
 01020            if ((int)_statusCode != 200)
 1021            {
 01022                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1023                try
 1024                {
 01025                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01026                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01027                    if (_errorBody != null)
 1028                    {
 01029                        ex.Body = _errorBody;
 1030                    }
 01031                }
 01032                catch (JsonException)
 1033                {
 1034                    // Ignore the exception
 01035                }
 01036                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01037                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01038                if (_shouldTrace)
 1039                {
 01040                    ServiceClientTracing.Error(_invocationId, ex);
 1041                }
 01042                _httpRequest.Dispose();
 01043                if (_httpResponse != null)
 1044                {
 01045                    _httpResponse.Dispose();
 1046                }
 01047                throw ex;
 1048            }
 1049            // Create Result
 01050            var _result = new HttpOperationResponse<FoundFaces>();
 01051            _result.Request = _httpRequest;
 01052            _result.Response = _httpResponse;
 1053            // Deserialize Response
 01054            if ((int)_statusCode == 200)
 1055            {
 01056                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1057                try
 1058                {
 01059                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<FoundFaces>(_responseContent, Cl
 01060                }
 01061                catch (JsonException ex)
 1062                {
 01063                    _httpRequest.Dispose();
 01064                    if (_httpResponse != null)
 1065                    {
 01066                        _httpResponse.Dispose();
 1067                    }
 01068                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1069                }
 1070            }
 01071            if (_shouldTrace)
 1072            {
 01073                ServiceClientTracing.Exit(_invocationId, _result);
 1074            }
 01075            return _result;
 01076        }
 1077
 1078        /// <summary>
 1079        /// Returns any text found in the image for the language specified. If no
 1080        /// language is specified in input then the detection defaults to English.
 1081        /// </summary>
 1082        /// <param name='language'>
 1083        /// Language of the terms.
 1084        /// </param>
 1085        /// <param name='contentType'>
 1086        /// The content type.
 1087        /// </param>
 1088        /// <param name='imageUrl'>
 1089        /// The image url.
 1090        /// </param>
 1091        /// <param name='cacheImage'>
 1092        /// Whether to retain the submitted image for future use; defaults to false if
 1093        /// omitted.
 1094        /// </param>
 1095        /// <param name='enhanced'>
 1096        /// When set to True, the image goes through additional processing to come with
 1097        /// additional candidates.
 1098        ///
 1099        /// image/tiff is not supported when enhanced is set to true
 1100        ///
 1101        /// Note: This impacts the response time.
 1102        /// </param>
 1103        /// <param name='customHeaders'>
 1104        /// Headers that will be added to request.
 1105        /// </param>
 1106        /// <param name='cancellationToken'>
 1107        /// The cancellation token.
 1108        /// </param>
 1109        /// <exception cref="APIErrorException">
 1110        /// Thrown when the operation returned an invalid status code
 1111        /// </exception>
 1112        /// <exception cref="SerializationException">
 1113        /// Thrown when unable to deserialize the response
 1114        /// </exception>
 1115        /// <exception cref="ValidationException">
 1116        /// Thrown when a required parameter is null
 1117        /// </exception>
 1118        /// <exception cref="System.ArgumentNullException">
 1119        /// Thrown when a required parameter is null
 1120        /// </exception>
 1121        /// <return>
 1122        /// A response object containing the response body and response headers.
 1123        /// </return>
 1124        public async Task<HttpOperationResponse<OCR>> OCRUrlInputWithHttpMessagesAsync(string language, string contentTy
 1125        {
 01126            if (Client.Endpoint == null)
 1127            {
 01128                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1129            }
 01130            if (language == null)
 1131            {
 01132                throw new ValidationException(ValidationRules.CannotBeNull, "language");
 1133            }
 01134            if (contentType == null)
 1135            {
 01136                throw new ValidationException(ValidationRules.CannotBeNull, "contentType");
 1137            }
 01138            if (imageUrl == null)
 1139            {
 01140                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 1141            }
 1142            // Tracing
 01143            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01144            string _invocationId = null;
 01145            if (_shouldTrace)
 1146            {
 01147                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01148                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01149                tracingParameters.Add("language", language);
 01150                tracingParameters.Add("cacheImage", cacheImage);
 01151                tracingParameters.Add("enhanced", enhanced);
 01152                tracingParameters.Add("contentType", contentType);
 01153                tracingParameters.Add("imageUrl", imageUrl);
 01154                tracingParameters.Add("cancellationToken", cancellationToken);
 01155                ServiceClientTracing.Enter(_invocationId, this, "OCRUrlInput", tracingParameters);
 1156            }
 1157            // Construct URL
 01158            var _baseUrl = Client.BaseUri;
 01159            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/OCR
 01160            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01161            List<string> _queryParameters = new List<string>();
 01162            if (language != null)
 1163            {
 01164                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language)));
 1165            }
 01166            if (cacheImage != null)
 1167            {
 01168                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 1169            }
 01170            if (enhanced != null)
 1171            {
 01172                _queryParameters.Add(string.Format("enhanced={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs
 1173            }
 01174            if (_queryParameters.Count > 0)
 1175            {
 01176                _url += "?" + string.Join("&", _queryParameters);
 1177            }
 1178            // Create HTTP transport objects
 01179            var _httpRequest = new HttpRequestMessage();
 01180            HttpResponseMessage _httpResponse = null;
 01181            _httpRequest.Method = new HttpMethod("POST");
 01182            _httpRequest.RequestUri = new System.Uri(_url);
 1183            // Set Headers
 1184
 1185
 01186            if (customHeaders != null)
 1187            {
 01188                foreach(var _header in customHeaders)
 1189                {
 01190                    if (_httpRequest.Headers.Contains(_header.Key))
 1191                    {
 01192                        _httpRequest.Headers.Remove(_header.Key);
 1193                    }
 01194                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1195                }
 1196            }
 1197
 1198            // Serialize Request
 01199            string _requestContent = null;
 01200            if(imageUrl != null)
 1201            {
 01202                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01203                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01204                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1205            }
 1206            // Set Credentials
 01207            if (Client.Credentials != null)
 1208            {
 01209                cancellationToken.ThrowIfCancellationRequested();
 01210                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1211            }
 1212            // Send Request
 01213            if (_shouldTrace)
 1214            {
 01215                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1216            }
 01217            cancellationToken.ThrowIfCancellationRequested();
 01218            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01219            if (_shouldTrace)
 1220            {
 01221                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1222            }
 01223            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01224            cancellationToken.ThrowIfCancellationRequested();
 01225            string _responseContent = null;
 01226            if ((int)_statusCode != 200)
 1227            {
 01228                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1229                try
 1230                {
 01231                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01232                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01233                    if (_errorBody != null)
 1234                    {
 01235                        ex.Body = _errorBody;
 1236                    }
 01237                }
 01238                catch (JsonException)
 1239                {
 1240                    // Ignore the exception
 01241                }
 01242                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01243                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01244                if (_shouldTrace)
 1245                {
 01246                    ServiceClientTracing.Error(_invocationId, ex);
 1247                }
 01248                _httpRequest.Dispose();
 01249                if (_httpResponse != null)
 1250                {
 01251                    _httpResponse.Dispose();
 1252                }
 01253                throw ex;
 1254            }
 1255            // Create Result
 01256            var _result = new HttpOperationResponse<OCR>();
 01257            _result.Request = _httpRequest;
 01258            _result.Response = _httpResponse;
 1259            // Deserialize Response
 01260            if ((int)_statusCode == 200)
 1261            {
 01262                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1263                try
 1264                {
 01265                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OCR>(_responseContent, Client.De
 01266                }
 01267                catch (JsonException ex)
 1268                {
 01269                    _httpRequest.Dispose();
 01270                    if (_httpResponse != null)
 1271                    {
 01272                        _httpResponse.Dispose();
 1273                    }
 01274                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1275                }
 1276            }
 01277            if (_shouldTrace)
 1278            {
 01279                ServiceClientTracing.Exit(_invocationId, _result);
 1280            }
 01281            return _result;
 01282        }
 1283
 1284        /// <summary>
 1285        /// Returns any text found in the image for the language specified. If no
 1286        /// language is specified in input then the detection defaults to English.
 1287        /// </summary>
 1288        /// <param name='language'>
 1289        /// Language of the terms.
 1290        /// </param>
 1291        /// <param name='imageStream'>
 1292        /// The image file.
 1293        /// </param>
 1294        /// <param name='cacheImage'>
 1295        /// Whether to retain the submitted image for future use; defaults to false if
 1296        /// omitted.
 1297        /// </param>
 1298        /// <param name='enhanced'>
 1299        /// When set to True, the image goes through additional processing to come with
 1300        /// additional candidates.
 1301        ///
 1302        /// image/tiff is not supported when enhanced is set to true
 1303        ///
 1304        /// Note: This impacts the response time.
 1305        /// </param>
 1306        /// <param name='customHeaders'>
 1307        /// Headers that will be added to request.
 1308        /// </param>
 1309        /// <param name='cancellationToken'>
 1310        /// The cancellation token.
 1311        /// </param>
 1312        /// <exception cref="APIErrorException">
 1313        /// Thrown when the operation returned an invalid status code
 1314        /// </exception>
 1315        /// <exception cref="SerializationException">
 1316        /// Thrown when unable to deserialize the response
 1317        /// </exception>
 1318        /// <exception cref="ValidationException">
 1319        /// Thrown when a required parameter is null
 1320        /// </exception>
 1321        /// <exception cref="System.ArgumentNullException">
 1322        /// Thrown when a required parameter is null
 1323        /// </exception>
 1324        /// <return>
 1325        /// A response object containing the response body and response headers.
 1326        /// </return>
 1327        public async Task<HttpOperationResponse<OCR>> OCRFileInputWithHttpMessagesAsync(string language, Stream imageStr
 1328        {
 01329            if (Client.Endpoint == null)
 1330            {
 01331                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1332            }
 01333            if (language == null)
 1334            {
 01335                throw new ValidationException(ValidationRules.CannotBeNull, "language");
 1336            }
 01337            if (imageStream == null)
 1338            {
 01339                throw new ValidationException(ValidationRules.CannotBeNull, "imageStream");
 1340            }
 1341            // Tracing
 01342            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01343            string _invocationId = null;
 01344            if (_shouldTrace)
 1345            {
 01346                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01347                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01348                tracingParameters.Add("language", language);
 01349                tracingParameters.Add("cacheImage", cacheImage);
 01350                tracingParameters.Add("enhanced", enhanced);
 01351                tracingParameters.Add("imageStream", imageStream);
 01352                tracingParameters.Add("cancellationToken", cancellationToken);
 01353                ServiceClientTracing.Enter(_invocationId, this, "OCRFileInput", tracingParameters);
 1354            }
 1355            // Construct URL
 01356            var _baseUrl = Client.BaseUri;
 01357            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/OCR
 01358            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01359            List<string> _queryParameters = new List<string>();
 01360            if (language != null)
 1361            {
 01362                _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language)));
 1363            }
 01364            if (cacheImage != null)
 1365            {
 01366                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 1367            }
 01368            if (enhanced != null)
 1369            {
 01370                _queryParameters.Add(string.Format("enhanced={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJs
 1371            }
 01372            if (_queryParameters.Count > 0)
 1373            {
 01374                _url += "?" + string.Join("&", _queryParameters);
 1375            }
 1376            // Create HTTP transport objects
 01377            var _httpRequest = new HttpRequestMessage();
 01378            HttpResponseMessage _httpResponse = null;
 01379            _httpRequest.Method = new HttpMethod("POST");
 01380            _httpRequest.RequestUri = new System.Uri(_url);
 1381            // Set Headers
 1382
 1383
 01384            if (customHeaders != null)
 1385            {
 01386                foreach(var _header in customHeaders)
 1387                {
 01388                    if (_httpRequest.Headers.Contains(_header.Key))
 1389                    {
 01390                        _httpRequest.Headers.Remove(_header.Key);
 1391                    }
 01392                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1393                }
 1394            }
 1395
 1396            // Serialize Request
 01397            string _requestContent = null;
 01398            if(imageStream == null)
 1399            {
 01400              throw new System.ArgumentNullException("imageStream");
 1401            }
 01402            if (imageStream != null && imageStream != Stream.Null)
 1403            {
 01404                _httpRequest.Content = new StreamContent(imageStream);
 01405                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif"
 1406            }
 1407            // Set Credentials
 01408            if (Client.Credentials != null)
 1409            {
 01410                cancellationToken.ThrowIfCancellationRequested();
 01411                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1412            }
 1413            // Send Request
 01414            if (_shouldTrace)
 1415            {
 01416                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1417            }
 01418            cancellationToken.ThrowIfCancellationRequested();
 01419            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01420            if (_shouldTrace)
 1421            {
 01422                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1423            }
 01424            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01425            cancellationToken.ThrowIfCancellationRequested();
 01426            string _responseContent = null;
 01427            if ((int)_statusCode != 200)
 1428            {
 01429                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1430                try
 1431                {
 01432                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01433                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01434                    if (_errorBody != null)
 1435                    {
 01436                        ex.Body = _errorBody;
 1437                    }
 01438                }
 01439                catch (JsonException)
 1440                {
 1441                    // Ignore the exception
 01442                }
 01443                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01444                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01445                if (_shouldTrace)
 1446                {
 01447                    ServiceClientTracing.Error(_invocationId, ex);
 1448                }
 01449                _httpRequest.Dispose();
 01450                if (_httpResponse != null)
 1451                {
 01452                    _httpResponse.Dispose();
 1453                }
 01454                throw ex;
 1455            }
 1456            // Create Result
 01457            var _result = new HttpOperationResponse<OCR>();
 01458            _result.Request = _httpRequest;
 01459            _result.Response = _httpResponse;
 1460            // Deserialize Response
 01461            if ((int)_statusCode == 200)
 1462            {
 01463                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1464                try
 1465                {
 01466                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OCR>(_responseContent, Client.De
 01467                }
 01468                catch (JsonException ex)
 1469                {
 01470                    _httpRequest.Dispose();
 01471                    if (_httpResponse != null)
 1472                    {
 01473                        _httpResponse.Dispose();
 1474                    }
 01475                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1476                }
 1477            }
 01478            if (_shouldTrace)
 1479            {
 01480                ServiceClientTracing.Exit(_invocationId, _result);
 1481            }
 01482            return _result;
 01483        }
 1484
 1485        /// <summary>
 1486        /// Returns probabilities of the image containing racy or adult content.
 1487        /// </summary>
 1488        /// <param name='imageStream'>
 1489        /// The image file.
 1490        /// </param>
 1491        /// <param name='cacheImage'>
 1492        /// Whether to retain the submitted image for future use; defaults to false if
 1493        /// omitted.
 1494        /// </param>
 1495        /// <param name='customHeaders'>
 1496        /// Headers that will be added to request.
 1497        /// </param>
 1498        /// <param name='cancellationToken'>
 1499        /// The cancellation token.
 1500        /// </param>
 1501        /// <exception cref="APIErrorException">
 1502        /// Thrown when the operation returned an invalid status code
 1503        /// </exception>
 1504        /// <exception cref="SerializationException">
 1505        /// Thrown when unable to deserialize the response
 1506        /// </exception>
 1507        /// <exception cref="ValidationException">
 1508        /// Thrown when a required parameter is null
 1509        /// </exception>
 1510        /// <exception cref="System.ArgumentNullException">
 1511        /// Thrown when a required parameter is null
 1512        /// </exception>
 1513        /// <return>
 1514        /// A response object containing the response body and response headers.
 1515        /// </return>
 1516        public async Task<HttpOperationResponse<Evaluate>> EvaluateFileInputWithHttpMessagesAsync(Stream imageStream, bo
 1517        {
 01518            if (Client.Endpoint == null)
 1519            {
 01520                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1521            }
 01522            if (imageStream == null)
 1523            {
 01524                throw new ValidationException(ValidationRules.CannotBeNull, "imageStream");
 1525            }
 1526            // Tracing
 01527            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01528            string _invocationId = null;
 01529            if (_shouldTrace)
 1530            {
 01531                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01532                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01533                tracingParameters.Add("cacheImage", cacheImage);
 01534                tracingParameters.Add("imageStream", imageStream);
 01535                tracingParameters.Add("cancellationToken", cancellationToken);
 01536                ServiceClientTracing.Enter(_invocationId, this, "EvaluateFileInput", tracingParameters);
 1537            }
 1538            // Construct URL
 01539            var _baseUrl = Client.BaseUri;
 01540            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Eva
 01541            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01542            List<string> _queryParameters = new List<string>();
 01543            if (cacheImage != null)
 1544            {
 01545                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 1546            }
 01547            if (_queryParameters.Count > 0)
 1548            {
 01549                _url += "?" + string.Join("&", _queryParameters);
 1550            }
 1551            // Create HTTP transport objects
 01552            var _httpRequest = new HttpRequestMessage();
 01553            HttpResponseMessage _httpResponse = null;
 01554            _httpRequest.Method = new HttpMethod("POST");
 01555            _httpRequest.RequestUri = new System.Uri(_url);
 1556            // Set Headers
 1557
 1558
 01559            if (customHeaders != null)
 1560            {
 01561                foreach(var _header in customHeaders)
 1562                {
 01563                    if (_httpRequest.Headers.Contains(_header.Key))
 1564                    {
 01565                        _httpRequest.Headers.Remove(_header.Key);
 1566                    }
 01567                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1568                }
 1569            }
 1570
 1571            // Serialize Request
 01572            string _requestContent = null;
 01573            if(imageStream == null)
 1574            {
 01575              throw new System.ArgumentNullException("imageStream");
 1576            }
 01577            if (imageStream != null && imageStream != Stream.Null)
 1578            {
 01579                _httpRequest.Content = new StreamContent(imageStream);
 01580                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif"
 1581            }
 1582            // Set Credentials
 01583            if (Client.Credentials != null)
 1584            {
 01585                cancellationToken.ThrowIfCancellationRequested();
 01586                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1587            }
 1588            // Send Request
 01589            if (_shouldTrace)
 1590            {
 01591                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1592            }
 01593            cancellationToken.ThrowIfCancellationRequested();
 01594            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01595            if (_shouldTrace)
 1596            {
 01597                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1598            }
 01599            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01600            cancellationToken.ThrowIfCancellationRequested();
 01601            string _responseContent = null;
 01602            if ((int)_statusCode != 200)
 1603            {
 01604                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1605                try
 1606                {
 01607                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01608                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01609                    if (_errorBody != null)
 1610                    {
 01611                        ex.Body = _errorBody;
 1612                    }
 01613                }
 01614                catch (JsonException)
 1615                {
 1616                    // Ignore the exception
 01617                }
 01618                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01619                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01620                if (_shouldTrace)
 1621                {
 01622                    ServiceClientTracing.Error(_invocationId, ex);
 1623                }
 01624                _httpRequest.Dispose();
 01625                if (_httpResponse != null)
 1626                {
 01627                    _httpResponse.Dispose();
 1628                }
 01629                throw ex;
 1630            }
 1631            // Create Result
 01632            var _result = new HttpOperationResponse<Evaluate>();
 01633            _result.Request = _httpRequest;
 01634            _result.Response = _httpResponse;
 1635            // Deserialize Response
 01636            if ((int)_statusCode == 200)
 1637            {
 01638                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1639                try
 1640                {
 01641                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Evaluate>(_responseContent, Clie
 01642                }
 01643                catch (JsonException ex)
 1644                {
 01645                    _httpRequest.Dispose();
 01646                    if (_httpResponse != null)
 1647                    {
 01648                        _httpResponse.Dispose();
 1649                    }
 01650                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1651                }
 1652            }
 01653            if (_shouldTrace)
 1654            {
 01655                ServiceClientTracing.Exit(_invocationId, _result);
 1656            }
 01657            return _result;
 01658        }
 1659
 1660        /// <summary>
 1661        /// Returns probabilities of the image containing racy or adult content.
 1662        /// </summary>
 1663        /// <param name='contentType'>
 1664        /// The content type.
 1665        /// </param>
 1666        /// <param name='imageUrl'>
 1667        /// The image url.
 1668        /// </param>
 1669        /// <param name='cacheImage'>
 1670        /// Whether to retain the submitted image for future use; defaults to false if
 1671        /// omitted.
 1672        /// </param>
 1673        /// <param name='customHeaders'>
 1674        /// Headers that will be added to request.
 1675        /// </param>
 1676        /// <param name='cancellationToken'>
 1677        /// The cancellation token.
 1678        /// </param>
 1679        /// <exception cref="APIErrorException">
 1680        /// Thrown when the operation returned an invalid status code
 1681        /// </exception>
 1682        /// <exception cref="SerializationException">
 1683        /// Thrown when unable to deserialize the response
 1684        /// </exception>
 1685        /// <exception cref="ValidationException">
 1686        /// Thrown when a required parameter is null
 1687        /// </exception>
 1688        /// <exception cref="System.ArgumentNullException">
 1689        /// Thrown when a required parameter is null
 1690        /// </exception>
 1691        /// <return>
 1692        /// A response object containing the response body and response headers.
 1693        /// </return>
 1694        public async Task<HttpOperationResponse<Evaluate>> EvaluateUrlInputWithHttpMessagesAsync(string contentType, Bod
 1695        {
 01696            if (Client.Endpoint == null)
 1697            {
 01698                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1699            }
 01700            if (contentType == null)
 1701            {
 01702                throw new ValidationException(ValidationRules.CannotBeNull, "contentType");
 1703            }
 01704            if (imageUrl == null)
 1705            {
 01706                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 1707            }
 1708            // Tracing
 01709            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01710            string _invocationId = null;
 01711            if (_shouldTrace)
 1712            {
 01713                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01714                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01715                tracingParameters.Add("cacheImage", cacheImage);
 01716                tracingParameters.Add("contentType", contentType);
 01717                tracingParameters.Add("imageUrl", imageUrl);
 01718                tracingParameters.Add("cancellationToken", cancellationToken);
 01719                ServiceClientTracing.Enter(_invocationId, this, "EvaluateUrlInput", tracingParameters);
 1720            }
 1721            // Construct URL
 01722            var _baseUrl = Client.BaseUri;
 01723            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Eva
 01724            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01725            List<string> _queryParameters = new List<string>();
 01726            if (cacheImage != null)
 1727            {
 01728                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 1729            }
 01730            if (_queryParameters.Count > 0)
 1731            {
 01732                _url += "?" + string.Join("&", _queryParameters);
 1733            }
 1734            // Create HTTP transport objects
 01735            var _httpRequest = new HttpRequestMessage();
 01736            HttpResponseMessage _httpResponse = null;
 01737            _httpRequest.Method = new HttpMethod("POST");
 01738            _httpRequest.RequestUri = new System.Uri(_url);
 1739            // Set Headers
 1740
 1741
 01742            if (customHeaders != null)
 1743            {
 01744                foreach(var _header in customHeaders)
 1745                {
 01746                    if (_httpRequest.Headers.Contains(_header.Key))
 1747                    {
 01748                        _httpRequest.Headers.Remove(_header.Key);
 1749                    }
 01750                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1751                }
 1752            }
 1753
 1754            // Serialize Request
 01755            string _requestContent = null;
 01756            if(imageUrl != null)
 1757            {
 01758                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01759                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01760                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1761            }
 1762            // Set Credentials
 01763            if (Client.Credentials != null)
 1764            {
 01765                cancellationToken.ThrowIfCancellationRequested();
 01766                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1767            }
 1768            // Send Request
 01769            if (_shouldTrace)
 1770            {
 01771                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1772            }
 01773            cancellationToken.ThrowIfCancellationRequested();
 01774            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01775            if (_shouldTrace)
 1776            {
 01777                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1778            }
 01779            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01780            cancellationToken.ThrowIfCancellationRequested();
 01781            string _responseContent = null;
 01782            if ((int)_statusCode != 200)
 1783            {
 01784                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1785                try
 1786                {
 01787                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01788                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01789                    if (_errorBody != null)
 1790                    {
 01791                        ex.Body = _errorBody;
 1792                    }
 01793                }
 01794                catch (JsonException)
 1795                {
 1796                    // Ignore the exception
 01797                }
 01798                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01799                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01800                if (_shouldTrace)
 1801                {
 01802                    ServiceClientTracing.Error(_invocationId, ex);
 1803                }
 01804                _httpRequest.Dispose();
 01805                if (_httpResponse != null)
 1806                {
 01807                    _httpResponse.Dispose();
 1808                }
 01809                throw ex;
 1810            }
 1811            // Create Result
 01812            var _result = new HttpOperationResponse<Evaluate>();
 01813            _result.Request = _httpRequest;
 01814            _result.Response = _httpResponse;
 1815            // Deserialize Response
 01816            if ((int)_statusCode == 200)
 1817            {
 01818                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1819                try
 1820                {
 01821                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Evaluate>(_responseContent, Clie
 01822                }
 01823                catch (JsonException ex)
 1824                {
 01825                    _httpRequest.Dispose();
 01826                    if (_httpResponse != null)
 1827                    {
 01828                        _httpResponse.Dispose();
 1829                    }
 01830                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1831                }
 1832            }
 01833            if (_shouldTrace)
 1834            {
 01835                ServiceClientTracing.Exit(_invocationId, _result);
 1836            }
 01837            return _result;
 01838        }
 1839
 1840        /// <summary>
 1841        /// Fuzzily match an image against one of your custom Image Lists. You can
 1842        /// create and manage your custom image lists using &lt;a
 1843        /// href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe"&gt;this&lt;/a&gt;
 1844        /// API.
 1845        ///
 1846        /// Returns ID and tags of matching image.&lt;br/&gt;
 1847        /// &lt;br/&gt;
 1848        /// Note: Refresh Index must be run on the corresponding Image List before
 1849        /// additions and removals are reflected in the response.
 1850        /// </summary>
 1851        /// <param name='contentType'>
 1852        /// The content type.
 1853        /// </param>
 1854        /// <param name='imageUrl'>
 1855        /// The image url.
 1856        /// </param>
 1857        /// <param name='listId'>
 1858        /// The list Id.
 1859        /// </param>
 1860        /// <param name='cacheImage'>
 1861        /// Whether to retain the submitted image for future use; defaults to false if
 1862        /// omitted.
 1863        /// </param>
 1864        /// <param name='customHeaders'>
 1865        /// Headers that will be added to request.
 1866        /// </param>
 1867        /// <param name='cancellationToken'>
 1868        /// The cancellation token.
 1869        /// </param>
 1870        /// <exception cref="APIErrorException">
 1871        /// Thrown when the operation returned an invalid status code
 1872        /// </exception>
 1873        /// <exception cref="SerializationException">
 1874        /// Thrown when unable to deserialize the response
 1875        /// </exception>
 1876        /// <exception cref="ValidationException">
 1877        /// Thrown when a required parameter is null
 1878        /// </exception>
 1879        /// <exception cref="System.ArgumentNullException">
 1880        /// Thrown when a required parameter is null
 1881        /// </exception>
 1882        /// <return>
 1883        /// A response object containing the response body and response headers.
 1884        /// </return>
 1885        public async Task<HttpOperationResponse<MatchResponse>> MatchUrlInputWithHttpMessagesAsync(string contentType, B
 1886        {
 01887            if (Client.Endpoint == null)
 1888            {
 01889                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 1890            }
 01891            if (contentType == null)
 1892            {
 01893                throw new ValidationException(ValidationRules.CannotBeNull, "contentType");
 1894            }
 01895            if (imageUrl == null)
 1896            {
 01897                throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl");
 1898            }
 1899            // Tracing
 01900            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01901            string _invocationId = null;
 01902            if (_shouldTrace)
 1903            {
 01904                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01905                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01906                tracingParameters.Add("listId", listId);
 01907                tracingParameters.Add("cacheImage", cacheImage);
 01908                tracingParameters.Add("contentType", contentType);
 01909                tracingParameters.Add("imageUrl", imageUrl);
 01910                tracingParameters.Add("cancellationToken", cancellationToken);
 01911                ServiceClientTracing.Enter(_invocationId, this, "MatchUrlInput", tracingParameters);
 1912            }
 1913            // Construct URL
 01914            var _baseUrl = Client.BaseUri;
 01915            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Mat
 01916            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 01917            List<string> _queryParameters = new List<string>();
 01918            if (listId != null)
 1919            {
 01920                _queryParameters.Add(string.Format("listId={0}", System.Uri.EscapeDataString(listId)));
 1921            }
 01922            if (cacheImage != null)
 1923            {
 01924                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 1925            }
 01926            if (_queryParameters.Count > 0)
 1927            {
 01928                _url += "?" + string.Join("&", _queryParameters);
 1929            }
 1930            // Create HTTP transport objects
 01931            var _httpRequest = new HttpRequestMessage();
 01932            HttpResponseMessage _httpResponse = null;
 01933            _httpRequest.Method = new HttpMethod("POST");
 01934            _httpRequest.RequestUri = new System.Uri(_url);
 1935            // Set Headers
 1936
 1937
 01938            if (customHeaders != null)
 1939            {
 01940                foreach(var _header in customHeaders)
 1941                {
 01942                    if (_httpRequest.Headers.Contains(_header.Key))
 1943                    {
 01944                        _httpRequest.Headers.Remove(_header.Key);
 1945                    }
 01946                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1947                }
 1948            }
 1949
 1950            // Serialize Request
 01951            string _requestContent = null;
 01952            if(imageUrl != null)
 1953            {
 01954                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti
 01955                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01956                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1957            }
 1958            // Set Credentials
 01959            if (Client.Credentials != null)
 1960            {
 01961                cancellationToken.ThrowIfCancellationRequested();
 01962                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1963            }
 1964            // Send Request
 01965            if (_shouldTrace)
 1966            {
 01967                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1968            }
 01969            cancellationToken.ThrowIfCancellationRequested();
 01970            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01971            if (_shouldTrace)
 1972            {
 01973                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1974            }
 01975            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01976            cancellationToken.ThrowIfCancellationRequested();
 01977            string _responseContent = null;
 01978            if ((int)_statusCode != 200)
 1979            {
 01980                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 1981                try
 1982                {
 01983                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01984                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 01985                    if (_errorBody != null)
 1986                    {
 01987                        ex.Body = _errorBody;
 1988                    }
 01989                }
 01990                catch (JsonException)
 1991                {
 1992                    // Ignore the exception
 01993                }
 01994                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01995                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01996                if (_shouldTrace)
 1997                {
 01998                    ServiceClientTracing.Error(_invocationId, ex);
 1999                }
 02000                _httpRequest.Dispose();
 02001                if (_httpResponse != null)
 2002                {
 02003                    _httpResponse.Dispose();
 2004                }
 02005                throw ex;
 2006            }
 2007            // Create Result
 02008            var _result = new HttpOperationResponse<MatchResponse>();
 02009            _result.Request = _httpRequest;
 02010            _result.Response = _httpResponse;
 2011            // Deserialize Response
 02012            if ((int)_statusCode == 200)
 2013            {
 02014                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2015                try
 2016                {
 02017                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<MatchResponse>(_responseContent,
 02018                }
 02019                catch (JsonException ex)
 2020                {
 02021                    _httpRequest.Dispose();
 02022                    if (_httpResponse != null)
 2023                    {
 02024                        _httpResponse.Dispose();
 2025                    }
 02026                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2027                }
 2028            }
 02029            if (_shouldTrace)
 2030            {
 02031                ServiceClientTracing.Exit(_invocationId, _result);
 2032            }
 02033            return _result;
 02034        }
 2035
 2036        /// <summary>
 2037        /// Fuzzily match an image against one of your custom Image Lists. You can
 2038        /// create and manage your custom image lists using &lt;a
 2039        /// href="/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe"&gt;this&lt;/a&gt;
 2040        /// API.
 2041        ///
 2042        /// Returns ID and tags of matching image.&lt;br/&gt;
 2043        /// &lt;br/&gt;
 2044        /// Note: Refresh Index must be run on the corresponding Image List before
 2045        /// additions and removals are reflected in the response.
 2046        /// </summary>
 2047        /// <param name='imageStream'>
 2048        /// The image file.
 2049        /// </param>
 2050        /// <param name='listId'>
 2051        /// The list Id.
 2052        /// </param>
 2053        /// <param name='cacheImage'>
 2054        /// Whether to retain the submitted image for future use; defaults to false if
 2055        /// omitted.
 2056        /// </param>
 2057        /// <param name='customHeaders'>
 2058        /// Headers that will be added to request.
 2059        /// </param>
 2060        /// <param name='cancellationToken'>
 2061        /// The cancellation token.
 2062        /// </param>
 2063        /// <exception cref="APIErrorException">
 2064        /// Thrown when the operation returned an invalid status code
 2065        /// </exception>
 2066        /// <exception cref="SerializationException">
 2067        /// Thrown when unable to deserialize the response
 2068        /// </exception>
 2069        /// <exception cref="ValidationException">
 2070        /// Thrown when a required parameter is null
 2071        /// </exception>
 2072        /// <exception cref="System.ArgumentNullException">
 2073        /// Thrown when a required parameter is null
 2074        /// </exception>
 2075        /// <return>
 2076        /// A response object containing the response body and response headers.
 2077        /// </return>
 2078        public async Task<HttpOperationResponse<MatchResponse>> MatchFileInputWithHttpMessagesAsync(Stream imageStream, 
 2079        {
 02080            if (Client.Endpoint == null)
 2081            {
 02082                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint");
 2083            }
 02084            if (imageStream == null)
 2085            {
 02086                throw new ValidationException(ValidationRules.CannotBeNull, "imageStream");
 2087            }
 2088            // Tracing
 02089            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02090            string _invocationId = null;
 02091            if (_shouldTrace)
 2092            {
 02093                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02094                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02095                tracingParameters.Add("listId", listId);
 02096                tracingParameters.Add("cacheImage", cacheImage);
 02097                tracingParameters.Add("imageStream", imageStream);
 02098                tracingParameters.Add("cancellationToken", cancellationToken);
 02099                ServiceClientTracing.Enter(_invocationId, this, "MatchFileInput", tracingParameters);
 2100            }
 2101            // Construct URL
 02102            var _baseUrl = Client.BaseUri;
 02103            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/moderate/v1.0/ProcessImage/Mat
 02104            _url = _url.Replace("{Endpoint}", Client.Endpoint);
 02105            List<string> _queryParameters = new List<string>();
 02106            if (listId != null)
 2107            {
 02108                _queryParameters.Add(string.Format("listId={0}", System.Uri.EscapeDataString(listId)));
 2109            }
 02110            if (cacheImage != null)
 2111            {
 02112                _queryParameters.Add(string.Format("CacheImage={0}", System.Uri.EscapeDataString(Rest.Serialization.Safe
 2113            }
 02114            if (_queryParameters.Count > 0)
 2115            {
 02116                _url += "?" + string.Join("&", _queryParameters);
 2117            }
 2118            // Create HTTP transport objects
 02119            var _httpRequest = new HttpRequestMessage();
 02120            HttpResponseMessage _httpResponse = null;
 02121            _httpRequest.Method = new HttpMethod("POST");
 02122            _httpRequest.RequestUri = new System.Uri(_url);
 2123            // Set Headers
 2124
 2125
 02126            if (customHeaders != null)
 2127            {
 02128                foreach(var _header in customHeaders)
 2129                {
 02130                    if (_httpRequest.Headers.Contains(_header.Key))
 2131                    {
 02132                        _httpRequest.Headers.Remove(_header.Key);
 2133                    }
 02134                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2135                }
 2136            }
 2137
 2138            // Serialize Request
 02139            string _requestContent = null;
 02140            if(imageStream == null)
 2141            {
 02142              throw new System.ArgumentNullException("imageStream");
 2143            }
 02144            if (imageStream != null && imageStream != Stream.Null)
 2145            {
 02146                _httpRequest.Content = new StreamContent(imageStream);
 02147                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("image/gif"
 2148            }
 2149            // Set Credentials
 02150            if (Client.Credentials != null)
 2151            {
 02152                cancellationToken.ThrowIfCancellationRequested();
 02153                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2154            }
 2155            // Send Request
 02156            if (_shouldTrace)
 2157            {
 02158                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2159            }
 02160            cancellationToken.ThrowIfCancellationRequested();
 02161            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02162            if (_shouldTrace)
 2163            {
 02164                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2165            }
 02166            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02167            cancellationToken.ThrowIfCancellationRequested();
 02168            string _responseContent = null;
 02169            if ((int)_statusCode != 200)
 2170            {
 02171                var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC
 2172                try
 2173                {
 02174                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02175                    APIError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte
 02176                    if (_errorBody != null)
 2177                    {
 02178                        ex.Body = _errorBody;
 2179                    }
 02180                }
 02181                catch (JsonException)
 2182                {
 2183                    // Ignore the exception
 02184                }
 02185                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02186                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02187                if (_shouldTrace)
 2188                {
 02189                    ServiceClientTracing.Error(_invocationId, ex);
 2190                }
 02191                _httpRequest.Dispose();
 02192                if (_httpResponse != null)
 2193                {
 02194                    _httpResponse.Dispose();
 2195                }
 02196                throw ex;
 2197            }
 2198            // Create Result
 02199            var _result = new HttpOperationResponse<MatchResponse>();
 02200            _result.Request = _httpRequest;
 02201            _result.Response = _httpResponse;
 2202            // Deserialize Response
 02203            if ((int)_statusCode == 200)
 2204            {
 02205                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2206                try
 2207                {
 02208                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<MatchResponse>(_responseContent,
 02209                }
 02210                catch (JsonException ex)
 2211                {
 02212                    _httpRequest.Dispose();
 02213                    if (_httpResponse != null)
 2214                    {
 02215                        _httpResponse.Dispose();
 2216                    }
 02217                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2218                }
 2219            }
 02220            if (_shouldTrace)
 2221            {
 02222                ServiceClientTracing.Exit(_invocationId, _result);
 2223            }
 02224            return _result;
 02225        }
 2226
 2227    }
 2228}