< Summary

Class:Microsoft.Azure.Batch.Protocol.ApplicationOperations
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\GeneratedProtocol\ApplicationOperations.cs
Covered lines:134
Uncovered lines:229
Coverable lines:363
Total lines:803
Line coverage:36.9% (134 of 363)
Covered branches:81
Total branches:220
Branch coverage:36.8% (81 of 220)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
ListWithHttpMessagesAsync()-56.8%58.97%
GetWithHttpMessagesAsync()-0%0%
ListNextWithHttpMessagesAsync()-53.21%53.13%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\GeneratedProtocol\ApplicationOperations.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    /// ApplicationOperations operations.
 28    /// </summary>
 29    internal partial class ApplicationOperations : IServiceOperations<BatchServiceClient>, IApplicationOperations
 30    {
 31        /// <summary>
 32        /// Initializes a new instance of the ApplicationOperations 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 ApplicationOperations(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>
 19252        public BatchServiceClient Client { get; private set; }
 53
 54        /// <summary>
 55        /// Lists all of the applications available in the specified Account.
 56        /// </summary>
 57        /// <remarks>
 58        /// This operation returns only Applications and versions that are available
 59        /// for use on Compute Nodes; that is, that can be used in an Package
 60        /// reference. For administrator information about applications and versions
 61        /// that are not yet available to Compute Nodes, use the Azure portal or the
 62        /// Azure Resource Manager API.
 63        /// </remarks>
 64        /// <param name='applicationListOptions'>
 65        /// Additional parameters for the operation
 66        /// </param>
 67        /// <param name='customHeaders'>
 68        /// Headers that will be added to request.
 69        /// </param>
 70        /// <param name='cancellationToken'>
 71        /// The cancellation token.
 72        /// </param>
 73        /// <exception cref="BatchErrorException">
 74        /// Thrown when the operation returned an invalid status code
 75        /// </exception>
 76        /// <exception cref="SerializationException">
 77        /// Thrown when unable to deserialize the response
 78        /// </exception>
 79        /// <exception cref="ValidationException">
 80        /// Thrown when a required parameter is null
 81        /// </exception>
 82        /// <exception cref="System.ArgumentNullException">
 83        /// Thrown when a required parameter is null
 84        /// </exception>
 85        /// <return>
 86        /// A response object containing the response body and response headers.
 87        /// </return>
 88        public async Task<AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>> ListWithHttpMessages
 89        {
 290            if (Client.BatchUrl == null)
 91            {
 092                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 93            }
 294            if (Client.ApiVersion == null)
 95            {
 096                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 97            }
 298            int? maxResults = default(int?);
 299            if (applicationListOptions != null)
 100            {
 2101                maxResults = applicationListOptions.MaxResults;
 102            }
 2103            int? timeout = default(int?);
 2104            if (applicationListOptions != null)
 105            {
 2106                timeout = applicationListOptions.Timeout;
 107            }
 2108            System.Guid? clientRequestId = default(System.Guid?);
 2109            if (applicationListOptions != null)
 110            {
 2111                clientRequestId = applicationListOptions.ClientRequestId;
 112            }
 2113            bool? returnClientRequestId = default(bool?);
 2114            if (applicationListOptions != null)
 115            {
 2116                returnClientRequestId = applicationListOptions.ReturnClientRequestId;
 117            }
 2118            System.DateTime? ocpDate = default(System.DateTime?);
 2119            if (applicationListOptions != null)
 120            {
 2121                ocpDate = applicationListOptions.OcpDate;
 122            }
 123            // Tracing
 2124            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2125            string _invocationId = null;
 2126            if (_shouldTrace)
 127            {
 0128                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0129                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0130                tracingParameters.Add("maxResults", maxResults);
 0131                tracingParameters.Add("timeout", timeout);
 0132                tracingParameters.Add("clientRequestId", clientRequestId);
 0133                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0134                tracingParameters.Add("ocpDate", ocpDate);
 0135                tracingParameters.Add("cancellationToken", cancellationToken);
 0136                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 137            }
 138            // Construct URL
 2139            var _baseUrl = Client.BaseUri;
 2140            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "applications";
 2141            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 2142            List<string> _queryParameters = new List<string>();
 2143            if (Client.ApiVersion != null)
 144            {
 2145                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 146            }
 2147            if (maxResults != null)
 148            {
 0149                _queryParameters.Add(string.Format("maxresults={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali
 150            }
 2151            if (timeout != null)
 152            {
 0153                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 154            }
 2155            if (_queryParameters.Count > 0)
 156            {
 2157                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 158            }
 159            // Create HTTP transport objects
 2160            var _httpRequest = new HttpRequestMessage();
 2161            HttpResponseMessage _httpResponse = null;
 2162            _httpRequest.Method = new HttpMethod("GET");
 2163            _httpRequest.RequestUri = new System.Uri(_url);
 164            // Set Headers
 2165            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 166            {
 2167                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 168            }
 2169            if (Client.AcceptLanguage != null)
 170            {
 2171                if (_httpRequest.Headers.Contains("accept-language"))
 172                {
 0173                    _httpRequest.Headers.Remove("accept-language");
 174                }
 2175                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 176            }
 2177            if (clientRequestId != null)
 178            {
 2179                if (_httpRequest.Headers.Contains("client-request-id"))
 180                {
 2181                    _httpRequest.Headers.Remove("client-request-id");
 182                }
 2183                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 184            }
 2185            if (returnClientRequestId != null)
 186            {
 0187                if (_httpRequest.Headers.Contains("return-client-request-id"))
 188                {
 0189                    _httpRequest.Headers.Remove("return-client-request-id");
 190                }
 0191                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 192            }
 2193            if (ocpDate != null)
 194            {
 0195                if (_httpRequest.Headers.Contains("ocp-date"))
 196                {
 0197                    _httpRequest.Headers.Remove("ocp-date");
 198                }
 0199                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 200            }
 201
 202
 2203            if (customHeaders != null)
 204            {
 0205                foreach(var _header in customHeaders)
 206                {
 0207                    if (_httpRequest.Headers.Contains(_header.Key))
 208                    {
 0209                        _httpRequest.Headers.Remove(_header.Key);
 210                    }
 0211                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 212                }
 213            }
 214
 215            // Serialize Request
 2216            string _requestContent = null;
 217            // Set Credentials
 2218            if (Client.Credentials != null)
 219            {
 2220                cancellationToken.ThrowIfCancellationRequested();
 2221                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 222            }
 223            // Send Request
 2224            if (_shouldTrace)
 225            {
 0226                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 227            }
 2228            cancellationToken.ThrowIfCancellationRequested();
 2229            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2230            if (_shouldTrace)
 231            {
 0232                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 233            }
 2234            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2235            cancellationToken.ThrowIfCancellationRequested();
 2236            string _responseContent = null;
 2237            if ((int)_statusCode != 200)
 238            {
 0239                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 240                try
 241                {
 0242                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0243                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0244                    if (_errorBody != null)
 245                    {
 0246                        ex.Body = _errorBody;
 247                    }
 0248                }
 0249                catch (JsonException)
 250                {
 251                    // Ignore the exception
 0252                }
 0253                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0254                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0255                if (_shouldTrace)
 256                {
 0257                    ServiceClientTracing.Error(_invocationId, ex);
 258                }
 0259                _httpRequest.Dispose();
 0260                if (_httpResponse != null)
 261                {
 0262                    _httpResponse.Dispose();
 263                }
 0264                throw ex;
 265            }
 266            // Create Result
 2267            var _result = new AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>();
 2268            _result.Request = _httpRequest;
 2269            _result.Response = _httpResponse;
 2270            if (_httpResponse.Headers.Contains("request-id"))
 271            {
 0272                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 273            }
 274            // Deserialize Response
 2275            if ((int)_statusCode == 200)
 276            {
 2277                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 278                try
 279                {
 2280                    _result.Body = SafeJsonConvert.DeserializeObject<Page<ApplicationSummary>>(_responseContent, Client.
 2281                }
 0282                catch (JsonException ex)
 283                {
 0284                    _httpRequest.Dispose();
 0285                    if (_httpResponse != null)
 286                    {
 0287                        _httpResponse.Dispose();
 288                    }
 0289                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 290                }
 291            }
 292            try
 293            {
 2294                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ApplicationListHeaders>(JsonSerializer.Creat
 2295            }
 0296            catch (JsonException ex)
 297            {
 0298                _httpRequest.Dispose();
 0299                if (_httpResponse != null)
 300                {
 0301                    _httpResponse.Dispose();
 302                }
 0303                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 304            }
 2305            if (_shouldTrace)
 306            {
 0307                ServiceClientTracing.Exit(_invocationId, _result);
 308            }
 2309            return _result;
 2310        }
 311
 312        /// <summary>
 313        /// Gets information about the specified Application.
 314        /// </summary>
 315        /// <remarks>
 316        /// This operation returns only Applications and versions that are available
 317        /// for use on Compute Nodes; that is, that can be used in an Package
 318        /// reference. For administrator information about Applications and versions
 319        /// that are not yet available to Compute Nodes, use the Azure portal or the
 320        /// Azure Resource Manager API.
 321        /// </remarks>
 322        /// <param name='applicationId'>
 323        /// The ID of the Application.
 324        /// </param>
 325        /// <param name='applicationGetOptions'>
 326        /// Additional parameters for the operation
 327        /// </param>
 328        /// <param name='customHeaders'>
 329        /// Headers that will be added to request.
 330        /// </param>
 331        /// <param name='cancellationToken'>
 332        /// The cancellation token.
 333        /// </param>
 334        /// <exception cref="BatchErrorException">
 335        /// Thrown when the operation returned an invalid status code
 336        /// </exception>
 337        /// <exception cref="SerializationException">
 338        /// Thrown when unable to deserialize the response
 339        /// </exception>
 340        /// <exception cref="ValidationException">
 341        /// Thrown when a required parameter is null
 342        /// </exception>
 343        /// <exception cref="System.ArgumentNullException">
 344        /// Thrown when a required parameter is null
 345        /// </exception>
 346        /// <return>
 347        /// A response object containing the response body and response headers.
 348        /// </return>
 349        public async Task<AzureOperationResponse<ApplicationSummary,ApplicationGetHeaders>> GetWithHttpMessagesAsync(str
 350        {
 0351            if (Client.BatchUrl == null)
 352            {
 0353                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.BatchUrl");
 354            }
 0355            if (applicationId == null)
 356            {
 0357                throw new ValidationException(ValidationRules.CannotBeNull, "applicationId");
 358            }
 0359            if (Client.ApiVersion == null)
 360            {
 0361                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 362            }
 0363            int? timeout = default(int?);
 0364            if (applicationGetOptions != null)
 365            {
 0366                timeout = applicationGetOptions.Timeout;
 367            }
 0368            System.Guid? clientRequestId = default(System.Guid?);
 0369            if (applicationGetOptions != null)
 370            {
 0371                clientRequestId = applicationGetOptions.ClientRequestId;
 372            }
 0373            bool? returnClientRequestId = default(bool?);
 0374            if (applicationGetOptions != null)
 375            {
 0376                returnClientRequestId = applicationGetOptions.ReturnClientRequestId;
 377            }
 0378            System.DateTime? ocpDate = default(System.DateTime?);
 0379            if (applicationGetOptions != null)
 380            {
 0381                ocpDate = applicationGetOptions.OcpDate;
 382            }
 383            // Tracing
 0384            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0385            string _invocationId = null;
 0386            if (_shouldTrace)
 387            {
 0388                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0389                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0390                tracingParameters.Add("applicationId", applicationId);
 0391                tracingParameters.Add("timeout", timeout);
 0392                tracingParameters.Add("clientRequestId", clientRequestId);
 0393                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0394                tracingParameters.Add("ocpDate", ocpDate);
 0395                tracingParameters.Add("cancellationToken", cancellationToken);
 0396                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 397            }
 398            // Construct URL
 0399            var _baseUrl = Client.BaseUri;
 0400            var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "applications/{applicationId}";
 0401            _url = _url.Replace("{batchUrl}", Client.BatchUrl);
 0402            _url = _url.Replace("{applicationId}", System.Uri.EscapeDataString(applicationId));
 0403            List<string> _queryParameters = new List<string>();
 0404            if (Client.ApiVersion != null)
 405            {
 0406                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 407            }
 0408            if (timeout != null)
 409            {
 0410                _queryParameters.Add(string.Format("timeout={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO
 411            }
 0412            if (_queryParameters.Count > 0)
 413            {
 0414                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 415            }
 416            // Create HTTP transport objects
 0417            var _httpRequest = new HttpRequestMessage();
 0418            HttpResponseMessage _httpResponse = null;
 0419            _httpRequest.Method = new HttpMethod("GET");
 0420            _httpRequest.RequestUri = new System.Uri(_url);
 421            // Set Headers
 0422            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 423            {
 0424                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 425            }
 0426            if (Client.AcceptLanguage != null)
 427            {
 0428                if (_httpRequest.Headers.Contains("accept-language"))
 429                {
 0430                    _httpRequest.Headers.Remove("accept-language");
 431                }
 0432                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 433            }
 0434            if (clientRequestId != null)
 435            {
 0436                if (_httpRequest.Headers.Contains("client-request-id"))
 437                {
 0438                    _httpRequest.Headers.Remove("client-request-id");
 439                }
 0440                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 441            }
 0442            if (returnClientRequestId != null)
 443            {
 0444                if (_httpRequest.Headers.Contains("return-client-request-id"))
 445                {
 0446                    _httpRequest.Headers.Remove("return-client-request-id");
 447                }
 0448                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 449            }
 0450            if (ocpDate != null)
 451            {
 0452                if (_httpRequest.Headers.Contains("ocp-date"))
 453                {
 0454                    _httpRequest.Headers.Remove("ocp-date");
 455                }
 0456                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 457            }
 458
 459
 0460            if (customHeaders != null)
 461            {
 0462                foreach(var _header in customHeaders)
 463                {
 0464                    if (_httpRequest.Headers.Contains(_header.Key))
 465                    {
 0466                        _httpRequest.Headers.Remove(_header.Key);
 467                    }
 0468                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 469                }
 470            }
 471
 472            // Serialize Request
 0473            string _requestContent = null;
 474            // Set Credentials
 0475            if (Client.Credentials != null)
 476            {
 0477                cancellationToken.ThrowIfCancellationRequested();
 0478                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 479            }
 480            // Send Request
 0481            if (_shouldTrace)
 482            {
 0483                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 484            }
 0485            cancellationToken.ThrowIfCancellationRequested();
 0486            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0487            if (_shouldTrace)
 488            {
 0489                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 490            }
 0491            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0492            cancellationToken.ThrowIfCancellationRequested();
 0493            string _responseContent = null;
 0494            if ((int)_statusCode != 200)
 495            {
 0496                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 497                try
 498                {
 0499                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0500                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0501                    if (_errorBody != null)
 502                    {
 0503                        ex.Body = _errorBody;
 504                    }
 0505                }
 0506                catch (JsonException)
 507                {
 508                    // Ignore the exception
 0509                }
 0510                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0511                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0512                if (_shouldTrace)
 513                {
 0514                    ServiceClientTracing.Error(_invocationId, ex);
 515                }
 0516                _httpRequest.Dispose();
 0517                if (_httpResponse != null)
 518                {
 0519                    _httpResponse.Dispose();
 520                }
 0521                throw ex;
 522            }
 523            // Create Result
 0524            var _result = new AzureOperationResponse<ApplicationSummary,ApplicationGetHeaders>();
 0525            _result.Request = _httpRequest;
 0526            _result.Response = _httpResponse;
 0527            if (_httpResponse.Headers.Contains("request-id"))
 528            {
 0529                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 530            }
 531            // Deserialize Response
 0532            if ((int)_statusCode == 200)
 533            {
 0534                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 535                try
 536                {
 0537                    _result.Body = SafeJsonConvert.DeserializeObject<ApplicationSummary>(_responseContent, Client.Deseri
 0538                }
 0539                catch (JsonException ex)
 540                {
 0541                    _httpRequest.Dispose();
 0542                    if (_httpResponse != null)
 543                    {
 0544                        _httpResponse.Dispose();
 545                    }
 0546                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 547                }
 548            }
 549            try
 550            {
 0551                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ApplicationGetHeaders>(JsonSerializer.Create
 0552            }
 0553            catch (JsonException ex)
 554            {
 0555                _httpRequest.Dispose();
 0556                if (_httpResponse != null)
 557                {
 0558                    _httpResponse.Dispose();
 559                }
 0560                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 561            }
 0562            if (_shouldTrace)
 563            {
 0564                ServiceClientTracing.Exit(_invocationId, _result);
 565            }
 0566            return _result;
 0567        }
 568
 569        /// <summary>
 570        /// Lists all of the applications available in the specified Account.
 571        /// </summary>
 572        /// <remarks>
 573        /// This operation returns only Applications and versions that are available
 574        /// for use on Compute Nodes; that is, that can be used in an Package
 575        /// reference. For administrator information about applications and versions
 576        /// that are not yet available to Compute Nodes, use the Azure portal or the
 577        /// Azure Resource Manager API.
 578        /// </remarks>
 579        /// <param name='nextPageLink'>
 580        /// The NextLink from the previous successful call to List operation.
 581        /// </param>
 582        /// <param name='applicationListNextOptions'>
 583        /// Additional parameters for the operation
 584        /// </param>
 585        /// <param name='customHeaders'>
 586        /// Headers that will be added to request.
 587        /// </param>
 588        /// <param name='cancellationToken'>
 589        /// The cancellation token.
 590        /// </param>
 591        /// <exception cref="BatchErrorException">
 592        /// Thrown when the operation returned an invalid status code
 593        /// </exception>
 594        /// <exception cref="SerializationException">
 595        /// Thrown when unable to deserialize the response
 596        /// </exception>
 597        /// <exception cref="ValidationException">
 598        /// Thrown when a required parameter is null
 599        /// </exception>
 600        /// <exception cref="System.ArgumentNullException">
 601        /// Thrown when a required parameter is null
 602        /// </exception>
 603        /// <return>
 604        /// A response object containing the response body and response headers.
 605        /// </return>
 606        public async Task<AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>> ListNextWithHttpMess
 607        {
 2608            if (nextPageLink == null)
 609            {
 0610                throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink");
 611            }
 2612            System.Guid? clientRequestId = default(System.Guid?);
 2613            if (applicationListNextOptions != null)
 614            {
 2615                clientRequestId = applicationListNextOptions.ClientRequestId;
 616            }
 2617            bool? returnClientRequestId = default(bool?);
 2618            if (applicationListNextOptions != null)
 619            {
 2620                returnClientRequestId = applicationListNextOptions.ReturnClientRequestId;
 621            }
 2622            System.DateTime? ocpDate = default(System.DateTime?);
 2623            if (applicationListNextOptions != null)
 624            {
 2625                ocpDate = applicationListNextOptions.OcpDate;
 626            }
 627            // Tracing
 2628            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2629            string _invocationId = null;
 2630            if (_shouldTrace)
 631            {
 0632                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0633                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0634                tracingParameters.Add("nextPageLink", nextPageLink);
 0635                tracingParameters.Add("clientRequestId", clientRequestId);
 0636                tracingParameters.Add("returnClientRequestId", returnClientRequestId);
 0637                tracingParameters.Add("ocpDate", ocpDate);
 0638                tracingParameters.Add("cancellationToken", cancellationToken);
 0639                ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters);
 640            }
 641            // Construct URL
 2642            string _url = "{nextLink}";
 2643            _url = _url.Replace("{nextLink}", nextPageLink);
 2644            List<string> _queryParameters = new List<string>();
 2645            if (_queryParameters.Count > 0)
 646            {
 0647                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 648            }
 649            // Create HTTP transport objects
 2650            var _httpRequest = new HttpRequestMessage();
 2651            HttpResponseMessage _httpResponse = null;
 2652            _httpRequest.Method = new HttpMethod("GET");
 2653            _httpRequest.RequestUri = new System.Uri(_url);
 654            // Set Headers
 2655            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 656            {
 2657                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", System.Guid.NewGuid().ToString());
 658            }
 2659            if (Client.AcceptLanguage != null)
 660            {
 2661                if (_httpRequest.Headers.Contains("accept-language"))
 662                {
 0663                    _httpRequest.Headers.Remove("accept-language");
 664                }
 2665                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 666            }
 2667            if (clientRequestId != null)
 668            {
 2669                if (_httpRequest.Headers.Contains("client-request-id"))
 670                {
 2671                    _httpRequest.Headers.Remove("client-request-id");
 672                }
 2673                _httpRequest.Headers.TryAddWithoutValidation("client-request-id", SafeJsonConvert.SerializeObject(client
 674            }
 2675            if (returnClientRequestId != null)
 676            {
 0677                if (_httpRequest.Headers.Contains("return-client-request-id"))
 678                {
 0679                    _httpRequest.Headers.Remove("return-client-request-id");
 680                }
 0681                _httpRequest.Headers.TryAddWithoutValidation("return-client-request-id", SafeJsonConvert.SerializeObject
 682            }
 2683            if (ocpDate != null)
 684            {
 0685                if (_httpRequest.Headers.Contains("ocp-date"))
 686                {
 0687                    _httpRequest.Headers.Remove("ocp-date");
 688                }
 0689                _httpRequest.Headers.TryAddWithoutValidation("ocp-date", SafeJsonConvert.SerializeObject(ocpDate, new Da
 690            }
 691
 692
 2693            if (customHeaders != null)
 694            {
 0695                foreach(var _header in customHeaders)
 696                {
 0697                    if (_httpRequest.Headers.Contains(_header.Key))
 698                    {
 0699                        _httpRequest.Headers.Remove(_header.Key);
 700                    }
 0701                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 702                }
 703            }
 704
 705            // Serialize Request
 2706            string _requestContent = null;
 707            // Set Credentials
 2708            if (Client.Credentials != null)
 709            {
 2710                cancellationToken.ThrowIfCancellationRequested();
 2711                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 712            }
 713            // Send Request
 2714            if (_shouldTrace)
 715            {
 0716                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 717            }
 2718            cancellationToken.ThrowIfCancellationRequested();
 2719            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2720            if (_shouldTrace)
 721            {
 0722                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 723            }
 2724            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2725            cancellationToken.ThrowIfCancellationRequested();
 2726            string _responseContent = null;
 2727            if ((int)_statusCode != 200)
 728            {
 0729                var ex = new BatchErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 730                try
 731                {
 0732                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0733                    BatchError _errorBody =  SafeJsonConvert.DeserializeObject<BatchError>(_responseContent, Client.Dese
 0734                    if (_errorBody != null)
 735                    {
 0736                        ex.Body = _errorBody;
 737                    }
 0738                }
 0739                catch (JsonException)
 740                {
 741                    // Ignore the exception
 0742                }
 0743                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0744                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0745                if (_shouldTrace)
 746                {
 0747                    ServiceClientTracing.Error(_invocationId, ex);
 748                }
 0749                _httpRequest.Dispose();
 0750                if (_httpResponse != null)
 751                {
 0752                    _httpResponse.Dispose();
 753                }
 0754                throw ex;
 755            }
 756            // Create Result
 2757            var _result = new AzureOperationResponse<IPage<ApplicationSummary>,ApplicationListHeaders>();
 2758            _result.Request = _httpRequest;
 2759            _result.Response = _httpResponse;
 2760            if (_httpResponse.Headers.Contains("request-id"))
 761            {
 0762                _result.RequestId = _httpResponse.Headers.GetValues("request-id").FirstOrDefault();
 763            }
 764            // Deserialize Response
 2765            if ((int)_statusCode == 200)
 766            {
 2767                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 768                try
 769                {
 2770                    _result.Body = SafeJsonConvert.DeserializeObject<Page<ApplicationSummary>>(_responseContent, Client.
 2771                }
 0772                catch (JsonException ex)
 773                {
 0774                    _httpRequest.Dispose();
 0775                    if (_httpResponse != null)
 776                    {
 0777                        _httpResponse.Dispose();
 778                    }
 0779                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 780                }
 781            }
 782            try
 783            {
 2784                _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<ApplicationListHeaders>(JsonSerializer.Creat
 2785            }
 0786            catch (JsonException ex)
 787            {
 0788                _httpRequest.Dispose();
 0789                if (_httpResponse != null)
 790                {
 0791                    _httpResponse.Dispose();
 792                }
 0793                throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().
 794            }
 2795            if (_shouldTrace)
 796            {
 0797                ServiceClientTracing.Exit(_invocationId, _result);
 798            }
 2799            return _result;
 2800        }
 801
 802    }
 803}