< Summary

Class:Microsoft.Azure.Batch.Protocol.PoolOperations
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\GeneratedProtocol\PoolOperations.cs
Covered lines:89
Uncovered lines:2243
Coverable lines:2332
Total lines:4762
Line coverage:3.8% (89 of 2332)
Covered branches:57
Total branches:1486
Branch coverage:3.8% (57 of 1486)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
ListUsageMetricsWithHttpMessagesAsync()-0%0%
GetAllLifetimeStatisticsWithHttpMessagesAsync()-0%0%
AddWithHttpMessagesAsync()-0%0%
ListWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-55.48%56.25%
ExistsWithHttpMessagesAsync()-0%0%
GetWithHttpMessagesAsync()-1.8%1.85%
PatchWithHttpMessagesAsync()-0%0%
DisableAutoScaleWithHttpMessagesAsync()-0%0%
EnableAutoScaleWithHttpMessagesAsync()-0%0%
EvaluateAutoScaleWithHttpMessagesAsync()-0%0%
ResizeWithHttpMessagesAsync()-0%0%
StopResizeWithHttpMessagesAsync()-0%0%
UpdatePropertiesWithHttpMessagesAsync()-0%0%
RemoveNodesWithHttpMessagesAsync()-0%0%
ListUsageMetricsNextWithHttpMessagesAsync()-0%0%
ListNextWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\GeneratedProtocol\PoolOperations.cs

