< Summary

Class:Microsoft.Azure.Graph.RBAC.OAuth2PermissionGrantOperations
Assembly:Microsoft.Azure.Graph.RBAC
File(s):C:\Git\azure-sdk-for-net\sdk\graphrbac\Microsoft.Azure.Graph.RBAC\src\Generated\OAuth2PermissionGrantOperations.cs
Covered lines:4
Uncovered lines:343
Coverable lines:347
Total lines:772
Line coverage:1.1% (4 of 347)
Covered branches:1
Total branches:210
Branch coverage:0.4% (1 of 210)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-0%100%
ListWithHttpMessagesAsync()-0%0%
CreateWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-0%0%
ListNextWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\graphrbac\Microsoft.Azure.Graph.RBAC\src\Generated\OAuth2PermissionGrantOperations.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.Graph.RBAC
 12{
 13    using Microsoft.Rest;
 14    using Microsoft.Rest.Azure;
 15    using Models;
 16    using Newtonsoft.Json;
 17    using System.Collections;
 18    using System.Collections.Generic;
 19    using System.Linq;
 20    using System.Net;
 21    using System.Net.Http;
 22    using System.Threading;
 23    using System.Threading.Tasks;
 24
 25    /// <summary>
 26    /// OAuth2PermissionGrantOperations operations.
 27    /// </summary>
 28    internal partial class OAuth2PermissionGrantOperations : IServiceOperations<GraphRbacManagementClient>, IOAuth2Permi
 29    {
 30        /// <summary>
 31        /// Initializes a new instance of the OAuth2PermissionGrantOperations class.
 32        /// </summary>
 33        /// <param name='client'>
 34        /// Reference to the service client.
 35        /// </param>
 36        /// <exception cref="System.ArgumentNullException">
 37        /// Thrown when a required parameter is null
 38        /// </exception>
 4639        internal OAuth2PermissionGrantOperations(GraphRbacManagementClient client)
 40        {
 4641            if (client == null)
 42            {
 043                throw new System.ArgumentNullException("client");
 44            }
 4645            Client = client;
 4646        }
 47
 48        /// <summary>
 49        /// Gets a reference to the GraphRbacManagementClient
 50        /// </summary>
 051        public GraphRbacManagementClient Client { get; private set; }
 52
 53        /// <summary>
 54        /// Queries OAuth2 permissions grants for the relevant SP ObjectId of an app.
 55        /// </summary>
 56        /// <param name='filter'>
 57        /// This is the Service Principal ObjectId associated with the app
 58        /// </param>
 59        /// <param name='customHeaders'>
 60        /// Headers that will be added to request.
 61        /// </param>
 62        /// <param name='cancellationToken'>
 63        /// The cancellation token.
 64        /// </param>
 65        /// <exception cref="CloudException">
 66        /// Thrown when the operation returned an invalid status code
 67        /// </exception>
 68        /// <exception cref="SerializationException">
 69        /// Thrown when unable to deserialize the response
 70        /// </exception>
 71        /// <exception cref="ValidationException">
 72        /// Thrown when a required parameter is null
 73        /// </exception>
 74        /// <exception cref="System.ArgumentNullException">
 75        /// Thrown when a required parameter is null
 76        /// </exception>
 77        /// <return>
 78        /// A response object containing the response body and response headers.
 79        /// </return>
 80        public async Task<AzureOperationResponse<IPage<OAuth2PermissionGrant>>> ListWithHttpMessagesAsync(string filter 
 81        {
 082            if (Client.ApiVersion == null)
 83            {
 084                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 85            }
 086            if (Client.TenantID == null)
 87            {
 088                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 89            }
 90            // Tracing
 091            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 092            string _invocationId = null;
 093            if (_shouldTrace)
 94            {
 095                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 096                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 097                tracingParameters.Add("filter", filter);
 098                tracingParameters.Add("cancellationToken", cancellationToken);
 099                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 100            }
 101            // Construct URL
 0102            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0103            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/oauth2
 0104            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0105            List<string> _queryParameters = new List<string>();
 0106            if (filter != null)
 107            {
 0108                _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter)));
 109            }
 0110            if (Client.ApiVersion != null)
 111            {
 0112                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 113            }
 0114            if (_queryParameters.Count > 0)
 115            {
 0116                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 117            }
 118            // Create HTTP transport objects
 0119            var _httpRequest = new HttpRequestMessage();
 0120            HttpResponseMessage _httpResponse = null;
 0121            _httpRequest.Method = new HttpMethod("GET");
 0122            _httpRequest.RequestUri = new System.Uri(_url);
 123            // Set Headers
 0124            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 125            {
 0126                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 127            }
 0128            if (Client.AcceptLanguage != null)
 129            {
 0130                if (_httpRequest.Headers.Contains("accept-language"))
 131                {
 0132                    _httpRequest.Headers.Remove("accept-language");
 133                }
 0134                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 135            }
 136
 137
 0138            if (customHeaders != null)
 139            {
 0140                foreach(var _header in customHeaders)
 141                {
 0142                    if (_httpRequest.Headers.Contains(_header.Key))
 143                    {
 0144                        _httpRequest.Headers.Remove(_header.Key);
 145                    }
 0146                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 147                }
 148            }
 149
 150            // Serialize Request
 0151            string _requestContent = null;
 152            // Set Credentials
 0153            if (Client.Credentials != null)
 154            {
 0155                cancellationToken.ThrowIfCancellationRequested();
 0156                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 157            }
 158            // Send Request
 0159            if (_shouldTrace)
 160            {
 0161                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 162            }
 0163            cancellationToken.ThrowIfCancellationRequested();
 0164            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0165            if (_shouldTrace)
 166            {
 0167                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 168            }
 0169            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0170            cancellationToken.ThrowIfCancellationRequested();
 0171            string _responseContent = null;
 0172            if ((int)_statusCode != 200)
 173            {
 0174                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 175                try
 176                {
 0177                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0178                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0179                    if (_errorBody != null)
 180                    {
 0181                        ex = new CloudException(_errorBody.Message);
 0182                        ex.Body = _errorBody;
 183                    }
 0184                }
 0185                catch (JsonException)
 186                {
 187                    // Ignore the exception
 0188                }
 0189                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0190                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0191                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 192                {
 0193                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 194                }
 0195                if (_shouldTrace)
 196                {
 0197                    ServiceClientTracing.Error(_invocationId, ex);
 198                }
 0199                _httpRequest.Dispose();
 0200                if (_httpResponse != null)
 201                {
 0202                    _httpResponse.Dispose();
 203                }
 0204                throw ex;
 205            }
 206            // Create Result
 0207            var _result = new AzureOperationResponse<IPage<OAuth2PermissionGrant>>();
 0208            _result.Request = _httpRequest;
 0209            _result.Response = _httpResponse;
 0210            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 211            {
 0212                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 213            }
 214            // Deserialize Response
 0215            if ((int)_statusCode == 200)
 216            {
 0217                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 218                try
 219                {
 0220                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<OAuth2PermissionGrant>>(_re
 0221                }
 0222                catch (JsonException ex)
 223                {
 0224                    _httpRequest.Dispose();
 0225                    if (_httpResponse != null)
 226                    {
 0227                        _httpResponse.Dispose();
 228                    }
 0229                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 230                }
 231            }
 0232            if (_shouldTrace)
 233            {
 0234                ServiceClientTracing.Exit(_invocationId, _result);
 235            }
 0236            return _result;
 0237        }
 238
 239        /// <summary>
 240        /// Grants OAuth2 permissions for the relevant resource Ids of an app.
 241        /// </summary>
 242        /// <param name='body'>
 243        /// The relevant app Service Principal Object Id and the Service Principal
 244        /// Object Id you want to grant.
 245        /// </param>
 246        /// <param name='customHeaders'>
 247        /// Headers that will be added to request.
 248        /// </param>
 249        /// <param name='cancellationToken'>
 250        /// The cancellation token.
 251        /// </param>
 252        /// <exception cref="CloudException">
 253        /// Thrown when the operation returned an invalid status code
 254        /// </exception>
 255        /// <exception cref="SerializationException">
 256        /// Thrown when unable to deserialize the response
 257        /// </exception>
 258        /// <exception cref="ValidationException">
 259        /// Thrown when a required parameter is null
 260        /// </exception>
 261        /// <exception cref="System.ArgumentNullException">
 262        /// Thrown when a required parameter is null
 263        /// </exception>
 264        /// <return>
 265        /// A response object containing the response body and response headers.
 266        /// </return>
 267        public async Task<AzureOperationResponse<OAuth2PermissionGrant>> CreateWithHttpMessagesAsync(OAuth2PermissionGra
 268        {
 0269            if (Client.ApiVersion == null)
 270            {
 0271                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 272            }
 0273            if (Client.TenantID == null)
 274            {
 0275                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 276            }
 277            // Tracing
 0278            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0279            string _invocationId = null;
 0280            if (_shouldTrace)
 281            {
 0282                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0283                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0284                tracingParameters.Add("body", body);
 0285                tracingParameters.Add("cancellationToken", cancellationToken);
 0286                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 287            }
 288            // Construct URL
 0289            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0290            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/oauth2
 0291            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0292            List<string> _queryParameters = new List<string>();
 0293            if (Client.ApiVersion != null)
 294            {
 0295                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 296            }
 0297            if (_queryParameters.Count > 0)
 298            {
 0299                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 300            }
 301            // Create HTTP transport objects
 0302            var _httpRequest = new HttpRequestMessage();
 0303            HttpResponseMessage _httpResponse = null;
 0304            _httpRequest.Method = new HttpMethod("POST");
 0305            _httpRequest.RequestUri = new System.Uri(_url);
 306            // Set Headers
 0307            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 308            {
 0309                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 310            }
 0311            if (Client.AcceptLanguage != null)
 312            {
 0313                if (_httpRequest.Headers.Contains("accept-language"))
 314                {
 0315                    _httpRequest.Headers.Remove("accept-language");
 316                }
 0317                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 318            }
 319
 320
 0321            if (customHeaders != null)
 322            {
 0323                foreach(var _header in customHeaders)
 324                {
 0325                    if (_httpRequest.Headers.Contains(_header.Key))
 326                    {
 0327                        _httpRequest.Headers.Remove(_header.Key);
 328                    }
 0329                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 330                }
 331            }
 332
 333            // Serialize Request
 0334            string _requestContent = null;
 0335            if(body != null)
 336            {
 0337                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings)
 0338                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0339                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 340            }
 341            // Set Credentials
 0342            if (Client.Credentials != null)
 343            {
 0344                cancellationToken.ThrowIfCancellationRequested();
 0345                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 346            }
 347            // Send Request
 0348            if (_shouldTrace)
 349            {
 0350                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 351            }
 0352            cancellationToken.ThrowIfCancellationRequested();
 0353            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0354            if (_shouldTrace)
 355            {
 0356                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 357            }
 0358            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0359            cancellationToken.ThrowIfCancellationRequested();
 0360            string _responseContent = null;
 0361            if ((int)_statusCode != 201)
 362            {
 0363                var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode
 364                try
 365                {
 0366                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0367                    CloudError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseC
 0368                    if (_errorBody != null)
 369                    {
 0370                        ex = new CloudException(_errorBody.Message);
 0371                        ex.Body = _errorBody;
 372                    }
 0373                }
 0374                catch (JsonException)
 375                {
 376                    // Ignore the exception
 0377                }
 0378                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0379                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0380                if (_httpResponse.Headers.Contains("x-ms-request-id"))
 381                {
 0382                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 383                }
 0384                if (_shouldTrace)
 385                {
 0386                    ServiceClientTracing.Error(_invocationId, ex);
 387                }
 0388                _httpRequest.Dispose();
 0389                if (_httpResponse != null)
 390                {
 0391                    _httpResponse.Dispose();
 392                }
 0393                throw ex;
 394            }
 395            // Create Result
 0396            var _result = new AzureOperationResponse<OAuth2PermissionGrant>();
 0397            _result.Request = _httpRequest;
 0398            _result.Response = _httpResponse;
 0399            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 400            {
 0401                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 402            }
 403            // Deserialize Response
 0404            if ((int)_statusCode == 201)
 405            {
 0406                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 407                try
 408                {
 0409                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OAuth2PermissionGrant>(_response
 0410                }
 0411                catch (JsonException ex)
 412                {
 0413                    _httpRequest.Dispose();
 0414                    if (_httpResponse != null)
 415                    {
 0416                        _httpResponse.Dispose();
 417                    }
 0418                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 419                }
 420            }
 0421            if (_shouldTrace)
 422            {
 0423                ServiceClientTracing.Exit(_invocationId, _result);
 424            }
 0425            return _result;
 0426        }
 427
 428        /// <summary>
 429        /// Delete a OAuth2 permission grant for the relevant resource Ids of an app.
 430        /// </summary>
 431        /// <param name='objectId'>
 432        /// The object ID of a permission grant.
 433        /// </param>
 434        /// <param name='customHeaders'>
 435        /// Headers that will be added to request.
 436        /// </param>
 437        /// <param name='cancellationToken'>
 438        /// The cancellation token.
 439        /// </param>
 440        /// <exception cref="GraphErrorException">
 441        /// Thrown when the operation returned an invalid status code
 442        /// </exception>
 443        /// <exception cref="ValidationException">
 444        /// Thrown when a required parameter is null
 445        /// </exception>
 446        /// <exception cref="System.ArgumentNullException">
 447        /// Thrown when a required parameter is null
 448        /// </exception>
 449        /// <return>
 450        /// A response object containing the response body and response headers.
 451        /// </return>
 452        public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string objectId, Dictionary<string, List<s
 453        {
 0454            if (objectId == null)
 455            {
 0456                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 457            }
 0458            if (Client.ApiVersion == null)
 459            {
 0460                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 461            }
 0462            if (Client.TenantID == null)
 463            {
 0464                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 465            }
 466            // Tracing
 0467            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0468            string _invocationId = null;
 0469            if (_shouldTrace)
 470            {
 0471                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0472                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0473                tracingParameters.Add("objectId", objectId);
 0474                tracingParameters.Add("cancellationToken", cancellationToken);
 0475                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 476            }
 477            // Construct URL
 0478            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0479            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/oauth2
 0480            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 0481            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0482            List<string> _queryParameters = new List<string>();
 0483            if (Client.ApiVersion != null)
 484            {
 0485                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 486            }
 0487            if (_queryParameters.Count > 0)
 488            {
 0489                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 490            }
 491            // Create HTTP transport objects
 0492            var _httpRequest = new HttpRequestMessage();
 0493            HttpResponseMessage _httpResponse = null;
 0494            _httpRequest.Method = new HttpMethod("DELETE");
 0495            _httpRequest.RequestUri = new System.Uri(_url);
 496            // Set Headers
 0497            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 498            {
 0499                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 500            }
 0501            if (Client.AcceptLanguage != null)
 502            {
 0503                if (_httpRequest.Headers.Contains("accept-language"))
 504                {
 0505                    _httpRequest.Headers.Remove("accept-language");
 506                }
 0507                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 508            }
 509
 510
 0511            if (customHeaders != null)
 512            {
 0513                foreach(var _header in customHeaders)
 514                {
 0515                    if (_httpRequest.Headers.Contains(_header.Key))
 516                    {
 0517                        _httpRequest.Headers.Remove(_header.Key);
 518                    }
 0519                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 520                }
 521            }
 522
 523            // Serialize Request
 0524            string _requestContent = null;
 525            // Set Credentials
 0526            if (Client.Credentials != null)
 527            {
 0528                cancellationToken.ThrowIfCancellationRequested();
 0529                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 530            }
 531            // Send Request
 0532            if (_shouldTrace)
 533            {
 0534                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 535            }
 0536            cancellationToken.ThrowIfCancellationRequested();
 0537            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0538            if (_shouldTrace)
 539            {
 0540                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 541            }
 0542            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0543            cancellationToken.ThrowIfCancellationRequested();
 0544            string _responseContent = null;
 0545            if ((int)_statusCode != 204)
 546            {
 0547                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 548                try
 549                {
 0550                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0551                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0552                    if (_errorBody != null)
 553                    {
 0554                        ex.Body = _errorBody;
 555                    }
 0556                }
 0557                catch (JsonException)
 558                {
 559                    // Ignore the exception
 0560                }
 0561                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0562                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0563                if (_shouldTrace)
 564                {
 0565                    ServiceClientTracing.Error(_invocationId, ex);
 566                }
 0567                _httpRequest.Dispose();
 0568                if (_httpResponse != null)
 569                {
 0570                    _httpResponse.Dispose();
 571                }
 0572                throw ex;
 573            }
 574            // Create Result
 0575            var _result = new AzureOperationResponse();
 0576            _result.Request = _httpRequest;
 0577            _result.Response = _httpResponse;
 0578            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 579            {
 0580                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 581            }
 0582            if (_shouldTrace)
 583            {
 0584                ServiceClientTracing.Exit(_invocationId, _result);
 585            }
 0586            return _result;
 0587        }
 588
 589        /// <summary>
 590        /// Gets the next page of OAuth2 permission grants
 591        /// </summary>
 592        /// <param name='nextLink'>
 593        /// Next link for the list operation.
 594        /// </param>
 595        /// <param name='customHeaders'>
 596        /// Headers that will be added to request.
 597        /// </param>
 598        /// <param name='cancellationToken'>
 599        /// The cancellation token.
 600        /// </param>
 601        /// <exception cref="GraphErrorException">
 602        /// Thrown when the operation returned an invalid status code
 603        /// </exception>
 604        /// <exception cref="SerializationException">
 605        /// Thrown when unable to deserialize the response
 606        /// </exception>
 607        /// <exception cref="ValidationException">
 608        /// Thrown when a required parameter is null
 609        /// </exception>
 610        /// <exception cref="System.ArgumentNullException">
 611        /// Thrown when a required parameter is null
 612        /// </exception>
 613        /// <return>
 614        /// A response object containing the response body and response headers.
 615        /// </return>
 616        public async Task<AzureOperationResponse<IPage<OAuth2PermissionGrant>>> ListNextWithHttpMessagesAsync(string nex
 617        {
 0618            if (nextLink == null)
 619            {
 0620                throw new ValidationException(ValidationRules.CannotBeNull, "nextLink");
 621            }
 0622            if (Client.ApiVersion == null)
 623            {
 0624                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 625            }
 0626            if (Client.TenantID == null)
 627            {
 0628                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 629            }
 630            // Tracing
 0631            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0632            string _invocationId = null;
 0633            if (_shouldTrace)
 634            {
 0635                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0636                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0637                tracingParameters.Add("nextLink", nextLink);
 0638                tracingParameters.Add("cancellationToken", cancellationToken);
 0639                ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters);
 640            }
 641            // Construct URL
 0642            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0643            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/{nextL
 0644            _url = _url.Replace("{nextLink}", nextLink);
 0645            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0646            List<string> _queryParameters = new List<string>();
 0647            if (Client.ApiVersion != null)
 648            {
 0649                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 650            }
 0651            if (_queryParameters.Count > 0)
 652            {
 0653                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 654            }
 655            // Create HTTP transport objects
 0656            var _httpRequest = new HttpRequestMessage();
 0657            HttpResponseMessage _httpResponse = null;
 0658            _httpRequest.Method = new HttpMethod("GET");
 0659            _httpRequest.RequestUri = new System.Uri(_url);
 660            // Set Headers
 0661            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 662            {
 0663                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 664            }
 0665            if (Client.AcceptLanguage != null)
 666            {
 0667                if (_httpRequest.Headers.Contains("accept-language"))
 668                {
 0669                    _httpRequest.Headers.Remove("accept-language");
 670                }
 0671                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 672            }
 673
 674
 0675            if (customHeaders != null)
 676            {
 0677                foreach(var _header in customHeaders)
 678                {
 0679                    if (_httpRequest.Headers.Contains(_header.Key))
 680                    {
 0681                        _httpRequest.Headers.Remove(_header.Key);
 682                    }
 0683                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 684                }
 685            }
 686
 687            // Serialize Request
 0688            string _requestContent = null;
 689            // Set Credentials
 0690            if (Client.Credentials != null)
 691            {
 0692                cancellationToken.ThrowIfCancellationRequested();
 0693                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 694            }
 695            // Send Request
 0696            if (_shouldTrace)
 697            {
 0698                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 699            }
 0700            cancellationToken.ThrowIfCancellationRequested();
 0701            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0702            if (_shouldTrace)
 703            {
 0704                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 705            }
 0706            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0707            cancellationToken.ThrowIfCancellationRequested();
 0708            string _responseContent = null;
 0709            if ((int)_statusCode != 200)
 710            {
 0711                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 712                try
 713                {
 0714                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0715                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0716                    if (_errorBody != null)
 717                    {
 0718                        ex.Body = _errorBody;
 719                    }
 0720                }
 0721                catch (JsonException)
 722                {
 723                    // Ignore the exception
 0724                }
 0725                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0726                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0727                if (_shouldTrace)
 728                {
 0729                    ServiceClientTracing.Error(_invocationId, ex);
 730                }
 0731                _httpRequest.Dispose();
 0732                if (_httpResponse != null)
 733                {
 0734                    _httpResponse.Dispose();
 735                }
 0736                throw ex;
 737            }
 738            // Create Result
 0739            var _result = new AzureOperationResponse<IPage<OAuth2PermissionGrant>>();
 0740            _result.Request = _httpRequest;
 0741            _result.Response = _httpResponse;
 0742            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 743            {
 0744                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 745            }
 746            // Deserialize Response
 0747            if ((int)_statusCode == 200)
 748            {
 0749                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 750                try
 751                {
 0752                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<OAuth2PermissionGrant>>(_re
 0753                }
 0754                catch (JsonException ex)
 755                {
 0756                    _httpRequest.Dispose();
 0757                    if (_httpResponse != null)
 758                    {
 0759                        _httpResponse.Dispose();
 760                    }
 0761                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 762                }
 763            }
 0764            if (_shouldTrace)
 765            {
 0766                ServiceClientTracing.Exit(_invocationId, _result);
 767            }
 0768            return _result;
 0769        }
 770
 771    }
 772}