| | 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 | | /// Log operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Log : IServiceOperations<PersonalizerClient>, ILog |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Log 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 Log(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> |
| 60 | 51 | | public PersonalizerClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Deletes Logs. |
| | 55 | | /// </summary> |
| | 56 | | /// <remarks> |
| | 57 | | /// Delete all generated logs. |
| | 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="ValidationException"> |
| | 69 | | /// Thrown when a required parameter is null |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="System.ArgumentNullException"> |
| | 72 | | /// Thrown when a required parameter is null |
| | 73 | | /// </exception> |
| | 74 | | /// <return> |
| | 75 | | /// A response object containing the response body and response headers. |
| | 76 | | /// </return> |
| | 77 | | public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(Dictionary<string, List<string>> customHead |
| | 78 | | { |
| 2 | 79 | | if (Client.Endpoint == null) |
| | 80 | | { |
| 0 | 81 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 82 | | } |
| | 83 | | // Tracing |
| 2 | 84 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 85 | | string _invocationId = null; |
| 2 | 86 | | if (_shouldTrace) |
| | 87 | | { |
| 0 | 88 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 89 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 90 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 91 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 92 | | } |
| | 93 | | // Construct URL |
| 2 | 94 | | var _baseUrl = Client.BaseUri; |
| 2 | 95 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "logs"; |
| 2 | 96 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 97 | | // Create HTTP transport objects |
| 2 | 98 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 99 | | HttpResponseMessage _httpResponse = null; |
| 2 | 100 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 101 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 102 | | // Set Headers |
| | 103 | |
|
| | 104 | |
|
| 2 | 105 | | if (customHeaders != null) |
| | 106 | | { |
| 0 | 107 | | foreach(var _header in customHeaders) |
| | 108 | | { |
| 0 | 109 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 110 | | { |
| 0 | 111 | | _httpRequest.Headers.Remove(_header.Key); |
| | 112 | | } |
| 0 | 113 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 114 | | } |
| | 115 | | } |
| | 116 | |
|
| | 117 | | // Serialize Request |
| 2 | 118 | | string _requestContent = null; |
| | 119 | | // Set Credentials |
| 2 | 120 | | if (Client.Credentials != null) |
| | 121 | | { |
| 2 | 122 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 123 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 124 | | } |
| | 125 | | // Send Request |
| 2 | 126 | | if (_shouldTrace) |
| | 127 | | { |
| 0 | 128 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 129 | | } |
| 2 | 130 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 131 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 132 | | if (_shouldTrace) |
| | 133 | | { |
| 0 | 134 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 135 | | } |
| 2 | 136 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 137 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 138 | | string _responseContent = null; |
| 2 | 139 | | if ((int)_statusCode != 204) |
| | 140 | | { |
| 0 | 141 | | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st |
| 0 | 142 | | if (_httpResponse.Content != null) { |
| 0 | 143 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 144 | | } |
| | 145 | | else { |
| 0 | 146 | | _responseContent = string.Empty; |
| | 147 | | } |
| 0 | 148 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 149 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 150 | | if (_shouldTrace) |
| | 151 | | { |
| 0 | 152 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 153 | | } |
| 0 | 154 | | _httpRequest.Dispose(); |
| 0 | 155 | | if (_httpResponse != null) |
| | 156 | | { |
| 0 | 157 | | _httpResponse.Dispose(); |
| | 158 | | } |
| 0 | 159 | | throw ex; |
| | 160 | | } |
| | 161 | | // Create Result |
| 2 | 162 | | var _result = new HttpOperationResponse(); |
| 2 | 163 | | _result.Request = _httpRequest; |
| 2 | 164 | | _result.Response = _httpResponse; |
| 2 | 165 | | if (_shouldTrace) |
| | 166 | | { |
| 0 | 167 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 168 | | } |
| 2 | 169 | | return _result; |
| 2 | 170 | | } |
| | 171 | |
|
| | 172 | | /// <summary> |
| | 173 | | /// Get Log Properties. |
| | 174 | | /// </summary> |
| | 175 | | /// <remarks> |
| | 176 | | /// Get properties of generated logs. |
| | 177 | | /// </remarks> |
| | 178 | | /// <param name='customHeaders'> |
| | 179 | | /// Headers that will be added to request. |
| | 180 | | /// </param> |
| | 181 | | /// <param name='cancellationToken'> |
| | 182 | | /// The cancellation token. |
| | 183 | | /// </param> |
| | 184 | | /// <exception cref="ErrorResponseException"> |
| | 185 | | /// Thrown when the operation returned an invalid status code |
| | 186 | | /// </exception> |
| | 187 | | /// <exception cref="SerializationException"> |
| | 188 | | /// Thrown when unable to deserialize the response |
| | 189 | | /// </exception> |
| | 190 | | /// <exception cref="ValidationException"> |
| | 191 | | /// Thrown when a required parameter is null |
| | 192 | | /// </exception> |
| | 193 | | /// <exception cref="System.ArgumentNullException"> |
| | 194 | | /// Thrown when a required parameter is null |
| | 195 | | /// </exception> |
| | 196 | | /// <return> |
| | 197 | | /// A response object containing the response body and response headers. |
| | 198 | | /// </return> |
| | 199 | | public async Task<HttpOperationResponse<LogsProperties>> GetPropertiesWithHttpMessagesAsync(Dictionary<string, L |
| | 200 | | { |
| 2 | 201 | | if (Client.Endpoint == null) |
| | 202 | | { |
| 0 | 203 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 204 | | } |
| | 205 | | // Tracing |
| 2 | 206 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 207 | | string _invocationId = null; |
| 2 | 208 | | if (_shouldTrace) |
| | 209 | | { |
| 0 | 210 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 211 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 212 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 213 | | ServiceClientTracing.Enter(_invocationId, this, "GetProperties", tracingParameters); |
| | 214 | | } |
| | 215 | | // Construct URL |
| 2 | 216 | | var _baseUrl = Client.BaseUri; |
| 2 | 217 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "logs/properties"; |
| 2 | 218 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 219 | | // Create HTTP transport objects |
| 2 | 220 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 221 | | HttpResponseMessage _httpResponse = null; |
| 2 | 222 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 223 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 224 | | // Set Headers |
| | 225 | |
|
| | 226 | |
|
| 2 | 227 | | if (customHeaders != null) |
| | 228 | | { |
| 0 | 229 | | foreach(var _header in customHeaders) |
| | 230 | | { |
| 0 | 231 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 232 | | { |
| 0 | 233 | | _httpRequest.Headers.Remove(_header.Key); |
| | 234 | | } |
| 0 | 235 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 236 | | } |
| | 237 | | } |
| | 238 | |
|
| | 239 | | // Serialize Request |
| 2 | 240 | | string _requestContent = null; |
| | 241 | | // Set Credentials |
| 2 | 242 | | if (Client.Credentials != null) |
| | 243 | | { |
| 2 | 244 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 245 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 246 | | } |
| | 247 | | // Send Request |
| 2 | 248 | | if (_shouldTrace) |
| | 249 | | { |
| 0 | 250 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 251 | | } |
| 2 | 252 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 253 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 254 | | if (_shouldTrace) |
| | 255 | | { |
| 0 | 256 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 257 | | } |
| 2 | 258 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 259 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 260 | | string _responseContent = null; |
| 2 | 261 | | if ((int)_statusCode != 200) |
| | 262 | | { |
| 0 | 263 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 264 | | try |
| | 265 | | { |
| 0 | 266 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 267 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 268 | | if (_errorBody != null) |
| | 269 | | { |
| 0 | 270 | | ex.Body = _errorBody; |
| | 271 | | } |
| 0 | 272 | | } |
| 0 | 273 | | catch (JsonException) |
| | 274 | | { |
| | 275 | | // Ignore the exception |
| 0 | 276 | | } |
| 0 | 277 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 278 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 279 | | if (_shouldTrace) |
| | 280 | | { |
| 0 | 281 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 282 | | } |
| 0 | 283 | | _httpRequest.Dispose(); |
| 0 | 284 | | if (_httpResponse != null) |
| | 285 | | { |
| 0 | 286 | | _httpResponse.Dispose(); |
| | 287 | | } |
| 0 | 288 | | throw ex; |
| | 289 | | } |
| | 290 | | // Create Result |
| 2 | 291 | | var _result = new HttpOperationResponse<LogsProperties>(); |
| 2 | 292 | | _result.Request = _httpRequest; |
| 2 | 293 | | _result.Response = _httpResponse; |
| | 294 | | // Deserialize Response |
| 2 | 295 | | if ((int)_statusCode == 200) |
| | 296 | | { |
| 2 | 297 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 298 | | try |
| | 299 | | { |
| 2 | 300 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LogsProperties>(_responseContent |
| 2 | 301 | | } |
| 0 | 302 | | catch (JsonException ex) |
| | 303 | | { |
| 0 | 304 | | _httpRequest.Dispose(); |
| 0 | 305 | | if (_httpResponse != null) |
| | 306 | | { |
| 0 | 307 | | _httpResponse.Dispose(); |
| | 308 | | } |
| 0 | 309 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 310 | | } |
| | 311 | | } |
| 2 | 312 | | if (_shouldTrace) |
| | 313 | | { |
| 0 | 314 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 315 | | } |
| 2 | 316 | | return _result; |
| 2 | 317 | | } |
| | 318 | |
|
| | 319 | | } |
| | 320 | | } |