#LineLine coverage
 1// <auto-generated>
 2// Copyright (c) Microsoft Corporation. All rights reserved.
 3// Licensed under the MIT License. See License.txt in the project root for
 4// license information.
 5//
 6// Code generated by Microsoft (R) AutoRest Code Generator.
 7// Changes may cause incorrect behavior and will be lost if the code is
 8// regenerated.
 9// </auto-generated>
 10
 11namespace Microsoft.Azure.Batch.Protocol
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Azure;
 15    using Microsoft.Rest.Serialization;
 16    using Models;
 17    using Newtonsoft.Json;
 18    using System.Collections;
 19    using System.Collections.Generic;
 20    using System.Linq;
 21    using System.Net;
 22    using System.Net.Http;
 23    using System.Threading;
 24    using System.Threading.Tasks;
 25
 26    /// <summary>
 27    /// PoolOperations operations.
 28    /// </summary>
 29    internal partial class PoolOperations : IServiceOperations<BatchServiceClient>, IPoolOperations
 30    {
 31        /// <summary>
 32        /// Initializes a new instance of the PoolOperations class.
 33        /// </summary>
 34        /// <param name='client'>
 35        /// Reference to the service client.
 36        /// </param>
 37        /// <exception cref="System.ArgumentNullException">
 38        /// Thrown when a required parameter is null
 39        /// </exception>
 14840        internal PoolOperations(BatchServiceClient client)
 41        {
 14842            if (client == null)
 43            {
 044                throw new System.ArgumentNullException("client");
 45            }
 14846            Client = client;
 14847        }
 48
 49        /// <summary>
 50        /// Gets a reference to the BatchServiceClient
 51        /// </summary>
 20152        public BatchServiceClient Client { get; private set; }
 53
 54        /// <summary>
 55        /// Lists the usage metrics, aggregated by Pool across individual time
 56        /// intervals, for the specified Account.
 57        /// </summary>
 58        /// <remarks>
 59        /// If you do not specify a $filter clause including a poolId, the response
 60        /// includes all Pools that existed in the Account in the time range of the
 61        /// returned aggregation intervals. If you do not specify a $filter clause
 62        /// including a startTime or endTime these filters default to the start and end
 63        /// times of the last aggregation interval currently available; that is, only
 64        /// the last aggregation interval is returned.
 65        /// </remarks>
 66        /// <param name='poolListUsageMetricsOptions'>
 67        /// Additional parameters for the operation
 68        /// </param>
 69        /// <param name='customHeaders'>
 70        /// Headers that will be added to request.
 71        /// </param>
 72        /// <param name='cancellationToken'>
 73        /// The cancellation token.
 74        /// </param>
 75        /// <exception cref="BatchErrorException">
 76        /// Thrown when the operation returned an invalid status code
 77        /// </exception>
 78        /// <exception cref="SerializationException">
 79        /// Thrown when unable to deserialize the response
 80        /// </exception>
 81        /// <exception cref="ValidationException">
 82        /// Thrown when a required parameter is null
 83        /// </exception>
 84        /// <exception cref="System.ArgumentNullException">
 85        /// Thrown when a required parameter is null
 86        /// </exception>
 87        /// <return>
 88        /// A response object containing the response body and response headers.
 89        /// </return>
 90        public async Task<AzureOperationResponse<IPage<PoolUsageMetrics>,PoolListUsageMetricsHeaders>> ListUsageMetricsW
 91        {
 092            if (Client.BatchUrl == null)
 93            {
 094                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 95            }
 096            if (Client.ApiVersion == null)
 97            {
 098                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 99            }
 0100            System.DateTime? startTime = default(System.DateTime?);
 0101            if (poolListUsageMetricsOptions != null)
 102            {
 0103                startTime = poolListUsageMetricsOptions.StartTime;
 104            }
 0105            System.DateTime? endTime = default(System.DateTime?);
 0106            if (poolListUsageMetricsOptions != null)
 107            {
 0108                endTime = poolListUsageMetricsOptions.EndTime;
 109            }
 0110            string filter = default(string);
 0111            if (poolListUsageMetricsOptions != null)
 112            {
 0113                filter = poolListUsageMetricsOptions.Filter;
 114            }
 0115            int? maxResults = default(int?);
 0116            if (poolListUsageMetricsOptions != null)
 117            {
 0118                maxResults = poolListUsageMetricsOptions.MaxResults;
 119            }
 0120            int? timeout = default(int?);
 0121            if (poolListUsageMetricsOptions != null)
 122            {
 0123                timeout = poolListUsageMetricsOptions.Timeout;
 124            }
 0125            System.Guid? clientRequestId = default(System.Guid?);
 0126            if (poolListUsageMetricsOptions != null)
 127            {
 0128                clientRequestId = poolListUsageMetricsOptions.ClientRequestId;
 129            }
 0130            bool? returnClientRequestId = default(bool?);
 0131            if (poolListUsageMetricsOptions != null)
 132            {
 0133                returnClientRequestId = poolListUsageMetricsOptions.ReturnClientRequestId;
 134            }
 0135            System.DateTime? ocpDate = default(System.DateTime?);
 0136            if (poolListUsageMetricsOptions != null)
 137            {
 0138                ocpDate = poolListUsageMetricsOptions.OcpDate;
 139            }
 140            // Tracing
 0141            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0142            string _invocationId = null;
 0143            if (_shouldTrace)
 144            {
 0145                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0146                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0147                tracingParameters.Add("startTime", startTime);
 0148                tracingParameters.Add("endTime", endTime);
 0149                tracingParameters.Add("filter", filter);
 0150                tracingParameters.Add("maxResults", maxResults);
 0151                tracingParameters.Add("timeout", timeout);
 0152                tracingParameters.Add("clientRequestId", clientRequestId);
 0153                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0154                tracingParameters.Add("ocpDate", ocpDate);
 0155                tracingParameters.Add("cancellationToken", cancellationToken);
 0156                ServiceClientTracing.Enter(_invocationId, this, "ListUsageMetrics", tracingParameters);
 157            }
 158            // Construct URL
 0159            var _baseUrl = Client.BaseUri;
 0160            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "poolusagemetrics";
 0161            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0162            List<string> _queryParameters = new List<string>();
 0163            if (Client.ApiVersion != null)
 164            {
 0165                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 166            }
 0167            if (startTime != null)
 168            {
 0169                _queryParameters.Add(string.Format("starttime={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ
 170            }
 0171            if (endTime != null)
 172            {
 0173                _queryParameters.Add(string.Format("endtime={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 174            }
 0175            if (filter != null)
 176            {
 0177                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 178            }
 0179            if (maxResults != null)
 180            {
 0181                _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali
 182            }
 0183            if (timeout != null)
 184            {
 0185                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 186            }
 0187            if (_queryParameters.Count > 0)
 188            {
 0189                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 190            }
 191            // Create HTTP transport objects
 0192            var _httpRequest = new HttpRequestMessage();
 0193            HttpResponseMessage _httpResponse = null;
 0194            _httpRequest.Method = new HttpMethod("GET");
 0195            _httpRequest.RequestUri = new System.Uri(_url);
 196            // Set Headers
 0197            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 198            {
 0199                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 200            }
 0201            if (Client.AcceptLanguage != null)
 202            {
 0203                if (_httpRequest.Headers.Contains("accept-language"))
 204                {
 0205                    _httpRequest.Headers.Remove("accept-language");
 206                }
 0207                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 208            }
 0209            if (clientRequestId != null)
 210            {
 0211                if (_httpRequest.Headers.Contains("client-request-id"))
 212                {
 0213                    _httpRequest.Headers.Remove("client-request-id");
 214                }
 0215                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 216            }
 0217            if (returnClientRequestId != null)
 218            {
 0219                if (_httpRequest.Headers.Contains("return-client-request-id"))
 220                {
 0221                    _httpRequest.Headers.Remove("return-client-request-id");
 222                }
 0223                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 224            }
 0225            if (ocpDate != null)
 226            {
 0227                if (_httpRequest.Headers.Contains("ocp-date"))
 228                {
 0229                    _httpRequest.Headers.Remove("ocp-date");
 230                }
 0231                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 232            }
 233
 234
 0235            if (customHeaders != null)
 236            {
 0237                foreach(var _header in customHeaders)
 238                {
 0239                    if (_httpRequest.Headers.Contains(_header.Key))
 240                    {
 0241                        _httpRequest.Headers.Remove(_header.Key);
 242                    }
 0243                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 244                }
 245            }
 246
 247            // Serialize Request
 0248            string _requestContent = null;
 249            // Set Credentials
 0250            if (Client.Credentials != null)
 251            {
 0252                cancellationToken.ThrowIfCancellationRequested();
 0253                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 254            }
 255            // Send Request
 0256            if (_shouldTrace)
 257            {
 0258                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 259            }
 0260            cancellationToken.ThrowIfCancellationRequested();
 0261            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0262            if (_shouldTrace)
 263            {
 0264                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 265            }
 0266            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0267            cancellationToken.ThrowIfCancellationRequested();
 0268            string _responseContent = null;
 0269            if ((int)_statusCode != 200)
 270            {
 0271                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 272                try
 273                {
 0274                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0275                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0276                    if (_errorBody != null)
 277                    {
 0278                        ex.Body = _errorBody;
 279                    }
 0280                }
 0281                catch (JsonException)
 282                {
 283                    // Ignore the exception
 0284                }
 0285                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0286                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0287                if (_shouldTrace)
 288                {
 0289                    ServiceClientTracing.Error(_invocationId, ex);
 290                }
 0291                _httpRequest.Dispose();
 0292                if (_httpResponse != null)
 293                {
 0294                    _httpResponse.Dispose();
 295                }
 0296                throw ex;
 297            }
 298            // Create Result
 0299            var _result = new AzureOperationResponse<IPage<PoolUsageMetrics>,PoolListUsageMetricsHeaders>();
 0300            _result.Request = _httpRequest;
 0301            _result.Response = _httpResponse;
 0302            if (_httpResponse.Headers.Contains("request-id"))
 303            {
 0304                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 305            }
 306            // Deserialize Response
 0307            if ((int)_statusCode == 200)
 308            {
 0309                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 310                try
 311                {
 0312                    _result.Body = SafeJsonConvert.DeserializeObject<Page<PoolUsageMetrics>>(_responseContent, Client.De
 0313                }
 0314                catch (JsonException ex)
 315                {
 0316                    _httpRequest.Dispose();
 0317                    if (_httpResponse != null)
 318                    {
 0319                        _httpResponse.Dispose();
 320                    }
 0321                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 322                }
 323            }
 324            try
 325            {
 0326                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolListUsageMetricsHeaders>(JsonSerializer.
 0327            }
 0328            catch (JsonException ex)
 329            {
 0330                _httpRequest.Dispose();
 0331                if (_httpResponse != null)
 332                {
 0333                    _httpResponse.Dispose();
 334                }
 0335                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 336            }
 0337            if (_shouldTrace)
 338            {
 0339                ServiceClientTracing.Exit(_invocationId, _result);
 340            }
 0341            return _result;
 0342        }
 343
 344        /// <summary>
 345        /// Gets lifetime summary statistics for all of the Pools in the specified
 346        /// Account.
 347        /// </summary>
 348        /// <remarks>
 349        /// Statistics are aggregated across all Pools that have ever existed in the
 350        /// Account, from Account creation to the last update time of the statistics.
 351        /// The statistics may not be immediately available. The Batch service performs
 352        /// periodic roll-up of statistics. The typical delay is about 30 minutes.
 353        /// </remarks>
 354        /// <param name='poolGetAllLifetimeStatisticsOptions'>
 355        /// Additional parameters for the operation
 356        /// </param>
 357        /// <param name='customHeaders'>
 358        /// Headers that will be added to request.
 359        /// </param>
 360        /// <param name='cancellationToken'>
 361        /// The cancellation token.
 362        /// </param>
 363        /// <exception cref="BatchErrorException">
 364        /// Thrown when the operation returned an invalid status code
 365        /// </exception>
 366        /// <exception cref="SerializationException">
 367        /// Thrown when unable to deserialize the response
 368        /// </exception>
 369        /// <exception cref="ValidationException">
 370        /// Thrown when a required parameter is null
 371        /// </exception>
 372        /// <exception cref="System.ArgumentNullException">
 373        /// Thrown when a required parameter is null
 374        /// </exception>
 375        /// <return>
 376        /// A response object containing the response body and response headers.
 377        /// </return>
 378        public async Task<AzureOperationResponse<PoolStatistics,PoolGetAllLifetimeStatisticsHeaders>> GetAllLifetimeStat
 379        {
 0380            if (Client.BatchUrl == null)
 381            {
 0382                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 383            }
 0384            if (Client.ApiVersion == null)
 385            {
 0386                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 387            }
 0388            int? timeout = default(int?);
 0389            if (poolGetAllLifetimeStatisticsOptions != null)
 390            {
 0391                timeout = poolGetAllLifetimeStatisticsOptions.Timeout;
 392            }
 0393            System.Guid? clientRequestId = default(System.Guid?);
 0394            if (poolGetAllLifetimeStatisticsOptions != null)
 395            {
 0396                clientRequestId = poolGetAllLifetimeStatisticsOptions.ClientRequestId;
 397            }
 0398            bool? returnClientRequestId = default(bool?);
 0399            if (poolGetAllLifetimeStatisticsOptions != null)
 400            {
 0401                returnClientRequestId = poolGetAllLifetimeStatisticsOptions.ReturnClientRequestId;
 402            }
 0403            System.DateTime? ocpDate = default(System.DateTime?);
 0404            if (poolGetAllLifetimeStatisticsOptions != null)
 405            {
 0406                ocpDate = poolGetAllLifetimeStatisticsOptions.OcpDate;
 407            }
 408            // Tracing
 0409            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0410            string _invocationId = null;
 0411            if (_shouldTrace)
 412            {
 0413                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0414                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0415                tracingParameters.Add("timeout", timeout);
 0416                tracingParameters.Add("clientRequestId", clientRequestId);
 0417                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0418                tracingParameters.Add("ocpDate", ocpDate);
 0419                tracingParameters.Add("cancellationToken", cancellationToken);
 0420                ServiceClientTracing.Enter(_invocationId, this, "GetAllLifetimeStatistics", tracingParameters);
 421            }
 422            // Construct URL
 0423            var _baseUrl = Client.BaseUri;
 0424            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "lifetimepoolstats";
 0425            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0426            List<string> _queryParameters = new List<string>();
 0427            if (Client.ApiVersion != null)
 428            {
 0429                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 430            }
 0431            if (timeout != null)
 432            {
 0433                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 434            }
 0435            if (_queryParameters.Count > 0)
 436            {
 0437                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 438            }
 439            // Create HTTP transport objects
 0440            var _httpRequest = new HttpRequestMessage();
 0441            HttpResponseMessage _httpResponse = null;
 0442            _httpRequest.Method = new HttpMethod("GET");
 0443            _httpRequest.RequestUri = new System.Uri(_url);
 444            // Set Headers
 0445            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 446            {
 0447                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 448            }
 0449            if (Client.AcceptLanguage != null)
 450            {
 0451                if (_httpRequest.Headers.Contains("accept-language"))
 452                {
 0453                    _httpRequest.Headers.Remove("accept-language");
 454                }
 0455                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 456            }
 0457            if (clientRequestId != null)
 458            {
 0459                if (_httpRequest.Headers.Contains("client-request-id"))
 460                {
 0461                    _httpRequest.Headers.Remove("client-request-id");
 462                }
 0463                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 464            }
 0465            if (returnClientRequestId != null)
 466            {
 0467                if (_httpRequest.Headers.Contains("return-client-request-id"))
 468                {
 0469                    _httpRequest.Headers.Remove("return-client-request-id");
 470                }
 0471                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 472            }
 0473            if (ocpDate != null)
 474            {
 0475                if (_httpRequest.Headers.Contains("ocp-date"))
 476                {
 0477                    _httpRequest.Headers.Remove("ocp-date");
 478                }
 0479                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 480            }
 481
 482
 0483            if (customHeaders != null)
 484            {
 0485                foreach(var _header in customHeaders)
 486                {
 0487                    if (_httpRequest.Headers.Contains(_header.Key))
 488                    {
 0489                        _httpRequest.Headers.Remove(_header.Key);
 490                    }
 0491                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 492                }
 493            }
 494
 495            // Serialize Request
 0496            string _requestContent = null;
 497            // Set Credentials
 0498            if (Client.Credentials != null)
 499            {
 0500                cancellationToken.ThrowIfCancellationRequested();
 0501                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 502            }
 503            // Send Request
 0504            if (_shouldTrace)
 505            {
 0506                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 507            }
 0508            cancellationToken.ThrowIfCancellationRequested();
 0509            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0510            if (_shouldTrace)
 511            {
 0512                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 513            }
 0514            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0515            cancellationToken.ThrowIfCancellationRequested();
 0516            string _responseContent = null;
 0517            if ((int)_statusCode != 200)
 518            {
 0519                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 520                try
 521                {
 0522                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0523                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0524                    if (_errorBody != null)
 525                    {
 0526                        ex.Body = _errorBody;
 527                    }
 0528                }
 0529                catch (JsonException)
 530                {
 531                    // Ignore the exception
 0532                }
 0533                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0534                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0535                if (_shouldTrace)
 536                {
 0537                    ServiceClientTracing.Error(_invocationId, ex);
 538                }
 0539                _httpRequest.Dispose();
 0540                if (_httpResponse != null)
 541                {
 0542                    _httpResponse.Dispose();
 543                }
 0544                throw ex;
 545            }
 546            // Create Result
 0547            var _result = new AzureOperationResponse<PoolStatistics,PoolGetAllLifetimeStatisticsHeaders>();
 0548            _result.Request = _httpRequest;
 0549            _result.Response = _httpResponse;
 0550            if (_httpResponse.Headers.Contains("request-id"))
 551            {
 0552                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 553            }
 554            // Deserialize Response
 0555            if ((int)_statusCode == 200)
 556            {
 0557                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 558                try
 559                {
 0560                    _result.Body = SafeJsonConvert.DeserializeObject<PoolStatistics>(_responseContent, Client.Deserializ
 0561                }
 0562                catch (JsonException ex)
 563                {
 0564                    _httpRequest.Dispose();
 0565                    if (_httpResponse != null)
 566                    {
 0567                        _httpResponse.Dispose();
 568                    }
 0569                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 570                }
 571            }
 572            try
 573            {
 0574                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolGetAllLifetimeStatisticsHeaders>(JsonSer
 0575            }
 0576            catch (JsonException ex)
 577            {
 0578                _httpRequest.Dispose();
 0579                if (_httpResponse != null)
 580                {
 0581                    _httpResponse.Dispose();
 582                }
 0583                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 584            }
 0585            if (_shouldTrace)
 586            {
 0587                ServiceClientTracing.Exit(_invocationId, _result);
 588            }
 0589            return _result;
 0590        }
 591
 592        /// <summary>
 593        /// Adds a Pool to the specified Account.
 594        /// </summary>
 595        /// <remarks>
 596        /// When naming Pools, avoid including sensitive information such as user names
 597        /// or secret project names. This information may appear in telemetry logs
 598        /// accessible to Microsoft Support engineers.
 599        /// </remarks>
 600        /// <param name='pool'>
 601        /// The Pool to be added.
 602        /// </param>
 603        /// <param name='poolAddOptions'>
 604        /// Additional parameters for the operation
 605        /// </param>
 606        /// <param name='customHeaders'>
 607        /// Headers that will be added to request.
 608        /// </param>
 609        /// <param name='cancellationToken'>
 610        /// The cancellation token.
 611        /// </param>
 612        /// <exception cref="BatchErrorException">
 613        /// Thrown when the operation returned an invalid status code
 614        /// </exception>
 615        /// <exception cref="ValidationException">
 616        /// Thrown when a required parameter is null
 617        /// </exception>
 618        /// <exception cref="System.ArgumentNullException">
 619        /// Thrown when a required parameter is null
 620        /// </exception>
 621        /// <return>
 622        /// A response object containing the response body and response headers.
 623        /// </return>
 624        public async Task<AzureOperationHeaderResponse<PoolAddHeaders>> AddWithHttpMessagesAsync(PoolAddParameter pool, 
 625        {
 0626            if (Client.BatchUrl == null)
 627            {
 0628                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 629            }
 0630            if (pool == null)
 631            {
 0632                throw new ValidationException(ValidationRules.CannotBeNull, "pool");
 633            }
 0634            if (Client.ApiVersion == null)
 635            {
 0636                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 637            }
 0638            int? timeout = default(int?);
 0639            if (poolAddOptions != null)
 640            {
 0641                timeout = poolAddOptions.Timeout;
 642            }
 0643            System.Guid? clientRequestId = default(System.Guid?);
 0644            if (poolAddOptions != null)
 645            {
 0646                clientRequestId = poolAddOptions.ClientRequestId;
 647            }
 0648            bool? returnClientRequestId = default(bool?);
 0649            if (poolAddOptions != null)
 650            {
 0651                returnClientRequestId = poolAddOptions.ReturnClientRequestId;
 652            }
 0653            System.DateTime? ocpDate = default(System.DateTime?);
 0654            if (poolAddOptions != null)
 655            {
 0656                ocpDate = poolAddOptions.OcpDate;
 657            }
 658            // Tracing
 0659            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0660            string _invocationId = null;
 0661            if (_shouldTrace)
 662            {
 0663                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0664                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0665                tracingParameters.Add("pool", pool);
 0666                tracingParameters.Add("timeout", timeout);
 0667                tracingParameters.Add("clientRequestId", clientRequestId);
 0668                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0669                tracingParameters.Add("ocpDate", ocpDate);
 0670                tracingParameters.Add("cancellationToken", cancellationToken);
 0671                ServiceClientTracing.Enter(_invocationId, this, "Add", tracingParameters);
 672            }
 673            // Construct URL
 0674            var _baseUrl = Client.BaseUri;
 0675            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools";
 0676            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0677            List<string> _queryParameters = new List<string>();
 0678            if (Client.ApiVersion != null)
 679            {
 0680                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 681            }
 0682            if (timeout != null)
 683            {
 0684                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 685            }
 0686            if (_queryParameters.Count > 0)
 687            {
 0688                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 689            }
 690            // Create HTTP transport objects
 0691            var _httpRequest = new HttpRequestMessage();
 0692            HttpResponseMessage _httpResponse = null;
 0693            _httpRequest.Method = new HttpMethod("POST");
 0694            _httpRequest.RequestUri = new System.Uri(_url);
 695            // Set Headers
 0696            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 697            {
 0698                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 699            }
 0700            if (Client.AcceptLanguage != null)
 701            {
 0702                if (_httpRequest.Headers.Contains("accept-language"))
 703                {
 0704                    _httpRequest.Headers.Remove("accept-language");
 705                }
 0706                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 707            }
 0708            if (clientRequestId != null)
 709            {
 0710                if (_httpRequest.Headers.Contains("client-request-id"))
 711                {
 0712                    _httpRequest.Headers.Remove("client-request-id");
 713                }
 0714                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 715            }
 0716            if (returnClientRequestId != null)
 717            {
 0718                if (_httpRequest.Headers.Contains("return-client-request-id"))
 719                {
 0720                    _httpRequest.Headers.Remove("return-client-request-id");
 721                }
 0722                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 723            }
 0724            if (ocpDate != null)
 725            {
 0726                if (_httpRequest.Headers.Contains("ocp-date"))
 727                {
 0728                    _httpRequest.Headers.Remove("ocp-date");
 729                }
 0730                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 731            }
 732
 733
 0734            if (customHeaders != null)
 735            {
 0736                foreach(var _header in customHeaders)
 737                {
 0738                    if (_httpRequest.Headers.Contains(_header.Key))
 739                    {
 0740                        _httpRequest.Headers.Remove(_header.Key);
 741                    }
 0742                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 743                }
 744            }
 745
 746            // Serialize Request
 0747            string _requestContent = null;
 0748            if(pool != null)
 749            {
 0750                _requestContent = SafeJsonConvert.SerializeObject(pool, Client.SerializationSettings);
 0751                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0752                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 753            }
 754            // Set Credentials
 0755            if (Client.Credentials != null)
 756            {
 0757                cancellationToken.ThrowIfCancellationRequested();
 0758                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 759            }
 760            // Send Request
 0761            if (_shouldTrace)
 762            {
 0763                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 764            }
 0765            cancellationToken.ThrowIfCancellationRequested();
 0766            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0767            if (_shouldTrace)
 768            {
 0769                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 770            }
 0771            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0772            cancellationToken.ThrowIfCancellationRequested();
 0773            string _responseContent = null;
 0774            if ((int)_statusCode != 201)
 775            {
 0776                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 777                try
 778                {
 0779                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0780                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0781                    if (_errorBody != null)
 782                    {
 0783                        ex.Body = _errorBody;
 784                    }
 0785                }
 0786                catch (JsonException)
 787                {
 788                    // Ignore the exception
 0789                }
 0790                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0791                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0792                if (_shouldTrace)
 793                {
 0794                    ServiceClientTracing.Error(_invocationId, ex);
 795                }
 0796                _httpRequest.Dispose();
 0797                if (_httpResponse != null)
 798                {
 0799                    _httpResponse.Dispose();
 800                }
 0801                throw ex;
 802            }
 803            // Create Result
 0804            var _result = new AzureOperationHeaderResponse<PoolAddHeaders>();
 0805            _result.Request = _httpRequest;
 0806            _result.Response = _httpResponse;
 0807            if (_httpResponse.Headers.Contains("request-id"))
 808            {
 0809                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 810            }
 811            try
 812            {
 0813                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolAddHeaders>(JsonSerializer.Create(Client
 0814            }
 0815            catch (JsonException ex)
 816            {
 0817                _httpRequest.Dispose();
 0818                if (_httpResponse != null)
 819                {
 0820                    _httpResponse.Dispose();
 821                }
 0822                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 823            }
 0824            if (_shouldTrace)
 825            {
 0826                ServiceClientTracing.Exit(_invocationId, _result);
 827            }
 0828            return _result;
 0829        }
 830
 831        /// <summary>
 832        /// Lists all of the Pools in the specified Account.
 833        /// </summary>
 834        /// <param name='poolListOptions'>
 835        /// Additional parameters for the operation
 836        /// </param>
 837        /// <param name='customHeaders'>
 838        /// Headers that will be added to request.
 839        /// </param>
 840        /// <param name='cancellationToken'>
 841        /// The cancellation token.
 842        /// </param>
 843        /// <exception cref="BatchErrorException">
 844        /// Thrown when the operation returned an invalid status code
 845        /// </exception>
 846        /// <exception cref="SerializationException">
 847        /// Thrown when unable to deserialize the response
 848        /// </exception>
 849        /// <exception cref="ValidationException">
 850        /// Thrown when a required parameter is null
 851        /// </exception>
 852        /// <exception cref="System.ArgumentNullException">
 853        /// Thrown when a required parameter is null
 854        /// </exception>
 855        /// <return>
 856        /// A response object containing the response body and response headers.
 857        /// </return>
 858        public async Task<AzureOperationResponse<IPage<CloudPool>,PoolListHeaders>> ListWithHttpMessagesAsync(PoolListOp
 859        {
 0860            if (Client.BatchUrl == null)
 861            {
 0862                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 863            }
 0864            if (Client.ApiVersion == null)
 865            {
 0866                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 867            }
 0868            string filter = default(string);
 0869            if (poolListOptions != null)
 870            {
 0871                filter = poolListOptions.Filter;
 872            }
 0873            string select = default(string);
 0874            if (poolListOptions != null)
 875            {
 0876                select = poolListOptions.Select;
 877            }
 0878            string expand = default(string);
 0879            if (poolListOptions != null)
 880            {
 0881                expand = poolListOptions.Expand;
 882            }
 0883            int? maxResults = default(int?);
 0884            if (poolListOptions != null)
 885            {
 0886                maxResults = poolListOptions.MaxResults;
 887            }
 0888            int? timeout = default(int?);
 0889            if (poolListOptions != null)
 890            {
 0891                timeout = poolListOptions.Timeout;
 892            }
 0893            System.Guid? clientRequestId = default(System.Guid?);
 0894            if (poolListOptions != null)
 895            {
 0896                clientRequestId = poolListOptions.ClientRequestId;
 897            }
 0898            bool? returnClientRequestId = default(bool?);
 0899            if (poolListOptions != null)
 900            {
 0901                returnClientRequestId = poolListOptions.ReturnClientRequestId;
 902            }
 0903            System.DateTime? ocpDate = default(System.DateTime?);
 0904            if (poolListOptions != null)
 905            {
 0906                ocpDate = poolListOptions.OcpDate;
 907            }
 908            // Tracing
 0909            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0910            string _invocationId = null;
 0911            if (_shouldTrace)
 912            {
 0913                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0914                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0915                tracingParameters.Add("filter", filter);
 0916                tracingParameters.Add("select", select);
 0917                tracingParameters.Add("expand", expand);
 0918                tracingParameters.Add("maxResults", maxResults);
 0919                tracingParameters.Add("timeout", timeout);
 0920                tracingParameters.Add("clientRequestId", clientRequestId);
 0921                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0922                tracingParameters.Add("ocpDate", ocpDate);
 0923                tracingParameters.Add("cancellationToken", cancellationToken);
 0924                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 925            }
 926            // Construct URL
 0927            var _baseUrl = Client.BaseUri;
 0928            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools";
 0929            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0930            List<string> _queryParameters = new List<string>();
 0931            if (Client.ApiVersion != null)
 932            {
 0933                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 934            }
 0935            if (filter != null)
 936            {
 0937                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 938            }
 0939            if (select != null)
 940            {
 0941                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select)));
 942            }
 0943            if (expand != null)
 944            {
 0945                _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand)));
 946            }
 0947            if (maxResults != null)
 948            {
 0949                _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali
 950            }
 0951            if (timeout != null)
 952            {
 0953                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 954            }
 0955            if (_queryParameters.Count > 0)
 956            {
 0957                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 958            }
 959            // Create HTTP transport objects
 0960            var _httpRequest = new HttpRequestMessage();
 0961            HttpResponseMessage _httpResponse = null;
 0962            _httpRequest.Method = new HttpMethod("GET");
 0963            _httpRequest.RequestUri = new System.Uri(_url);
 964            // Set Headers
 0965            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 966            {
 0967                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 968            }
 0969            if (Client.AcceptLanguage != null)
 970            {
 0971                if (_httpRequest.Headers.Contains("accept-language"))
 972                {
 0973                    _httpRequest.Headers.Remove("accept-language");
 974                }
 0975                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 976            }
 0977            if (clientRequestId != null)
 978            {
 0979                if (_httpRequest.Headers.Contains("client-request-id"))
 980                {
 0981                    _httpRequest.Headers.Remove("client-request-id");
 982                }
 0983                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 984            }
 0985            if (returnClientRequestId != null)
 986            {
 0987                if (_httpRequest.Headers.Contains("return-client-request-id"))
 988                {
 0989                    _httpRequest.Headers.Remove("return-client-request-id");
 990                }
 0991                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 992            }
 0993            if (ocpDate != null)
 994            {
 0995                if (_httpRequest.Headers.Contains("ocp-date"))
 996                {
 0997                    _httpRequest.Headers.Remove("ocp-date");
 998                }
 0999                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1000            }
 1001
 1002
 01003            if (customHeaders != null)
 1004            {
 01005                foreach(var _header in customHeaders)
 1006                {
 01007                    if (_httpRequest.Headers.Contains(_header.Key))
 1008                    {
 01009                        _httpRequest.Headers.Remove(_header.Key);
 1010                    }
 01011                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1012                }
 1013            }
 1014
 1015            // Serialize Request
 01016            string _requestContent = null;
 1017            // Set Credentials
 01018            if (Client.Credentials != null)
 1019            {
 01020                cancellationToken.ThrowIfCancellationRequested();
 01021                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1022            }
 1023            // Send Request
 01024            if (_shouldTrace)
 1025            {
 01026                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1027            }
 01028            cancellationToken.ThrowIfCancellationRequested();
 01029            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01030            if (_shouldTrace)
 1031            {
 01032                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1033            }
 01034            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01035            cancellationToken.ThrowIfCancellationRequested();
 01036            string _responseContent = null;
 01037            if ((int)_statusCode != 200)
 1038            {
 01039                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1040                try
 1041                {
 01042                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01043                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01044                    if (_errorBody != null)
 1045                    {
 01046                        ex.Body = _errorBody;
 1047                    }
 01048                }
 01049                catch (JsonException)
 1050                {
 1051                    // Ignore the exception
 01052                }
 01053                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01054                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01055                if (_shouldTrace)
 1056                {
 01057                    ServiceClientTracing.Error(_invocationId, ex);
 1058                }
 01059                _httpRequest.Dispose();
 01060                if (_httpResponse != null)
 1061                {
 01062                    _httpResponse.Dispose();
 1063                }
 01064                throw ex;
 1065            }
 1066            // Create Result
 01067            var _result = new AzureOperationResponse<IPage<CloudPool>,PoolListHeaders>();
 01068            _result.Request = _httpRequest;
 01069            _result.Response = _httpResponse;
 01070            if (_httpResponse.Headers.Contains("request-id"))
 1071            {
 01072                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1073            }
 1074            // Deserialize Response
 01075            if ((int)_statusCode == 200)
 1076            {
 01077                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1078                try
 1079                {
 01080                    _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudPool>>(_responseContent, Client.Deseriali
 01081                }
 01082                catch (JsonException ex)
 1083                {
 01084                    _httpRequest.Dispose();
 01085                    if (_httpResponse != null)
 1086                    {
 01087                        _httpResponse.Dispose();
 1088                    }
 01089                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1090                }
 1091            }
 1092            try
 1093            {
 01094                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolListHeaders>(JsonSerializer.Create(Clien
 01095            }
 01096            catch (JsonException ex)
 1097            {
 01098                _httpRequest.Dispose();
 01099                if (_httpResponse != null)
 1100                {
 01101                    _httpResponse.Dispose();
 1102                }
 01103                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1104            }
 01105            if (_shouldTrace)
 1106            {
 01107                ServiceClientTracing.Exit(_invocationId, _result);
 1108            }
 01109            return _result;
 01110        }
 1111
 1112        /// <summary>
 1113        /// Deletes a Pool from the specified Account.
 1114        /// </summary>
 1115        /// <remarks>
 1116        /// When you request that a Pool be deleted, the following actions occur: the
 1117        /// Pool state is set to deleting; any ongoing resize operation on the Pool are
 1118        /// stopped; the Batch service starts resizing the Pool to zero Compute Nodes;
 1119        /// any Tasks running on existing Compute Nodes are terminated and requeued (as
 1120        /// if a resize Pool operation had been requested with the default requeue
 1121        /// option); finally, the Pool is removed from the system. Because running
 1122        /// Tasks are requeued, the user can rerun these Tasks by updating their Job to
 1123        /// target a different Pool. The Tasks can then run on the new Pool. If you
 1124        /// want to override the requeue behavior, then you should call resize Pool
 1125        /// explicitly to shrink the Pool to zero size before deleting the Pool. If you
 1126        /// call an Update, Patch or Delete API on a Pool in the deleting state, it
 1127        /// will fail with HTTP status code 409 with error code PoolBeingDeleted.
 1128        /// </remarks>
 1129        /// <param name='poolId'>
 1130        /// The ID of the Pool to delete.
 1131        /// </param>
 1132        /// <param name='poolDeleteOptions'>
 1133        /// Additional parameters for the operation
 1134        /// </param>
 1135        /// <param name='customHeaders'>
 1136        /// Headers that will be added to request.
 1137        /// </param>
 1138        /// <param name='cancellationToken'>
 1139        /// The cancellation token.
 1140        /// </param>
 1141        /// <exception cref="BatchErrorException">
 1142        /// Thrown when the operation returned an invalid status code
 1143        /// </exception>
 1144        /// <exception cref="ValidationException">
 1145        /// Thrown when a required parameter is null
 1146        /// </exception>
 1147        /// <exception cref="System.ArgumentNullException">
 1148        /// Thrown when a required parameter is null
 1149        /// </exception>
 1150        /// <return>
 1151        /// A response object containing the response body and response headers.
 1152        /// </return>
 1153        public async Task<AzureOperationHeaderResponse<PoolDeleteHeaders>> DeleteWithHttpMessagesAsync(string poolId, Po
 1154        {
 41155            if (Client.BatchUrl == null)
 1156            {
 01157                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 1158            }
 41159            if (poolId == null)
 1160            {
 01161                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 1162            }
 41163            if (Client.ApiVersion == null)
 1164            {
 01165                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1166            }
 41167            int? timeout = default(int?);
 41168            if (poolDeleteOptions != null)
 1169            {
 41170                timeout = poolDeleteOptions.Timeout;
 1171            }
 41172            System.Guid? clientRequestId = default(System.Guid?);
 41173            if (poolDeleteOptions != null)
 1174            {
 41175                clientRequestId = poolDeleteOptions.ClientRequestId;
 1176            }
 41177            bool? returnClientRequestId = default(bool?);
 41178            if (poolDeleteOptions != null)
 1179            {
 41180                returnClientRequestId = poolDeleteOptions.ReturnClientRequestId;
 1181            }
 41182            System.DateTime? ocpDate = default(System.DateTime?);
 41183            if (poolDeleteOptions != null)
 1184            {
 41185                ocpDate = poolDeleteOptions.OcpDate;
 1186            }
 41187            string ifMatch = default(string);
 41188            if (poolDeleteOptions != null)
 1189            {
 41190                ifMatch = poolDeleteOptions.IfMatch;
 1191            }
 41192            string ifNoneMatch = default(string);
 41193            if (poolDeleteOptions != null)
 1194            {
 41195                ifNoneMatch = poolDeleteOptions.IfNoneMatch;
 1196            }
 41197            System.DateTime? ifModifiedSince = default(System.DateTime?);
 41198            if (poolDeleteOptions != null)
 1199            {
 41200                ifModifiedSince = poolDeleteOptions.IfModifiedSince;
 1201            }
 41202            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 41203            if (poolDeleteOptions != null)
 1204            {
 41205                ifUnmodifiedSince = poolDeleteOptions.IfUnmodifiedSince;
 1206            }
 1207            // Tracing
 41208            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 41209            string _invocationId = null;
 41210            if (_shouldTrace)
 1211            {
 01212                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01213                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01214                tracingParameters.Add("poolId", poolId);
 01215                tracingParameters.Add("timeout", timeout);
 01216                tracingParameters.Add("clientRequestId", clientRequestId);
 01217                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 01218                tracingParameters.Add("ocpDate", ocpDate);
 01219                tracingParameters.Add("ifMatch", ifMatch);
 01220                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 01221                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 01222                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 01223                tracingParameters.Add("cancellationToken", cancellationToken);
 01224                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 1225            }
 1226            // Construct URL
 41227            var _baseUrl = Client.BaseUri;
 41228            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}";
 41229            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 41230            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 41231            List<string> _queryParameters = new List<string>();
 41232            if (Client.ApiVersion != null)
 1233            {
 41234                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1235            }
 41236            if (timeout != null)
 1237            {
 01238                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1239            }
 41240            if (_queryParameters.Count > 0)
 1241            {
 41242                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1243            }
 1244            // Create HTTP transport objects
 41245            var _httpRequest = new HttpRequestMessage();
 41246            HttpResponseMessage _httpResponse = null;
 41247            _httpRequest.Method = new HttpMethod("DELETE");
 41248            _httpRequest.RequestUri = new System.Uri(_url);
 1249            // Set Headers
 41250            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1251            {
 41252                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1253            }
 41254            if (Client.AcceptLanguage != null)
 1255            {
 41256                if (_httpRequest.Headers.Contains("accept-language"))
 1257                {
 01258                    _httpRequest.Headers.Remove("accept-language");
 1259                }
 41260                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1261            }
 41262            if (clientRequestId != null)
 1263            {
 41264                if (_httpRequest.Headers.Contains("client-request-id"))
 1265                {
 41266                    _httpRequest.Headers.Remove("client-request-id");
 1267                }
 41268                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1269            }
 41270            if (returnClientRequestId != null)
 1271            {
 01272                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1273                {
 01274                    _httpRequest.Headers.Remove("return-client-request-id");
 1275                }
 01276                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1277            }
 41278            if (ocpDate != null)
 1279            {
 01280                if (_httpRequest.Headers.Contains("ocp-date"))
 1281                {
 01282                    _httpRequest.Headers.Remove("ocp-date");
 1283                }
 01284                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1285            }
 41286            if (ifMatch != null)
 1287            {
 01288                if (_httpRequest.Headers.Contains("If-Match"))
 1289                {
 01290                    _httpRequest.Headers.Remove("If-Match");
 1291                }
 01292                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 1293            }
 41294            if (ifNoneMatch != null)
 1295            {
 01296                if (_httpRequest.Headers.Contains("If-None-Match"))
 1297                {
 01298                    _httpRequest.Headers.Remove("If-None-Match");
 1299                }
 01300                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 1301            }
 41302            if (ifModifiedSince != null)
 1303            {
 01304                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 1305                {
 01306                    _httpRequest.Headers.Remove("If-Modified-Since");
 1307                }
 01308                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 1309            }
 41310            if (ifUnmodifiedSince != null)
 1311            {
 01312                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 1313                {
 01314                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 1315                }
 01316                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 1317            }
 1318
 1319
 41320            if (customHeaders != null)
 1321            {
 01322                foreach(var _header in customHeaders)
 1323                {
 01324                    if (_httpRequest.Headers.Contains(_header.Key))
 1325                    {
 01326                        _httpRequest.Headers.Remove(_header.Key);
 1327                    }
 01328                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1329                }
 1330            }
 1331
 1332            // Serialize Request
 41333            string _requestContent = null;
 1334            // Set Credentials
 41335            if (Client.Credentials != null)
 1336            {
 41337                cancellationToken.ThrowIfCancellationRequested();
 41338                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1339            }
 1340            // Send Request
 41341            if (_shouldTrace)
 1342            {
 01343                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1344            }
 41345            cancellationToken.ThrowIfCancellationRequested();
 41346            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 41347            if (_shouldTrace)
 1348            {
 01349                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1350            }
 41351            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 41352            cancellationToken.ThrowIfCancellationRequested();
 41353            string _responseContent = null;
 41354            if ((int)_statusCode != 202)
 1355            {
 01356                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1357                try
 1358                {
 01359                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01360                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01361                    if (_errorBody != null)
 1362                    {
 01363                        ex.Body = _errorBody;
 1364                    }
 01365                }
 01366                catch (JsonException)
 1367                {
 1368                    // Ignore the exception
 01369                }
 01370                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01371                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01372                if (_shouldTrace)
 1373                {
 01374                    ServiceClientTracing.Error(_invocationId, ex);
 1375                }
 01376                _httpRequest.Dispose();
 01377                if (_httpResponse != null)
 1378                {
 01379                    _httpResponse.Dispose();
 1380                }
 01381                throw ex;
 1382            }
 1383            // Create Result
 41384            var _result = new AzureOperationHeaderResponse<PoolDeleteHeaders>();
 41385            _result.Request = _httpRequest;
 41386            _result.Response = _httpResponse;
 41387            if (_httpResponse.Headers.Contains("request-id"))
 1388            {
 01389                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1390            }
 1391            try
 1392            {
 41393                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolDeleteHeaders>(JsonSerializer.Create(Cli
 41394            }
 01395            catch (JsonException ex)
 1396            {
 01397                _httpRequest.Dispose();
 01398                if (_httpResponse != null)
 1399                {
 01400                    _httpResponse.Dispose();
 1401                }
 01402                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1403            }
 41404            if (_shouldTrace)
 1405            {
 01406                ServiceClientTracing.Exit(_invocationId, _result);
 1407            }
 41408            return _result;
 41409        }
 1410
 1411        /// <summary>
 1412        /// Gets basic properties of a Pool.
 1413        /// </summary>
 1414        /// <param name='poolId'>
 1415        /// The ID of the Pool to get.
 1416        /// </param>
 1417        /// <param name='poolExistsOptions'>
 1418        /// Additional parameters for the operation
 1419        /// </param>
 1420        /// <param name='customHeaders'>
 1421        /// Headers that will be added to request.
 1422        /// </param>
 1423        /// <param name='cancellationToken'>
 1424        /// The cancellation token.
 1425        /// </param>
 1426        /// <exception cref="BatchErrorException">
 1427        /// Thrown when the operation returned an invalid status code
 1428        /// </exception>
 1429        /// <exception cref="ValidationException">
 1430        /// Thrown when a required parameter is null
 1431        /// </exception>
 1432        /// <exception cref="System.ArgumentNullException">
 1433        /// Thrown when a required parameter is null
 1434        /// </exception>
 1435        /// <return>
 1436        /// A response object containing the response body and response headers.
 1437        /// </return>
 1438        public async Task<AzureOperationResponse<bool,PoolExistsHeaders>> ExistsWithHttpMessagesAsync(string poolId, Poo
 1439        {
 01440            if (Client.BatchUrl == null)
 1441            {
 01442                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 1443            }
 01444            if (poolId == null)
 1445            {
 01446                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 1447            }
 01448            if (Client.ApiVersion == null)
 1449            {
 01450                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1451            }
 01452            int? timeout = default(int?);
 01453            if (poolExistsOptions != null)
 1454            {
 01455                timeout = poolExistsOptions.Timeout;
 1456            }
 01457            System.Guid? clientRequestId = default(System.Guid?);
 01458            if (poolExistsOptions != null)
 1459            {
 01460                clientRequestId = poolExistsOptions.ClientRequestId;
 1461            }
 01462            bool? returnClientRequestId = default(bool?);
 01463            if (poolExistsOptions != null)
 1464            {
 01465                returnClientRequestId = poolExistsOptions.ReturnClientRequestId;
 1466            }
 01467            System.DateTime? ocpDate = default(System.DateTime?);
 01468            if (poolExistsOptions != null)
 1469            {
 01470                ocpDate = poolExistsOptions.OcpDate;
 1471            }
 01472            string ifMatch = default(string);
 01473            if (poolExistsOptions != null)
 1474            {
 01475                ifMatch = poolExistsOptions.IfMatch;
 1476            }
 01477            string ifNoneMatch = default(string);
 01478            if (poolExistsOptions != null)
 1479            {
 01480                ifNoneMatch = poolExistsOptions.IfNoneMatch;
 1481            }
 01482            System.DateTime? ifModifiedSince = default(System.DateTime?);
 01483            if (poolExistsOptions != null)
 1484            {
 01485                ifModifiedSince = poolExistsOptions.IfModifiedSince;
 1486            }
 01487            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 01488            if (poolExistsOptions != null)
 1489            {
 01490                ifUnmodifiedSince = poolExistsOptions.IfUnmodifiedSince;
 1491            }
 1492            // Tracing
 01493            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01494            string _invocationId = null;
 01495            if (_shouldTrace)
 1496            {
 01497                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01498                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01499                tracingParameters.Add("poolId", poolId);
 01500                tracingParameters.Add("timeout", timeout);
 01501                tracingParameters.Add("clientRequestId", clientRequestId);
 01502                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 01503                tracingParameters.Add("ocpDate", ocpDate);
 01504                tracingParameters.Add("ifMatch", ifMatch);
 01505                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 01506                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 01507                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 01508                tracingParameters.Add("cancellationToken", cancellationToken);
 01509                ServiceClientTracing.Enter(_invocationId, this, "Exists", tracingParameters);
 1510            }
 1511            // Construct URL
 01512            var _baseUrl = Client.BaseUri;
 01513            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}";
 01514            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 01515            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 01516            List<string> _queryParameters = new List<string>();
 01517            if (Client.ApiVersion != null)
 1518            {
 01519                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1520            }
 01521            if (timeout != null)
 1522            {
 01523                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1524            }
 01525            if (_queryParameters.Count > 0)
 1526            {
 01527                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1528            }
 1529            // Create HTTP transport objects
 01530            var _httpRequest = new HttpRequestMessage();
 01531            HttpResponseMessage _httpResponse = null;
 01532            _httpRequest.Method = new HttpMethod("HEAD");
 01533            _httpRequest.RequestUri = new System.Uri(_url);
 1534            // Set Headers
 01535            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1536            {
 01537                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1538            }
 01539            if (Client.AcceptLanguage != null)
 1540            {
 01541                if (_httpRequest.Headers.Contains("accept-language"))
 1542                {
 01543                    _httpRequest.Headers.Remove("accept-language");
 1544                }
 01545                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1546            }
 01547            if (clientRequestId != null)
 1548            {
 01549                if (_httpRequest.Headers.Contains("client-request-id"))
 1550                {
 01551                    _httpRequest.Headers.Remove("client-request-id");
 1552                }
 01553                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1554            }
 01555            if (returnClientRequestId != null)
 1556            {
 01557                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1558                {
 01559                    _httpRequest.Headers.Remove("return-client-request-id");
 1560                }
 01561                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1562            }
 01563            if (ocpDate != null)
 1564            {
 01565                if (_httpRequest.Headers.Contains("ocp-date"))
 1566                {
 01567                    _httpRequest.Headers.Remove("ocp-date");
 1568                }
 01569                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1570            }
 01571            if (ifMatch != null)
 1572            {
 01573                if (_httpRequest.Headers.Contains("If-Match"))
 1574                {
 01575                    _httpRequest.Headers.Remove("If-Match");
 1576                }
 01577                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 1578            }
 01579            if (ifNoneMatch != null)
 1580            {
 01581                if (_httpRequest.Headers.Contains("If-None-Match"))
 1582                {
 01583                    _httpRequest.Headers.Remove("If-None-Match");
 1584                }
 01585                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 1586            }
 01587            if (ifModifiedSince != null)
 1588            {
 01589                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 1590                {
 01591                    _httpRequest.Headers.Remove("If-Modified-Since");
 1592                }
 01593                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 1594            }
 01595            if (ifUnmodifiedSince != null)
 1596            {
 01597                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 1598                {
 01599                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 1600                }
 01601                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 1602            }
 1603
 1604
 01605            if (customHeaders != null)
 1606            {
 01607                foreach(var _header in customHeaders)
 1608                {
 01609                    if (_httpRequest.Headers.Contains(_header.Key))
 1610                    {
 01611                        _httpRequest.Headers.Remove(_header.Key);
 1612                    }
 01613                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1614                }
 1615            }
 1616
 1617            // Serialize Request
 01618            string _requestContent = null;
 1619            // Set Credentials
 01620            if (Client.Credentials != null)
 1621            {
 01622                cancellationToken.ThrowIfCancellationRequested();
 01623                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1624            }
 1625            // Send Request
 01626            if (_shouldTrace)
 1627            {
 01628                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1629            }
 01630            cancellationToken.ThrowIfCancellationRequested();
 01631            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons
 01632            if (_shouldTrace)
 1633            {
 01634                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1635            }
 01636            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01637            cancellationToken.ThrowIfCancellationRequested();
 01638            string _responseContent = null;
 01639            if ((int)_statusCode != 200 && (int)_statusCode != 404)
 1640            {
 01641                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1642                try
 1643                {
 01644                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01645                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01646                    if (_errorBody != null)
 1647                    {
 01648                        ex.Body = _errorBody;
 1649                    }
 01650                }
 01651                catch (JsonException)
 1652                {
 1653                    // Ignore the exception
 01654                }
 01655                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01656                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01657                if (_shouldTrace)
 1658                {
 01659                    ServiceClientTracing.Error(_invocationId, ex);
 1660                }
 01661                _httpRequest.Dispose();
 01662                if (_httpResponse != null)
 1663                {
 01664                    _httpResponse.Dispose();
 1665                }
 01666                throw ex;
 1667            }
 1668            // Create Result
 01669            var _result = new AzureOperationResponse<bool,PoolExistsHeaders>();
 01670            _result.Request = _httpRequest;
 01671            _result.Response = _httpResponse;
 01672            _result.Body = _statusCode == System.Net.HttpStatusCode.OK;
 01673            if (_httpResponse.Headers.Contains("request-id"))
 1674            {
 01675                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1676            }
 1677            try
 1678            {
 01679                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolExistsHeaders>(JsonSerializer.Create(Cli
 01680            }
 01681            catch (JsonException ex)
 1682            {
 01683                _httpRequest.Dispose();
 01684                if (_httpResponse != null)
 1685                {
 01686                    _httpResponse.Dispose();
 1687                }
 01688                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1689            }
 01690            if (_shouldTrace)
 1691            {
 01692                ServiceClientTracing.Exit(_invocationId, _result);
 1693            }
 01694            return _result;
 01695        }
 1696
 1697        /// <summary>
 1698        /// Gets information about the specified Pool.
 1699        /// </summary>
 1700        /// <param name='poolId'>
 1701        /// The ID of the Pool to get.
 1702        /// </param>
 1703        /// <param name='poolGetOptions'>
 1704        /// Additional parameters for the operation
 1705        /// </param>
 1706        /// <param name='customHeaders'>
 1707        /// Headers that will be added to request.
 1708        /// </param>
 1709        /// <param name='cancellationToken'>
 1710        /// The cancellation token.
 1711        /// </param>
 1712        /// <exception cref="BatchErrorException">
 1713        /// Thrown when the operation returned an invalid status code
 1714        /// </exception>
 1715        /// <exception cref="SerializationException">
 1716        /// Thrown when unable to deserialize the response
 1717        /// </exception>
 1718        /// <exception cref="ValidationException">
 1719        /// Thrown when a required parameter is null
 1720        /// </exception>
 1721        /// <exception cref="System.ArgumentNullException">
 1722        /// Thrown when a required parameter is null
 1723        /// </exception>
 1724        /// <return>
 1725        /// A response object containing the response body and response headers.
 1726        /// </return>
 1727        public async Task<AzureOperationResponse<CloudPool,PoolGetHeaders>> GetWithHttpMessagesAsync(string poolId, Pool
 1728        {
 11729            if (Client.BatchUrl == null)
 1730            {
 01731                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 1732            }
 11733            if (poolId == null)
 1734            {
 11735                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 1736            }
 01737            if (Client.ApiVersion == null)
 1738            {
 01739                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1740            }
 01741            string select = default(string);
 01742            if (poolGetOptions != null)
 1743            {
 01744                select = poolGetOptions.Select;
 1745            }
 01746            string expand = default(string);
 01747            if (poolGetOptions != null)
 1748            {
 01749                expand = poolGetOptions.Expand;
 1750            }
 01751            int? timeout = default(int?);
 01752            if (poolGetOptions != null)
 1753            {
 01754                timeout = poolGetOptions.Timeout;
 1755            }
 01756            System.Guid? clientRequestId = default(System.Guid?);
 01757            if (poolGetOptions != null)
 1758            {
 01759                clientRequestId = poolGetOptions.ClientRequestId;
 1760            }
 01761            bool? returnClientRequestId = default(bool?);
 01762            if (poolGetOptions != null)
 1763            {
 01764                returnClientRequestId = poolGetOptions.ReturnClientRequestId;
 1765            }
 01766            System.DateTime? ocpDate = default(System.DateTime?);
 01767            if (poolGetOptions != null)
 1768            {
 01769                ocpDate = poolGetOptions.OcpDate;
 1770            }
 01771            string ifMatch = default(string);
 01772            if (poolGetOptions != null)
 1773            {
 01774                ifMatch = poolGetOptions.IfMatch;
 1775            }
 01776            string ifNoneMatch = default(string);
 01777            if (poolGetOptions != null)
 1778            {
 01779                ifNoneMatch = poolGetOptions.IfNoneMatch;
 1780            }
 01781            System.DateTime? ifModifiedSince = default(System.DateTime?);
 01782            if (poolGetOptions != null)
 1783            {
 01784                ifModifiedSince = poolGetOptions.IfModifiedSince;
 1785            }
 01786            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 01787            if (poolGetOptions != null)
 1788            {
 01789                ifUnmodifiedSince = poolGetOptions.IfUnmodifiedSince;
 1790            }
 1791            // Tracing
 01792            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01793            string _invocationId = null;
 01794            if (_shouldTrace)
 1795            {
 01796                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01797                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01798                tracingParameters.Add("poolId", poolId);
 01799                tracingParameters.Add("select", select);
 01800                tracingParameters.Add("expand", expand);
 01801                tracingParameters.Add("timeout", timeout);
 01802                tracingParameters.Add("clientRequestId", clientRequestId);
 01803                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 01804                tracingParameters.Add("ocpDate", ocpDate);
 01805                tracingParameters.Add("ifMatch", ifMatch);
 01806                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 01807                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 01808                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 01809                tracingParameters.Add("cancellationToken", cancellationToken);
 01810                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 1811            }
 1812            // Construct URL
 01813            var _baseUrl = Client.BaseUri;
 01814            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}";
 01815            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 01816            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 01817            List<string> _queryParameters = new List<string>();
 01818            if (Client.ApiVersion != null)
 1819            {
 01820                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1821            }
 01822            if (select != null)
 1823            {
 01824                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select)));
 1825            }
 01826            if (expand != null)
 1827            {
 01828                _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand)));
 1829            }
 01830            if (timeout != null)
 1831            {
 01832                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1833            }
 01834            if (_queryParameters.Count > 0)
 1835            {
 01836                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1837            }
 1838            // Create HTTP transport objects
 01839            var _httpRequest = new HttpRequestMessage();
 01840            HttpResponseMessage _httpResponse = null;
 01841            _httpRequest.Method = new HttpMethod("GET");
 01842            _httpRequest.RequestUri = new System.Uri(_url);
 1843            // Set Headers
 01844            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1845            {
 01846                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1847            }
 01848            if (Client.AcceptLanguage != null)
 1849            {
 01850                if (_httpRequest.Headers.Contains("accept-language"))
 1851                {
 01852                    _httpRequest.Headers.Remove("accept-language");
 1853                }
 01854                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1855            }
 01856            if (clientRequestId != null)
 1857            {
 01858                if (_httpRequest.Headers.Contains("client-request-id"))
 1859                {
 01860                    _httpRequest.Headers.Remove("client-request-id");
 1861                }
 01862                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1863            }
 01864            if (returnClientRequestId != null)
 1865            {
 01866                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1867                {
 01868                    _httpRequest.Headers.Remove("return-client-request-id");
 1869                }
 01870                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1871            }
 01872            if (ocpDate != null)
 1873            {
 01874                if (_httpRequest.Headers.Contains("ocp-date"))
 1875                {
 01876                    _httpRequest.Headers.Remove("ocp-date");
 1877                }
 01878                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1879            }
 01880            if (ifMatch != null)
 1881            {
 01882                if (_httpRequest.Headers.Contains("If-Match"))
 1883                {
 01884                    _httpRequest.Headers.Remove("If-Match");
 1885                }
 01886                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 1887            }
 01888            if (ifNoneMatch != null)
 1889            {
 01890                if (_httpRequest.Headers.Contains("If-None-Match"))
 1891                {
 01892                    _httpRequest.Headers.Remove("If-None-Match");
 1893                }
 01894                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 1895            }
 01896            if (ifModifiedSince != null)
 1897            {
 01898                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 1899                {
 01900                    _httpRequest.Headers.Remove("If-Modified-Since");
 1901                }
 01902                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 1903            }
 01904            if (ifUnmodifiedSince != null)
 1905            {
 01906                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 1907                {
 01908                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 1909                }
 01910                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 1911            }
 1912
 1913
 01914            if (customHeaders != null)
 1915            {
 01916                foreach(var _header in customHeaders)
 1917                {
 01918                    if (_httpRequest.Headers.Contains(_header.Key))
 1919                    {
 01920                        _httpRequest.Headers.Remove(_header.Key);
 1921                    }
 01922                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1923                }
 1924            }
 1925
 1926            // Serialize Request
 01927            string _requestContent = null;
 1928            // Set Credentials
 01929            if (Client.Credentials != null)
 1930            {
 01931                cancellationToken.ThrowIfCancellationRequested();
 01932                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1933            }
 1934            // Send Request
 01935            if (_shouldTrace)
 1936            {
 01937                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1938            }
 01939            cancellationToken.ThrowIfCancellationRequested();
 01940            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01941            if (_shouldTrace)
 1942            {
 01943                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1944            }
 01945            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01946            cancellationToken.ThrowIfCancellationRequested();
 01947            string _responseContent = null;
 01948            if ((int)_statusCode != 200)
 1949            {
 01950                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1951                try
 1952                {
 01953                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01954                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01955                    if (_errorBody != null)
 1956                    {
 01957                        ex.Body = _errorBody;
 1958                    }
 01959                }
 01960                catch (JsonException)
 1961                {
 1962                    // Ignore the exception
 01963                }
 01964                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01965                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01966                if (_shouldTrace)
 1967                {
 01968                    ServiceClientTracing.Error(_invocationId, ex);
 1969                }
 01970                _httpRequest.Dispose();
 01971                if (_httpResponse != null)
 1972                {
 01973                    _httpResponse.Dispose();
 1974                }
 01975                throw ex;
 1976            }
 1977            // Create Result
 01978            var _result = new AzureOperationResponse<CloudPool,PoolGetHeaders>();
 01979            _result.Request = _httpRequest;
 01980            _result.Response = _httpResponse;
 01981            if (_httpResponse.Headers.Contains("request-id"))
 1982            {
 01983                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1984            }
 1985            // Deserialize Response
 01986            if ((int)_statusCode == 200)
 1987            {
 01988                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1989                try
 1990                {
 01991                    _result.Body = SafeJsonConvert.DeserializeObject<CloudPool>(_responseContent, Client.Deserialization
 01992                }
 01993                catch (JsonException ex)
 1994                {
 01995                    _httpRequest.Dispose();
 01996                    if (_httpResponse != null)
 1997                    {
 01998                        _httpResponse.Dispose();
 1999                    }
 02000                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2001                }
 2002            }
 2003            try
 2004            {
 02005                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolGetHeaders>(JsonSerializer.Create(Client
 02006            }
 02007            catch (JsonException ex)
 2008            {
 02009                _httpRequest.Dispose();
 02010                if (_httpResponse != null)
 2011                {
 02012                    _httpResponse.Dispose();
 2013                }
 02014                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2015            }
 02016            if (_shouldTrace)
 2017            {
 02018                ServiceClientTracing.Exit(_invocationId, _result);
 2019            }
 02020            return _result;
 02021        }
 2022
 2023        /// <summary>
 2024        /// Updates the properties of the specified Pool.
 2025        /// </summary>
 2026        /// <remarks>
 2027        /// This only replaces the Pool properties specified in the request. For
 2028        /// example, if the Pool has a StartTask associated with it, and a request does
 2029        /// not specify a StartTask element, then the Pool keeps the existing
 2030        /// StartTask.
 2031        /// </remarks>
 2032        /// <param name='poolId'>
 2033        /// The ID of the Pool to update.
 2034        /// </param>
 2035        /// <param name='poolPatchParameter'>
 2036        /// The parameters for the request.
 2037        /// </param>
 2038        /// <param name='poolPatchOptions'>
 2039        /// Additional parameters for the operation
 2040        /// </param>
 2041        /// <param name='customHeaders'>
 2042        /// Headers that will be added to request.
 2043        /// </param>
 2044        /// <param name='cancellationToken'>
 2045        /// The cancellation token.
 2046        /// </param>
 2047        /// <exception cref="BatchErrorException">
 2048        /// Thrown when the operation returned an invalid status code
 2049        /// </exception>
 2050        /// <exception cref="ValidationException">
 2051        /// Thrown when a required parameter is null
 2052        /// </exception>
 2053        /// <exception cref="System.ArgumentNullException">
 2054        /// Thrown when a required parameter is null
 2055        /// </exception>
 2056        /// <return>
 2057        /// A response object containing the response body and response headers.
 2058        /// </return>
 2059        public async Task<AzureOperationHeaderResponse<PoolPatchHeaders>> PatchWithHttpMessagesAsync(string poolId, Pool
 2060        {
 02061            if (Client.BatchUrl == null)
 2062            {
 02063                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 2064            }
 02065            if (poolId == null)
 2066            {
 02067                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 2068            }
 02069            if (poolPatchParameter == null)
 2070            {
 02071                throw new ValidationException(ValidationRules.CannotBeNull, "poolPatchParameter");
 2072            }
 02073            if (Client.ApiVersion == null)
 2074            {
 02075                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2076            }
 02077            int? timeout = default(int?);
 02078            if (poolPatchOptions != null)
 2079            {
 02080                timeout = poolPatchOptions.Timeout;
 2081            }
 02082            System.Guid? clientRequestId = default(System.Guid?);
 02083            if (poolPatchOptions != null)
 2084            {
 02085                clientRequestId = poolPatchOptions.ClientRequestId;
 2086            }
 02087            bool? returnClientRequestId = default(bool?);
 02088            if (poolPatchOptions != null)
 2089            {
 02090                returnClientRequestId = poolPatchOptions.ReturnClientRequestId;
 2091            }
 02092            System.DateTime? ocpDate = default(System.DateTime?);
 02093            if (poolPatchOptions != null)
 2094            {
 02095                ocpDate = poolPatchOptions.OcpDate;
 2096            }
 02097            string ifMatch = default(string);
 02098            if (poolPatchOptions != null)
 2099            {
 02100                ifMatch = poolPatchOptions.IfMatch;
 2101            }
 02102            string ifNoneMatch = default(string);
 02103            if (poolPatchOptions != null)
 2104            {
 02105                ifNoneMatch = poolPatchOptions.IfNoneMatch;
 2106            }
 02107            System.DateTime? ifModifiedSince = default(System.DateTime?);
 02108            if (poolPatchOptions != null)
 2109            {
 02110                ifModifiedSince = poolPatchOptions.IfModifiedSince;
 2111            }
 02112            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 02113            if (poolPatchOptions != null)
 2114            {
 02115                ifUnmodifiedSince = poolPatchOptions.IfUnmodifiedSince;
 2116            }
 2117            // Tracing
 02118            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02119            string _invocationId = null;
 02120            if (_shouldTrace)
 2121            {
 02122                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02123                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02124                tracingParameters.Add("poolId", poolId);
 02125                tracingParameters.Add("poolPatchParameter", poolPatchParameter);
 02126                tracingParameters.Add("timeout", timeout);
 02127                tracingParameters.Add("clientRequestId", clientRequestId);
 02128                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02129                tracingParameters.Add("ocpDate", ocpDate);
 02130                tracingParameters.Add("ifMatch", ifMatch);
 02131                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 02132                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 02133                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 02134                tracingParameters.Add("cancellationToken", cancellationToken);
 02135                ServiceClientTracing.Enter(_invocationId, this, "Patch", tracingParameters);
 2136            }
 2137            // Construct URL
 02138            var _baseUrl = Client.BaseUri;
 02139            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}";
 02140            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 02141            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 02142            List<string> _queryParameters = new List<string>();
 02143            if (Client.ApiVersion != null)
 2144            {
 02145                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2146            }
 02147            if (timeout != null)
 2148            {
 02149                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 2150            }
 02151            if (_queryParameters.Count > 0)
 2152            {
 02153                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2154            }
 2155            // Create HTTP transport objects
 02156            var _httpRequest = new HttpRequestMessage();
 02157            HttpResponseMessage _httpResponse = null;
 02158            _httpRequest.Method = new HttpMethod("PATCH");
 02159            _httpRequest.RequestUri = new System.Uri(_url);
 2160            // Set Headers
 02161            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2162            {
 02163                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2164            }
 02165            if (Client.AcceptLanguage != null)
 2166            {
 02167                if (_httpRequest.Headers.Contains("accept-language"))
 2168                {
 02169                    _httpRequest.Headers.Remove("accept-language");
 2170                }
 02171                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2172            }
 02173            if (clientRequestId != null)
 2174            {
 02175                if (_httpRequest.Headers.Contains("client-request-id"))
 2176                {
 02177                    _httpRequest.Headers.Remove("client-request-id");
 2178                }
 02179                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 2180            }
 02181            if (returnClientRequestId != null)
 2182            {
 02183                if (_httpRequest.Headers.Contains("return-client-request-id"))
 2184                {
 02185                    _httpRequest.Headers.Remove("return-client-request-id");
 2186                }
 02187                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 2188            }
 02189            if (ocpDate != null)
 2190            {
 02191                if (_httpRequest.Headers.Contains("ocp-date"))
 2192                {
 02193                    _httpRequest.Headers.Remove("ocp-date");
 2194                }
 02195                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2196            }
 02197            if (ifMatch != null)
 2198            {
 02199                if (_httpRequest.Headers.Contains("If-Match"))
 2200                {
 02201                    _httpRequest.Headers.Remove("If-Match");
 2202                }
 02203                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 2204            }
 02205            if (ifNoneMatch != null)
 2206            {
 02207                if (_httpRequest.Headers.Contains("If-None-Match"))
 2208                {
 02209                    _httpRequest.Headers.Remove("If-None-Match");
 2210                }
 02211                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 2212            }
 02213            if (ifModifiedSince != null)
 2214            {
 02215                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 2216                {
 02217                    _httpRequest.Headers.Remove("If-Modified-Since");
 2218                }
 02219                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 2220            }
 02221            if (ifUnmodifiedSince != null)
 2222            {
 02223                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 2224                {
 02225                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 2226                }
 02227                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 2228            }
 2229
 2230
 02231            if (customHeaders != null)
 2232            {
 02233                foreach(var _header in customHeaders)
 2234                {
 02235                    if (_httpRequest.Headers.Contains(_header.Key))
 2236                    {
 02237                        _httpRequest.Headers.Remove(_header.Key);
 2238                    }
 02239                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2240                }
 2241            }
 2242
 2243            // Serialize Request
 02244            string _requestContent = null;
 02245            if(poolPatchParameter != null)
 2246            {
 02247                _requestContent = SafeJsonConvert.SerializeObject(poolPatchParameter, Client.SerializationSettings);
 02248                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 02249                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2250            }
 2251            // Set Credentials
 02252            if (Client.Credentials != null)
 2253            {
 02254                cancellationToken.ThrowIfCancellationRequested();
 02255                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2256            }
 2257            // Send Request
 02258            if (_shouldTrace)
 2259            {
 02260                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2261            }
 02262            cancellationToken.ThrowIfCancellationRequested();
 02263            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02264            if (_shouldTrace)
 2265            {
 02266                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2267            }
 02268            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02269            cancellationToken.ThrowIfCancellationRequested();
 02270            string _responseContent = null;
 02271            if ((int)_statusCode != 200)
 2272            {
 02273                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2274                try
 2275                {
 02276                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02277                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02278                    if (_errorBody != null)
 2279                    {
 02280                        ex.Body = _errorBody;
 2281                    }
 02282                }
 02283                catch (JsonException)
 2284                {
 2285                    // Ignore the exception
 02286                }
 02287                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02288                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02289                if (_shouldTrace)
 2290                {
 02291                    ServiceClientTracing.Error(_invocationId, ex);
 2292                }
 02293                _httpRequest.Dispose();
 02294                if (_httpResponse != null)
 2295                {
 02296                    _httpResponse.Dispose();
 2297                }
 02298                throw ex;
 2299            }
 2300            // Create Result
 02301            var _result = new AzureOperationHeaderResponse<PoolPatchHeaders>();
 02302            _result.Request = _httpRequest;
 02303            _result.Response = _httpResponse;
 02304            if (_httpResponse.Headers.Contains("request-id"))
 2305            {
 02306                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2307            }
 2308            try
 2309            {
 02310                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolPatchHeaders>(JsonSerializer.Create(Clie
 02311            }
 02312            catch (JsonException ex)
 2313            {
 02314                _httpRequest.Dispose();
 02315                if (_httpResponse != null)
 2316                {
 02317                    _httpResponse.Dispose();
 2318                }
 02319                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2320            }
 02321            if (_shouldTrace)
 2322            {
 02323                ServiceClientTracing.Exit(_invocationId, _result);
 2324            }
 02325            return _result;
 02326        }
 2327
 2328        /// <summary>
 2329        /// Disables automatic scaling for a Pool.
 2330        /// </summary>
 2331        /// <param name='poolId'>
 2332        /// The ID of the Pool on which to disable automatic scaling.
 2333        /// </param>
 2334        /// <param name='poolDisableAutoScaleOptions'>
 2335        /// Additional parameters for the operation
 2336        /// </param>
 2337        /// <param name='customHeaders'>
 2338        /// Headers that will be added to request.
 2339        /// </param>
 2340        /// <param name='cancellationToken'>
 2341        /// The cancellation token.
 2342        /// </param>
 2343        /// <exception cref="BatchErrorException">
 2344        /// Thrown when the operation returned an invalid status code
 2345        /// </exception>
 2346        /// <exception cref="ValidationException">
 2347        /// Thrown when a required parameter is null
 2348        /// </exception>
 2349        /// <exception cref="System.ArgumentNullException">
 2350        /// Thrown when a required parameter is null
 2351        /// </exception>
 2352        /// <return>
 2353        /// A response object containing the response body and response headers.
 2354        /// </return>
 2355        public async Task<AzureOperationHeaderResponse<PoolDisableAutoScaleHeaders>> DisableAutoScaleWithHttpMessagesAsy
 2356        {
 02357            if (Client.BatchUrl == null)
 2358            {
 02359                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 2360            }
 02361            if (poolId == null)
 2362            {
 02363                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 2364            }
 02365            if (Client.ApiVersion == null)
 2366            {
 02367                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2368            }
 02369            int? timeout = default(int?);
 02370            if (poolDisableAutoScaleOptions != null)
 2371            {
 02372                timeout = poolDisableAutoScaleOptions.Timeout;
 2373            }
 02374            System.Guid? clientRequestId = default(System.Guid?);
 02375            if (poolDisableAutoScaleOptions != null)
 2376            {
 02377                clientRequestId = poolDisableAutoScaleOptions.ClientRequestId;
 2378            }
 02379            bool? returnClientRequestId = default(bool?);
 02380            if (poolDisableAutoScaleOptions != null)
 2381            {
 02382                returnClientRequestId = poolDisableAutoScaleOptions.ReturnClientRequestId;
 2383            }
 02384            System.DateTime? ocpDate = default(System.DateTime?);
 02385            if (poolDisableAutoScaleOptions != null)
 2386            {
 02387                ocpDate = poolDisableAutoScaleOptions.OcpDate;
 2388            }
 2389            // Tracing
 02390            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02391            string _invocationId = null;
 02392            if (_shouldTrace)
 2393            {
 02394                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02395                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02396                tracingParameters.Add("poolId", poolId);
 02397                tracingParameters.Add("timeout", timeout);
 02398                tracingParameters.Add("clientRequestId", clientRequestId);
 02399                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02400                tracingParameters.Add("ocpDate", ocpDate);
 02401                tracingParameters.Add("cancellationToken", cancellationToken);
 02402                ServiceClientTracing.Enter(_invocationId, this, "DisableAutoScale", tracingParameters);
 2403            }
 2404            // Construct URL
 02405            var _baseUrl = Client.BaseUri;
 02406            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/disableautoscale";
 02407            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 02408            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 02409            List<string> _queryParameters = new List<string>();
 02410            if (Client.ApiVersion != null)
 2411            {
 02412                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2413            }
 02414            if (timeout != null)
 2415            {
 02416                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 2417            }
 02418            if (_queryParameters.Count > 0)
 2419            {
 02420                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2421            }
 2422            // Create HTTP transport objects
 02423            var _httpRequest = new HttpRequestMessage();
 02424            HttpResponseMessage _httpResponse = null;
 02425            _httpRequest.Method = new HttpMethod("POST");
 02426            _httpRequest.RequestUri = new System.Uri(_url);
 2427            // Set Headers
 02428            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2429            {
 02430                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2431            }
 02432            if (Client.AcceptLanguage != null)
 2433            {
 02434                if (_httpRequest.Headers.Contains("accept-language"))
 2435                {
 02436                    _httpRequest.Headers.Remove("accept-language");
 2437                }
 02438                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2439            }
 02440            if (clientRequestId != null)
 2441            {
 02442                if (_httpRequest.Headers.Contains("client-request-id"))
 2443                {
 02444                    _httpRequest.Headers.Remove("client-request-id");
 2445                }
 02446                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 2447            }
 02448            if (returnClientRequestId != null)
 2449            {
 02450                if (_httpRequest.Headers.Contains("return-client-request-id"))
 2451                {
 02452                    _httpRequest.Headers.Remove("return-client-request-id");
 2453                }
 02454                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 2455            }
 02456            if (ocpDate != null)
 2457            {
 02458                if (_httpRequest.Headers.Contains("ocp-date"))
 2459                {
 02460                    _httpRequest.Headers.Remove("ocp-date");
 2461                }
 02462                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2463            }
 2464
 2465
 02466            if (customHeaders != null)
 2467            {
 02468                foreach(var _header in customHeaders)
 2469                {
 02470                    if (_httpRequest.Headers.Contains(_header.Key))
 2471                    {
 02472                        _httpRequest.Headers.Remove(_header.Key);
 2473                    }
 02474                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2475                }
 2476            }
 2477
 2478            // Serialize Request
 02479            string _requestContent = null;
 2480            // Set Credentials
 02481            if (Client.Credentials != null)
 2482            {
 02483                cancellationToken.ThrowIfCancellationRequested();
 02484                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2485            }
 2486            // Send Request
 02487            if (_shouldTrace)
 2488            {
 02489                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2490            }
 02491            cancellationToken.ThrowIfCancellationRequested();
 02492            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02493            if (_shouldTrace)
 2494            {
 02495                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2496            }
 02497            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02498            cancellationToken.ThrowIfCancellationRequested();
 02499            string _responseContent = null;
 02500            if ((int)_statusCode != 200)
 2501            {
 02502                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2503                try
 2504                {
 02505                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02506                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02507                    if (_errorBody != null)
 2508                    {
 02509                        ex.Body = _errorBody;
 2510                    }
 02511                }
 02512                catch (JsonException)
 2513                {
 2514                    // Ignore the exception
 02515                }
 02516                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02517                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02518                if (_shouldTrace)
 2519                {
 02520                    ServiceClientTracing.Error(_invocationId, ex);
 2521                }
 02522                _httpRequest.Dispose();
 02523                if (_httpResponse != null)
 2524                {
 02525                    _httpResponse.Dispose();
 2526                }
 02527                throw ex;
 2528            }
 2529            // Create Result
 02530            var _result = new AzureOperationHeaderResponse<PoolDisableAutoScaleHeaders>();
 02531            _result.Request = _httpRequest;
 02532            _result.Response = _httpResponse;
 02533            if (_httpResponse.Headers.Contains("request-id"))
 2534            {
 02535                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2536            }
 2537            try
 2538            {
 02539                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolDisableAutoScaleHeaders>(JsonSerializer.
 02540            }
 02541            catch (JsonException ex)
 2542            {
 02543                _httpRequest.Dispose();
 02544                if (_httpResponse != null)
 2545                {
 02546                    _httpResponse.Dispose();
 2547                }
 02548                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2549            }
 02550            if (_shouldTrace)
 2551            {
 02552                ServiceClientTracing.Exit(_invocationId, _result);
 2553            }
 02554            return _result;
 02555        }
 2556
 2557        /// <summary>
 2558        /// Enables automatic scaling for a Pool.
 2559        /// </summary>
 2560        /// <remarks>
 2561        /// You cannot enable automatic scaling on a Pool if a resize operation is in
 2562        /// progress on the Pool. If automatic scaling of the Pool is currently
 2563        /// disabled, you must specify a valid autoscale formula as part of the
 2564        /// request. If automatic scaling of the Pool is already enabled, you may
 2565        /// specify a new autoscale formula and/or a new evaluation interval. You
 2566        /// cannot call this API for the same Pool more than once every 30 seconds.
 2567        /// </remarks>
 2568        /// <param name='poolId'>
 2569        /// The ID of the Pool on which to enable automatic scaling.
 2570        /// </param>
 2571        /// <param name='poolEnableAutoScaleParameter'>
 2572        /// The parameters for the request.
 2573        /// </param>
 2574        /// <param name='poolEnableAutoScaleOptions'>
 2575        /// Additional parameters for the operation
 2576        /// </param>
 2577        /// <param name='customHeaders'>
 2578        /// Headers that will be added to request.
 2579        /// </param>
 2580        /// <param name='cancellationToken'>
 2581        /// The cancellation token.
 2582        /// </param>
 2583        /// <exception cref="BatchErrorException">
 2584        /// Thrown when the operation returned an invalid status code
 2585        /// </exception>
 2586        /// <exception cref="ValidationException">
 2587        /// Thrown when a required parameter is null
 2588        /// </exception>
 2589        /// <exception cref="System.ArgumentNullException">
 2590        /// Thrown when a required parameter is null
 2591        /// </exception>
 2592        /// <return>
 2593        /// A response object containing the response body and response headers.
 2594        /// </return>
 2595        public async Task<AzureOperationHeaderResponse<PoolEnableAutoScaleHeaders>> EnableAutoScaleWithHttpMessagesAsync
 2596        {
 02597            if (Client.BatchUrl == null)
 2598            {
 02599                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 2600            }
 02601            if (poolId == null)
 2602            {
 02603                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 2604            }
 02605            if (poolEnableAutoScaleParameter == null)
 2606            {
 02607                throw new ValidationException(ValidationRules.CannotBeNull, "poolEnableAutoScaleParameter");
 2608            }
 02609            if (Client.ApiVersion == null)
 2610            {
 02611                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2612            }
 02613            int? timeout = default(int?);
 02614            if (poolEnableAutoScaleOptions != null)
 2615            {
 02616                timeout = poolEnableAutoScaleOptions.Timeout;
 2617            }
 02618            System.Guid? clientRequestId = default(System.Guid?);
 02619            if (poolEnableAutoScaleOptions != null)
 2620            {
 02621                clientRequestId = poolEnableAutoScaleOptions.ClientRequestId;
 2622            }
 02623            bool? returnClientRequestId = default(bool?);
 02624            if (poolEnableAutoScaleOptions != null)
 2625            {
 02626                returnClientRequestId = poolEnableAutoScaleOptions.ReturnClientRequestId;
 2627            }
 02628            System.DateTime? ocpDate = default(System.DateTime?);
 02629            if (poolEnableAutoScaleOptions != null)
 2630            {
 02631                ocpDate = poolEnableAutoScaleOptions.OcpDate;
 2632            }
 02633            string ifMatch = default(string);
 02634            if (poolEnableAutoScaleOptions != null)
 2635            {
 02636                ifMatch = poolEnableAutoScaleOptions.IfMatch;
 2637            }
 02638            string ifNoneMatch = default(string);
 02639            if (poolEnableAutoScaleOptions != null)
 2640            {
 02641                ifNoneMatch = poolEnableAutoScaleOptions.IfNoneMatch;
 2642            }
 02643            System.DateTime? ifModifiedSince = default(System.DateTime?);
 02644            if (poolEnableAutoScaleOptions != null)
 2645            {
 02646                ifModifiedSince = poolEnableAutoScaleOptions.IfModifiedSince;
 2647            }
 02648            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 02649            if (poolEnableAutoScaleOptions != null)
 2650            {
 02651                ifUnmodifiedSince = poolEnableAutoScaleOptions.IfUnmodifiedSince;
 2652            }
 2653            // Tracing
 02654            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02655            string _invocationId = null;
 02656            if (_shouldTrace)
 2657            {
 02658                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02659                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02660                tracingParameters.Add("poolId", poolId);
 02661                tracingParameters.Add("poolEnableAutoScaleParameter", poolEnableAutoScaleParameter);
 02662                tracingParameters.Add("timeout", timeout);
 02663                tracingParameters.Add("clientRequestId", clientRequestId);
 02664                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02665                tracingParameters.Add("ocpDate", ocpDate);
 02666                tracingParameters.Add("ifMatch", ifMatch);
 02667                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 02668                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 02669                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 02670                tracingParameters.Add("cancellationToken", cancellationToken);
 02671                ServiceClientTracing.Enter(_invocationId, this, "EnableAutoScale", tracingParameters);
 2672            }
 2673            // Construct URL
 02674            var _baseUrl = Client.BaseUri;
 02675            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/enableautoscale";
 02676            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 02677            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 02678            List<string> _queryParameters = new List<string>();
 02679            if (Client.ApiVersion != null)
 2680            {
 02681                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2682            }
 02683            if (timeout != null)
 2684            {
 02685                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 2686            }
 02687            if (_queryParameters.Count > 0)
 2688            {
 02689                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2690            }
 2691            // Create HTTP transport objects
 02692            var _httpRequest = new HttpRequestMessage();
 02693            HttpResponseMessage _httpResponse = null;
 02694            _httpRequest.Method = new HttpMethod("POST");
 02695            _httpRequest.RequestUri = new System.Uri(_url);
 2696            // Set Headers
 02697            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2698            {
 02699                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2700            }
 02701            if (Client.AcceptLanguage != null)
 2702            {
 02703                if (_httpRequest.Headers.Contains("accept-language"))
 2704                {
 02705                    _httpRequest.Headers.Remove("accept-language");
 2706                }
 02707                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2708            }
 02709            if (clientRequestId != null)
 2710            {
 02711                if (_httpRequest.Headers.Contains("client-request-id"))
 2712                {
 02713                    _httpRequest.Headers.Remove("client-request-id");
 2714                }
 02715                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 2716            }
 02717            if (returnClientRequestId != null)
 2718            {
 02719                if (_httpRequest.Headers.Contains("return-client-request-id"))
 2720                {
 02721                    _httpRequest.Headers.Remove("return-client-request-id");
 2722                }
 02723                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 2724            }
 02725            if (ocpDate != null)
 2726            {
 02727                if (_httpRequest.Headers.Contains("ocp-date"))
 2728                {
 02729                    _httpRequest.Headers.Remove("ocp-date");
 2730                }
 02731                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2732            }
 02733            if (ifMatch != null)
 2734            {
 02735                if (_httpRequest.Headers.Contains("If-Match"))
 2736                {
 02737                    _httpRequest.Headers.Remove("If-Match");
 2738                }
 02739                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 2740            }
 02741            if (ifNoneMatch != null)
 2742            {
 02743                if (_httpRequest.Headers.Contains("If-None-Match"))
 2744                {
 02745                    _httpRequest.Headers.Remove("If-None-Match");
 2746                }
 02747                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 2748            }
 02749            if (ifModifiedSince != null)
 2750            {
 02751                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 2752                {
 02753                    _httpRequest.Headers.Remove("If-Modified-Since");
 2754                }
 02755                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 2756            }
 02757            if (ifUnmodifiedSince != null)
 2758            {
 02759                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 2760                {
 02761                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 2762                }
 02763                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 2764            }
 2765
 2766
 02767            if (customHeaders != null)
 2768            {
 02769                foreach(var _header in customHeaders)
 2770                {
 02771                    if (_httpRequest.Headers.Contains(_header.Key))
 2772                    {
 02773                        _httpRequest.Headers.Remove(_header.Key);
 2774                    }
 02775                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2776                }
 2777            }
 2778
 2779            // Serialize Request
 02780            string _requestContent = null;
 02781            if(poolEnableAutoScaleParameter != null)
 2782            {
 02783                _requestContent = SafeJsonConvert.SerializeObject(poolEnableAutoScaleParameter, Client.SerializationSett
 02784                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 02785                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 2786            }
 2787            // Set Credentials
 02788            if (Client.Credentials != null)
 2789            {
 02790                cancellationToken.ThrowIfCancellationRequested();
 02791                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2792            }
 2793            // Send Request
 02794            if (_shouldTrace)
 2795            {
 02796                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2797            }
 02798            cancellationToken.ThrowIfCancellationRequested();
 02799            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02800            if (_shouldTrace)
 2801            {
 02802                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2803            }
 02804            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02805            cancellationToken.ThrowIfCancellationRequested();
 02806            string _responseContent = null;
 02807            if ((int)_statusCode != 200)
 2808            {
 02809                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2810                try
 2811                {
 02812                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02813                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02814                    if (_errorBody != null)
 2815                    {
 02816                        ex.Body = _errorBody;
 2817                    }
 02818                }
 02819                catch (JsonException)
 2820                {
 2821                    // Ignore the exception
 02822                }
 02823                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02824                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02825                if (_shouldTrace)
 2826                {
 02827                    ServiceClientTracing.Error(_invocationId, ex);
 2828                }
 02829                _httpRequest.Dispose();
 02830                if (_httpResponse != null)
 2831                {
 02832                    _httpResponse.Dispose();
 2833                }
 02834                throw ex;
 2835            }
 2836            // Create Result
 02837            var _result = new AzureOperationHeaderResponse<PoolEnableAutoScaleHeaders>();
 02838            _result.Request = _httpRequest;
 02839            _result.Response = _httpResponse;
 02840            if (_httpResponse.Headers.Contains("request-id"))
 2841            {
 02842                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2843            }
 2844            try
 2845            {
 02846                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolEnableAutoScaleHeaders>(JsonSerializer.C
 02847            }
 02848            catch (JsonException ex)
 2849            {
 02850                _httpRequest.Dispose();
 02851                if (_httpResponse != null)
 2852                {
 02853                    _httpResponse.Dispose();
 2854                }
 02855                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2856            }
 02857            if (_shouldTrace)
 2858            {
 02859                ServiceClientTracing.Exit(_invocationId, _result);
 2860            }
 02861            return _result;
 02862        }
 2863
 2864        /// <summary>
 2865        /// Gets the result of evaluating an automatic scaling formula on the Pool.
 2866        /// </summary>
 2867        /// <remarks>
 2868        /// This API is primarily for validating an autoscale formula, as it simply
 2869        /// returns the result without applying the formula to the Pool. The Pool must
 2870        /// have auto scaling enabled in order to evaluate a formula.
 2871        /// </remarks>
 2872        /// <param name='poolId'>
 2873        /// The ID of the Pool on which to evaluate the automatic scaling formula.
 2874        /// </param>
 2875        /// <param name='autoScaleFormula'>
 2876        /// The formula for the desired number of Compute Nodes in the Pool. The
 2877        /// formula is validated and its results calculated, but it is not applied to
 2878        /// the Pool. To apply the formula to the Pool, 'Enable automatic scaling on a
 2879        /// Pool'. For more information about specifying this formula, see
 2880        /// Automatically scale Compute Nodes in an Azure Batch Pool
 2881        /// (https://azure.microsoft.com/en-us/documentation/articles/batch-automatic-scaling).
 2882        /// </param>
 2883        /// <param name='poolEvaluateAutoScaleOptions'>
 2884        /// Additional parameters for the operation
 2885        /// </param>
 2886        /// <param name='customHeaders'>
 2887        /// Headers that will be added to request.
 2888        /// </param>
 2889        /// <param name='cancellationToken'>
 2890        /// The cancellation token.
 2891        /// </param>
 2892        /// <exception cref="BatchErrorException">
 2893        /// Thrown when the operation returned an invalid status code
 2894        /// </exception>
 2895        /// <exception cref="SerializationException">
 2896        /// Thrown when unable to deserialize the response
 2897        /// </exception>
 2898        /// <exception cref="ValidationException">
 2899        /// Thrown when a required parameter is null
 2900        /// </exception>
 2901        /// <exception cref="System.ArgumentNullException">
 2902        /// Thrown when a required parameter is null
 2903        /// </exception>
 2904        /// <return>
 2905        /// A response object containing the response body and response headers.
 2906        /// </return>
 2907        public async Task<AzureOperationResponse<AutoScaleRun,PoolEvaluateAutoScaleHeaders>> EvaluateAutoScaleWithHttpMe
 2908        {
 02909            if (Client.BatchUrl == null)
 2910            {
 02911                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 2912            }
 02913            if (poolId == null)
 2914            {
 02915                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 2916            }
 02917            if (Client.ApiVersion == null)
 2918            {
 02919                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2920            }
 02921            if (autoScaleFormula == null)
 2922            {
 02923                throw new ValidationException(ValidationRules.CannotBeNull, "autoScaleFormula");
 2924            }
 02925            int? timeout = default(int?);
 02926            if (poolEvaluateAutoScaleOptions != null)
 2927            {
 02928                timeout = poolEvaluateAutoScaleOptions.Timeout;
 2929            }
 02930            System.Guid? clientRequestId = default(System.Guid?);
 02931            if (poolEvaluateAutoScaleOptions != null)
 2932            {
 02933                clientRequestId = poolEvaluateAutoScaleOptions.ClientRequestId;
 2934            }
 02935            bool? returnClientRequestId = default(bool?);
 02936            if (poolEvaluateAutoScaleOptions != null)
 2937            {
 02938                returnClientRequestId = poolEvaluateAutoScaleOptions.ReturnClientRequestId;
 2939            }
 02940            System.DateTime? ocpDate = default(System.DateTime?);
 02941            if (poolEvaluateAutoScaleOptions != null)
 2942            {
 02943                ocpDate = poolEvaluateAutoScaleOptions.OcpDate;
 2944            }
 02945            PoolEvaluateAutoScaleParameter poolEvaluateAutoScaleParameter = new PoolEvaluateAutoScaleParameter();
 02946            if (autoScaleFormula != null)
 2947            {
 02948                poolEvaluateAutoScaleParameter.AutoScaleFormula = autoScaleFormula;
 2949            }
 2950            // Tracing
 02951            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02952            string _invocationId = null;
 02953            if (_shouldTrace)
 2954            {
 02955                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02956                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02957                tracingParameters.Add("poolId", poolId);
 02958                tracingParameters.Add("timeout", timeout);
 02959                tracingParameters.Add("clientRequestId", clientRequestId);
 02960                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02961                tracingParameters.Add("ocpDate", ocpDate);
 02962                tracingParameters.Add("poolEvaluateAutoScaleParameter", poolEvaluateAutoScaleParameter);
 02963                tracingParameters.Add("cancellationToken", cancellationToken);
 02964                ServiceClientTracing.Enter(_invocationId, this, "EvaluateAutoScale", tracingParameters);
 2965            }
 2966            // Construct URL
 02967            var _baseUrl = Client.BaseUri;
 02968            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/evaluateautoscale";
 02969            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 02970            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 02971            List<string> _queryParameters = new List<string>();
 02972            if (Client.ApiVersion != null)
 2973            {
 02974                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2975            }
 02976            if (timeout != null)
 2977            {
 02978                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 2979            }
 02980            if (_queryParameters.Count > 0)
 2981            {
 02982                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2983            }
 2984            // Create HTTP transport objects
 02985            var _httpRequest = new HttpRequestMessage();
 02986            HttpResponseMessage _httpResponse = null;
 02987            _httpRequest.Method = new HttpMethod("POST");
 02988            _httpRequest.RequestUri = new System.Uri(_url);
 2989            // Set Headers
 02990            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2991            {
 02992                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2993            }
 02994            if (Client.AcceptLanguage != null)
 2995            {
 02996                if (_httpRequest.Headers.Contains("accept-language"))
 2997                {
 02998                    _httpRequest.Headers.Remove("accept-language");
 2999                }
 03000                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3001            }
 03002            if (clientRequestId != null)
 3003            {
 03004                if (_httpRequest.Headers.Contains("client-request-id"))
 3005                {
 03006                    _httpRequest.Headers.Remove("client-request-id");
 3007                }
 03008                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 3009            }
 03010            if (returnClientRequestId != null)
 3011            {
 03012                if (_httpRequest.Headers.Contains("return-client-request-id"))
 3013                {
 03014                    _httpRequest.Headers.Remove("return-client-request-id");
 3015                }
 03016                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 3017            }
 03018            if (ocpDate != null)
 3019            {
 03020                if (_httpRequest.Headers.Contains("ocp-date"))
 3021                {
 03022                    _httpRequest.Headers.Remove("ocp-date");
 3023                }
 03024                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 3025            }
 3026
 3027
 03028            if (customHeaders != null)
 3029            {
 03030                foreach(var _header in customHeaders)
 3031                {
 03032                    if (_httpRequest.Headers.Contains(_header.Key))
 3033                    {
 03034                        _httpRequest.Headers.Remove(_header.Key);
 3035                    }
 03036                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3037                }
 3038            }
 3039
 3040            // Serialize Request
 03041            string _requestContent = null;
 03042            if(poolEvaluateAutoScaleParameter != null)
 3043            {
 03044                _requestContent = SafeJsonConvert.SerializeObject(poolEvaluateAutoScaleParameter, Client.SerializationSe
 03045                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 03046                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3047            }
 3048            // Set Credentials
 03049            if (Client.Credentials != null)
 3050            {
 03051                cancellationToken.ThrowIfCancellationRequested();
 03052                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3053            }
 3054            // Send Request
 03055            if (_shouldTrace)
 3056            {
 03057                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3058            }
 03059            cancellationToken.ThrowIfCancellationRequested();
 03060            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03061            if (_shouldTrace)
 3062            {
 03063                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3064            }
 03065            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03066            cancellationToken.ThrowIfCancellationRequested();
 03067            string _responseContent = null;
 03068            if ((int)_statusCode != 200)
 3069            {
 03070                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 3071                try
 3072                {
 03073                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03074                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 03075                    if (_errorBody != null)
 3076                    {
 03077                        ex.Body = _errorBody;
 3078                    }
 03079                }
 03080                catch (JsonException)
 3081                {
 3082                    // Ignore the exception
 03083                }
 03084                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03085                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03086                if (_shouldTrace)
 3087                {
 03088                    ServiceClientTracing.Error(_invocationId, ex);
 3089                }
 03090                _httpRequest.Dispose();
 03091                if (_httpResponse != null)
 3092                {
 03093                    _httpResponse.Dispose();
 3094                }
 03095                throw ex;
 3096            }
 3097            // Create Result
 03098            var _result = new AzureOperationResponse<AutoScaleRun,PoolEvaluateAutoScaleHeaders>();
 03099            _result.Request = _httpRequest;
 03100            _result.Response = _httpResponse;
 03101            if (_httpResponse.Headers.Contains("request-id"))
 3102            {
 03103                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 3104            }
 3105            // Deserialize Response
 03106            if ((int)_statusCode == 200)
 3107            {
 03108                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 3109                try
 3110                {
 03111                    _result.Body = SafeJsonConvert.DeserializeObject<AutoScaleRun>(_responseContent, Client.Deserializat
 03112                }
 03113                catch (JsonException ex)
 3114                {
 03115                    _httpRequest.Dispose();
 03116                    if (_httpResponse != null)
 3117                    {
 03118                        _httpResponse.Dispose();
 3119                    }
 03120                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 3121                }
 3122            }
 3123            try
 3124            {
 03125                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolEvaluateAutoScaleHeaders>(JsonSerializer
 03126            }
 03127            catch (JsonException ex)
 3128            {
 03129                _httpRequest.Dispose();
 03130                if (_httpResponse != null)
 3131                {
 03132                    _httpResponse.Dispose();
 3133                }
 03134                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 3135            }
 03136            if (_shouldTrace)
 3137            {
 03138                ServiceClientTracing.Exit(_invocationId, _result);
 3139            }
 03140            return _result;
 03141        }
 3142
 3143        /// <summary>
 3144        /// Changes the number of Compute Nodes that are assigned to a Pool.
 3145        /// </summary>
 3146        /// <remarks>
 3147        /// You can only resize a Pool when its allocation state is steady. If the Pool
 3148        /// is already resizing, the request fails with status code 409. When you
 3149        /// resize a Pool, the Pool's allocation state changes from steady to resizing.
 3150        /// You cannot resize Pools which are configured for automatic scaling. If you
 3151        /// try to do this, the Batch service returns an error 409. If you resize a
 3152        /// Pool downwards, the Batch service chooses which Compute Nodes to remove. To
 3153        /// remove specific Compute Nodes, use the Pool remove Compute Nodes API
 3154        /// instead.
 3155        /// </remarks>
 3156        /// <param name='poolId'>
 3157        /// The ID of the Pool to resize.
 3158        /// </param>
 3159        /// <param name='poolResizeParameter'>
 3160        /// The parameters for the request.
 3161        /// </param>
 3162        /// <param name='poolResizeOptions'>
 3163        /// Additional parameters for the operation
 3164        /// </param>
 3165        /// <param name='customHeaders'>
 3166        /// Headers that will be added to request.
 3167        /// </param>
 3168        /// <param name='cancellationToken'>
 3169        /// The cancellation token.
 3170        /// </param>
 3171        /// <exception cref="BatchErrorException">
 3172        /// Thrown when the operation returned an invalid status code
 3173        /// </exception>
 3174        /// <exception cref="ValidationException">
 3175        /// Thrown when a required parameter is null
 3176        /// </exception>
 3177        /// <exception cref="System.ArgumentNullException">
 3178        /// Thrown when a required parameter is null
 3179        /// </exception>
 3180        /// <return>
 3181        /// A response object containing the response body and response headers.
 3182        /// </return>
 3183        public async Task<AzureOperationHeaderResponse<PoolResizeHeaders>> ResizeWithHttpMessagesAsync(string poolId, Po
 3184        {
 03185            if (Client.BatchUrl == null)
 3186            {
 03187                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 3188            }
 03189            if (poolId == null)
 3190            {
 03191                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 3192            }
 03193            if (poolResizeParameter == null)
 3194            {
 03195                throw new ValidationException(ValidationRules.CannotBeNull, "poolResizeParameter");
 3196            }
 03197            if (Client.ApiVersion == null)
 3198            {
 03199                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 3200            }
 03201            int? timeout = default(int?);
 03202            if (poolResizeOptions != null)
 3203            {
 03204                timeout = poolResizeOptions.Timeout;
 3205            }
 03206            System.Guid? clientRequestId = default(System.Guid?);
 03207            if (poolResizeOptions != null)
 3208            {
 03209                clientRequestId = poolResizeOptions.ClientRequestId;
 3210            }
 03211            bool? returnClientRequestId = default(bool?);
 03212            if (poolResizeOptions != null)
 3213            {
 03214                returnClientRequestId = poolResizeOptions.ReturnClientRequestId;
 3215            }
 03216            System.DateTime? ocpDate = default(System.DateTime?);
 03217            if (poolResizeOptions != null)
 3218            {
 03219                ocpDate = poolResizeOptions.OcpDate;
 3220            }
 03221            string ifMatch = default(string);
 03222            if (poolResizeOptions != null)
 3223            {
 03224                ifMatch = poolResizeOptions.IfMatch;
 3225            }
 03226            string ifNoneMatch = default(string);
 03227            if (poolResizeOptions != null)
 3228            {
 03229                ifNoneMatch = poolResizeOptions.IfNoneMatch;
 3230            }
 03231            System.DateTime? ifModifiedSince = default(System.DateTime?);
 03232            if (poolResizeOptions != null)
 3233            {
 03234                ifModifiedSince = poolResizeOptions.IfModifiedSince;
 3235            }
 03236            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 03237            if (poolResizeOptions != null)
 3238            {
 03239                ifUnmodifiedSince = poolResizeOptions.IfUnmodifiedSince;
 3240            }
 3241            // Tracing
 03242            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03243            string _invocationId = null;
 03244            if (_shouldTrace)
 3245            {
 03246                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03247                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03248                tracingParameters.Add("poolId", poolId);
 03249                tracingParameters.Add("poolResizeParameter", poolResizeParameter);
 03250                tracingParameters.Add("timeout", timeout);
 03251                tracingParameters.Add("clientRequestId", clientRequestId);
 03252                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 03253                tracingParameters.Add("ocpDate", ocpDate);
 03254                tracingParameters.Add("ifMatch", ifMatch);
 03255                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 03256                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 03257                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 03258                tracingParameters.Add("cancellationToken", cancellationToken);
 03259                ServiceClientTracing.Enter(_invocationId, this, "Resize", tracingParameters);
 3260            }
 3261            // Construct URL
 03262            var _baseUrl = Client.BaseUri;
 03263            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/resize";
 03264            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 03265            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 03266            List<string> _queryParameters = new List<string>();
 03267            if (Client.ApiVersion != null)
 3268            {
 03269                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 3270            }
 03271            if (timeout != null)
 3272            {
 03273                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 3274            }
 03275            if (_queryParameters.Count > 0)
 3276            {
 03277                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3278            }
 3279            // Create HTTP transport objects
 03280            var _httpRequest = new HttpRequestMessage();
 03281            HttpResponseMessage _httpResponse = null;
 03282            _httpRequest.Method = new HttpMethod("POST");
 03283            _httpRequest.RequestUri = new System.Uri(_url);
 3284            // Set Headers
 03285            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3286            {
 03287                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 3288            }
 03289            if (Client.AcceptLanguage != null)
 3290            {
 03291                if (_httpRequest.Headers.Contains("accept-language"))
 3292                {
 03293                    _httpRequest.Headers.Remove("accept-language");
 3294                }
 03295                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3296            }
 03297            if (clientRequestId != null)
 3298            {
 03299                if (_httpRequest.Headers.Contains("client-request-id"))
 3300                {
 03301                    _httpRequest.Headers.Remove("client-request-id");
 3302                }
 03303                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 3304            }
 03305            if (returnClientRequestId != null)
 3306            {
 03307                if (_httpRequest.Headers.Contains("return-client-request-id"))
 3308                {
 03309                    _httpRequest.Headers.Remove("return-client-request-id");
 3310                }
 03311                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 3312            }
 03313            if (ocpDate != null)
 3314            {
 03315                if (_httpRequest.Headers.Contains("ocp-date"))
 3316                {
 03317                    _httpRequest.Headers.Remove("ocp-date");
 3318                }
 03319                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 3320            }
 03321            if (ifMatch != null)
 3322            {
 03323                if (_httpRequest.Headers.Contains("If-Match"))
 3324                {
 03325                    _httpRequest.Headers.Remove("If-Match");
 3326                }
 03327                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 3328            }
 03329            if (ifNoneMatch != null)
 3330            {
 03331                if (_httpRequest.Headers.Contains("If-None-Match"))
 3332                {
 03333                    _httpRequest.Headers.Remove("If-None-Match");
 3334                }
 03335                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 3336            }
 03337            if (ifModifiedSince != null)
 3338            {
 03339                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 3340                {
 03341                    _httpRequest.Headers.Remove("If-Modified-Since");
 3342                }
 03343                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 3344            }
 03345            if (ifUnmodifiedSince != null)
 3346            {
 03347                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 3348                {
 03349                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 3350                }
 03351                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 3352            }
 3353
 3354
 03355            if (customHeaders != null)
 3356            {
 03357                foreach(var _header in customHeaders)
 3358                {
 03359                    if (_httpRequest.Headers.Contains(_header.Key))
 3360                    {
 03361                        _httpRequest.Headers.Remove(_header.Key);
 3362                    }
 03363                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3364                }
 3365            }
 3366
 3367            // Serialize Request
 03368            string _requestContent = null;
 03369            if(poolResizeParameter != null)
 3370            {
 03371                _requestContent = SafeJsonConvert.SerializeObject(poolResizeParameter, Client.SerializationSettings);
 03372                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 03373                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3374            }
 3375            // Set Credentials
 03376            if (Client.Credentials != null)
 3377            {
 03378                cancellationToken.ThrowIfCancellationRequested();
 03379                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3380            }
 3381            // Send Request
 03382            if (_shouldTrace)
 3383            {
 03384                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3385            }
 03386            cancellationToken.ThrowIfCancellationRequested();
 03387            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03388            if (_shouldTrace)
 3389            {
 03390                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3391            }
 03392            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03393            cancellationToken.ThrowIfCancellationRequested();
 03394            string _responseContent = null;
 03395            if ((int)_statusCode != 202)
 3396            {
 03397                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 3398                try
 3399                {
 03400                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03401                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 03402                    if (_errorBody != null)
 3403                    {
 03404                        ex.Body = _errorBody;
 3405                    }
 03406                }
 03407                catch (JsonException)
 3408                {
 3409                    // Ignore the exception
 03410                }
 03411                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03412                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03413                if (_shouldTrace)
 3414                {
 03415                    ServiceClientTracing.Error(_invocationId, ex);
 3416                }
 03417                _httpRequest.Dispose();
 03418                if (_httpResponse != null)
 3419                {
 03420                    _httpResponse.Dispose();
 3421                }
 03422                throw ex;
 3423            }
 3424            // Create Result
 03425            var _result = new AzureOperationHeaderResponse<PoolResizeHeaders>();
 03426            _result.Request = _httpRequest;
 03427            _result.Response = _httpResponse;
 03428            if (_httpResponse.Headers.Contains("request-id"))
 3429            {
 03430                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 3431            }
 3432            try
 3433            {
 03434                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolResizeHeaders>(JsonSerializer.Create(Cli
 03435            }
 03436            catch (JsonException ex)
 3437            {
 03438                _httpRequest.Dispose();
 03439                if (_httpResponse != null)
 3440                {
 03441                    _httpResponse.Dispose();
 3442                }
 03443                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 3444            }
 03445            if (_shouldTrace)
 3446            {
 03447                ServiceClientTracing.Exit(_invocationId, _result);
 3448            }
 03449            return _result;
 03450        }
 3451
 3452        /// <summary>
 3453        /// Stops an ongoing resize operation on the Pool.
 3454        /// </summary>
 3455        /// <remarks>
 3456        /// This does not restore the Pool to its previous state before the resize
 3457        /// operation: it only stops any further changes being made, and the Pool
 3458        /// maintains its current state. After stopping, the Pool stabilizes at the
 3459        /// number of Compute Nodes it was at when the stop operation was done. During
 3460        /// the stop operation, the Pool allocation state changes first to stopping and
 3461        /// then to steady. A resize operation need not be an explicit resize Pool
 3462        /// request; this API can also be used to halt the initial sizing of the Pool
 3463        /// when it is created.
 3464        /// </remarks>
 3465        /// <param name='poolId'>
 3466        /// The ID of the Pool whose resizing you want to stop.
 3467        /// </param>
 3468        /// <param name='poolStopResizeOptions'>
 3469        /// Additional parameters for the operation
 3470        /// </param>
 3471        /// <param name='customHeaders'>
 3472        /// Headers that will be added to request.
 3473        /// </param>
 3474        /// <param name='cancellationToken'>
 3475        /// The cancellation token.
 3476        /// </param>
 3477        /// <exception cref="BatchErrorException">
 3478        /// Thrown when the operation returned an invalid status code
 3479        /// </exception>
 3480        /// <exception cref="ValidationException">
 3481        /// Thrown when a required parameter is null
 3482        /// </exception>
 3483        /// <exception cref="System.ArgumentNullException">
 3484        /// Thrown when a required parameter is null
 3485        /// </exception>
 3486        /// <return>
 3487        /// A response object containing the response body and response headers.
 3488        /// </return>
 3489        public async Task<AzureOperationHeaderResponse<PoolStopResizeHeaders>> StopResizeWithHttpMessagesAsync(string po
 3490        {
 03491            if (Client.BatchUrl == null)
 3492            {
 03493                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 3494            }
 03495            if (poolId == null)
 3496            {
 03497                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 3498            }
 03499            if (Client.ApiVersion == null)
 3500            {
 03501                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 3502            }
 03503            int? timeout = default(int?);
 03504            if (poolStopResizeOptions != null)
 3505            {
 03506                timeout = poolStopResizeOptions.Timeout;
 3507            }
 03508            System.Guid? clientRequestId = default(System.Guid?);
 03509            if (poolStopResizeOptions != null)
 3510            {
 03511                clientRequestId = poolStopResizeOptions.ClientRequestId;
 3512            }
 03513            bool? returnClientRequestId = default(bool?);
 03514            if (poolStopResizeOptions != null)
 3515            {
 03516                returnClientRequestId = poolStopResizeOptions.ReturnClientRequestId;
 3517            }
 03518            System.DateTime? ocpDate = default(System.DateTime?);
 03519            if (poolStopResizeOptions != null)
 3520            {
 03521                ocpDate = poolStopResizeOptions.OcpDate;
 3522            }
 03523            string ifMatch = default(string);
 03524            if (poolStopResizeOptions != null)
 3525            {
 03526                ifMatch = poolStopResizeOptions.IfMatch;
 3527            }
 03528            string ifNoneMatch = default(string);
 03529            if (poolStopResizeOptions != null)
 3530            {
 03531                ifNoneMatch = poolStopResizeOptions.IfNoneMatch;
 3532            }
 03533            System.DateTime? ifModifiedSince = default(System.DateTime?);
 03534            if (poolStopResizeOptions != null)
 3535            {
 03536                ifModifiedSince = poolStopResizeOptions.IfModifiedSince;
 3537            }
 03538            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 03539            if (poolStopResizeOptions != null)
 3540            {
 03541                ifUnmodifiedSince = poolStopResizeOptions.IfUnmodifiedSince;
 3542            }
 3543            // Tracing
 03544            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03545            string _invocationId = null;
 03546            if (_shouldTrace)
 3547            {
 03548                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03549                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03550                tracingParameters.Add("poolId", poolId);
 03551                tracingParameters.Add("timeout", timeout);
 03552                tracingParameters.Add("clientRequestId", clientRequestId);
 03553                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 03554                tracingParameters.Add("ocpDate", ocpDate);
 03555                tracingParameters.Add("ifMatch", ifMatch);
 03556                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 03557                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 03558                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 03559                tracingParameters.Add("cancellationToken", cancellationToken);
 03560                ServiceClientTracing.Enter(_invocationId, this, "StopResize", tracingParameters);
 3561            }
 3562            // Construct URL
 03563            var _baseUrl = Client.BaseUri;
 03564            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/stopresize";
 03565            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 03566            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 03567            List<string> _queryParameters = new List<string>();
 03568            if (Client.ApiVersion != null)
 3569            {
 03570                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 3571            }
 03572            if (timeout != null)
 3573            {
 03574                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 3575            }
 03576            if (_queryParameters.Count > 0)
 3577            {
 03578                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3579            }
 3580            // Create HTTP transport objects
 03581            var _httpRequest = new HttpRequestMessage();
 03582            HttpResponseMessage _httpResponse = null;
 03583            _httpRequest.Method = new HttpMethod("POST");
 03584            _httpRequest.RequestUri = new System.Uri(_url);
 3585            // Set Headers
 03586            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3587            {
 03588                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 3589            }
 03590            if (Client.AcceptLanguage != null)
 3591            {
 03592                if (_httpRequest.Headers.Contains("accept-language"))
 3593                {
 03594                    _httpRequest.Headers.Remove("accept-language");
 3595                }
 03596                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3597            }
 03598            if (clientRequestId != null)
 3599            {
 03600                if (_httpRequest.Headers.Contains("client-request-id"))
 3601                {
 03602                    _httpRequest.Headers.Remove("client-request-id");
 3603                }
 03604                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 3605            }
 03606            if (returnClientRequestId != null)
 3607            {
 03608                if (_httpRequest.Headers.Contains("return-client-request-id"))
 3609                {
 03610                    _httpRequest.Headers.Remove("return-client-request-id");
 3611                }
 03612                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 3613            }
 03614            if (ocpDate != null)
 3615            {
 03616                if (_httpRequest.Headers.Contains("ocp-date"))
 3617                {
 03618                    _httpRequest.Headers.Remove("ocp-date");
 3619                }
 03620                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 3621            }
 03622            if (ifMatch != null)
 3623            {
 03624                if (_httpRequest.Headers.Contains("If-Match"))
 3625                {
 03626                    _httpRequest.Headers.Remove("If-Match");
 3627                }
 03628                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 3629            }
 03630            if (ifNoneMatch != null)
 3631            {
 03632                if (_httpRequest.Headers.Contains("If-None-Match"))
 3633                {
 03634                    _httpRequest.Headers.Remove("If-None-Match");
 3635                }
 03636                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 3637            }
 03638            if (ifModifiedSince != null)
 3639            {
 03640                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 3641                {
 03642                    _httpRequest.Headers.Remove("If-Modified-Since");
 3643                }
 03644                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 3645            }
 03646            if (ifUnmodifiedSince != null)
 3647            {
 03648                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 3649                {
 03650                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 3651                }
 03652                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 3653            }
 3654
 3655
 03656            if (customHeaders != null)
 3657            {
 03658                foreach(var _header in customHeaders)
 3659                {
 03660                    if (_httpRequest.Headers.Contains(_header.Key))
 3661                    {
 03662                        _httpRequest.Headers.Remove(_header.Key);
 3663                    }
 03664                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3665                }
 3666            }
 3667
 3668            // Serialize Request
 03669            string _requestContent = null;
 3670            // Set Credentials
 03671            if (Client.Credentials != null)
 3672            {
 03673                cancellationToken.ThrowIfCancellationRequested();
 03674                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3675            }
 3676            // Send Request
 03677            if (_shouldTrace)
 3678            {
 03679                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3680            }
 03681            cancellationToken.ThrowIfCancellationRequested();
 03682            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03683            if (_shouldTrace)
 3684            {
 03685                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3686            }
 03687            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03688            cancellationToken.ThrowIfCancellationRequested();
 03689            string _responseContent = null;
 03690            if ((int)_statusCode != 202)
 3691            {
 03692                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 3693                try
 3694                {
 03695                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03696                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 03697                    if (_errorBody != null)
 3698                    {
 03699                        ex.Body = _errorBody;
 3700                    }
 03701                }
 03702                catch (JsonException)
 3703                {
 3704                    // Ignore the exception
 03705                }
 03706                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03707                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03708                if (_shouldTrace)
 3709                {
 03710                    ServiceClientTracing.Error(_invocationId, ex);
 3711                }
 03712                _httpRequest.Dispose();
 03713                if (_httpResponse != null)
 3714                {
 03715                    _httpResponse.Dispose();
 3716                }
 03717                throw ex;
 3718            }
 3719            // Create Result
 03720            var _result = new AzureOperationHeaderResponse<PoolStopResizeHeaders>();
 03721            _result.Request = _httpRequest;
 03722            _result.Response = _httpResponse;
 03723            if (_httpResponse.Headers.Contains("request-id"))
 3724            {
 03725                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 3726            }
 3727            try
 3728            {
 03729                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolStopResizeHeaders>(JsonSerializer.Create
 03730            }
 03731            catch (JsonException ex)
 3732            {
 03733                _httpRequest.Dispose();
 03734                if (_httpResponse != null)
 3735                {
 03736                    _httpResponse.Dispose();
 3737                }
 03738                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 3739            }
 03740            if (_shouldTrace)
 3741            {
 03742                ServiceClientTracing.Exit(_invocationId, _result);
 3743            }
 03744            return _result;
 03745        }
 3746
 3747        /// <summary>
 3748        /// Updates the properties of the specified Pool.
 3749        /// </summary>
 3750        /// <remarks>
 3751        /// This fully replaces all the updatable properties of the Pool. For example,
 3752        /// if the Pool has a StartTask associated with it and if StartTask is not
 3753        /// specified with this request, then the Batch service will remove the
 3754        /// existing StartTask.
 3755        /// </remarks>
 3756        /// <param name='poolId'>
 3757        /// The ID of the Pool to update.
 3758        /// </param>
 3759        /// <param name='poolUpdatePropertiesParameter'>
 3760        /// The parameters for the request.
 3761        /// </param>
 3762        /// <param name='poolUpdatePropertiesOptions'>
 3763        /// Additional parameters for the operation
 3764        /// </param>
 3765        /// <param name='customHeaders'>
 3766        /// Headers that will be added to request.
 3767        /// </param>
 3768        /// <param name='cancellationToken'>
 3769        /// The cancellation token.
 3770        /// </param>
 3771        /// <exception cref="BatchErrorException">
 3772        /// Thrown when the operation returned an invalid status code
 3773        /// </exception>
 3774        /// <exception cref="ValidationException">
 3775        /// Thrown when a required parameter is null
 3776        /// </exception>
 3777        /// <exception cref="System.ArgumentNullException">
 3778        /// Thrown when a required parameter is null
 3779        /// </exception>
 3780        /// <return>
 3781        /// A response object containing the response body and response headers.
 3782        /// </return>
 3783        public async Task<AzureOperationHeaderResponse<PoolUpdatePropertiesHeaders>> UpdatePropertiesWithHttpMessagesAsy
 3784        {
 03785            if (Client.BatchUrl == null)
 3786            {
 03787                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 3788            }
 03789            if (poolId == null)
 3790            {
 03791                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 3792            }
 03793            if (poolUpdatePropertiesParameter == null)
 3794            {
 03795                throw new ValidationException(ValidationRules.CannotBeNull, "poolUpdatePropertiesParameter");
 3796            }
 03797            if (Client.ApiVersion == null)
 3798            {
 03799                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 3800            }
 03801            int? timeout = default(int?);
 03802            if (poolUpdatePropertiesOptions != null)
 3803            {
 03804                timeout = poolUpdatePropertiesOptions.Timeout;
 3805            }
 03806            System.Guid? clientRequestId = default(System.Guid?);
 03807            if (poolUpdatePropertiesOptions != null)
 3808            {
 03809                clientRequestId = poolUpdatePropertiesOptions.ClientRequestId;
 3810            }
 03811            bool? returnClientRequestId = default(bool?);
 03812            if (poolUpdatePropertiesOptions != null)
 3813            {
 03814                returnClientRequestId = poolUpdatePropertiesOptions.ReturnClientRequestId;
 3815            }
 03816            System.DateTime? ocpDate = default(System.DateTime?);
 03817            if (poolUpdatePropertiesOptions != null)
 3818            {
 03819                ocpDate = poolUpdatePropertiesOptions.OcpDate;
 3820            }
 3821            // Tracing
 03822            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 03823            string _invocationId = null;
 03824            if (_shouldTrace)
 3825            {
 03826                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 03827                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 03828                tracingParameters.Add("poolId", poolId);
 03829                tracingParameters.Add("poolUpdatePropertiesParameter", poolUpdatePropertiesParameter);
 03830                tracingParameters.Add("timeout", timeout);
 03831                tracingParameters.Add("clientRequestId", clientRequestId);
 03832                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 03833                tracingParameters.Add("ocpDate", ocpDate);
 03834                tracingParameters.Add("cancellationToken", cancellationToken);
 03835                ServiceClientTracing.Enter(_invocationId, this, "UpdateProperties", tracingParameters);
 3836            }
 3837            // Construct URL
 03838            var _baseUrl = Client.BaseUri;
 03839            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/updateproperties";
 03840            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 03841            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 03842            List<string> _queryParameters = new List<string>();
 03843            if (Client.ApiVersion != null)
 3844            {
 03845                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 3846            }
 03847            if (timeout != null)
 3848            {
 03849                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 3850            }
 03851            if (_queryParameters.Count > 0)
 3852            {
 03853                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 3854            }
 3855            // Create HTTP transport objects
 03856            var _httpRequest = new HttpRequestMessage();
 03857            HttpResponseMessage _httpResponse = null;
 03858            _httpRequest.Method = new HttpMethod("POST");
 03859            _httpRequest.RequestUri = new System.Uri(_url);
 3860            // Set Headers
 03861            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 3862            {
 03863                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 3864            }
 03865            if (Client.AcceptLanguage != null)
 3866            {
 03867                if (_httpRequest.Headers.Contains("accept-language"))
 3868                {
 03869                    _httpRequest.Headers.Remove("accept-language");
 3870                }
 03871                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 3872            }
 03873            if (clientRequestId != null)
 3874            {
 03875                if (_httpRequest.Headers.Contains("client-request-id"))
 3876                {
 03877                    _httpRequest.Headers.Remove("client-request-id");
 3878                }
 03879                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 3880            }
 03881            if (returnClientRequestId != null)
 3882            {
 03883                if (_httpRequest.Headers.Contains("return-client-request-id"))
 3884                {
 03885                    _httpRequest.Headers.Remove("return-client-request-id");
 3886                }
 03887                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 3888            }
 03889            if (ocpDate != null)
 3890            {
 03891                if (_httpRequest.Headers.Contains("ocp-date"))
 3892                {
 03893                    _httpRequest.Headers.Remove("ocp-date");
 3894                }
 03895                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 3896            }
 3897
 3898
 03899            if (customHeaders != null)
 3900            {
 03901                foreach(var _header in customHeaders)
 3902                {
 03903                    if (_httpRequest.Headers.Contains(_header.Key))
 3904                    {
 03905                        _httpRequest.Headers.Remove(_header.Key);
 3906                    }
 03907                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 3908                }
 3909            }
 3910
 3911            // Serialize Request
 03912            string _requestContent = null;
 03913            if(poolUpdatePropertiesParameter != null)
 3914            {
 03915                _requestContent = SafeJsonConvert.SerializeObject(poolUpdatePropertiesParameter, Client.SerializationSet
 03916                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 03917                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 3918            }
 3919            // Set Credentials
 03920            if (Client.Credentials != null)
 3921            {
 03922                cancellationToken.ThrowIfCancellationRequested();
 03923                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 3924            }
 3925            // Send Request
 03926            if (_shouldTrace)
 3927            {
 03928                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 3929            }
 03930            cancellationToken.ThrowIfCancellationRequested();
 03931            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 03932            if (_shouldTrace)
 3933            {
 03934                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 3935            }
 03936            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 03937            cancellationToken.ThrowIfCancellationRequested();
 03938            string _responseContent = null;
 03939            if ((int)_statusCode != 204)
 3940            {
 03941                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 3942                try
 3943                {
 03944                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 03945                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 03946                    if (_errorBody != null)
 3947                    {
 03948                        ex.Body = _errorBody;
 3949                    }
 03950                }
 03951                catch (JsonException)
 3952                {
 3953                    // Ignore the exception
 03954                }
 03955                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 03956                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 03957                if (_shouldTrace)
 3958                {
 03959                    ServiceClientTracing.Error(_invocationId, ex);
 3960                }
 03961                _httpRequest.Dispose();
 03962                if (_httpResponse != null)
 3963                {
 03964                    _httpResponse.Dispose();
 3965                }
 03966                throw ex;
 3967            }
 3968            // Create Result
 03969            var _result = new AzureOperationHeaderResponse<PoolUpdatePropertiesHeaders>();
 03970            _result.Request = _httpRequest;
 03971            _result.Response = _httpResponse;
 03972            if (_httpResponse.Headers.Contains("request-id"))
 3973            {
 03974                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 3975            }
 3976            try
 3977            {
 03978                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolUpdatePropertiesHeaders>(JsonSerializer.
 03979            }
 03980            catch (JsonException ex)
 3981            {
 03982                _httpRequest.Dispose();
 03983                if (_httpResponse != null)
 3984                {
 03985                    _httpResponse.Dispose();
 3986                }
 03987                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 3988            }
 03989            if (_shouldTrace)
 3990            {
 03991                ServiceClientTracing.Exit(_invocationId, _result);
 3992            }
 03993            return _result;
 03994        }
 3995
 3996        /// <summary>
 3997        /// Removes Compute Nodes from the specified Pool.
 3998        /// </summary>
 3999        /// <remarks>
 4000        /// This operation can only run when the allocation state of the Pool is
 4001        /// steady. When this operation runs, the allocation state changes from steady
 4002        /// to resizing.
 4003        /// </remarks>
 4004        /// <param name='poolId'>
 4005        /// The ID of the Pool from which you want to remove Compute Nodes.
 4006        /// </param>
 4007        /// <param name='nodeRemoveParameter'>
 4008        /// The parameters for the request.
 4009        /// </param>
 4010        /// <param name='poolRemoveNodesOptions'>
 4011        /// Additional parameters for the operation
 4012        /// </param>
 4013        /// <param name='customHeaders'>
 4014        /// Headers that will be added to request.
 4015        /// </param>
 4016        /// <param name='cancellationToken'>
 4017        /// The cancellation token.
 4018        /// </param>
 4019        /// <exception cref="BatchErrorException">
 4020        /// Thrown when the operation returned an invalid status code
 4021        /// </exception>
 4022        /// <exception cref="ValidationException">
 4023        /// Thrown when a required parameter is null
 4024        /// </exception>
 4025        /// <exception cref="System.ArgumentNullException">
 4026        /// Thrown when a required parameter is null
 4027        /// </exception>
 4028        /// <return>
 4029        /// A response object containing the response body and response headers.
 4030        /// </return>
 4031        public async Task<AzureOperationHeaderResponse<PoolRemoveNodesHeaders>> RemoveNodesWithHttpMessagesAsync(string 
 4032        {
 04033            if (Client.BatchUrl == null)
 4034            {
 04035                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 4036            }
 04037            if (poolId == null)
 4038            {
 04039                throw new ValidationException(ValidationRules.CannotBeNull, "poolId");
 4040            }
 04041            if (nodeRemoveParameter == null)
 4042            {
 04043                throw new ValidationException(ValidationRules.CannotBeNull, "nodeRemoveParameter");
 4044            }
 04045            if (Client.ApiVersion == null)
 4046            {
 04047                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 4048            }
 04049            int? timeout = default(int?);
 04050            if (poolRemoveNodesOptions != null)
 4051            {
 04052                timeout = poolRemoveNodesOptions.Timeout;
 4053            }
 04054            System.Guid? clientRequestId = default(System.Guid?);
 04055            if (poolRemoveNodesOptions != null)
 4056            {
 04057                clientRequestId = poolRemoveNodesOptions.ClientRequestId;
 4058            }
 04059            bool? returnClientRequestId = default(bool?);
 04060            if (poolRemoveNodesOptions != null)
 4061            {
 04062                returnClientRequestId = poolRemoveNodesOptions.ReturnClientRequestId;
 4063            }
 04064            System.DateTime? ocpDate = default(System.DateTime?);
 04065            if (poolRemoveNodesOptions != null)
 4066            {
 04067                ocpDate = poolRemoveNodesOptions.OcpDate;
 4068            }
 04069            string ifMatch = default(string);
 04070            if (poolRemoveNodesOptions != null)
 4071            {
 04072                ifMatch = poolRemoveNodesOptions.IfMatch;
 4073            }
 04074            string ifNoneMatch = default(string);
 04075            if (poolRemoveNodesOptions != null)
 4076            {
 04077                ifNoneMatch = poolRemoveNodesOptions.IfNoneMatch;
 4078            }
 04079            System.DateTime? ifModifiedSince = default(System.DateTime?);
 04080            if (poolRemoveNodesOptions != null)
 4081            {
 04082                ifModifiedSince = poolRemoveNodesOptions.IfModifiedSince;
 4083            }
 04084            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 04085            if (poolRemoveNodesOptions != null)
 4086            {
 04087                ifUnmodifiedSince = poolRemoveNodesOptions.IfUnmodifiedSince;
 4088            }
 4089            // Tracing
 04090            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 04091            string _invocationId = null;
 04092            if (_shouldTrace)
 4093            {
 04094                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04095                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04096                tracingParameters.Add("poolId", poolId);
 04097                tracingParameters.Add("nodeRemoveParameter", nodeRemoveParameter);
 04098                tracingParameters.Add("timeout", timeout);
 04099                tracingParameters.Add("clientRequestId", clientRequestId);
 04100                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 04101                tracingParameters.Add("ocpDate", ocpDate);
 04102                tracingParameters.Add("ifMatch", ifMatch);
 04103                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 04104                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 04105                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 04106                tracingParameters.Add("cancellationToken", cancellationToken);
 04107                ServiceClientTracing.Enter(_invocationId, this, "RemoveNodes", tracingParameters);
 4108            }
 4109            // Construct URL
 04110            var _baseUrl = Client.BaseUri;
 04111            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "pools/{poolId}/removenodes";
 04112            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 04113            _url = _url.Replace("{poolId}", System.Uri.EscapeDataString(poolId));
 04114            List<string> _queryParameters = new List<string>();
 04115            if (Client.ApiVersion != null)
 4116            {
 04117                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 4118            }
 04119            if (timeout != null)
 4120            {
 04121                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 4122            }
 04123            if (_queryParameters.Count > 0)
 4124            {
 04125                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4126            }
 4127            // Create HTTP transport objects
 04128            var _httpRequest = new HttpRequestMessage();
 04129            HttpResponseMessage _httpResponse = null;
 04130            _httpRequest.Method = new HttpMethod("POST");
 04131            _httpRequest.RequestUri = new System.Uri(_url);
 4132            // Set Headers
 04133            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4134            {
 04135                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 4136            }
 04137            if (Client.AcceptLanguage != null)
 4138            {
 04139                if (_httpRequest.Headers.Contains("accept-language"))
 4140                {
 04141                    _httpRequest.Headers.Remove("accept-language");
 4142                }
 04143                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4144            }
 04145            if (clientRequestId != null)
 4146            {
 04147                if (_httpRequest.Headers.Contains("client-request-id"))
 4148                {
 04149                    _httpRequest.Headers.Remove("client-request-id");
 4150                }
 04151                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 4152            }
 04153            if (returnClientRequestId != null)
 4154            {
 04155                if (_httpRequest.Headers.Contains("return-client-request-id"))
 4156                {
 04157                    _httpRequest.Headers.Remove("return-client-request-id");
 4158                }
 04159                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 4160            }
 04161            if (ocpDate != null)
 4162            {
 04163                if (_httpRequest.Headers.Contains("ocp-date"))
 4164                {
 04165                    _httpRequest.Headers.Remove("ocp-date");
 4166                }
 04167                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 4168            }
 04169            if (ifMatch != null)
 4170            {
 04171                if (_httpRequest.Headers.Contains("If-Match"))
 4172                {
 04173                    _httpRequest.Headers.Remove("If-Match");
 4174                }
 04175                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 4176            }
 04177            if (ifNoneMatch != null)
 4178            {
 04179                if (_httpRequest.Headers.Contains("If-None-Match"))
 4180                {
 04181                    _httpRequest.Headers.Remove("If-None-Match");
 4182                }
 04183                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 4184            }
 04185            if (ifModifiedSince != null)
 4186            {
 04187                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 4188                {
 04189                    _httpRequest.Headers.Remove("If-Modified-Since");
 4190                }
 04191                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 4192            }
 04193            if (ifUnmodifiedSince != null)
 4194            {
 04195                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 4196                {
 04197                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 4198                }
 04199                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 4200            }
 4201
 4202
 04203            if (customHeaders != null)
 4204            {
 04205                foreach(var _header in customHeaders)
 4206                {
 04207                    if (_httpRequest.Headers.Contains(_header.Key))
 4208                    {
 04209                        _httpRequest.Headers.Remove(_header.Key);
 4210                    }
 04211                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4212                }
 4213            }
 4214
 4215            // Serialize Request
 04216            string _requestContent = null;
 04217            if(nodeRemoveParameter != null)
 4218            {
 04219                _requestContent = SafeJsonConvert.SerializeObject(nodeRemoveParameter, Client.SerializationSettings);
 04220                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 04221                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 4222            }
 4223            // Set Credentials
 04224            if (Client.Credentials != null)
 4225            {
 04226                cancellationToken.ThrowIfCancellationRequested();
 04227                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4228            }
 4229            // Send Request
 04230            if (_shouldTrace)
 4231            {
 04232                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4233            }
 04234            cancellationToken.ThrowIfCancellationRequested();
 04235            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 04236            if (_shouldTrace)
 4237            {
 04238                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4239            }
 04240            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 04241            cancellationToken.ThrowIfCancellationRequested();
 04242            string _responseContent = null;
 04243            if ((int)_statusCode != 202)
 4244            {
 04245                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 4246                try
 4247                {
 04248                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04249                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 04250                    if (_errorBody != null)
 4251                    {
 04252                        ex.Body = _errorBody;
 4253                    }
 04254                }
 04255                catch (JsonException)
 4256                {
 4257                    // Ignore the exception
 04258                }
 04259                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04260                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04261                if (_shouldTrace)
 4262                {
 04263                    ServiceClientTracing.Error(_invocationId, ex);
 4264                }
 04265                _httpRequest.Dispose();
 04266                if (_httpResponse != null)
 4267                {
 04268                    _httpResponse.Dispose();
 4269                }
 04270                throw ex;
 4271            }
 4272            // Create Result
 04273            var _result = new AzureOperationHeaderResponse<PoolRemoveNodesHeaders>();
 04274            _result.Request = _httpRequest;
 04275            _result.Response = _httpResponse;
 04276            if (_httpResponse.Headers.Contains("request-id"))
 4277            {
 04278                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 4279            }
 4280            try
 4281            {
 04282                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolRemoveNodesHeaders>(JsonSerializer.Creat
 04283            }
 04284            catch (JsonException ex)
 4285            {
 04286                _httpRequest.Dispose();
 04287                if (_httpResponse != null)
 4288                {
 04289                    _httpResponse.Dispose();
 4290                }
 04291                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 4292            }
 04293            if (_shouldTrace)
 4294            {
 04295                ServiceClientTracing.Exit(_invocationId, _result);
 4296            }
 04297            return _result;
 04298        }
 4299
 4300        /// <summary>
 4301        /// Lists the usage metrics, aggregated by Pool across individual time
 4302        /// intervals, for the specified Account.
 4303        /// </summary>
 4304        /// <remarks>
 4305        /// If you do not specify a $filter clause including a poolId, the response
 4306        /// includes all Pools that existed in the Account in the time range of the
 4307        /// returned aggregation intervals. If you do not specify a $filter clause
 4308        /// including a startTime or endTime these filters default to the start and end
 4309        /// times of the last aggregation interval currently available; that is, only
 4310        /// the last aggregation interval is returned.
 4311        /// </remarks>
 4312        /// <param name='nextPageLink'>
 4313        /// The NextLink from the previous successful call to List operation.
 4314        /// </param>
 4315        /// <param name='poolListUsageMetricsNextOptions'>
 4316        /// Additional parameters for the operation
 4317        /// </param>
 4318        /// <param name='customHeaders'>
 4319        /// Headers that will be added to request.
 4320        /// </param>
 4321        /// <param name='cancellationToken'>
 4322        /// The cancellation token.
 4323        /// </param>
 4324        /// <exception cref="BatchErrorException">
 4325        /// Thrown when the operation returned an invalid status code
 4326        /// </exception>
 4327        /// <exception cref="SerializationException">
 4328        /// Thrown when unable to deserialize the response
 4329        /// </exception>
 4330        /// <exception cref="ValidationException">
 4331        /// Thrown when a required parameter is null
 4332        /// </exception>
 4333        /// <exception cref="System.ArgumentNullException">
 4334        /// Thrown when a required parameter is null
 4335        /// </exception>
 4336        /// <return>
 4337        /// A response object containing the response body and response headers.
 4338        /// </return>
 4339        public async Task<AzureOperationResponse<IPage<PoolUsageMetrics>,PoolListUsageMetricsHeaders>> ListUsageMetricsN
 4340        {
 04341            if (nextPageLink == null)
 4342            {
 04343                throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink");
 4344            }
 04345            System.Guid? clientRequestId = default(System.Guid?);
 04346            if (poolListUsageMetricsNextOptions != null)
 4347            {
 04348                clientRequestId = poolListUsageMetricsNextOptions.ClientRequestId;
 4349            }
 04350            bool? returnClientRequestId = default(bool?);
 04351            if (poolListUsageMetricsNextOptions != null)
 4352            {
 04353                returnClientRequestId = poolListUsageMetricsNextOptions.ReturnClientRequestId;
 4354            }
 04355            System.DateTime? ocpDate = default(System.DateTime?);
 04356            if (poolListUsageMetricsNextOptions != null)
 4357            {
 04358                ocpDate = poolListUsageMetricsNextOptions.OcpDate;
 4359            }
 4360            // Tracing
 04361            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 04362            string _invocationId = null;
 04363            if (_shouldTrace)
 4364            {
 04365                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04366                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04367                tracingParameters.Add("nextPageLink", nextPageLink);
 04368                tracingParameters.Add("clientRequestId", clientRequestId);
 04369                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 04370                tracingParameters.Add("ocpDate", ocpDate);
 04371                tracingParameters.Add("cancellationToken", cancellationToken);
 04372                ServiceClientTracing.Enter(_invocationId, this, "ListUsageMetricsNext", tracingParameters);
 4373            }
 4374            // Construct URL
 04375            string _url = "{nextLink}";
 04376            _url = _url.Replace("{nextLink}", nextPageLink);
 04377            List<string> _queryParameters = new List<string>();
 04378            if (_queryParameters.Count > 0)
 4379            {
 04380                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4381            }
 4382            // Create HTTP transport objects
 04383            var _httpRequest = new HttpRequestMessage();
 04384            HttpResponseMessage _httpResponse = null;
 04385            _httpRequest.Method = new HttpMethod("GET");
 04386            _httpRequest.RequestUri = new System.Uri(_url);
 4387            // Set Headers
 04388            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4389            {
 04390                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 4391            }
 04392            if (Client.AcceptLanguage != null)
 4393            {
 04394                if (_httpRequest.Headers.Contains("accept-language"))
 4395                {
 04396                    _httpRequest.Headers.Remove("accept-language");
 4397                }
 04398                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4399            }
 04400            if (clientRequestId != null)
 4401            {
 04402                if (_httpRequest.Headers.Contains("client-request-id"))
 4403                {
 04404                    _httpRequest.Headers.Remove("client-request-id");
 4405                }
 04406                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 4407            }
 04408            if (returnClientRequestId != null)
 4409            {
 04410                if (_httpRequest.Headers.Contains("return-client-request-id"))
 4411                {
 04412                    _httpRequest.Headers.Remove("return-client-request-id");
 4413                }
 04414                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 4415            }
 04416            if (ocpDate != null)
 4417            {
 04418                if (_httpRequest.Headers.Contains("ocp-date"))
 4419                {
 04420                    _httpRequest.Headers.Remove("ocp-date");
 4421                }
 04422                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 4423            }
 4424
 4425
 04426            if (customHeaders != null)
 4427            {
 04428                foreach(var _header in customHeaders)
 4429                {
 04430                    if (_httpRequest.Headers.Contains(_header.Key))
 4431                    {
 04432                        _httpRequest.Headers.Remove(_header.Key);
 4433                    }
 04434                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4435                }
 4436            }
 4437
 4438            // Serialize Request
 04439            string _requestContent = null;
 4440            // Set Credentials
 04441            if (Client.Credentials != null)
 4442            {
 04443                cancellationToken.ThrowIfCancellationRequested();
 04444                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4445            }
 4446            // Send Request
 04447            if (_shouldTrace)
 4448            {
 04449                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4450            }
 04451            cancellationToken.ThrowIfCancellationRequested();
 04452            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 04453            if (_shouldTrace)
 4454            {
 04455                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4456            }
 04457            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 04458            cancellationToken.ThrowIfCancellationRequested();
 04459            string _responseContent = null;
 04460            if ((int)_statusCode != 200)
 4461            {
 04462                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 4463                try
 4464                {
 04465                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04466                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 04467                    if (_errorBody != null)
 4468                    {
 04469                        ex.Body = _errorBody;
 4470                    }
 04471                }
 04472                catch (JsonException)
 4473                {
 4474                    // Ignore the exception
 04475                }
 04476                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04477                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04478                if (_shouldTrace)
 4479                {
 04480                    ServiceClientTracing.Error(_invocationId, ex);
 4481                }
 04482                _httpRequest.Dispose();
 04483                if (_httpResponse != null)
 4484                {
 04485                    _httpResponse.Dispose();
 4486                }
 04487                throw ex;
 4488            }
 4489            // Create Result
 04490            var _result = new AzureOperationResponse<IPage<PoolUsageMetrics>,PoolListUsageMetricsHeaders>();
 04491            _result.Request = _httpRequest;
 04492            _result.Response = _httpResponse;
 04493            if (_httpResponse.Headers.Contains("request-id"))
 4494            {
 04495                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 4496            }
 4497            // Deserialize Response
 04498            if ((int)_statusCode == 200)
 4499            {
 04500                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4501                try
 4502                {
 04503                    _result.Body = SafeJsonConvert.DeserializeObject<Page<PoolUsageMetrics>>(_responseContent, Client.De
 04504                }
 04505                catch (JsonException ex)
 4506                {
 04507                    _httpRequest.Dispose();
 04508                    if (_httpResponse != null)
 4509                    {
 04510                        _httpResponse.Dispose();
 4511                    }
 04512                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4513                }
 4514            }
 4515            try
 4516            {
 04517                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolListUsageMetricsHeaders>(JsonSerializer.
 04518            }
 04519            catch (JsonException ex)
 4520            {
 04521                _httpRequest.Dispose();
 04522                if (_httpResponse != null)
 4523                {
 04524                    _httpResponse.Dispose();
 4525                }
 04526                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 4527            }
 04528            if (_shouldTrace)
 4529            {
 04530                ServiceClientTracing.Exit(_invocationId, _result);
 4531            }
 04532            return _result;
 04533        }
 4534
 4535        /// <summary>
 4536        /// Lists all of the Pools in the specified Account.
 4537        /// </summary>
 4538        /// <param name='nextPageLink'>
 4539        /// The NextLink from the previous successful call to List operation.
 4540        /// </param>
 4541        /// <param name='poolListNextOptions'>
 4542        /// Additional parameters for the operation
 4543        /// </param>
 4544        /// <param name='customHeaders'>
 4545        /// Headers that will be added to request.
 4546        /// </param>
 4547        /// <param name='cancellationToken'>
 4548        /// The cancellation token.
 4549        /// </param>
 4550        /// <exception cref="BatchErrorException">
 4551        /// Thrown when the operation returned an invalid status code
 4552        /// </exception>
 4553        /// <exception cref="SerializationException">
 4554        /// Thrown when unable to deserialize the response
 4555        /// </exception>
 4556        /// <exception cref="ValidationException">
 4557        /// Thrown when a required parameter is null
 4558        /// </exception>
 4559        /// <exception cref="System.ArgumentNullException">
 4560        /// Thrown when a required parameter is null
 4561        /// </exception>
 4562        /// <return>
 4563        /// A response object containing the response body and response headers.
 4564        /// </return>
 4565        public async Task<AzureOperationResponse<IPage<CloudPool>,PoolListHeaders>> ListNextWithHttpMessagesAsync(string
 4566        {
 04567            if (nextPageLink == null)
 4568            {
 04569                throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink");
 4570            }
 04571            System.Guid? clientRequestId = default(System.Guid?);
 04572            if (poolListNextOptions != null)
 4573            {
 04574                clientRequestId = poolListNextOptions.ClientRequestId;
 4575            }
 04576            bool? returnClientRequestId = default(bool?);
 04577            if (poolListNextOptions != null)
 4578            {
 04579                returnClientRequestId = poolListNextOptions.ReturnClientRequestId;
 4580            }
 04581            System.DateTime? ocpDate = default(System.DateTime?);
 04582            if (poolListNextOptions != null)
 4583            {
 04584                ocpDate = poolListNextOptions.OcpDate;
 4585            }
 4586            // Tracing
 04587            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 04588            string _invocationId = null;
 04589            if (_shouldTrace)
 4590            {
 04591                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 04592                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 04593                tracingParameters.Add("nextPageLink", nextPageLink);
 04594                tracingParameters.Add("clientRequestId", clientRequestId);
 04595                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 04596                tracingParameters.Add("ocpDate", ocpDate);
 04597                tracingParameters.Add("cancellationToken", cancellationToken);
 04598                ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters);
 4599            }
 4600            // Construct URL
 04601            string _url = "{nextLink}";
 04602            _url = _url.Replace("{nextLink}", nextPageLink);
 04603            List<string> _queryParameters = new List<string>();
 04604            if (_queryParameters.Count > 0)
 4605            {
 04606                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 4607            }
 4608            // Create HTTP transport objects
 04609            var _httpRequest = new HttpRequestMessage();
 04610            HttpResponseMessage _httpResponse = null;
 04611            _httpRequest.Method = new HttpMethod("GET");
 04612            _httpRequest.RequestUri = new System.Uri(_url);
 4613            // Set Headers
 04614            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 4615            {
 04616                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 4617            }
 04618            if (Client.AcceptLanguage != null)
 4619            {
 04620                if (_httpRequest.Headers.Contains("accept-language"))
 4621                {
 04622                    _httpRequest.Headers.Remove("accept-language");
 4623                }
 04624                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 4625            }
 04626            if (clientRequestId != null)
 4627            {
 04628                if (_httpRequest.Headers.Contains("client-request-id"))
 4629                {
 04630                    _httpRequest.Headers.Remove("client-request-id");
 4631                }
 04632                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 4633            }
 04634            if (returnClientRequestId != null)
 4635            {
 04636                if (_httpRequest.Headers.Contains("return-client-request-id"))
 4637                {
 04638                    _httpRequest.Headers.Remove("return-client-request-id");
 4639                }
 04640                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 4641            }
 04642            if (ocpDate != null)
 4643            {
 04644                if (_httpRequest.Headers.Contains("ocp-date"))
 4645                {
 04646                    _httpRequest.Headers.Remove("ocp-date");
 4647                }
 04648                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 4649            }
 4650
 4651
 04652            if (customHeaders != null)
 4653            {
 04654                foreach(var _header in customHeaders)
 4655                {
 04656                    if (_httpRequest.Headers.Contains(_header.Key))
 4657                    {
 04658                        _httpRequest.Headers.Remove(_header.Key);
 4659                    }
 04660                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 4661                }
 4662            }
 4663
 4664            // Serialize Request
 04665            string _requestContent = null;
 4666            // Set Credentials
 04667            if (Client.Credentials != null)
 4668            {
 04669                cancellationToken.ThrowIfCancellationRequested();
 04670                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 4671            }
 4672            // Send Request
 04673            if (_shouldTrace)
 4674            {
 04675                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 4676            }
 04677            cancellationToken.ThrowIfCancellationRequested();
 04678            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 04679            if (_shouldTrace)
 4680            {
 04681                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 4682            }
 04683            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 04684            cancellationToken.ThrowIfCancellationRequested();
 04685            string _responseContent = null;
 04686            if ((int)_statusCode != 200)
 4687            {
 04688                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 4689                try
 4690                {
 04691                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 04692                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 04693                    if (_errorBody != null)
 4694                    {
 04695                        ex.Body = _errorBody;
 4696                    }
 04697                }
 04698                catch (JsonException)
 4699                {
 4700                    // Ignore the exception
 04701                }
 04702                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 04703                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 04704                if (_shouldTrace)
 4705                {
 04706                    ServiceClientTracing.Error(_invocationId, ex);
 4707                }
 04708                _httpRequest.Dispose();
 04709                if (_httpResponse != null)
 4710                {
 04711                    _httpResponse.Dispose();
 4712                }
 04713                throw ex;
 4714            }
 4715            // Create Result
 04716            var _result = new AzureOperationResponse<IPage<CloudPool>,PoolListHeaders>();
 04717            _result.Request = _httpRequest;
 04718            _result.Response = _httpResponse;
 04719            if (_httpResponse.Headers.Contains("request-id"))
 4720            {
 04721                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 4722            }
 4723            // Deserialize Response
 04724            if ((int)_statusCode == 200)
 4725            {
 04726                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 4727                try
 4728                {
 04729                    _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudPool>>(_responseContent, Client.Deseriali
 04730                }
 04731                catch (JsonException ex)
 4732                {
 04733                    _httpRequest.Dispose();
 04734                    if (_httpResponse != null)
 4735                    {
 04736                        _httpResponse.Dispose();
 4737                    }
 04738                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 4739                }
 4740            }
 4741            try
 4742            {
 04743                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<PoolListHeaders>(JsonSerializer.Create(Clien
 04744            }
 04745            catch (JsonException ex)
 4746            {
 04747                _httpRequest.Dispose();
 04748                if (_httpResponse != null)
 4749                {
 04750                    _httpResponse.Dispose();
 4751                }
 04752                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 4753            }
 04754            if (_shouldTrace)
 4755            {
 04756                ServiceClientTracing.Exit(_invocationId, _result);
 4757            }
 04758            return _result;
 04759        }
 4760
 4761    }
 4762}