| | 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 | |
|
| | 11 | | namespace 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> |
| 46 | 40 | | internal ServicePrincipalsOperations(GraphRbacManagementClient client) |
| | 41 | | { |
| 46 | 42 | | if (client == null) |
| | 43 | | { |
| 0 | 44 | | throw new System.ArgumentNullException("client"); |
| | 45 | | } |
| 46 | 46 | | Client = client; |
| 46 | 47 | | } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets a reference to the GraphRbacManagementClient |
| | 51 | | /// </summary> |
| 186 | 52 | | 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 | | { |
| 0 | 83 | | if (parameters == null) |
| | 84 | | { |
| 0 | 85 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 86 | | } |
| 0 | 87 | | if (parameters != null) |
| | 88 | | { |
| 0 | 89 | | parameters.Validate(); |
| | 90 | | } |
| 0 | 91 | | if (Client.ApiVersion == null) |
| | 92 | | { |
| 0 | 93 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 94 | | } |
| 0 | 95 | | if (Client.TenantID == null) |
| | 96 | | { |
| 0 | 97 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 98 | | } |
| | 99 | | // Tracing |
| 0 | 100 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 101 | | string _invocationId = null; |
| 0 | 102 | | if (_shouldTrace) |
| | 103 | | { |
| 0 | 104 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 105 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 106 | | tracingParameters.Add("parameters", parameters); |
| 0 | 107 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 108 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 109 | | } |
| | 110 | | // Construct URL |
| 0 | 111 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 112 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 113 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 114 | | List<string> _queryParameters = new List<string>(); |
| 0 | 115 | | if (Client.ApiVersion != null) |
| | 116 | | { |
| 0 | 117 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 118 | | } |
| 0 | 119 | | if (_queryParameters.Count > 0) |
| | 120 | | { |
| 0 | 121 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 122 | | } |
| | 123 | | // Create HTTP transport objects |
| 0 | 124 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 125 | | HttpResponseMessage _httpResponse = null; |
| 0 | 126 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 127 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 128 | | // Set Headers |
| 0 | 129 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 130 | | { |
| 0 | 131 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 132 | | } |
| 0 | 133 | | if (Client.AcceptLanguage != null) |
| | 134 | | { |
| 0 | 135 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 136 | | { |
| 0 | 137 | | _httpRequest.Headers.Remove("accept-language"); |
| | 138 | | } |
| 0 | 139 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 140 | | } |
| | 141 | |
|
| | 142 | |
|
| 0 | 143 | | if (customHeaders != null) |
| | 144 | | { |
| 0 | 145 | | foreach(var _header in customHeaders) |
| | 146 | | { |
| 0 | 147 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 148 | | { |
| 0 | 149 | | _httpRequest.Headers.Remove(_header.Key); |
| | 150 | | } |
| 0 | 151 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 152 | | } |
| | 153 | | } |
| | 154 | |
|
| | 155 | | // Serialize Request |
| 0 | 156 | | string _requestContent = null; |
| 0 | 157 | | if(parameters != null) |
| | 158 | | { |
| 0 | 159 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 160 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 161 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 162 | | } |
| | 163 | | // Set Credentials |
| 0 | 164 | | if (Client.Credentials != null) |
| | 165 | | { |
| 0 | 166 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 167 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 168 | | } |
| | 169 | | // Send Request |
| 0 | 170 | | if (_shouldTrace) |
| | 171 | | { |
| 0 | 172 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 173 | | } |
| 0 | 174 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 175 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 176 | | if (_shouldTrace) |
| | 177 | | { |
| 0 | 178 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 179 | | } |
| 0 | 180 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 181 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 182 | | string _responseContent = null; |
| 0 | 183 | | if ((int)_statusCode != 201) |
| | 184 | | { |
| 0 | 185 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 186 | | try |
| | 187 | | { |
| 0 | 188 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 189 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 190 | | if (_errorBody != null) |
| | 191 | | { |
| 0 | 192 | | ex.Body = _errorBody; |
| | 193 | | } |
| 0 | 194 | | } |
| 0 | 195 | | catch (JsonException) |
| | 196 | | { |
| | 197 | | // Ignore the exception |
| 0 | 198 | | } |
| 0 | 199 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 200 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 201 | | if (_shouldTrace) |
| | 202 | | { |
| 0 | 203 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 204 | | } |
| 0 | 205 | | _httpRequest.Dispose(); |
| 0 | 206 | | if (_httpResponse != null) |
| | 207 | | { |
| 0 | 208 | | _httpResponse.Dispose(); |
| | 209 | | } |
| 0 | 210 | | throw ex; |
| | 211 | | } |
| | 212 | | // Create Result |
| 0 | 213 | | var _result = new AzureOperationResponse<ServicePrincipal>(); |
| 0 | 214 | | _result.Request = _httpRequest; |
| 0 | 215 | | _result.Response = _httpResponse; |
| 0 | 216 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 217 | | { |
| 0 | 218 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 219 | | } |
| | 220 | | // Deserialize Response |
| 0 | 221 | | if ((int)_statusCode == 201) |
| | 222 | | { |
| 0 | 223 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 224 | | try |
| | 225 | | { |
| 0 | 226 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ServicePrincipal>(_responseConte |
| 0 | 227 | | } |
| 0 | 228 | | catch (JsonException ex) |
| | 229 | | { |
| 0 | 230 | | _httpRequest.Dispose(); |
| 0 | 231 | | if (_httpResponse != null) |
| | 232 | | { |
| 0 | 233 | | _httpResponse.Dispose(); |
| | 234 | | } |
| 0 | 235 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 236 | | } |
| | 237 | | } |
| 0 | 238 | | if (_shouldTrace) |
| | 239 | | { |
| 0 | 240 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 241 | | } |
| 0 | 242 | | return _result; |
| 0 | 243 | | } |
| | 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 | | { |
| 8 | 274 | | if (Client.ApiVersion == null) |
| | 275 | | { |
| 0 | 276 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 277 | | } |
| 8 | 278 | | if (Client.TenantID == null) |
| | 279 | | { |
| 0 | 280 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 281 | | } |
| | 282 | | // Tracing |
| 8 | 283 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 284 | | string _invocationId = null; |
| 8 | 285 | | if (_shouldTrace) |
| | 286 | | { |
| 0 | 287 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 288 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 289 | | tracingParameters.Add("odataQuery", odataQuery); |
| 0 | 290 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 291 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 292 | | } |
| | 293 | | // Construct URL |
| 8 | 294 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 8 | 295 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 8 | 296 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 8 | 297 | | List<string> _queryParameters = new List<string>(); |
| 8 | 298 | | if (odataQuery != null) |
| | 299 | | { |
| 4 | 300 | | var _odataFilter = odataQuery.ToString(); |
| 4 | 301 | | if (!string.IsNullOrEmpty(_odataFilter)) |
| | 302 | | { |
| 4 | 303 | | _queryParameters.Add(_odataFilter); |
| | 304 | | } |
| | 305 | | } |
| 8 | 306 | | if (Client.ApiVersion != null) |
| | 307 | | { |
| 8 | 308 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 309 | | } |
| 8 | 310 | | if (_queryParameters.Count > 0) |
| | 311 | | { |
| 8 | 312 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 313 | | } |
| | 314 | | // Create HTTP transport objects |
| 8 | 315 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 316 | | HttpResponseMessage _httpResponse = null; |
| 8 | 317 | | _httpRequest.Method = new HttpMethod("GET"); |
| 8 | 318 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 319 | | // Set Headers |
| 8 | 320 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 321 | | { |
| 8 | 322 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 323 | | } |
| 8 | 324 | | if (Client.AcceptLanguage != null) |
| | 325 | | { |
| 8 | 326 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 327 | | { |
| 0 | 328 | | _httpRequest.Headers.Remove("accept-language"); |
| | 329 | | } |
| 8 | 330 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 331 | | } |
| | 332 | |
|
| | 333 | |
|
| 8 | 334 | | if (customHeaders != null) |
| | 335 | | { |
| 0 | 336 | | foreach(var _header in customHeaders) |
| | 337 | | { |
| 0 | 338 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 339 | | { |
| 0 | 340 | | _httpRequest.Headers.Remove(_header.Key); |
| | 341 | | } |
| 0 | 342 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 343 | | } |
| | 344 | | } |
| | 345 | |
|
| | 346 | | // Serialize Request |
| 8 | 347 | | string _requestContent = null; |
| | 348 | | // Set Credentials |
| 8 | 349 | | if (Client.Credentials != null) |
| | 350 | | { |
| 8 | 351 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 352 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 353 | | } |
| | 354 | | // Send Request |
| 8 | 355 | | if (_shouldTrace) |
| | 356 | | { |
| 0 | 357 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 358 | | } |
| 8 | 359 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 360 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 361 | | if (_shouldTrace) |
| | 362 | | { |
| 0 | 363 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 364 | | } |
| 8 | 365 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 366 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 367 | | string _responseContent = null; |
| 8 | 368 | | if ((int)_statusCode != 200) |
| | 369 | | { |
| 0 | 370 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 371 | | try |
| | 372 | | { |
| 0 | 373 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 374 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 375 | | if (_errorBody != null) |
| | 376 | | { |
| 0 | 377 | | ex.Body = _errorBody; |
| | 378 | | } |
| 0 | 379 | | } |
| 0 | 380 | | catch (JsonException) |
| | 381 | | { |
| | 382 | | // Ignore the exception |
| 0 | 383 | | } |
| 0 | 384 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 385 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 386 | | if (_shouldTrace) |
| | 387 | | { |
| 0 | 388 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 389 | | } |
| 0 | 390 | | _httpRequest.Dispose(); |
| 0 | 391 | | if (_httpResponse != null) |
| | 392 | | { |
| 0 | 393 | | _httpResponse.Dispose(); |
| | 394 | | } |
| 0 | 395 | | throw ex; |
| | 396 | | } |
| | 397 | | // Create Result |
| 8 | 398 | | var _result = new AzureOperationResponse<IPage<ServicePrincipal>>(); |
| 8 | 399 | | _result.Request = _httpRequest; |
| 8 | 400 | | _result.Response = _httpResponse; |
| 8 | 401 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 402 | | { |
| 0 | 403 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 404 | | } |
| | 405 | | // Deserialize Response |
| 8 | 406 | | if ((int)_statusCode == 200) |
| | 407 | | { |
| 8 | 408 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 409 | | try |
| | 410 | | { |
| 8 | 411 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<ServicePrincipal>>(_respons |
| 8 | 412 | | } |
| 0 | 413 | | catch (JsonException ex) |
| | 414 | | { |
| 0 | 415 | | _httpRequest.Dispose(); |
| 0 | 416 | | if (_httpResponse != null) |
| | 417 | | { |
| 0 | 418 | | _httpResponse.Dispose(); |
| | 419 | | } |
| 0 | 420 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 421 | | } |
| | 422 | | } |
| 8 | 423 | | if (_shouldTrace) |
| | 424 | | { |
| 0 | 425 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 426 | | } |
| 8 | 427 | | return _result; |
| 8 | 428 | | } |
| | 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 | | { |
| 0 | 459 | | if (objectId == null) |
| | 460 | | { |
| 0 | 461 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 462 | | } |
| 0 | 463 | | if (parameters == null) |
| | 464 | | { |
| 0 | 465 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 466 | | } |
| 0 | 467 | | if (Client.ApiVersion == null) |
| | 468 | | { |
| 0 | 469 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 470 | | } |
| 0 | 471 | | if (Client.TenantID == null) |
| | 472 | | { |
| 0 | 473 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 474 | | } |
| | 475 | | // Tracing |
| 0 | 476 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 477 | | string _invocationId = null; |
| 0 | 478 | | if (_shouldTrace) |
| | 479 | | { |
| 0 | 480 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 481 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 482 | | tracingParameters.Add("objectId", objectId); |
| 0 | 483 | | tracingParameters.Add("parameters", parameters); |
| 0 | 484 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 485 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 486 | | } |
| | 487 | | // Construct URL |
| 0 | 488 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 489 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 490 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 491 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 492 | | List<string> _queryParameters = new List<string>(); |
| 0 | 493 | | if (Client.ApiVersion != null) |
| | 494 | | { |
| 0 | 495 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 496 | | } |
| 0 | 497 | | if (_queryParameters.Count > 0) |
| | 498 | | { |
| 0 | 499 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 500 | | } |
| | 501 | | // Create HTTP transport objects |
| 0 | 502 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 503 | | HttpResponseMessage _httpResponse = null; |
| 0 | 504 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 505 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 506 | | // Set Headers |
| 0 | 507 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 508 | | { |
| 0 | 509 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 510 | | } |
| 0 | 511 | | if (Client.AcceptLanguage != null) |
| | 512 | | { |
| 0 | 513 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 514 | | { |
| 0 | 515 | | _httpRequest.Headers.Remove("accept-language"); |
| | 516 | | } |
| 0 | 517 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 518 | | } |
| | 519 | |
|
| | 520 | |
|
| 0 | 521 | | if (customHeaders != null) |
| | 522 | | { |
| 0 | 523 | | foreach(var _header in customHeaders) |
| | 524 | | { |
| 0 | 525 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 526 | | { |
| 0 | 527 | | _httpRequest.Headers.Remove(_header.Key); |
| | 528 | | } |
| 0 | 529 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 530 | | } |
| | 531 | | } |
| | 532 | |
|
| | 533 | | // Serialize Request |
| 0 | 534 | | string _requestContent = null; |
| 0 | 535 | | if(parameters != null) |
| | 536 | | { |
| 0 | 537 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 538 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 539 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 540 | | } |
| | 541 | | // Set Credentials |
| 0 | 542 | | if (Client.Credentials != null) |
| | 543 | | { |
| 0 | 544 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 545 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 546 | | } |
| | 547 | | // Send Request |
| 0 | 548 | | if (_shouldTrace) |
| | 549 | | { |
| 0 | 550 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 551 | | } |
| 0 | 552 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 553 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 554 | | if (_shouldTrace) |
| | 555 | | { |
| 0 | 556 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 557 | | } |
| 0 | 558 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 559 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 560 | | string _responseContent = null; |
| 0 | 561 | | if ((int)_statusCode != 204) |
| | 562 | | { |
| 0 | 563 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 564 | | try |
| | 565 | | { |
| 0 | 566 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 567 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 568 | | if (_errorBody != null) |
| | 569 | | { |
| 0 | 570 | | ex.Body = _errorBody; |
| | 571 | | } |
| 0 | 572 | | } |
| 0 | 573 | | catch (JsonException) |
| | 574 | | { |
| | 575 | | // Ignore the exception |
| 0 | 576 | | } |
| 0 | 577 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 578 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 579 | | if (_shouldTrace) |
| | 580 | | { |
| 0 | 581 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 582 | | } |
| 0 | 583 | | _httpRequest.Dispose(); |
| 0 | 584 | | if (_httpResponse != null) |
| | 585 | | { |
| 0 | 586 | | _httpResponse.Dispose(); |
| | 587 | | } |
| 0 | 588 | | throw ex; |
| | 589 | | } |
| | 590 | | // Create Result |
| 0 | 591 | | var _result = new AzureOperationResponse(); |
| 0 | 592 | | _result.Request = _httpRequest; |
| 0 | 593 | | _result.Response = _httpResponse; |
| 0 | 594 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 595 | | { |
| 0 | 596 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 597 | | } |
| 0 | 598 | | if (_shouldTrace) |
| | 599 | | { |
| 0 | 600 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 601 | | } |
| 0 | 602 | | return _result; |
| 0 | 603 | | } |
| | 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 | | { |
| 0 | 631 | | if (objectId == null) |
| | 632 | | { |
| 0 | 633 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 634 | | } |
| 0 | 635 | | if (Client.ApiVersion == null) |
| | 636 | | { |
| 0 | 637 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 638 | | } |
| 0 | 639 | | if (Client.TenantID == null) |
| | 640 | | { |
| 0 | 641 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 642 | | } |
| | 643 | | // Tracing |
| 0 | 644 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 645 | | string _invocationId = null; |
| 0 | 646 | | if (_shouldTrace) |
| | 647 | | { |
| 0 | 648 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 649 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 650 | | tracingParameters.Add("objectId", objectId); |
| 0 | 651 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 652 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 653 | | } |
| | 654 | | // Construct URL |
| 0 | 655 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 656 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 657 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 658 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 659 | | List<string> _queryParameters = new List<string>(); |
| 0 | 660 | | if (Client.ApiVersion != null) |
| | 661 | | { |
| 0 | 662 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 663 | | } |
| 0 | 664 | | if (_queryParameters.Count > 0) |
| | 665 | | { |
| 0 | 666 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 667 | | } |
| | 668 | | // Create HTTP transport objects |
| 0 | 669 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 670 | | HttpResponseMessage _httpResponse = null; |
| 0 | 671 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 672 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 673 | | // Set Headers |
| 0 | 674 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 675 | | { |
| 0 | 676 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 677 | | } |
| 0 | 678 | | if (Client.AcceptLanguage != null) |
| | 679 | | { |
| 0 | 680 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 681 | | { |
| 0 | 682 | | _httpRequest.Headers.Remove("accept-language"); |
| | 683 | | } |
| 0 | 684 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 685 | | } |
| | 686 | |
|
| | 687 | |
|
| 0 | 688 | | if (customHeaders != null) |
| | 689 | | { |
| 0 | 690 | | foreach(var _header in customHeaders) |
| | 691 | | { |
| 0 | 692 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 693 | | { |
| 0 | 694 | | _httpRequest.Headers.Remove(_header.Key); |
| | 695 | | } |
| 0 | 696 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 697 | | } |
| | 698 | | } |
| | 699 | |
|
| | 700 | | // Serialize Request |
| 0 | 701 | | string _requestContent = null; |
| | 702 | | // Set Credentials |
| 0 | 703 | | if (Client.Credentials != null) |
| | 704 | | { |
| 0 | 705 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 706 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 707 | | } |
| | 708 | | // Send Request |
| 0 | 709 | | if (_shouldTrace) |
| | 710 | | { |
| 0 | 711 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 712 | | } |
| 0 | 713 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 714 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 715 | | if (_shouldTrace) |
| | 716 | | { |
| 0 | 717 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 718 | | } |
| 0 | 719 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 720 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 721 | | string _responseContent = null; |
| 0 | 722 | | if ((int)_statusCode != 204) |
| | 723 | | { |
| 0 | 724 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 725 | | try |
| | 726 | | { |
| 0 | 727 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 728 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 729 | | if (_errorBody != null) |
| | 730 | | { |
| 0 | 731 | | ex.Body = _errorBody; |
| | 732 | | } |
| 0 | 733 | | } |
| 0 | 734 | | catch (JsonException) |
| | 735 | | { |
| | 736 | | // Ignore the exception |
| 0 | 737 | | } |
| 0 | 738 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 739 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 740 | | if (_shouldTrace) |
| | 741 | | { |
| 0 | 742 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 743 | | } |
| 0 | 744 | | _httpRequest.Dispose(); |
| 0 | 745 | | if (_httpResponse != null) |
| | 746 | | { |
| 0 | 747 | | _httpResponse.Dispose(); |
| | 748 | | } |
| 0 | 749 | | throw ex; |
| | 750 | | } |
| | 751 | | // Create Result |
| 0 | 752 | | var _result = new AzureOperationResponse(); |
| 0 | 753 | | _result.Request = _httpRequest; |
| 0 | 754 | | _result.Response = _httpResponse; |
| 0 | 755 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 756 | | { |
| 0 | 757 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 758 | | } |
| 0 | 759 | | if (_shouldTrace) |
| | 760 | | { |
| 0 | 761 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 762 | | } |
| 0 | 763 | | return _result; |
| 0 | 764 | | } |
| | 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 | | { |
| 2 | 796 | | if (objectId == null) |
| | 797 | | { |
| 0 | 798 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 799 | | } |
| 2 | 800 | | if (Client.ApiVersion == null) |
| | 801 | | { |
| 0 | 802 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 803 | | } |
| 2 | 804 | | if (Client.TenantID == null) |
| | 805 | | { |
| 0 | 806 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 807 | | } |
| | 808 | | // Tracing |
| 2 | 809 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 810 | | string _invocationId = null; |
| 2 | 811 | | if (_shouldTrace) |
| | 812 | | { |
| 0 | 813 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 814 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 815 | | tracingParameters.Add("objectId", objectId); |
| 0 | 816 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 817 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 818 | | } |
| | 819 | | // Construct URL |
| 2 | 820 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 2 | 821 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 2 | 822 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 2 | 823 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 2 | 824 | | List<string> _queryParameters = new List<string>(); |
| 2 | 825 | | if (Client.ApiVersion != null) |
| | 826 | | { |
| 2 | 827 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 828 | | } |
| 2 | 829 | | if (_queryParameters.Count > 0) |
| | 830 | | { |
| 2 | 831 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 832 | | } |
| | 833 | | // Create HTTP transport objects |
| 2 | 834 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 835 | | HttpResponseMessage _httpResponse = null; |
| 2 | 836 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 837 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 838 | | // Set Headers |
| 2 | 839 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 840 | | { |
| 2 | 841 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 842 | | } |
| 2 | 843 | | if (Client.AcceptLanguage != null) |
| | 844 | | { |
| 2 | 845 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 846 | | { |
| 0 | 847 | | _httpRequest.Headers.Remove("accept-language"); |
| | 848 | | } |
| 2 | 849 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 850 | | } |
| | 851 | |
|
| | 852 | |
|
| 2 | 853 | | if (customHeaders != null) |
| | 854 | | { |
| 0 | 855 | | foreach(var _header in customHeaders) |
| | 856 | | { |
| 0 | 857 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 858 | | { |
| 0 | 859 | | _httpRequest.Headers.Remove(_header.Key); |
| | 860 | | } |
| 0 | 861 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 862 | | } |
| | 863 | | } |
| | 864 | |
|
| | 865 | | // Serialize Request |
| 2 | 866 | | string _requestContent = null; |
| | 867 | | // Set Credentials |
| 2 | 868 | | if (Client.Credentials != null) |
| | 869 | | { |
| 2 | 870 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 871 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 872 | | } |
| | 873 | | // Send Request |
| 2 | 874 | | if (_shouldTrace) |
| | 875 | | { |
| 0 | 876 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 877 | | } |
| 2 | 878 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 879 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 880 | | if (_shouldTrace) |
| | 881 | | { |
| 0 | 882 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 883 | | } |
| 2 | 884 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 885 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 886 | | string _responseContent = null; |
| 2 | 887 | | if ((int)_statusCode != 200) |
| | 888 | | { |
| 0 | 889 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 890 | | try |
| | 891 | | { |
| 0 | 892 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 893 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 894 | | if (_errorBody != null) |
| | 895 | | { |
| 0 | 896 | | ex.Body = _errorBody; |
| | 897 | | } |
| 0 | 898 | | } |
| 0 | 899 | | catch (JsonException) |
| | 900 | | { |
| | 901 | | // Ignore the exception |
| 0 | 902 | | } |
| 0 | 903 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 904 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 905 | | if (_shouldTrace) |
| | 906 | | { |
| 0 | 907 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 908 | | } |
| 0 | 909 | | _httpRequest.Dispose(); |
| 0 | 910 | | if (_httpResponse != null) |
| | 911 | | { |
| 0 | 912 | | _httpResponse.Dispose(); |
| | 913 | | } |
| 0 | 914 | | throw ex; |
| | 915 | | } |
| | 916 | | // Create Result |
| 2 | 917 | | var _result = new AzureOperationResponse<ServicePrincipal>(); |
| 2 | 918 | | _result.Request = _httpRequest; |
| 2 | 919 | | _result.Response = _httpResponse; |
| 2 | 920 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 921 | | { |
| 0 | 922 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 923 | | } |
| | 924 | | // Deserialize Response |
| 2 | 925 | | if ((int)_statusCode == 200) |
| | 926 | | { |
| 2 | 927 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 928 | | try |
| | 929 | | { |
| 2 | 930 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ServicePrincipal>(_responseConte |
| 2 | 931 | | } |
| 0 | 932 | | catch (JsonException ex) |
| | 933 | | { |
| 0 | 934 | | _httpRequest.Dispose(); |
| 0 | 935 | | if (_httpResponse != null) |
| | 936 | | { |
| 0 | 937 | | _httpResponse.Dispose(); |
| | 938 | | } |
| 0 | 939 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 940 | | } |
| | 941 | | } |
| 2 | 942 | | if (_shouldTrace) |
| | 943 | | { |
| 0 | 944 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 945 | | } |
| 2 | 946 | | return _result; |
| 2 | 947 | | } |
| | 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 | | { |
| 0 | 982 | | if (objectId == null) |
| | 983 | | { |
| 0 | 984 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 985 | | } |
| 0 | 986 | | if (Client.ApiVersion == null) |
| | 987 | | { |
| 0 | 988 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 989 | | } |
| 0 | 990 | | if (Client.TenantID == null) |
| | 991 | | { |
| 0 | 992 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 993 | | } |
| | 994 | | // Tracing |
| 0 | 995 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 996 | | string _invocationId = null; |
| 0 | 997 | | if (_shouldTrace) |
| | 998 | | { |
| 0 | 999 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1000 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1001 | | tracingParameters.Add("objectId", objectId); |
| 0 | 1002 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1003 | | ServiceClientTracing.Enter(_invocationId, this, "ListOwners", tracingParameters); |
| | 1004 | | } |
| | 1005 | | // Construct URL |
| 0 | 1006 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1007 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 1008 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 1009 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1010 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1011 | | if (Client.ApiVersion != null) |
| | 1012 | | { |
| 0 | 1013 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1014 | | } |
| 0 | 1015 | | if (_queryParameters.Count > 0) |
| | 1016 | | { |
| 0 | 1017 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1018 | | } |
| | 1019 | | // Create HTTP transport objects |
| 0 | 1020 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1021 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1022 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1023 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1024 | | // Set Headers |
| 0 | 1025 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1026 | | { |
| 0 | 1027 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1028 | | } |
| 0 | 1029 | | if (Client.AcceptLanguage != null) |
| | 1030 | | { |
| 0 | 1031 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1032 | | { |
| 0 | 1033 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1034 | | } |
| 0 | 1035 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1036 | | } |
| | 1037 | |
|
| | 1038 | |
|
| 0 | 1039 | | if (customHeaders != null) |
| | 1040 | | { |
| 0 | 1041 | | foreach(var _header in customHeaders) |
| | 1042 | | { |
| 0 | 1043 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1044 | | { |
| 0 | 1045 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1046 | | } |
| 0 | 1047 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1048 | | } |
| | 1049 | | } |
| | 1050 | |
|
| | 1051 | | // Serialize Request |
| 0 | 1052 | | string _requestContent = null; |
| | 1053 | | // Set Credentials |
| 0 | 1054 | | if (Client.Credentials != null) |
| | 1055 | | { |
| 0 | 1056 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1057 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1058 | | } |
| | 1059 | | // Send Request |
| 0 | 1060 | | if (_shouldTrace) |
| | 1061 | | { |
| 0 | 1062 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1063 | | } |
| 0 | 1064 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1065 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1066 | | if (_shouldTrace) |
| | 1067 | | { |
| 0 | 1068 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1069 | | } |
| 0 | 1070 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1071 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1072 | | string _responseContent = null; |
| 0 | 1073 | | if ((int)_statusCode != 200) |
| | 1074 | | { |
| 0 | 1075 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1076 | | try |
| | 1077 | | { |
| 0 | 1078 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1079 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1080 | | if (_errorBody != null) |
| | 1081 | | { |
| 0 | 1082 | | ex.Body = _errorBody; |
| | 1083 | | } |
| 0 | 1084 | | } |
| 0 | 1085 | | catch (JsonException) |
| | 1086 | | { |
| | 1087 | | // Ignore the exception |
| 0 | 1088 | | } |
| 0 | 1089 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1090 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1091 | | if (_shouldTrace) |
| | 1092 | | { |
| 0 | 1093 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1094 | | } |
| 0 | 1095 | | _httpRequest.Dispose(); |
| 0 | 1096 | | if (_httpResponse != null) |
| | 1097 | | { |
| 0 | 1098 | | _httpResponse.Dispose(); |
| | 1099 | | } |
| 0 | 1100 | | throw ex; |
| | 1101 | | } |
| | 1102 | | // Create Result |
| 0 | 1103 | | var _result = new AzureOperationResponse<IPage<DirectoryObject>>(); |
| 0 | 1104 | | _result.Request = _httpRequest; |
| 0 | 1105 | | _result.Response = _httpResponse; |
| 0 | 1106 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1107 | | { |
| 0 | 1108 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1109 | | } |
| | 1110 | | // Deserialize Response |
| 0 | 1111 | | if ((int)_statusCode == 200) |
| | 1112 | | { |
| 0 | 1113 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1114 | | try |
| | 1115 | | { |
| 0 | 1116 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<DirectoryObject>>(_response |
| 0 | 1117 | | } |
| 0 | 1118 | | catch (JsonException ex) |
| | 1119 | | { |
| 0 | 1120 | | _httpRequest.Dispose(); |
| 0 | 1121 | | if (_httpResponse != null) |
| | 1122 | | { |
| 0 | 1123 | | _httpResponse.Dispose(); |
| | 1124 | | } |
| 0 | 1125 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1126 | | } |
| | 1127 | | } |
| 0 | 1128 | | if (_shouldTrace) |
| | 1129 | | { |
| 0 | 1130 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1131 | | } |
| 0 | 1132 | | return _result; |
| 0 | 1133 | | } |
| | 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 | | { |
| 0 | 1164 | | if (objectId == null) |
| | 1165 | | { |
| 0 | 1166 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 1167 | | } |
| 0 | 1168 | | if (Client.ApiVersion == null) |
| | 1169 | | { |
| 0 | 1170 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1171 | | } |
| 0 | 1172 | | if (Client.TenantID == null) |
| | 1173 | | { |
| 0 | 1174 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1175 | | } |
| | 1176 | | // Tracing |
| 0 | 1177 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1178 | | string _invocationId = null; |
| 0 | 1179 | | if (_shouldTrace) |
| | 1180 | | { |
| 0 | 1181 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1182 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1183 | | tracingParameters.Add("objectId", objectId); |
| 0 | 1184 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1185 | | ServiceClientTracing.Enter(_invocationId, this, "ListKeyCredentials", tracingParameters); |
| | 1186 | | } |
| | 1187 | | // Construct URL |
| 0 | 1188 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1189 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 1190 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 1191 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1192 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1193 | | if (Client.ApiVersion != null) |
| | 1194 | | { |
| 0 | 1195 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1196 | | } |
| 0 | 1197 | | if (_queryParameters.Count > 0) |
| | 1198 | | { |
| 0 | 1199 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1200 | | } |
| | 1201 | | // Create HTTP transport objects |
| 0 | 1202 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1203 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1204 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1205 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1206 | | // Set Headers |
| 0 | 1207 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1208 | | { |
| 0 | 1209 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1210 | | } |
| 0 | 1211 | | if (Client.AcceptLanguage != null) |
| | 1212 | | { |
| 0 | 1213 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1214 | | { |
| 0 | 1215 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1216 | | } |
| 0 | 1217 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1218 | | } |
| | 1219 | |
|
| | 1220 | |
|
| 0 | 1221 | | if (customHeaders != null) |
| | 1222 | | { |
| 0 | 1223 | | foreach(var _header in customHeaders) |
| | 1224 | | { |
| 0 | 1225 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1226 | | { |
| 0 | 1227 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1228 | | } |
| 0 | 1229 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1230 | | } |
| | 1231 | | } |
| | 1232 | |
|
| | 1233 | | // Serialize Request |
| 0 | 1234 | | string _requestContent = null; |
| | 1235 | | // Set Credentials |
| 0 | 1236 | | if (Client.Credentials != null) |
| | 1237 | | { |
| 0 | 1238 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1239 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1240 | | } |
| | 1241 | | // Send Request |
| 0 | 1242 | | if (_shouldTrace) |
| | 1243 | | { |
| 0 | 1244 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1245 | | } |
| 0 | 1246 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1247 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1248 | | if (_shouldTrace) |
| | 1249 | | { |
| 0 | 1250 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1251 | | } |
| 0 | 1252 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1253 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1254 | | string _responseContent = null; |
| 0 | 1255 | | if ((int)_statusCode != 200) |
| | 1256 | | { |
| 0 | 1257 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1258 | | try |
| | 1259 | | { |
| 0 | 1260 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1261 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1262 | | if (_errorBody != null) |
| | 1263 | | { |
| 0 | 1264 | | ex.Body = _errorBody; |
| | 1265 | | } |
| 0 | 1266 | | } |
| 0 | 1267 | | catch (JsonException) |
| | 1268 | | { |
| | 1269 | | // Ignore the exception |
| 0 | 1270 | | } |
| 0 | 1271 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1272 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1273 | | if (_shouldTrace) |
| | 1274 | | { |
| 0 | 1275 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1276 | | } |
| 0 | 1277 | | _httpRequest.Dispose(); |
| 0 | 1278 | | if (_httpResponse != null) |
| | 1279 | | { |
| 0 | 1280 | | _httpResponse.Dispose(); |
| | 1281 | | } |
| 0 | 1282 | | throw ex; |
| | 1283 | | } |
| | 1284 | | // Create Result |
| 0 | 1285 | | var _result = new AzureOperationResponse<IEnumerable<KeyCredential>>(); |
| 0 | 1286 | | _result.Request = _httpRequest; |
| 0 | 1287 | | _result.Response = _httpResponse; |
| 0 | 1288 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1289 | | { |
| 0 | 1290 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1291 | | } |
| | 1292 | | // Deserialize Response |
| 0 | 1293 | | if ((int)_statusCode == 200) |
| | 1294 | | { |
| 0 | 1295 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1296 | | try |
| | 1297 | | { |
| 0 | 1298 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<KeyCredential>>(_responseC |
| 0 | 1299 | | } |
| 0 | 1300 | | catch (JsonException ex) |
| | 1301 | | { |
| 0 | 1302 | | _httpRequest.Dispose(); |
| 0 | 1303 | | if (_httpResponse != null) |
| | 1304 | | { |
| 0 | 1305 | | _httpResponse.Dispose(); |
| | 1306 | | } |
| 0 | 1307 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1308 | | } |
| | 1309 | | } |
| 0 | 1310 | | if (_shouldTrace) |
| | 1311 | | { |
| 0 | 1312 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1313 | | } |
| 0 | 1314 | | return _result; |
| 0 | 1315 | | } |
| | 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 | | { |
| 0 | 1346 | | if (objectId == null) |
| | 1347 | | { |
| 0 | 1348 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 1349 | | } |
| 0 | 1350 | | if (parameters == null) |
| | 1351 | | { |
| 0 | 1352 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 1353 | | } |
| 0 | 1354 | | if (Client.ApiVersion == null) |
| | 1355 | | { |
| 0 | 1356 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1357 | | } |
| 0 | 1358 | | if (Client.TenantID == null) |
| | 1359 | | { |
| 0 | 1360 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1361 | | } |
| | 1362 | | // Tracing |
| 0 | 1363 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1364 | | string _invocationId = null; |
| 0 | 1365 | | if (_shouldTrace) |
| | 1366 | | { |
| 0 | 1367 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1368 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1369 | | tracingParameters.Add("objectId", objectId); |
| 0 | 1370 | | tracingParameters.Add("parameters", parameters); |
| 0 | 1371 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1372 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateKeyCredentials", tracingParameters); |
| | 1373 | | } |
| | 1374 | | // Construct URL |
| 0 | 1375 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1376 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 1377 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 1378 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1379 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1380 | | if (Client.ApiVersion != null) |
| | 1381 | | { |
| 0 | 1382 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1383 | | } |
| 0 | 1384 | | if (_queryParameters.Count > 0) |
| | 1385 | | { |
| 0 | 1386 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1387 | | } |
| | 1388 | | // Create HTTP transport objects |
| 0 | 1389 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1390 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1391 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 1392 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1393 | | // Set Headers |
| 0 | 1394 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1395 | | { |
| 0 | 1396 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1397 | | } |
| 0 | 1398 | | if (Client.AcceptLanguage != null) |
| | 1399 | | { |
| 0 | 1400 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1401 | | { |
| 0 | 1402 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1403 | | } |
| 0 | 1404 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1405 | | } |
| | 1406 | |
|
| | 1407 | |
|
| 0 | 1408 | | if (customHeaders != null) |
| | 1409 | | { |
| 0 | 1410 | | foreach(var _header in customHeaders) |
| | 1411 | | { |
| 0 | 1412 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1413 | | { |
| 0 | 1414 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1415 | | } |
| 0 | 1416 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1417 | | } |
| | 1418 | | } |
| | 1419 | |
|
| | 1420 | | // Serialize Request |
| 0 | 1421 | | string _requestContent = null; |
| 0 | 1422 | | if(parameters != null) |
| | 1423 | | { |
| 0 | 1424 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 1425 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1426 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1427 | | } |
| | 1428 | | // Set Credentials |
| 0 | 1429 | | if (Client.Credentials != null) |
| | 1430 | | { |
| 0 | 1431 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1432 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1433 | | } |
| | 1434 | | // Send Request |
| 0 | 1435 | | if (_shouldTrace) |
| | 1436 | | { |
| 0 | 1437 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1438 | | } |
| 0 | 1439 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1440 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1441 | | if (_shouldTrace) |
| | 1442 | | { |
| 0 | 1443 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1444 | | } |
| 0 | 1445 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1446 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1447 | | string _responseContent = null; |
| 0 | 1448 | | if ((int)_statusCode != 204) |
| | 1449 | | { |
| 0 | 1450 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1451 | | try |
| | 1452 | | { |
| 0 | 1453 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1454 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1455 | | if (_errorBody != null) |
| | 1456 | | { |
| 0 | 1457 | | ex.Body = _errorBody; |
| | 1458 | | } |
| 0 | 1459 | | } |
| 0 | 1460 | | catch (JsonException) |
| | 1461 | | { |
| | 1462 | | // Ignore the exception |
| 0 | 1463 | | } |
| 0 | 1464 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1465 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1466 | | if (_shouldTrace) |
| | 1467 | | { |
| 0 | 1468 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1469 | | } |
| 0 | 1470 | | _httpRequest.Dispose(); |
| 0 | 1471 | | if (_httpResponse != null) |
| | 1472 | | { |
| 0 | 1473 | | _httpResponse.Dispose(); |
| | 1474 | | } |
| 0 | 1475 | | throw ex; |
| | 1476 | | } |
| | 1477 | | // Create Result |
| 0 | 1478 | | var _result = new AzureOperationResponse(); |
| 0 | 1479 | | _result.Request = _httpRequest; |
| 0 | 1480 | | _result.Response = _httpResponse; |
| 0 | 1481 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1482 | | { |
| 0 | 1483 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1484 | | } |
| 0 | 1485 | | if (_shouldTrace) |
| | 1486 | | { |
| 0 | 1487 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1488 | | } |
| 0 | 1489 | | return _result; |
| 0 | 1490 | | } |
| | 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 | | { |
| 0 | 1521 | | if (objectId == null) |
| | 1522 | | { |
| 0 | 1523 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 1524 | | } |
| 0 | 1525 | | if (Client.ApiVersion == null) |
| | 1526 | | { |
| 0 | 1527 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1528 | | } |
| 0 | 1529 | | if (Client.TenantID == null) |
| | 1530 | | { |
| 0 | 1531 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1532 | | } |
| | 1533 | | // Tracing |
| 0 | 1534 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1535 | | string _invocationId = null; |
| 0 | 1536 | | if (_shouldTrace) |
| | 1537 | | { |
| 0 | 1538 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1539 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1540 | | tracingParameters.Add("objectId", objectId); |
| 0 | 1541 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1542 | | ServiceClientTracing.Enter(_invocationId, this, "ListPasswordCredentials", tracingParameters); |
| | 1543 | | } |
| | 1544 | | // Construct URL |
| 0 | 1545 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1546 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 1547 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 1548 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1549 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1550 | | if (Client.ApiVersion != null) |
| | 1551 | | { |
| 0 | 1552 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1553 | | } |
| 0 | 1554 | | if (_queryParameters.Count > 0) |
| | 1555 | | { |
| 0 | 1556 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1557 | | } |
| | 1558 | | // Create HTTP transport objects |
| 0 | 1559 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1560 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1561 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1562 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1563 | | // Set Headers |
| 0 | 1564 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1565 | | { |
| 0 | 1566 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1567 | | } |
| 0 | 1568 | | if (Client.AcceptLanguage != null) |
| | 1569 | | { |
| 0 | 1570 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1571 | | { |
| 0 | 1572 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1573 | | } |
| 0 | 1574 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1575 | | } |
| | 1576 | |
|
| | 1577 | |
|
| 0 | 1578 | | if (customHeaders != null) |
| | 1579 | | { |
| 0 | 1580 | | foreach(var _header in customHeaders) |
| | 1581 | | { |
| 0 | 1582 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1583 | | { |
| 0 | 1584 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1585 | | } |
| 0 | 1586 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1587 | | } |
| | 1588 | | } |
| | 1589 | |
|
| | 1590 | | // Serialize Request |
| 0 | 1591 | | string _requestContent = null; |
| | 1592 | | // Set Credentials |
| 0 | 1593 | | if (Client.Credentials != null) |
| | 1594 | | { |
| 0 | 1595 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1596 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1597 | | } |
| | 1598 | | // Send Request |
| 0 | 1599 | | if (_shouldTrace) |
| | 1600 | | { |
| 0 | 1601 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1602 | | } |
| 0 | 1603 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1604 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1605 | | if (_shouldTrace) |
| | 1606 | | { |
| 0 | 1607 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1608 | | } |
| 0 | 1609 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1610 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1611 | | string _responseContent = null; |
| 0 | 1612 | | if ((int)_statusCode != 200) |
| | 1613 | | { |
| 0 | 1614 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1615 | | try |
| | 1616 | | { |
| 0 | 1617 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1618 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1619 | | if (_errorBody != null) |
| | 1620 | | { |
| 0 | 1621 | | ex.Body = _errorBody; |
| | 1622 | | } |
| 0 | 1623 | | } |
| 0 | 1624 | | catch (JsonException) |
| | 1625 | | { |
| | 1626 | | // Ignore the exception |
| 0 | 1627 | | } |
| 0 | 1628 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1629 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1630 | | if (_shouldTrace) |
| | 1631 | | { |
| 0 | 1632 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1633 | | } |
| 0 | 1634 | | _httpRequest.Dispose(); |
| 0 | 1635 | | if (_httpResponse != null) |
| | 1636 | | { |
| 0 | 1637 | | _httpResponse.Dispose(); |
| | 1638 | | } |
| 0 | 1639 | | throw ex; |
| | 1640 | | } |
| | 1641 | | // Create Result |
| 0 | 1642 | | var _result = new AzureOperationResponse<IEnumerable<PasswordCredential>>(); |
| 0 | 1643 | | _result.Request = _httpRequest; |
| 0 | 1644 | | _result.Response = _httpResponse; |
| 0 | 1645 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1646 | | { |
| 0 | 1647 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1648 | | } |
| | 1649 | | // Deserialize Response |
| 0 | 1650 | | if ((int)_statusCode == 200) |
| | 1651 | | { |
| 0 | 1652 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1653 | | try |
| | 1654 | | { |
| 0 | 1655 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<PasswordCredential>>(_resp |
| 0 | 1656 | | } |
| 0 | 1657 | | catch (JsonException ex) |
| | 1658 | | { |
| 0 | 1659 | | _httpRequest.Dispose(); |
| 0 | 1660 | | if (_httpResponse != null) |
| | 1661 | | { |
| 0 | 1662 | | _httpResponse.Dispose(); |
| | 1663 | | } |
| 0 | 1664 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1665 | | } |
| | 1666 | | } |
| 0 | 1667 | | if (_shouldTrace) |
| | 1668 | | { |
| 0 | 1669 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1670 | | } |
| 0 | 1671 | | return _result; |
| 0 | 1672 | | } |
| | 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 | | { |
| 0 | 1704 | | if (objectId == null) |
| | 1705 | | { |
| 0 | 1706 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 1707 | | } |
| 0 | 1708 | | if (parameters == null) |
| | 1709 | | { |
| 0 | 1710 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 1711 | | } |
| 0 | 1712 | | if (Client.ApiVersion == null) |
| | 1713 | | { |
| 0 | 1714 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1715 | | } |
| 0 | 1716 | | if (Client.TenantID == null) |
| | 1717 | | { |
| 0 | 1718 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1719 | | } |
| | 1720 | | // Tracing |
| 0 | 1721 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1722 | | string _invocationId = null; |
| 0 | 1723 | | if (_shouldTrace) |
| | 1724 | | { |
| 0 | 1725 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1726 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1727 | | tracingParameters.Add("objectId", objectId); |
| 0 | 1728 | | tracingParameters.Add("parameters", parameters); |
| 0 | 1729 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1730 | | ServiceClientTracing.Enter(_invocationId, this, "UpdatePasswordCredentials", tracingParameters); |
| | 1731 | | } |
| | 1732 | | // Construct URL |
| 0 | 1733 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1734 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 1735 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 0 | 1736 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1737 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1738 | | if (Client.ApiVersion != null) |
| | 1739 | | { |
| 0 | 1740 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1741 | | } |
| 0 | 1742 | | if (_queryParameters.Count > 0) |
| | 1743 | | { |
| 0 | 1744 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1745 | | } |
| | 1746 | | // Create HTTP transport objects |
| 0 | 1747 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1748 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1749 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 1750 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1751 | | // Set Headers |
| 0 | 1752 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1753 | | { |
| 0 | 1754 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1755 | | } |
| 0 | 1756 | | if (Client.AcceptLanguage != null) |
| | 1757 | | { |
| 0 | 1758 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1759 | | { |
| 0 | 1760 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1761 | | } |
| 0 | 1762 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1763 | | } |
| | 1764 | |
|
| | 1765 | |
|
| 0 | 1766 | | if (customHeaders != null) |
| | 1767 | | { |
| 0 | 1768 | | foreach(var _header in customHeaders) |
| | 1769 | | { |
| 0 | 1770 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1771 | | { |
| 0 | 1772 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1773 | | } |
| 0 | 1774 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1775 | | } |
| | 1776 | | } |
| | 1777 | |
|
| | 1778 | | // Serialize Request |
| 0 | 1779 | | string _requestContent = null; |
| 0 | 1780 | | if(parameters != null) |
| | 1781 | | { |
| 0 | 1782 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 1783 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1784 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1785 | | } |
| | 1786 | | // Set Credentials |
| 0 | 1787 | | if (Client.Credentials != null) |
| | 1788 | | { |
| 0 | 1789 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1790 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1791 | | } |
| | 1792 | | // Send Request |
| 0 | 1793 | | if (_shouldTrace) |
| | 1794 | | { |
| 0 | 1795 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1796 | | } |
| 0 | 1797 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1798 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1799 | | if (_shouldTrace) |
| | 1800 | | { |
| 0 | 1801 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1802 | | } |
| 0 | 1803 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1804 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1805 | | string _responseContent = null; |
| 0 | 1806 | | if ((int)_statusCode != 204) |
| | 1807 | | { |
| 0 | 1808 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1809 | | try |
| | 1810 | | { |
| 0 | 1811 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1812 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1813 | | if (_errorBody != null) |
| | 1814 | | { |
| 0 | 1815 | | ex.Body = _errorBody; |
| | 1816 | | } |
| 0 | 1817 | | } |
| 0 | 1818 | | catch (JsonException) |
| | 1819 | | { |
| | 1820 | | // Ignore the exception |
| 0 | 1821 | | } |
| 0 | 1822 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1823 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1824 | | if (_shouldTrace) |
| | 1825 | | { |
| 0 | 1826 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1827 | | } |
| 0 | 1828 | | _httpRequest.Dispose(); |
| 0 | 1829 | | if (_httpResponse != null) |
| | 1830 | | { |
| 0 | 1831 | | _httpResponse.Dispose(); |
| | 1832 | | } |
| 0 | 1833 | | throw ex; |
| | 1834 | | } |
| | 1835 | | // Create Result |
| 0 | 1836 | | var _result = new AzureOperationResponse(); |
| 0 | 1837 | | _result.Request = _httpRequest; |
| 0 | 1838 | | _result.Response = _httpResponse; |
| 0 | 1839 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1840 | | { |
| 0 | 1841 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1842 | | } |
| 0 | 1843 | | if (_shouldTrace) |
| | 1844 | | { |
| 0 | 1845 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1846 | | } |
| 0 | 1847 | | return _result; |
| 0 | 1848 | | } |
| | 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 | | { |
| 0 | 1879 | | if (nextLink == null) |
| | 1880 | | { |
| 0 | 1881 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextLink"); |
| | 1882 | | } |
| 0 | 1883 | | if (Client.ApiVersion == null) |
| | 1884 | | { |
| 0 | 1885 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1886 | | } |
| 0 | 1887 | | if (Client.TenantID == null) |
| | 1888 | | { |
| 0 | 1889 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1890 | | } |
| | 1891 | | // Tracing |
| 0 | 1892 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1893 | | string _invocationId = null; |
| 0 | 1894 | | if (_shouldTrace) |
| | 1895 | | { |
| 0 | 1896 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1897 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1898 | | tracingParameters.Add("nextLink", nextLink); |
| 0 | 1899 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1900 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 1901 | | } |
| | 1902 | | // Construct URL |
| 0 | 1903 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1904 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/{nextL |
| 0 | 1905 | | _url = _url.Replace("{nextLink}", nextLink); |
| 0 | 1906 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1907 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1908 | | if (Client.ApiVersion != null) |
| | 1909 | | { |
| 0 | 1910 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1911 | | } |
| 0 | 1912 | | if (_queryParameters.Count > 0) |
| | 1913 | | { |
| 0 | 1914 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1915 | | } |
| | 1916 | | // Create HTTP transport objects |
| 0 | 1917 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1918 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1919 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1920 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1921 | | // Set Headers |
| 0 | 1922 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1923 | | { |
| 0 | 1924 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1925 | | } |
| 0 | 1926 | | if (Client.AcceptLanguage != null) |
| | 1927 | | { |
| 0 | 1928 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1929 | | { |
| 0 | 1930 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1931 | | } |
| 0 | 1932 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1933 | | } |
| | 1934 | |
|
| | 1935 | |
|
| 0 | 1936 | | if (customHeaders != null) |
| | 1937 | | { |
| 0 | 1938 | | foreach(var _header in customHeaders) |
| | 1939 | | { |
| 0 | 1940 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1941 | | { |
| 0 | 1942 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1943 | | } |
| 0 | 1944 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1945 | | } |
| | 1946 | | } |
| | 1947 | |
|
| | 1948 | | // Serialize Request |
| 0 | 1949 | | string _requestContent = null; |
| | 1950 | | // Set Credentials |
| 0 | 1951 | | if (Client.Credentials != null) |
| | 1952 | | { |
| 0 | 1953 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1954 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1955 | | } |
| | 1956 | | // Send Request |
| 0 | 1957 | | if (_shouldTrace) |
| | 1958 | | { |
| 0 | 1959 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1960 | | } |
| 0 | 1961 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1962 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1963 | | if (_shouldTrace) |
| | 1964 | | { |
| 0 | 1965 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1966 | | } |
| 0 | 1967 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1968 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1969 | | string _responseContent = null; |
| 0 | 1970 | | if ((int)_statusCode != 200) |
| | 1971 | | { |
| 0 | 1972 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1973 | | try |
| | 1974 | | { |
| 0 | 1975 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1976 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1977 | | if (_errorBody != null) |
| | 1978 | | { |
| 0 | 1979 | | ex.Body = _errorBody; |
| | 1980 | | } |
| 0 | 1981 | | } |
| 0 | 1982 | | catch (JsonException) |
| | 1983 | | { |
| | 1984 | | // Ignore the exception |
| 0 | 1985 | | } |
| 0 | 1986 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1987 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1988 | | if (_shouldTrace) |
| | 1989 | | { |
| 0 | 1990 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1991 | | } |
| 0 | 1992 | | _httpRequest.Dispose(); |
| 0 | 1993 | | if (_httpResponse != null) |
| | 1994 | | { |
| 0 | 1995 | | _httpResponse.Dispose(); |
| | 1996 | | } |
| 0 | 1997 | | throw ex; |
| | 1998 | | } |
| | 1999 | | // Create Result |
| 0 | 2000 | | var _result = new AzureOperationResponse<IPage<ServicePrincipal>>(); |
| 0 | 2001 | | _result.Request = _httpRequest; |
| 0 | 2002 | | _result.Response = _httpResponse; |
| 0 | 2003 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2004 | | { |
| 0 | 2005 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2006 | | } |
| | 2007 | | // Deserialize Response |
| 0 | 2008 | | if ((int)_statusCode == 200) |
| | 2009 | | { |
| 0 | 2010 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2011 | | try |
| | 2012 | | { |
| 0 | 2013 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<ServicePrincipal>>(_respons |
| 0 | 2014 | | } |
| 0 | 2015 | | catch (JsonException ex) |
| | 2016 | | { |
| 0 | 2017 | | _httpRequest.Dispose(); |
| 0 | 2018 | | if (_httpResponse != null) |
| | 2019 | | { |
| 0 | 2020 | | _httpResponse.Dispose(); |
| | 2021 | | } |
| 0 | 2022 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2023 | | } |
| | 2024 | | } |
| 0 | 2025 | | if (_shouldTrace) |
| | 2026 | | { |
| 0 | 2027 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2028 | | } |
| 0 | 2029 | | return _result; |
| 0 | 2030 | | } |
| | 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 | | { |
| 0 | 2065 | | if (nextPageLink == null) |
| | 2066 | | { |
| 0 | 2067 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 2068 | | } |
| | 2069 | | // Tracing |
| 0 | 2070 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2071 | | string _invocationId = null; |
| 0 | 2072 | | if (_shouldTrace) |
| | 2073 | | { |
| 0 | 2074 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2075 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2076 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 2077 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2078 | | ServiceClientTracing.Enter(_invocationId, this, "ListOwnersNext", tracingParameters); |
| | 2079 | | } |
| | 2080 | | // Construct URL |
| 0 | 2081 | | string _url = "{nextLink}"; |
| 0 | 2082 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 2083 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2084 | | if (_queryParameters.Count > 0) |
| | 2085 | | { |
| 0 | 2086 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2087 | | } |
| | 2088 | | // Create HTTP transport objects |
| 0 | 2089 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2090 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2091 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2092 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2093 | | // Set Headers |
| 0 | 2094 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2095 | | { |
| 0 | 2096 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2097 | | } |
| 0 | 2098 | | if (Client.AcceptLanguage != null) |
| | 2099 | | { |
| 0 | 2100 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2101 | | { |
| 0 | 2102 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2103 | | } |
| 0 | 2104 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2105 | | } |
| | 2106 | |
|
| | 2107 | |
|
| 0 | 2108 | | if (customHeaders != null) |
| | 2109 | | { |
| 0 | 2110 | | foreach(var _header in customHeaders) |
| | 2111 | | { |
| 0 | 2112 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2113 | | { |
| 0 | 2114 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2115 | | } |
| 0 | 2116 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2117 | | } |
| | 2118 | | } |
| | 2119 | |
|
| | 2120 | | // Serialize Request |
| 0 | 2121 | | string _requestContent = null; |
| | 2122 | | // Set Credentials |
| 0 | 2123 | | if (Client.Credentials != null) |
| | 2124 | | { |
| 0 | 2125 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2126 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2127 | | } |
| | 2128 | | // Send Request |
| 0 | 2129 | | if (_shouldTrace) |
| | 2130 | | { |
| 0 | 2131 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2132 | | } |
| 0 | 2133 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2134 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2135 | | if (_shouldTrace) |
| | 2136 | | { |
| 0 | 2137 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2138 | | } |
| 0 | 2139 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2140 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2141 | | string _responseContent = null; |
| 0 | 2142 | | if ((int)_statusCode != 200) |
| | 2143 | | { |
| 0 | 2144 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2145 | | try |
| | 2146 | | { |
| 0 | 2147 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2148 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 2149 | | if (_errorBody != null) |
| | 2150 | | { |
| 0 | 2151 | | ex.Body = _errorBody; |
| | 2152 | | } |
| 0 | 2153 | | } |
| 0 | 2154 | | catch (JsonException) |
| | 2155 | | { |
| | 2156 | | // Ignore the exception |
| 0 | 2157 | | } |
| 0 | 2158 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2159 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2160 | | if (_shouldTrace) |
| | 2161 | | { |
| 0 | 2162 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2163 | | } |
| 0 | 2164 | | _httpRequest.Dispose(); |
| 0 | 2165 | | if (_httpResponse != null) |
| | 2166 | | { |
| 0 | 2167 | | _httpResponse.Dispose(); |
| | 2168 | | } |
| 0 | 2169 | | throw ex; |
| | 2170 | | } |
| | 2171 | | // Create Result |
| 0 | 2172 | | var _result = new AzureOperationResponse<IPage<DirectoryObject>>(); |
| 0 | 2173 | | _result.Request = _httpRequest; |
| 0 | 2174 | | _result.Response = _httpResponse; |
| 0 | 2175 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2176 | | { |
| 0 | 2177 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2178 | | } |
| | 2179 | | // Deserialize Response |
| 0 | 2180 | | if ((int)_statusCode == 200) |
| | 2181 | | { |
| 0 | 2182 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2183 | | try |
| | 2184 | | { |
| 0 | 2185 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<DirectoryObject>>(_response |
| 0 | 2186 | | } |
| 0 | 2187 | | catch (JsonException ex) |
| | 2188 | | { |
| 0 | 2189 | | _httpRequest.Dispose(); |
| 0 | 2190 | | if (_httpResponse != null) |
| | 2191 | | { |
| 0 | 2192 | | _httpResponse.Dispose(); |
| | 2193 | | } |
| 0 | 2194 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2195 | | } |
| | 2196 | | } |
| 0 | 2197 | | if (_shouldTrace) |
| | 2198 | | { |
| 0 | 2199 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2200 | | } |
| 0 | 2201 | | return _result; |
| 0 | 2202 | | } |
| | 2203 | |
|
| | 2204 | | } |
| | 2205 | | } |