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