| | 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 | | /// ApplicationsOperations operations. |
| | 28 | | /// </summary> |
| | 29 | | internal partial class ApplicationsOperations : IServiceOperations<GraphRbacManagementClient>, IApplicationsOperatio |
| | 30 | | { |
| | 31 | | /// <summary> |
| | 32 | | /// Initializes a new instance of the ApplicationsOperations 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 ApplicationsOperations(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> |
| 0 | 52 | | public GraphRbacManagementClient Client { get; private set; } |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Create a new application. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name='parameters'> |
| | 58 | | /// The parameters for creating an application. |
| | 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<Application>> CreateWithHttpMessagesAsync(ApplicationCreateParameters p |
| | 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}/applic |
| 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<Application>(); |
| 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<Application>(_responseContent, C |
| 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 | | /// Lists applications by filter parameters. |
| | 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<Application>>> ListWithHttpMessagesAsync(ODataQuery<Application> |
| | 273 | | { |
| 0 | 274 | | if (Client.ApiVersion == null) |
| | 275 | | { |
| 0 | 276 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 277 | | } |
| 0 | 278 | | if (Client.TenantID == null) |
| | 279 | | { |
| 0 | 280 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 281 | | } |
| | 282 | | // Tracing |
| 0 | 283 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 284 | | string _invocationId = null; |
| 0 | 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 |
| 0 | 294 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 295 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 296 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 297 | | List<string> _queryParameters = new List<string>(); |
| 0 | 298 | | if (odataQuery != null) |
| | 299 | | { |
| 0 | 300 | | var _odataFilter = odataQuery.ToString(); |
| 0 | 301 | | if (!string.IsNullOrEmpty(_odataFilter)) |
| | 302 | | { |
| 0 | 303 | | _queryParameters.Add(_odataFilter); |
| | 304 | | } |
| | 305 | | } |
| 0 | 306 | | if (Client.ApiVersion != null) |
| | 307 | | { |
| 0 | 308 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 309 | | } |
| 0 | 310 | | if (_queryParameters.Count > 0) |
| | 311 | | { |
| 0 | 312 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 313 | | } |
| | 314 | | // Create HTTP transport objects |
| 0 | 315 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 316 | | HttpResponseMessage _httpResponse = null; |
| 0 | 317 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 318 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 319 | | // Set Headers |
| 0 | 320 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 321 | | { |
| 0 | 322 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 323 | | } |
| 0 | 324 | | if (Client.AcceptLanguage != null) |
| | 325 | | { |
| 0 | 326 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 327 | | { |
| 0 | 328 | | _httpRequest.Headers.Remove("accept-language"); |
| | 329 | | } |
| 0 | 330 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 331 | | } |
| | 332 | |
|
| | 333 | |
|
| 0 | 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 |
| 0 | 347 | | string _requestContent = null; |
| | 348 | | // Set Credentials |
| 0 | 349 | | if (Client.Credentials != null) |
| | 350 | | { |
| 0 | 351 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 352 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 353 | | } |
| | 354 | | // Send Request |
| 0 | 355 | | if (_shouldTrace) |
| | 356 | | { |
| 0 | 357 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 358 | | } |
| 0 | 359 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 360 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 361 | | if (_shouldTrace) |
| | 362 | | { |
| 0 | 363 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 364 | | } |
| 0 | 365 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 366 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 367 | | string _responseContent = null; |
| 0 | 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 |
| 0 | 398 | | var _result = new AzureOperationResponse<IPage<Application>>(); |
| 0 | 399 | | _result.Request = _httpRequest; |
| 0 | 400 | | _result.Response = _httpResponse; |
| 0 | 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 |
| 0 | 406 | | if ((int)_statusCode == 200) |
| | 407 | | { |
| 0 | 408 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 409 | | try |
| | 410 | | { |
| 0 | 411 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<Application>>(_responseCont |
| 0 | 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 | | } |
| 0 | 423 | | if (_shouldTrace) |
| | 424 | | { |
| 0 | 425 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 426 | | } |
| 0 | 427 | | return _result; |
| 0 | 428 | | } |
| | 429 | |
|
| | 430 | | /// <summary> |
| | 431 | | /// Delete an application. |
| | 432 | | /// </summary> |
| | 433 | | /// <param name='applicationObjectId'> |
| | 434 | | /// Application object ID. |
| | 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="ValidationException"> |
| | 446 | | /// Thrown when a required parameter is null |
| | 447 | | /// </exception> |
| | 448 | | /// <exception cref="System.ArgumentNullException"> |
| | 449 | | /// Thrown when a required parameter is null |
| | 450 | | /// </exception> |
| | 451 | | /// <return> |
| | 452 | | /// A response object containing the response body and response headers. |
| | 453 | | /// </return> |
| | 454 | | public async Task<AzureOperationResponse> DeleteWithHttpMessagesAsync(string applicationObjectId, Dictionary<str |
| | 455 | | { |
| 0 | 456 | | if (applicationObjectId == null) |
| | 457 | | { |
| 0 | 458 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 459 | | } |
| 0 | 460 | | if (Client.ApiVersion == null) |
| | 461 | | { |
| 0 | 462 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 463 | | } |
| 0 | 464 | | if (Client.TenantID == null) |
| | 465 | | { |
| 0 | 466 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 467 | | } |
| | 468 | | // Tracing |
| 0 | 469 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 470 | | string _invocationId = null; |
| 0 | 471 | | if (_shouldTrace) |
| | 472 | | { |
| 0 | 473 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 474 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 475 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 476 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 477 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 478 | | } |
| | 479 | | // Construct URL |
| 0 | 480 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 481 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 482 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 483 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 484 | | List<string> _queryParameters = new List<string>(); |
| 0 | 485 | | if (Client.ApiVersion != null) |
| | 486 | | { |
| 0 | 487 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 488 | | } |
| 0 | 489 | | if (_queryParameters.Count > 0) |
| | 490 | | { |
| 0 | 491 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 492 | | } |
| | 493 | | // Create HTTP transport objects |
| 0 | 494 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 495 | | HttpResponseMessage _httpResponse = null; |
| 0 | 496 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 497 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 498 | | // Set Headers |
| 0 | 499 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 500 | | { |
| 0 | 501 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 502 | | } |
| 0 | 503 | | if (Client.AcceptLanguage != null) |
| | 504 | | { |
| 0 | 505 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 506 | | { |
| 0 | 507 | | _httpRequest.Headers.Remove("accept-language"); |
| | 508 | | } |
| 0 | 509 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 510 | | } |
| | 511 | |
|
| | 512 | |
|
| 0 | 513 | | if (customHeaders != null) |
| | 514 | | { |
| 0 | 515 | | foreach(var _header in customHeaders) |
| | 516 | | { |
| 0 | 517 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 518 | | { |
| 0 | 519 | | _httpRequest.Headers.Remove(_header.Key); |
| | 520 | | } |
| 0 | 521 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 522 | | } |
| | 523 | | } |
| | 524 | |
|
| | 525 | | // Serialize Request |
| 0 | 526 | | string _requestContent = null; |
| | 527 | | // Set Credentials |
| 0 | 528 | | if (Client.Credentials != null) |
| | 529 | | { |
| 0 | 530 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 531 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 532 | | } |
| | 533 | | // Send Request |
| 0 | 534 | | if (_shouldTrace) |
| | 535 | | { |
| 0 | 536 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 537 | | } |
| 0 | 538 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 539 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 540 | | if (_shouldTrace) |
| | 541 | | { |
| 0 | 542 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 543 | | } |
| 0 | 544 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 545 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 546 | | string _responseContent = null; |
| 0 | 547 | | if ((int)_statusCode != 204) |
| | 548 | | { |
| 0 | 549 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 550 | | try |
| | 551 | | { |
| 0 | 552 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 553 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 554 | | if (_errorBody != null) |
| | 555 | | { |
| 0 | 556 | | ex.Body = _errorBody; |
| | 557 | | } |
| 0 | 558 | | } |
| 0 | 559 | | catch (JsonException) |
| | 560 | | { |
| | 561 | | // Ignore the exception |
| 0 | 562 | | } |
| 0 | 563 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 564 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 565 | | if (_shouldTrace) |
| | 566 | | { |
| 0 | 567 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 568 | | } |
| 0 | 569 | | _httpRequest.Dispose(); |
| 0 | 570 | | if (_httpResponse != null) |
| | 571 | | { |
| 0 | 572 | | _httpResponse.Dispose(); |
| | 573 | | } |
| 0 | 574 | | throw ex; |
| | 575 | | } |
| | 576 | | // Create Result |
| 0 | 577 | | var _result = new AzureOperationResponse(); |
| 0 | 578 | | _result.Request = _httpRequest; |
| 0 | 579 | | _result.Response = _httpResponse; |
| 0 | 580 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 581 | | { |
| 0 | 582 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 583 | | } |
| 0 | 584 | | if (_shouldTrace) |
| | 585 | | { |
| 0 | 586 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 587 | | } |
| 0 | 588 | | return _result; |
| 0 | 589 | | } |
| | 590 | |
|
| | 591 | | /// <summary> |
| | 592 | | /// Get an application by object ID. |
| | 593 | | /// </summary> |
| | 594 | | /// <param name='applicationObjectId'> |
| | 595 | | /// Application object ID. |
| | 596 | | /// </param> |
| | 597 | | /// <param name='customHeaders'> |
| | 598 | | /// Headers that will be added to request. |
| | 599 | | /// </param> |
| | 600 | | /// <param name='cancellationToken'> |
| | 601 | | /// The cancellation token. |
| | 602 | | /// </param> |
| | 603 | | /// <exception cref="GraphErrorException"> |
| | 604 | | /// Thrown when the operation returned an invalid status code |
| | 605 | | /// </exception> |
| | 606 | | /// <exception cref="SerializationException"> |
| | 607 | | /// Thrown when unable to deserialize the response |
| | 608 | | /// </exception> |
| | 609 | | /// <exception cref="ValidationException"> |
| | 610 | | /// Thrown when a required parameter is null |
| | 611 | | /// </exception> |
| | 612 | | /// <exception cref="System.ArgumentNullException"> |
| | 613 | | /// Thrown when a required parameter is null |
| | 614 | | /// </exception> |
| | 615 | | /// <return> |
| | 616 | | /// A response object containing the response body and response headers. |
| | 617 | | /// </return> |
| | 618 | | public async Task<AzureOperationResponse<Application>> GetWithHttpMessagesAsync(string applicationObjectId, Dict |
| | 619 | | { |
| 0 | 620 | | if (applicationObjectId == null) |
| | 621 | | { |
| 0 | 622 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 623 | | } |
| 0 | 624 | | if (Client.ApiVersion == null) |
| | 625 | | { |
| 0 | 626 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 627 | | } |
| 0 | 628 | | if (Client.TenantID == null) |
| | 629 | | { |
| 0 | 630 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 631 | | } |
| | 632 | | // Tracing |
| 0 | 633 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 634 | | string _invocationId = null; |
| 0 | 635 | | if (_shouldTrace) |
| | 636 | | { |
| 0 | 637 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 638 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 639 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 640 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 641 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 642 | | } |
| | 643 | | // Construct URL |
| 0 | 644 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 645 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 646 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 647 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 648 | | List<string> _queryParameters = new List<string>(); |
| 0 | 649 | | if (Client.ApiVersion != null) |
| | 650 | | { |
| 0 | 651 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 652 | | } |
| 0 | 653 | | if (_queryParameters.Count > 0) |
| | 654 | | { |
| 0 | 655 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 656 | | } |
| | 657 | | // Create HTTP transport objects |
| 0 | 658 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 659 | | HttpResponseMessage _httpResponse = null; |
| 0 | 660 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 661 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 662 | | // Set Headers |
| 0 | 663 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 664 | | { |
| 0 | 665 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 666 | | } |
| 0 | 667 | | if (Client.AcceptLanguage != null) |
| | 668 | | { |
| 0 | 669 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 670 | | { |
| 0 | 671 | | _httpRequest.Headers.Remove("accept-language"); |
| | 672 | | } |
| 0 | 673 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 674 | | } |
| | 675 | |
|
| | 676 | |
|
| 0 | 677 | | if (customHeaders != null) |
| | 678 | | { |
| 0 | 679 | | foreach(var _header in customHeaders) |
| | 680 | | { |
| 0 | 681 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 682 | | { |
| 0 | 683 | | _httpRequest.Headers.Remove(_header.Key); |
| | 684 | | } |
| 0 | 685 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 686 | | } |
| | 687 | | } |
| | 688 | |
|
| | 689 | | // Serialize Request |
| 0 | 690 | | string _requestContent = null; |
| | 691 | | // Set Credentials |
| 0 | 692 | | if (Client.Credentials != null) |
| | 693 | | { |
| 0 | 694 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 695 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 696 | | } |
| | 697 | | // Send Request |
| 0 | 698 | | if (_shouldTrace) |
| | 699 | | { |
| 0 | 700 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 701 | | } |
| 0 | 702 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 703 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 704 | | if (_shouldTrace) |
| | 705 | | { |
| 0 | 706 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 707 | | } |
| 0 | 708 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 709 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 710 | | string _responseContent = null; |
| 0 | 711 | | if ((int)_statusCode != 200) |
| | 712 | | { |
| 0 | 713 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 714 | | try |
| | 715 | | { |
| 0 | 716 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 717 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 718 | | if (_errorBody != null) |
| | 719 | | { |
| 0 | 720 | | ex.Body = _errorBody; |
| | 721 | | } |
| 0 | 722 | | } |
| 0 | 723 | | catch (JsonException) |
| | 724 | | { |
| | 725 | | // Ignore the exception |
| 0 | 726 | | } |
| 0 | 727 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 728 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 729 | | if (_shouldTrace) |
| | 730 | | { |
| 0 | 731 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 732 | | } |
| 0 | 733 | | _httpRequest.Dispose(); |
| 0 | 734 | | if (_httpResponse != null) |
| | 735 | | { |
| 0 | 736 | | _httpResponse.Dispose(); |
| | 737 | | } |
| 0 | 738 | | throw ex; |
| | 739 | | } |
| | 740 | | // Create Result |
| 0 | 741 | | var _result = new AzureOperationResponse<Application>(); |
| 0 | 742 | | _result.Request = _httpRequest; |
| 0 | 743 | | _result.Response = _httpResponse; |
| 0 | 744 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 745 | | { |
| 0 | 746 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 747 | | } |
| | 748 | | // Deserialize Response |
| 0 | 749 | | if ((int)_statusCode == 200) |
| | 750 | | { |
| 0 | 751 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 752 | | try |
| | 753 | | { |
| 0 | 754 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Application>(_responseContent, C |
| 0 | 755 | | } |
| 0 | 756 | | catch (JsonException ex) |
| | 757 | | { |
| 0 | 758 | | _httpRequest.Dispose(); |
| 0 | 759 | | if (_httpResponse != null) |
| | 760 | | { |
| 0 | 761 | | _httpResponse.Dispose(); |
| | 762 | | } |
| 0 | 763 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 764 | | } |
| | 765 | | } |
| 0 | 766 | | if (_shouldTrace) |
| | 767 | | { |
| 0 | 768 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 769 | | } |
| 0 | 770 | | return _result; |
| 0 | 771 | | } |
| | 772 | |
|
| | 773 | | /// <summary> |
| | 774 | | /// Update an existing application. |
| | 775 | | /// </summary> |
| | 776 | | /// <param name='applicationObjectId'> |
| | 777 | | /// Application object ID. |
| | 778 | | /// </param> |
| | 779 | | /// <param name='parameters'> |
| | 780 | | /// Parameters to update an existing application. |
| | 781 | | /// </param> |
| | 782 | | /// <param name='customHeaders'> |
| | 783 | | /// Headers that will be added to request. |
| | 784 | | /// </param> |
| | 785 | | /// <param name='cancellationToken'> |
| | 786 | | /// The cancellation token. |
| | 787 | | /// </param> |
| | 788 | | /// <exception cref="GraphErrorException"> |
| | 789 | | /// Thrown when the operation returned an invalid status code |
| | 790 | | /// </exception> |
| | 791 | | /// <exception cref="ValidationException"> |
| | 792 | | /// Thrown when a required parameter is null |
| | 793 | | /// </exception> |
| | 794 | | /// <exception cref="System.ArgumentNullException"> |
| | 795 | | /// Thrown when a required parameter is null |
| | 796 | | /// </exception> |
| | 797 | | /// <return> |
| | 798 | | /// A response object containing the response body and response headers. |
| | 799 | | /// </return> |
| | 800 | | public async Task<AzureOperationResponse> PatchWithHttpMessagesAsync(string applicationObjectId, ApplicationUpda |
| | 801 | | { |
| 0 | 802 | | if (applicationObjectId == null) |
| | 803 | | { |
| 0 | 804 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 805 | | } |
| 0 | 806 | | if (parameters == null) |
| | 807 | | { |
| 0 | 808 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 809 | | } |
| 0 | 810 | | if (Client.ApiVersion == null) |
| | 811 | | { |
| 0 | 812 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 813 | | } |
| 0 | 814 | | if (Client.TenantID == null) |
| | 815 | | { |
| 0 | 816 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 817 | | } |
| | 818 | | // Tracing |
| 0 | 819 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 820 | | string _invocationId = null; |
| 0 | 821 | | if (_shouldTrace) |
| | 822 | | { |
| 0 | 823 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 824 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 825 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 826 | | tracingParameters.Add("parameters", parameters); |
| 0 | 827 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 828 | | ServiceClientTracing.Enter(_invocationId, this, "Patch", tracingParameters); |
| | 829 | | } |
| | 830 | | // Construct URL |
| 0 | 831 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 832 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 833 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 834 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 835 | | List<string> _queryParameters = new List<string>(); |
| 0 | 836 | | if (Client.ApiVersion != null) |
| | 837 | | { |
| 0 | 838 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 839 | | } |
| 0 | 840 | | if (_queryParameters.Count > 0) |
| | 841 | | { |
| 0 | 842 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 843 | | } |
| | 844 | | // Create HTTP transport objects |
| 0 | 845 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 846 | | HttpResponseMessage _httpResponse = null; |
| 0 | 847 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 848 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 849 | | // Set Headers |
| 0 | 850 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 851 | | { |
| 0 | 852 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 853 | | } |
| 0 | 854 | | if (Client.AcceptLanguage != null) |
| | 855 | | { |
| 0 | 856 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 857 | | { |
| 0 | 858 | | _httpRequest.Headers.Remove("accept-language"); |
| | 859 | | } |
| 0 | 860 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 861 | | } |
| | 862 | |
|
| | 863 | |
|
| 0 | 864 | | if (customHeaders != null) |
| | 865 | | { |
| 0 | 866 | | foreach(var _header in customHeaders) |
| | 867 | | { |
| 0 | 868 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 869 | | { |
| 0 | 870 | | _httpRequest.Headers.Remove(_header.Key); |
| | 871 | | } |
| 0 | 872 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 873 | | } |
| | 874 | | } |
| | 875 | |
|
| | 876 | | // Serialize Request |
| 0 | 877 | | string _requestContent = null; |
| 0 | 878 | | if(parameters != null) |
| | 879 | | { |
| 0 | 880 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 881 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 882 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 883 | | } |
| | 884 | | // Set Credentials |
| 0 | 885 | | if (Client.Credentials != null) |
| | 886 | | { |
| 0 | 887 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 888 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 889 | | } |
| | 890 | | // Send Request |
| 0 | 891 | | if (_shouldTrace) |
| | 892 | | { |
| 0 | 893 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 894 | | } |
| 0 | 895 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 896 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 897 | | if (_shouldTrace) |
| | 898 | | { |
| 0 | 899 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 900 | | } |
| 0 | 901 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 902 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 903 | | string _responseContent = null; |
| 0 | 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 |
| 0 | 934 | | var _result = new AzureOperationResponse(); |
| 0 | 935 | | _result.Request = _httpRequest; |
| 0 | 936 | | _result.Response = _httpResponse; |
| 0 | 937 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 938 | | { |
| 0 | 939 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 940 | | } |
| 0 | 941 | | if (_shouldTrace) |
| | 942 | | { |
| 0 | 943 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 944 | | } |
| 0 | 945 | | return _result; |
| 0 | 946 | | } |
| | 947 | |
|
| | 948 | | /// <summary> |
| | 949 | | /// Directory objects that are owners of the application. |
| | 950 | | /// </summary> |
| | 951 | | /// <remarks> |
| | 952 | | /// The owners are a set of non-admin users who are allowed to modify this |
| | 953 | | /// object. |
| | 954 | | /// </remarks> |
| | 955 | | /// <param name='applicationObjectId'> |
| | 956 | | /// The object ID of the application for which to get owners. |
| | 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<IPage<DirectoryObject>>> ListOwnersWithHttpMessagesAsync(string applica |
| | 980 | | { |
| 0 | 981 | | if (applicationObjectId == null) |
| | 982 | | { |
| 0 | 983 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 984 | | } |
| 0 | 985 | | if (Client.ApiVersion == null) |
| | 986 | | { |
| 0 | 987 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 988 | | } |
| 0 | 989 | | if (Client.TenantID == null) |
| | 990 | | { |
| 0 | 991 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 992 | | } |
| | 993 | | // Tracing |
| 0 | 994 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 995 | | string _invocationId = null; |
| 0 | 996 | | if (_shouldTrace) |
| | 997 | | { |
| 0 | 998 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 999 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1000 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 1001 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1002 | | ServiceClientTracing.Enter(_invocationId, this, "ListOwners", tracingParameters); |
| | 1003 | | } |
| | 1004 | | // Construct URL |
| 0 | 1005 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1006 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 1007 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 1008 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1009 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1010 | | if (Client.ApiVersion != null) |
| | 1011 | | { |
| 0 | 1012 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1013 | | } |
| 0 | 1014 | | if (_queryParameters.Count > 0) |
| | 1015 | | { |
| 0 | 1016 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1017 | | } |
| | 1018 | | // Create HTTP transport objects |
| 0 | 1019 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1020 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1021 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1022 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1023 | | // Set Headers |
| 0 | 1024 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1025 | | { |
| 0 | 1026 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1027 | | } |
| 0 | 1028 | | if (Client.AcceptLanguage != null) |
| | 1029 | | { |
| 0 | 1030 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1031 | | { |
| 0 | 1032 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1033 | | } |
| 0 | 1034 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1035 | | } |
| | 1036 | |
|
| | 1037 | |
|
| 0 | 1038 | | if (customHeaders != null) |
| | 1039 | | { |
| 0 | 1040 | | foreach(var _header in customHeaders) |
| | 1041 | | { |
| 0 | 1042 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1043 | | { |
| 0 | 1044 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1045 | | } |
| 0 | 1046 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1047 | | } |
| | 1048 | | } |
| | 1049 | |
|
| | 1050 | | // Serialize Request |
| 0 | 1051 | | string _requestContent = null; |
| | 1052 | | // Set Credentials |
| 0 | 1053 | | if (Client.Credentials != null) |
| | 1054 | | { |
| 0 | 1055 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1056 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1057 | | } |
| | 1058 | | // Send Request |
| 0 | 1059 | | if (_shouldTrace) |
| | 1060 | | { |
| 0 | 1061 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1062 | | } |
| 0 | 1063 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1064 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1065 | | if (_shouldTrace) |
| | 1066 | | { |
| 0 | 1067 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1068 | | } |
| 0 | 1069 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1070 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1071 | | string _responseContent = null; |
| 0 | 1072 | | if ((int)_statusCode != 200) |
| | 1073 | | { |
| 0 | 1074 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1075 | | try |
| | 1076 | | { |
| 0 | 1077 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1078 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1079 | | if (_errorBody != null) |
| | 1080 | | { |
| 0 | 1081 | | ex.Body = _errorBody; |
| | 1082 | | } |
| 0 | 1083 | | } |
| 0 | 1084 | | catch (JsonException) |
| | 1085 | | { |
| | 1086 | | // Ignore the exception |
| 0 | 1087 | | } |
| 0 | 1088 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1089 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1090 | | if (_shouldTrace) |
| | 1091 | | { |
| 0 | 1092 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1093 | | } |
| 0 | 1094 | | _httpRequest.Dispose(); |
| 0 | 1095 | | if (_httpResponse != null) |
| | 1096 | | { |
| 0 | 1097 | | _httpResponse.Dispose(); |
| | 1098 | | } |
| 0 | 1099 | | throw ex; |
| | 1100 | | } |
| | 1101 | | // Create Result |
| 0 | 1102 | | var _result = new AzureOperationResponse<IPage<DirectoryObject>>(); |
| 0 | 1103 | | _result.Request = _httpRequest; |
| 0 | 1104 | | _result.Response = _httpResponse; |
| 0 | 1105 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1106 | | { |
| 0 | 1107 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1108 | | } |
| | 1109 | | // Deserialize Response |
| 0 | 1110 | | if ((int)_statusCode == 200) |
| | 1111 | | { |
| 0 | 1112 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1113 | | try |
| | 1114 | | { |
| 0 | 1115 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<DirectoryObject>>(_response |
| 0 | 1116 | | } |
| 0 | 1117 | | catch (JsonException ex) |
| | 1118 | | { |
| 0 | 1119 | | _httpRequest.Dispose(); |
| 0 | 1120 | | if (_httpResponse != null) |
| | 1121 | | { |
| 0 | 1122 | | _httpResponse.Dispose(); |
| | 1123 | | } |
| 0 | 1124 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1125 | | } |
| | 1126 | | } |
| 0 | 1127 | | if (_shouldTrace) |
| | 1128 | | { |
| 0 | 1129 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1130 | | } |
| 0 | 1131 | | return _result; |
| 0 | 1132 | | } |
| | 1133 | |
|
| | 1134 | | /// <summary> |
| | 1135 | | /// Add an owner to an application. |
| | 1136 | | /// </summary> |
| | 1137 | | /// <param name='applicationObjectId'> |
| | 1138 | | /// The object ID of the application to which to add the owner. |
| | 1139 | | /// </param> |
| | 1140 | | /// <param name='parameters'> |
| | 1141 | | /// The URL of the owner object, such as |
| | 1142 | | /// https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b |
| | 1143 | | /// </param> |
| | 1144 | | /// <param name='customHeaders'> |
| | 1145 | | /// Headers that will be added to request. |
| | 1146 | | /// </param> |
| | 1147 | | /// <param name='cancellationToken'> |
| | 1148 | | /// The cancellation token. |
| | 1149 | | /// </param> |
| | 1150 | | /// <exception cref="GraphErrorException"> |
| | 1151 | | /// Thrown when the operation returned an invalid status code |
| | 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> AddOwnerWithHttpMessagesAsync(string applicationObjectId, AddOwnerPara |
| | 1163 | | { |
| 0 | 1164 | | if (applicationObjectId == null) |
| | 1165 | | { |
| 0 | 1166 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 1167 | | } |
| 0 | 1168 | | if (parameters == null) |
| | 1169 | | { |
| 0 | 1170 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 1171 | | } |
| 0 | 1172 | | if (parameters != null) |
| | 1173 | | { |
| 0 | 1174 | | parameters.Validate(); |
| | 1175 | | } |
| 0 | 1176 | | if (Client.ApiVersion == null) |
| | 1177 | | { |
| 0 | 1178 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1179 | | } |
| 0 | 1180 | | if (Client.TenantID == null) |
| | 1181 | | { |
| 0 | 1182 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1183 | | } |
| | 1184 | | // Tracing |
| 0 | 1185 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1186 | | string _invocationId = null; |
| 0 | 1187 | | if (_shouldTrace) |
| | 1188 | | { |
| 0 | 1189 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1190 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1191 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 1192 | | tracingParameters.Add("parameters", parameters); |
| 0 | 1193 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1194 | | ServiceClientTracing.Enter(_invocationId, this, "AddOwner", tracingParameters); |
| | 1195 | | } |
| | 1196 | | // Construct URL |
| 0 | 1197 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1198 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 1199 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 1200 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1201 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1202 | | if (Client.ApiVersion != null) |
| | 1203 | | { |
| 0 | 1204 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1205 | | } |
| 0 | 1206 | | if (_queryParameters.Count > 0) |
| | 1207 | | { |
| 0 | 1208 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1209 | | } |
| | 1210 | | // Create HTTP transport objects |
| 0 | 1211 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1212 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1213 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1214 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1215 | | // Set Headers |
| 0 | 1216 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1217 | | { |
| 0 | 1218 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1219 | | } |
| 0 | 1220 | | if (Client.AcceptLanguage != null) |
| | 1221 | | { |
| 0 | 1222 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1223 | | { |
| 0 | 1224 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1225 | | } |
| 0 | 1226 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1227 | | } |
| | 1228 | |
|
| | 1229 | |
|
| 0 | 1230 | | if (customHeaders != null) |
| | 1231 | | { |
| 0 | 1232 | | foreach(var _header in customHeaders) |
| | 1233 | | { |
| 0 | 1234 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1235 | | { |
| 0 | 1236 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1237 | | } |
| 0 | 1238 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1239 | | } |
| | 1240 | | } |
| | 1241 | |
|
| | 1242 | | // Serialize Request |
| 0 | 1243 | | string _requestContent = null; |
| 0 | 1244 | | if(parameters != null) |
| | 1245 | | { |
| 0 | 1246 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 1247 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1248 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1249 | | } |
| | 1250 | | // Set Credentials |
| 0 | 1251 | | if (Client.Credentials != null) |
| | 1252 | | { |
| 0 | 1253 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1254 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1255 | | } |
| | 1256 | | // Send Request |
| 0 | 1257 | | if (_shouldTrace) |
| | 1258 | | { |
| 0 | 1259 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1260 | | } |
| 0 | 1261 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1262 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1263 | | if (_shouldTrace) |
| | 1264 | | { |
| 0 | 1265 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1266 | | } |
| 0 | 1267 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1268 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1269 | | string _responseContent = null; |
| 0 | 1270 | | if ((int)_statusCode != 204) |
| | 1271 | | { |
| 0 | 1272 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1273 | | try |
| | 1274 | | { |
| 0 | 1275 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1276 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1277 | | if (_errorBody != null) |
| | 1278 | | { |
| 0 | 1279 | | ex.Body = _errorBody; |
| | 1280 | | } |
| 0 | 1281 | | } |
| 0 | 1282 | | catch (JsonException) |
| | 1283 | | { |
| | 1284 | | // Ignore the exception |
| 0 | 1285 | | } |
| 0 | 1286 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1287 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1288 | | if (_shouldTrace) |
| | 1289 | | { |
| 0 | 1290 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1291 | | } |
| 0 | 1292 | | _httpRequest.Dispose(); |
| 0 | 1293 | | if (_httpResponse != null) |
| | 1294 | | { |
| 0 | 1295 | | _httpResponse.Dispose(); |
| | 1296 | | } |
| 0 | 1297 | | throw ex; |
| | 1298 | | } |
| | 1299 | | // Create Result |
| 0 | 1300 | | var _result = new AzureOperationResponse(); |
| 0 | 1301 | | _result.Request = _httpRequest; |
| 0 | 1302 | | _result.Response = _httpResponse; |
| 0 | 1303 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1304 | | { |
| 0 | 1305 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1306 | | } |
| 0 | 1307 | | if (_shouldTrace) |
| | 1308 | | { |
| 0 | 1309 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1310 | | } |
| 0 | 1311 | | return _result; |
| 0 | 1312 | | } |
| | 1313 | |
|
| | 1314 | | /// <summary> |
| | 1315 | | /// Remove a member from owners. |
| | 1316 | | /// </summary> |
| | 1317 | | /// <param name='applicationObjectId'> |
| | 1318 | | /// The object ID of the application from which to remove the owner. |
| | 1319 | | /// </param> |
| | 1320 | | /// <param name='ownerObjectId'> |
| | 1321 | | /// Owner object id |
| | 1322 | | /// </param> |
| | 1323 | | /// <param name='customHeaders'> |
| | 1324 | | /// Headers that will be added to request. |
| | 1325 | | /// </param> |
| | 1326 | | /// <param name='cancellationToken'> |
| | 1327 | | /// The cancellation token. |
| | 1328 | | /// </param> |
| | 1329 | | /// <exception cref="GraphErrorException"> |
| | 1330 | | /// Thrown when the operation returned an invalid status code |
| | 1331 | | /// </exception> |
| | 1332 | | /// <exception cref="ValidationException"> |
| | 1333 | | /// Thrown when a required parameter is null |
| | 1334 | | /// </exception> |
| | 1335 | | /// <exception cref="System.ArgumentNullException"> |
| | 1336 | | /// Thrown when a required parameter is null |
| | 1337 | | /// </exception> |
| | 1338 | | /// <return> |
| | 1339 | | /// A response object containing the response body and response headers. |
| | 1340 | | /// </return> |
| | 1341 | | public async Task<AzureOperationResponse> RemoveOwnerWithHttpMessagesAsync(string applicationObjectId, string ow |
| | 1342 | | { |
| 0 | 1343 | | if (applicationObjectId == null) |
| | 1344 | | { |
| 0 | 1345 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 1346 | | } |
| 0 | 1347 | | if (ownerObjectId == null) |
| | 1348 | | { |
| 0 | 1349 | | throw new ValidationException(ValidationRules.CannotBeNull, "ownerObjectId"); |
| | 1350 | | } |
| 0 | 1351 | | if (Client.ApiVersion == null) |
| | 1352 | | { |
| 0 | 1353 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1354 | | } |
| 0 | 1355 | | if (Client.TenantID == null) |
| | 1356 | | { |
| 0 | 1357 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1358 | | } |
| | 1359 | | // Tracing |
| 0 | 1360 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1361 | | string _invocationId = null; |
| 0 | 1362 | | if (_shouldTrace) |
| | 1363 | | { |
| 0 | 1364 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1365 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1366 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 1367 | | tracingParameters.Add("ownerObjectId", ownerObjectId); |
| 0 | 1368 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1369 | | ServiceClientTracing.Enter(_invocationId, this, "RemoveOwner", tracingParameters); |
| | 1370 | | } |
| | 1371 | | // Construct URL |
| 0 | 1372 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1373 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 1374 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 1375 | | _url = _url.Replace("{ownerObjectId}", System.Uri.EscapeDataString(ownerObjectId)); |
| 0 | 1376 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1377 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1378 | | if (Client.ApiVersion != null) |
| | 1379 | | { |
| 0 | 1380 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1381 | | } |
| 0 | 1382 | | if (_queryParameters.Count > 0) |
| | 1383 | | { |
| 0 | 1384 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1385 | | } |
| | 1386 | | // Create HTTP transport objects |
| 0 | 1387 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1388 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1389 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 1390 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1391 | | // Set Headers |
| 0 | 1392 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1393 | | { |
| 0 | 1394 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1395 | | } |
| 0 | 1396 | | if (Client.AcceptLanguage != null) |
| | 1397 | | { |
| 0 | 1398 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1399 | | { |
| 0 | 1400 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1401 | | } |
| 0 | 1402 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1403 | | } |
| | 1404 | |
|
| | 1405 | |
|
| 0 | 1406 | | if (customHeaders != null) |
| | 1407 | | { |
| 0 | 1408 | | foreach(var _header in customHeaders) |
| | 1409 | | { |
| 0 | 1410 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1411 | | { |
| 0 | 1412 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1413 | | } |
| 0 | 1414 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1415 | | } |
| | 1416 | | } |
| | 1417 | |
|
| | 1418 | | // Serialize Request |
| 0 | 1419 | | string _requestContent = null; |
| | 1420 | | // Set Credentials |
| 0 | 1421 | | if (Client.Credentials != null) |
| | 1422 | | { |
| 0 | 1423 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1424 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1425 | | } |
| | 1426 | | // Send Request |
| 0 | 1427 | | if (_shouldTrace) |
| | 1428 | | { |
| 0 | 1429 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1430 | | } |
| 0 | 1431 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1432 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1433 | | if (_shouldTrace) |
| | 1434 | | { |
| 0 | 1435 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1436 | | } |
| 0 | 1437 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1438 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1439 | | string _responseContent = null; |
| 0 | 1440 | | if ((int)_statusCode != 204) |
| | 1441 | | { |
| 0 | 1442 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1443 | | try |
| | 1444 | | { |
| 0 | 1445 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1446 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1447 | | if (_errorBody != null) |
| | 1448 | | { |
| 0 | 1449 | | ex.Body = _errorBody; |
| | 1450 | | } |
| 0 | 1451 | | } |
| 0 | 1452 | | catch (JsonException) |
| | 1453 | | { |
| | 1454 | | // Ignore the exception |
| 0 | 1455 | | } |
| 0 | 1456 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1457 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1458 | | if (_shouldTrace) |
| | 1459 | | { |
| 0 | 1460 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1461 | | } |
| 0 | 1462 | | _httpRequest.Dispose(); |
| 0 | 1463 | | if (_httpResponse != null) |
| | 1464 | | { |
| 0 | 1465 | | _httpResponse.Dispose(); |
| | 1466 | | } |
| 0 | 1467 | | throw ex; |
| | 1468 | | } |
| | 1469 | | // Create Result |
| 0 | 1470 | | var _result = new AzureOperationResponse(); |
| 0 | 1471 | | _result.Request = _httpRequest; |
| 0 | 1472 | | _result.Response = _httpResponse; |
| 0 | 1473 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1474 | | { |
| 0 | 1475 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1476 | | } |
| 0 | 1477 | | if (_shouldTrace) |
| | 1478 | | { |
| 0 | 1479 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1480 | | } |
| 0 | 1481 | | return _result; |
| 0 | 1482 | | } |
| | 1483 | |
|
| | 1484 | | /// <summary> |
| | 1485 | | /// Get the keyCredentials associated with an application. |
| | 1486 | | /// </summary> |
| | 1487 | | /// <param name='applicationObjectId'> |
| | 1488 | | /// Application object ID. |
| | 1489 | | /// </param> |
| | 1490 | | /// <param name='customHeaders'> |
| | 1491 | | /// Headers that will be added to request. |
| | 1492 | | /// </param> |
| | 1493 | | /// <param name='cancellationToken'> |
| | 1494 | | /// The cancellation token. |
| | 1495 | | /// </param> |
| | 1496 | | /// <exception cref="GraphErrorException"> |
| | 1497 | | /// Thrown when the operation returned an invalid status code |
| | 1498 | | /// </exception> |
| | 1499 | | /// <exception cref="SerializationException"> |
| | 1500 | | /// Thrown when unable to deserialize the response |
| | 1501 | | /// </exception> |
| | 1502 | | /// <exception cref="ValidationException"> |
| | 1503 | | /// Thrown when a required parameter is null |
| | 1504 | | /// </exception> |
| | 1505 | | /// <exception cref="System.ArgumentNullException"> |
| | 1506 | | /// Thrown when a required parameter is null |
| | 1507 | | /// </exception> |
| | 1508 | | /// <return> |
| | 1509 | | /// A response object containing the response body and response headers. |
| | 1510 | | /// </return> |
| | 1511 | | public async Task<AzureOperationResponse<IEnumerable<KeyCredential>>> ListKeyCredentialsWithHttpMessagesAsync(st |
| | 1512 | | { |
| 0 | 1513 | | if (applicationObjectId == null) |
| | 1514 | | { |
| 0 | 1515 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 1516 | | } |
| 0 | 1517 | | if (Client.ApiVersion == null) |
| | 1518 | | { |
| 0 | 1519 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1520 | | } |
| 0 | 1521 | | if (Client.TenantID == null) |
| | 1522 | | { |
| 0 | 1523 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1524 | | } |
| | 1525 | | // Tracing |
| 0 | 1526 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1527 | | string _invocationId = null; |
| 0 | 1528 | | if (_shouldTrace) |
| | 1529 | | { |
| 0 | 1530 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1531 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1532 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 1533 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1534 | | ServiceClientTracing.Enter(_invocationId, this, "ListKeyCredentials", tracingParameters); |
| | 1535 | | } |
| | 1536 | | // Construct URL |
| 0 | 1537 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1538 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 1539 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 1540 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1541 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1542 | | if (Client.ApiVersion != null) |
| | 1543 | | { |
| 0 | 1544 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1545 | | } |
| 0 | 1546 | | if (_queryParameters.Count > 0) |
| | 1547 | | { |
| 0 | 1548 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1549 | | } |
| | 1550 | | // Create HTTP transport objects |
| 0 | 1551 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1552 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1553 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1554 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1555 | | // Set Headers |
| 0 | 1556 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1557 | | { |
| 0 | 1558 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1559 | | } |
| 0 | 1560 | | if (Client.AcceptLanguage != null) |
| | 1561 | | { |
| 0 | 1562 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1563 | | { |
| 0 | 1564 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1565 | | } |
| 0 | 1566 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1567 | | } |
| | 1568 | |
|
| | 1569 | |
|
| 0 | 1570 | | if (customHeaders != null) |
| | 1571 | | { |
| 0 | 1572 | | foreach(var _header in customHeaders) |
| | 1573 | | { |
| 0 | 1574 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1575 | | { |
| 0 | 1576 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1577 | | } |
| 0 | 1578 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1579 | | } |
| | 1580 | | } |
| | 1581 | |
|
| | 1582 | | // Serialize Request |
| 0 | 1583 | | string _requestContent = null; |
| | 1584 | | // Set Credentials |
| 0 | 1585 | | if (Client.Credentials != null) |
| | 1586 | | { |
| 0 | 1587 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1588 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1589 | | } |
| | 1590 | | // Send Request |
| 0 | 1591 | | if (_shouldTrace) |
| | 1592 | | { |
| 0 | 1593 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1594 | | } |
| 0 | 1595 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1596 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1597 | | if (_shouldTrace) |
| | 1598 | | { |
| 0 | 1599 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1600 | | } |
| 0 | 1601 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1602 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1603 | | string _responseContent = null; |
| 0 | 1604 | | if ((int)_statusCode != 200) |
| | 1605 | | { |
| 0 | 1606 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1607 | | try |
| | 1608 | | { |
| 0 | 1609 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1610 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1611 | | if (_errorBody != null) |
| | 1612 | | { |
| 0 | 1613 | | ex.Body = _errorBody; |
| | 1614 | | } |
| 0 | 1615 | | } |
| 0 | 1616 | | catch (JsonException) |
| | 1617 | | { |
| | 1618 | | // Ignore the exception |
| 0 | 1619 | | } |
| 0 | 1620 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1621 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1622 | | if (_shouldTrace) |
| | 1623 | | { |
| 0 | 1624 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1625 | | } |
| 0 | 1626 | | _httpRequest.Dispose(); |
| 0 | 1627 | | if (_httpResponse != null) |
| | 1628 | | { |
| 0 | 1629 | | _httpResponse.Dispose(); |
| | 1630 | | } |
| 0 | 1631 | | throw ex; |
| | 1632 | | } |
| | 1633 | | // Create Result |
| 0 | 1634 | | var _result = new AzureOperationResponse<IEnumerable<KeyCredential>>(); |
| 0 | 1635 | | _result.Request = _httpRequest; |
| 0 | 1636 | | _result.Response = _httpResponse; |
| 0 | 1637 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1638 | | { |
| 0 | 1639 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1640 | | } |
| | 1641 | | // Deserialize Response |
| 0 | 1642 | | if ((int)_statusCode == 200) |
| | 1643 | | { |
| 0 | 1644 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1645 | | try |
| | 1646 | | { |
| 0 | 1647 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<KeyCredential>>(_responseC |
| 0 | 1648 | | } |
| 0 | 1649 | | catch (JsonException ex) |
| | 1650 | | { |
| 0 | 1651 | | _httpRequest.Dispose(); |
| 0 | 1652 | | if (_httpResponse != null) |
| | 1653 | | { |
| 0 | 1654 | | _httpResponse.Dispose(); |
| | 1655 | | } |
| 0 | 1656 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1657 | | } |
| | 1658 | | } |
| 0 | 1659 | | if (_shouldTrace) |
| | 1660 | | { |
| 0 | 1661 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1662 | | } |
| 0 | 1663 | | return _result; |
| 0 | 1664 | | } |
| | 1665 | |
|
| | 1666 | | /// <summary> |
| | 1667 | | /// Update the keyCredentials associated with an application. |
| | 1668 | | /// </summary> |
| | 1669 | | /// <param name='applicationObjectId'> |
| | 1670 | | /// Application object ID. |
| | 1671 | | /// </param> |
| | 1672 | | /// <param name='parameters'> |
| | 1673 | | /// Parameters to update the keyCredentials of an existing application. |
| | 1674 | | /// </param> |
| | 1675 | | /// <param name='customHeaders'> |
| | 1676 | | /// Headers that will be added to request. |
| | 1677 | | /// </param> |
| | 1678 | | /// <param name='cancellationToken'> |
| | 1679 | | /// The cancellation token. |
| | 1680 | | /// </param> |
| | 1681 | | /// <exception cref="GraphErrorException"> |
| | 1682 | | /// Thrown when the operation returned an invalid status code |
| | 1683 | | /// </exception> |
| | 1684 | | /// <exception cref="ValidationException"> |
| | 1685 | | /// Thrown when a required parameter is null |
| | 1686 | | /// </exception> |
| | 1687 | | /// <exception cref="System.ArgumentNullException"> |
| | 1688 | | /// Thrown when a required parameter is null |
| | 1689 | | /// </exception> |
| | 1690 | | /// <return> |
| | 1691 | | /// A response object containing the response body and response headers. |
| | 1692 | | /// </return> |
| | 1693 | | public async Task<AzureOperationResponse> UpdateKeyCredentialsWithHttpMessagesAsync(string applicationObjectId, |
| | 1694 | | { |
| 0 | 1695 | | if (applicationObjectId == null) |
| | 1696 | | { |
| 0 | 1697 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 1698 | | } |
| 0 | 1699 | | if (parameters == null) |
| | 1700 | | { |
| 0 | 1701 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 1702 | | } |
| 0 | 1703 | | if (Client.ApiVersion == null) |
| | 1704 | | { |
| 0 | 1705 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1706 | | } |
| 0 | 1707 | | if (Client.TenantID == null) |
| | 1708 | | { |
| 0 | 1709 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1710 | | } |
| | 1711 | | // Tracing |
| 0 | 1712 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1713 | | string _invocationId = null; |
| 0 | 1714 | | if (_shouldTrace) |
| | 1715 | | { |
| 0 | 1716 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1717 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1718 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 1719 | | tracingParameters.Add("parameters", parameters); |
| 0 | 1720 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1721 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateKeyCredentials", tracingParameters); |
| | 1722 | | } |
| | 1723 | | // Construct URL |
| 0 | 1724 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1725 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 1726 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 1727 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1728 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1729 | | if (Client.ApiVersion != null) |
| | 1730 | | { |
| 0 | 1731 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1732 | | } |
| 0 | 1733 | | if (_queryParameters.Count > 0) |
| | 1734 | | { |
| 0 | 1735 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1736 | | } |
| | 1737 | | // Create HTTP transport objects |
| 0 | 1738 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1739 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1740 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 1741 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1742 | | // Set Headers |
| 0 | 1743 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1744 | | { |
| 0 | 1745 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1746 | | } |
| 0 | 1747 | | if (Client.AcceptLanguage != null) |
| | 1748 | | { |
| 0 | 1749 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1750 | | { |
| 0 | 1751 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1752 | | } |
| 0 | 1753 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1754 | | } |
| | 1755 | |
|
| | 1756 | |
|
| 0 | 1757 | | if (customHeaders != null) |
| | 1758 | | { |
| 0 | 1759 | | foreach(var _header in customHeaders) |
| | 1760 | | { |
| 0 | 1761 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1762 | | { |
| 0 | 1763 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1764 | | } |
| 0 | 1765 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1766 | | } |
| | 1767 | | } |
| | 1768 | |
|
| | 1769 | | // Serialize Request |
| 0 | 1770 | | string _requestContent = null; |
| 0 | 1771 | | if(parameters != null) |
| | 1772 | | { |
| 0 | 1773 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 1774 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1775 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1776 | | } |
| | 1777 | | // Set Credentials |
| 0 | 1778 | | if (Client.Credentials != null) |
| | 1779 | | { |
| 0 | 1780 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1781 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1782 | | } |
| | 1783 | | // Send Request |
| 0 | 1784 | | if (_shouldTrace) |
| | 1785 | | { |
| 0 | 1786 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1787 | | } |
| 0 | 1788 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1789 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1790 | | if (_shouldTrace) |
| | 1791 | | { |
| 0 | 1792 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1793 | | } |
| 0 | 1794 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1795 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1796 | | string _responseContent = null; |
| 0 | 1797 | | if ((int)_statusCode != 204) |
| | 1798 | | { |
| 0 | 1799 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1800 | | try |
| | 1801 | | { |
| 0 | 1802 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1803 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1804 | | if (_errorBody != null) |
| | 1805 | | { |
| 0 | 1806 | | ex.Body = _errorBody; |
| | 1807 | | } |
| 0 | 1808 | | } |
| 0 | 1809 | | catch (JsonException) |
| | 1810 | | { |
| | 1811 | | // Ignore the exception |
| 0 | 1812 | | } |
| 0 | 1813 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1814 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1815 | | if (_shouldTrace) |
| | 1816 | | { |
| 0 | 1817 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1818 | | } |
| 0 | 1819 | | _httpRequest.Dispose(); |
| 0 | 1820 | | if (_httpResponse != null) |
| | 1821 | | { |
| 0 | 1822 | | _httpResponse.Dispose(); |
| | 1823 | | } |
| 0 | 1824 | | throw ex; |
| | 1825 | | } |
| | 1826 | | // Create Result |
| 0 | 1827 | | var _result = new AzureOperationResponse(); |
| 0 | 1828 | | _result.Request = _httpRequest; |
| 0 | 1829 | | _result.Response = _httpResponse; |
| 0 | 1830 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1831 | | { |
| 0 | 1832 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1833 | | } |
| 0 | 1834 | | if (_shouldTrace) |
| | 1835 | | { |
| 0 | 1836 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1837 | | } |
| 0 | 1838 | | return _result; |
| 0 | 1839 | | } |
| | 1840 | |
|
| | 1841 | | /// <summary> |
| | 1842 | | /// Get the passwordCredentials associated with an application. |
| | 1843 | | /// </summary> |
| | 1844 | | /// <param name='applicationObjectId'> |
| | 1845 | | /// Application object ID. |
| | 1846 | | /// </param> |
| | 1847 | | /// <param name='customHeaders'> |
| | 1848 | | /// Headers that will be added to request. |
| | 1849 | | /// </param> |
| | 1850 | | /// <param name='cancellationToken'> |
| | 1851 | | /// The cancellation token. |
| | 1852 | | /// </param> |
| | 1853 | | /// <exception cref="GraphErrorException"> |
| | 1854 | | /// Thrown when the operation returned an invalid status code |
| | 1855 | | /// </exception> |
| | 1856 | | /// <exception cref="SerializationException"> |
| | 1857 | | /// Thrown when unable to deserialize the response |
| | 1858 | | /// </exception> |
| | 1859 | | /// <exception cref="ValidationException"> |
| | 1860 | | /// Thrown when a required parameter is null |
| | 1861 | | /// </exception> |
| | 1862 | | /// <exception cref="System.ArgumentNullException"> |
| | 1863 | | /// Thrown when a required parameter is null |
| | 1864 | | /// </exception> |
| | 1865 | | /// <return> |
| | 1866 | | /// A response object containing the response body and response headers. |
| | 1867 | | /// </return> |
| | 1868 | | public async Task<AzureOperationResponse<IEnumerable<PasswordCredential>>> ListPasswordCredentialsWithHttpMessag |
| | 1869 | | { |
| 0 | 1870 | | if (applicationObjectId == null) |
| | 1871 | | { |
| 0 | 1872 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 1873 | | } |
| 0 | 1874 | | if (Client.ApiVersion == null) |
| | 1875 | | { |
| 0 | 1876 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 1877 | | } |
| 0 | 1878 | | if (Client.TenantID == null) |
| | 1879 | | { |
| 0 | 1880 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 1881 | | } |
| | 1882 | | // Tracing |
| 0 | 1883 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1884 | | string _invocationId = null; |
| 0 | 1885 | | if (_shouldTrace) |
| | 1886 | | { |
| 0 | 1887 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1888 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1889 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 1890 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1891 | | ServiceClientTracing.Enter(_invocationId, this, "ListPasswordCredentials", tracingParameters); |
| | 1892 | | } |
| | 1893 | | // Construct URL |
| 0 | 1894 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 1895 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 1896 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 1897 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 1898 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1899 | | if (Client.ApiVersion != null) |
| | 1900 | | { |
| 0 | 1901 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 1902 | | } |
| 0 | 1903 | | if (_queryParameters.Count > 0) |
| | 1904 | | { |
| 0 | 1905 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 1906 | | } |
| | 1907 | | // Create HTTP transport objects |
| 0 | 1908 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1909 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1910 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1911 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1912 | | // Set Headers |
| 0 | 1913 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 1914 | | { |
| 0 | 1915 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 1916 | | } |
| 0 | 1917 | | if (Client.AcceptLanguage != null) |
| | 1918 | | { |
| 0 | 1919 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 1920 | | { |
| 0 | 1921 | | _httpRequest.Headers.Remove("accept-language"); |
| | 1922 | | } |
| 0 | 1923 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 1924 | | } |
| | 1925 | |
|
| | 1926 | |
|
| 0 | 1927 | | if (customHeaders != null) |
| | 1928 | | { |
| 0 | 1929 | | foreach(var _header in customHeaders) |
| | 1930 | | { |
| 0 | 1931 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1932 | | { |
| 0 | 1933 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1934 | | } |
| 0 | 1935 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1936 | | } |
| | 1937 | | } |
| | 1938 | |
|
| | 1939 | | // Serialize Request |
| 0 | 1940 | | string _requestContent = null; |
| | 1941 | | // Set Credentials |
| 0 | 1942 | | if (Client.Credentials != null) |
| | 1943 | | { |
| 0 | 1944 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1945 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1946 | | } |
| | 1947 | | // Send Request |
| 0 | 1948 | | if (_shouldTrace) |
| | 1949 | | { |
| 0 | 1950 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1951 | | } |
| 0 | 1952 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1953 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1954 | | if (_shouldTrace) |
| | 1955 | | { |
| 0 | 1956 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1957 | | } |
| 0 | 1958 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1959 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1960 | | string _responseContent = null; |
| 0 | 1961 | | if ((int)_statusCode != 200) |
| | 1962 | | { |
| 0 | 1963 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 1964 | | try |
| | 1965 | | { |
| 0 | 1966 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1967 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 1968 | | if (_errorBody != null) |
| | 1969 | | { |
| 0 | 1970 | | ex.Body = _errorBody; |
| | 1971 | | } |
| 0 | 1972 | | } |
| 0 | 1973 | | catch (JsonException) |
| | 1974 | | { |
| | 1975 | | // Ignore the exception |
| 0 | 1976 | | } |
| 0 | 1977 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1978 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1979 | | if (_shouldTrace) |
| | 1980 | | { |
| 0 | 1981 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1982 | | } |
| 0 | 1983 | | _httpRequest.Dispose(); |
| 0 | 1984 | | if (_httpResponse != null) |
| | 1985 | | { |
| 0 | 1986 | | _httpResponse.Dispose(); |
| | 1987 | | } |
| 0 | 1988 | | throw ex; |
| | 1989 | | } |
| | 1990 | | // Create Result |
| 0 | 1991 | | var _result = new AzureOperationResponse<IEnumerable<PasswordCredential>>(); |
| 0 | 1992 | | _result.Request = _httpRequest; |
| 0 | 1993 | | _result.Response = _httpResponse; |
| 0 | 1994 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 1995 | | { |
| 0 | 1996 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 1997 | | } |
| | 1998 | | // Deserialize Response |
| 0 | 1999 | | if ((int)_statusCode == 200) |
| | 2000 | | { |
| 0 | 2001 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2002 | | try |
| | 2003 | | { |
| 0 | 2004 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page1<PasswordCredential>>(_resp |
| 0 | 2005 | | } |
| 0 | 2006 | | catch (JsonException ex) |
| | 2007 | | { |
| 0 | 2008 | | _httpRequest.Dispose(); |
| 0 | 2009 | | if (_httpResponse != null) |
| | 2010 | | { |
| 0 | 2011 | | _httpResponse.Dispose(); |
| | 2012 | | } |
| 0 | 2013 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2014 | | } |
| | 2015 | | } |
| 0 | 2016 | | if (_shouldTrace) |
| | 2017 | | { |
| 0 | 2018 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2019 | | } |
| 0 | 2020 | | return _result; |
| 0 | 2021 | | } |
| | 2022 | |
|
| | 2023 | | /// <summary> |
| | 2024 | | /// Update passwordCredentials associated with an application. |
| | 2025 | | /// </summary> |
| | 2026 | | /// <param name='applicationObjectId'> |
| | 2027 | | /// Application object ID. |
| | 2028 | | /// </param> |
| | 2029 | | /// <param name='parameters'> |
| | 2030 | | /// Parameters to update passwordCredentials of an existing application. |
| | 2031 | | /// </param> |
| | 2032 | | /// <param name='customHeaders'> |
| | 2033 | | /// Headers that will be added to request. |
| | 2034 | | /// </param> |
| | 2035 | | /// <param name='cancellationToken'> |
| | 2036 | | /// The cancellation token. |
| | 2037 | | /// </param> |
| | 2038 | | /// <exception cref="GraphErrorException"> |
| | 2039 | | /// Thrown when the operation returned an invalid status code |
| | 2040 | | /// </exception> |
| | 2041 | | /// <exception cref="ValidationException"> |
| | 2042 | | /// Thrown when a required parameter is null |
| | 2043 | | /// </exception> |
| | 2044 | | /// <exception cref="System.ArgumentNullException"> |
| | 2045 | | /// Thrown when a required parameter is null |
| | 2046 | | /// </exception> |
| | 2047 | | /// <return> |
| | 2048 | | /// A response object containing the response body and response headers. |
| | 2049 | | /// </return> |
| | 2050 | | public async Task<AzureOperationResponse> UpdatePasswordCredentialsWithHttpMessagesAsync(string applicationObjec |
| | 2051 | | { |
| 0 | 2052 | | if (applicationObjectId == null) |
| | 2053 | | { |
| 0 | 2054 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationObjectId"); |
| | 2055 | | } |
| 0 | 2056 | | if (parameters == null) |
| | 2057 | | { |
| 0 | 2058 | | throw new ValidationException(ValidationRules.CannotBeNull, "parameters"); |
| | 2059 | | } |
| 0 | 2060 | | if (Client.ApiVersion == null) |
| | 2061 | | { |
| 0 | 2062 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2063 | | } |
| 0 | 2064 | | if (Client.TenantID == null) |
| | 2065 | | { |
| 0 | 2066 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 2067 | | } |
| | 2068 | | // Tracing |
| 0 | 2069 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2070 | | string _invocationId = null; |
| 0 | 2071 | | if (_shouldTrace) |
| | 2072 | | { |
| 0 | 2073 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2074 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2075 | | tracingParameters.Add("applicationObjectId", applicationObjectId); |
| 0 | 2076 | | tracingParameters.Add("parameters", parameters); |
| 0 | 2077 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2078 | | ServiceClientTracing.Enter(_invocationId, this, "UpdatePasswordCredentials", tracingParameters); |
| | 2079 | | } |
| | 2080 | | // Construct URL |
| 0 | 2081 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 2082 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/applic |
| 0 | 2083 | | _url = _url.Replace("{applicationObjectId}", System.Uri.EscapeDataString(applicationObjectId)); |
| 0 | 2084 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 2085 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2086 | | if (Client.ApiVersion != null) |
| | 2087 | | { |
| 0 | 2088 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2089 | | } |
| 0 | 2090 | | if (_queryParameters.Count > 0) |
| | 2091 | | { |
| 0 | 2092 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2093 | | } |
| | 2094 | | // Create HTTP transport objects |
| 0 | 2095 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2096 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2097 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 2098 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2099 | | // Set Headers |
| 0 | 2100 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2101 | | { |
| 0 | 2102 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2103 | | } |
| 0 | 2104 | | if (Client.AcceptLanguage != null) |
| | 2105 | | { |
| 0 | 2106 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2107 | | { |
| 0 | 2108 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2109 | | } |
| 0 | 2110 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2111 | | } |
| | 2112 | |
|
| | 2113 | |
|
| 0 | 2114 | | if (customHeaders != null) |
| | 2115 | | { |
| 0 | 2116 | | foreach(var _header in customHeaders) |
| | 2117 | | { |
| 0 | 2118 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2119 | | { |
| 0 | 2120 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2121 | | } |
| 0 | 2122 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2123 | | } |
| | 2124 | | } |
| | 2125 | |
|
| | 2126 | | // Serialize Request |
| 0 | 2127 | | string _requestContent = null; |
| 0 | 2128 | | if(parameters != null) |
| | 2129 | | { |
| 0 | 2130 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSet |
| 0 | 2131 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 2132 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2133 | | } |
| | 2134 | | // Set Credentials |
| 0 | 2135 | | if (Client.Credentials != null) |
| | 2136 | | { |
| 0 | 2137 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2138 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2139 | | } |
| | 2140 | | // Send Request |
| 0 | 2141 | | if (_shouldTrace) |
| | 2142 | | { |
| 0 | 2143 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2144 | | } |
| 0 | 2145 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2146 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2147 | | if (_shouldTrace) |
| | 2148 | | { |
| 0 | 2149 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2150 | | } |
| 0 | 2151 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2152 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2153 | | string _responseContent = null; |
| 0 | 2154 | | if ((int)_statusCode != 204) |
| | 2155 | | { |
| 0 | 2156 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2157 | | try |
| | 2158 | | { |
| 0 | 2159 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2160 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 2161 | | if (_errorBody != null) |
| | 2162 | | { |
| 0 | 2163 | | ex.Body = _errorBody; |
| | 2164 | | } |
| 0 | 2165 | | } |
| 0 | 2166 | | catch (JsonException) |
| | 2167 | | { |
| | 2168 | | // Ignore the exception |
| 0 | 2169 | | } |
| 0 | 2170 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2171 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2172 | | if (_shouldTrace) |
| | 2173 | | { |
| 0 | 2174 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2175 | | } |
| 0 | 2176 | | _httpRequest.Dispose(); |
| 0 | 2177 | | if (_httpResponse != null) |
| | 2178 | | { |
| 0 | 2179 | | _httpResponse.Dispose(); |
| | 2180 | | } |
| 0 | 2181 | | throw ex; |
| | 2182 | | } |
| | 2183 | | // Create Result |
| 0 | 2184 | | var _result = new AzureOperationResponse(); |
| 0 | 2185 | | _result.Request = _httpRequest; |
| 0 | 2186 | | _result.Response = _httpResponse; |
| 0 | 2187 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2188 | | { |
| 0 | 2189 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2190 | | } |
| 0 | 2191 | | if (_shouldTrace) |
| | 2192 | | { |
| 0 | 2193 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2194 | | } |
| 0 | 2195 | | return _result; |
| 0 | 2196 | | } |
| | 2197 | |
|
| | 2198 | | /// <summary> |
| | 2199 | | /// Gets an object id for a given application id from the current tenant. |
| | 2200 | | /// </summary> |
| | 2201 | | /// <param name='applicationID'> |
| | 2202 | | /// The application ID. |
| | 2203 | | /// </param> |
| | 2204 | | /// <param name='customHeaders'> |
| | 2205 | | /// Headers that will be added to request. |
| | 2206 | | /// </param> |
| | 2207 | | /// <param name='cancellationToken'> |
| | 2208 | | /// The cancellation token. |
| | 2209 | | /// </param> |
| | 2210 | | /// <exception cref="GraphErrorException"> |
| | 2211 | | /// Thrown when the operation returned an invalid status code |
| | 2212 | | /// </exception> |
| | 2213 | | /// <exception cref="SerializationException"> |
| | 2214 | | /// Thrown when unable to deserialize the response |
| | 2215 | | /// </exception> |
| | 2216 | | /// <exception cref="ValidationException"> |
| | 2217 | | /// Thrown when a required parameter is null |
| | 2218 | | /// </exception> |
| | 2219 | | /// <exception cref="System.ArgumentNullException"> |
| | 2220 | | /// Thrown when a required parameter is null |
| | 2221 | | /// </exception> |
| | 2222 | | /// <return> |
| | 2223 | | /// A response object containing the response body and response headers. |
| | 2224 | | /// </return> |
| | 2225 | | public async Task<AzureOperationResponse<ServicePrincipalObjectResult>> GetServicePrincipalsIdByAppIdWithHttpMes |
| | 2226 | | { |
| 0 | 2227 | | if (Client.ApiVersion == null) |
| | 2228 | | { |
| 0 | 2229 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2230 | | } |
| 0 | 2231 | | if (Client.TenantID == null) |
| | 2232 | | { |
| 0 | 2233 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 2234 | | } |
| 0 | 2235 | | if (applicationID == null) |
| | 2236 | | { |
| 0 | 2237 | | throw new ValidationException(ValidationRules.CannotBeNull, "applicationID"); |
| | 2238 | | } |
| | 2239 | | // Tracing |
| 0 | 2240 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2241 | | string _invocationId = null; |
| 0 | 2242 | | if (_shouldTrace) |
| | 2243 | | { |
| 0 | 2244 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2245 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2246 | | tracingParameters.Add("applicationID", applicationID); |
| 0 | 2247 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2248 | | ServiceClientTracing.Enter(_invocationId, this, "GetServicePrincipalsIdByAppId", tracingParameters); |
| | 2249 | | } |
| | 2250 | | // Construct URL |
| 0 | 2251 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 2252 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/servic |
| 0 | 2253 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 2254 | | _url = _url.Replace("{applicationID}", System.Uri.EscapeDataString(applicationID)); |
| 0 | 2255 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2256 | | if (Client.ApiVersion != null) |
| | 2257 | | { |
| 0 | 2258 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2259 | | } |
| 0 | 2260 | | if (_queryParameters.Count > 0) |
| | 2261 | | { |
| 0 | 2262 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2263 | | } |
| | 2264 | | // Create HTTP transport objects |
| 0 | 2265 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2266 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2267 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2268 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2269 | | // Set Headers |
| 0 | 2270 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2271 | | { |
| 0 | 2272 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2273 | | } |
| 0 | 2274 | | if (Client.AcceptLanguage != null) |
| | 2275 | | { |
| 0 | 2276 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2277 | | { |
| 0 | 2278 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2279 | | } |
| 0 | 2280 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2281 | | } |
| | 2282 | |
|
| | 2283 | |
|
| 0 | 2284 | | if (customHeaders != null) |
| | 2285 | | { |
| 0 | 2286 | | foreach(var _header in customHeaders) |
| | 2287 | | { |
| 0 | 2288 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2289 | | { |
| 0 | 2290 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2291 | | } |
| 0 | 2292 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2293 | | } |
| | 2294 | | } |
| | 2295 | |
|
| | 2296 | | // Serialize Request |
| 0 | 2297 | | string _requestContent = null; |
| | 2298 | | // Set Credentials |
| 0 | 2299 | | if (Client.Credentials != null) |
| | 2300 | | { |
| 0 | 2301 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2302 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2303 | | } |
| | 2304 | | // Send Request |
| 0 | 2305 | | if (_shouldTrace) |
| | 2306 | | { |
| 0 | 2307 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2308 | | } |
| 0 | 2309 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2310 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2311 | | if (_shouldTrace) |
| | 2312 | | { |
| 0 | 2313 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2314 | | } |
| 0 | 2315 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2316 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2317 | | string _responseContent = null; |
| 0 | 2318 | | if ((int)_statusCode != 200) |
| | 2319 | | { |
| 0 | 2320 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2321 | | try |
| | 2322 | | { |
| 0 | 2323 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2324 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 2325 | | if (_errorBody != null) |
| | 2326 | | { |
| 0 | 2327 | | ex.Body = _errorBody; |
| | 2328 | | } |
| 0 | 2329 | | } |
| 0 | 2330 | | catch (JsonException) |
| | 2331 | | { |
| | 2332 | | // Ignore the exception |
| 0 | 2333 | | } |
| 0 | 2334 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2335 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2336 | | if (_shouldTrace) |
| | 2337 | | { |
| 0 | 2338 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2339 | | } |
| 0 | 2340 | | _httpRequest.Dispose(); |
| 0 | 2341 | | if (_httpResponse != null) |
| | 2342 | | { |
| 0 | 2343 | | _httpResponse.Dispose(); |
| | 2344 | | } |
| 0 | 2345 | | throw ex; |
| | 2346 | | } |
| | 2347 | | // Create Result |
| 0 | 2348 | | var _result = new AzureOperationResponse<ServicePrincipalObjectResult>(); |
| 0 | 2349 | | _result.Request = _httpRequest; |
| 0 | 2350 | | _result.Response = _httpResponse; |
| 0 | 2351 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2352 | | { |
| 0 | 2353 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2354 | | } |
| | 2355 | | // Deserialize Response |
| 0 | 2356 | | if ((int)_statusCode == 200) |
| | 2357 | | { |
| 0 | 2358 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2359 | | try |
| | 2360 | | { |
| 0 | 2361 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ServicePrincipalObjectResult>(_r |
| 0 | 2362 | | } |
| 0 | 2363 | | catch (JsonException ex) |
| | 2364 | | { |
| 0 | 2365 | | _httpRequest.Dispose(); |
| 0 | 2366 | | if (_httpResponse != null) |
| | 2367 | | { |
| 0 | 2368 | | _httpResponse.Dispose(); |
| | 2369 | | } |
| 0 | 2370 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2371 | | } |
| | 2372 | | } |
| 0 | 2373 | | if (_shouldTrace) |
| | 2374 | | { |
| 0 | 2375 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2376 | | } |
| 0 | 2377 | | return _result; |
| 0 | 2378 | | } |
| | 2379 | |
|
| | 2380 | | /// <summary> |
| | 2381 | | /// Gets a list of applications from the current tenant. |
| | 2382 | | /// </summary> |
| | 2383 | | /// <param name='nextLink'> |
| | 2384 | | /// Next link for the list operation. |
| | 2385 | | /// </param> |
| | 2386 | | /// <param name='customHeaders'> |
| | 2387 | | /// Headers that will be added to request. |
| | 2388 | | /// </param> |
| | 2389 | | /// <param name='cancellationToken'> |
| | 2390 | | /// The cancellation token. |
| | 2391 | | /// </param> |
| | 2392 | | /// <exception cref="GraphErrorException"> |
| | 2393 | | /// Thrown when the operation returned an invalid status code |
| | 2394 | | /// </exception> |
| | 2395 | | /// <exception cref="SerializationException"> |
| | 2396 | | /// Thrown when unable to deserialize the response |
| | 2397 | | /// </exception> |
| | 2398 | | /// <exception cref="ValidationException"> |
| | 2399 | | /// Thrown when a required parameter is null |
| | 2400 | | /// </exception> |
| | 2401 | | /// <exception cref="System.ArgumentNullException"> |
| | 2402 | | /// Thrown when a required parameter is null |
| | 2403 | | /// </exception> |
| | 2404 | | /// <return> |
| | 2405 | | /// A response object containing the response body and response headers. |
| | 2406 | | /// </return> |
| | 2407 | | public async Task<AzureOperationResponse<IPage<Application>>> ListNextWithHttpMessagesAsync(string nextLink, Dic |
| | 2408 | | { |
| 0 | 2409 | | if (nextLink == null) |
| | 2410 | | { |
| 0 | 2411 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextLink"); |
| | 2412 | | } |
| 0 | 2413 | | if (Client.ApiVersion == null) |
| | 2414 | | { |
| 0 | 2415 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); |
| | 2416 | | } |
| 0 | 2417 | | if (Client.TenantID == null) |
| | 2418 | | { |
| 0 | 2419 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.TenantID"); |
| | 2420 | | } |
| | 2421 | | // Tracing |
| 0 | 2422 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2423 | | string _invocationId = null; |
| 0 | 2424 | | if (_shouldTrace) |
| | 2425 | | { |
| 0 | 2426 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2427 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2428 | | tracingParameters.Add("nextLink", nextLink); |
| 0 | 2429 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2430 | | ServiceClientTracing.Enter(_invocationId, this, "ListNext", tracingParameters); |
| | 2431 | | } |
| | 2432 | | // Construct URL |
| 0 | 2433 | | var _baseUrl = Client.BaseUri.AbsoluteUri; |
| 0 | 2434 | | var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "{tenantID}/{nextL |
| 0 | 2435 | | _url = _url.Replace("{nextLink}", nextLink); |
| 0 | 2436 | | _url = _url.Replace("{tenantID}", System.Uri.EscapeDataString(Client.TenantID)); |
| 0 | 2437 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2438 | | if (Client.ApiVersion != null) |
| | 2439 | | { |
| 0 | 2440 | | _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); |
| | 2441 | | } |
| 0 | 2442 | | if (_queryParameters.Count > 0) |
| | 2443 | | { |
| 0 | 2444 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2445 | | } |
| | 2446 | | // Create HTTP transport objects |
| 0 | 2447 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2448 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2449 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2450 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2451 | | // Set Headers |
| 0 | 2452 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2453 | | { |
| 0 | 2454 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2455 | | } |
| 0 | 2456 | | if (Client.AcceptLanguage != null) |
| | 2457 | | { |
| 0 | 2458 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2459 | | { |
| 0 | 2460 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2461 | | } |
| 0 | 2462 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2463 | | } |
| | 2464 | |
|
| | 2465 | |
|
| 0 | 2466 | | if (customHeaders != null) |
| | 2467 | | { |
| 0 | 2468 | | foreach(var _header in customHeaders) |
| | 2469 | | { |
| 0 | 2470 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2471 | | { |
| 0 | 2472 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2473 | | } |
| 0 | 2474 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2475 | | } |
| | 2476 | | } |
| | 2477 | |
|
| | 2478 | | // Serialize Request |
| 0 | 2479 | | string _requestContent = null; |
| | 2480 | | // Set Credentials |
| 0 | 2481 | | if (Client.Credentials != null) |
| | 2482 | | { |
| 0 | 2483 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2484 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2485 | | } |
| | 2486 | | // Send Request |
| 0 | 2487 | | if (_shouldTrace) |
| | 2488 | | { |
| 0 | 2489 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2490 | | } |
| 0 | 2491 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2492 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2493 | | if (_shouldTrace) |
| | 2494 | | { |
| 0 | 2495 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2496 | | } |
| 0 | 2497 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2498 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2499 | | string _responseContent = null; |
| 0 | 2500 | | if ((int)_statusCode != 200) |
| | 2501 | | { |
| 0 | 2502 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2503 | | try |
| | 2504 | | { |
| 0 | 2505 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2506 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 2507 | | if (_errorBody != null) |
| | 2508 | | { |
| 0 | 2509 | | ex.Body = _errorBody; |
| | 2510 | | } |
| 0 | 2511 | | } |
| 0 | 2512 | | catch (JsonException) |
| | 2513 | | { |
| | 2514 | | // Ignore the exception |
| 0 | 2515 | | } |
| 0 | 2516 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2517 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2518 | | if (_shouldTrace) |
| | 2519 | | { |
| 0 | 2520 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2521 | | } |
| 0 | 2522 | | _httpRequest.Dispose(); |
| 0 | 2523 | | if (_httpResponse != null) |
| | 2524 | | { |
| 0 | 2525 | | _httpResponse.Dispose(); |
| | 2526 | | } |
| 0 | 2527 | | throw ex; |
| | 2528 | | } |
| | 2529 | | // Create Result |
| 0 | 2530 | | var _result = new AzureOperationResponse<IPage<Application>>(); |
| 0 | 2531 | | _result.Request = _httpRequest; |
| 0 | 2532 | | _result.Response = _httpResponse; |
| 0 | 2533 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2534 | | { |
| 0 | 2535 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2536 | | } |
| | 2537 | | // Deserialize Response |
| 0 | 2538 | | if ((int)_statusCode == 200) |
| | 2539 | | { |
| 0 | 2540 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2541 | | try |
| | 2542 | | { |
| 0 | 2543 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<Application>>(_responseCont |
| 0 | 2544 | | } |
| 0 | 2545 | | catch (JsonException ex) |
| | 2546 | | { |
| 0 | 2547 | | _httpRequest.Dispose(); |
| 0 | 2548 | | if (_httpResponse != null) |
| | 2549 | | { |
| 0 | 2550 | | _httpResponse.Dispose(); |
| | 2551 | | } |
| 0 | 2552 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2553 | | } |
| | 2554 | | } |
| 0 | 2555 | | if (_shouldTrace) |
| | 2556 | | { |
| 0 | 2557 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2558 | | } |
| 0 | 2559 | | return _result; |
| 0 | 2560 | | } |
| | 2561 | |
|
| | 2562 | | /// <summary> |
| | 2563 | | /// Directory objects that are owners of the application. |
| | 2564 | | /// </summary> |
| | 2565 | | /// <remarks> |
| | 2566 | | /// The owners are a set of non-admin users who are allowed to modify this |
| | 2567 | | /// object. |
| | 2568 | | /// </remarks> |
| | 2569 | | /// <param name='nextPageLink'> |
| | 2570 | | /// The NextLink from the previous successful call to List operation. |
| | 2571 | | /// </param> |
| | 2572 | | /// <param name='customHeaders'> |
| | 2573 | | /// Headers that will be added to request. |
| | 2574 | | /// </param> |
| | 2575 | | /// <param name='cancellationToken'> |
| | 2576 | | /// The cancellation token. |
| | 2577 | | /// </param> |
| | 2578 | | /// <exception cref="GraphErrorException"> |
| | 2579 | | /// Thrown when the operation returned an invalid status code |
| | 2580 | | /// </exception> |
| | 2581 | | /// <exception cref="SerializationException"> |
| | 2582 | | /// Thrown when unable to deserialize the response |
| | 2583 | | /// </exception> |
| | 2584 | | /// <exception cref="ValidationException"> |
| | 2585 | | /// Thrown when a required parameter is null |
| | 2586 | | /// </exception> |
| | 2587 | | /// <exception cref="System.ArgumentNullException"> |
| | 2588 | | /// Thrown when a required parameter is null |
| | 2589 | | /// </exception> |
| | 2590 | | /// <return> |
| | 2591 | | /// A response object containing the response body and response headers. |
| | 2592 | | /// </return> |
| | 2593 | | public async Task<AzureOperationResponse<IPage<DirectoryObject>>> ListOwnersNextWithHttpMessagesAsync(string nex |
| | 2594 | | { |
| 0 | 2595 | | if (nextPageLink == null) |
| | 2596 | | { |
| 0 | 2597 | | throw new ValidationException(ValidationRules.CannotBeNull, "nextPageLink"); |
| | 2598 | | } |
| | 2599 | | // Tracing |
| 0 | 2600 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 2601 | | string _invocationId = null; |
| 0 | 2602 | | if (_shouldTrace) |
| | 2603 | | { |
| 0 | 2604 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2605 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2606 | | tracingParameters.Add("nextPageLink", nextPageLink); |
| 0 | 2607 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2608 | | ServiceClientTracing.Enter(_invocationId, this, "ListOwnersNext", tracingParameters); |
| | 2609 | | } |
| | 2610 | | // Construct URL |
| 0 | 2611 | | string _url = "{nextLink}"; |
| 0 | 2612 | | _url = _url.Replace("{nextLink}", nextPageLink); |
| 0 | 2613 | | List<string> _queryParameters = new List<string>(); |
| 0 | 2614 | | if (_queryParameters.Count > 0) |
| | 2615 | | { |
| 0 | 2616 | | _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); |
| | 2617 | | } |
| | 2618 | | // Create HTTP transport objects |
| 0 | 2619 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 2620 | | HttpResponseMessage _httpResponse = null; |
| 0 | 2621 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 2622 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2623 | | // Set Headers |
| 0 | 2624 | | if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) |
| | 2625 | | { |
| 0 | 2626 | | _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()) |
| | 2627 | | } |
| 0 | 2628 | | if (Client.AcceptLanguage != null) |
| | 2629 | | { |
| 0 | 2630 | | if (_httpRequest.Headers.Contains("accept-language")) |
| | 2631 | | { |
| 0 | 2632 | | _httpRequest.Headers.Remove("accept-language"); |
| | 2633 | | } |
| 0 | 2634 | | _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); |
| | 2635 | | } |
| | 2636 | |
|
| | 2637 | |
|
| 0 | 2638 | | if (customHeaders != null) |
| | 2639 | | { |
| 0 | 2640 | | foreach(var _header in customHeaders) |
| | 2641 | | { |
| 0 | 2642 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2643 | | { |
| 0 | 2644 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2645 | | } |
| 0 | 2646 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2647 | | } |
| | 2648 | | } |
| | 2649 | |
|
| | 2650 | | // Serialize Request |
| 0 | 2651 | | string _requestContent = null; |
| | 2652 | | // Set Credentials |
| 0 | 2653 | | if (Client.Credentials != null) |
| | 2654 | | { |
| 0 | 2655 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2656 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2657 | | } |
| | 2658 | | // Send Request |
| 0 | 2659 | | if (_shouldTrace) |
| | 2660 | | { |
| 0 | 2661 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2662 | | } |
| 0 | 2663 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2664 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 2665 | | if (_shouldTrace) |
| | 2666 | | { |
| 0 | 2667 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2668 | | } |
| 0 | 2669 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 2670 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 2671 | | string _responseContent = null; |
| 0 | 2672 | | if ((int)_statusCode != 200) |
| | 2673 | | { |
| 0 | 2674 | | var ex = new GraphErrorException(string.Format("Operation returned an invalid status code '{0}'", _statu |
| | 2675 | | try |
| | 2676 | | { |
| 0 | 2677 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2678 | | GraphError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<GraphError>(_responseC |
| 0 | 2679 | | if (_errorBody != null) |
| | 2680 | | { |
| 0 | 2681 | | ex.Body = _errorBody; |
| | 2682 | | } |
| 0 | 2683 | | } |
| 0 | 2684 | | catch (JsonException) |
| | 2685 | | { |
| | 2686 | | // Ignore the exception |
| 0 | 2687 | | } |
| 0 | 2688 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2689 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2690 | | if (_shouldTrace) |
| | 2691 | | { |
| 0 | 2692 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2693 | | } |
| 0 | 2694 | | _httpRequest.Dispose(); |
| 0 | 2695 | | if (_httpResponse != null) |
| | 2696 | | { |
| 0 | 2697 | | _httpResponse.Dispose(); |
| | 2698 | | } |
| 0 | 2699 | | throw ex; |
| | 2700 | | } |
| | 2701 | | // Create Result |
| 0 | 2702 | | var _result = new AzureOperationResponse<IPage<DirectoryObject>>(); |
| 0 | 2703 | | _result.Request = _httpRequest; |
| 0 | 2704 | | _result.Response = _httpResponse; |
| 0 | 2705 | | if (_httpResponse.Headers.Contains("x-ms-request-id")) |
| | 2706 | | { |
| 0 | 2707 | | _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); |
| | 2708 | | } |
| | 2709 | | // Deserialize Response |
| 0 | 2710 | | if ((int)_statusCode == 200) |
| | 2711 | | { |
| 0 | 2712 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2713 | | try |
| | 2714 | | { |
| 0 | 2715 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Page<DirectoryObject>>(_response |
| 0 | 2716 | | } |
| 0 | 2717 | | catch (JsonException ex) |
| | 2718 | | { |
| 0 | 2719 | | _httpRequest.Dispose(); |
| 0 | 2720 | | if (_httpResponse != null) |
| | 2721 | | { |
| 0 | 2722 | | _httpResponse.Dispose(); |
| | 2723 | | } |
| 0 | 2724 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2725 | | } |
| | 2726 | | } |
| 0 | 2727 | | if (_shouldTrace) |
| | 2728 | | { |
| 0 | 2729 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2730 | | } |
| 0 | 2731 | | return _result; |
| 0 | 2732 | | } |
| | 2733 | |
|
| | 2734 | | } |
| | 2735 | | } |