< Summary

Class:Microsoft.Azure.Batch.Protocol.TaskOperations
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\GeneratedProtocol\TaskOperations.cs
Covered lines:4
Uncovered lines:1424
Coverable lines:1428
Total lines:2951
Line coverage:0.2% (4 of 1428)
Covered branches:1
Total branches:904
Branch coverage:0.1% (1 of 904)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-0%100%
AddWithHttpMessagesAsync()-0%0%
ListWithHttpMessagesAsync()-0%0%
AddCollectionWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-0%0%
GetWithHttpMessagesAsync()-0%0%
UpdateWithHttpMessagesAsync()-0%0%
ListSubtasksWithHttpMessagesAsync()-0%0%
TerminateWithHttpMessagesAsync()-0%0%
ReactivateWithHttpMessagesAsync()-0%0%
ListNextWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\GeneratedProtocol\TaskOperations.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    /// TaskOperations operations.
 28    /// </summary>
 29    internal partial class TaskOperations : IServiceOperations<BatchServiceClient>, ITaskOperations
 30    {
 31        /// <summary>
 32        /// Initializes a new instance of the TaskOperations 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 TaskOperations(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>
 052        public BatchServiceClient Client { get; private set; }
 53
 54        /// <summary>
 55        /// Adds a Task to the specified Job.
 56        /// </summary>
 57        /// <remarks>
 58        /// The maximum lifetime of a Task from addition to completion is 180 days. If
 59        /// a Task has not completed within 180 days of being added it will be
 60        /// terminated by the Batch service and left in whatever state it was in at
 61        /// that time.
 62        /// </remarks>
 63        /// <param name='jobId'>
 64        /// The ID of the Job to which the Task is to be added.
 65        /// </param>
 66        /// <param name='task'>
 67        /// The Task to be added.
 68        /// </param>
 69        /// <param name='taskAddOptions'>
 70        /// Additional parameters for the operation
 71        /// </param>
 72        /// <param name='customHeaders'>
 73        /// Headers that will be added to request.
 74        /// </param>
 75        /// <param name='cancellationToken'>
 76        /// The cancellation token.
 77        /// </param>
 78        /// <exception cref="BatchErrorException">
 79        /// Thrown when the operation returned an invalid status code
 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<AzureOperationHeaderResponse<TaskAddHeaders>> AddWithHttpMessagesAsync(string jobId, TaskAddPa
 91        {
 092            if (Client.BatchUrl == null)
 93            {
 094                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 95            }
 096            if (jobId == null)
 97            {
 098                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 99            }
 0100            if (task == null)
 101            {
 0102                throw new ValidationException(ValidationRules.CannotBeNull, "task");
 103            }
 0104            if (Client.ApiVersion == null)
 105            {
 0106                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 107            }
 0108            int? timeout = default(int?);
 0109            if (taskAddOptions != null)
 110            {
 0111                timeout = taskAddOptions.Timeout;
 112            }
 0113            System.Guid? clientRequestId = default(System.Guid?);
 0114            if (taskAddOptions != null)
 115            {
 0116                clientRequestId = taskAddOptions.ClientRequestId;
 117            }
 0118            bool? returnClientRequestId = default(bool?);
 0119            if (taskAddOptions != null)
 120            {
 0121                returnClientRequestId = taskAddOptions.ReturnClientRequestId;
 122            }
 0123            System.DateTime? ocpDate = default(System.DateTime?);
 0124            if (taskAddOptions != null)
 125            {
 0126                ocpDate = taskAddOptions.OcpDate;
 127            }
 128            // Tracing
 0129            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0130            string _invocationId = null;
 0131            if (_shouldTrace)
 132            {
 0133                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0134                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0135                tracingParameters.Add("jobId", jobId);
 0136                tracingParameters.Add("task", task);
 0137                tracingParameters.Add("timeout", timeout);
 0138                tracingParameters.Add("clientRequestId", clientRequestId);
 0139                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0140                tracingParameters.Add("ocpDate", ocpDate);
 0141                tracingParameters.Add("cancellationToken", cancellationToken);
 0142                ServiceClientTracing.Enter(_invocationId, this, "Add", tracingParameters);
 143            }
 144            // Construct URL
 0145            var _baseUrl = Client.BaseUri;
 0146            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks";
 0147            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0148            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 0149            List<string> _queryParameters = new List<string>();
 0150            if (Client.ApiVersion != null)
 151            {
 0152                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 153            }
 0154            if (timeout != null)
 155            {
 0156                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 157            }
 0158            if (_queryParameters.Count > 0)
 159            {
 0160                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 161            }
 162            // Create HTTP transport objects
 0163            var _httpRequest = new HttpRequestMessage();
 0164            HttpResponseMessage _httpResponse = null;
 0165            _httpRequest.Method = new HttpMethod("POST");
 0166            _httpRequest.RequestUri = new System.Uri(_url);
 167            // Set Headers
 0168            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 169            {
 0170                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 171            }
 0172            if (Client.AcceptLanguage != null)
 173            {
 0174                if (_httpRequest.Headers.Contains("accept-language"))
 175                {
 0176                    _httpRequest.Headers.Remove("accept-language");
 177                }
 0178                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 179            }
 0180            if (clientRequestId != null)
 181            {
 0182                if (_httpRequest.Headers.Contains("client-request-id"))
 183                {
 0184                    _httpRequest.Headers.Remove("client-request-id");
 185                }
 0186                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 187            }
 0188            if (returnClientRequestId != null)
 189            {
 0190                if (_httpRequest.Headers.Contains("return-client-request-id"))
 191                {
 0192                    _httpRequest.Headers.Remove("return-client-request-id");
 193                }
 0194                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 195            }
 0196            if (ocpDate != null)
 197            {
 0198                if (_httpRequest.Headers.Contains("ocp-date"))
 199                {
 0200                    _httpRequest.Headers.Remove("ocp-date");
 201                }
 0202                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 203            }
 204
 205
 0206            if (customHeaders != null)
 207            {
 0208                foreach(var _header in customHeaders)
 209                {
 0210                    if (_httpRequest.Headers.Contains(_header.Key))
 211                    {
 0212                        _httpRequest.Headers.Remove(_header.Key);
 213                    }
 0214                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 215                }
 216            }
 217
 218            // Serialize Request
 0219            string _requestContent = null;
 0220            if(task != null)
 221            {
 0222                _requestContent = SafeJsonConvert.SerializeObject(task, Client.SerializationSettings);
 0223                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0224                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 225            }
 226            // Set Credentials
 0227            if (Client.Credentials != null)
 228            {
 0229                cancellationToken.ThrowIfCancellationRequested();
 0230                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 231            }
 232            // Send Request
 0233            if (_shouldTrace)
 234            {
 0235                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 236            }
 0237            cancellationToken.ThrowIfCancellationRequested();
 0238            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0239            if (_shouldTrace)
 240            {
 0241                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 242            }
 0243            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0244            cancellationToken.ThrowIfCancellationRequested();
 0245            string _responseContent = null;
 0246            if ((int)_statusCode != 201)
 247            {
 0248                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 249                try
 250                {
 0251                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0252                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0253                    if (_errorBody != null)
 254                    {
 0255                        ex.Body = _errorBody;
 256                    }
 0257                }
 0258                catch (JsonException)
 259                {
 260                    // Ignore the exception
 0261                }
 0262                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0263                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0264                if (_shouldTrace)
 265                {
 0266                    ServiceClientTracing.Error(_invocationId, ex);
 267                }
 0268                _httpRequest.Dispose();
 0269                if (_httpResponse != null)
 270                {
 0271                    _httpResponse.Dispose();
 272                }
 0273                throw ex;
 274            }
 275            // Create Result
 0276            var _result = new AzureOperationHeaderResponse<TaskAddHeaders>();
 0277            _result.Request = _httpRequest;
 0278            _result.Response = _httpResponse;
 0279            if (_httpResponse.Headers.Contains("request-id"))
 280            {
 0281                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 282            }
 283            try
 284            {
 0285                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskAddHeaders>(JsonSerializer.Create(Client
 0286            }
 0287            catch (JsonException ex)
 288            {
 0289                _httpRequest.Dispose();
 0290                if (_httpResponse != null)
 291                {
 0292                    _httpResponse.Dispose();
 293                }
 0294                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 295            }
 0296            if (_shouldTrace)
 297            {
 0298                ServiceClientTracing.Exit(_invocationId, _result);
 299            }
 0300            return _result;
 0301        }
 302
 303        /// <summary>
 304        /// Lists all of the Tasks that are associated with the specified Job.
 305        /// </summary>
 306        /// <remarks>
 307        /// For multi-instance Tasks, information such as affinityId, executionInfo and
 308        /// nodeInfo refer to the primary Task. Use the list subtasks API to retrieve
 309        /// information about subtasks.
 310        /// </remarks>
 311        /// <param name='jobId'>
 312        /// The ID of the Job.
 313        /// </param>
 314        /// <param name='taskListOptions'>
 315        /// Additional parameters for the operation
 316        /// </param>
 317        /// <param name='customHeaders'>
 318        /// Headers that will be added to request.
 319        /// </param>
 320        /// <param name='cancellationToken'>
 321        /// The cancellation token.
 322        /// </param>
 323        /// <exception cref="BatchErrorException">
 324        /// Thrown when the operation returned an invalid status code
 325        /// </exception>
 326        /// <exception cref="SerializationException">
 327        /// Thrown when unable to deserialize the response
 328        /// </exception>
 329        /// <exception cref="ValidationException">
 330        /// Thrown when a required parameter is null
 331        /// </exception>
 332        /// <exception cref="System.ArgumentNullException">
 333        /// Thrown when a required parameter is null
 334        /// </exception>
 335        /// <return>
 336        /// A response object containing the response body and response headers.
 337        /// </return>
 338        public async Task<AzureOperationResponse<IPage<CloudTask>,TaskListHeaders>> ListWithHttpMessagesAsync(string job
 339        {
 0340            if (Client.BatchUrl == null)
 341            {
 0342                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 343            }
 0344            if (jobId == null)
 345            {
 0346                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 347            }
 0348            if (Client.ApiVersion == null)
 349            {
 0350                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 351            }
 0352            string filter = default(string);
 0353            if (taskListOptions != null)
 354            {
 0355                filter = taskListOptions.Filter;
 356            }
 0357            string select = default(string);
 0358            if (taskListOptions != null)
 359            {
 0360                select = taskListOptions.Select;
 361            }
 0362            string expand = default(string);
 0363            if (taskListOptions != null)
 364            {
 0365                expand = taskListOptions.Expand;
 366            }
 0367            int? maxResults = default(int?);
 0368            if (taskListOptions != null)
 369            {
 0370                maxResults = taskListOptions.MaxResults;
 371            }
 0372            int? timeout = default(int?);
 0373            if (taskListOptions != null)
 374            {
 0375                timeout = taskListOptions.Timeout;
 376            }
 0377            System.Guid? clientRequestId = default(System.Guid?);
 0378            if (taskListOptions != null)
 379            {
 0380                clientRequestId = taskListOptions.ClientRequestId;
 381            }
 0382            bool? returnClientRequestId = default(bool?);
 0383            if (taskListOptions != null)
 384            {
 0385                returnClientRequestId = taskListOptions.ReturnClientRequestId;
 386            }
 0387            System.DateTime? ocpDate = default(System.DateTime?);
 0388            if (taskListOptions != null)
 389            {
 0390                ocpDate = taskListOptions.OcpDate;
 391            }
 392            // Tracing
 0393            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0394            string _invocationId = null;
 0395            if (_shouldTrace)
 396            {
 0397                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0398                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0399                tracingParameters.Add("jobId", jobId);
 0400                tracingParameters.Add("filter", filter);
 0401                tracingParameters.Add("select", select);
 0402                tracingParameters.Add("expand", expand);
 0403                tracingParameters.Add("maxResults", maxResults);
 0404                tracingParameters.Add("timeout", timeout);
 0405                tracingParameters.Add("clientRequestId", clientRequestId);
 0406                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0407                tracingParameters.Add("ocpDate", ocpDate);
 0408                tracingParameters.Add("cancellationToken", cancellationToken);
 0409                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 410            }
 411            // Construct URL
 0412            var _baseUrl = Client.BaseUri;
 0413            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks";
 0414            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0415            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 0416            List<string> _queryParameters = new List<string>();
 0417            if (Client.ApiVersion != null)
 418            {
 0419                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 420            }
 0421            if (filter != null)
 422            {
 0423                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 424            }
 0425            if (select != null)
 426            {
 0427                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select)));
 428            }
 0429            if (expand != null)
 430            {
 0431                _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand)));
 432            }
 0433            if (maxResults != null)
 434            {
 0435                _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali
 436            }
 0437            if (timeout != null)
 438            {
 0439                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 440            }
 0441            if (_queryParameters.Count > 0)
 442            {
 0443                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 444            }
 445            // Create HTTP transport objects
 0446            var _httpRequest = new HttpRequestMessage();
 0447            HttpResponseMessage _httpResponse = null;
 0448            _httpRequest.Method = new HttpMethod("GET");
 0449            _httpRequest.RequestUri = new System.Uri(_url);
 450            // Set Headers
 0451            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 452            {
 0453                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 454            }
 0455            if (Client.AcceptLanguage != null)
 456            {
 0457                if (_httpRequest.Headers.Contains("accept-language"))
 458                {
 0459                    _httpRequest.Headers.Remove("accept-language");
 460                }
 0461                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 462            }
 0463            if (clientRequestId != null)
 464            {
 0465                if (_httpRequest.Headers.Contains("client-request-id"))
 466                {
 0467                    _httpRequest.Headers.Remove("client-request-id");
 468                }
 0469                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 470            }
 0471            if (returnClientRequestId != null)
 472            {
 0473                if (_httpRequest.Headers.Contains("return-client-request-id"))
 474                {
 0475                    _httpRequest.Headers.Remove("return-client-request-id");
 476                }
 0477                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 478            }
 0479            if (ocpDate != null)
 480            {
 0481                if (_httpRequest.Headers.Contains("ocp-date"))
 482                {
 0483                    _httpRequest.Headers.Remove("ocp-date");
 484                }
 0485                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 486            }
 487
 488
 0489            if (customHeaders != null)
 490            {
 0491                foreach(var _header in customHeaders)
 492                {
 0493                    if (_httpRequest.Headers.Contains(_header.Key))
 494                    {
 0495                        _httpRequest.Headers.Remove(_header.Key);
 496                    }
 0497                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 498                }
 499            }
 500
 501            // Serialize Request
 0502            string _requestContent = null;
 503            // Set Credentials
 0504            if (Client.Credentials != null)
 505            {
 0506                cancellationToken.ThrowIfCancellationRequested();
 0507                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 508            }
 509            // Send Request
 0510            if (_shouldTrace)
 511            {
 0512                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 513            }
 0514            cancellationToken.ThrowIfCancellationRequested();
 0515            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0516            if (_shouldTrace)
 517            {
 0518                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 519            }
 0520            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0521            cancellationToken.ThrowIfCancellationRequested();
 0522            string _responseContent = null;
 0523            if ((int)_statusCode != 200)
 524            {
 0525                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 526                try
 527                {
 0528                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0529                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0530                    if (_errorBody != null)
 531                    {
 0532                        ex.Body = _errorBody;
 533                    }
 0534                }
 0535                catch (JsonException)
 536                {
 537                    // Ignore the exception
 0538                }
 0539                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0540                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0541                if (_shouldTrace)
 542                {
 0543                    ServiceClientTracing.Error(_invocationId, ex);
 544                }
 0545                _httpRequest.Dispose();
 0546                if (_httpResponse != null)
 547                {
 0548                    _httpResponse.Dispose();
 549                }
 0550                throw ex;
 551            }
 552            // Create Result
 0553            var _result = new AzureOperationResponse<IPage<CloudTask>,TaskListHeaders>();
 0554            _result.Request = _httpRequest;
 0555            _result.Response = _httpResponse;
 0556            if (_httpResponse.Headers.Contains("request-id"))
 557            {
 0558                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 559            }
 560            // Deserialize Response
 0561            if ((int)_statusCode == 200)
 562            {
 0563                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 564                try
 565                {
 0566                    _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudTask>>(_responseContent, Client.Deseriali
 0567                }
 0568                catch (JsonException ex)
 569                {
 0570                    _httpRequest.Dispose();
 0571                    if (_httpResponse != null)
 572                    {
 0573                        _httpResponse.Dispose();
 574                    }
 0575                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 576                }
 577            }
 578            try
 579            {
 0580                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskListHeaders>(JsonSerializer.Create(Clien
 0581            }
 0582            catch (JsonException ex)
 583            {
 0584                _httpRequest.Dispose();
 0585                if (_httpResponse != null)
 586                {
 0587                    _httpResponse.Dispose();
 588                }
 0589                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 590            }
 0591            if (_shouldTrace)
 592            {
 0593                ServiceClientTracing.Exit(_invocationId, _result);
 594            }
 0595            return _result;
 0596        }
 597
 598        /// <summary>
 599        /// Adds a collection of Tasks to the specified Job.
 600        /// </summary>
 601        /// <remarks>
 602        /// Note that each Task must have a unique ID. The Batch service may not return
 603        /// the results for each Task in the same order the Tasks were submitted in
 604        /// this request. If the server times out or the connection is closed during
 605        /// the request, the request may have been partially or fully processed, or not
 606        /// at all. In such cases, the user should re-issue the request. Note that it
 607        /// is up to the user to correctly handle failures when re-issuing a request.
 608        /// For example, you should use the same Task IDs during a retry so that if the
 609        /// prior operation succeeded, the retry will not create extra Tasks
 610        /// unexpectedly. If the response contains any Tasks which failed to add, a
 611        /// client can retry the request. In a retry, it is most efficient to resubmit
 612        /// only Tasks that failed to add, and to omit Tasks that were successfully
 613        /// added on the first attempt. The maximum lifetime of a Task from addition to
 614        /// completion is 180 days. If a Task has not completed within 180 days of
 615        /// being added it will be terminated by the Batch service and left in whatever
 616        /// state it was in at that time.
 617        /// </remarks>
 618        /// <param name='jobId'>
 619        /// The ID of the Job to which the Task collection is to be added.
 620        /// </param>
 621        /// <param name='value'>
 622        /// The collection of Tasks to add. The maximum count of Tasks is 100. The
 623        /// total serialized size of this collection must be less than 1MB. If it is
 624        /// greater than 1MB (for example if each Task has 100's of resource files or
 625        /// environment variables), the request will fail with code
 626        /// 'RequestBodyTooLarge' and should be retried again with fewer Tasks.
 627        /// </param>
 628        /// <param name='taskAddCollectionOptions'>
 629        /// Additional parameters for the operation
 630        /// </param>
 631        /// <param name='customHeaders'>
 632        /// Headers that will be added to request.
 633        /// </param>
 634        /// <param name='cancellationToken'>
 635        /// The cancellation token.
 636        /// </param>
 637        /// <exception cref="BatchErrorException">
 638        /// Thrown when the operation returned an invalid status code
 639        /// </exception>
 640        /// <exception cref="SerializationException">
 641        /// Thrown when unable to deserialize the response
 642        /// </exception>
 643        /// <exception cref="ValidationException">
 644        /// Thrown when a required parameter is null
 645        /// </exception>
 646        /// <exception cref="System.ArgumentNullException">
 647        /// Thrown when a required parameter is null
 648        /// </exception>
 649        /// <return>
 650        /// A response object containing the response body and response headers.
 651        /// </return>
 652        public async Task<AzureOperationResponse<TaskAddCollectionResult,TaskAddCollectionHeaders>> AddCollectionWithHtt
 653        {
 0654            if (Client.BatchUrl == null)
 655            {
 0656                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 657            }
 0658            if (jobId == null)
 659            {
 0660                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 661            }
 0662            if (Client.ApiVersion == null)
 663            {
 0664                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 665            }
 0666            if (value == null)
 667            {
 0668                throw new ValidationException(ValidationRules.CannotBeNull, "value");
 669            }
 0670            int? timeout = default(int?);
 0671            if (taskAddCollectionOptions != null)
 672            {
 0673                timeout = taskAddCollectionOptions.Timeout;
 674            }
 0675            System.Guid? clientRequestId = default(System.Guid?);
 0676            if (taskAddCollectionOptions != null)
 677            {
 0678                clientRequestId = taskAddCollectionOptions.ClientRequestId;
 679            }
 0680            bool? returnClientRequestId = default(bool?);
 0681            if (taskAddCollectionOptions != null)
 682            {
 0683                returnClientRequestId = taskAddCollectionOptions.ReturnClientRequestId;
 684            }
 0685            System.DateTime? ocpDate = default(System.DateTime?);
 0686            if (taskAddCollectionOptions != null)
 687            {
 0688                ocpDate = taskAddCollectionOptions.OcpDate;
 689            }
 0690            TaskAddCollectionParameter taskCollection = new TaskAddCollectionParameter();
 0691            if (value != null)
 692            {
 0693                taskCollection.Value = value;
 694            }
 695            // Tracing
 0696            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0697            string _invocationId = null;
 0698            if (_shouldTrace)
 699            {
 0700                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0701                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0702                tracingParameters.Add("jobId", jobId);
 0703                tracingParameters.Add("timeout", timeout);
 0704                tracingParameters.Add("clientRequestId", clientRequestId);
 0705                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0706                tracingParameters.Add("ocpDate", ocpDate);
 0707                tracingParameters.Add("taskCollection", taskCollection);
 0708                tracingParameters.Add("cancellationToken", cancellationToken);
 0709                ServiceClientTracing.Enter(_invocationId, this, "AddCollection", tracingParameters);
 710            }
 711            // Construct URL
 0712            var _baseUrl = Client.BaseUri;
 0713            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/addtaskcollection";
 0714            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0715            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 0716            List<string> _queryParameters = new List<string>();
 0717            if (Client.ApiVersion != null)
 718            {
 0719                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 720            }
 0721            if (timeout != null)
 722            {
 0723                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 724            }
 0725            if (_queryParameters.Count > 0)
 726            {
 0727                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 728            }
 729            // Create HTTP transport objects
 0730            var _httpRequest = new HttpRequestMessage();
 0731            HttpResponseMessage _httpResponse = null;
 0732            _httpRequest.Method = new HttpMethod("POST");
 0733            _httpRequest.RequestUri = new System.Uri(_url);
 734            // Set Headers
 0735            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 736            {
 0737                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 738            }
 0739            if (Client.AcceptLanguage != null)
 740            {
 0741                if (_httpRequest.Headers.Contains("accept-language"))
 742                {
 0743                    _httpRequest.Headers.Remove("accept-language");
 744                }
 0745                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 746            }
 0747            if (clientRequestId != null)
 748            {
 0749                if (_httpRequest.Headers.Contains("client-request-id"))
 750                {
 0751                    _httpRequest.Headers.Remove("client-request-id");
 752                }
 0753                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 754            }
 0755            if (returnClientRequestId != null)
 756            {
 0757                if (_httpRequest.Headers.Contains("return-client-request-id"))
 758                {
 0759                    _httpRequest.Headers.Remove("return-client-request-id");
 760                }
 0761                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 762            }
 0763            if (ocpDate != null)
 764            {
 0765                if (_httpRequest.Headers.Contains("ocp-date"))
 766                {
 0767                    _httpRequest.Headers.Remove("ocp-date");
 768                }
 0769                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 770            }
 771
 772
 0773            if (customHeaders != null)
 774            {
 0775                foreach(var _header in customHeaders)
 776                {
 0777                    if (_httpRequest.Headers.Contains(_header.Key))
 778                    {
 0779                        _httpRequest.Headers.Remove(_header.Key);
 780                    }
 0781                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 782                }
 783            }
 784
 785            // Serialize Request
 0786            string _requestContent = null;
 0787            if(taskCollection != null)
 788            {
 0789                _requestContent = SafeJsonConvert.SerializeObject(taskCollection, Client.SerializationSettings);
 0790                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0791                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 792            }
 793            // Set Credentials
 0794            if (Client.Credentials != null)
 795            {
 0796                cancellationToken.ThrowIfCancellationRequested();
 0797                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 798            }
 799            // Send Request
 0800            if (_shouldTrace)
 801            {
 0802                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 803            }
 0804            cancellationToken.ThrowIfCancellationRequested();
 0805            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0806            if (_shouldTrace)
 807            {
 0808                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 809            }
 0810            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0811            cancellationToken.ThrowIfCancellationRequested();
 0812            string _responseContent = null;
 0813            if ((int)_statusCode != 200)
 814            {
 0815                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 816                try
 817                {
 0818                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0819                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0820                    if (_errorBody != null)
 821                    {
 0822                        ex.Body = _errorBody;
 823                    }
 0824                }
 0825                catch (JsonException)
 826                {
 827                    // Ignore the exception
 0828                }
 0829                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0830                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0831                if (_shouldTrace)
 832                {
 0833                    ServiceClientTracing.Error(_invocationId, ex);
 834                }
 0835                _httpRequest.Dispose();
 0836                if (_httpResponse != null)
 837                {
 0838                    _httpResponse.Dispose();
 839                }
 0840                throw ex;
 841            }
 842            // Create Result
 0843            var _result = new AzureOperationResponse<TaskAddCollectionResult,TaskAddCollectionHeaders>();
 0844            _result.Request = _httpRequest;
 0845            _result.Response = _httpResponse;
 0846            if (_httpResponse.Headers.Contains("request-id"))
 847            {
 0848                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 849            }
 850            // Deserialize Response
 0851            if ((int)_statusCode == 200)
 852            {
 0853                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 854                try
 855                {
 0856                    _result.Body = SafeJsonConvert.DeserializeObject<TaskAddCollectionResult>(_responseContent, Client.D
 0857                }
 0858                catch (JsonException ex)
 859                {
 0860                    _httpRequest.Dispose();
 0861                    if (_httpResponse != null)
 862                    {
 0863                        _httpResponse.Dispose();
 864                    }
 0865                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 866                }
 867            }
 868            try
 869            {
 0870                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskAddCollectionHeaders>(JsonSerializer.Cre
 0871            }
 0872            catch (JsonException ex)
 873            {
 0874                _httpRequest.Dispose();
 0875                if (_httpResponse != null)
 876                {
 0877                    _httpResponse.Dispose();
 878                }
 0879                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 880            }
 0881            if (_shouldTrace)
 882            {
 0883                ServiceClientTracing.Exit(_invocationId, _result);
 884            }
 0885            return _result;
 0886        }
 887
 888        /// <summary>
 889        /// Deletes a Task from the specified Job.
 890        /// </summary>
 891        /// <remarks>
 892        /// When a Task is deleted, all of the files in its directory on the Compute
 893        /// Node where it ran are also deleted (regardless of the retention time). For
 894        /// multi-instance Tasks, the delete Task operation applies synchronously to
 895        /// the primary task; subtasks and their files are then deleted asynchronously
 896        /// in the background.
 897        /// </remarks>
 898        /// <param name='jobId'>
 899        /// The ID of the Job from which to delete the Task.
 900        /// </param>
 901        /// <param name='taskId'>
 902        /// The ID of the Task to delete.
 903        /// </param>
 904        /// <param name='taskDeleteOptions'>
 905        /// Additional parameters for the operation
 906        /// </param>
 907        /// <param name='customHeaders'>
 908        /// Headers that will be added to request.
 909        /// </param>
 910        /// <param name='cancellationToken'>
 911        /// The cancellation token.
 912        /// </param>
 913        /// <exception cref="BatchErrorException">
 914        /// Thrown when the operation returned an invalid status code
 915        /// </exception>
 916        /// <exception cref="ValidationException">
 917        /// Thrown when a required parameter is null
 918        /// </exception>
 919        /// <exception cref="System.ArgumentNullException">
 920        /// Thrown when a required parameter is null
 921        /// </exception>
 922        /// <return>
 923        /// A response object containing the response body and response headers.
 924        /// </return>
 925        public async Task<AzureOperationHeaderResponse<TaskDeleteHeaders>> DeleteWithHttpMessagesAsync(string jobId, str
 926        {
 0927            if (Client.BatchUrl == null)
 928            {
 0929                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 930            }
 0931            if (jobId == null)
 932            {
 0933                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 934            }
 0935            if (taskId == null)
 936            {
 0937                throw new ValidationException(ValidationRules.CannotBeNull, "taskId");
 938            }
 0939            if (Client.ApiVersion == null)
 940            {
 0941                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 942            }
 0943            int? timeout = default(int?);
 0944            if (taskDeleteOptions != null)
 945            {
 0946                timeout = taskDeleteOptions.Timeout;
 947            }
 0948            System.Guid? clientRequestId = default(System.Guid?);
 0949            if (taskDeleteOptions != null)
 950            {
 0951                clientRequestId = taskDeleteOptions.ClientRequestId;
 952            }
 0953            bool? returnClientRequestId = default(bool?);
 0954            if (taskDeleteOptions != null)
 955            {
 0956                returnClientRequestId = taskDeleteOptions.ReturnClientRequestId;
 957            }
 0958            System.DateTime? ocpDate = default(System.DateTime?);
 0959            if (taskDeleteOptions != null)
 960            {
 0961                ocpDate = taskDeleteOptions.OcpDate;
 962            }
 0963            string ifMatch = default(string);
 0964            if (taskDeleteOptions != null)
 965            {
 0966                ifMatch = taskDeleteOptions.IfMatch;
 967            }
 0968            string ifNoneMatch = default(string);
 0969            if (taskDeleteOptions != null)
 970            {
 0971                ifNoneMatch = taskDeleteOptions.IfNoneMatch;
 972            }
 0973            System.DateTime? ifModifiedSince = default(System.DateTime?);
 0974            if (taskDeleteOptions != null)
 975            {
 0976                ifModifiedSince = taskDeleteOptions.IfModifiedSince;
 977            }
 0978            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 0979            if (taskDeleteOptions != null)
 980            {
 0981                ifUnmodifiedSince = taskDeleteOptions.IfUnmodifiedSince;
 982            }
 983            // Tracing
 0984            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0985            string _invocationId = null;
 0986            if (_shouldTrace)
 987            {
 0988                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0989                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0990                tracingParameters.Add("jobId", jobId);
 0991                tracingParameters.Add("taskId", taskId);
 0992                tracingParameters.Add("timeout", timeout);
 0993                tracingParameters.Add("clientRequestId", clientRequestId);
 0994                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0995                tracingParameters.Add("ocpDate", ocpDate);
 0996                tracingParameters.Add("ifMatch", ifMatch);
 0997                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 0998                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 0999                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 01000                tracingParameters.Add("cancellationToken", cancellationToken);
 01001                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 1002            }
 1003            // Construct URL
 01004            var _baseUrl = Client.BaseUri;
 01005            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks/{taskId}";
 01006            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 01007            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 01008            _url = _url.Replace("{taskId}", System.Uri.EscapeDataString(taskId));
 01009            List<string> _queryParameters = new List<string>();
 01010            if (Client.ApiVersion != null)
 1011            {
 01012                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1013            }
 01014            if (timeout != null)
 1015            {
 01016                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1017            }
 01018            if (_queryParameters.Count > 0)
 1019            {
 01020                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1021            }
 1022            // Create HTTP transport objects
 01023            var _httpRequest = new HttpRequestMessage();
 01024            HttpResponseMessage _httpResponse = null;
 01025            _httpRequest.Method = new HttpMethod("DELETE");
 01026            _httpRequest.RequestUri = new System.Uri(_url);
 1027            // Set Headers
 01028            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1029            {
 01030                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1031            }
 01032            if (Client.AcceptLanguage != null)
 1033            {
 01034                if (_httpRequest.Headers.Contains("accept-language"))
 1035                {
 01036                    _httpRequest.Headers.Remove("accept-language");
 1037                }
 01038                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1039            }
 01040            if (clientRequestId != null)
 1041            {
 01042                if (_httpRequest.Headers.Contains("client-request-id"))
 1043                {
 01044                    _httpRequest.Headers.Remove("client-request-id");
 1045                }
 01046                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1047            }
 01048            if (returnClientRequestId != null)
 1049            {
 01050                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1051                {
 01052                    _httpRequest.Headers.Remove("return-client-request-id");
 1053                }
 01054                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1055            }
 01056            if (ocpDate != null)
 1057            {
 01058                if (_httpRequest.Headers.Contains("ocp-date"))
 1059                {
 01060                    _httpRequest.Headers.Remove("ocp-date");
 1061                }
 01062                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1063            }
 01064            if (ifMatch != null)
 1065            {
 01066                if (_httpRequest.Headers.Contains("If-Match"))
 1067                {
 01068                    _httpRequest.Headers.Remove("If-Match");
 1069                }
 01070                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 1071            }
 01072            if (ifNoneMatch != null)
 1073            {
 01074                if (_httpRequest.Headers.Contains("If-None-Match"))
 1075                {
 01076                    _httpRequest.Headers.Remove("If-None-Match");
 1077                }
 01078                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 1079            }
 01080            if (ifModifiedSince != null)
 1081            {
 01082                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 1083                {
 01084                    _httpRequest.Headers.Remove("If-Modified-Since");
 1085                }
 01086                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 1087            }
 01088            if (ifUnmodifiedSince != null)
 1089            {
 01090                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 1091                {
 01092                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 1093                }
 01094                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 1095            }
 1096
 1097
 01098            if (customHeaders != null)
 1099            {
 01100                foreach(var _header in customHeaders)
 1101                {
 01102                    if (_httpRequest.Headers.Contains(_header.Key))
 1103                    {
 01104                        _httpRequest.Headers.Remove(_header.Key);
 1105                    }
 01106                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1107                }
 1108            }
 1109
 1110            // Serialize Request
 01111            string _requestContent = null;
 1112            // Set Credentials
 01113            if (Client.Credentials != null)
 1114            {
 01115                cancellationToken.ThrowIfCancellationRequested();
 01116                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1117            }
 1118            // Send Request
 01119            if (_shouldTrace)
 1120            {
 01121                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1122            }
 01123            cancellationToken.ThrowIfCancellationRequested();
 01124            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01125            if (_shouldTrace)
 1126            {
 01127                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1128            }
 01129            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01130            cancellationToken.ThrowIfCancellationRequested();
 01131            string _responseContent = null;
 01132            if ((int)_statusCode != 200)
 1133            {
 01134                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1135                try
 1136                {
 01137                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01138                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01139                    if (_errorBody != null)
 1140                    {
 01141                        ex.Body = _errorBody;
 1142                    }
 01143                }
 01144                catch (JsonException)
 1145                {
 1146                    // Ignore the exception
 01147                }
 01148                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01149                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01150                if (_shouldTrace)
 1151                {
 01152                    ServiceClientTracing.Error(_invocationId, ex);
 1153                }
 01154                _httpRequest.Dispose();
 01155                if (_httpResponse != null)
 1156                {
 01157                    _httpResponse.Dispose();
 1158                }
 01159                throw ex;
 1160            }
 1161            // Create Result
 01162            var _result = new AzureOperationHeaderResponse<TaskDeleteHeaders>();
 01163            _result.Request = _httpRequest;
 01164            _result.Response = _httpResponse;
 01165            if (_httpResponse.Headers.Contains("request-id"))
 1166            {
 01167                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1168            }
 1169            try
 1170            {
 01171                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskDeleteHeaders>(JsonSerializer.Create(Cli
 01172            }
 01173            catch (JsonException ex)
 1174            {
 01175                _httpRequest.Dispose();
 01176                if (_httpResponse != null)
 1177                {
 01178                    _httpResponse.Dispose();
 1179                }
 01180                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1181            }
 01182            if (_shouldTrace)
 1183            {
 01184                ServiceClientTracing.Exit(_invocationId, _result);
 1185            }
 01186            return _result;
 01187        }
 1188
 1189        /// <summary>
 1190        /// Gets information about the specified Task.
 1191        /// </summary>
 1192        /// <remarks>
 1193        /// For multi-instance Tasks, information such as affinityId, executionInfo and
 1194        /// nodeInfo refer to the primary Task. Use the list subtasks API to retrieve
 1195        /// information about subtasks.
 1196        /// </remarks>
 1197        /// <param name='jobId'>
 1198        /// The ID of the Job that contains the Task.
 1199        /// </param>
 1200        /// <param name='taskId'>
 1201        /// The ID of the Task to get information about.
 1202        /// </param>
 1203        /// <param name='taskGetOptions'>
 1204        /// Additional parameters for the operation
 1205        /// </param>
 1206        /// <param name='customHeaders'>
 1207        /// Headers that will be added to request.
 1208        /// </param>
 1209        /// <param name='cancellationToken'>
 1210        /// The cancellation token.
 1211        /// </param>
 1212        /// <exception cref="BatchErrorException">
 1213        /// Thrown when the operation returned an invalid status code
 1214        /// </exception>
 1215        /// <exception cref="SerializationException">
 1216        /// Thrown when unable to deserialize the response
 1217        /// </exception>
 1218        /// <exception cref="ValidationException">
 1219        /// Thrown when a required parameter is null
 1220        /// </exception>
 1221        /// <exception cref="System.ArgumentNullException">
 1222        /// Thrown when a required parameter is null
 1223        /// </exception>
 1224        /// <return>
 1225        /// A response object containing the response body and response headers.
 1226        /// </return>
 1227        public async Task<AzureOperationResponse<CloudTask,TaskGetHeaders>> GetWithHttpMessagesAsync(string jobId, strin
 1228        {
 01229            if (Client.BatchUrl == null)
 1230            {
 01231                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 1232            }
 01233            if (jobId == null)
 1234            {
 01235                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 1236            }
 01237            if (taskId == null)
 1238            {
 01239                throw new ValidationException(ValidationRules.CannotBeNull, "taskId");
 1240            }
 01241            if (Client.ApiVersion == null)
 1242            {
 01243                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1244            }
 01245            string select = default(string);
 01246            if (taskGetOptions != null)
 1247            {
 01248                select = taskGetOptions.Select;
 1249            }
 01250            string expand = default(string);
 01251            if (taskGetOptions != null)
 1252            {
 01253                expand = taskGetOptions.Expand;
 1254            }
 01255            int? timeout = default(int?);
 01256            if (taskGetOptions != null)
 1257            {
 01258                timeout = taskGetOptions.Timeout;
 1259            }
 01260            System.Guid? clientRequestId = default(System.Guid?);
 01261            if (taskGetOptions != null)
 1262            {
 01263                clientRequestId = taskGetOptions.ClientRequestId;
 1264            }
 01265            bool? returnClientRequestId = default(bool?);
 01266            if (taskGetOptions != null)
 1267            {
 01268                returnClientRequestId = taskGetOptions.ReturnClientRequestId;
 1269            }
 01270            System.DateTime? ocpDate = default(System.DateTime?);
 01271            if (taskGetOptions != null)
 1272            {
 01273                ocpDate = taskGetOptions.OcpDate;
 1274            }
 01275            string ifMatch = default(string);
 01276            if (taskGetOptions != null)
 1277            {
 01278                ifMatch = taskGetOptions.IfMatch;
 1279            }
 01280            string ifNoneMatch = default(string);
 01281            if (taskGetOptions != null)
 1282            {
 01283                ifNoneMatch = taskGetOptions.IfNoneMatch;
 1284            }
 01285            System.DateTime? ifModifiedSince = default(System.DateTime?);
 01286            if (taskGetOptions != null)
 1287            {
 01288                ifModifiedSince = taskGetOptions.IfModifiedSince;
 1289            }
 01290            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 01291            if (taskGetOptions != null)
 1292            {
 01293                ifUnmodifiedSince = taskGetOptions.IfUnmodifiedSince;
 1294            }
 1295            // Tracing
 01296            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01297            string _invocationId = null;
 01298            if (_shouldTrace)
 1299            {
 01300                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01301                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01302                tracingParameters.Add("jobId", jobId);
 01303                tracingParameters.Add("taskId", taskId);
 01304                tracingParameters.Add("select", select);
 01305                tracingParameters.Add("expand", expand);
 01306                tracingParameters.Add("timeout", timeout);
 01307                tracingParameters.Add("clientRequestId", clientRequestId);
 01308                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 01309                tracingParameters.Add("ocpDate", ocpDate);
 01310                tracingParameters.Add("ifMatch", ifMatch);
 01311                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 01312                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 01313                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 01314                tracingParameters.Add("cancellationToken", cancellationToken);
 01315                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 1316            }
 1317            // Construct URL
 01318            var _baseUrl = Client.BaseUri;
 01319            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks/{taskId}";
 01320            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 01321            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 01322            _url = _url.Replace("{taskId}", System.Uri.EscapeDataString(taskId));
 01323            List<string> _queryParameters = new List<string>();
 01324            if (Client.ApiVersion != null)
 1325            {
 01326                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1327            }
 01328            if (select != null)
 1329            {
 01330                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select)));
 1331            }
 01332            if (expand != null)
 1333            {
 01334                _queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand)));
 1335            }
 01336            if (timeout != null)
 1337            {
 01338                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1339            }
 01340            if (_queryParameters.Count > 0)
 1341            {
 01342                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1343            }
 1344            // Create HTTP transport objects
 01345            var _httpRequest = new HttpRequestMessage();
 01346            HttpResponseMessage _httpResponse = null;
 01347            _httpRequest.Method = new HttpMethod("GET");
 01348            _httpRequest.RequestUri = new System.Uri(_url);
 1349            // Set Headers
 01350            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1351            {
 01352                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1353            }
 01354            if (Client.AcceptLanguage != null)
 1355            {
 01356                if (_httpRequest.Headers.Contains("accept-language"))
 1357                {
 01358                    _httpRequest.Headers.Remove("accept-language");
 1359                }
 01360                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1361            }
 01362            if (clientRequestId != null)
 1363            {
 01364                if (_httpRequest.Headers.Contains("client-request-id"))
 1365                {
 01366                    _httpRequest.Headers.Remove("client-request-id");
 1367                }
 01368                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1369            }
 01370            if (returnClientRequestId != null)
 1371            {
 01372                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1373                {
 01374                    _httpRequest.Headers.Remove("return-client-request-id");
 1375                }
 01376                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1377            }
 01378            if (ocpDate != null)
 1379            {
 01380                if (_httpRequest.Headers.Contains("ocp-date"))
 1381                {
 01382                    _httpRequest.Headers.Remove("ocp-date");
 1383                }
 01384                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1385            }
 01386            if (ifMatch != null)
 1387            {
 01388                if (_httpRequest.Headers.Contains("If-Match"))
 1389                {
 01390                    _httpRequest.Headers.Remove("If-Match");
 1391                }
 01392                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 1393            }
 01394            if (ifNoneMatch != null)
 1395            {
 01396                if (_httpRequest.Headers.Contains("If-None-Match"))
 1397                {
 01398                    _httpRequest.Headers.Remove("If-None-Match");
 1399                }
 01400                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 1401            }
 01402            if (ifModifiedSince != null)
 1403            {
 01404                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 1405                {
 01406                    _httpRequest.Headers.Remove("If-Modified-Since");
 1407                }
 01408                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 1409            }
 01410            if (ifUnmodifiedSince != null)
 1411            {
 01412                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 1413                {
 01414                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 1415                }
 01416                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 1417            }
 1418
 1419
 01420            if (customHeaders != null)
 1421            {
 01422                foreach(var _header in customHeaders)
 1423                {
 01424                    if (_httpRequest.Headers.Contains(_header.Key))
 1425                    {
 01426                        _httpRequest.Headers.Remove(_header.Key);
 1427                    }
 01428                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1429                }
 1430            }
 1431
 1432            // Serialize Request
 01433            string _requestContent = null;
 1434            // Set Credentials
 01435            if (Client.Credentials != null)
 1436            {
 01437                cancellationToken.ThrowIfCancellationRequested();
 01438                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1439            }
 1440            // Send Request
 01441            if (_shouldTrace)
 1442            {
 01443                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1444            }
 01445            cancellationToken.ThrowIfCancellationRequested();
 01446            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01447            if (_shouldTrace)
 1448            {
 01449                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1450            }
 01451            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01452            cancellationToken.ThrowIfCancellationRequested();
 01453            string _responseContent = null;
 01454            if ((int)_statusCode != 200)
 1455            {
 01456                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1457                try
 1458                {
 01459                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01460                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01461                    if (_errorBody != null)
 1462                    {
 01463                        ex.Body = _errorBody;
 1464                    }
 01465                }
 01466                catch (JsonException)
 1467                {
 1468                    // Ignore the exception
 01469                }
 01470                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01471                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01472                if (_shouldTrace)
 1473                {
 01474                    ServiceClientTracing.Error(_invocationId, ex);
 1475                }
 01476                _httpRequest.Dispose();
 01477                if (_httpResponse != null)
 1478                {
 01479                    _httpResponse.Dispose();
 1480                }
 01481                throw ex;
 1482            }
 1483            // Create Result
 01484            var _result = new AzureOperationResponse<CloudTask,TaskGetHeaders>();
 01485            _result.Request = _httpRequest;
 01486            _result.Response = _httpResponse;
 01487            if (_httpResponse.Headers.Contains("request-id"))
 1488            {
 01489                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1490            }
 1491            // Deserialize Response
 01492            if ((int)_statusCode == 200)
 1493            {
 01494                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1495                try
 1496                {
 01497                    _result.Body = SafeJsonConvert.DeserializeObject<CloudTask>(_responseContent, Client.Deserialization
 01498                }
 01499                catch (JsonException ex)
 1500                {
 01501                    _httpRequest.Dispose();
 01502                    if (_httpResponse != null)
 1503                    {
 01504                        _httpResponse.Dispose();
 1505                    }
 01506                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1507                }
 1508            }
 1509            try
 1510            {
 01511                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskGetHeaders>(JsonSerializer.Create(Client
 01512            }
 01513            catch (JsonException ex)
 1514            {
 01515                _httpRequest.Dispose();
 01516                if (_httpResponse != null)
 1517                {
 01518                    _httpResponse.Dispose();
 1519                }
 01520                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1521            }
 01522            if (_shouldTrace)
 1523            {
 01524                ServiceClientTracing.Exit(_invocationId, _result);
 1525            }
 01526            return _result;
 01527        }
 1528
 1529        /// <summary>
 1530        /// Updates the properties of the specified Task.
 1531        /// </summary>
 1532        /// <param name='jobId'>
 1533        /// The ID of the Job containing the Task.
 1534        /// </param>
 1535        /// <param name='taskId'>
 1536        /// The ID of the Task to update.
 1537        /// </param>
 1538        /// <param name='constraints'>
 1539        /// Constraints that apply to this Task. If omitted, the Task is given the
 1540        /// default constraints. For multi-instance Tasks, updating the retention time
 1541        /// applies only to the primary Task and not subtasks.
 1542        /// </param>
 1543        /// <param name='taskUpdateOptions'>
 1544        /// Additional parameters for the operation
 1545        /// </param>
 1546        /// <param name='customHeaders'>
 1547        /// Headers that will be added to request.
 1548        /// </param>
 1549        /// <param name='cancellationToken'>
 1550        /// The cancellation token.
 1551        /// </param>
 1552        /// <exception cref="BatchErrorException">
 1553        /// Thrown when the operation returned an invalid status code
 1554        /// </exception>
 1555        /// <exception cref="ValidationException">
 1556        /// Thrown when a required parameter is null
 1557        /// </exception>
 1558        /// <exception cref="System.ArgumentNullException">
 1559        /// Thrown when a required parameter is null
 1560        /// </exception>
 1561        /// <return>
 1562        /// A response object containing the response body and response headers.
 1563        /// </return>
 1564        public async Task<AzureOperationHeaderResponse<TaskUpdateHeaders>> UpdateWithHttpMessagesAsync(string jobId, str
 1565        {
 01566            if (Client.BatchUrl == null)
 1567            {
 01568                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 1569            }
 01570            if (jobId == null)
 1571            {
 01572                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 1573            }
 01574            if (taskId == null)
 1575            {
 01576                throw new ValidationException(ValidationRules.CannotBeNull, "taskId");
 1577            }
 01578            if (Client.ApiVersion == null)
 1579            {
 01580                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1581            }
 01582            int? timeout = default(int?);
 01583            if (taskUpdateOptions != null)
 1584            {
 01585                timeout = taskUpdateOptions.Timeout;
 1586            }
 01587            System.Guid? clientRequestId = default(System.Guid?);
 01588            if (taskUpdateOptions != null)
 1589            {
 01590                clientRequestId = taskUpdateOptions.ClientRequestId;
 1591            }
 01592            bool? returnClientRequestId = default(bool?);
 01593            if (taskUpdateOptions != null)
 1594            {
 01595                returnClientRequestId = taskUpdateOptions.ReturnClientRequestId;
 1596            }
 01597            System.DateTime? ocpDate = default(System.DateTime?);
 01598            if (taskUpdateOptions != null)
 1599            {
 01600                ocpDate = taskUpdateOptions.OcpDate;
 1601            }
 01602            string ifMatch = default(string);
 01603            if (taskUpdateOptions != null)
 1604            {
 01605                ifMatch = taskUpdateOptions.IfMatch;
 1606            }
 01607            string ifNoneMatch = default(string);
 01608            if (taskUpdateOptions != null)
 1609            {
 01610                ifNoneMatch = taskUpdateOptions.IfNoneMatch;
 1611            }
 01612            System.DateTime? ifModifiedSince = default(System.DateTime?);
 01613            if (taskUpdateOptions != null)
 1614            {
 01615                ifModifiedSince = taskUpdateOptions.IfModifiedSince;
 1616            }
 01617            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 01618            if (taskUpdateOptions != null)
 1619            {
 01620                ifUnmodifiedSince = taskUpdateOptions.IfUnmodifiedSince;
 1621            }
 01622            TaskUpdateParameter taskUpdateParameter = new TaskUpdateParameter();
 01623            if (constraints != null)
 1624            {
 01625                taskUpdateParameter.Constraints = constraints;
 1626            }
 1627            // Tracing
 01628            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01629            string _invocationId = null;
 01630            if (_shouldTrace)
 1631            {
 01632                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01633                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01634                tracingParameters.Add("jobId", jobId);
 01635                tracingParameters.Add("taskId", taskId);
 01636                tracingParameters.Add("timeout", timeout);
 01637                tracingParameters.Add("clientRequestId", clientRequestId);
 01638                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 01639                tracingParameters.Add("ocpDate", ocpDate);
 01640                tracingParameters.Add("ifMatch", ifMatch);
 01641                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 01642                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 01643                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 01644                tracingParameters.Add("taskUpdateParameter", taskUpdateParameter);
 01645                tracingParameters.Add("cancellationToken", cancellationToken);
 01646                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 1647            }
 1648            // Construct URL
 01649            var _baseUrl = Client.BaseUri;
 01650            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks/{taskId}";
 01651            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 01652            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 01653            _url = _url.Replace("{taskId}", System.Uri.EscapeDataString(taskId));
 01654            List<string> _queryParameters = new List<string>();
 01655            if (Client.ApiVersion != null)
 1656            {
 01657                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1658            }
 01659            if (timeout != null)
 1660            {
 01661                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1662            }
 01663            if (_queryParameters.Count > 0)
 1664            {
 01665                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1666            }
 1667            // Create HTTP transport objects
 01668            var _httpRequest = new HttpRequestMessage();
 01669            HttpResponseMessage _httpResponse = null;
 01670            _httpRequest.Method = new HttpMethod("PUT");
 01671            _httpRequest.RequestUri = new System.Uri(_url);
 1672            // Set Headers
 01673            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1674            {
 01675                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1676            }
 01677            if (Client.AcceptLanguage != null)
 1678            {
 01679                if (_httpRequest.Headers.Contains("accept-language"))
 1680                {
 01681                    _httpRequest.Headers.Remove("accept-language");
 1682                }
 01683                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1684            }
 01685            if (clientRequestId != null)
 1686            {
 01687                if (_httpRequest.Headers.Contains("client-request-id"))
 1688                {
 01689                    _httpRequest.Headers.Remove("client-request-id");
 1690                }
 01691                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1692            }
 01693            if (returnClientRequestId != null)
 1694            {
 01695                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1696                {
 01697                    _httpRequest.Headers.Remove("return-client-request-id");
 1698                }
 01699                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1700            }
 01701            if (ocpDate != null)
 1702            {
 01703                if (_httpRequest.Headers.Contains("ocp-date"))
 1704                {
 01705                    _httpRequest.Headers.Remove("ocp-date");
 1706                }
 01707                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 1708            }
 01709            if (ifMatch != null)
 1710            {
 01711                if (_httpRequest.Headers.Contains("If-Match"))
 1712                {
 01713                    _httpRequest.Headers.Remove("If-Match");
 1714                }
 01715                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 1716            }
 01717            if (ifNoneMatch != null)
 1718            {
 01719                if (_httpRequest.Headers.Contains("If-None-Match"))
 1720                {
 01721                    _httpRequest.Headers.Remove("If-None-Match");
 1722                }
 01723                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 1724            }
 01725            if (ifModifiedSince != null)
 1726            {
 01727                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 1728                {
 01729                    _httpRequest.Headers.Remove("If-Modified-Since");
 1730                }
 01731                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 1732            }
 01733            if (ifUnmodifiedSince != null)
 1734            {
 01735                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 1736                {
 01737                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 1738                }
 01739                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 1740            }
 1741
 1742
 01743            if (customHeaders != null)
 1744            {
 01745                foreach(var _header in customHeaders)
 1746                {
 01747                    if (_httpRequest.Headers.Contains(_header.Key))
 1748                    {
 01749                        _httpRequest.Headers.Remove(_header.Key);
 1750                    }
 01751                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1752                }
 1753            }
 1754
 1755            // Serialize Request
 01756            string _requestContent = null;
 01757            if(taskUpdateParameter != null)
 1758            {
 01759                _requestContent = SafeJsonConvert.SerializeObject(taskUpdateParameter, Client.SerializationSettings);
 01760                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01761                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1762            }
 1763            // Set Credentials
 01764            if (Client.Credentials != null)
 1765            {
 01766                cancellationToken.ThrowIfCancellationRequested();
 01767                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1768            }
 1769            // Send Request
 01770            if (_shouldTrace)
 1771            {
 01772                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1773            }
 01774            cancellationToken.ThrowIfCancellationRequested();
 01775            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01776            if (_shouldTrace)
 1777            {
 01778                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1779            }
 01780            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01781            cancellationToken.ThrowIfCancellationRequested();
 01782            string _responseContent = null;
 01783            if ((int)_statusCode != 200)
 1784            {
 01785                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1786                try
 1787                {
 01788                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01789                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 01790                    if (_errorBody != null)
 1791                    {
 01792                        ex.Body = _errorBody;
 1793                    }
 01794                }
 01795                catch (JsonException)
 1796                {
 1797                    // Ignore the exception
 01798                }
 01799                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01800                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01801                if (_shouldTrace)
 1802                {
 01803                    ServiceClientTracing.Error(_invocationId, ex);
 1804                }
 01805                _httpRequest.Dispose();
 01806                if (_httpResponse != null)
 1807                {
 01808                    _httpResponse.Dispose();
 1809                }
 01810                throw ex;
 1811            }
 1812            // Create Result
 01813            var _result = new AzureOperationHeaderResponse<TaskUpdateHeaders>();
 01814            _result.Request = _httpRequest;
 01815            _result.Response = _httpResponse;
 01816            if (_httpResponse.Headers.Contains("request-id"))
 1817            {
 01818                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 1819            }
 1820            try
 1821            {
 01822                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskUpdateHeaders>(JsonSerializer.Create(Cli
 01823            }
 01824            catch (JsonException ex)
 1825            {
 01826                _httpRequest.Dispose();
 01827                if (_httpResponse != null)
 1828                {
 01829                    _httpResponse.Dispose();
 1830                }
 01831                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 1832            }
 01833            if (_shouldTrace)
 1834            {
 01835                ServiceClientTracing.Exit(_invocationId, _result);
 1836            }
 01837            return _result;
 01838        }
 1839
 1840        /// <summary>
 1841        /// Lists all of the subtasks that are associated with the specified
 1842        /// multi-instance Task.
 1843        /// </summary>
 1844        /// <remarks>
 1845        /// If the Task is not a multi-instance Task then this returns an empty
 1846        /// collection.
 1847        /// </remarks>
 1848        /// <param name='jobId'>
 1849        /// The ID of the Job.
 1850        /// </param>
 1851        /// <param name='taskId'>
 1852        /// The ID of the Task.
 1853        /// </param>
 1854        /// <param name='taskListSubtasksOptions'>
 1855        /// Additional parameters for the operation
 1856        /// </param>
 1857        /// <param name='customHeaders'>
 1858        /// Headers that will be added to request.
 1859        /// </param>
 1860        /// <param name='cancellationToken'>
 1861        /// The cancellation token.
 1862        /// </param>
 1863        /// <exception cref="BatchErrorException">
 1864        /// Thrown when the operation returned an invalid status code
 1865        /// </exception>
 1866        /// <exception cref="SerializationException">
 1867        /// Thrown when unable to deserialize the response
 1868        /// </exception>
 1869        /// <exception cref="ValidationException">
 1870        /// Thrown when a required parameter is null
 1871        /// </exception>
 1872        /// <exception cref="System.ArgumentNullException">
 1873        /// Thrown when a required parameter is null
 1874        /// </exception>
 1875        /// <return>
 1876        /// A response object containing the response body and response headers.
 1877        /// </return>
 1878        public async Task<AzureOperationResponse<CloudTaskListSubtasksResult,TaskListSubtasksHeaders>> ListSubtasksWithH
 1879        {
 01880            if (Client.BatchUrl == null)
 1881            {
 01882                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 1883            }
 01884            if (jobId == null)
 1885            {
 01886                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 1887            }
 01888            if (taskId == null)
 1889            {
 01890                throw new ValidationException(ValidationRules.CannotBeNull, "taskId");
 1891            }
 01892            if (Client.ApiVersion == null)
 1893            {
 01894                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1895            }
 01896            string select = default(string);
 01897            if (taskListSubtasksOptions != null)
 1898            {
 01899                select = taskListSubtasksOptions.Select;
 1900            }
 01901            int? timeout = default(int?);
 01902            if (taskListSubtasksOptions != null)
 1903            {
 01904                timeout = taskListSubtasksOptions.Timeout;
 1905            }
 01906            System.Guid? clientRequestId = default(System.Guid?);
 01907            if (taskListSubtasksOptions != null)
 1908            {
 01909                clientRequestId = taskListSubtasksOptions.ClientRequestId;
 1910            }
 01911            bool? returnClientRequestId = default(bool?);
 01912            if (taskListSubtasksOptions != null)
 1913            {
 01914                returnClientRequestId = taskListSubtasksOptions.ReturnClientRequestId;
 1915            }
 01916            System.DateTime? ocpDate = default(System.DateTime?);
 01917            if (taskListSubtasksOptions != null)
 1918            {
 01919                ocpDate = taskListSubtasksOptions.OcpDate;
 1920            }
 1921            // Tracing
 01922            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01923            string _invocationId = null;
 01924            if (_shouldTrace)
 1925            {
 01926                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01927                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01928                tracingParameters.Add("jobId", jobId);
 01929                tracingParameters.Add("taskId", taskId);
 01930                tracingParameters.Add("select", select);
 01931                tracingParameters.Add("timeout", timeout);
 01932                tracingParameters.Add("clientRequestId", clientRequestId);
 01933                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 01934                tracingParameters.Add("ocpDate", ocpDate);
 01935                tracingParameters.Add("cancellationToken", cancellationToken);
 01936                ServiceClientTracing.Enter(_invocationId, this, "ListSubtasks", tracingParameters);
 1937            }
 1938            // Construct URL
 01939            var _baseUrl = Client.BaseUri;
 01940            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks/{taskId}/subtasksinfo";
 01941            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 01942            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 01943            _url = _url.Replace("{taskId}", System.Uri.EscapeDataString(taskId));
 01944            List<string> _queryParameters = new List<string>();
 01945            if (Client.ApiVersion != null)
 1946            {
 01947                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1948            }
 01949            if (select != null)
 1950            {
 01951                _queryParameters.Add(string.Format("$select={0}", System.Uri.EscapeDataString(select)));
 1952            }
 01953            if (timeout != null)
 1954            {
 01955                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 1956            }
 01957            if (_queryParameters.Count > 0)
 1958            {
 01959                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1960            }
 1961            // Create HTTP transport objects
 01962            var _httpRequest = new HttpRequestMessage();
 01963            HttpResponseMessage _httpResponse = null;
 01964            _httpRequest.Method = new HttpMethod("GET");
 01965            _httpRequest.RequestUri = new System.Uri(_url);
 1966            // Set Headers
 01967            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1968            {
 01969                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 1970            }
 01971            if (Client.AcceptLanguage != null)
 1972            {
 01973                if (_httpRequest.Headers.Contains("accept-language"))
 1974                {
 01975                    _httpRequest.Headers.Remove("accept-language");
 1976                }
 01977                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1978            }
 01979            if (clientRequestId != null)
 1980            {
 01981                if (_httpRequest.Headers.Contains("client-request-id"))
 1982                {
 01983                    _httpRequest.Headers.Remove("client-request-id");
 1984                }
 01985                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 1986            }
 01987            if (returnClientRequestId != null)
 1988            {
 01989                if (_httpRequest.Headers.Contains("return-client-request-id"))
 1990                {
 01991                    _httpRequest.Headers.Remove("return-client-request-id");
 1992                }
 01993                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 1994            }
 01995            if (ocpDate != null)
 1996            {
 01997                if (_httpRequest.Headers.Contains("ocp-date"))
 1998                {
 01999                    _httpRequest.Headers.Remove("ocp-date");
 2000                }
 02001                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2002            }
 2003
 2004
 02005            if (customHeaders != null)
 2006            {
 02007                foreach(var _header in customHeaders)
 2008                {
 02009                    if (_httpRequest.Headers.Contains(_header.Key))
 2010                    {
 02011                        _httpRequest.Headers.Remove(_header.Key);
 2012                    }
 02013                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2014                }
 2015            }
 2016
 2017            // Serialize Request
 02018            string _requestContent = null;
 2019            // Set Credentials
 02020            if (Client.Credentials != null)
 2021            {
 02022                cancellationToken.ThrowIfCancellationRequested();
 02023                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2024            }
 2025            // Send Request
 02026            if (_shouldTrace)
 2027            {
 02028                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2029            }
 02030            cancellationToken.ThrowIfCancellationRequested();
 02031            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02032            if (_shouldTrace)
 2033            {
 02034                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2035            }
 02036            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02037            cancellationToken.ThrowIfCancellationRequested();
 02038            string _responseContent = null;
 02039            if ((int)_statusCode != 200)
 2040            {
 02041                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2042                try
 2043                {
 02044                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02045                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02046                    if (_errorBody != null)
 2047                    {
 02048                        ex.Body = _errorBody;
 2049                    }
 02050                }
 02051                catch (JsonException)
 2052                {
 2053                    // Ignore the exception
 02054                }
 02055                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02056                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02057                if (_shouldTrace)
 2058                {
 02059                    ServiceClientTracing.Error(_invocationId, ex);
 2060                }
 02061                _httpRequest.Dispose();
 02062                if (_httpResponse != null)
 2063                {
 02064                    _httpResponse.Dispose();
 2065                }
 02066                throw ex;
 2067            }
 2068            // Create Result
 02069            var _result = new AzureOperationResponse<CloudTaskListSubtasksResult,TaskListSubtasksHeaders>();
 02070            _result.Request = _httpRequest;
 02071            _result.Response = _httpResponse;
 02072            if (_httpResponse.Headers.Contains("request-id"))
 2073            {
 02074                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2075            }
 2076            // Deserialize Response
 02077            if ((int)_statusCode == 200)
 2078            {
 02079                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2080                try
 2081                {
 02082                    _result.Body = SafeJsonConvert.DeserializeObject<CloudTaskListSubtasksResult>(_responseContent, Clie
 02083                }
 02084                catch (JsonException ex)
 2085                {
 02086                    _httpRequest.Dispose();
 02087                    if (_httpResponse != null)
 2088                    {
 02089                        _httpResponse.Dispose();
 2090                    }
 02091                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2092                }
 2093            }
 2094            try
 2095            {
 02096                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskListSubtasksHeaders>(JsonSerializer.Crea
 02097            }
 02098            catch (JsonException ex)
 2099            {
 02100                _httpRequest.Dispose();
 02101                if (_httpResponse != null)
 2102                {
 02103                    _httpResponse.Dispose();
 2104                }
 02105                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2106            }
 02107            if (_shouldTrace)
 2108            {
 02109                ServiceClientTracing.Exit(_invocationId, _result);
 2110            }
 02111            return _result;
 02112        }
 2113
 2114        /// <summary>
 2115        /// Terminates the specified Task.
 2116        /// </summary>
 2117        /// <remarks>
 2118        /// When the Task has been terminated, it moves to the completed state. For
 2119        /// multi-instance Tasks, the terminate Task operation applies synchronously to
 2120        /// the primary task; subtasks are then terminated asynchronously in the
 2121        /// background.
 2122        /// </remarks>
 2123        /// <param name='jobId'>
 2124        /// The ID of the Job containing the Task.
 2125        /// </param>
 2126        /// <param name='taskId'>
 2127        /// The ID of the Task to terminate.
 2128        /// </param>
 2129        /// <param name='taskTerminateOptions'>
 2130        /// Additional parameters for the operation
 2131        /// </param>
 2132        /// <param name='customHeaders'>
 2133        /// Headers that will be added to request.
 2134        /// </param>
 2135        /// <param name='cancellationToken'>
 2136        /// The cancellation token.
 2137        /// </param>
 2138        /// <exception cref="BatchErrorException">
 2139        /// Thrown when the operation returned an invalid status code
 2140        /// </exception>
 2141        /// <exception cref="ValidationException">
 2142        /// Thrown when a required parameter is null
 2143        /// </exception>
 2144        /// <exception cref="System.ArgumentNullException">
 2145        /// Thrown when a required parameter is null
 2146        /// </exception>
 2147        /// <return>
 2148        /// A response object containing the response body and response headers.
 2149        /// </return>
 2150        public async Task<AzureOperationHeaderResponse<TaskTerminateHeaders>> TerminateWithHttpMessagesAsync(string jobI
 2151        {
 02152            if (Client.BatchUrl == null)
 2153            {
 02154                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 2155            }
 02156            if (jobId == null)
 2157            {
 02158                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 2159            }
 02160            if (taskId == null)
 2161            {
 02162                throw new ValidationException(ValidationRules.CannotBeNull, "taskId");
 2163            }
 02164            if (Client.ApiVersion == null)
 2165            {
 02166                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2167            }
 02168            int? timeout = default(int?);
 02169            if (taskTerminateOptions != null)
 2170            {
 02171                timeout = taskTerminateOptions.Timeout;
 2172            }
 02173            System.Guid? clientRequestId = default(System.Guid?);
 02174            if (taskTerminateOptions != null)
 2175            {
 02176                clientRequestId = taskTerminateOptions.ClientRequestId;
 2177            }
 02178            bool? returnClientRequestId = default(bool?);
 02179            if (taskTerminateOptions != null)
 2180            {
 02181                returnClientRequestId = taskTerminateOptions.ReturnClientRequestId;
 2182            }
 02183            System.DateTime? ocpDate = default(System.DateTime?);
 02184            if (taskTerminateOptions != null)
 2185            {
 02186                ocpDate = taskTerminateOptions.OcpDate;
 2187            }
 02188            string ifMatch = default(string);
 02189            if (taskTerminateOptions != null)
 2190            {
 02191                ifMatch = taskTerminateOptions.IfMatch;
 2192            }
 02193            string ifNoneMatch = default(string);
 02194            if (taskTerminateOptions != null)
 2195            {
 02196                ifNoneMatch = taskTerminateOptions.IfNoneMatch;
 2197            }
 02198            System.DateTime? ifModifiedSince = default(System.DateTime?);
 02199            if (taskTerminateOptions != null)
 2200            {
 02201                ifModifiedSince = taskTerminateOptions.IfModifiedSince;
 2202            }
 02203            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 02204            if (taskTerminateOptions != null)
 2205            {
 02206                ifUnmodifiedSince = taskTerminateOptions.IfUnmodifiedSince;
 2207            }
 2208            // Tracing
 02209            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02210            string _invocationId = null;
 02211            if (_shouldTrace)
 2212            {
 02213                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02214                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02215                tracingParameters.Add("jobId", jobId);
 02216                tracingParameters.Add("taskId", taskId);
 02217                tracingParameters.Add("timeout", timeout);
 02218                tracingParameters.Add("clientRequestId", clientRequestId);
 02219                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02220                tracingParameters.Add("ocpDate", ocpDate);
 02221                tracingParameters.Add("ifMatch", ifMatch);
 02222                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 02223                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 02224                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 02225                tracingParameters.Add("cancellationToken", cancellationToken);
 02226                ServiceClientTracing.Enter(_invocationId, this, "Terminate", tracingParameters);
 2227            }
 2228            // Construct URL
 02229            var _baseUrl = Client.BaseUri;
 02230            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks/{taskId}/terminate";
 02231            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 02232            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 02233            _url = _url.Replace("{taskId}", System.Uri.EscapeDataString(taskId));
 02234            List<string> _queryParameters = new List<string>();
 02235            if (Client.ApiVersion != null)
 2236            {
 02237                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2238            }
 02239            if (timeout != null)
 2240            {
 02241                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 2242            }
 02243            if (_queryParameters.Count > 0)
 2244            {
 02245                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2246            }
 2247            // Create HTTP transport objects
 02248            var _httpRequest = new HttpRequestMessage();
 02249            HttpResponseMessage _httpResponse = null;
 02250            _httpRequest.Method = new HttpMethod("POST");
 02251            _httpRequest.RequestUri = new System.Uri(_url);
 2252            // Set Headers
 02253            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2254            {
 02255                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2256            }
 02257            if (Client.AcceptLanguage != null)
 2258            {
 02259                if (_httpRequest.Headers.Contains("accept-language"))
 2260                {
 02261                    _httpRequest.Headers.Remove("accept-language");
 2262                }
 02263                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2264            }
 02265            if (clientRequestId != null)
 2266            {
 02267                if (_httpRequest.Headers.Contains("client-request-id"))
 2268                {
 02269                    _httpRequest.Headers.Remove("client-request-id");
 2270                }
 02271                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 2272            }
 02273            if (returnClientRequestId != null)
 2274            {
 02275                if (_httpRequest.Headers.Contains("return-client-request-id"))
 2276                {
 02277                    _httpRequest.Headers.Remove("return-client-request-id");
 2278                }
 02279                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 2280            }
 02281            if (ocpDate != null)
 2282            {
 02283                if (_httpRequest.Headers.Contains("ocp-date"))
 2284                {
 02285                    _httpRequest.Headers.Remove("ocp-date");
 2286                }
 02287                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2288            }
 02289            if (ifMatch != null)
 2290            {
 02291                if (_httpRequest.Headers.Contains("If-Match"))
 2292                {
 02293                    _httpRequest.Headers.Remove("If-Match");
 2294                }
 02295                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 2296            }
 02297            if (ifNoneMatch != null)
 2298            {
 02299                if (_httpRequest.Headers.Contains("If-None-Match"))
 2300                {
 02301                    _httpRequest.Headers.Remove("If-None-Match");
 2302                }
 02303                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 2304            }
 02305            if (ifModifiedSince != null)
 2306            {
 02307                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 2308                {
 02309                    _httpRequest.Headers.Remove("If-Modified-Since");
 2310                }
 02311                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 2312            }
 02313            if (ifUnmodifiedSince != null)
 2314            {
 02315                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 2316                {
 02317                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 2318                }
 02319                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 2320            }
 2321
 2322
 02323            if (customHeaders != null)
 2324            {
 02325                foreach(var _header in customHeaders)
 2326                {
 02327                    if (_httpRequest.Headers.Contains(_header.Key))
 2328                    {
 02329                        _httpRequest.Headers.Remove(_header.Key);
 2330                    }
 02331                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2332                }
 2333            }
 2334
 2335            // Serialize Request
 02336            string _requestContent = null;
 2337            // Set Credentials
 02338            if (Client.Credentials != null)
 2339            {
 02340                cancellationToken.ThrowIfCancellationRequested();
 02341                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2342            }
 2343            // Send Request
 02344            if (_shouldTrace)
 2345            {
 02346                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2347            }
 02348            cancellationToken.ThrowIfCancellationRequested();
 02349            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02350            if (_shouldTrace)
 2351            {
 02352                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2353            }
 02354            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02355            cancellationToken.ThrowIfCancellationRequested();
 02356            string _responseContent = null;
 02357            if ((int)_statusCode != 204)
 2358            {
 02359                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2360                try
 2361                {
 02362                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02363                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02364                    if (_errorBody != null)
 2365                    {
 02366                        ex.Body = _errorBody;
 2367                    }
 02368                }
 02369                catch (JsonException)
 2370                {
 2371                    // Ignore the exception
 02372                }
 02373                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02374                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02375                if (_shouldTrace)
 2376                {
 02377                    ServiceClientTracing.Error(_invocationId, ex);
 2378                }
 02379                _httpRequest.Dispose();
 02380                if (_httpResponse != null)
 2381                {
 02382                    _httpResponse.Dispose();
 2383                }
 02384                throw ex;
 2385            }
 2386            // Create Result
 02387            var _result = new AzureOperationHeaderResponse<TaskTerminateHeaders>();
 02388            _result.Request = _httpRequest;
 02389            _result.Response = _httpResponse;
 02390            if (_httpResponse.Headers.Contains("request-id"))
 2391            {
 02392                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2393            }
 2394            try
 2395            {
 02396                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskTerminateHeaders>(JsonSerializer.Create(
 02397            }
 02398            catch (JsonException ex)
 2399            {
 02400                _httpRequest.Dispose();
 02401                if (_httpResponse != null)
 2402                {
 02403                    _httpResponse.Dispose();
 2404                }
 02405                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2406            }
 02407            if (_shouldTrace)
 2408            {
 02409                ServiceClientTracing.Exit(_invocationId, _result);
 2410            }
 02411            return _result;
 02412        }
 2413
 2414        /// <summary>
 2415        /// Reactivates a Task, allowing it to run again even if its retry count has
 2416        /// been exhausted.
 2417        /// </summary>
 2418        /// <remarks>
 2419        /// Reactivation makes a Task eligible to be retried again up to its maximum
 2420        /// retry count. The Task's state is changed to active. As the Task is no
 2421        /// longer in the completed state, any previous exit code or failure
 2422        /// information is no longer available after reactivation. Each time a Task is
 2423        /// reactivated, its retry count is reset to 0. Reactivation will fail for
 2424        /// Tasks that are not completed or that previously completed successfully
 2425        /// (with an exit code of 0). Additionally, it will fail if the Job has
 2426        /// completed (or is terminating or deleting).
 2427        /// </remarks>
 2428        /// <param name='jobId'>
 2429        /// The ID of the Job containing the Task.
 2430        /// </param>
 2431        /// <param name='taskId'>
 2432        /// The ID of the Task to reactivate.
 2433        /// </param>
 2434        /// <param name='taskReactivateOptions'>
 2435        /// Additional parameters for the operation
 2436        /// </param>
 2437        /// <param name='customHeaders'>
 2438        /// Headers that will be added to request.
 2439        /// </param>
 2440        /// <param name='cancellationToken'>
 2441        /// The cancellation token.
 2442        /// </param>
 2443        /// <exception cref="BatchErrorException">
 2444        /// Thrown when the operation returned an invalid status code
 2445        /// </exception>
 2446        /// <exception cref="ValidationException">
 2447        /// Thrown when a required parameter is null
 2448        /// </exception>
 2449        /// <exception cref="System.ArgumentNullException">
 2450        /// Thrown when a required parameter is null
 2451        /// </exception>
 2452        /// <return>
 2453        /// A response object containing the response body and response headers.
 2454        /// </return>
 2455        public async Task<AzureOperationHeaderResponse<TaskReactivateHeaders>> ReactivateWithHttpMessagesAsync(string jo
 2456        {
 02457            if (Client.BatchUrl == null)
 2458            {
 02459                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 2460            }
 02461            if (jobId == null)
 2462            {
 02463                throw new ValidationException(ValidationRules.CannotBeNull, "jobId");
 2464            }
 02465            if (taskId == null)
 2466            {
 02467                throw new ValidationException(ValidationRules.CannotBeNull, "taskId");
 2468            }
 02469            if (Client.ApiVersion == null)
 2470            {
 02471                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 2472            }
 02473            int? timeout = default(int?);
 02474            if (taskReactivateOptions != null)
 2475            {
 02476                timeout = taskReactivateOptions.Timeout;
 2477            }
 02478            System.Guid? clientRequestId = default(System.Guid?);
 02479            if (taskReactivateOptions != null)
 2480            {
 02481                clientRequestId = taskReactivateOptions.ClientRequestId;
 2482            }
 02483            bool? returnClientRequestId = default(bool?);
 02484            if (taskReactivateOptions != null)
 2485            {
 02486                returnClientRequestId = taskReactivateOptions.ReturnClientRequestId;
 2487            }
 02488            System.DateTime? ocpDate = default(System.DateTime?);
 02489            if (taskReactivateOptions != null)
 2490            {
 02491                ocpDate = taskReactivateOptions.OcpDate;
 2492            }
 02493            string ifMatch = default(string);
 02494            if (taskReactivateOptions != null)
 2495            {
 02496                ifMatch = taskReactivateOptions.IfMatch;
 2497            }
 02498            string ifNoneMatch = default(string);
 02499            if (taskReactivateOptions != null)
 2500            {
 02501                ifNoneMatch = taskReactivateOptions.IfNoneMatch;
 2502            }
 02503            System.DateTime? ifModifiedSince = default(System.DateTime?);
 02504            if (taskReactivateOptions != null)
 2505            {
 02506                ifModifiedSince = taskReactivateOptions.IfModifiedSince;
 2507            }
 02508            System.DateTime? ifUnmodifiedSince = default(System.DateTime?);
 02509            if (taskReactivateOptions != null)
 2510            {
 02511                ifUnmodifiedSince = taskReactivateOptions.IfUnmodifiedSince;
 2512            }
 2513            // Tracing
 02514            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02515            string _invocationId = null;
 02516            if (_shouldTrace)
 2517            {
 02518                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02519                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02520                tracingParameters.Add("jobId", jobId);
 02521                tracingParameters.Add("taskId", taskId);
 02522                tracingParameters.Add("timeout", timeout);
 02523                tracingParameters.Add("clientRequestId", clientRequestId);
 02524                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02525                tracingParameters.Add("ocpDate", ocpDate);
 02526                tracingParameters.Add("ifMatch", ifMatch);
 02527                tracingParameters.Add("ifNoneMatch", ifNoneMatch);
 02528                tracingParameters.Add("ifModifiedSince", ifModifiedSince);
 02529                tracingParameters.Add("ifUnmodifiedSince", ifUnmodifiedSince);
 02530                tracingParameters.Add("cancellationToken", cancellationToken);
 02531                ServiceClientTracing.Enter(_invocationId, this, "Reactivate", tracingParameters);
 2532            }
 2533            // Construct URL
 02534            var _baseUrl = Client.BaseUri;
 02535            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "jobs/{jobId}/tasks/{taskId}/reactivate";
 02536            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 02537            _url = _url.Replace("{jobId}", System.Uri.EscapeDataString(jobId));
 02538            _url = _url.Replace("{taskId}", System.Uri.EscapeDataString(taskId));
 02539            List<string> _queryParameters = new List<string>();
 02540            if (Client.ApiVersion != null)
 2541            {
 02542                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 2543            }
 02544            if (timeout != null)
 2545            {
 02546                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 2547            }
 02548            if (_queryParameters.Count > 0)
 2549            {
 02550                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2551            }
 2552            // Create HTTP transport objects
 02553            var _httpRequest = new HttpRequestMessage();
 02554            HttpResponseMessage _httpResponse = null;
 02555            _httpRequest.Method = new HttpMethod("POST");
 02556            _httpRequest.RequestUri = new System.Uri(_url);
 2557            // Set Headers
 02558            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2559            {
 02560                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2561            }
 02562            if (Client.AcceptLanguage != null)
 2563            {
 02564                if (_httpRequest.Headers.Contains("accept-language"))
 2565                {
 02566                    _httpRequest.Headers.Remove("accept-language");
 2567                }
 02568                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2569            }
 02570            if (clientRequestId != null)
 2571            {
 02572                if (_httpRequest.Headers.Contains("client-request-id"))
 2573                {
 02574                    _httpRequest.Headers.Remove("client-request-id");
 2575                }
 02576                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 2577            }
 02578            if (returnClientRequestId != null)
 2579            {
 02580                if (_httpRequest.Headers.Contains("return-client-request-id"))
 2581                {
 02582                    _httpRequest.Headers.Remove("return-client-request-id");
 2583                }
 02584                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 2585            }
 02586            if (ocpDate != null)
 2587            {
 02588                if (_httpRequest.Headers.Contains("ocp-date"))
 2589                {
 02590                    _httpRequest.Headers.Remove("ocp-date");
 2591                }
 02592                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2593            }
 02594            if (ifMatch != null)
 2595            {
 02596                if (_httpRequest.Headers.Contains("If-Match"))
 2597                {
 02598                    _httpRequest.Headers.Remove("If-Match");
 2599                }
 02600                _httpRequest.Headers.TryAddWithoutValidation("If-Match", ifMatch);
 2601            }
 02602            if (ifNoneMatch != null)
 2603            {
 02604                if (_httpRequest.Headers.Contains("If-None-Match"))
 2605                {
 02606                    _httpRequest.Headers.Remove("If-None-Match");
 2607                }
 02608                _httpRequest.Headers.TryAddWithoutValidation("If-None-Match", ifNoneMatch);
 2609            }
 02610            if (ifModifiedSince != null)
 2611            {
 02612                if (_httpRequest.Headers.Contains("If-Modified-Since"))
 2613                {
 02614                    _httpRequest.Headers.Remove("If-Modified-Since");
 2615                }
 02616                _httpRequest.Headers.TryAddWithoutValidation("If-Modified-Since", SafeJsonConvert.SerializeObject(ifModi
 2617            }
 02618            if (ifUnmodifiedSince != null)
 2619            {
 02620                if (_httpRequest.Headers.Contains("If-Unmodified-Since"))
 2621                {
 02622                    _httpRequest.Headers.Remove("If-Unmodified-Since");
 2623                }
 02624                _httpRequest.Headers.TryAddWithoutValidation("If-Unmodified-Since", SafeJsonConvert.SerializeObject(ifUn
 2625            }
 2626
 2627
 02628            if (customHeaders != null)
 2629            {
 02630                foreach(var _header in customHeaders)
 2631                {
 02632                    if (_httpRequest.Headers.Contains(_header.Key))
 2633                    {
 02634                        _httpRequest.Headers.Remove(_header.Key);
 2635                    }
 02636                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2637                }
 2638            }
 2639
 2640            // Serialize Request
 02641            string _requestContent = null;
 2642            // Set Credentials
 02643            if (Client.Credentials != null)
 2644            {
 02645                cancellationToken.ThrowIfCancellationRequested();
 02646                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2647            }
 2648            // Send Request
 02649            if (_shouldTrace)
 2650            {
 02651                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2652            }
 02653            cancellationToken.ThrowIfCancellationRequested();
 02654            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02655            if (_shouldTrace)
 2656            {
 02657                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2658            }
 02659            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02660            cancellationToken.ThrowIfCancellationRequested();
 02661            string _responseContent = null;
 02662            if ((int)_statusCode != 204)
 2663            {
 02664                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2665                try
 2666                {
 02667                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02668                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02669                    if (_errorBody != null)
 2670                    {
 02671                        ex.Body = _errorBody;
 2672                    }
 02673                }
 02674                catch (JsonException)
 2675                {
 2676                    // Ignore the exception
 02677                }
 02678                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02679                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02680                if (_shouldTrace)
 2681                {
 02682                    ServiceClientTracing.Error(_invocationId, ex);
 2683                }
 02684                _httpRequest.Dispose();
 02685                if (_httpResponse != null)
 2686                {
 02687                    _httpResponse.Dispose();
 2688                }
 02689                throw ex;
 2690            }
 2691            // Create Result
 02692            var _result = new AzureOperationHeaderResponse<TaskReactivateHeaders>();
 02693            _result.Request = _httpRequest;
 02694            _result.Response = _httpResponse;
 02695            if (_httpResponse.Headers.Contains("request-id"))
 2696            {
 02697                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2698            }
 2699            try
 2700            {
 02701                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskReactivateHeaders>(JsonSerializer.Create
 02702            }
 02703            catch (JsonException ex)
 2704            {
 02705                _httpRequest.Dispose();
 02706                if (_httpResponse != null)
 2707                {
 02708                    _httpResponse.Dispose();
 2709                }
 02710                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2711            }
 02712            if (_shouldTrace)
 2713            {
 02714                ServiceClientTracing.Exit(_invocationId, _result);
 2715            }
 02716            return _result;
 02717        }
 2718
 2719        /// <summary>
 2720        /// Lists all of the Tasks that are associated with the specified Job.
 2721        /// </summary>
 2722        /// <remarks>
 2723        /// For multi-instance Tasks, information such as affinityId, executionInfo and
 2724        /// nodeInfo refer to the primary Task. Use the list subtasks API to retrieve
 2725        /// information about subtasks.
 2726        /// </remarks>
 2727        /// <param name='nextPageLink'>
 2728        /// The NextLink from the previous successful call to List operation.
 2729        /// </param>
 2730        /// <param name='taskListNextOptions'>
 2731        /// Additional parameters for the operation
 2732        /// </param>
 2733        /// <param name='customHeaders'>
 2734        /// Headers that will be added to request.
 2735        /// </param>
 2736        /// <param name='cancellationToken'>
 2737        /// The cancellation token.
 2738        /// </param>
 2739        /// <exception cref="BatchErrorException">
 2740        /// Thrown when the operation returned an invalid status code
 2741        /// </exception>
 2742        /// <exception cref="SerializationException">
 2743        /// Thrown when unable to deserialize the response
 2744        /// </exception>
 2745        /// <exception cref="ValidationException">
 2746        /// Thrown when a required parameter is null
 2747        /// </exception>
 2748        /// <exception cref="System.ArgumentNullException">
 2749        /// Thrown when a required parameter is null
 2750        /// </exception>
 2751        /// <return>
 2752        /// A response object containing the response body and response headers.
 2753        /// </return>
 2754        public async Task<AzureOperationResponse<IPage<CloudTask>,TaskListHeaders>> ListNextWithHttpMessagesAsync(string
 2755        {
 02756            if (nextPageLink == null)
 2757            {
 02758                throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink");
 2759            }
 02760            System.Guid? clientRequestId = default(System.Guid?);
 02761            if (taskListNextOptions != null)
 2762            {
 02763                clientRequestId = taskListNextOptions.ClientRequestId;
 2764            }
 02765            bool? returnClientRequestId = default(bool?);
 02766            if (taskListNextOptions != null)
 2767            {
 02768                returnClientRequestId = taskListNextOptions.ReturnClientRequestId;
 2769            }
 02770            System.DateTime? ocpDate = default(System.DateTime?);
 02771            if (taskListNextOptions != null)
 2772            {
 02773                ocpDate = taskListNextOptions.OcpDate;
 2774            }
 2775            // Tracing
 02776            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02777            string _invocationId = null;
 02778            if (_shouldTrace)
 2779            {
 02780                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02781                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02782                tracingParameters.Add("nextPageLink", nextPageLink);
 02783                tracingParameters.Add("clientRequestId", clientRequestId);
 02784                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 02785                tracingParameters.Add("ocpDate", ocpDate);
 02786                tracingParameters.Add("cancellationToken", cancellationToken);
 02787                ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters);
 2788            }
 2789            // Construct URL
 02790            string _url = "{nextLink}";
 02791            _url = _url.Replace("{nextLink}", nextPageLink);
 02792            List<string> _queryParameters = new List<string>();
 02793            if (_queryParameters.Count > 0)
 2794            {
 02795                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2796            }
 2797            // Create HTTP transport objects
 02798            var _httpRequest = new HttpRequestMessage();
 02799            HttpResponseMessage _httpResponse = null;
 02800            _httpRequest.Method = new HttpMethod("GET");
 02801            _httpRequest.RequestUri = new System.Uri(_url);
 2802            // Set Headers
 02803            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2804            {
 02805                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 2806            }
 02807            if (Client.AcceptLanguage != null)
 2808            {
 02809                if (_httpRequest.Headers.Contains("accept-language"))
 2810                {
 02811                    _httpRequest.Headers.Remove("accept-language");
 2812                }
 02813                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2814            }
 02815            if (clientRequestId != null)
 2816            {
 02817                if (_httpRequest.Headers.Contains("client-request-id"))
 2818                {
 02819                    _httpRequest.Headers.Remove("client-request-id");
 2820                }
 02821                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 2822            }
 02823            if (returnClientRequestId != null)
 2824            {
 02825                if (_httpRequest.Headers.Contains("return-client-request-id"))
 2826                {
 02827                    _httpRequest.Headers.Remove("return-client-request-id");
 2828                }
 02829                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 2830            }
 02831            if (ocpDate != null)
 2832            {
 02833                if (_httpRequest.Headers.Contains("ocp-date"))
 2834                {
 02835                    _httpRequest.Headers.Remove("ocp-date");
 2836                }
 02837                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 2838            }
 2839
 2840
 02841            if (customHeaders != null)
 2842            {
 02843                foreach(var _header in customHeaders)
 2844                {
 02845                    if (_httpRequest.Headers.Contains(_header.Key))
 2846                    {
 02847                        _httpRequest.Headers.Remove(_header.Key);
 2848                    }
 02849                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2850                }
 2851            }
 2852
 2853            // Serialize Request
 02854            string _requestContent = null;
 2855            // Set Credentials
 02856            if (Client.Credentials != null)
 2857            {
 02858                cancellationToken.ThrowIfCancellationRequested();
 02859                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2860            }
 2861            // Send Request
 02862            if (_shouldTrace)
 2863            {
 02864                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2865            }
 02866            cancellationToken.ThrowIfCancellationRequested();
 02867            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02868            if (_shouldTrace)
 2869            {
 02870                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2871            }
 02872            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02873            cancellationToken.ThrowIfCancellationRequested();
 02874            string _responseContent = null;
 02875            if ((int)_statusCode != 200)
 2876            {
 02877                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2878                try
 2879                {
 02880                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02881                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 02882                    if (_errorBody != null)
 2883                    {
 02884                        ex.Body = _errorBody;
 2885                    }
 02886                }
 02887                catch (JsonException)
 2888                {
 2889                    // Ignore the exception
 02890                }
 02891                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02892                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02893                if (_shouldTrace)
 2894                {
 02895                    ServiceClientTracing.Error(_invocationId, ex);
 2896                }
 02897                _httpRequest.Dispose();
 02898                if (_httpResponse != null)
 2899                {
 02900                    _httpResponse.Dispose();
 2901                }
 02902                throw ex;
 2903            }
 2904            // Create Result
 02905            var _result = new AzureOperationResponse<IPage<CloudTask>,TaskListHeaders>();
 02906            _result.Request = _httpRequest;
 02907            _result.Response = _httpResponse;
 02908            if (_httpResponse.Headers.Contains("request-id"))
 2909            {
 02910                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 2911            }
 2912            // Deserialize Response
 02913            if ((int)_statusCode == 200)
 2914            {
 02915                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2916                try
 2917                {
 02918                    _result.Body = SafeJsonConvert.DeserializeObject<Page<CloudTask>>(_responseContent, Client.Deseriali
 02919                }
 02920                catch (JsonException ex)
 2921                {
 02922                    _httpRequest.Dispose();
 02923                    if (_httpResponse != null)
 2924                    {
 02925                        _httpResponse.Dispose();
 2926                    }
 02927                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2928                }
 2929            }
 2930            try
 2931            {
 02932                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<TaskListHeaders>(JsonSerializer.Create(Clien
 02933            }
 02934            catch (JsonException ex)
 2935            {
 02936                _httpRequest.Dispose();
 02937                if (_httpResponse != null)
 2938                {
 02939                    _httpResponse.Dispose();
 2940                }
 02941                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 2942            }
 02943            if (_shouldTrace)
 2944            {
 02945                ServiceClientTracing.Exit(_invocationId, _result);
 2946            }
 02947            return _result;
 02948        }
 2949
 2950    }
 2951}