| | 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 | | /// UsersOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class UsersOperations : IServiceOperations<GraphRbacManagementClient>, IUsersOperations |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the UsersOperations 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 UsersOperations(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> |
| 444 | 52 | | public GraphRbacManagementClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Create a new user. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='parameters'> |
| | 58 | | /// Parameters to create a user. |
| | 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<User>> CreateWithHttpMessagesAsync(UserCreateParameters parameters, Dic |
| | 82 | | { |
| 4 | 83 | | if (parameters == null) |
| | 84 | | { |
| 0 | 85 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 86 | | } |
| 4 | 87 | | if (parameters != null) |
| | 88 | | { |
| 4 | 89 | | parameters.Validate(); |
| | 90 | | } |
| 4 | 91 | | if (Client.ApiVersion == null) |
| | 92 | | { |
| 0 | 93 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 94 | | } |
| 4 | 95 | | if (Client.TenantID == null) |
| | 96 | | { |
| 0 | 97 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 98 | | } |
| | 99 | | // Tracing |
| 4 | 100 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 101 | | string _invocationId = null; |
| 4 | 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 |
| 4 | 111 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 4 | 112 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/users" |
| 4 | 113 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 4 | 114 | | List<string> _queryParameters = new List<string>(); |
| 4 | 115 | | if (Client.ApiVersion != null) |
| | 116 | | { |
| 4 | 117 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 118 | | } |
| 4 | 119 | | if (_queryParameters.Count > 0) |
| | 120 | | { |
| 4 | 121 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 122 | | } |
| | 123 | | // Create HTTP transport objects |
| 4 | 124 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 125 | | HttpResponseMessage _httpResponse = null; |
| 4 | 126 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 127 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 128 | | // Set Headers |
| 4 | 129 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 130 | | { |
| 4 | 131 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 132 | | } |
| 4 | 133 | | if (Client.AcceptLanguage != null) |
| | 134 | | { |
| 4 | 135 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 136 | | { |
| 0 | 137 | | _httpRequest.Headers.Remove("accept-language"); |
| | 138 | | } |
| 4 | 139 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 140 | | } |
| | 141 | |
|
| | 142 | |
|
| 4 | 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 |
| 4 | 156 | | string _requestContent = null; |
| 4 | 157 | | if(parameters != null) |
| | 158 | | { |
| 4 | 159 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 4 | 160 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 161 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 162 | | } |
| | 163 | | // Set Credentials |
| 4 | 164 | | if (Client.Credentials != null) |
| | 165 | | { |
| 4 | 166 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 167 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 168 | | } |
| | 169 | | // Send Request |
| 4 | 170 | | if (_shouldTrace) |
| | 171 | | { |
| 0 | 172 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 173 | | } |
| 4 | 174 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 175 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 176 | | if (_shouldTrace) |
| | 177 | | { |
| 0 | 178 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 179 | | } |
| 4 | 180 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 181 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 182 | | string _responseContent = null; |
| 4 | 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 |
| 4 | 213 | | var _result = new AzureOperationResponse<User>(); |
| 4 | 214 | | _result.Request = _httpRequest; |
| 4 | 215 | | _result.Response = _httpResponse; |
| 4 | 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 |
| 4 | 221 | | if ((int)_statusCode == 201) |
| | 222 | | { |
| 4 | 223 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 224 | | try |
| | 225 | | { |
| 4 | 226 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<User>(_responseContent, Client.D |
| 4 | 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 | | } |
| 4 | 238 | | if (_shouldTrace) |
| | 239 | | { |
| 0 | 240 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 241 | | } |
| 4 | 242 | | return _result; |
| 4 | 243 | | } |
| | 244 | |
|
| | 245 | | /// <summary> |
| | 246 | | /// Gets list of users for 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<User>>> ListWithHttpMessagesAsync(ODataQuery<User> odataQuery = d |
| | 273 | | { |
| 10 | 274 | | if (Client.ApiVersion == null) |
| | 275 | | { |
| 0 | 276 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 277 | | } |
| 10 | 278 | | if (Client.TenantID == null) |
| | 279 | | { |
| 0 | 280 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 281 | | } |
| | 282 | | // Tracing |
| 10 | 283 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 10 | 284 | | string _invocationId = null; |
| 10 | 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 |
| 10 | 294 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 10 | 295 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/users" |
| 10 | 296 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 10 | 297 | | List<string> _queryParameters = new List<string>(); |
| 10 | 298 | | if (odataQuery != null) |
| | 299 | | { |
| 2 | 300 | | var _odataFilter = odataQuery.ToString(); |
| 2 | 301 | | if (!string.IsNullOrEmpty(_odataFilter)) |
| | 302 | | { |
| 2 | 303 | | _queryParameters.Add(_odataFilter); |
| | 304 | | } |
| | 305 | | } |
| 10 | 306 | | if (Client.ApiVersion != null) |
| | 307 | | { |
| 10 | 308 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 309 | | } |
| 10 | 310 | | if (_queryParameters.Count > 0) |
| | 311 | | { |
| 10 | 312 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 313 | | } |
| | 314 | | // Create HTTP transport objects |
| 10 | 315 | | var _httpRequest = new HttpRequestMessage(); |
| 10 | 316 | | HttpResponseMessage _httpResponse = null; |
| 10 | 317 | | _httpRequest.Method = new HttpMethod("GET"); |
| 10 | 318 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 319 | | // Set Headers |
| 10 | 320 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 321 | | { |
| 10 | 322 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 323 | | } |
| 10 | 324 | | if (Client.AcceptLanguage != null) |
| | 325 | | { |
| 10 | 326 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 327 | | { |
| 0 | 328 | | _httpRequest.Headers.Remove("accept-language"); |
| | 329 | | } |
| 10 | 330 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 331 | | } |
| | 332 | |
|
| | 333 | |
|
| 10 | 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 |
| 10 | 347 | | string _requestContent = null; |
| | 348 | | // Set Credentials |
| 10 | 349 | | if (Client.Credentials != null) |
| | 350 | | { |
| 10 | 351 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 352 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 353 | | } |
| | 354 | | // Send Request |
| 10 | 355 | | if (_shouldTrace) |
| | 356 | | { |
| 0 | 357 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 358 | | } |
| 10 | 359 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 360 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 10 | 361 | | if (_shouldTrace) |
| | 362 | | { |
| 0 | 363 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 364 | | } |
| 10 | 365 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 10 | 366 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 367 | | string _responseContent = null; |
| 10 | 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 |
| 10 | 398 | | var _result = new AzureOperationResponse<IPage<User>>(); |
| 10 | 399 | | _result.Request = _httpRequest; |
| 10 | 400 | | _result.Response = _httpResponse; |
| 10 | 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 |
| 10 | 406 | | if ((int)_statusCode == 200) |
| | 407 | | { |
| 10 | 408 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 409 | | try |
| | 410 | | { |
| 10 | 411 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<User>>(_responseContent, Cl |
| 10 | 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 | | } |
| 10 | 423 | | if (_shouldTrace) |
| | 424 | | { |
| 0 | 425 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 426 | | } |
| 10 | 427 | | return _result; |
| 10 | 428 | | } |
| | 429 | |
|
| | 430 | | /// <summary> |
| | 431 | | /// Gets user information from the directory. |
| | 432 | | /// </summary> |
| | 433 | | /// <param name='upnOrObjectId'> |
| | 434 | | /// The object ID or principal name of the user for which to get information. |
| | 435 | | /// </param> |
| | 436 | | /// <param name='customHeaders'> |
| | 437 | | /// Headers that will be added to request. |
| | 438 | | /// </param> |
| | 439 | | /// <param name='cancellationToken'> |
| | 440 | | /// The cancellation token. |
| | 441 | | /// </param> |
| | 442 | | /// <exception cref="GraphErrorException"> |
| | 443 | | /// Thrown when the operation returned an invalid status code |
| | 444 | | /// </exception> |
| | 445 | | /// <exception cref="SerializationException"> |
| | 446 | | /// Thrown when unable to deserialize the response |
| | 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<User>> GetWithHttpMessagesAsync(string upnOrObjectId, Dictionary<string |
| | 458 | | { |
| 4 | 459 | | if (upnOrObjectId == null) |
| | 460 | | { |
| 0 | 461 | | throw new ValidationException(ValidationRules.CannotBeNull, "upnOrObjectId"); |
| | 462 | | } |
| 4 | 463 | | if (Client.ApiVersion == null) |
| | 464 | | { |
| 0 | 465 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 466 | | } |
| 4 | 467 | | if (Client.TenantID == null) |
| | 468 | | { |
| 0 | 469 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 470 | | } |
| | 471 | | // Tracing |
| 4 | 472 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 473 | | string _invocationId = null; |
| 4 | 474 | | if (_shouldTrace) |
| | 475 | | { |
| 0 | 476 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 477 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 478 | | tracingParameters.Add("upnOrObjectId", upnOrObjectId); |
| 0 | 479 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 480 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 481 | | } |
| | 482 | | // Construct URL |
| 4 | 483 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 4 | 484 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/users/ |
| 4 | 485 | | _url = _url.Replace("{upnOrObjectId}", System.Uri.EscapeDataString(upnOrObjectId)); |
| 4 | 486 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 4 | 487 | | List<string> _queryParameters = new List<string>(); |
| 4 | 488 | | if (Client.ApiVersion != null) |
| | 489 | | { |
| 4 | 490 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 491 | | } |
| 4 | 492 | | if (_queryParameters.Count > 0) |
| | 493 | | { |
| 4 | 494 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 495 | | } |
| | 496 | | // Create HTTP transport objects |
| 4 | 497 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 498 | | HttpResponseMessage _httpResponse = null; |
| 4 | 499 | | _httpRequest.Method = new HttpMethod("GET"); |
| 4 | 500 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 501 | | // Set Headers |
| 4 | 502 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 503 | | { |
| 4 | 504 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 505 | | } |
| 4 | 506 | | if (Client.AcceptLanguage != null) |
| | 507 | | { |
| 4 | 508 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 509 | | { |
| 0 | 510 | | _httpRequest.Headers.Remove("accept-language"); |
| | 511 | | } |
| 4 | 512 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 513 | | } |
| | 514 | |
|
| | 515 | |
|
| 4 | 516 | | if (customHeaders != null) |
| | 517 | | { |
| 0 | 518 | | foreach(var _header in customHeaders) |
| | 519 | | { |
| 0 | 520 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 521 | | { |
| 0 | 522 | | _httpRequest.Headers.Remove(_header.Key); |
| | 523 | | } |
| 0 | 524 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 525 | | } |
| | 526 | | } |
| | 527 | |
|
| | 528 | | // Serialize Request |
| 4 | 529 | | string _requestContent = null; |
| | 530 | | // Set Credentials |
| 4 | 531 | | if (Client.Credentials != null) |
| | 532 | | { |
| 4 | 533 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 534 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 535 | | } |
| | 536 | | // Send Request |
| 4 | 537 | | if (_shouldTrace) |
| | 538 | | { |
| 0 | 539 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 540 | | } |
| 4 | 541 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 542 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 543 | | if (_shouldTrace) |
| | 544 | | { |
| 0 | 545 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 546 | | } |
| 4 | 547 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 548 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 549 | | string _responseContent = null; |
| 4 | 550 | | if ((int)_statusCode != 200) |
| | 551 | | { |
| 2 | 552 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 553 | | try |
| | 554 | | { |
| 2 | 555 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 2 | 556 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 2 | 557 | | if (_errorBody != null) |
| | 558 | | { |
| 2 | 559 | | ex.Body = _errorBody; |
| | 560 | | } |
| 2 | 561 | | } |
| 0 | 562 | | catch (JsonException) |
| | 563 | | { |
| | 564 | | // Ignore the exception |
| 0 | 565 | | } |
| 2 | 566 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 2 | 567 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 2 | 568 | | if (_shouldTrace) |
| | 569 | | { |
| 0 | 570 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 571 | | } |
| 2 | 572 | | _httpRequest.Dispose(); |
| 2 | 573 | | if (_httpResponse != null) |
| | 574 | | { |
| 2 | 575 | | _httpResponse.Dispose(); |
| | 576 | | } |
| 2 | 577 | | throw ex; |
| | 578 | | } |
| | 579 | | // Create Result |
| 2 | 580 | | var _result = new AzureOperationResponse<User>(); |
| 2 | 581 | | _result.Request = _httpRequest; |
| 2 | 582 | | _result.Response = _httpResponse; |
| 2 | 583 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 584 | | { |
| 0 | 585 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 586 | | } |
| | 587 | | // Deserialize Response |
| 2 | 588 | | if ((int)_statusCode == 200) |
| | 589 | | { |
| 2 | 590 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 591 | | try |
| | 592 | | { |
| 2 | 593 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<User>(_responseContent, Client.D |
| 2 | 594 | | } |
| 0 | 595 | | catch (JsonException ex) |
| | 596 | | { |
| 0 | 597 | | _httpRequest.Dispose(); |
| 0 | 598 | | if (_httpResponse != null) |
| | 599 | | { |
| 0 | 600 | | _httpResponse.Dispose(); |
| | 601 | | } |
| 0 | 602 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 603 | | } |
| | 604 | | } |
| 2 | 605 | | if (_shouldTrace) |
| | 606 | | { |
| 0 | 607 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 608 | | } |
| 2 | 609 | | return _result; |
| 2 | 610 | | } |
| | 611 | |
|
| | 612 | | /// <summary> |
| | 613 | | /// Updates a user. |
| | 614 | | /// </summary> |
| | 615 | | /// <param name='upnOrObjectId'> |
| | 616 | | /// The object ID or principal name of the user to update. |
| | 617 | | /// </param> |
| | 618 | | /// <param name='parameters'> |
| | 619 | | /// Parameters to update an existing user. |
| | 620 | | /// </param> |
| | 621 | | /// <param name='customHeaders'> |
| | 622 | | /// Headers that will be added to request. |
| | 623 | | /// </param> |
| | 624 | | /// <param name='cancellationToken'> |
| | 625 | | /// The cancellation token. |
| | 626 | | /// </param> |
| | 627 | | /// <exception cref="GraphErrorException"> |
| | 628 | | /// Thrown when the operation returned an invalid status code |
| | 629 | | /// </exception> |
| | 630 | | /// <exception cref="ValidationException"> |
| | 631 | | /// Thrown when a required parameter is null |
| | 632 | | /// </exception> |
| | 633 | | /// <exception cref="System.ArgumentNullException"> |
| | 634 | | /// Thrown when a required parameter is null |
| | 635 | | /// </exception> |
| | 636 | | /// <return> |
| | 637 | | /// A response object containing the response body and response headers. |
| | 638 | | /// </return> |
| | 639 | | public async Task<AzureOperationResponse> UpdateWithHttpMessagesAsync(string upnOrObjectId, UserUpdateParameters |
| | 640 | | { |
| 0 | 641 | | if (upnOrObjectId == null) |
| | 642 | | { |
| 0 | 643 | | throw new ValidationException(ValidationRules.CannotBeNull, "upnOrObjectId"); |
| | 644 | | } |
| 0 | 645 | | if (parameters == null) |
| | 646 | | { |
| 0 | 647 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 648 | | } |
| 0 | 649 | | if (Client.ApiVersion == null) |
| | 650 | | { |
| 0 | 651 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 652 | | } |
| 0 | 653 | | if (Client.TenantID == null) |
| | 654 | | { |
| 0 | 655 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 656 | | } |
| | 657 | | // Tracing |
| 0 | 658 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 659 | | string _invocationId = null; |
| 0 | 660 | | if (_shouldTrace) |
| | 661 | | { |
| 0 | 662 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 663 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 664 | | tracingParameters.Add("upnOrObjectId", upnOrObjectId); |
| 0 | 665 | | tracingParameters.Add("parameters", parameters); |
| 0 | 666 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 667 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 668 | | } |
| | 669 | | // Construct URL |
| 0 | 670 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 671 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/users/ |
| 0 | 672 | | _url = _url.Replace("{upnOrObjectId}", System.Uri.EscapeDataString(upnOrObjectId)); |
| 0 | 673 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 674 | | List<string> _queryParameters = new List<string>(); |
| 0 | 675 | | if (Client.ApiVersion != null) |
| | 676 | | { |
| 0 | 677 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 678 | | } |
| 0 | 679 | | if (_queryParameters.Count > 0) |
| | 680 | | { |
| 0 | 681 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 682 | | } |
| | 683 | | // Create HTTP transport objects |
| 0 | 684 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 685 | | HttpResponseMessage _httpResponse = null; |
| 0 | 686 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 687 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 688 | | // Set Headers |
| 0 | 689 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 690 | | { |
| 0 | 691 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 692 | | } |
| 0 | 693 | | if (Client.AcceptLanguage != null) |
| | 694 | | { |
| 0 | 695 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 696 | | { |
| 0 | 697 | | _httpRequest.Headers.Remove("accept-language"); |
| | 698 | | } |
| 0 | 699 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 700 | | } |
| | 701 | |
|
| | 702 | |
|
| 0 | 703 | | if (customHeaders != null) |
| | 704 | | { |
| 0 | 705 | | foreach(var _header in customHeaders) |
| | 706 | | { |
| 0 | 707 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 708 | | { |
| 0 | 709 | | _httpRequest.Headers.Remove(_header.Key); |
| | 710 | | } |
| 0 | 711 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 712 | | } |
| | 713 | | } |
| | 714 | |
|
| | 715 | | // Serialize Request |
| 0 | 716 | | string _requestContent = null; |
| 0 | 717 | | if(parameters != null) |
| | 718 | | { |
| 0 | 719 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 720 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 721 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 722 | | } |
| | 723 | | // Set Credentials |
| 0 | 724 | | if (Client.Credentials != null) |
| | 725 | | { |
| 0 | 726 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 727 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 728 | | } |
| | 729 | | // Send Request |
| 0 | 730 | | if (_shouldTrace) |
| | 731 | | { |
| 0 | 732 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 733 | | } |
| 0 | 734 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 735 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 736 | | if (_shouldTrace) |
| | 737 | | { |
| 0 | 738 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 739 | | } |
| 0 | 740 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 741 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 742 | | string _responseContent = null; |
| 0 | 743 | | if ((int)_statusCode != 204) |
| | 744 | | { |
| 0 | 745 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 746 | | try |
| | 747 | | { |
| 0 | 748 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 749 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 750 | | if (_errorBody != null) |
| | 751 | | { |
| 0 | 752 | | ex.Body = _errorBody; |
| | 753 | | } |
| 0 | 754 | | } |
| 0 | 755 | | catch (JsonException) |
| | 756 | | { |
| | 757 | | // Ignore the exception |
| 0 | 758 | | } |
| 0 | 759 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 760 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 761 | | if (_shouldTrace) |
| | 762 | | { |
| 0 | 763 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 764 | | } |
| 0 | 765 | | _httpRequest.Dispose(); |
| 0 | 766 | | if (_httpResponse != null) |
| | 767 | | { |
| 0 | 768 | | _httpResponse.Dispose(); |
| | 769 | | } |
| 0 | 770 | | throw ex; |
| | 771 | | } |
| | 772 | | // Create Result |
| 0 | 773 | | var _result = new AzureOperationResponse(); |
| 0 | 774 | | _result.Request = _httpRequest; |
| 0 | 775 | | _result.Response = _httpResponse; |
| 0 | 776 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 777 | | { |
| 0 | 778 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 779 | | } |
| 0 | 780 | | if (_shouldTrace) |
| | 781 | | { |
| 0 | 782 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 783 | | } |
| 0 | 784 | | return _result; |
| 0 | 785 | | } |
| | 786 | |
|
| | 787 | | /// <summary> |
| | 788 | | /// Delete a user. |
| | 789 | | /// </summary> |
| | 790 | | /// <param name='upnOrObjectId'> |
| | 791 | | /// The object ID or principal name of the user to delete. |
| | 792 | | /// </param> |
| | 793 | | /// <param name='customHeaders'> |
| | 794 | | /// Headers that will be added to request. |
| | 795 | | /// </param> |
| | 796 | | /// <param name='cancellationToken'> |
| | 797 | | /// The cancellation token. |
| | 798 | | /// </param> |
| | 799 | | /// <exception cref="GraphErrorException"> |
| | 800 | | /// Thrown when the operation returned an invalid status code |
| | 801 | | /// </exception> |
| | 802 | | /// <exception cref="ValidationException"> |
| | 803 | | /// Thrown when a required parameter is null |
| | 804 | | /// </exception> |
| | 805 | | /// <exception cref="System.ArgumentNullException"> |
| | 806 | | /// Thrown when a required parameter is null |
| | 807 | | /// </exception> |
| | 808 | | /// <return> |
| | 809 | | /// A response object containing the response body and response headers. |
| | 810 | | /// </return> |
| | 811 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string upnOrObjectId, Dictionary<string, L |
| | 812 | | { |
| 4 | 813 | | if (upnOrObjectId == null) |
| | 814 | | { |
| 0 | 815 | | throw new ValidationException(ValidationRules.CannotBeNull, "upnOrObjectId"); |
| | 816 | | } |
| 4 | 817 | | if (Client.ApiVersion == null) |
| | 818 | | { |
| 0 | 819 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 820 | | } |
| 4 | 821 | | if (Client.TenantID == null) |
| | 822 | | { |
| 0 | 823 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 824 | | } |
| | 825 | | // Tracing |
| 4 | 826 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 827 | | string _invocationId = null; |
| 4 | 828 | | if (_shouldTrace) |
| | 829 | | { |
| 0 | 830 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 831 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 832 | | tracingParameters.Add("upnOrObjectId", upnOrObjectId); |
| 0 | 833 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 834 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 835 | | } |
| | 836 | | // Construct URL |
| 4 | 837 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 4 | 838 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/users/ |
| 4 | 839 | | _url = _url.Replace("{upnOrObjectId}", System.Uri.EscapeDataString(upnOrObjectId)); |
| 4 | 840 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 4 | 841 | | List<string> _queryParameters = new List<string>(); |
| 4 | 842 | | if (Client.ApiVersion != null) |
| | 843 | | { |
| 4 | 844 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 845 | | } |
| 4 | 846 | | if (_queryParameters.Count > 0) |
| | 847 | | { |
| 4 | 848 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 849 | | } |
| | 850 | | // Create HTTP transport objects |
| 4 | 851 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 852 | | HttpResponseMessage _httpResponse = null; |
| 4 | 853 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 4 | 854 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 855 | | // Set Headers |
| 4 | 856 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 857 | | { |
| 4 | 858 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 859 | | } |
| 4 | 860 | | if (Client.AcceptLanguage != null) |
| | 861 | | { |
| 4 | 862 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 863 | | { |
| 0 | 864 | | _httpRequest.Headers.Remove("accept-language"); |
| | 865 | | } |
| 4 | 866 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 867 | | } |
| | 868 | |
|
| | 869 | |
|
| 4 | 870 | | if (customHeaders != null) |
| | 871 | | { |
| 0 | 872 | | foreach(var _header in customHeaders) |
| | 873 | | { |
| 0 | 874 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 875 | | { |
| 0 | 876 | | _httpRequest.Headers.Remove(_header.Key); |
| | 877 | | } |
| 0 | 878 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 879 | | } |
| | 880 | | } |
| | 881 | |
|
| | 882 | | // Serialize Request |
| 4 | 883 | | string _requestContent = null; |
| | 884 | | // Set Credentials |
| 4 | 885 | | if (Client.Credentials != null) |
| | 886 | | { |
| 4 | 887 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 888 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 889 | | } |
| | 890 | | // Send Request |
| 4 | 891 | | if (_shouldTrace) |
| | 892 | | { |
| 0 | 893 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 894 | | } |
| 4 | 895 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 896 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 897 | | if (_shouldTrace) |
| | 898 | | { |
| 0 | 899 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 900 | | } |
| 4 | 901 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 902 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 903 | | string _responseContent = null; |
| 4 | 904 | | if ((int)_statusCode != 204) |
| | 905 | | { |
| 0 | 906 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 907 | | try |
| | 908 | | { |
| 0 | 909 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 910 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 911 | | if (_errorBody != null) |
| | 912 | | { |
| 0 | 913 | | ex.Body = _errorBody; |
| | 914 | | } |
| 0 | 915 | | } |
| 0 | 916 | | catch (JsonException) |
| | 917 | | { |
| | 918 | | // Ignore the exception |
| 0 | 919 | | } |
| 0 | 920 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 921 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 922 | | if (_shouldTrace) |
| | 923 | | { |
| 0 | 924 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 925 | | } |
| 0 | 926 | | _httpRequest.Dispose(); |
| 0 | 927 | | if (_httpResponse != null) |
| | 928 | | { |
| 0 | 929 | | _httpResponse.Dispose(); |
| | 930 | | } |
| 0 | 931 | | throw ex; |
| | 932 | | } |
| | 933 | | // Create Result |
| 4 | 934 | | var _result = new AzureOperationResponse(); |
| 4 | 935 | | _result.Request = _httpRequest; |
| 4 | 936 | | _result.Response = _httpResponse; |
| 4 | 937 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 938 | | { |
| 0 | 939 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 940 | | } |
| 4 | 941 | | if (_shouldTrace) |
| | 942 | | { |
| 0 | 943 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 944 | | } |
| 4 | 945 | | return _result; |
| 4 | 946 | | } |
| | 947 | |
|
| | 948 | | /// <summary> |
| | 949 | | /// Gets a collection that contains the object IDs of the groups of which the |
| | 950 | | /// user is a member. |
| | 951 | | /// </summary> |
| | 952 | | /// <param name='objectId'> |
| | 953 | | /// The object ID of the user for which to get group membership. |
| | 954 | | /// </param> |
| | 955 | | /// <param name='parameters'> |
| | 956 | | /// User filtering parameters. |
| | 957 | | /// </param> |
| | 958 | | /// <param name='customHeaders'> |
| | 959 | | /// Headers that will be added to request. |
| | 960 | | /// </param> |
| | 961 | | /// <param name='cancellationToken'> |
| | 962 | | /// The cancellation token. |
| | 963 | | /// </param> |
| | 964 | | /// <exception cref="GraphErrorException"> |
| | 965 | | /// Thrown when the operation returned an invalid status code |
| | 966 | | /// </exception> |
| | 967 | | /// <exception cref="SerializationException"> |
| | 968 | | /// Thrown when unable to deserialize the response |
| | 969 | | /// </exception> |
| | 970 | | /// <exception cref="ValidationException"> |
| | 971 | | /// Thrown when a required parameter is null |
| | 972 | | /// </exception> |
| | 973 | | /// <exception cref="System.ArgumentNullException"> |
| | 974 | | /// Thrown when a required parameter is null |
| | 975 | | /// </exception> |
| | 976 | | /// <return> |
| | 977 | | /// A response object containing the response body and response headers. |
| | 978 | | /// </return> |
| | 979 | | public async Task<AzureOperationResponse<IEnumerable<string>>> GetMemberGroupsWithHttpMessagesAsync(string objec |
| | 980 | | { |
| 6 | 981 | | if (objectId == null) |
| | 982 | | { |
| 0 | 983 | | throw new ValidationException(ValidationRules.CannotBeNull, "objectId"); |
| | 984 | | } |
| 6 | 985 | | if (parameters == null) |
| | 986 | | { |
| 0 | 987 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 988 | | } |
| 6 | 989 | | if (parameters != null) |
| | 990 | | { |
| 6 | 991 | | parameters.Validate(); |
| | 992 | | } |
| 6 | 993 | | if (Client.ApiVersion == null) |
| | 994 | | { |
| 0 | 995 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 996 | | } |
| 6 | 997 | | if (Client.TenantID == null) |
| | 998 | | { |
| 0 | 999 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1000 | | } |
| | 1001 | | // Tracing |
| 6 | 1002 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 1003 | | string _invocationId = null; |
| 6 | 1004 | | if (_shouldTrace) |
| | 1005 | | { |
| 0 | 1006 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1007 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1008 | | tracingParameters.Add("objectId", objectId); |
| 0 | 1009 | | tracingParameters.Add("parameters", parameters); |
| 0 | 1010 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1011 | | ServiceClientTracing.Enter(_invocationId, this, "GetMemberGroups", tracingParameters); |
| | 1012 | | } |
| | 1013 | | // Construct URL |
| 6 | 1014 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 6 | 1015 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/users/ |
| 6 | 1016 | | _url = _url.Replace("{objectId}", System.Uri.EscapeDataString(objectId)); |
| 6 | 1017 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 6 | 1018 | | List<string> _queryParameters = new List<string>(); |
| 6 | 1019 | | if (Client.ApiVersion != null) |
| | 1020 | | { |
| 6 | 1021 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1022 | | } |
| 6 | 1023 | | if (_queryParameters.Count > 0) |
| | 1024 | | { |
| 6 | 1025 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1026 | | } |
| | 1027 | | // Create HTTP transport objects |
| 6 | 1028 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 1029 | | HttpResponseMessage _httpResponse = null; |
| 6 | 1030 | | _httpRequest.Method = new HttpMethod("POST"); |
| 6 | 1031 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1032 | | // Set Headers |
| 6 | 1033 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1034 | | { |
| 6 | 1035 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1036 | | } |
| 6 | 1037 | | if (Client.AcceptLanguage != null) |
| | 1038 | | { |
| 6 | 1039 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1040 | | { |
| 0 | 1041 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1042 | | } |
| 6 | 1043 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1044 | | } |
| | 1045 | |
|
| | 1046 | |
|
| 6 | 1047 | | if (customHeaders != null) |
| | 1048 | | { |
| 0 | 1049 | | foreach(var _header in customHeaders) |
| | 1050 | | { |
| 0 | 1051 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1052 | | { |
| 0 | 1053 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1054 | | } |
| 0 | 1055 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1056 | | } |
| | 1057 | | } |
| | 1058 | |
|
| | 1059 | | // Serialize Request |
| 6 | 1060 | | string _requestContent = null; |
| 6 | 1061 | | if(parameters != null) |
| | 1062 | | { |
| 6 | 1063 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 6 | 1064 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 6 | 1065 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1066 | | } |
| | 1067 | | // Set Credentials |
| 6 | 1068 | | if (Client.Credentials != null) |
| | 1069 | | { |
| 6 | 1070 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1071 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1072 | | } |
| | 1073 | | // Send Request |
| 6 | 1074 | | if (_shouldTrace) |
| | 1075 | | { |
| 0 | 1076 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1077 | | } |
| 6 | 1078 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1079 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 1080 | | if (_shouldTrace) |
| | 1081 | | { |
| 0 | 1082 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1083 | | } |
| 6 | 1084 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 1085 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1086 | | string _responseContent = null; |
| 6 | 1087 | | if ((int)_statusCode != 200) |
| | 1088 | | { |
| 0 | 1089 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1090 | | try |
| | 1091 | | { |
| 0 | 1092 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1093 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1094 | | if (_errorBody != null) |
| | 1095 | | { |
| 0 | 1096 | | ex.Body = _errorBody; |
| | 1097 | | } |
| 0 | 1098 | | } |
| 0 | 1099 | | catch (JsonException) |
| | 1100 | | { |
| | 1101 | | // Ignore the exception |
| 0 | 1102 | | } |
| 0 | 1103 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1104 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1105 | | if (_shouldTrace) |
| | 1106 | | { |
| 0 | 1107 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1108 | | } |
| 0 | 1109 | | _httpRequest.Dispose(); |
| 0 | 1110 | | if (_httpResponse != null) |
| | 1111 | | { |
| 0 | 1112 | | _httpResponse.Dispose(); |
| | 1113 | | } |
| 0 | 1114 | | throw ex; |
| | 1115 | | } |
| | 1116 | | // Create Result |
| 6 | 1117 | | var _result = new AzureOperationResponse<IEnumerable<string>>(); |
| 6 | 1118 | | _result.Request = _httpRequest; |
| 6 | 1119 | | _result.Response = _httpResponse; |
| 6 | 1120 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1121 | | { |
| 0 | 1122 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1123 | | } |
| | 1124 | | // Deserialize Response |
| 6 | 1125 | | if ((int)_statusCode == 200) |
| | 1126 | | { |
| 6 | 1127 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1128 | | try |
| | 1129 | | { |
| 6 | 1130 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<string>>(_responseContent, |
| 6 | 1131 | | } |
| 0 | 1132 | | catch (JsonException ex) |
| | 1133 | | { |
| 0 | 1134 | | _httpRequest.Dispose(); |
| 0 | 1135 | | if (_httpResponse != null) |
| | 1136 | | { |
| 0 | 1137 | | _httpResponse.Dispose(); |
| | 1138 | | } |
| 0 | 1139 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1140 | | } |
| | 1141 | | } |
| 6 | 1142 | | if (_shouldTrace) |
| | 1143 | | { |
| 0 | 1144 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1145 | | } |
| 6 | 1146 | | return _result; |
| 6 | 1147 | | } |
| | 1148 | |
|
| | 1149 | | /// <summary> |
| | 1150 | | /// Gets a list of users for the current tenant. |
| | 1151 | | /// </summary> |
| | 1152 | | /// <param name='nextLink'> |
| | 1153 | | /// Next link for the list operation. |
| | 1154 | | /// </param> |
| | 1155 | | /// <param name='customHeaders'> |
| | 1156 | | /// Headers that will be added to request. |
| | 1157 | | /// </param> |
| | 1158 | | /// <param name='cancellationToken'> |
| | 1159 | | /// The cancellation token. |
| | 1160 | | /// </param> |
| | 1161 | | /// <exception cref="GraphErrorException"> |
| | 1162 | | /// Thrown when the operation returned an invalid status code |
| | 1163 | | /// </exception> |
| | 1164 | | /// <exception cref="SerializationException"> |
| | 1165 | | /// Thrown when unable to deserialize the response |
| | 1166 | | /// </exception> |
| | 1167 | | /// <exception cref="ValidationException"> |
| | 1168 | | /// Thrown when a required parameter is null |
| | 1169 | | /// </exception> |
| | 1170 | | /// <exception cref="System.ArgumentNullException"> |
| | 1171 | | /// Thrown when a required parameter is null |
| | 1172 | | /// </exception> |
| | 1173 | | /// <return> |
| | 1174 | | /// A response object containing the response body and response headers. |
| | 1175 | | /// </return> |
| | 1176 | | public async Task<AzureOperationResponse<IPage<User>>> ListNextWithHttpMessagesAsync(string nextLink, Dictionary |
| | 1177 | | { |
| 0 | 1178 | | if (nextLink == null) |
| | 1179 | | { |
| 0 | 1180 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextLink"); |
| | 1181 | | } |
| 0 | 1182 | | if (Client.ApiVersion == null) |
| | 1183 | | { |
| 0 | 1184 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1185 | | } |
| 0 | 1186 | | if (Client.TenantID == null) |
| | 1187 | | { |
| 0 | 1188 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1189 | | } |
| | 1190 | | // Tracing |
| 0 | 1191 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1192 | | string _invocationId = null; |
| 0 | 1193 | | if (_shouldTrace) |
| | 1194 | | { |
| 0 | 1195 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1196 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1197 | | tracingParameters.Add("nextLink", nextLink); |
| 0 | 1198 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1199 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 1200 | | } |
| | 1201 | | // Construct URL |
| 0 | 1202 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1203 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/{nextL |
| 0 | 1204 | | _url = _url.Replace("{nextLink}", nextLink); |
| 0 | 1205 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1206 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1207 | | if (Client.ApiVersion != null) |
| | 1208 | | { |
| 0 | 1209 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1210 | | } |
| 0 | 1211 | | if (_queryParameters.Count > 0) |
| | 1212 | | { |
| 0 | 1213 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1214 | | } |
| | 1215 | | // Create HTTP transport objects |
| 0 | 1216 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1217 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1218 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1219 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1220 | | // Set Headers |
| 0 | 1221 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1222 | | { |
| 0 | 1223 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1224 | | } |
| 0 | 1225 | | if (Client.AcceptLanguage != null) |
| | 1226 | | { |
| 0 | 1227 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1228 | | { |
| 0 | 1229 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1230 | | } |
| 0 | 1231 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1232 | | } |
| | 1233 | |
|
| | 1234 | |
|
| 0 | 1235 | | if (customHeaders != null) |
| | 1236 | | { |
| 0 | 1237 | | foreach(var _header in customHeaders) |
| | 1238 | | { |
| 0 | 1239 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1240 | | { |
| 0 | 1241 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1242 | | } |
| 0 | 1243 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1244 | | } |
| | 1245 | | } |
| | 1246 | |
|
| | 1247 | | // Serialize Request |
| 0 | 1248 | | string _requestContent = null; |
| | 1249 | | // Set Credentials |
| 0 | 1250 | | if (Client.Credentials != null) |
| | 1251 | | { |
| 0 | 1252 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1253 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1254 | | } |
| | 1255 | | // Send Request |
| 0 | 1256 | | if (_shouldTrace) |
| | 1257 | | { |
| 0 | 1258 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1259 | | } |
| 0 | 1260 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1261 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1262 | | if (_shouldTrace) |
| | 1263 | | { |
| 0 | 1264 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1265 | | } |
| 0 | 1266 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1267 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1268 | | string _responseContent = null; |
| 0 | 1269 | | if ((int)_statusCode != 200) |
| | 1270 | | { |
| 0 | 1271 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1272 | | try |
| | 1273 | | { |
| 0 | 1274 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1275 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1276 | | if (_errorBody != null) |
| | 1277 | | { |
| 0 | 1278 | | ex.Body = _errorBody; |
| | 1279 | | } |
| 0 | 1280 | | } |
| 0 | 1281 | | catch (JsonException) |
| | 1282 | | { |
| | 1283 | | // Ignore the exception |
| 0 | 1284 | | } |
| 0 | 1285 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1286 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1287 | | if (_shouldTrace) |
| | 1288 | | { |
| 0 | 1289 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1290 | | } |
| 0 | 1291 | | _httpRequest.Dispose(); |
| 0 | 1292 | | if (_httpResponse != null) |
| | 1293 | | { |
| 0 | 1294 | | _httpResponse.Dispose(); |
| | 1295 | | } |
| 0 | 1296 | | throw ex; |
| | 1297 | | } |
| | 1298 | | // Create Result |
| 0 | 1299 | | var _result = new AzureOperationResponse<IPage<User>>(); |
| 0 | 1300 | | _result.Request = _httpRequest; |
| 0 | 1301 | | _result.Response = _httpResponse; |
| 0 | 1302 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1303 | | { |
| 0 | 1304 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1305 | | } |
| | 1306 | | // Deserialize Response |
| 0 | 1307 | | if ((int)_statusCode == 200) |
| | 1308 | | { |
| 0 | 1309 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1310 | | try |
| | 1311 | | { |
| 0 | 1312 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<User>>(_responseContent, Cl |
| 0 | 1313 | | } |
| 0 | 1314 | | catch (JsonException ex) |
| | 1315 | | { |
| 0 | 1316 | | _httpRequest.Dispose(); |
| 0 | 1317 | | if (_httpResponse != null) |
| | 1318 | | { |
| 0 | 1319 | | _httpResponse.Dispose(); |
| | 1320 | | } |
| 0 | 1321 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1322 | | } |
| | 1323 | | } |
| 0 | 1324 | | if (_shouldTrace) |
| | 1325 | | { |
| 0 | 1326 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1327 | | } |
| 0 | 1328 | | return _result; |
| 0 | 1329 | | } |
| | 1330 | |
|
| | 1331 | | } |
| | 1332 | | } |