| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.CognitiveServices.Personalizer |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Models; |
| | 15 | | using Newtonsoft.Json; |
| | 16 | | using System.Collections; |
| | 17 | | using System.Collections.Generic; |
| | 18 | | using System.IO; |
| | 19 | | using System.Linq; |
| | 20 | | using System.Net; |
| | 21 | | using System.Net.Http; |
| | 22 | | using System.Threading; |
| | 23 | | using System.Threading.Tasks; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Model operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Model : IServiceOperations<PersonalizerClient>, IModel |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Model class. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name='client'> |
| | 34 | | /// Reference to the service client. |
| | 35 | | /// </param> |
| | 36 | | /// <exception cref="System.ArgumentNullException"> |
| | 37 | | /// Thrown when a required parameter is null |
| | 38 | | /// </exception> |
| 34 | 39 | | public Model(PersonalizerClient client) |
| | 40 | | { |
| 34 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 34 | 45 | | Client = client; |
| 34 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the PersonalizerClient |
| | 50 | | /// </summary> |
| 72 | 51 | | public PersonalizerClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Get Model. |
| | 55 | | /// </summary> |
| | 56 | | /// <remarks> |
| | 57 | | /// Get the model file generated by Personalizer service. |
| | 58 | | /// </remarks> |
| | 59 | | /// <param name='customHeaders'> |
| | 60 | | /// Headers that will be added to request. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='cancellationToken'> |
| | 63 | | /// The cancellation token. |
| | 64 | | /// </param> |
| | 65 | | /// <exception cref="HttpOperationException"> |
| | 66 | | /// Thrown when the operation returned an invalid status code |
| | 67 | | /// </exception> |
| | 68 | | /// <exception cref="SerializationException"> |
| | 69 | | /// Thrown when unable to deserialize the response |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="ValidationException"> |
| | 72 | | /// Thrown when a required parameter is null |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="System.ArgumentNullException"> |
| | 75 | | /// Thrown when a required parameter is null |
| | 76 | | /// </exception> |
| | 77 | | /// <return> |
| | 78 | | /// A response object containing the response body and response headers. |
| | 79 | | /// </return> |
| | 80 | | public async Task<HttpOperationResponse<Stream>> GetWithHttpMessagesAsync(Dictionary<string, List<string>> custo |
| | 81 | | { |
| 2 | 82 | | if (Client.Endpoint == null) |
| | 83 | | { |
| 0 | 84 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 85 | | } |
| | 86 | | // Tracing |
| 2 | 87 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 88 | | string _invocationId = null; |
| 2 | 89 | | if (_shouldTrace) |
| | 90 | | { |
| 0 | 91 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 92 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 93 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 94 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 95 | | } |
| | 96 | | // Construct URL |
| 2 | 97 | | var _baseUrl = Client.BaseUri; |
| 2 | 98 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "model"; |
| 2 | 99 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 100 | | // Create HTTP transport objects |
| 2 | 101 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 102 | | HttpResponseMessage _httpResponse = null; |
| 2 | 103 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 104 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 105 | | // Set Headers |
| | 106 | |
|
| | 107 | |
|
| 2 | 108 | | if (customHeaders != null) |
| | 109 | | { |
| 0 | 110 | | foreach(var _header in customHeaders) |
| | 111 | | { |
| 0 | 112 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 113 | | { |
| 0 | 114 | | _httpRequest.Headers.Remove(_header.Key); |
| | 115 | | } |
| 0 | 116 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 117 | | } |
| | 118 | | } |
| | 119 | |
|
| | 120 | | // Serialize Request |
| 2 | 121 | | string _requestContent = null; |
| | 122 | | // Set Credentials |
| 2 | 123 | | if (Client.Credentials != null) |
| | 124 | | { |
| 2 | 125 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 126 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 127 | | } |
| | 128 | | // Send Request |
| 2 | 129 | | if (_shouldTrace) |
| | 130 | | { |
| 0 | 131 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 132 | | } |
| 2 | 133 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 134 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.Respons |
| 2 | 135 | | if (_shouldTrace) |
| | 136 | | { |
| 0 | 137 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 138 | | } |
| 2 | 139 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 140 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 141 | | string _responseContent = null; |
| 2 | 142 | | if ((int)_statusCode != 200) |
| | 143 | | { |
| 0 | 144 | | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st |
| 0 | 145 | | if (_httpResponse.Content != null) { |
| 0 | 146 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 147 | | } |
| | 148 | | else { |
| 0 | 149 | | _responseContent = string.Empty; |
| | 150 | | } |
| 0 | 151 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 152 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 153 | | if (_shouldTrace) |
| | 154 | | { |
| 0 | 155 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 156 | | } |
| 0 | 157 | | _httpRequest.Dispose(); |
| 0 | 158 | | if (_httpResponse != null) |
| | 159 | | { |
| 0 | 160 | | _httpResponse.Dispose(); |
| | 161 | | } |
| 0 | 162 | | throw ex; |
| | 163 | | } |
| | 164 | | // Create Result |
| 2 | 165 | | var _result = new HttpOperationResponse<Stream>(); |
| 2 | 166 | | _result.Request = _httpRequest; |
| 2 | 167 | | _result.Response = _httpResponse; |
| | 168 | | // Deserialize Response |
| 2 | 169 | | if ((int)_statusCode == 200) |
| | 170 | | { |
| 2 | 171 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 172 | | } |
| 2 | 173 | | if (_shouldTrace) |
| | 174 | | { |
| 0 | 175 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 176 | | } |
| 2 | 177 | | return _result; |
| 2 | 178 | | } |
| | 179 | |
|
| | 180 | | /// <summary> |
| | 181 | | /// Reset Model. |
| | 182 | | /// </summary> |
| | 183 | | /// <remarks> |
| | 184 | | /// Resets the model file generated by Personalizer service. |
| | 185 | | /// </remarks> |
| | 186 | | /// <param name='customHeaders'> |
| | 187 | | /// Headers that will be added to request. |
| | 188 | | /// </param> |
| | 189 | | /// <param name='cancellationToken'> |
| | 190 | | /// The cancellation token. |
| | 191 | | /// </param> |
| | 192 | | /// <exception cref="ErrorResponseException"> |
| | 193 | | /// Thrown when the operation returned an invalid status code |
| | 194 | | /// </exception> |
| | 195 | | /// <exception cref="ValidationException"> |
| | 196 | | /// Thrown when a required parameter is null |
| | 197 | | /// </exception> |
| | 198 | | /// <exception cref="System.ArgumentNullException"> |
| | 199 | | /// Thrown when a required parameter is null |
| | 200 | | /// </exception> |
| | 201 | | /// <return> |
| | 202 | | /// A response object containing the response body and response headers. |
| | 203 | | /// </return> |
| | 204 | | public async Task<HttpOperationResponse> ResetWithHttpMessagesAsync(Dictionary<string, List<string>> customHeade |
| | 205 | | { |
| 2 | 206 | | if (Client.Endpoint == null) |
| | 207 | | { |
| 0 | 208 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 209 | | } |
| | 210 | | // Tracing |
| 2 | 211 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 212 | | string _invocationId = null; |
| 2 | 213 | | if (_shouldTrace) |
| | 214 | | { |
| 0 | 215 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 216 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 217 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 218 | | ServiceClientTracing.Enter(_invocationId, this, "Reset", tracingParameters); |
| | 219 | | } |
| | 220 | | // Construct URL |
| 2 | 221 | | var _baseUrl = Client.BaseUri; |
| 2 | 222 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "model"; |
| 2 | 223 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 224 | | // Create HTTP transport objects |
| 2 | 225 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 226 | | HttpResponseMessage _httpResponse = null; |
| 2 | 227 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 228 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 229 | | // Set Headers |
| | 230 | |
|
| | 231 | |
|
| 2 | 232 | | if (customHeaders != null) |
| | 233 | | { |
| 0 | 234 | | foreach(var _header in customHeaders) |
| | 235 | | { |
| 0 | 236 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 237 | | { |
| 0 | 238 | | _httpRequest.Headers.Remove(_header.Key); |
| | 239 | | } |
| 0 | 240 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 241 | | } |
| | 242 | | } |
| | 243 | |
|
| | 244 | | // Serialize Request |
| 2 | 245 | | string _requestContent = null; |
| | 246 | | // Set Credentials |
| 2 | 247 | | if (Client.Credentials != null) |
| | 248 | | { |
| 2 | 249 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 250 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 251 | | } |
| | 252 | | // Send Request |
| 2 | 253 | | if (_shouldTrace) |
| | 254 | | { |
| 0 | 255 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 256 | | } |
| 2 | 257 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 258 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 259 | | if (_shouldTrace) |
| | 260 | | { |
| 0 | 261 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 262 | | } |
| 2 | 263 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 264 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 265 | | string _responseContent = null; |
| 2 | 266 | | if ((int)_statusCode != 204) |
| | 267 | | { |
| 0 | 268 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 269 | | try |
| | 270 | | { |
| 0 | 271 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 272 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 273 | | if (_errorBody != null) |
| | 274 | | { |
| 0 | 275 | | ex.Body = _errorBody; |
| | 276 | | } |
| 0 | 277 | | } |
| 0 | 278 | | catch (JsonException) |
| | 279 | | { |
| | 280 | | // Ignore the exception |
| 0 | 281 | | } |
| 0 | 282 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 283 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 284 | | if (_shouldTrace) |
| | 285 | | { |
| 0 | 286 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 287 | | } |
| 0 | 288 | | _httpRequest.Dispose(); |
| 0 | 289 | | if (_httpResponse != null) |
| | 290 | | { |
| 0 | 291 | | _httpResponse.Dispose(); |
| | 292 | | } |
| 0 | 293 | | throw ex; |
| | 294 | | } |
| | 295 | | // Create Result |
| 2 | 296 | | var _result = new HttpOperationResponse(); |
| 2 | 297 | | _result.Request = _httpRequest; |
| 2 | 298 | | _result.Response = _httpResponse; |
| 2 | 299 | | if (_shouldTrace) |
| | 300 | | { |
| 0 | 301 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 302 | | } |
| 2 | 303 | | return _result; |
| 2 | 304 | | } |
| | 305 | |
|
| | 306 | | /// <summary> |
| | 307 | | /// Get Model Properties. |
| | 308 | | /// </summary> |
| | 309 | | /// <remarks> |
| | 310 | | /// Get properties of the model file generated by Personalizer service. |
| | 311 | | /// </remarks> |
| | 312 | | /// <param name='customHeaders'> |
| | 313 | | /// Headers that will be added to request. |
| | 314 | | /// </param> |
| | 315 | | /// <param name='cancellationToken'> |
| | 316 | | /// The cancellation token. |
| | 317 | | /// </param> |
| | 318 | | /// <exception cref="HttpOperationException"> |
| | 319 | | /// Thrown when the operation returned an invalid status code |
| | 320 | | /// </exception> |
| | 321 | | /// <exception cref="SerializationException"> |
| | 322 | | /// Thrown when unable to deserialize the response |
| | 323 | | /// </exception> |
| | 324 | | /// <exception cref="ValidationException"> |
| | 325 | | /// Thrown when a required parameter is null |
| | 326 | | /// </exception> |
| | 327 | | /// <exception cref="System.ArgumentNullException"> |
| | 328 | | /// Thrown when a required parameter is null |
| | 329 | | /// </exception> |
| | 330 | | /// <return> |
| | 331 | | /// A response object containing the response body and response headers. |
| | 332 | | /// </return> |
| | 333 | | public async Task<HttpOperationResponse<ModelProperties>> GetPropertiesWithHttpMessagesAsync(Dictionary<string, |
| | 334 | | { |
| 2 | 335 | | if (Client.Endpoint == null) |
| | 336 | | { |
| 0 | 337 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 338 | | } |
| | 339 | | // Tracing |
| 2 | 340 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 341 | | string _invocationId = null; |
| 2 | 342 | | if (_shouldTrace) |
| | 343 | | { |
| 0 | 344 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 345 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 346 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 347 | | ServiceClientTracing.Enter(_invocationId, this, "GetProperties", tracingParameters); |
| | 348 | | } |
| | 349 | | // Construct URL |
| 2 | 350 | | var _baseUrl = Client.BaseUri; |
| 2 | 351 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "model/properties"; |
| 2 | 352 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 353 | | // Create HTTP transport objects |
| 2 | 354 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 355 | | HttpResponseMessage _httpResponse = null; |
| 2 | 356 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 357 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 358 | | // Set Headers |
| | 359 | |
|
| | 360 | |
|
| 2 | 361 | | if (customHeaders != null) |
| | 362 | | { |
| 0 | 363 | | foreach(var _header in customHeaders) |
| | 364 | | { |
| 0 | 365 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 366 | | { |
| 0 | 367 | | _httpRequest.Headers.Remove(_header.Key); |
| | 368 | | } |
| 0 | 369 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 370 | | } |
| | 371 | | } |
| | 372 | |
|
| | 373 | | // Serialize Request |
| 2 | 374 | | string _requestContent = null; |
| | 375 | | // Set Credentials |
| 2 | 376 | | if (Client.Credentials != null) |
| | 377 | | { |
| 2 | 378 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 379 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 380 | | } |
| | 381 | | // Send Request |
| 2 | 382 | | if (_shouldTrace) |
| | 383 | | { |
| 0 | 384 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 385 | | } |
| 2 | 386 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 387 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 388 | | if (_shouldTrace) |
| | 389 | | { |
| 0 | 390 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 391 | | } |
| 2 | 392 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 393 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 394 | | string _responseContent = null; |
| 2 | 395 | | if ((int)_statusCode != 200) |
| | 396 | | { |
| 0 | 397 | | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st |
| 0 | 398 | | if (_httpResponse.Content != null) { |
| 0 | 399 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 400 | | } |
| | 401 | | else { |
| 0 | 402 | | _responseContent = string.Empty; |
| | 403 | | } |
| 0 | 404 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 405 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 406 | | if (_shouldTrace) |
| | 407 | | { |
| 0 | 408 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 409 | | } |
| 0 | 410 | | _httpRequest.Dispose(); |
| 0 | 411 | | if (_httpResponse != null) |
| | 412 | | { |
| 0 | 413 | | _httpResponse.Dispose(); |
| | 414 | | } |
| 0 | 415 | | throw ex; |
| | 416 | | } |
| | 417 | | // Create Result |
| 2 | 418 | | var _result = new HttpOperationResponse<ModelProperties>(); |
| 2 | 419 | | _result.Request = _httpRequest; |
| 2 | 420 | | _result.Response = _httpResponse; |
| | 421 | | // Deserialize Response |
| 2 | 422 | | if ((int)_statusCode == 200) |
| | 423 | | { |
| 2 | 424 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 425 | | try |
| | 426 | | { |
| 2 | 427 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<ModelProperties>(_responseConten |
| 2 | 428 | | } |
| 0 | 429 | | catch (JsonException ex) |
| | 430 | | { |
| 0 | 431 | | _httpRequest.Dispose(); |
| 0 | 432 | | if (_httpResponse != null) |
| | 433 | | { |
| 0 | 434 | | _httpResponse.Dispose(); |
| | 435 | | } |
| 0 | 436 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 437 | | } |
| | 438 | | } |
| 2 | 439 | | if (_shouldTrace) |
| | 440 | | { |
| 0 | 441 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 442 | | } |
| 2 | 443 | | return _result; |
| 2 | 444 | | } |
| | 445 | |
|
| | 446 | | } |
| | 447 | | } |