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