| | 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 | | /// ListManagementTerm operations. |
| | 23 | | /// </summary> |
| | 24 | | public partial class ListManagementTerm : IServiceOperations<ContentModeratorClient>, IListManagementTerm |
| | 25 | | { |
| | 26 | | /// <summary> |
| | 27 | | /// Initializes a new instance of the ListManagementTerm 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 ListManagementTerm(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 | | /// Add a term to the term 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='term'> |
| | 56 | | /// Term to be deleted |
| | 57 | | /// </param> |
| | 58 | | /// <param name='language'> |
| | 59 | | /// Language of the terms. |
| | 60 | | /// </param> |
| | 61 | | /// <param name='customHeaders'> |
| | 62 | | /// Headers that will be added to request. |
| | 63 | | /// </param> |
| | 64 | | /// <param name='cancellationToken'> |
| | 65 | | /// The cancellation token. |
| | 66 | | /// </param> |
| | 67 | | /// <exception cref="APIErrorException"> |
| | 68 | | /// Thrown when the operation returned an invalid status code |
| | 69 | | /// </exception> |
| | 70 | | /// <exception cref="SerializationException"> |
| | 71 | | /// Thrown when unable to deserialize the response |
| | 72 | | /// </exception> |
| | 73 | | /// <exception cref="ValidationException"> |
| | 74 | | /// Thrown when a required parameter is null |
| | 75 | | /// </exception> |
| | 76 | | /// <exception cref="System.ArgumentNullException"> |
| | 77 | | /// Thrown when a required parameter is null |
| | 78 | | /// </exception> |
| | 79 | | /// <return> |
| | 80 | | /// A response object containing the response body and response headers. |
| | 81 | | /// </return> |
| | 82 | | public async Task<HttpOperationResponse<object>> AddTermWithHttpMessagesAsync(string listId, string term, string |
| | 83 | | { |
| 0 | 84 | | if (Client.Endpoint == null) |
| | 85 | | { |
| 0 | 86 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 87 | | } |
| 0 | 88 | | if (listId == null) |
| | 89 | | { |
| 0 | 90 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 91 | | } |
| 0 | 92 | | if (term == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "term"); |
| | 95 | | } |
| 0 | 96 | | if (language == null) |
| | 97 | | { |
| 0 | 98 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 99 | | } |
| | 100 | | // Tracing |
| 0 | 101 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 102 | | string _invocationId = null; |
| 0 | 103 | | if (_shouldTrace) |
| | 104 | | { |
| 0 | 105 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 106 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 107 | | tracingParameters.Add("listId", listId); |
| 0 | 108 | | tracingParameters.Add("term", term); |
| 0 | 109 | | tracingParameters.Add("language", language); |
| 0 | 110 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 111 | | ServiceClientTracing.Enter(_invocationId, this, "AddTerm", tracingParameters); |
| | 112 | | } |
| | 113 | | // Construct URL |
| 0 | 114 | | var _baseUrl = Client.BaseUri; |
| 0 | 115 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/termlists/{listId}/ |
| 0 | 116 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 117 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| 0 | 118 | | _url = _url.Replace("{term}", System.Uri.EscapeDataString(term)); |
| 0 | 119 | | List<string> _queryParameters = new List<string>(); |
| 0 | 120 | | if (language != null) |
| | 121 | | { |
| 0 | 122 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 123 | | } |
| 0 | 124 | | if (_queryParameters.Count > 0) |
| | 125 | | { |
| 0 | 126 | | _url += "?" + string.Join("&", _queryParameters); |
| | 127 | | } |
| | 128 | | // Create HTTP transport objects |
| 0 | 129 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 130 | | HttpResponseMessage _httpResponse = null; |
| 0 | 131 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 132 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 133 | | // Set Headers |
| | 134 | |
|
| | 135 | |
|
| 0 | 136 | | if (customHeaders != null) |
| | 137 | | { |
| 0 | 138 | | foreach(var _header in customHeaders) |
| | 139 | | { |
| 0 | 140 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 141 | | { |
| 0 | 142 | | _httpRequest.Headers.Remove(_header.Key); |
| | 143 | | } |
| 0 | 144 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 145 | | } |
| | 146 | | } |
| | 147 | |
|
| | 148 | | // Serialize Request |
| 0 | 149 | | string _requestContent = null; |
| | 150 | | // Set Credentials |
| 0 | 151 | | if (Client.Credentials != null) |
| | 152 | | { |
| 0 | 153 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 154 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 155 | | } |
| | 156 | | // Send Request |
| 0 | 157 | | if (_shouldTrace) |
| | 158 | | { |
| 0 | 159 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 160 | | } |
| 0 | 161 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 162 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 163 | | if (_shouldTrace) |
| | 164 | | { |
| 0 | 165 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 166 | | } |
| 0 | 167 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 168 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 169 | | string _responseContent = null; |
| 0 | 170 | | if ((int)_statusCode != 201) |
| | 171 | | { |
| 0 | 172 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 173 | | try |
| | 174 | | { |
| 0 | 175 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 176 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 177 | | if (_errorBody != null) |
| | 178 | | { |
| 0 | 179 | | ex.Body = _errorBody; |
| | 180 | | } |
| 0 | 181 | | } |
| 0 | 182 | | catch (JsonException) |
| | 183 | | { |
| | 184 | | // Ignore the exception |
| 0 | 185 | | } |
| 0 | 186 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 187 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 188 | | if (_shouldTrace) |
| | 189 | | { |
| 0 | 190 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 191 | | } |
| 0 | 192 | | _httpRequest.Dispose(); |
| 0 | 193 | | if (_httpResponse != null) |
| | 194 | | { |
| 0 | 195 | | _httpResponse.Dispose(); |
| | 196 | | } |
| 0 | 197 | | throw ex; |
| | 198 | | } |
| | 199 | | // Create Result |
| 0 | 200 | | var _result = new HttpOperationResponse<object>(); |
| 0 | 201 | | _result.Request = _httpRequest; |
| 0 | 202 | | _result.Response = _httpResponse; |
| | 203 | | // Deserialize Response |
| 0 | 204 | | if ((int)_statusCode == 201) |
| | 205 | | { |
| 0 | 206 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 207 | | try |
| | 208 | | { |
| 0 | 209 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<object>(_responseContent, Client |
| 0 | 210 | | } |
| 0 | 211 | | catch (JsonException ex) |
| | 212 | | { |
| 0 | 213 | | _httpRequest.Dispose(); |
| 0 | 214 | | if (_httpResponse != null) |
| | 215 | | { |
| 0 | 216 | | _httpResponse.Dispose(); |
| | 217 | | } |
| 0 | 218 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 219 | | } |
| | 220 | | } |
| 0 | 221 | | if (_shouldTrace) |
| | 222 | | { |
| 0 | 223 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 224 | | } |
| 0 | 225 | | return _result; |
| 0 | 226 | | } |
| | 227 | |
|
| | 228 | | /// <summary> |
| | 229 | | /// Deletes a term from the list with list Id equal to the list Id passed. |
| | 230 | | /// </summary> |
| | 231 | | /// <param name='listId'> |
| | 232 | | /// List Id of the image list. |
| | 233 | | /// </param> |
| | 234 | | /// <param name='term'> |
| | 235 | | /// Term to be deleted |
| | 236 | | /// </param> |
| | 237 | | /// <param name='language'> |
| | 238 | | /// Language of the terms. |
| | 239 | | /// </param> |
| | 240 | | /// <param name='customHeaders'> |
| | 241 | | /// Headers that will be added to request. |
| | 242 | | /// </param> |
| | 243 | | /// <param name='cancellationToken'> |
| | 244 | | /// The cancellation token. |
| | 245 | | /// </param> |
| | 246 | | /// <exception cref="APIErrorException"> |
| | 247 | | /// Thrown when the operation returned an invalid status code |
| | 248 | | /// </exception> |
| | 249 | | /// <exception cref="SerializationException"> |
| | 250 | | /// Thrown when unable to deserialize the response |
| | 251 | | /// </exception> |
| | 252 | | /// <exception cref="ValidationException"> |
| | 253 | | /// Thrown when a required parameter is null |
| | 254 | | /// </exception> |
| | 255 | | /// <exception cref="System.ArgumentNullException"> |
| | 256 | | /// Thrown when a required parameter is null |
| | 257 | | /// </exception> |
| | 258 | | /// <return> |
| | 259 | | /// A response object containing the response body and response headers. |
| | 260 | | /// </return> |
| | 261 | | public async Task<HttpOperationResponse<string>> DeleteTermWithHttpMessagesAsync(string listId, string term, str |
| | 262 | | { |
| 0 | 263 | | if (Client.Endpoint == null) |
| | 264 | | { |
| 0 | 265 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 266 | | } |
| 0 | 267 | | if (listId == null) |
| | 268 | | { |
| 0 | 269 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 270 | | } |
| 0 | 271 | | if (term == null) |
| | 272 | | { |
| 0 | 273 | | throw new ValidationException(ValidationRules.CannotBeNull, "term"); |
| | 274 | | } |
| 0 | 275 | | if (language == null) |
| | 276 | | { |
| 0 | 277 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 278 | | } |
| | 279 | | // Tracing |
| 0 | 280 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 281 | | string _invocationId = null; |
| 0 | 282 | | if (_shouldTrace) |
| | 283 | | { |
| 0 | 284 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 285 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 286 | | tracingParameters.Add("listId", listId); |
| 0 | 287 | | tracingParameters.Add("term", term); |
| 0 | 288 | | tracingParameters.Add("language", language); |
| 0 | 289 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 290 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteTerm", tracingParameters); |
| | 291 | | } |
| | 292 | | // Construct URL |
| 0 | 293 | | var _baseUrl = Client.BaseUri; |
| 0 | 294 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/termlists/{listId}/ |
| 0 | 295 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 296 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| 0 | 297 | | _url = _url.Replace("{term}", System.Uri.EscapeDataString(term)); |
| 0 | 298 | | List<string> _queryParameters = new List<string>(); |
| 0 | 299 | | if (language != null) |
| | 300 | | { |
| 0 | 301 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 302 | | } |
| 0 | 303 | | if (_queryParameters.Count > 0) |
| | 304 | | { |
| 0 | 305 | | _url += "?" + string.Join("&", _queryParameters); |
| | 306 | | } |
| | 307 | | // Create HTTP transport objects |
| 0 | 308 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 309 | | HttpResponseMessage _httpResponse = null; |
| 0 | 310 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 311 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 312 | | // Set Headers |
| | 313 | |
|
| | 314 | |
|
| 0 | 315 | | if (customHeaders != null) |
| | 316 | | { |
| 0 | 317 | | foreach(var _header in customHeaders) |
| | 318 | | { |
| 0 | 319 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 320 | | { |
| 0 | 321 | | _httpRequest.Headers.Remove(_header.Key); |
| | 322 | | } |
| 0 | 323 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 324 | | } |
| | 325 | | } |
| | 326 | |
|
| | 327 | | // Serialize Request |
| 0 | 328 | | string _requestContent = null; |
| | 329 | | // Set Credentials |
| 0 | 330 | | if (Client.Credentials != null) |
| | 331 | | { |
| 0 | 332 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 333 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 334 | | } |
| | 335 | | // Send Request |
| 0 | 336 | | if (_shouldTrace) |
| | 337 | | { |
| 0 | 338 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 339 | | } |
| 0 | 340 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 341 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 342 | | if (_shouldTrace) |
| | 343 | | { |
| 0 | 344 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 345 | | } |
| 0 | 346 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 347 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 348 | | string _responseContent = null; |
| 0 | 349 | | if ((int)_statusCode != 204) |
| | 350 | | { |
| 0 | 351 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 352 | | try |
| | 353 | | { |
| 0 | 354 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 355 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 356 | | if (_errorBody != null) |
| | 357 | | { |
| 0 | 358 | | ex.Body = _errorBody; |
| | 359 | | } |
| 0 | 360 | | } |
| 0 | 361 | | catch (JsonException) |
| | 362 | | { |
| | 363 | | // Ignore the exception |
| 0 | 364 | | } |
| 0 | 365 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 366 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 367 | | if (_shouldTrace) |
| | 368 | | { |
| 0 | 369 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 370 | | } |
| 0 | 371 | | _httpRequest.Dispose(); |
| 0 | 372 | | if (_httpResponse != null) |
| | 373 | | { |
| 0 | 374 | | _httpResponse.Dispose(); |
| | 375 | | } |
| 0 | 376 | | throw ex; |
| | 377 | | } |
| | 378 | | // Create Result |
| 0 | 379 | | var _result = new HttpOperationResponse<string>(); |
| 0 | 380 | | _result.Request = _httpRequest; |
| 0 | 381 | | _result.Response = _httpResponse; |
| | 382 | | // Deserialize Response |
| 0 | 383 | | if ((int)_statusCode == 204) |
| | 384 | | { |
| 0 | 385 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 386 | | try |
| | 387 | | { |
| 0 | 388 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 0 | 389 | | } |
| 0 | 390 | | catch (JsonException ex) |
| | 391 | | { |
| 0 | 392 | | _httpRequest.Dispose(); |
| 0 | 393 | | if (_httpResponse != null) |
| | 394 | | { |
| 0 | 395 | | _httpResponse.Dispose(); |
| | 396 | | } |
| 0 | 397 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 398 | | } |
| | 399 | | } |
| 0 | 400 | | if (_shouldTrace) |
| | 401 | | { |
| 0 | 402 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 403 | | } |
| 0 | 404 | | return _result; |
| 0 | 405 | | } |
| | 406 | |
|
| | 407 | | /// <summary> |
| | 408 | | /// Gets all terms from the list with list Id equal to the list Id passed. |
| | 409 | | /// </summary> |
| | 410 | | /// <param name='listId'> |
| | 411 | | /// List Id of the image list. |
| | 412 | | /// </param> |
| | 413 | | /// <param name='language'> |
| | 414 | | /// Language of the terms. |
| | 415 | | /// </param> |
| | 416 | | /// <param name='offset'> |
| | 417 | | /// The pagination start index. |
| | 418 | | /// </param> |
| | 419 | | /// <param name='limit'> |
| | 420 | | /// The max limit. |
| | 421 | | /// </param> |
| | 422 | | /// <param name='customHeaders'> |
| | 423 | | /// Headers that will be added to request. |
| | 424 | | /// </param> |
| | 425 | | /// <param name='cancellationToken'> |
| | 426 | | /// The cancellation token. |
| | 427 | | /// </param> |
| | 428 | | /// <exception cref="APIErrorException"> |
| | 429 | | /// Thrown when the operation returned an invalid status code |
| | 430 | | /// </exception> |
| | 431 | | /// <exception cref="SerializationException"> |
| | 432 | | /// Thrown when unable to deserialize the response |
| | 433 | | /// </exception> |
| | 434 | | /// <exception cref="ValidationException"> |
| | 435 | | /// Thrown when a required parameter is null |
| | 436 | | /// </exception> |
| | 437 | | /// <exception cref="System.ArgumentNullException"> |
| | 438 | | /// Thrown when a required parameter is null |
| | 439 | | /// </exception> |
| | 440 | | /// <return> |
| | 441 | | /// A response object containing the response body and response headers. |
| | 442 | | /// </return> |
| | 443 | | public async Task<HttpOperationResponse<Terms>> GetAllTermsWithHttpMessagesAsync(string listId, string language, |
| | 444 | | { |
| 0 | 445 | | if (Client.Endpoint == null) |
| | 446 | | { |
| 0 | 447 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 448 | | } |
| 0 | 449 | | if (listId == null) |
| | 450 | | { |
| 0 | 451 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 452 | | } |
| 0 | 453 | | if (language == null) |
| | 454 | | { |
| 0 | 455 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 456 | | } |
| | 457 | | // Tracing |
| 0 | 458 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 459 | | string _invocationId = null; |
| 0 | 460 | | if (_shouldTrace) |
| | 461 | | { |
| 0 | 462 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 463 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 464 | | tracingParameters.Add("listId", listId); |
| 0 | 465 | | tracingParameters.Add("language", language); |
| 0 | 466 | | tracingParameters.Add("offset", offset); |
| 0 | 467 | | tracingParameters.Add("limit", limit); |
| 0 | 468 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 469 | | ServiceClientTracing.Enter(_invocationId, this, "GetAllTerms", tracingParameters); |
| | 470 | | } |
| | 471 | | // Construct URL |
| 0 | 472 | | var _baseUrl = Client.BaseUri; |
| 0 | 473 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/termlists/{listId}/ |
| 0 | 474 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 475 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| 0 | 476 | | List<string> _queryParameters = new List<string>(); |
| 0 | 477 | | if (language != null) |
| | 478 | | { |
| 0 | 479 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 480 | | } |
| 0 | 481 | | if (offset != null) |
| | 482 | | { |
| 0 | 483 | | _queryParameters.Add(string.Format("offset={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJson |
| | 484 | | } |
| 0 | 485 | | if (limit != null) |
| | 486 | | { |
| 0 | 487 | | _queryParameters.Add(string.Format("limit={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonC |
| | 488 | | } |
| 0 | 489 | | if (_queryParameters.Count > 0) |
| | 490 | | { |
| 0 | 491 | | _url += "?" + 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("GET"); |
| 0 | 497 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 498 | | // Set Headers |
| | 499 | |
|
| | 500 | |
|
| 0 | 501 | | if (customHeaders != null) |
| | 502 | | { |
| 0 | 503 | | foreach(var _header in customHeaders) |
| | 504 | | { |
| 0 | 505 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 506 | | { |
| 0 | 507 | | _httpRequest.Headers.Remove(_header.Key); |
| | 508 | | } |
| 0 | 509 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 510 | | } |
| | 511 | | } |
| | 512 | |
|
| | 513 | | // Serialize Request |
| 0 | 514 | | string _requestContent = null; |
| | 515 | | // Set Credentials |
| 0 | 516 | | if (Client.Credentials != null) |
| | 517 | | { |
| 0 | 518 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 519 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 520 | | } |
| | 521 | | // Send Request |
| 0 | 522 | | if (_shouldTrace) |
| | 523 | | { |
| 0 | 524 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 525 | | } |
| 0 | 526 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 527 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 528 | | if (_shouldTrace) |
| | 529 | | { |
| 0 | 530 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 531 | | } |
| 0 | 532 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 533 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 534 | | string _responseContent = null; |
| 0 | 535 | | if ((int)_statusCode != 200) |
| | 536 | | { |
| 0 | 537 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 538 | | try |
| | 539 | | { |
| 0 | 540 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 541 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 542 | | if (_errorBody != null) |
| | 543 | | { |
| 0 | 544 | | ex.Body = _errorBody; |
| | 545 | | } |
| 0 | 546 | | } |
| 0 | 547 | | catch (JsonException) |
| | 548 | | { |
| | 549 | | // Ignore the exception |
| 0 | 550 | | } |
| 0 | 551 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 552 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 553 | | if (_shouldTrace) |
| | 554 | | { |
| 0 | 555 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 556 | | } |
| 0 | 557 | | _httpRequest.Dispose(); |
| 0 | 558 | | if (_httpResponse != null) |
| | 559 | | { |
| 0 | 560 | | _httpResponse.Dispose(); |
| | 561 | | } |
| 0 | 562 | | throw ex; |
| | 563 | | } |
| | 564 | | // Create Result |
| 0 | 565 | | var _result = new HttpOperationResponse<Terms>(); |
| 0 | 566 | | _result.Request = _httpRequest; |
| 0 | 567 | | _result.Response = _httpResponse; |
| | 568 | | // Deserialize Response |
| 0 | 569 | | if ((int)_statusCode == 200) |
| | 570 | | { |
| 0 | 571 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 572 | | try |
| | 573 | | { |
| 0 | 574 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Terms>(_responseContent, Client. |
| 0 | 575 | | } |
| 0 | 576 | | catch (JsonException ex) |
| | 577 | | { |
| 0 | 578 | | _httpRequest.Dispose(); |
| 0 | 579 | | if (_httpResponse != null) |
| | 580 | | { |
| 0 | 581 | | _httpResponse.Dispose(); |
| | 582 | | } |
| 0 | 583 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 584 | | } |
| | 585 | | } |
| 0 | 586 | | if (_shouldTrace) |
| | 587 | | { |
| 0 | 588 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 589 | | } |
| 0 | 590 | | return _result; |
| 0 | 591 | | } |
| | 592 | |
|
| | 593 | | /// <summary> |
| | 594 | | /// Deletes all terms from the list with list Id equal to the list Id passed. |
| | 595 | | /// </summary> |
| | 596 | | /// <param name='listId'> |
| | 597 | | /// List Id of the image list. |
| | 598 | | /// </param> |
| | 599 | | /// <param name='language'> |
| | 600 | | /// Language of the terms. |
| | 601 | | /// </param> |
| | 602 | | /// <param name='customHeaders'> |
| | 603 | | /// Headers that will be added to request. |
| | 604 | | /// </param> |
| | 605 | | /// <param name='cancellationToken'> |
| | 606 | | /// The cancellation token. |
| | 607 | | /// </param> |
| | 608 | | /// <exception cref="APIErrorException"> |
| | 609 | | /// Thrown when the operation returned an invalid status code |
| | 610 | | /// </exception> |
| | 611 | | /// <exception cref="SerializationException"> |
| | 612 | | /// Thrown when unable to deserialize the response |
| | 613 | | /// </exception> |
| | 614 | | /// <exception cref="ValidationException"> |
| | 615 | | /// Thrown when a required parameter is null |
| | 616 | | /// </exception> |
| | 617 | | /// <exception cref="System.ArgumentNullException"> |
| | 618 | | /// Thrown when a required parameter is null |
| | 619 | | /// </exception> |
| | 620 | | /// <return> |
| | 621 | | /// A response object containing the response body and response headers. |
| | 622 | | /// </return> |
| | 623 | | public async Task<HttpOperationResponse<string>> DeleteAllTermsWithHttpMessagesAsync(string listId, string langu |
| | 624 | | { |
| 0 | 625 | | if (Client.Endpoint == null) |
| | 626 | | { |
| 0 | 627 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 628 | | } |
| 0 | 629 | | if (listId == null) |
| | 630 | | { |
| 0 | 631 | | throw new ValidationException(ValidationRules.CannotBeNull, "listId"); |
| | 632 | | } |
| 0 | 633 | | if (language == null) |
| | 634 | | { |
| 0 | 635 | | throw new ValidationException(ValidationRules.CannotBeNull, "language"); |
| | 636 | | } |
| | 637 | | // Tracing |
| 0 | 638 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 639 | | string _invocationId = null; |
| 0 | 640 | | if (_shouldTrace) |
| | 641 | | { |
| 0 | 642 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 643 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 644 | | tracingParameters.Add("listId", listId); |
| 0 | 645 | | tracingParameters.Add("language", language); |
| 0 | 646 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 647 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteAllTerms", tracingParameters); |
| | 648 | | } |
| | 649 | | // Construct URL |
| 0 | 650 | | var _baseUrl = Client.BaseUri; |
| 0 | 651 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "contentmoderator/lists/v1.0/termlists/{listId}/ |
| 0 | 652 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 653 | | _url = _url.Replace("{listId}", System.Uri.EscapeDataString(listId)); |
| 0 | 654 | | List<string> _queryParameters = new List<string>(); |
| 0 | 655 | | if (language != null) |
| | 656 | | { |
| 0 | 657 | | _queryParameters.Add(string.Format("language={0}", System.Uri.EscapeDataString(language))); |
| | 658 | | } |
| 0 | 659 | | if (_queryParameters.Count > 0) |
| | 660 | | { |
| 0 | 661 | | _url += "?" + string.Join("&", _queryParameters); |
| | 662 | | } |
| | 663 | | // Create HTTP transport objects |
| 0 | 664 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 665 | | HttpResponseMessage _httpResponse = null; |
| 0 | 666 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 667 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 668 | | // Set Headers |
| | 669 | |
|
| | 670 | |
|
| 0 | 671 | | if (customHeaders != null) |
| | 672 | | { |
| 0 | 673 | | foreach(var _header in customHeaders) |
| | 674 | | { |
| 0 | 675 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 676 | | { |
| 0 | 677 | | _httpRequest.Headers.Remove(_header.Key); |
| | 678 | | } |
| 0 | 679 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 680 | | } |
| | 681 | | } |
| | 682 | |
|
| | 683 | | // Serialize Request |
| 0 | 684 | | string _requestContent = null; |
| | 685 | | // Set Credentials |
| 0 | 686 | | if (Client.Credentials != null) |
| | 687 | | { |
| 0 | 688 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 689 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 690 | | } |
| | 691 | | // Send Request |
| 0 | 692 | | if (_shouldTrace) |
| | 693 | | { |
| 0 | 694 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 695 | | } |
| 0 | 696 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 697 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 698 | | if (_shouldTrace) |
| | 699 | | { |
| 0 | 700 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 701 | | } |
| 0 | 702 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 703 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 704 | | string _responseContent = null; |
| 0 | 705 | | if ((int)_statusCode != 204) |
| | 706 | | { |
| 0 | 707 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 708 | | try |
| | 709 | | { |
| 0 | 710 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 711 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 712 | | if (_errorBody != null) |
| | 713 | | { |
| 0 | 714 | | ex.Body = _errorBody; |
| | 715 | | } |
| 0 | 716 | | } |
| 0 | 717 | | catch (JsonException) |
| | 718 | | { |
| | 719 | | // Ignore the exception |
| 0 | 720 | | } |
| 0 | 721 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 722 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 723 | | if (_shouldTrace) |
| | 724 | | { |
| 0 | 725 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 726 | | } |
| 0 | 727 | | _httpRequest.Dispose(); |
| 0 | 728 | | if (_httpResponse != null) |
| | 729 | | { |
| 0 | 730 | | _httpResponse.Dispose(); |
| | 731 | | } |
| 0 | 732 | | throw ex; |
| | 733 | | } |
| | 734 | | // Create Result |
| 0 | 735 | | var _result = new HttpOperationResponse<string>(); |
| 0 | 736 | | _result.Request = _httpRequest; |
| 0 | 737 | | _result.Response = _httpResponse; |
| | 738 | | // Deserialize Response |
| 0 | 739 | | if ((int)_statusCode == 204) |
| | 740 | | { |
| 0 | 741 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 742 | | try |
| | 743 | | { |
| 0 | 744 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<string>(_responseContent, Client |
| 0 | 745 | | } |
| 0 | 746 | | catch (JsonException ex) |
| | 747 | | { |
| 0 | 748 | | _httpRequest.Dispose(); |
| 0 | 749 | | if (_httpResponse != null) |
| | 750 | | { |
| 0 | 751 | | _httpResponse.Dispose(); |
| | 752 | | } |
| 0 | 753 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 754 | | } |
| | 755 | | } |
| 0 | 756 | | if (_shouldTrace) |
| | 757 | | { |
| 0 | 758 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 759 | | } |
| 0 | 760 | | return _result; |
| 0 | 761 | | } |
| | 762 | |
|
| | 763 | | } |
| | 764 | | } |