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