< Summary

Class:Microsoft.Azure.Graph.RBAC.ServicePrincipalsOperations
Assembly:Microsoft.Azure.Graph.RBAC
File(s):C:\Git\azure-sdk-for-net\sdk\graphrbac\Microsoft.Azure.Graph.RBAC\src\Generated\ServicePrincipalsOperations.cs
Covered lines:103
Uncovered lines:918
Coverable lines:1021
Total lines:2205
Line coverage:10% (103 of 1021)
Covered branches:58
Total branches:620
Branch coverage:9.3% (58 of 620)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Client()-100%100%
CreateWithHttpMessagesAsync()-0%0%
ListWithHttpMessagesAsync()-57.47%55.56%
UpdateWithHttpMessagesAsync()-0%0%
DeleteWithHttpMessagesAsync()-0%0%
GetWithHttpMessagesAsync()-55.81%51.92%
ListOwnersWithHttpMessagesAsync()-0%0%
ListKeyCredentialsWithHttpMessagesAsync()-0%0%
UpdateKeyCredentialsWithHttpMessagesAsync()-0%0%
ListPasswordCredentialsWithHttpMessagesAsync()-0%0%
UpdatePasswordCredentialsWithHttpMessagesAsync()-0%0%
ListNextWithHttpMessagesAsync()-0%0%
ListOwnersNextWithHttpMessagesAsync()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\graphrbac\Microsoft.Azure.Graph.RBAC\src\Generated\ServicePrincipalsOperations.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 Microsoft.Rest.Azure.OData;
 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    /// ServicePrincipalsOperations operations.
 28    /// </summary>
 29    internal partial class ServicePrincipalsOperations : IServiceOperations<GraphRbacManagementClient>, IServicePrincipa
 30    {
 31        /// <summary>
 32        /// Initializes a new instance of the ServicePrincipalsOperations 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>
 4640        internal ServicePrincipalsOperations(GraphRbacManagementClient client)
 41        {
 4642            if (client == null)
 43            {
 044                throw new System.ArgumentNullException("client");
 45            }
 4646            Client = client;
 4647        }
 48
 49        /// <summary>
 50        /// Gets a reference to the GraphRbacManagementClient
 51        /// </summary>
 18652        public GraphRbacManagementClient Client { get; private set; }
 53
 54        /// <summary>
 55        /// Creates a service principal in the directory.
 56        /// </summary>
 57        /// <param name='parameters'>
 58        /// Parameters to create a service principal.
 59        /// </param>
 60        /// <param name='customHeaders'>
 61        /// Headers that will be added to request.
 62        /// </param>
 63        /// <param name='cancellationToken'>
 64        /// The cancellation token.
 65        /// </param>
 66        /// <exception cref="GraphErrorException">
 67        /// Thrown when the operation returned an invalid status code
 68        /// </exception>
 69        /// <exception cref="SerializationException">
 70        /// Thrown when unable to deserialize the response
 71        /// </exception>
 72        /// <exception cref="ValidationException">
 73        /// Thrown when a required parameter is null
 74        /// </exception>
 75        /// <exception cref="System.ArgumentNullException">
 76        /// Thrown when a required parameter is null
 77        /// </exception>
 78        /// <return>
 79        /// A response object containing the response body and response headers.
 80        /// </return>
 81        public async Task<AzureOperationResponse<ServicePrincipal>> CreateWithHttpMessagesAsync(ServicePrincipalCreatePa
 82        {
 083            if (parameters == null)
 84            {
 085                throw new ValidationException(ValidationRules.CannotBeNull, "parameters");
 86            }
 087            if (parameters != null)
 88            {
 089                parameters.Validate();
 90            }
 091            if (Client.ApiVersion == null)
 92            {
 093                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 94            }
 095            if (Client.TenantID == null)
 96            {
 097                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 98            }
 99            // Tracing
 0100            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0101            string _invocationId = null;
 0102            if (_shouldTrace)
 103            {
 0104                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0105                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0106                tracingParameters.Add("parameters", parameters);
 0107                tracingParameters.Add("cancellationToken", cancellationToken);
 0108                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
 109            }
 110            // Construct URL
 0111            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0112            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 0113            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0114            List<string> _queryParameters = new List<string>();
 0115            if (Client.ApiVersion != null)
 116            {
 0117                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 118            }
 0119            if (_queryParameters.Count > 0)
 120            {
 0121                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 122            }
 123            // Create HTTP transport objects
 0124            var _httpRequest = new HttpRequestMessage();
 0125            HttpResponseMessage _httpResponse = null;
 0126            _httpRequest.Method = new HttpMethod("POST");
 0127            _httpRequest.RequestUri = new System.Uri(_url);
 128            // Set Headers
 0129            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 130            {
 0131                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 132            }
 0133            if (Client.AcceptLanguage != null)
 134            {
 0135                if (_httpRequest.Headers.Contains("accept-language"))
 136                {
 0137                    _httpRequest.Headers.Remove("accept-language");
 138                }
 0139                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 140            }
 141
 142
 0143            if (customHeaders != null)
 144            {
 0145                foreach(var _header in customHeaders)
 146                {
 0147                    if (_httpRequest.Headers.Contains(_header.Key))
 148                    {
 0149                        _httpRequest.Headers.Remove(_header.Key);
 150                    }
 0151                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 152                }
 153            }
 154
 155            // Serialize Request
 0156            string _requestContent = null;
 0157            if(parameters != null)
 158            {
 0159                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet
 0160                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0161                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 162            }
 163            // Set Credentials
 0164            if (Client.Credentials != null)
 165            {
 0166                cancellationToken.ThrowIfCancellationRequested();
 0167                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 168            }
 169            // Send Request
 0170            if (_shouldTrace)
 171            {
 0172                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 173            }
 0174            cancellationToken.ThrowIfCancellationRequested();
 0175            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0176            if (_shouldTrace)
 177            {
 0178                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 179            }
 0180            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0181            cancellationToken.ThrowIfCancellationRequested();
 0182            string _responseContent = null;
 0183            if ((int)_statusCode != 201)
 184            {
 0185                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 186                try
 187                {
 0188                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0189                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0190                    if (_errorBody != null)
 191                    {
 0192                        ex.Body = _errorBody;
 193                    }
 0194                }
 0195                catch (JsonException)
 196                {
 197                    // Ignore the exception
 0198                }
 0199                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0200                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0201                if (_shouldTrace)
 202                {
 0203                    ServiceClientTracing.Error(_invocationId, ex);
 204                }
 0205                _httpRequest.Dispose();
 0206                if (_httpResponse != null)
 207                {
 0208                    _httpResponse.Dispose();
 209                }
 0210                throw ex;
 211            }
 212            // Create Result
 0213            var _result = new AzureOperationResponse<ServicePrincipal>();
 0214            _result.Request = _httpRequest;
 0215            _result.Response = _httpResponse;
 0216            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 217            {
 0218                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 219            }
 220            // Deserialize Response
 0221            if ((int)_statusCode == 201)
 222            {
 0223                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 224                try
 225                {
 0226                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ServicePrincipal>(_responseConte
 0227                }
 0228                catch (JsonException ex)
 229                {
 0230                    _httpRequest.Dispose();
 0231                    if (_httpResponse != null)
 232                    {
 0233                        _httpResponse.Dispose();
 234                    }
 0235                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 236                }
 237            }
 0238            if (_shouldTrace)
 239            {
 0240                ServiceClientTracing.Exit(_invocationId, _result);
 241            }
 0242            return _result;
 0243        }
 244
 245        /// <summary>
 246        /// Gets a list of service principals from the current tenant.
 247        /// </summary>
 248        /// <param name='odataQuery'>
 249        /// OData parameters to apply to the operation.
 250        /// </param>
 251        /// <param name='customHeaders'>
 252        /// Headers that will be added to request.
 253        /// </param>
 254        /// <param name='cancellationToken'>
 255        /// The cancellation token.
 256        /// </param>
 257        /// <exception cref="GraphErrorException">
 258        /// Thrown when the operation returned an invalid status code
 259        /// </exception>
 260        /// <exception cref="SerializationException">
 261        /// Thrown when unable to deserialize the response
 262        /// </exception>
 263        /// <exception cref="ValidationException">
 264        /// Thrown when a required parameter is null
 265        /// </exception>
 266        /// <exception cref="System.ArgumentNullException">
 267        /// Thrown when a required parameter is null
 268        /// </exception>
 269        /// <return>
 270        /// A response object containing the response body and response headers.
 271        /// </return>
 272        public async Task<AzureOperationResponse<IPage<ServicePrincipal>>> ListWithHttpMessagesAsync(ODataQuery<ServiceP
 273        {
 8274            if (Client.ApiVersion == null)
 275            {
 0276                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 277            }
 8278            if (Client.TenantID == null)
 279            {
 0280                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 281            }
 282            // Tracing
 8283            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 8284            string _invocationId = null;
 8285            if (_shouldTrace)
 286            {
 0287                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0288                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0289                tracingParameters.Add("odataQuery", odataQuery);
 0290                tracingParameters.Add("cancellationToken", cancellationToken);
 0291                ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters);
 292            }
 293            // Construct URL
 8294            var _baseUrl = Client.BaseUri.AbsoluteUri;
 8295            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 8296            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 8297            List<string> _queryParameters = new List<string>();
 8298            if (odataQuery != null)
 299            {
 4300                var _odataFilter = odataQuery.ToString();
 4301                if (!string.IsNullOrEmpty(_odataFilter))
 302                {
 4303                    _queryParameters.Add(_odataFilter);
 304                }
 305            }
 8306            if (Client.ApiVersion != null)
 307            {
 8308                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 309            }
 8310            if (_queryParameters.Count > 0)
 311            {
 8312                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 313            }
 314            // Create HTTP transport objects
 8315            var _httpRequest = new HttpRequestMessage();
 8316            HttpResponseMessage _httpResponse = null;
 8317            _httpRequest.Method = new HttpMethod("GET");
 8318            _httpRequest.RequestUri = new System.Uri(_url);
 319            // Set Headers
 8320            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 321            {
 8322                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 323            }
 8324            if (Client.AcceptLanguage != null)
 325            {
 8326                if (_httpRequest.Headers.Contains("accept-language"))
 327                {
 0328                    _httpRequest.Headers.Remove("accept-language");
 329                }
 8330                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 331            }
 332
 333
 8334            if (customHeaders != null)
 335            {
 0336                foreach(var _header in customHeaders)
 337                {
 0338                    if (_httpRequest.Headers.Contains(_header.Key))
 339                    {
 0340                        _httpRequest.Headers.Remove(_header.Key);
 341                    }
 0342                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 343                }
 344            }
 345
 346            // Serialize Request
 8347            string _requestContent = null;
 348            // Set Credentials
 8349            if (Client.Credentials != null)
 350            {
 8351                cancellationToken.ThrowIfCancellationRequested();
 8352                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 353            }
 354            // Send Request
 8355            if (_shouldTrace)
 356            {
 0357                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 358            }
 8359            cancellationToken.ThrowIfCancellationRequested();
 8360            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 8361            if (_shouldTrace)
 362            {
 0363                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 364            }
 8365            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 8366            cancellationToken.ThrowIfCancellationRequested();
 8367            string _responseContent = null;
 8368            if ((int)_statusCode != 200)
 369            {
 0370                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 371                try
 372                {
 0373                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0374                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0375                    if (_errorBody != null)
 376                    {
 0377                        ex.Body = _errorBody;
 378                    }
 0379                }
 0380                catch (JsonException)
 381                {
 382                    // Ignore the exception
 0383                }
 0384                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0385                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0386                if (_shouldTrace)
 387                {
 0388                    ServiceClientTracing.Error(_invocationId, ex);
 389                }
 0390                _httpRequest.Dispose();
 0391                if (_httpResponse != null)
 392                {
 0393                    _httpResponse.Dispose();
 394                }
 0395                throw ex;
 396            }
 397            // Create Result
 8398            var _result = new AzureOperationResponse<IPage<ServicePrincipal>>();
 8399            _result.Request = _httpRequest;
 8400            _result.Response = _httpResponse;
 8401            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 402            {
 0403                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 404            }
 405            // Deserialize Response
 8406            if ((int)_statusCode == 200)
 407            {
 8408                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 409                try
 410                {
 8411                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<ServicePrincipal>>(_respons
 8412                }
 0413                catch (JsonException ex)
 414                {
 0415                    _httpRequest.Dispose();
 0416                    if (_httpResponse != null)
 417                    {
 0418                        _httpResponse.Dispose();
 419                    }
 0420                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 421                }
 422            }
 8423            if (_shouldTrace)
 424            {
 0425                ServiceClientTracing.Exit(_invocationId, _result);
 426            }
 8427            return _result;
 8428        }
 429
 430        /// <summary>
 431        /// Updates a service principal in the directory.
 432        /// </summary>
 433        /// <param name='objectId'>
 434        /// The object ID of the service principal to delete.
 435        /// </param>
 436        /// <param name='parameters'>
 437        /// Parameters to update a service principal.
 438        /// </param>
 439        /// <param name='customHeaders'>
 440        /// Headers that will be added to request.
 441        /// </param>
 442        /// <param name='cancellationToken'>
 443        /// The cancellation token.
 444        /// </param>
 445        /// <exception cref="GraphErrorException">
 446        /// Thrown when the operation returned an invalid status code
 447        /// </exception>
 448        /// <exception cref="ValidationException">
 449        /// Thrown when a required parameter is null
 450        /// </exception>
 451        /// <exception cref="System.ArgumentNullException">
 452        /// Thrown when a required parameter is null
 453        /// </exception>
 454        /// <return>
 455        /// A response object containing the response body and response headers.
 456        /// </return>
 457        public async Task<AzureOperationResponse> UpdateWithHttpMessagesAsync(string objectId, ServicePrincipalUpdatePar
 458        {
 0459            if (objectId == null)
 460            {
 0461                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 462            }
 0463            if (parameters == null)
 464            {
 0465                throw new ValidationException(ValidationRules.CannotBeNull, "parameters");
 466            }
 0467            if (Client.ApiVersion == null)
 468            {
 0469                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 470            }
 0471            if (Client.TenantID == null)
 472            {
 0473                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 474            }
 475            // Tracing
 0476            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0477            string _invocationId = null;
 0478            if (_shouldTrace)
 479            {
 0480                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0481                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0482                tracingParameters.Add("objectId", objectId);
 0483                tracingParameters.Add("parameters", parameters);
 0484                tracingParameters.Add("cancellationToken", cancellationToken);
 0485                ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters);
 486            }
 487            // Construct URL
 0488            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0489            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 0490            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 0491            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0492            List<string> _queryParameters = new List<string>();
 0493            if (Client.ApiVersion != null)
 494            {
 0495                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 496            }
 0497            if (_queryParameters.Count > 0)
 498            {
 0499                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 500            }
 501            // Create HTTP transport objects
 0502            var _httpRequest = new HttpRequestMessage();
 0503            HttpResponseMessage _httpResponse = null;
 0504            _httpRequest.Method = new HttpMethod("PATCH");
 0505            _httpRequest.RequestUri = new System.Uri(_url);
 506            // Set Headers
 0507            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 508            {
 0509                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 510            }
 0511            if (Client.AcceptLanguage != null)
 512            {
 0513                if (_httpRequest.Headers.Contains("accept-language"))
 514                {
 0515                    _httpRequest.Headers.Remove("accept-language");
 516                }
 0517                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 518            }
 519
 520
 0521            if (customHeaders != null)
 522            {
 0523                foreach(var _header in customHeaders)
 524                {
 0525                    if (_httpRequest.Headers.Contains(_header.Key))
 526                    {
 0527                        _httpRequest.Headers.Remove(_header.Key);
 528                    }
 0529                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 530                }
 531            }
 532
 533            // Serialize Request
 0534            string _requestContent = null;
 0535            if(parameters != null)
 536            {
 0537                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet
 0538                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 0539                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 540            }
 541            // Set Credentials
 0542            if (Client.Credentials != null)
 543            {
 0544                cancellationToken.ThrowIfCancellationRequested();
 0545                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 546            }
 547            // Send Request
 0548            if (_shouldTrace)
 549            {
 0550                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 551            }
 0552            cancellationToken.ThrowIfCancellationRequested();
 0553            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0554            if (_shouldTrace)
 555            {
 0556                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 557            }
 0558            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0559            cancellationToken.ThrowIfCancellationRequested();
 0560            string _responseContent = null;
 0561            if ((int)_statusCode != 204)
 562            {
 0563                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 564                try
 565                {
 0566                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0567                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0568                    if (_errorBody != null)
 569                    {
 0570                        ex.Body = _errorBody;
 571                    }
 0572                }
 0573                catch (JsonException)
 574                {
 575                    // Ignore the exception
 0576                }
 0577                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0578                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0579                if (_shouldTrace)
 580                {
 0581                    ServiceClientTracing.Error(_invocationId, ex);
 582                }
 0583                _httpRequest.Dispose();
 0584                if (_httpResponse != null)
 585                {
 0586                    _httpResponse.Dispose();
 587                }
 0588                throw ex;
 589            }
 590            // Create Result
 0591            var _result = new AzureOperationResponse();
 0592            _result.Request = _httpRequest;
 0593            _result.Response = _httpResponse;
 0594            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 595            {
 0596                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 597            }
 0598            if (_shouldTrace)
 599            {
 0600                ServiceClientTracing.Exit(_invocationId, _result);
 601            }
 0602            return _result;
 0603        }
 604
 605        /// <summary>
 606        /// Deletes a service principal from the directory.
 607        /// </summary>
 608        /// <param name='objectId'>
 609        /// The object ID of the service principal to delete.
 610        /// </param>
 611        /// <param name='customHeaders'>
 612        /// Headers that will be added to request.
 613        /// </param>
 614        /// <param name='cancellationToken'>
 615        /// The cancellation token.
 616        /// </param>
 617        /// <exception cref="GraphErrorException">
 618        /// Thrown when the operation returned an invalid status code
 619        /// </exception>
 620        /// <exception cref="ValidationException">
 621        /// Thrown when a required parameter is null
 622        /// </exception>
 623        /// <exception cref="System.ArgumentNullException">
 624        /// Thrown when a required parameter is null
 625        /// </exception>
 626        /// <return>
 627        /// A response object containing the response body and response headers.
 628        /// </return>
 629        public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string objectId, Dictionary<string, List<s
 630        {
 0631            if (objectId == null)
 632            {
 0633                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 634            }
 0635            if (Client.ApiVersion == null)
 636            {
 0637                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 638            }
 0639            if (Client.TenantID == null)
 640            {
 0641                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 642            }
 643            // Tracing
 0644            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0645            string _invocationId = null;
 0646            if (_shouldTrace)
 647            {
 0648                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0649                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0650                tracingParameters.Add("objectId", objectId);
 0651                tracingParameters.Add("cancellationToken", cancellationToken);
 0652                ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters);
 653            }
 654            // Construct URL
 0655            var _baseUrl = Client.BaseUri.AbsoluteUri;
 0656            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 0657            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 0658            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 0659            List<string> _queryParameters = new List<string>();
 0660            if (Client.ApiVersion != null)
 661            {
 0662                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 663            }
 0664            if (_queryParameters.Count > 0)
 665            {
 0666                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 667            }
 668            // Create HTTP transport objects
 0669            var _httpRequest = new HttpRequestMessage();
 0670            HttpResponseMessage _httpResponse = null;
 0671            _httpRequest.Method = new HttpMethod("DELETE");
 0672            _httpRequest.RequestUri = new System.Uri(_url);
 673            // Set Headers
 0674            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 675            {
 0676                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 677            }
 0678            if (Client.AcceptLanguage != null)
 679            {
 0680                if (_httpRequest.Headers.Contains("accept-language"))
 681                {
 0682                    _httpRequest.Headers.Remove("accept-language");
 683                }
 0684                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 685            }
 686
 687
 0688            if (customHeaders != null)
 689            {
 0690                foreach(var _header in customHeaders)
 691                {
 0692                    if (_httpRequest.Headers.Contains(_header.Key))
 693                    {
 0694                        _httpRequest.Headers.Remove(_header.Key);
 695                    }
 0696                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 697                }
 698            }
 699
 700            // Serialize Request
 0701            string _requestContent = null;
 702            // Set Credentials
 0703            if (Client.Credentials != null)
 704            {
 0705                cancellationToken.ThrowIfCancellationRequested();
 0706                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 707            }
 708            // Send Request
 0709            if (_shouldTrace)
 710            {
 0711                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 712            }
 0713            cancellationToken.ThrowIfCancellationRequested();
 0714            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 0715            if (_shouldTrace)
 716            {
 0717                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 718            }
 0719            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 0720            cancellationToken.ThrowIfCancellationRequested();
 0721            string _responseContent = null;
 0722            if ((int)_statusCode != 204)
 723            {
 0724                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 725                try
 726                {
 0727                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0728                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0729                    if (_errorBody != null)
 730                    {
 0731                        ex.Body = _errorBody;
 732                    }
 0733                }
 0734                catch (JsonException)
 735                {
 736                    // Ignore the exception
 0737                }
 0738                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0739                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0740                if (_shouldTrace)
 741                {
 0742                    ServiceClientTracing.Error(_invocationId, ex);
 743                }
 0744                _httpRequest.Dispose();
 0745                if (_httpResponse != null)
 746                {
 0747                    _httpResponse.Dispose();
 748                }
 0749                throw ex;
 750            }
 751            // Create Result
 0752            var _result = new AzureOperationResponse();
 0753            _result.Request = _httpRequest;
 0754            _result.Response = _httpResponse;
 0755            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 756            {
 0757                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 758            }
 0759            if (_shouldTrace)
 760            {
 0761                ServiceClientTracing.Exit(_invocationId, _result);
 762            }
 0763            return _result;
 0764        }
 765
 766        /// <summary>
 767        /// Gets service principal information from the directory. Query by objectId or
 768        /// pass a filter to query by appId
 769        /// </summary>
 770        /// <param name='objectId'>
 771        /// The object ID of the service principal to get.
 772        /// </param>
 773        /// <param name='customHeaders'>
 774        /// Headers that will be added to request.
 775        /// </param>
 776        /// <param name='cancellationToken'>
 777        /// The cancellation token.
 778        /// </param>
 779        /// <exception cref="GraphErrorException">
 780        /// Thrown when the operation returned an invalid status code
 781        /// </exception>
 782        /// <exception cref="SerializationException">
 783        /// Thrown when unable to deserialize the response
 784        /// </exception>
 785        /// <exception cref="ValidationException">
 786        /// Thrown when a required parameter is null
 787        /// </exception>
 788        /// <exception cref="System.ArgumentNullException">
 789        /// Thrown when a required parameter is null
 790        /// </exception>
 791        /// <return>
 792        /// A response object containing the response body and response headers.
 793        /// </return>
 794        public async Task<AzureOperationResponse<ServicePrincipal>> GetWithHttpMessagesAsync(string objectId, Dictionary
 795        {
 2796            if (objectId == null)
 797            {
 0798                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 799            }
 2800            if (Client.ApiVersion == null)
 801            {
 0802                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 803            }
 2804            if (Client.TenantID == null)
 805            {
 0806                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 807            }
 808            // Tracing
 2809            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 2810            string _invocationId = null;
 2811            if (_shouldTrace)
 812            {
 0813                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 0814                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 0815                tracingParameters.Add("objectId", objectId);
 0816                tracingParameters.Add("cancellationToken", cancellationToken);
 0817                ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters);
 818            }
 819            // Construct URL
 2820            var _baseUrl = Client.BaseUri.AbsoluteUri;
 2821            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 2822            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 2823            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 2824            List<string> _queryParameters = new List<string>();
 2825            if (Client.ApiVersion != null)
 826            {
 2827                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 828            }
 2829            if (_queryParameters.Count > 0)
 830            {
 2831                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 832            }
 833            // Create HTTP transport objects
 2834            var _httpRequest = new HttpRequestMessage();
 2835            HttpResponseMessage _httpResponse = null;
 2836            _httpRequest.Method = new HttpMethod("GET");
 2837            _httpRequest.RequestUri = new System.Uri(_url);
 838            // Set Headers
 2839            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 840            {
 2841                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 842            }
 2843            if (Client.AcceptLanguage != null)
 844            {
 2845                if (_httpRequest.Headers.Contains("accept-language"))
 846                {
 0847                    _httpRequest.Headers.Remove("accept-language");
 848                }
 2849                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 850            }
 851
 852
 2853            if (customHeaders != null)
 854            {
 0855                foreach(var _header in customHeaders)
 856                {
 0857                    if (_httpRequest.Headers.Contains(_header.Key))
 858                    {
 0859                        _httpRequest.Headers.Remove(_header.Key);
 860                    }
 0861                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 862                }
 863            }
 864
 865            // Serialize Request
 2866            string _requestContent = null;
 867            // Set Credentials
 2868            if (Client.Credentials != null)
 869            {
 2870                cancellationToken.ThrowIfCancellationRequested();
 2871                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 872            }
 873            // Send Request
 2874            if (_shouldTrace)
 875            {
 0876                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 877            }
 2878            cancellationToken.ThrowIfCancellationRequested();
 2879            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2880            if (_shouldTrace)
 881            {
 0882                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 883            }
 2884            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 2885            cancellationToken.ThrowIfCancellationRequested();
 2886            string _responseContent = null;
 2887            if ((int)_statusCode != 200)
 888            {
 0889                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 890                try
 891                {
 0892                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 0893                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 0894                    if (_errorBody != null)
 895                    {
 0896                        ex.Body = _errorBody;
 897                    }
 0898                }
 0899                catch (JsonException)
 900                {
 901                    // Ignore the exception
 0902                }
 0903                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 0904                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 0905                if (_shouldTrace)
 906                {
 0907                    ServiceClientTracing.Error(_invocationId, ex);
 908                }
 0909                _httpRequest.Dispose();
 0910                if (_httpResponse != null)
 911                {
 0912                    _httpResponse.Dispose();
 913                }
 0914                throw ex;
 915            }
 916            // Create Result
 2917            var _result = new AzureOperationResponse<ServicePrincipal>();
 2918            _result.Request = _httpRequest;
 2919            _result.Response = _httpResponse;
 2920            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 921            {
 0922                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 923            }
 924            // Deserialize Response
 2925            if ((int)_statusCode == 200)
 926            {
 2927                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 928                try
 929                {
 2930                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ServicePrincipal>(_responseConte
 2931                }
 0932                catch (JsonException ex)
 933                {
 0934                    _httpRequest.Dispose();
 0935                    if (_httpResponse != null)
 936                    {
 0937                        _httpResponse.Dispose();
 938                    }
 0939                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 940                }
 941            }
 2942            if (_shouldTrace)
 943            {
 0944                ServiceClientTracing.Exit(_invocationId, _result);
 945            }
 2946            return _result;
 2947        }
 948
 949        /// <summary>
 950        /// Directory objects that are owners of this service principal.
 951        /// </summary>
 952        /// <remarks>
 953        /// The owners are a set of non-admin users who are allowed to modify this
 954        /// object.
 955        /// </remarks>
 956        /// <param name='objectId'>
 957        /// The object ID of the service principal for which to get owners.
 958        /// </param>
 959        /// <param name='customHeaders'>
 960        /// Headers that will be added to request.
 961        /// </param>
 962        /// <param name='cancellationToken'>
 963        /// The cancellation token.
 964        /// </param>
 965        /// <exception cref="GraphErrorException">
 966        /// Thrown when the operation returned an invalid status code
 967        /// </exception>
 968        /// <exception cref="SerializationException">
 969        /// Thrown when unable to deserialize the response
 970        /// </exception>
 971        /// <exception cref="ValidationException">
 972        /// Thrown when a required parameter is null
 973        /// </exception>
 974        /// <exception cref="System.ArgumentNullException">
 975        /// Thrown when a required parameter is null
 976        /// </exception>
 977        /// <return>
 978        /// A response object containing the response body and response headers.
 979        /// </return>
 980        public async Task<AzureOperationResponse<IPage<DirectoryObject>>> ListOwnersWithHttpMessagesAsync(string objectI
 981        {
 0982            if (objectId == null)
 983            {
 0984                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 985            }
 0986            if (Client.ApiVersion == null)
 987            {
 0988                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 989            }
 0990            if (Client.TenantID == null)
 991            {
 0992                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 993            }
 994            // Tracing
 0995            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 0996            string _invocationId = null;
 0997            if (_shouldTrace)
 998            {
 0999                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01000                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01001                tracingParameters.Add("objectId", objectId);
 01002                tracingParameters.Add("cancellationToken", cancellationToken);
 01003                ServiceClientTracing.Enter(_invocationId, this, "ListOwners", tracingParameters);
 1004            }
 1005            // Construct URL
 01006            var _baseUrl = Client.BaseUri.AbsoluteUri;
 01007            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 01008            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 01009            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 01010            List<string> _queryParameters = new List<string>();
 01011            if (Client.ApiVersion != null)
 1012            {
 01013                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1014            }
 01015            if (_queryParameters.Count > 0)
 1016            {
 01017                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1018            }
 1019            // Create HTTP transport objects
 01020            var _httpRequest = new HttpRequestMessage();
 01021            HttpResponseMessage _httpResponse = null;
 01022            _httpRequest.Method = new HttpMethod("GET");
 01023            _httpRequest.RequestUri = new System.Uri(_url);
 1024            // Set Headers
 01025            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1026            {
 01027                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1028            }
 01029            if (Client.AcceptLanguage != null)
 1030            {
 01031                if (_httpRequest.Headers.Contains("accept-language"))
 1032                {
 01033                    _httpRequest.Headers.Remove("accept-language");
 1034                }
 01035                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1036            }
 1037
 1038
 01039            if (customHeaders != null)
 1040            {
 01041                foreach(var _header in customHeaders)
 1042                {
 01043                    if (_httpRequest.Headers.Contains(_header.Key))
 1044                    {
 01045                        _httpRequest.Headers.Remove(_header.Key);
 1046                    }
 01047                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1048                }
 1049            }
 1050
 1051            // Serialize Request
 01052            string _requestContent = null;
 1053            // Set Credentials
 01054            if (Client.Credentials != null)
 1055            {
 01056                cancellationToken.ThrowIfCancellationRequested();
 01057                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1058            }
 1059            // Send Request
 01060            if (_shouldTrace)
 1061            {
 01062                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1063            }
 01064            cancellationToken.ThrowIfCancellationRequested();
 01065            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01066            if (_shouldTrace)
 1067            {
 01068                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1069            }
 01070            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01071            cancellationToken.ThrowIfCancellationRequested();
 01072            string _responseContent = null;
 01073            if ((int)_statusCode != 200)
 1074            {
 01075                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1076                try
 1077                {
 01078                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01079                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 01080                    if (_errorBody != null)
 1081                    {
 01082                        ex.Body = _errorBody;
 1083                    }
 01084                }
 01085                catch (JsonException)
 1086                {
 1087                    // Ignore the exception
 01088                }
 01089                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01090                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01091                if (_shouldTrace)
 1092                {
 01093                    ServiceClientTracing.Error(_invocationId, ex);
 1094                }
 01095                _httpRequest.Dispose();
 01096                if (_httpResponse != null)
 1097                {
 01098                    _httpResponse.Dispose();
 1099                }
 01100                throw ex;
 1101            }
 1102            // Create Result
 01103            var _result = new AzureOperationResponse<IPage<DirectoryObject>>();
 01104            _result.Request = _httpRequest;
 01105            _result.Response = _httpResponse;
 01106            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1107            {
 01108                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1109            }
 1110            // Deserialize Response
 01111            if ((int)_statusCode == 200)
 1112            {
 01113                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1114                try
 1115                {
 01116                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<DirectoryObject>>(_response
 01117                }
 01118                catch (JsonException ex)
 1119                {
 01120                    _httpRequest.Dispose();
 01121                    if (_httpResponse != null)
 1122                    {
 01123                        _httpResponse.Dispose();
 1124                    }
 01125                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1126                }
 1127            }
 01128            if (_shouldTrace)
 1129            {
 01130                ServiceClientTracing.Exit(_invocationId, _result);
 1131            }
 01132            return _result;
 01133        }
 1134
 1135        /// <summary>
 1136        /// Get the keyCredentials associated with the specified service principal.
 1137        /// </summary>
 1138        /// <param name='objectId'>
 1139        /// The object ID of the service principal for which to get keyCredentials.
 1140        /// </param>
 1141        /// <param name='customHeaders'>
 1142        /// Headers that will be added to request.
 1143        /// </param>
 1144        /// <param name='cancellationToken'>
 1145        /// The cancellation token.
 1146        /// </param>
 1147        /// <exception cref="GraphErrorException">
 1148        /// Thrown when the operation returned an invalid status code
 1149        /// </exception>
 1150        /// <exception cref="SerializationException">
 1151        /// Thrown when unable to deserialize the response
 1152        /// </exception>
 1153        /// <exception cref="ValidationException">
 1154        /// Thrown when a required parameter is null
 1155        /// </exception>
 1156        /// <exception cref="System.ArgumentNullException">
 1157        /// Thrown when a required parameter is null
 1158        /// </exception>
 1159        /// <return>
 1160        /// A response object containing the response body and response headers.
 1161        /// </return>
 1162        public async Task<AzureOperationResponse<IEnumerable<KeyCredential>>> ListKeyCredentialsWithHttpMessagesAsync(st
 1163        {
 01164            if (objectId == null)
 1165            {
 01166                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 1167            }
 01168            if (Client.ApiVersion == null)
 1169            {
 01170                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1171            }
 01172            if (Client.TenantID == null)
 1173            {
 01174                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 1175            }
 1176            // Tracing
 01177            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01178            string _invocationId = null;
 01179            if (_shouldTrace)
 1180            {
 01181                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01182                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01183                tracingParameters.Add("objectId", objectId);
 01184                tracingParameters.Add("cancellationToken", cancellationToken);
 01185                ServiceClientTracing.Enter(_invocationId, this, "ListKeyCredentials", tracingParameters);
 1186            }
 1187            // Construct URL
 01188            var _baseUrl = Client.BaseUri.AbsoluteUri;
 01189            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 01190            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 01191            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 01192            List<string> _queryParameters = new List<string>();
 01193            if (Client.ApiVersion != null)
 1194            {
 01195                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1196            }
 01197            if (_queryParameters.Count > 0)
 1198            {
 01199                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1200            }
 1201            // Create HTTP transport objects
 01202            var _httpRequest = new HttpRequestMessage();
 01203            HttpResponseMessage _httpResponse = null;
 01204            _httpRequest.Method = new HttpMethod("GET");
 01205            _httpRequest.RequestUri = new System.Uri(_url);
 1206            // Set Headers
 01207            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1208            {
 01209                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1210            }
 01211            if (Client.AcceptLanguage != null)
 1212            {
 01213                if (_httpRequest.Headers.Contains("accept-language"))
 1214                {
 01215                    _httpRequest.Headers.Remove("accept-language");
 1216                }
 01217                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1218            }
 1219
 1220
 01221            if (customHeaders != null)
 1222            {
 01223                foreach(var _header in customHeaders)
 1224                {
 01225                    if (_httpRequest.Headers.Contains(_header.Key))
 1226                    {
 01227                        _httpRequest.Headers.Remove(_header.Key);
 1228                    }
 01229                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1230                }
 1231            }
 1232
 1233            // Serialize Request
 01234            string _requestContent = null;
 1235            // Set Credentials
 01236            if (Client.Credentials != null)
 1237            {
 01238                cancellationToken.ThrowIfCancellationRequested();
 01239                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1240            }
 1241            // Send Request
 01242            if (_shouldTrace)
 1243            {
 01244                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1245            }
 01246            cancellationToken.ThrowIfCancellationRequested();
 01247            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01248            if (_shouldTrace)
 1249            {
 01250                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1251            }
 01252            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01253            cancellationToken.ThrowIfCancellationRequested();
 01254            string _responseContent = null;
 01255            if ((int)_statusCode != 200)
 1256            {
 01257                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1258                try
 1259                {
 01260                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01261                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 01262                    if (_errorBody != null)
 1263                    {
 01264                        ex.Body = _errorBody;
 1265                    }
 01266                }
 01267                catch (JsonException)
 1268                {
 1269                    // Ignore the exception
 01270                }
 01271                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01272                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01273                if (_shouldTrace)
 1274                {
 01275                    ServiceClientTracing.Error(_invocationId, ex);
 1276                }
 01277                _httpRequest.Dispose();
 01278                if (_httpResponse != null)
 1279                {
 01280                    _httpResponse.Dispose();
 1281                }
 01282                throw ex;
 1283            }
 1284            // Create Result
 01285            var _result = new AzureOperationResponse<IEnumerable<KeyCredential>>();
 01286            _result.Request = _httpRequest;
 01287            _result.Response = _httpResponse;
 01288            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1289            {
 01290                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1291            }
 1292            // Deserialize Response
 01293            if ((int)_statusCode == 200)
 1294            {
 01295                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1296                try
 1297                {
 01298                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<KeyCredential>>(_responseC
 01299                }
 01300                catch (JsonException ex)
 1301                {
 01302                    _httpRequest.Dispose();
 01303                    if (_httpResponse != null)
 1304                    {
 01305                        _httpResponse.Dispose();
 1306                    }
 01307                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1308                }
 1309            }
 01310            if (_shouldTrace)
 1311            {
 01312                ServiceClientTracing.Exit(_invocationId, _result);
 1313            }
 01314            return _result;
 01315        }
 1316
 1317        /// <summary>
 1318        /// Update the keyCredentials associated with a service principal.
 1319        /// </summary>
 1320        /// <param name='objectId'>
 1321        /// The object ID for which to get service principal information.
 1322        /// </param>
 1323        /// <param name='parameters'>
 1324        /// Parameters to update the keyCredentials of an existing service principal.
 1325        /// </param>
 1326        /// <param name='customHeaders'>
 1327        /// Headers that will be added to request.
 1328        /// </param>
 1329        /// <param name='cancellationToken'>
 1330        /// The cancellation token.
 1331        /// </param>
 1332        /// <exception cref="GraphErrorException">
 1333        /// Thrown when the operation returned an invalid status code
 1334        /// </exception>
 1335        /// <exception cref="ValidationException">
 1336        /// Thrown when a required parameter is null
 1337        /// </exception>
 1338        /// <exception cref="System.ArgumentNullException">
 1339        /// Thrown when a required parameter is null
 1340        /// </exception>
 1341        /// <return>
 1342        /// A response object containing the response body and response headers.
 1343        /// </return>
 1344        public async Task<AzureOperationResponse> UpdateKeyCredentialsWithHttpMessagesAsync(string objectId, KeyCredenti
 1345        {
 01346            if (objectId == null)
 1347            {
 01348                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 1349            }
 01350            if (parameters == null)
 1351            {
 01352                throw new ValidationException(ValidationRules.CannotBeNull, "parameters");
 1353            }
 01354            if (Client.ApiVersion == null)
 1355            {
 01356                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1357            }
 01358            if (Client.TenantID == null)
 1359            {
 01360                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 1361            }
 1362            // Tracing
 01363            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01364            string _invocationId = null;
 01365            if (_shouldTrace)
 1366            {
 01367                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01368                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01369                tracingParameters.Add("objectId", objectId);
 01370                tracingParameters.Add("parameters", parameters);
 01371                tracingParameters.Add("cancellationToken", cancellationToken);
 01372                ServiceClientTracing.Enter(_invocationId, this, "UpdateKeyCredentials", tracingParameters);
 1373            }
 1374            // Construct URL
 01375            var _baseUrl = Client.BaseUri.AbsoluteUri;
 01376            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 01377            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 01378            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 01379            List<string> _queryParameters = new List<string>();
 01380            if (Client.ApiVersion != null)
 1381            {
 01382                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1383            }
 01384            if (_queryParameters.Count > 0)
 1385            {
 01386                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1387            }
 1388            // Create HTTP transport objects
 01389            var _httpRequest = new HttpRequestMessage();
 01390            HttpResponseMessage _httpResponse = null;
 01391            _httpRequest.Method = new HttpMethod("PATCH");
 01392            _httpRequest.RequestUri = new System.Uri(_url);
 1393            // Set Headers
 01394            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1395            {
 01396                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1397            }
 01398            if (Client.AcceptLanguage != null)
 1399            {
 01400                if (_httpRequest.Headers.Contains("accept-language"))
 1401                {
 01402                    _httpRequest.Headers.Remove("accept-language");
 1403                }
 01404                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1405            }
 1406
 1407
 01408            if (customHeaders != null)
 1409            {
 01410                foreach(var _header in customHeaders)
 1411                {
 01412                    if (_httpRequest.Headers.Contains(_header.Key))
 1413                    {
 01414                        _httpRequest.Headers.Remove(_header.Key);
 1415                    }
 01416                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1417                }
 1418            }
 1419
 1420            // Serialize Request
 01421            string _requestContent = null;
 01422            if(parameters != null)
 1423            {
 01424                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet
 01425                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01426                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1427            }
 1428            // Set Credentials
 01429            if (Client.Credentials != null)
 1430            {
 01431                cancellationToken.ThrowIfCancellationRequested();
 01432                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1433            }
 1434            // Send Request
 01435            if (_shouldTrace)
 1436            {
 01437                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1438            }
 01439            cancellationToken.ThrowIfCancellationRequested();
 01440            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01441            if (_shouldTrace)
 1442            {
 01443                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1444            }
 01445            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01446            cancellationToken.ThrowIfCancellationRequested();
 01447            string _responseContent = null;
 01448            if ((int)_statusCode != 204)
 1449            {
 01450                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1451                try
 1452                {
 01453                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01454                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 01455                    if (_errorBody != null)
 1456                    {
 01457                        ex.Body = _errorBody;
 1458                    }
 01459                }
 01460                catch (JsonException)
 1461                {
 1462                    // Ignore the exception
 01463                }
 01464                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01465                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01466                if (_shouldTrace)
 1467                {
 01468                    ServiceClientTracing.Error(_invocationId, ex);
 1469                }
 01470                _httpRequest.Dispose();
 01471                if (_httpResponse != null)
 1472                {
 01473                    _httpResponse.Dispose();
 1474                }
 01475                throw ex;
 1476            }
 1477            // Create Result
 01478            var _result = new AzureOperationResponse();
 01479            _result.Request = _httpRequest;
 01480            _result.Response = _httpResponse;
 01481            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1482            {
 01483                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1484            }
 01485            if (_shouldTrace)
 1486            {
 01487                ServiceClientTracing.Exit(_invocationId, _result);
 1488            }
 01489            return _result;
 01490        }
 1491
 1492        /// <summary>
 1493        /// Gets the passwordCredentials associated with a service principal.
 1494        /// </summary>
 1495        /// <param name='objectId'>
 1496        /// The object ID of the service principal.
 1497        /// </param>
 1498        /// <param name='customHeaders'>
 1499        /// Headers that will be added to request.
 1500        /// </param>
 1501        /// <param name='cancellationToken'>
 1502        /// The cancellation token.
 1503        /// </param>
 1504        /// <exception cref="GraphErrorException">
 1505        /// Thrown when the operation returned an invalid status code
 1506        /// </exception>
 1507        /// <exception cref="SerializationException">
 1508        /// Thrown when unable to deserialize the response
 1509        /// </exception>
 1510        /// <exception cref="ValidationException">
 1511        /// Thrown when a required parameter is null
 1512        /// </exception>
 1513        /// <exception cref="System.ArgumentNullException">
 1514        /// Thrown when a required parameter is null
 1515        /// </exception>
 1516        /// <return>
 1517        /// A response object containing the response body and response headers.
 1518        /// </return>
 1519        public async Task<AzureOperationResponse<IEnumerable<PasswordCredential>>> ListPasswordCredentialsWithHttpMessag
 1520        {
 01521            if (objectId == null)
 1522            {
 01523                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 1524            }
 01525            if (Client.ApiVersion == null)
 1526            {
 01527                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1528            }
 01529            if (Client.TenantID == null)
 1530            {
 01531                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 1532            }
 1533            // Tracing
 01534            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01535            string _invocationId = null;
 01536            if (_shouldTrace)
 1537            {
 01538                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01539                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01540                tracingParameters.Add("objectId", objectId);
 01541                tracingParameters.Add("cancellationToken", cancellationToken);
 01542                ServiceClientTracing.Enter(_invocationId, this, "ListPasswordCredentials", tracingParameters);
 1543            }
 1544            // Construct URL
 01545            var _baseUrl = Client.BaseUri.AbsoluteUri;
 01546            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 01547            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 01548            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 01549            List<string> _queryParameters = new List<string>();
 01550            if (Client.ApiVersion != null)
 1551            {
 01552                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1553            }
 01554            if (_queryParameters.Count > 0)
 1555            {
 01556                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1557            }
 1558            // Create HTTP transport objects
 01559            var _httpRequest = new HttpRequestMessage();
 01560            HttpResponseMessage _httpResponse = null;
 01561            _httpRequest.Method = new HttpMethod("GET");
 01562            _httpRequest.RequestUri = new System.Uri(_url);
 1563            // Set Headers
 01564            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1565            {
 01566                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1567            }
 01568            if (Client.AcceptLanguage != null)
 1569            {
 01570                if (_httpRequest.Headers.Contains("accept-language"))
 1571                {
 01572                    _httpRequest.Headers.Remove("accept-language");
 1573                }
 01574                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1575            }
 1576
 1577
 01578            if (customHeaders != null)
 1579            {
 01580                foreach(var _header in customHeaders)
 1581                {
 01582                    if (_httpRequest.Headers.Contains(_header.Key))
 1583                    {
 01584                        _httpRequest.Headers.Remove(_header.Key);
 1585                    }
 01586                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1587                }
 1588            }
 1589
 1590            // Serialize Request
 01591            string _requestContent = null;
 1592            // Set Credentials
 01593            if (Client.Credentials != null)
 1594            {
 01595                cancellationToken.ThrowIfCancellationRequested();
 01596                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1597            }
 1598            // Send Request
 01599            if (_shouldTrace)
 1600            {
 01601                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1602            }
 01603            cancellationToken.ThrowIfCancellationRequested();
 01604            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01605            if (_shouldTrace)
 1606            {
 01607                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1608            }
 01609            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01610            cancellationToken.ThrowIfCancellationRequested();
 01611            string _responseContent = null;
 01612            if ((int)_statusCode != 200)
 1613            {
 01614                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1615                try
 1616                {
 01617                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01618                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 01619                    if (_errorBody != null)
 1620                    {
 01621                        ex.Body = _errorBody;
 1622                    }
 01623                }
 01624                catch (JsonException)
 1625                {
 1626                    // Ignore the exception
 01627                }
 01628                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01629                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01630                if (_shouldTrace)
 1631                {
 01632                    ServiceClientTracing.Error(_invocationId, ex);
 1633                }
 01634                _httpRequest.Dispose();
 01635                if (_httpResponse != null)
 1636                {
 01637                    _httpResponse.Dispose();
 1638                }
 01639                throw ex;
 1640            }
 1641            // Create Result
 01642            var _result = new AzureOperationResponse<IEnumerable<PasswordCredential>>();
 01643            _result.Request = _httpRequest;
 01644            _result.Response = _httpResponse;
 01645            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1646            {
 01647                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1648            }
 1649            // Deserialize Response
 01650            if ((int)_statusCode == 200)
 1651            {
 01652                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 1653                try
 1654                {
 01655                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<PasswordCredential>>(_resp
 01656                }
 01657                catch (JsonException ex)
 1658                {
 01659                    _httpRequest.Dispose();
 01660                    if (_httpResponse != null)
 1661                    {
 01662                        _httpResponse.Dispose();
 1663                    }
 01664                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 1665                }
 1666            }
 01667            if (_shouldTrace)
 1668            {
 01669                ServiceClientTracing.Exit(_invocationId, _result);
 1670            }
 01671            return _result;
 01672        }
 1673
 1674        /// <summary>
 1675        /// Updates the passwordCredentials associated with a service principal.
 1676        /// </summary>
 1677        /// <param name='objectId'>
 1678        /// The object ID of the service principal.
 1679        /// </param>
 1680        /// <param name='parameters'>
 1681        /// Parameters to update the passwordCredentials of an existing service
 1682        /// principal.
 1683        /// </param>
 1684        /// <param name='customHeaders'>
 1685        /// Headers that will be added to request.
 1686        /// </param>
 1687        /// <param name='cancellationToken'>
 1688        /// The cancellation token.
 1689        /// </param>
 1690        /// <exception cref="GraphErrorException">
 1691        /// Thrown when the operation returned an invalid status code
 1692        /// </exception>
 1693        /// <exception cref="ValidationException">
 1694        /// Thrown when a required parameter is null
 1695        /// </exception>
 1696        /// <exception cref="System.ArgumentNullException">
 1697        /// Thrown when a required parameter is null
 1698        /// </exception>
 1699        /// <return>
 1700        /// A response object containing the response body and response headers.
 1701        /// </return>
 1702        public async Task<AzureOperationResponse> UpdatePasswordCredentialsWithHttpMessagesAsync(string objectId, Passwo
 1703        {
 01704            if (objectId == null)
 1705            {
 01706                throw new ValidationException(ValidationRules.CannotBeNull, "objectId");
 1707            }
 01708            if (parameters == null)
 1709            {
 01710                throw new ValidationException(ValidationRules.CannotBeNull, "parameters");
 1711            }
 01712            if (Client.ApiVersion == null)
 1713            {
 01714                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1715            }
 01716            if (Client.TenantID == null)
 1717            {
 01718                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 1719            }
 1720            // Tracing
 01721            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01722            string _invocationId = null;
 01723            if (_shouldTrace)
 1724            {
 01725                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01726                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01727                tracingParameters.Add("objectId", objectId);
 01728                tracingParameters.Add("parameters", parameters);
 01729                tracingParameters.Add("cancellationToken", cancellationToken);
 01730                ServiceClientTracing.Enter(_invocationId, this, "UpdatePasswordCredentials", tracingParameters);
 1731            }
 1732            // Construct URL
 01733            var _baseUrl = Client.BaseUri.AbsoluteUri;
 01734            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic
 01735            _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId));
 01736            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 01737            List<string> _queryParameters = new List<string>();
 01738            if (Client.ApiVersion != null)
 1739            {
 01740                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1741            }
 01742            if (_queryParameters.Count > 0)
 1743            {
 01744                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1745            }
 1746            // Create HTTP transport objects
 01747            var _httpRequest = new HttpRequestMessage();
 01748            HttpResponseMessage _httpResponse = null;
 01749            _httpRequest.Method = new HttpMethod("PATCH");
 01750            _httpRequest.RequestUri = new System.Uri(_url);
 1751            // Set Headers
 01752            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1753            {
 01754                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1755            }
 01756            if (Client.AcceptLanguage != null)
 1757            {
 01758                if (_httpRequest.Headers.Contains("accept-language"))
 1759                {
 01760                    _httpRequest.Headers.Remove("accept-language");
 1761                }
 01762                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1763            }
 1764
 1765
 01766            if (customHeaders != null)
 1767            {
 01768                foreach(var _header in customHeaders)
 1769                {
 01770                    if (_httpRequest.Headers.Contains(_header.Key))
 1771                    {
 01772                        _httpRequest.Headers.Remove(_header.Key);
 1773                    }
 01774                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1775                }
 1776            }
 1777
 1778            // Serialize Request
 01779            string _requestContent = null;
 01780            if(parameters != null)
 1781            {
 01782                _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet
 01783                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
 01784                _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio
 1785            }
 1786            // Set Credentials
 01787            if (Client.Credentials != null)
 1788            {
 01789                cancellationToken.ThrowIfCancellationRequested();
 01790                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1791            }
 1792            // Send Request
 01793            if (_shouldTrace)
 1794            {
 01795                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1796            }
 01797            cancellationToken.ThrowIfCancellationRequested();
 01798            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01799            if (_shouldTrace)
 1800            {
 01801                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1802            }
 01803            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01804            cancellationToken.ThrowIfCancellationRequested();
 01805            string _responseContent = null;
 01806            if ((int)_statusCode != 204)
 1807            {
 01808                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1809                try
 1810                {
 01811                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01812                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 01813                    if (_errorBody != null)
 1814                    {
 01815                        ex.Body = _errorBody;
 1816                    }
 01817                }
 01818                catch (JsonException)
 1819                {
 1820                    // Ignore the exception
 01821                }
 01822                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01823                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01824                if (_shouldTrace)
 1825                {
 01826                    ServiceClientTracing.Error(_invocationId, ex);
 1827                }
 01828                _httpRequest.Dispose();
 01829                if (_httpResponse != null)
 1830                {
 01831                    _httpResponse.Dispose();
 1832                }
 01833                throw ex;
 1834            }
 1835            // Create Result
 01836            var _result = new AzureOperationResponse();
 01837            _result.Request = _httpRequest;
 01838            _result.Response = _httpResponse;
 01839            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 1840            {
 01841                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 1842            }
 01843            if (_shouldTrace)
 1844            {
 01845                ServiceClientTracing.Exit(_invocationId, _result);
 1846            }
 01847            return _result;
 01848        }
 1849
 1850        /// <summary>
 1851        /// Gets a list of service principals from the current tenant.
 1852        /// </summary>
 1853        /// <param name='nextLink'>
 1854        /// Next link for the list operation.
 1855        /// </param>
 1856        /// <param name='customHeaders'>
 1857        /// Headers that will be added to request.
 1858        /// </param>
 1859        /// <param name='cancellationToken'>
 1860        /// The cancellation token.
 1861        /// </param>
 1862        /// <exception cref="GraphErrorException">
 1863        /// Thrown when the operation returned an invalid status code
 1864        /// </exception>
 1865        /// <exception cref="SerializationException">
 1866        /// Thrown when unable to deserialize the response
 1867        /// </exception>
 1868        /// <exception cref="ValidationException">
 1869        /// Thrown when a required parameter is null
 1870        /// </exception>
 1871        /// <exception cref="System.ArgumentNullException">
 1872        /// Thrown when a required parameter is null
 1873        /// </exception>
 1874        /// <return>
 1875        /// A response object containing the response body and response headers.
 1876        /// </return>
 1877        public async Task<AzureOperationResponse<IPage<ServicePrincipal>>> ListNextWithHttpMessagesAsync(string nextLink
 1878        {
 01879            if (nextLink == null)
 1880            {
 01881                throw new ValidationException(ValidationRules.CannotBeNull, "nextLink");
 1882            }
 01883            if (Client.ApiVersion == null)
 1884            {
 01885                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
 1886            }
 01887            if (Client.TenantID == null)
 1888            {
 01889                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID");
 1890            }
 1891            // Tracing
 01892            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 01893            string _invocationId = null;
 01894            if (_shouldTrace)
 1895            {
 01896                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 01897                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 01898                tracingParameters.Add("nextLink", nextLink);
 01899                tracingParameters.Add("cancellationToken", cancellationToken);
 01900                ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters);
 1901            }
 1902            // Construct URL
 01903            var _baseUrl = Client.BaseUri.AbsoluteUri;
 01904            var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/{nextL
 01905            _url = _url.Replace("{nextLink}", nextLink);
 01906            _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID));
 01907            List<string> _queryParameters = new List<string>();
 01908            if (Client.ApiVersion != null)
 1909            {
 01910                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
 1911            }
 01912            if (_queryParameters.Count > 0)
 1913            {
 01914                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 1915            }
 1916            // Create HTTP transport objects
 01917            var _httpRequest = new HttpRequestMessage();
 01918            HttpResponseMessage _httpResponse = null;
 01919            _httpRequest.Method = new HttpMethod("GET");
 01920            _httpRequest.RequestUri = new System.Uri(_url);
 1921            // Set Headers
 01922            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 1923            {
 01924                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 1925            }
 01926            if (Client.AcceptLanguage != null)
 1927            {
 01928                if (_httpRequest.Headers.Contains("accept-language"))
 1929                {
 01930                    _httpRequest.Headers.Remove("accept-language");
 1931                }
 01932                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 1933            }
 1934
 1935
 01936            if (customHeaders != null)
 1937            {
 01938                foreach(var _header in customHeaders)
 1939                {
 01940                    if (_httpRequest.Headers.Contains(_header.Key))
 1941                    {
 01942                        _httpRequest.Headers.Remove(_header.Key);
 1943                    }
 01944                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 1945                }
 1946            }
 1947
 1948            // Serialize Request
 01949            string _requestContent = null;
 1950            // Set Credentials
 01951            if (Client.Credentials != null)
 1952            {
 01953                cancellationToken.ThrowIfCancellationRequested();
 01954                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 1955            }
 1956            // Send Request
 01957            if (_shouldTrace)
 1958            {
 01959                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 1960            }
 01961            cancellationToken.ThrowIfCancellationRequested();
 01962            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 01963            if (_shouldTrace)
 1964            {
 01965                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 1966            }
 01967            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 01968            cancellationToken.ThrowIfCancellationRequested();
 01969            string _responseContent = null;
 01970            if ((int)_statusCode != 200)
 1971            {
 01972                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 1973                try
 1974                {
 01975                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 01976                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 01977                    if (_errorBody != null)
 1978                    {
 01979                        ex.Body = _errorBody;
 1980                    }
 01981                }
 01982                catch (JsonException)
 1983                {
 1984                    // Ignore the exception
 01985                }
 01986                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 01987                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 01988                if (_shouldTrace)
 1989                {
 01990                    ServiceClientTracing.Error(_invocationId, ex);
 1991                }
 01992                _httpRequest.Dispose();
 01993                if (_httpResponse != null)
 1994                {
 01995                    _httpResponse.Dispose();
 1996                }
 01997                throw ex;
 1998            }
 1999            // Create Result
 02000            var _result = new AzureOperationResponse<IPage<ServicePrincipal>>();
 02001            _result.Request = _httpRequest;
 02002            _result.Response = _httpResponse;
 02003            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2004            {
 02005                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2006            }
 2007            // Deserialize Response
 02008            if ((int)_statusCode == 200)
 2009            {
 02010                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2011                try
 2012                {
 02013                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<ServicePrincipal>>(_respons
 02014                }
 02015                catch (JsonException ex)
 2016                {
 02017                    _httpRequest.Dispose();
 02018                    if (_httpResponse != null)
 2019                    {
 02020                        _httpResponse.Dispose();
 2021                    }
 02022                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2023                }
 2024            }
 02025            if (_shouldTrace)
 2026            {
 02027                ServiceClientTracing.Exit(_invocationId, _result);
 2028            }
 02029            return _result;
 02030        }
 2031
 2032        /// <summary>
 2033        /// Directory objects that are owners of this service principal.
 2034        /// </summary>
 2035        /// <remarks>
 2036        /// The owners are a set of non-admin users who are allowed to modify this
 2037        /// object.
 2038        /// </remarks>
 2039        /// <param name='nextPageLink'>
 2040        /// The NextLink from the previous successful call to List operation.
 2041        /// </param>
 2042        /// <param name='customHeaders'>
 2043        /// Headers that will be added to request.
 2044        /// </param>
 2045        /// <param name='cancellationToken'>
 2046        /// The cancellation token.
 2047        /// </param>
 2048        /// <exception cref="GraphErrorException">
 2049        /// Thrown when the operation returned an invalid status code
 2050        /// </exception>
 2051        /// <exception cref="SerializationException">
 2052        /// Thrown when unable to deserialize the response
 2053        /// </exception>
 2054        /// <exception cref="ValidationException">
 2055        /// Thrown when a required parameter is null
 2056        /// </exception>
 2057        /// <exception cref="System.ArgumentNullException">
 2058        /// Thrown when a required parameter is null
 2059        /// </exception>
 2060        /// <return>
 2061        /// A response object containing the response body and response headers.
 2062        /// </return>
 2063        public async Task<AzureOperationResponse<IPage<DirectoryObject>>> ListOwnersNextWithHttpMessagesAsync(string nex
 2064        {
 02065            if (nextPageLink == null)
 2066            {
 02067                throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink");
 2068            }
 2069            // Tracing
 02070            bool _shouldTrace = ServiceClientTracing.IsEnabled;
 02071            string _invocationId = null;
 02072            if (_shouldTrace)
 2073            {
 02074                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
 02075                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 02076                tracingParameters.Add("nextPageLink", nextPageLink);
 02077                tracingParameters.Add("cancellationToken", cancellationToken);
 02078                ServiceClientTracing.Enter(_invocationId, this, "ListOwnersNext", tracingParameters);
 2079            }
 2080            // Construct URL
 02081            string _url = "{nextLink}";
 02082            _url = _url.Replace("{nextLink}", nextPageLink);
 02083            List<string> _queryParameters = new List<string>();
 02084            if (_queryParameters.Count > 0)
 2085            {
 02086                _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
 2087            }
 2088            // Create HTTP transport objects
 02089            var _httpRequest = new HttpRequestMessage();
 02090            HttpResponseMessage _httpResponse = null;
 02091            _httpRequest.Method = new HttpMethod("GET");
 02092            _httpRequest.RequestUri = new System.Uri(_url);
 2093            // Set Headers
 02094            if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
 2095            {
 02096                _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString())
 2097            }
 02098            if (Client.AcceptLanguage != null)
 2099            {
 02100                if (_httpRequest.Headers.Contains("accept-language"))
 2101                {
 02102                    _httpRequest.Headers.Remove("accept-language");
 2103                }
 02104                _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
 2105            }
 2106
 2107
 02108            if (customHeaders != null)
 2109            {
 02110                foreach(var _header in customHeaders)
 2111                {
 02112                    if (_httpRequest.Headers.Contains(_header.Key))
 2113                    {
 02114                        _httpRequest.Headers.Remove(_header.Key);
 2115                    }
 02116                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
 2117                }
 2118            }
 2119
 2120            // Serialize Request
 02121            string _requestContent = null;
 2122            // Set Credentials
 02123            if (Client.Credentials != null)
 2124            {
 02125                cancellationToken.ThrowIfCancellationRequested();
 02126                await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 2127            }
 2128            // Send Request
 02129            if (_shouldTrace)
 2130            {
 02131                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
 2132            }
 02133            cancellationToken.ThrowIfCancellationRequested();
 02134            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
 02135            if (_shouldTrace)
 2136            {
 02137                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
 2138            }
 02139            HttpStatusCode _statusCode = _httpResponse.StatusCode;
 02140            cancellationToken.ThrowIfCancellationRequested();
 02141            string _responseContent = null;
 02142            if ((int)_statusCode != 200)
 2143            {
 02144                var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu
 2145                try
 2146                {
 02147                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 02148                    GraphError _errorBody =  Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC
 02149                    if (_errorBody != null)
 2150                    {
 02151                        ex.Body = _errorBody;
 2152                    }
 02153                }
 02154                catch (JsonException)
 2155                {
 2156                    // Ignore the exception
 02157                }
 02158                ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
 02159                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
 02160                if (_shouldTrace)
 2161                {
 02162                    ServiceClientTracing.Error(_invocationId, ex);
 2163                }
 02164                _httpRequest.Dispose();
 02165                if (_httpResponse != null)
 2166                {
 02167                    _httpResponse.Dispose();
 2168                }
 02169                throw ex;
 2170            }
 2171            // Create Result
 02172            var _result = new AzureOperationResponse<IPage<DirectoryObject>>();
 02173            _result.Request = _httpRequest;
 02174            _result.Response = _httpResponse;
 02175            if (_httpResponse.Headers.Contains("x-ms-request-id"))
 2176            {
 02177                _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 2178            }
 2179            // Deserialize Response
 02180            if ((int)_statusCode == 200)
 2181            {
 02182                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 2183                try
 2184                {
 02185                    _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<DirectoryObject>>(_response
 02186                }
 02187                catch (JsonException ex)
 2188                {
 02189                    _httpRequest.Dispose();
 02190                    if (_httpResponse != null)
 2191                    {
 02192                        _httpResponse.Dispose();
 2193                    }
 02194                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
 2195                }
 2196            }
 02197            if (_shouldTrace)
 2198            {
 02199                ServiceClientTracing.Exit(_invocationId, _result);
 2200            }
 02201            return _result;
 02202        }
 2203
 2204    }
 2205}