| | 1 | | // <auto-generated> |
| | 2 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 3 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 4 | | // regenerated. |
| | 5 | | // </auto-generated> |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.CognitiveServices.ContentModerator |
| | 8 | | { |
| | 9 | | using Microsoft.Rest; |
| | 10 | | using Models; |
| | 11 | | using Newtonsoft.Json; |
| | 12 | | using System.Collections; |
| | 13 | | using System.Collections.Generic; |
| | 14 | | using System.IO; |
| | 15 | | using System.Linq; |
| | 16 | | using System.Net; |
| | 17 | | using System.Net.Http; |
| | 18 | | using System.Threading; |
| | 19 | | using System.Threading.Tasks; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// ListManagementImageLists operations. |
| | 23 | | /// </summary> |
| | 24 | | public partial class ListManagementImageLists : IServiceOperations<ContentModeratorClient>, IListManagementImageList |
| | 25 | | { |
| | 26 | | /// <summary> |
| | 27 | | /// Initializes a new instance of the ListManagementImageLists class. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name='client'> |
| | 30 | | /// Reference to the service client. |
| | 31 | | /// </param> |
| | 32 | | /// <exception cref="System.ArgumentNullException"> |
| | 33 | | /// Thrown when a required parameter is null |
| | 34 | | /// </exception> |
| 5 | 35 | | public ListManagementImageLists(ContentModeratorClient client) |
| | 36 | | { |
| 5 | 37 | | if (client == null) |
| | 38 | | { |
| 0 | 39 | | throw new System.ArgumentNullException("client"); |
| | 40 | | } |
| 5 | 41 | | Client = client; |
| 5 | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets a reference to the ContentModeratorClient |
| | 46 | | /// </summary> |
| 0 | 47 | | public ContentModeratorClient Client { get; private set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Returns the details of the image list with list Id equal to list Id passed. |
| | 51 | | /// </summary> |
| | 52 | | /// <param name='listId'> |
| | 53 | | /// List Id of the image list. |
| | 54 | | /// </param> |
| | 55 | | /// <param name='customHeaders'> |
| | 56 | | /// Headers that will be added to request. |
| | 57 | | /// </param> |
| | 58 | | /// <param name='cancellationToken'> |
| | 59 | | /// The cancellation token. |
| | 60 | | /// </param> |
| | 61 | | /// <exception cref="APIErrorException"> |
| | 62 | | /// Thrown when the operation returned an invalid status code |
| | 63 | | /// </exception> |
| | 64 | | /// <exception cref="SerializationException"> |
| | 65 | | /// Thrown when unable to deserialize the response |
| | 66 | | /// </exception> |
| | 67 | | /// <exception cref="ValidationException"> |
| | 68 | | /// Thrown when a required parameter is null |
| | 69 | | /// </exception> |
| | 70 | | /// <exception cref="System.ArgumentNullException"> |
| | 71 | | /// Thrown when a required parameter is null |
| | 72 | | /// </exception> |
| | 73 | | /// <return> |
| | 74 | | /// A response object containing the response body and response headers. |
| | 75 | | /// </return> |
| | 76 | | public async Task<HttpOperationResponse<ImageList>> GetDetailsWithHttpMessagesAsync(string listId, Dictionary<st |
| | 77 | | { |
| 0 | 78 | | if (Client.Endpoint == null) |
| | 79 | | { |
| 0 | 80 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 81 | | } |
| 0 | 82 | | if (listId == null) |
| | 83 | | { |
| 0 | 84 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 85 | | } |
| | 86 | | // Tracing |
| 0 | 87 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 88 | | string _invocationId = null; |
| 0 | 89 | | if (_shouldTrace) |
| | 90 | | { |
| 0 | 91 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 92 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 93 | | tracingParameters.Add("listId", listId); |
| 0 | 94 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 95 | | ServiceClientTracing.Enter(_invocationId, this, "GetDetails", tracingParameters); |
| | 96 | | } |
| | 97 | | // Construct URL |
| 0 | 98 | | var _baseUrl = Client.BaseUri; |
| 0 | 99 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/imagelists/{listId} |
| 0 | 100 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 101 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| | 102 | | // Create HTTP transport objects |
| 0 | 103 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 104 | | HttpResponseMessage _httpResponse = null; |
| 0 | 105 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 106 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 107 | | // Set Headers |
| | 108 | |
|
| | 109 | |
|
| 0 | 110 | | if (customHeaders != null) |
| | 111 | | { |
| 0 | 112 | | foreach(var _header in customHeaders) |
| | 113 | | { |
| 0 | 114 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 115 | | { |
| 0 | 116 | | _httpRequest.Headers.Remove(_header.Key); |
| | 117 | | } |
| 0 | 118 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 119 | | } |
| | 120 | | } |
| | 121 | |
|
| | 122 | | // Serialize Request |
| 0 | 123 | | string _requestContent = null; |
| | 124 | | // Set Credentials |
| 0 | 125 | | if (Client.Credentials != null) |
| | 126 | | { |
| 0 | 127 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 128 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 129 | | } |
| | 130 | | // Send Request |
| 0 | 131 | | if (_shouldTrace) |
| | 132 | | { |
| 0 | 133 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 134 | | } |
| 0 | 135 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 136 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 137 | | if (_shouldTrace) |
| | 138 | | { |
| 0 | 139 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 140 | | } |
| 0 | 141 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 142 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 143 | | string _responseContent = null; |
| 0 | 144 | | if ((int)_statusCode != 200) |
| | 145 | | { |
| 0 | 146 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 147 | | try |
| | 148 | | { |
| 0 | 149 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 150 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 151 | | if (_errorBody != null) |
| | 152 | | { |
| 0 | 153 | | ex.Body = _errorBody; |
| | 154 | | } |
| 0 | 155 | | } |
| 0 | 156 | | catch (JsonException) |
| | 157 | | { |
| | 158 | | // Ignore the exception |
| 0 | 159 | | } |
| 0 | 160 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 161 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 162 | | if (_shouldTrace) |
| | 163 | | { |
| 0 | 164 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 165 | | } |
| 0 | 166 | | _httpRequest.Dispose(); |
| 0 | 167 | | if (_httpResponse != null) |
| | 168 | | { |
| 0 | 169 | | _httpResponse.Dispose(); |
| | 170 | | } |
| 0 | 171 | | throw ex; |
| | 172 | | } |
| | 173 | | // Create Result |
| 0 | 174 | | var _result = new HttpOperationResponse<ImageList>(); |
| 0 | 175 | | _result.Request = _httpRequest; |
| 0 | 176 | | _result.Response = _httpResponse; |
| | 177 | | // Deserialize Response |
| 0 | 178 | | if ((int)_statusCode == 200) |
| | 179 | | { |
| 0 | 180 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 181 | | try |
| | 182 | | { |
| 0 | 183 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ImageList>(_responseContent, Cli |
| 0 | 184 | | } |
| 0 | 185 | | catch (JsonException ex) |
| | 186 | | { |
| 0 | 187 | | _httpRequest.Dispose(); |
| 0 | 188 | | if (_httpResponse != null) |
| | 189 | | { |
| 0 | 190 | | _httpResponse.Dispose(); |
| | 191 | | } |
| 0 | 192 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 193 | | } |
| | 194 | | } |
| 0 | 195 | | if (_shouldTrace) |
| | 196 | | { |
| 0 | 197 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 198 | | } |
| 0 | 199 | | return _result; |
| 0 | 200 | | } |
| | 201 | |
|
| | 202 | | /// <summary> |
| | 203 | | /// Deletes image list with the list Id equal to list Id passed. |
| | 204 | | /// </summary> |
| | 205 | | /// <param name='listId'> |
| | 206 | | /// List Id of the image list. |
| | 207 | | /// </param> |
| | 208 | | /// <param name='customHeaders'> |
| | 209 | | /// Headers that will be added to request. |
| | 210 | | /// </param> |
| | 211 | | /// <param name='cancellationToken'> |
| | 212 | | /// The cancellation token. |
| | 213 | | /// </param> |
| | 214 | | /// <exception cref="APIErrorException"> |
| | 215 | | /// Thrown when the operation returned an invalid status code |
| | 216 | | /// </exception> |
| | 217 | | /// <exception cref="SerializationException"> |
| | 218 | | /// Thrown when unable to deserialize the response |
| | 219 | | /// </exception> |
| | 220 | | /// <exception cref="ValidationException"> |
| | 221 | | /// Thrown when a required parameter is null |
| | 222 | | /// </exception> |
| | 223 | | /// <exception cref="System.ArgumentNullException"> |
| | 224 | | /// Thrown when a required parameter is null |
| | 225 | | /// </exception> |
| | 226 | | /// <return> |
| | 227 | | /// A response object containing the response body and response headers. |
| | 228 | | /// </return> |
| | 229 | | public async Task<HttpOperationResponse<string>> DeleteWithHttpMessagesAsync(string listId, Dictionary<string, L |
| | 230 | | { |
| 0 | 231 | | if (Client.Endpoint == null) |
| | 232 | | { |
| 0 | 233 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 234 | | } |
| 0 | 235 | | if (listId == null) |
| | 236 | | { |
| 0 | 237 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 238 | | } |
| | 239 | | // Tracing |
| 0 | 240 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 241 | | string _invocationId = null; |
| 0 | 242 | | if (_shouldTrace) |
| | 243 | | { |
| 0 | 244 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 245 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 246 | | tracingParameters.Add("listId", listId); |
| 0 | 247 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 248 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 249 | | } |
| | 250 | | // Construct URL |
| 0 | 251 | | var _baseUrl = Client.BaseUri; |
| 0 | 252 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/imagelists/{listId} |
| 0 | 253 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 254 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| | 255 | | // Create HTTP transport objects |
| 0 | 256 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 257 | | HttpResponseMessage _httpResponse = null; |
| 0 | 258 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 259 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 260 | | // Set Headers |
| | 261 | |
|
| | 262 | |
|
| 0 | 263 | | if (customHeaders != null) |
| | 264 | | { |
| 0 | 265 | | foreach(var _header in customHeaders) |
| | 266 | | { |
| 0 | 267 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 268 | | { |
| 0 | 269 | | _httpRequest.Headers.Remove(_header.Key); |
| | 270 | | } |
| 0 | 271 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 272 | | } |
| | 273 | | } |
| | 274 | |
|
| | 275 | | // Serialize Request |
| 0 | 276 | | string _requestContent = null; |
| | 277 | | // Set Credentials |
| 0 | 278 | | if (Client.Credentials != null) |
| | 279 | | { |
| 0 | 280 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 281 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 282 | | } |
| | 283 | | // Send Request |
| 0 | 284 | | if (_shouldTrace) |
| | 285 | | { |
| 0 | 286 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 287 | | } |
| 0 | 288 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 289 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 290 | | if (_shouldTrace) |
| | 291 | | { |
| 0 | 292 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 293 | | } |
| 0 | 294 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 295 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 296 | | string _responseContent = null; |
| 0 | 297 | | if ((int)_statusCode != 200) |
| | 298 | | { |
| 0 | 299 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 300 | | try |
| | 301 | | { |
| 0 | 302 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 303 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 304 | | if (_errorBody != null) |
| | 305 | | { |
| 0 | 306 | | ex.Body = _errorBody; |
| | 307 | | } |
| 0 | 308 | | } |
| 0 | 309 | | catch (JsonException) |
| | 310 | | { |
| | 311 | | // Ignore the exception |
| 0 | 312 | | } |
| 0 | 313 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 314 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 315 | | if (_shouldTrace) |
| | 316 | | { |
| 0 | 317 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 318 | | } |
| 0 | 319 | | _httpRequest.Dispose(); |
| 0 | 320 | | if (_httpResponse != null) |
| | 321 | | { |
| 0 | 322 | | _httpResponse.Dispose(); |
| | 323 | | } |
| 0 | 324 | | throw ex; |
| | 325 | | } |
| | 326 | | // Create Result |
| 0 | 327 | | var _result = new HttpOperationResponse<string>(); |
| 0 | 328 | | _result.Request = _httpRequest; |
| 0 | 329 | | _result.Response = _httpResponse; |
| | 330 | | // Deserialize Response |
| 0 | 331 | | if ((int)_statusCode == 200) |
| | 332 | | { |
| 0 | 333 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 334 | | try |
| | 335 | | { |
| 0 | 336 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 0 | 337 | | } |
| 0 | 338 | | catch (JsonException ex) |
| | 339 | | { |
| 0 | 340 | | _httpRequest.Dispose(); |
| 0 | 341 | | if (_httpResponse != null) |
| | 342 | | { |
| 0 | 343 | | _httpResponse.Dispose(); |
| | 344 | | } |
| 0 | 345 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 346 | | } |
| | 347 | | } |
| 0 | 348 | | if (_shouldTrace) |
| | 349 | | { |
| 0 | 350 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 351 | | } |
| 0 | 352 | | return _result; |
| 0 | 353 | | } |
| | 354 | |
|
| | 355 | | /// <summary> |
| | 356 | | /// Updates an image list with list Id equal to list Id passed. |
| | 357 | | /// </summary> |
| | 358 | | /// <param name='listId'> |
| | 359 | | /// List Id of the image list. |
| | 360 | | /// </param> |
| | 361 | | /// <param name='contentType'> |
| | 362 | | /// The content type. |
| | 363 | | /// </param> |
| | 364 | | /// <param name='body'> |
| | 365 | | /// Schema of the body. |
| | 366 | | /// </param> |
| | 367 | | /// <param name='customHeaders'> |
| | 368 | | /// Headers that will be added to request. |
| | 369 | | /// </param> |
| | 370 | | /// <param name='cancellationToken'> |
| | 371 | | /// The cancellation token. |
| | 372 | | /// </param> |
| | 373 | | /// <exception cref="APIErrorException"> |
| | 374 | | /// Thrown when the operation returned an invalid status code |
| | 375 | | /// </exception> |
| | 376 | | /// <exception cref="SerializationException"> |
| | 377 | | /// Thrown when unable to deserialize the response |
| | 378 | | /// </exception> |
| | 379 | | /// <exception cref="ValidationException"> |
| | 380 | | /// Thrown when a required parameter is null |
| | 381 | | /// </exception> |
| | 382 | | /// <exception cref="System.ArgumentNullException"> |
| | 383 | | /// Thrown when a required parameter is null |
| | 384 | | /// </exception> |
| | 385 | | /// <return> |
| | 386 | | /// A response object containing the response body and response headers. |
| | 387 | | /// </return> |
| | 388 | | public async Task<HttpOperationResponse<ImageList>> UpdateWithHttpMessagesAsync(string listId, string contentTyp |
| | 389 | | { |
| 0 | 390 | | if (Client.Endpoint == null) |
| | 391 | | { |
| 0 | 392 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 393 | | } |
| 0 | 394 | | if (listId == null) |
| | 395 | | { |
| 0 | 396 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 397 | | } |
| 0 | 398 | | if (contentType == null) |
| | 399 | | { |
| 0 | 400 | | throw new ValidationException(ValidationRules.CannotBeNull, "contentType"); |
| | 401 | | } |
| 0 | 402 | | if (body == null) |
| | 403 | | { |
| 0 | 404 | | throw new ValidationException(ValidationRules.CannotBeNull, "body"); |
| | 405 | | } |
| | 406 | | // Tracing |
| 0 | 407 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 408 | | string _invocationId = null; |
| 0 | 409 | | if (_shouldTrace) |
| | 410 | | { |
| 0 | 411 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 412 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 413 | | tracingParameters.Add("listId", listId); |
| 0 | 414 | | tracingParameters.Add("contentType", contentType); |
| 0 | 415 | | tracingParameters.Add("body", body); |
| 0 | 416 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 417 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 418 | | } |
| | 419 | | // Construct URL |
| 0 | 420 | | var _baseUrl = Client.BaseUri; |
| 0 | 421 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/imagelists/{listId} |
| 0 | 422 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 423 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| | 424 | | // Create HTTP transport objects |
| 0 | 425 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 426 | | HttpResponseMessage _httpResponse = null; |
| 0 | 427 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 0 | 428 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 429 | | // Set Headers |
| | 430 | |
|
| | 431 | |
|
| 0 | 432 | | if (customHeaders != null) |
| | 433 | | { |
| 0 | 434 | | foreach(var _header in customHeaders) |
| | 435 | | { |
| 0 | 436 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 437 | | { |
| 0 | 438 | | _httpRequest.Headers.Remove(_header.Key); |
| | 439 | | } |
| 0 | 440 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 441 | | } |
| | 442 | | } |
| | 443 | |
|
| | 444 | | // Serialize Request |
| 0 | 445 | | string _requestContent = null; |
| 0 | 446 | | if(body != null) |
| | 447 | | { |
| 0 | 448 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 449 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 450 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 451 | | } |
| | 452 | | // Set Credentials |
| 0 | 453 | | if (Client.Credentials != null) |
| | 454 | | { |
| 0 | 455 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 456 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 457 | | } |
| | 458 | | // Send Request |
| 0 | 459 | | if (_shouldTrace) |
| | 460 | | { |
| 0 | 461 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 462 | | } |
| 0 | 463 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 464 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 465 | | if (_shouldTrace) |
| | 466 | | { |
| 0 | 467 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 468 | | } |
| 0 | 469 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 470 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 471 | | string _responseContent = null; |
| 0 | 472 | | if ((int)_statusCode != 200) |
| | 473 | | { |
| 0 | 474 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 475 | | try |
| | 476 | | { |
| 0 | 477 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 478 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 479 | | if (_errorBody != null) |
| | 480 | | { |
| 0 | 481 | | ex.Body = _errorBody; |
| | 482 | | } |
| 0 | 483 | | } |
| 0 | 484 | | catch (JsonException) |
| | 485 | | { |
| | 486 | | // Ignore the exception |
| 0 | 487 | | } |
| 0 | 488 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 489 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 490 | | if (_shouldTrace) |
| | 491 | | { |
| 0 | 492 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 493 | | } |
| 0 | 494 | | _httpRequest.Dispose(); |
| 0 | 495 | | if (_httpResponse != null) |
| | 496 | | { |
| 0 | 497 | | _httpResponse.Dispose(); |
| | 498 | | } |
| 0 | 499 | | throw ex; |
| | 500 | | } |
| | 501 | | // Create Result |
| 0 | 502 | | var _result = new HttpOperationResponse<ImageList>(); |
| 0 | 503 | | _result.Request = _httpRequest; |
| 0 | 504 | | _result.Response = _httpResponse; |
| | 505 | | // Deserialize Response |
| 0 | 506 | | if ((int)_statusCode == 200) |
| | 507 | | { |
| 0 | 508 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 509 | | try |
| | 510 | | { |
| 0 | 511 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ImageList>(_responseContent, Cli |
| 0 | 512 | | } |
| 0 | 513 | | catch (JsonException ex) |
| | 514 | | { |
| 0 | 515 | | _httpRequest.Dispose(); |
| 0 | 516 | | if (_httpResponse != null) |
| | 517 | | { |
| 0 | 518 | | _httpResponse.Dispose(); |
| | 519 | | } |
| 0 | 520 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 521 | | } |
| | 522 | | } |
| 0 | 523 | | if (_shouldTrace) |
| | 524 | | { |
| 0 | 525 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 526 | | } |
| 0 | 527 | | return _result; |
| 0 | 528 | | } |
| | 529 | |
|
| | 530 | | /// <summary> |
| | 531 | | /// Creates an image list. |
| | 532 | | /// </summary> |
| | 533 | | /// <param name='contentType'> |
| | 534 | | /// The content type. |
| | 535 | | /// </param> |
| | 536 | | /// <param name='body'> |
| | 537 | | /// Schema of the body. |
| | 538 | | /// </param> |
| | 539 | | /// <param name='customHeaders'> |
| | 540 | | /// Headers that will be added to request. |
| | 541 | | /// </param> |
| | 542 | | /// <param name='cancellationToken'> |
| | 543 | | /// The cancellation token. |
| | 544 | | /// </param> |
| | 545 | | /// <exception cref="APIErrorException"> |
| | 546 | | /// Thrown when the operation returned an invalid status code |
| | 547 | | /// </exception> |
| | 548 | | /// <exception cref="SerializationException"> |
| | 549 | | /// Thrown when unable to deserialize the response |
| | 550 | | /// </exception> |
| | 551 | | /// <exception cref="ValidationException"> |
| | 552 | | /// Thrown when a required parameter is null |
| | 553 | | /// </exception> |
| | 554 | | /// <exception cref="System.ArgumentNullException"> |
| | 555 | | /// Thrown when a required parameter is null |
| | 556 | | /// </exception> |
| | 557 | | /// <return> |
| | 558 | | /// A response object containing the response body and response headers. |
| | 559 | | /// </return> |
| | 560 | | public async Task<HttpOperationResponse<ImageList>> CreateWithHttpMessagesAsync(string contentType, Body body, D |
| | 561 | | { |
| 0 | 562 | | if (Client.Endpoint == null) |
| | 563 | | { |
| 0 | 564 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 565 | | } |
| 0 | 566 | | if (contentType == null) |
| | 567 | | { |
| 0 | 568 | | throw new ValidationException(ValidationRules.CannotBeNull, "contentType"); |
| | 569 | | } |
| 0 | 570 | | if (body == null) |
| | 571 | | { |
| 0 | 572 | | throw new ValidationException(ValidationRules.CannotBeNull, "body"); |
| | 573 | | } |
| | 574 | | // Tracing |
| 0 | 575 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 576 | | string _invocationId = null; |
| 0 | 577 | | if (_shouldTrace) |
| | 578 | | { |
| 0 | 579 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 580 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 581 | | tracingParameters.Add("contentType", contentType); |
| 0 | 582 | | tracingParameters.Add("body", body); |
| 0 | 583 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 584 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 585 | | } |
| | 586 | | // Construct URL |
| 0 | 587 | | var _baseUrl = Client.BaseUri; |
| 0 | 588 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/imagelists"; |
| 0 | 589 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 590 | | // Create HTTP transport objects |
| 0 | 591 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 592 | | HttpResponseMessage _httpResponse = null; |
| 0 | 593 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 594 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 595 | | // Set Headers |
| | 596 | |
|
| | 597 | |
|
| 0 | 598 | | if (customHeaders != null) |
| | 599 | | { |
| 0 | 600 | | foreach(var _header in customHeaders) |
| | 601 | | { |
| 0 | 602 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 603 | | { |
| 0 | 604 | | _httpRequest.Headers.Remove(_header.Key); |
| | 605 | | } |
| 0 | 606 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 607 | | } |
| | 608 | | } |
| | 609 | |
|
| | 610 | | // Serialize Request |
| 0 | 611 | | string _requestContent = null; |
| 0 | 612 | | if(body != null) |
| | 613 | | { |
| 0 | 614 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 615 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 616 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 617 | | } |
| | 618 | | // Set Credentials |
| 0 | 619 | | if (Client.Credentials != null) |
| | 620 | | { |
| 0 | 621 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 622 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 623 | | } |
| | 624 | | // Send Request |
| 0 | 625 | | if (_shouldTrace) |
| | 626 | | { |
| 0 | 627 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 628 | | } |
| 0 | 629 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 630 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 631 | | if (_shouldTrace) |
| | 632 | | { |
| 0 | 633 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 634 | | } |
| 0 | 635 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 636 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 637 | | string _responseContent = null; |
| 0 | 638 | | if ((int)_statusCode != 200) |
| | 639 | | { |
| 0 | 640 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 641 | | try |
| | 642 | | { |
| 0 | 643 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 644 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 645 | | if (_errorBody != null) |
| | 646 | | { |
| 0 | 647 | | ex.Body = _errorBody; |
| | 648 | | } |
| 0 | 649 | | } |
| 0 | 650 | | catch (JsonException) |
| | 651 | | { |
| | 652 | | // Ignore the exception |
| 0 | 653 | | } |
| 0 | 654 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 655 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 656 | | if (_shouldTrace) |
| | 657 | | { |
| 0 | 658 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 659 | | } |
| 0 | 660 | | _httpRequest.Dispose(); |
| 0 | 661 | | if (_httpResponse != null) |
| | 662 | | { |
| 0 | 663 | | _httpResponse.Dispose(); |
| | 664 | | } |
| 0 | 665 | | throw ex; |
| | 666 | | } |
| | 667 | | // Create Result |
| 0 | 668 | | var _result = new HttpOperationResponse<ImageList>(); |
| 0 | 669 | | _result.Request = _httpRequest; |
| 0 | 670 | | _result.Response = _httpResponse; |
| | 671 | | // Deserialize Response |
| 0 | 672 | | if ((int)_statusCode == 200) |
| | 673 | | { |
| 0 | 674 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 675 | | try |
| | 676 | | { |
| 0 | 677 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ImageList>(_responseContent, Cli |
| 0 | 678 | | } |
| 0 | 679 | | catch (JsonException ex) |
| | 680 | | { |
| 0 | 681 | | _httpRequest.Dispose(); |
| 0 | 682 | | if (_httpResponse != null) |
| | 683 | | { |
| 0 | 684 | | _httpResponse.Dispose(); |
| | 685 | | } |
| 0 | 686 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 687 | | } |
| | 688 | | } |
| 0 | 689 | | if (_shouldTrace) |
| | 690 | | { |
| 0 | 691 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 692 | | } |
| 0 | 693 | | return _result; |
| 0 | 694 | | } |
| | 695 | |
|
| | 696 | | /// <summary> |
| | 697 | | /// Gets all the Image Lists. |
| | 698 | | /// </summary> |
| | 699 | | /// <param name='customHeaders'> |
| | 700 | | /// Headers that will be added to request. |
| | 701 | | /// </param> |
| | 702 | | /// <param name='cancellationToken'> |
| | 703 | | /// The cancellation token. |
| | 704 | | /// </param> |
| | 705 | | /// <exception cref="APIErrorException"> |
| | 706 | | /// Thrown when the operation returned an invalid status code |
| | 707 | | /// </exception> |
| | 708 | | /// <exception cref="SerializationException"> |
| | 709 | | /// Thrown when unable to deserialize the response |
| | 710 | | /// </exception> |
| | 711 | | /// <exception cref="ValidationException"> |
| | 712 | | /// Thrown when a required parameter is null |
| | 713 | | /// </exception> |
| | 714 | | /// <exception cref="System.ArgumentNullException"> |
| | 715 | | /// Thrown when a required parameter is null |
| | 716 | | /// </exception> |
| | 717 | | /// <return> |
| | 718 | | /// A response object containing the response body and response headers. |
| | 719 | | /// </return> |
| | 720 | | public async Task<HttpOperationResponse<IList<ImageList>>> GetAllImageListsWithHttpMessagesAsync(Dictionary<stri |
| | 721 | | { |
| 0 | 722 | | if (Client.Endpoint == null) |
| | 723 | | { |
| 0 | 724 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 725 | | } |
| | 726 | | // Tracing |
| 0 | 727 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 728 | | string _invocationId = null; |
| 0 | 729 | | if (_shouldTrace) |
| | 730 | | { |
| 0 | 731 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 732 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 733 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 734 | | ServiceClientTracing.Enter(_invocationId, this, "GetAllImageLists", tracingParameters); |
| | 735 | | } |
| | 736 | | // Construct URL |
| 0 | 737 | | var _baseUrl = Client.BaseUri; |
| 0 | 738 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/imagelists"; |
| 0 | 739 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 740 | | // Create HTTP transport objects |
| 0 | 741 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 742 | | HttpResponseMessage _httpResponse = null; |
| 0 | 743 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 744 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 745 | | // Set Headers |
| | 746 | |
|
| | 747 | |
|
| 0 | 748 | | if (customHeaders != null) |
| | 749 | | { |
| 0 | 750 | | foreach(var _header in customHeaders) |
| | 751 | | { |
| 0 | 752 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 753 | | { |
| 0 | 754 | | _httpRequest.Headers.Remove(_header.Key); |
| | 755 | | } |
| 0 | 756 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 757 | | } |
| | 758 | | } |
| | 759 | |
|
| | 760 | | // Serialize Request |
| 0 | 761 | | string _requestContent = null; |
| | 762 | | // Set Credentials |
| 0 | 763 | | if (Client.Credentials != null) |
| | 764 | | { |
| 0 | 765 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 766 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 767 | | } |
| | 768 | | // Send Request |
| 0 | 769 | | if (_shouldTrace) |
| | 770 | | { |
| 0 | 771 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 772 | | } |
| 0 | 773 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 774 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 775 | | if (_shouldTrace) |
| | 776 | | { |
| 0 | 777 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 778 | | } |
| 0 | 779 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 780 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 781 | | string _responseContent = null; |
| 0 | 782 | | if ((int)_statusCode != 200) |
| | 783 | | { |
| 0 | 784 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 785 | | try |
| | 786 | | { |
| 0 | 787 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 788 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 789 | | if (_errorBody != null) |
| | 790 | | { |
| 0 | 791 | | ex.Body = _errorBody; |
| | 792 | | } |
| 0 | 793 | | } |
| 0 | 794 | | catch (JsonException) |
| | 795 | | { |
| | 796 | | // Ignore the exception |
| 0 | 797 | | } |
| 0 | 798 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 799 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 800 | | if (_shouldTrace) |
| | 801 | | { |
| 0 | 802 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 803 | | } |
| 0 | 804 | | _httpRequest.Dispose(); |
| 0 | 805 | | if (_httpResponse != null) |
| | 806 | | { |
| 0 | 807 | | _httpResponse.Dispose(); |
| | 808 | | } |
| 0 | 809 | | throw ex; |
| | 810 | | } |
| | 811 | | // Create Result |
| 0 | 812 | | var _result = new HttpOperationResponse<IList<ImageList>>(); |
| 0 | 813 | | _result.Request = _httpRequest; |
| 0 | 814 | | _result.Response = _httpResponse; |
| | 815 | | // Deserialize Response |
| 0 | 816 | | if ((int)_statusCode == 200) |
| | 817 | | { |
| 0 | 818 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 819 | | try |
| | 820 | | { |
| 0 | 821 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<ImageList>>(_responseConte |
| 0 | 822 | | } |
| 0 | 823 | | catch (JsonException ex) |
| | 824 | | { |
| 0 | 825 | | _httpRequest.Dispose(); |
| 0 | 826 | | if (_httpResponse != null) |
| | 827 | | { |
| 0 | 828 | | _httpResponse.Dispose(); |
| | 829 | | } |
| 0 | 830 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 831 | | } |
| | 832 | | } |
| 0 | 833 | | if (_shouldTrace) |
| | 834 | | { |
| 0 | 835 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 836 | | } |
| 0 | 837 | | return _result; |
| 0 | 838 | | } |
| | 839 | |
|
| | 840 | | /// <summary> |
| | 841 | | /// Refreshes the index of the list with list Id equal to list Id passed. |
| | 842 | | /// </summary> |
| | 843 | | /// <param name='listId'> |
| | 844 | | /// List Id of the image list. |
| | 845 | | /// </param> |
| | 846 | | /// <param name='customHeaders'> |
| | 847 | | /// Headers that will be added to request. |
| | 848 | | /// </param> |
| | 849 | | /// <param name='cancellationToken'> |
| | 850 | | /// The cancellation token. |
| | 851 | | /// </param> |
| | 852 | | /// <exception cref="APIErrorException"> |
| | 853 | | /// Thrown when the operation returned an invalid status code |
| | 854 | | /// </exception> |
| | 855 | | /// <exception cref="SerializationException"> |
| | 856 | | /// Thrown when unable to deserialize the response |
| | 857 | | /// </exception> |
| | 858 | | /// <exception cref="ValidationException"> |
| | 859 | | /// Thrown when a required parameter is null |
| | 860 | | /// </exception> |
| | 861 | | /// <exception cref="System.ArgumentNullException"> |
| | 862 | | /// Thrown when a required parameter is null |
| | 863 | | /// </exception> |
| | 864 | | /// <return> |
| | 865 | | /// A response object containing the response body and response headers. |
| | 866 | | /// </return> |
| | 867 | | public async Task<HttpOperationResponse<RefreshIndex>> RefreshIndexMethodWithHttpMessagesAsync(string listId, Di |
| | 868 | | { |
| 0 | 869 | | if (Client.Endpoint == null) |
| | 870 | | { |
| 0 | 871 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 872 | | } |
| 0 | 873 | | if (listId == null) |
| | 874 | | { |
| 0 | 875 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 876 | | } |
| | 877 | | // Tracing |
| 0 | 878 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 879 | | string _invocationId = null; |
| 0 | 880 | | if (_shouldTrace) |
| | 881 | | { |
| 0 | 882 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 883 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 884 | | tracingParameters.Add("listId", listId); |
| 0 | 885 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 886 | | ServiceClientTracing.Enter(_invocationId, this, "RefreshIndexMethod", tracingParameters); |
| | 887 | | } |
| | 888 | | // Construct URL |
| 0 | 889 | | var _baseUrl = Client.BaseUri; |
| 0 | 890 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/imagelists/{listId} |
| 0 | 891 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 892 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| | 893 | | // Create HTTP transport objects |
| 0 | 894 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 895 | | HttpResponseMessage _httpResponse = null; |
| 0 | 896 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 897 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 898 | | // Set Headers |
| | 899 | |
|
| | 900 | |
|
| 0 | 901 | | if (customHeaders != null) |
| | 902 | | { |
| 0 | 903 | | foreach(var _header in customHeaders) |
| | 904 | | { |
| 0 | 905 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 906 | | { |
| 0 | 907 | | _httpRequest.Headers.Remove(_header.Key); |
| | 908 | | } |
| 0 | 909 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 910 | | } |
| | 911 | | } |
| | 912 | |
|
| | 913 | | // Serialize Request |
| 0 | 914 | | string _requestContent = null; |
| | 915 | | // Set Credentials |
| 0 | 916 | | if (Client.Credentials != null) |
| | 917 | | { |
| 0 | 918 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 919 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 920 | | } |
| | 921 | | // Send Request |
| 0 | 922 | | if (_shouldTrace) |
| | 923 | | { |
| 0 | 924 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 925 | | } |
| 0 | 926 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 927 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 928 | | if (_shouldTrace) |
| | 929 | | { |
| 0 | 930 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 931 | | } |
| 0 | 932 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 933 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 934 | | string _responseContent = null; |
| 0 | 935 | | if ((int)_statusCode != 200) |
| | 936 | | { |
| 0 | 937 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 938 | | try |
| | 939 | | { |
| 0 | 940 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 941 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 942 | | if (_errorBody != null) |
| | 943 | | { |
| 0 | 944 | | ex.Body = _errorBody; |
| | 945 | | } |
| 0 | 946 | | } |
| 0 | 947 | | catch (JsonException) |
| | 948 | | { |
| | 949 | | // Ignore the exception |
| 0 | 950 | | } |
| 0 | 951 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 952 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 953 | | if (_shouldTrace) |
| | 954 | | { |
| 0 | 955 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 956 | | } |
| 0 | 957 | | _httpRequest.Dispose(); |
| 0 | 958 | | if (_httpResponse != null) |
| | 959 | | { |
| 0 | 960 | | _httpResponse.Dispose(); |
| | 961 | | } |
| 0 | 962 | | throw ex; |
| | 963 | | } |
| | 964 | | // Create Result |
| 0 | 965 | | var _result = new HttpOperationResponse<RefreshIndex>(); |
| 0 | 966 | | _result.Request = _httpRequest; |
| 0 | 967 | | _result.Response = _httpResponse; |
| | 968 | | // Deserialize Response |
| 0 | 969 | | if ((int)_statusCode == 200) |
| | 970 | | { |
| 0 | 971 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 972 | | try |
| | 973 | | { |
| 0 | 974 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<RefreshIndex>(_responseContent, |
| 0 | 975 | | } |
| 0 | 976 | | catch (JsonException ex) |
| | 977 | | { |
| 0 | 978 | | _httpRequest.Dispose(); |
| 0 | 979 | | if (_httpResponse != null) |
| | 980 | | { |
| 0 | 981 | | _httpResponse.Dispose(); |
| | 982 | | } |
| 0 | 983 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 984 | | } |
| | 985 | | } |
| 0 | 986 | | if (_shouldTrace) |
| | 987 | | { |
| 0 | 988 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 989 | | } |
| 0 | 990 | | return _result; |
| 0 | 991 | | } |
| | 992 | |
|
| | 993 | | } |
| | 994 | | } |