| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using System.Threading; |
| | 8 | | using System.Threading.Tasks; |
| | 9 | | using Azure.Core; |
| | 10 | | using Azure.Core.Pipeline; |
| | 11 | | using Azure.Storage.Cryptography; |
| | 12 | | using Azure.Storage.Queues.Models; |
| | 13 | | using Azure.Storage.Queues.Specialized; |
| | 14 | |
|
| | 15 | | namespace Azure.Storage.Queues |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// A QueueServiceClient represents a URL to the Azure Storage Queue service. |
| | 19 | | /// </summary> |
| | 20 | | public class QueueServiceClient |
| | 21 | | { |
| | 22 | | /// <summary> |
| | 23 | | /// The Uri endpoint used by the object. |
| | 24 | | /// </summary> |
| | 25 | | private readonly Uri _uri; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// The Uri endpoint used by the object. |
| | 29 | | /// </summary> |
| 338 | 30 | | public virtual Uri Uri => _uri; |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// The HttpPipeline used to send REST requests. |
| | 34 | | /// </summary> |
| | 35 | | private readonly HttpPipeline _pipeline; |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Gets the HttpPipeline used to send REST requests. |
| | 39 | | /// </summary> |
| 352 | 40 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// The version of the service to use when sending requests. |
| | 44 | | /// </summary> |
| | 45 | | private readonly QueueClientOptions.ServiceVersion _version; |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// The version of the service to use when sending requests. |
| | 49 | | /// </summary> |
| 314 | 50 | | internal virtual QueueClientOptions.ServiceVersion Version => _version; |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 54 | | /// every request. |
| | 55 | | /// </summary> |
| | 56 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 60 | | /// every request. |
| | 61 | | /// </summary> |
| 314 | 62 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// The <see cref="ClientSideEncryptionOptions"/> to be used when sending/receiving requests. |
| | 66 | | /// </summary> |
| | 67 | | private readonly ClientSideEncryptionOptions _clientSideEncryption; |
| | 68 | |
|
| | 69 | | /// <summary> |
| | 70 | | /// The <see cref="ClientSideEncryptionOptions"/> to be used when sending/receiving requests. |
| | 71 | | /// </summary> |
| 276 | 72 | | internal virtual ClientSideEncryptionOptions ClientSideEncryption => _clientSideEncryption; |
| | 73 | |
|
| | 74 | | /// <summary> |
| | 75 | | /// The Storage account name corresponding to the service client. |
| | 76 | | /// </summary> |
| | 77 | | private string _accountName; |
| | 78 | |
|
| | 79 | | /// <summary> |
| | 80 | | /// Gets the Storage account name corresponding to the service client. |
| | 81 | | /// </summary> |
| | 82 | | public virtual string AccountName |
| | 83 | | { |
| | 84 | | get |
| | 85 | | { |
| 8 | 86 | | if (_accountName == null) |
| | 87 | | { |
| 4 | 88 | | _accountName = new QueueUriBuilder(Uri).AccountName; |
| | 89 | | } |
| 8 | 90 | | return _accountName; |
| | 91 | | } |
| | 92 | | } |
| | 93 | |
|
| | 94 | | #region ctors |
| | 95 | | /// <summary> |
| | 96 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 97 | | /// class for mocking. |
| | 98 | | /// </summary> |
| 268 | 99 | | protected QueueServiceClient() |
| | 100 | | { |
| 268 | 101 | | } |
| | 102 | |
|
| | 103 | | /// <summary> |
| | 104 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 105 | | /// class. |
| | 106 | | /// </summary> |
| | 107 | | /// <param name="connectionString"> |
| | 108 | | /// A connection string includes the authentication information |
| | 109 | | /// required for your application to access data in an Azure Storage |
| | 110 | | /// account at runtime. |
| | 111 | | /// |
| | 112 | | /// For more information, see |
| | 113 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 114 | | /// Configure Azure Storage connection strings</see>. |
| | 115 | | /// </param> |
| | 116 | | public QueueServiceClient(string connectionString) |
| 4 | 117 | | : this(connectionString, null) |
| | 118 | | { |
| 4 | 119 | | } |
| | 120 | |
|
| | 121 | | /// <summary> |
| | 122 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 123 | | /// class. |
| | 124 | | /// </summary> |
| | 125 | | /// <param name="connectionString"> |
| | 126 | | /// A connection string includes the authentication information |
| | 127 | | /// required for your application to access data in an Azure Storage |
| | 128 | | /// account at runtime. |
| | 129 | | /// |
| | 130 | | /// For more information, see |
| | 131 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 132 | | /// Configure Azure Storage connection strings</see>. |
| | 133 | | /// </param> |
| | 134 | | /// <param name="options"> |
| | 135 | | /// Optional client options that define the transport pipeline |
| | 136 | | /// policies for authentication, retries, etc., that are applied to |
| | 137 | | /// every request. |
| | 138 | | /// </param> |
| 8 | 139 | | public QueueServiceClient(string connectionString, QueueClientOptions options) |
| | 140 | | { |
| 8 | 141 | | var conn = StorageConnectionString.Parse(connectionString); |
| 8 | 142 | | _uri = conn.QueueEndpoint; |
| 8 | 143 | | options ??= new QueueClientOptions(); |
| 8 | 144 | | _pipeline = options.Build(conn.Credentials); |
| 8 | 145 | | _version = options.Version; |
| 8 | 146 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 8 | 147 | | _clientSideEncryption = QueueClientSideEncryptionOptions.CloneFrom(options._clientSideEncryptionOptions); |
| 8 | 148 | | } |
| | 149 | |
|
| | 150 | | /// <summary> |
| | 151 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 152 | | /// class. |
| | 153 | | /// </summary> |
| | 154 | | /// <param name="serviceUri"> |
| | 155 | | /// A <see cref="Uri"/> referencing the queue service. |
| | 156 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net". |
| | 157 | | /// </param> |
| | 158 | | /// <param name="options"> |
| | 159 | | /// Optional client options that define the transport pipeline |
| | 160 | | /// policies for authentication, retries, etc., that are applied to |
| | 161 | | /// every request. |
| | 162 | | /// </param> |
| | 163 | | public QueueServiceClient(Uri serviceUri, QueueClientOptions options = default) |
| 8 | 164 | | : this(serviceUri, (HttpPipelinePolicy)null, options) |
| | 165 | | { |
| 8 | 166 | | } |
| | 167 | |
|
| | 168 | | /// <summary> |
| | 169 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 170 | | /// class. |
| | 171 | | /// </summary> |
| | 172 | | /// <param name="serviceUri"> |
| | 173 | | /// A <see cref="Uri"/> referencing the queue service. |
| | 174 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net". |
| | 175 | | /// </param> |
| | 176 | | /// <param name="credential"> |
| | 177 | | /// The shared key credential used to sign requests. |
| | 178 | | /// </param> |
| | 179 | | /// <param name="options"> |
| | 180 | | /// Optional client options that define the transport pipeline |
| | 181 | | /// policies for authentication, retries, etc., that are applied to |
| | 182 | | /// every request. |
| | 183 | | /// </param> |
| | 184 | | public QueueServiceClient(Uri serviceUri, StorageSharedKeyCredential credential, QueueClientOptions options = de |
| 248 | 185 | | : this(serviceUri, credential.AsPolicy(), options) |
| | 186 | | { |
| 248 | 187 | | } |
| | 188 | |
|
| | 189 | | /// <summary> |
| | 190 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 191 | | /// class. |
| | 192 | | /// </summary> |
| | 193 | | /// <param name="serviceUri"> |
| | 194 | | /// A <see cref="Uri"/> referencing the queue service. |
| | 195 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net". |
| | 196 | | /// </param> |
| | 197 | | /// <param name="credential"> |
| | 198 | | /// The token credential used to sign requests. |
| | 199 | | /// </param> |
| | 200 | | /// <param name="options"> |
| | 201 | | /// Optional client options that define the transport pipeline |
| | 202 | | /// policies for authentication, retries, etc., that are applied to |
| | 203 | | /// every request. |
| | 204 | | /// </param> |
| | 205 | | public QueueServiceClient(Uri serviceUri, TokenCredential credential, QueueClientOptions options = default) |
| 8 | 206 | | : this(serviceUri, credential.AsPolicy(), options) |
| | 207 | | { |
| 8 | 208 | | Errors.VerifyHttpsTokenAuth(serviceUri); |
| 4 | 209 | | } |
| | 210 | |
|
| | 211 | | /// <summary> |
| | 212 | | /// Initializes a new instance of the <see cref="QueueServiceClient"/> |
| | 213 | | /// class. |
| | 214 | | /// </summary> |
| | 215 | | /// <param name="serviceUri"> |
| | 216 | | /// A <see cref="Uri"/> referencing the queue service. |
| | 217 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net". |
| | 218 | | /// </param> |
| | 219 | | /// <param name="authentication"> |
| | 220 | | /// An optional authentication policy used to sign requests. |
| | 221 | | /// </param> |
| | 222 | | /// <param name="options"> |
| | 223 | | /// Optional client options that define the transport pipeline |
| | 224 | | /// policies for authentication, retries, etc., that are applied to |
| | 225 | | /// every request. |
| | 226 | | /// </param> |
| 264 | 227 | | internal QueueServiceClient(Uri serviceUri, HttpPipelinePolicy authentication, QueueClientOptions options) |
| | 228 | | { |
| 264 | 229 | | _uri = serviceUri; |
| 264 | 230 | | options ??= new QueueClientOptions(); |
| 264 | 231 | | _pipeline = options.Build(authentication); |
| 264 | 232 | | _version = options.Version; |
| 264 | 233 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 264 | 234 | | _clientSideEncryption = QueueClientSideEncryptionOptions.CloneFrom(options._clientSideEncryptionOptions); |
| 264 | 235 | | } |
| | 236 | | #endregion ctors |
| | 237 | |
|
| | 238 | | /// <summary> |
| | 239 | | /// Create a new <see cref="QueueClient"/> object by appending |
| | 240 | | /// <paramref name="queueName"/> to the end of <see cref="Uri"/>. |
| | 241 | | /// The new <see cref="QueueClient"/> uses the same request |
| | 242 | | /// policy pipeline as the <see cref="QueueServiceClient"/>. |
| | 243 | | /// </summary> |
| | 244 | | /// <param name="queueName"> |
| | 245 | | /// The name of the queue to reference. |
| | 246 | | /// </param> |
| | 247 | | /// <returns> |
| | 248 | | /// A <see cref="QueueClient"/> for the desired queue. |
| | 249 | | /// </returns> |
| | 250 | | public virtual QueueClient GetQueueClient(string queueName) |
| 276 | 251 | | => new QueueClient(Uri.AppendToPath(queueName), Pipeline, Version, ClientDiagnostics, ClientSideEncryption); |
| | 252 | |
|
| | 253 | | #region GetQueues |
| | 254 | | /// <summary> |
| | 255 | | /// The <see cref="GetQueues"/> operation returns an async |
| | 256 | | /// sequence of queues in the storage account. Enumerating the |
| | 257 | | /// queues may make multiple requests to the service while fetching |
| | 258 | | /// all the values. Queue names are returned in lexicographic order. |
| | 259 | | /// |
| | 260 | | /// For more information, see |
| | 261 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-queues1"> |
| | 262 | | /// List Queues</see>. |
| | 263 | | /// </summary> |
| | 264 | | /// <param name="traits"> |
| | 265 | | /// Optional trait options for shaping the queues. |
| | 266 | | /// </param> |
| | 267 | | /// <param name="prefix"> |
| | 268 | | /// Optional string that filters the results to return only queues |
| | 269 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 270 | | /// </param> |
| | 271 | | /// <param name="cancellationToken"> |
| | 272 | | /// <see cref="CancellationToken"/> |
| | 273 | | /// </param> |
| | 274 | | /// <returns> |
| | 275 | | /// The queues in the storage account. |
| | 276 | | /// </returns> |
| | 277 | | public virtual Pageable<QueueItem> GetQueues( |
| | 278 | | QueueTraits traits = QueueTraits.None, |
| | 279 | | string prefix = default, |
| | 280 | | CancellationToken cancellationToken = default) => |
| 18 | 281 | | new GetQueuesAsyncCollection(this, traits, prefix).ToSyncCollection(cancellationToken); |
| | 282 | |
|
| | 283 | | /// <summary> |
| | 284 | | /// The <see cref="GetQueuesAsync"/> operation returns an async |
| | 285 | | /// collection of queues in the storage account. Enumerating the |
| | 286 | | /// queues may make multiple requests to the service while fetching |
| | 287 | | /// all the values. Queue names are returned in lexicographic order. |
| | 288 | | /// |
| | 289 | | /// For more information, see |
| | 290 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-queues1"> |
| | 291 | | /// List Queues</see>. |
| | 292 | | /// </summary> |
| | 293 | | /// <param name="traits"> |
| | 294 | | /// Optional trait options for shaping the queues. |
| | 295 | | /// </param> |
| | 296 | | /// <param name="prefix"> |
| | 297 | | /// Optional string that filters the results to return only queues |
| | 298 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 299 | | /// </param> |
| | 300 | | /// <param name="cancellationToken"> |
| | 301 | | /// <see cref="CancellationToken"/> |
| | 302 | | /// </param> |
| | 303 | | /// <returns> |
| | 304 | | /// The queues in the storage account. |
| | 305 | | /// </returns> |
| | 306 | | /// <remarks> |
| | 307 | | /// Use an empty marker to start enumeration from the beginning. Queue names are returned in lexicographic order |
| | 308 | | /// After getting a segment, process it, and then call ListQueuesSegment again (passing in the next marker) to g |
| | 309 | | /// </remarks> |
| | 310 | | public virtual AsyncPageable<QueueItem> GetQueuesAsync( |
| | 311 | | QueueTraits traits = QueueTraits.None, |
| | 312 | | string prefix = default, |
| | 313 | | CancellationToken cancellationToken = default) => |
| 20 | 314 | | new GetQueuesAsyncCollection(this, traits, prefix).ToAsyncCollection(cancellationToken); |
| | 315 | |
|
| | 316 | | /// <summary> |
| | 317 | | /// Returns a single segment of containers starting from the specified marker. |
| | 318 | | /// |
| | 319 | | /// For more information, see |
| | 320 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/list-queues1"> |
| | 321 | | /// List Queues</see>. |
| | 322 | | /// </summary> |
| | 323 | | /// <param name="marker"> |
| | 324 | | /// Marker from the previous request. |
| | 325 | | /// </param> |
| | 326 | | /// <param name="traits"> |
| | 327 | | /// Optional trait options for shaping the queues. |
| | 328 | | /// </param> |
| | 329 | | /// <param name="prefix"> |
| | 330 | | /// Optional string that filters the results to return only queues |
| | 331 | | /// whose name begins with the specified <paramref name="prefix"/>. |
| | 332 | | /// </param> |
| | 333 | | /// <param name="pageSizeHint"> |
| | 334 | | /// Optional hint to specify the desired size of the page returned. |
| | 335 | | /// </param> |
| | 336 | | /// <param name="async"> |
| | 337 | | /// Whether to invoke the operation asynchronously. |
| | 338 | | /// </param> |
| | 339 | | /// <param name="cancellationToken"> |
| | 340 | | /// <see cref="CancellationToken"/> |
| | 341 | | /// </param> |
| | 342 | | /// <returns> |
| | 343 | | /// A single segment of containers starting from the specified marker, including the next marker if appropriate. |
| | 344 | | /// </returns> |
| | 345 | | /// <remarks> |
| | 346 | | /// Use an empty marker to start enumeration from the beginning. Queue names are returned in lexicographic order |
| | 347 | | /// After getting a segment, process it, and then call ListQueuesSegmentAsync again (passing in the next marker) |
| | 348 | | /// </remarks> |
| | 349 | | internal async Task<Response<QueuesSegment>> GetQueuesInternal( |
| | 350 | | string marker, |
| | 351 | | QueueTraits traits, |
| | 352 | | string prefix, |
| | 353 | | int? pageSizeHint, |
| | 354 | | bool async, |
| | 355 | | CancellationToken cancellationToken) |
| | 356 | | { |
| 38 | 357 | | using (Pipeline.BeginLoggingScope(nameof(QueueServiceClient))) |
| | 358 | | { |
| | 359 | | Pipeline.LogMethodEnter( |
| | 360 | | nameof(QueueServiceClient), |
| | 361 | | message: |
| | 362 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 363 | | $"{nameof(marker)}: {marker}\n" + |
| | 364 | | $"{nameof(traits)}: {traits}\n" + |
| | 365 | | $"{nameof(prefix)}: {prefix}"); |
| | 366 | | try |
| | 367 | | { |
| 38 | 368 | | IEnumerable<ListQueuesIncludeType> includeTypes = traits.AsIncludeTypes(); |
| 38 | 369 | | Response<QueuesSegment> response = await QueueRestClient.Service.ListQueuesSegmentAsync( |
| 38 | 370 | | ClientDiagnostics, |
| 38 | 371 | | Pipeline, |
| 38 | 372 | | Uri, |
| 38 | 373 | | version: Version.ToVersionString(), |
| 38 | 374 | | marker: marker, |
| 38 | 375 | | prefix: prefix, |
| 38 | 376 | | maxresults: pageSizeHint, |
| 38 | 377 | | include: includeTypes.Any() ? includeTypes : null, |
| 38 | 378 | | async: async, |
| 38 | 379 | | cancellationToken: cancellationToken) |
| 38 | 380 | | .ConfigureAwait(false); |
| 36 | 381 | | if ((traits & QueueTraits.Metadata) != QueueTraits.Metadata) |
| | 382 | | { |
| 32 | 383 | | IEnumerable<QueueItem> queueItems = response.Value.QueueItems; |
| 156 | 384 | | foreach (QueueItem queueItem in queueItems) |
| | 385 | | { |
| 46 | 386 | | queueItem.Metadata = null; |
| | 387 | | } |
| | 388 | | } |
| 36 | 389 | | return response; |
| | 390 | | } |
| 2 | 391 | | catch (Exception ex) |
| | 392 | | { |
| | 393 | | Pipeline.LogException(ex); |
| 2 | 394 | | throw; |
| | 395 | | } |
| | 396 | | finally |
| | 397 | | { |
| | 398 | | Pipeline.LogMethodExit(nameof(QueueServiceClient)); |
| | 399 | | } |
| | 400 | | } |
| 36 | 401 | | } |
| | 402 | | #endregion GetQueues |
| | 403 | |
|
| | 404 | | #region GetProperties |
| | 405 | | /// <summary> |
| | 406 | | /// Gets the properties of the queue service. |
| | 407 | | /// |
| | 408 | | /// For more information, see |
| | 409 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-service-properties"> |
| | 410 | | /// Get Queue Service Properties</see>. |
| | 411 | | /// </summary> |
| | 412 | | /// <param name="cancellationToken"> |
| | 413 | | /// <see cref="CancellationToken"/> |
| | 414 | | /// </param> |
| | 415 | | /// <returns> |
| | 416 | | /// <see cref="Response{QueueServiceProperties}"/> |
| | 417 | | /// </returns> |
| | 418 | | public virtual Response<QueueServiceProperties> GetProperties( |
| | 419 | | CancellationToken cancellationToken = default) => |
| 0 | 420 | | GetPropertiesInternal( |
| 0 | 421 | | false, // async |
| 0 | 422 | | cancellationToken) |
| 0 | 423 | | .EnsureCompleted(); |
| | 424 | |
|
| | 425 | | /// <summary> |
| | 426 | | /// Gets the properties of the queue service. |
| | 427 | | /// |
| | 428 | | /// For more information, see |
| | 429 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-service-properties"> |
| | 430 | | /// Get Queue Service Properties</see>. |
| | 431 | | /// </summary> |
| | 432 | | /// <param name="cancellationToken"> |
| | 433 | | /// <see cref="CancellationToken"/> |
| | 434 | | /// </param> |
| | 435 | | /// <returns> |
| | 436 | | /// <see cref="Response{QueueServiceProperties}"/> |
| | 437 | | /// </returns> |
| | 438 | | public virtual async Task<Response<QueueServiceProperties>> GetPropertiesAsync( |
| | 439 | | CancellationToken cancellationToken = default) => |
| 0 | 440 | | await GetPropertiesInternal( |
| 0 | 441 | | true, // async |
| 0 | 442 | | cancellationToken) |
| 0 | 443 | | .ConfigureAwait(false); |
| | 444 | |
|
| | 445 | | /// <summary> |
| | 446 | | /// Gets the properties of the queue service. |
| | 447 | | /// |
| | 448 | | /// For more information, see |
| | 449 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-service-properties"> |
| | 450 | | /// Get Queue Service Properties</see>. |
| | 451 | | /// </summary> |
| | 452 | | /// <param name="async"> |
| | 453 | | /// Whether to invoke the operation asynchronously. |
| | 454 | | /// </param> |
| | 455 | | /// <param name="cancellationToken"> |
| | 456 | | /// <see cref="CancellationToken"/> |
| | 457 | | /// </param> |
| | 458 | | /// <returns> |
| | 459 | | /// <see cref="Response{QueueServiceProperties}"/> |
| | 460 | | /// </returns> |
| | 461 | | private async Task<Response<QueueServiceProperties>> GetPropertiesInternal( |
| | 462 | | bool async, |
| | 463 | | CancellationToken cancellationToken) |
| | 464 | | { |
| 0 | 465 | | using (Pipeline.BeginLoggingScope(nameof(QueueServiceClient))) |
| | 466 | | { |
| | 467 | | Pipeline.LogMethodEnter( |
| | 468 | | nameof(QueueServiceClient), |
| | 469 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 470 | | try |
| | 471 | | { |
| 0 | 472 | | return await QueueRestClient.Service.GetPropertiesAsync( |
| 0 | 473 | | ClientDiagnostics, |
| 0 | 474 | | Pipeline, |
| 0 | 475 | | Uri, |
| 0 | 476 | | version: Version.ToVersionString(), |
| 0 | 477 | | async: async, |
| 0 | 478 | | cancellationToken: cancellationToken) |
| 0 | 479 | | .ConfigureAwait(false); |
| | 480 | | } |
| 0 | 481 | | catch (Exception ex) |
| | 482 | | { |
| | 483 | | Pipeline.LogException(ex); |
| 0 | 484 | | throw; |
| | 485 | | } |
| | 486 | | finally |
| | 487 | | { |
| | 488 | | Pipeline.LogMethodExit(nameof(QueueServiceClient)); |
| | 489 | | } |
| | 490 | | } |
| 0 | 491 | | } |
| | 492 | | #endregion GetProperties |
| | 493 | |
|
| | 494 | | #region SetProperties |
| | 495 | | /// <summary> |
| | 496 | | /// Sets the properties of the queue service. |
| | 497 | | /// |
| | 498 | | /// For more information, see |
| | 499 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-service-properties"> |
| | 500 | | /// Set Queue Service Properties</see>. |
| | 501 | | /// </summary> |
| | 502 | | /// <param name="properties"> |
| | 503 | | /// <see cref="QueueServiceProperties"/> |
| | 504 | | /// </param> |
| | 505 | | /// <param name="cancellationToken"> |
| | 506 | | /// <see cref="CancellationToken"/> |
| | 507 | | /// </param> |
| | 508 | | /// <returns> |
| | 509 | | /// <see cref="Response"/> |
| | 510 | | /// </returns> |
| | 511 | | public virtual Response SetProperties( |
| | 512 | | QueueServiceProperties properties, |
| | 513 | | CancellationToken cancellationToken = default) => |
| 0 | 514 | | SetPropertiesInternal( |
| 0 | 515 | | properties, |
| 0 | 516 | | false, // async |
| 0 | 517 | | cancellationToken) |
| 0 | 518 | | .EnsureCompleted(); |
| | 519 | |
|
| | 520 | | /// <summary> |
| | 521 | | /// Sets the properties of the queue service. |
| | 522 | | /// |
| | 523 | | /// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-service-p |
| | 524 | | /// Set Queue Service Properties</see>. |
| | 525 | | /// </summary> |
| | 526 | | /// <param name="properties"> |
| | 527 | | /// <see cref="QueueServiceProperties"/> |
| | 528 | | /// </param> |
| | 529 | | /// <param name="cancellationToken"> |
| | 530 | | /// <see cref="CancellationToken"/> |
| | 531 | | /// </param> |
| | 532 | | /// <returns> |
| | 533 | | /// <see cref="Response"/> |
| | 534 | | /// </returns> |
| | 535 | | public virtual async Task<Response> SetPropertiesAsync( |
| | 536 | | QueueServiceProperties properties, |
| | 537 | | CancellationToken cancellationToken = default) => |
| 0 | 538 | | await SetPropertiesInternal( |
| 0 | 539 | | properties, |
| 0 | 540 | | true, // async |
| 0 | 541 | | cancellationToken) |
| 0 | 542 | | .ConfigureAwait(false); |
| | 543 | |
|
| | 544 | | /// <summary> |
| | 545 | | /// Sets the properties of the queue service. |
| | 546 | | /// |
| | 547 | | /// For more information, see |
| | 548 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-service-properties"> |
| | 549 | | /// Set Queue Service Properties</see>. |
| | 550 | | /// </summary> |
| | 551 | | /// <param name="properties"> |
| | 552 | | /// <see cref="QueueServiceProperties"/> |
| | 553 | | /// </param> |
| | 554 | | /// <param name="async"> |
| | 555 | | /// Whether to invoke the operation asynchronously. |
| | 556 | | /// </param> |
| | 557 | | /// <param name="cancellationToken"> |
| | 558 | | /// <see cref="CancellationToken"/> |
| | 559 | | /// </param> |
| | 560 | | /// <returns> |
| | 561 | | /// <see cref="Response"/> |
| | 562 | | /// </returns> |
| | 563 | | private async Task<Response> SetPropertiesInternal( |
| | 564 | | QueueServiceProperties properties, |
| | 565 | | bool async, |
| | 566 | | CancellationToken cancellationToken) |
| | 567 | | { |
| 0 | 568 | | using (Pipeline.BeginLoggingScope(nameof(QueueServiceClient))) |
| | 569 | | { |
| | 570 | | Pipeline.LogMethodEnter( |
| | 571 | | nameof(QueueServiceClient), |
| | 572 | | message: |
| | 573 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 574 | | $"{nameof(properties)}: {properties}"); |
| | 575 | | try |
| | 576 | | { |
| 0 | 577 | | return await QueueRestClient.Service.SetPropertiesAsync( |
| 0 | 578 | | ClientDiagnostics, |
| 0 | 579 | | Pipeline, |
| 0 | 580 | | Uri, |
| 0 | 581 | | properties: properties, |
| 0 | 582 | | version: Version.ToVersionString(), |
| 0 | 583 | | async: async, |
| 0 | 584 | | cancellationToken: cancellationToken) |
| 0 | 585 | | .ConfigureAwait(false); |
| | 586 | | } |
| 0 | 587 | | catch (Exception ex) |
| | 588 | | { |
| | 589 | | Pipeline.LogException(ex); |
| 0 | 590 | | throw; |
| | 591 | | } |
| | 592 | | finally |
| | 593 | | { |
| | 594 | | Pipeline.LogMethodExit(nameof(QueueServiceClient)); |
| | 595 | | } |
| | 596 | | } |
| 0 | 597 | | } |
| | 598 | | #endregion SetProperties |
| | 599 | |
|
| | 600 | | #region GetStatistics |
| | 601 | | /// <summary> |
| | 602 | | /// Retrieves statistics related to replication for the Blob service. It is |
| | 603 | | /// only available on the secondary location endpoint when read-access |
| | 604 | | /// geo-redundant replication is enabled for the storage account. |
| | 605 | | /// |
| | 606 | | /// For more information, see |
| | 607 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-service-stats"> |
| | 608 | | /// Get Queue Service Stats</see>. |
| | 609 | | /// </summary> |
| | 610 | | /// <param name="cancellationToken"> |
| | 611 | | /// <see cref="CancellationToken"/> |
| | 612 | | /// </param> |
| | 613 | | /// <returns> |
| | 614 | | /// <see cref="Response{QueueServiceStatistics}"/> |
| | 615 | | /// </returns> |
| | 616 | | public virtual Response<QueueServiceStatistics> GetStatistics( |
| | 617 | | CancellationToken cancellationToken = default) => |
| 0 | 618 | | GetStatisticsInternal( |
| 0 | 619 | | false, // async |
| 0 | 620 | | cancellationToken) |
| 0 | 621 | | .EnsureCompleted(); |
| | 622 | |
|
| | 623 | | /// <summary> |
| | 624 | | /// Retrieves statistics related to replication for the Blob service. It is |
| | 625 | | /// only available on the secondary location endpoint when read-access |
| | 626 | | /// geo-redundant replication is enabled for the storage account. |
| | 627 | | /// |
| | 628 | | /// For more information, see |
| | 629 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-service-stats"> |
| | 630 | | /// Get Queue Service Stats</see>. |
| | 631 | | /// </summary> |
| | 632 | | /// <param name="cancellationToken"> |
| | 633 | | /// <see cref="CancellationToken"/> |
| | 634 | | /// </param> |
| | 635 | | /// <returns> |
| | 636 | | /// <see cref="Response{QueueServiceStatistics}"/> |
| | 637 | | /// </returns> |
| | 638 | | public virtual async Task<Response<QueueServiceStatistics>> GetStatisticsAsync( |
| | 639 | | CancellationToken cancellationToken = default) => |
| 0 | 640 | | await GetStatisticsInternal( |
| 0 | 641 | | true, // async |
| 0 | 642 | | cancellationToken) |
| 0 | 643 | | .ConfigureAwait(false); |
| | 644 | |
|
| | 645 | | /// <summary> |
| | 646 | | /// Retrieves statistics related to replication for the Blob service. It is |
| | 647 | | /// only available on the secondary location endpoint when read-access |
| | 648 | | /// geo-redundant replication is enabled for the storage account. |
| | 649 | | /// |
| | 650 | | /// For more information, see |
| | 651 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-service-stats"> |
| | 652 | | /// Get Queue Service Stats</see>. |
| | 653 | | /// </summary> |
| | 654 | | /// <param name="async"> |
| | 655 | | /// Whether to invoke the operation asynchronously. |
| | 656 | | /// </param> |
| | 657 | | /// <param name="cancellationToken"> |
| | 658 | | /// <see cref="CancellationToken"/> |
| | 659 | | /// </param> |
| | 660 | | /// <returns> |
| | 661 | | /// <see cref="Response{QueueServiceStatistics}"/> |
| | 662 | | /// </returns> |
| | 663 | | private async Task<Response<QueueServiceStatistics>> GetStatisticsInternal( |
| | 664 | | bool async, |
| | 665 | | CancellationToken cancellationToken) |
| | 666 | | { |
| 0 | 667 | | using (Pipeline.BeginLoggingScope(nameof(QueueServiceClient))) |
| | 668 | | { |
| | 669 | | Pipeline.LogMethodEnter( |
| | 670 | | nameof(QueueServiceClient), |
| | 671 | | message: $"{nameof(Uri)}: {Uri}\n"); |
| | 672 | | try |
| | 673 | | { |
| 0 | 674 | | return await QueueRestClient.Service.GetStatisticsAsync( |
| 0 | 675 | | ClientDiagnostics, |
| 0 | 676 | | Pipeline, |
| 0 | 677 | | Uri, |
| 0 | 678 | | version: Version.ToVersionString(), |
| 0 | 679 | | async: async, |
| 0 | 680 | | cancellationToken: cancellationToken) |
| 0 | 681 | | .ConfigureAwait(false); |
| | 682 | | } |
| 0 | 683 | | catch (Exception ex) |
| | 684 | | { |
| | 685 | | Pipeline.LogException(ex); |
| 0 | 686 | | throw; |
| | 687 | | } |
| | 688 | | finally |
| | 689 | | { |
| | 690 | | Pipeline.LogMethodExit(nameof(QueueServiceClient)); |
| | 691 | | } |
| | 692 | | } |
| 0 | 693 | | } |
| | 694 | | #endregion GetStatistics |
| | 695 | |
|
| | 696 | | #region CreateQueue |
| | 697 | | /// <summary> |
| | 698 | | /// Creates a queue. |
| | 699 | | /// |
| | 700 | | /// For more information, see |
| | 701 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 702 | | /// Create Queue</see>. |
| | 703 | | /// </summary> |
| | 704 | | /// <param name="queueName"> |
| | 705 | | /// The name of the queue to create. |
| | 706 | | /// </param> |
| | 707 | | /// <param name="metadata"> |
| | 708 | | /// Optional <see cref="IDictionary{String, String}"/>. |
| | 709 | | /// </param> |
| | 710 | | /// <param name="cancellationToken"> |
| | 711 | | /// <see cref="CancellationToken"/> |
| | 712 | | /// </param> |
| | 713 | | /// <returns> |
| | 714 | | /// A newly created <see cref="Response{QueueClient}"/>. |
| | 715 | | /// </returns> |
| | 716 | | [ForwardsClientCalls] |
| | 717 | | public virtual Response<QueueClient> CreateQueue( |
| | 718 | | string queueName, |
| | 719 | | IDictionary<string, string> metadata = default, |
| | 720 | | CancellationToken cancellationToken = default) |
| | 721 | | { |
| 6 | 722 | | QueueClient queue = GetQueueClient(queueName); |
| 6 | 723 | | Response response = queue.Create(metadata, cancellationToken); |
| 6 | 724 | | return Response.FromValue(queue, response); |
| | 725 | | } |
| | 726 | |
|
| | 727 | | /// <summary> |
| | 728 | | /// Creates a queue. |
| | 729 | | /// |
| | 730 | | /// For more information, see |
| | 731 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 732 | | /// Create Queue</see>. |
| | 733 | | /// </summary> |
| | 734 | | /// <param name="queueName"> |
| | 735 | | /// The name of the queue to create. |
| | 736 | | /// </param> |
| | 737 | | /// <param name="metadata"> |
| | 738 | | /// Optional <see cref="IDictionary{String, String}"/>. |
| | 739 | | /// </param> |
| | 740 | | /// <param name="cancellationToken"> |
| | 741 | | /// <see cref="CancellationToken"/> |
| | 742 | | /// </param> |
| | 743 | | /// <returns> |
| | 744 | | /// A newly created <see cref="Response{QueueClient}"/>. |
| | 745 | | /// </returns> |
| | 746 | | [ForwardsClientCalls] |
| | 747 | | public virtual async Task<Response<QueueClient>> CreateQueueAsync( |
| | 748 | | string queueName, |
| | 749 | | IDictionary<string, string> metadata = default, |
| | 750 | | CancellationToken cancellationToken = default) |
| | 751 | | { |
| 6 | 752 | | QueueClient queue = GetQueueClient(queueName); |
| 6 | 753 | | Response response = await queue.CreateAsync(metadata, cancellationToken).ConfigureAwait(false); |
| 6 | 754 | | return Response.FromValue(queue, response); |
| 6 | 755 | | } |
| | 756 | | #endregion CreateQueue |
| | 757 | |
|
| | 758 | | #region DeleteQueue |
| | 759 | | /// <summary> |
| | 760 | | /// Deletes a queue. |
| | 761 | | /// |
| | 762 | | /// For more information, see |
| | 763 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-queue3"> |
| | 764 | | /// Delete Queue</see>. |
| | 765 | | /// </summary> |
| | 766 | | /// <param name="queueName"> |
| | 767 | | /// The name of the queue to delete. |
| | 768 | | /// </param> |
| | 769 | | /// <param name="cancellationToken"> |
| | 770 | | /// <see cref="CancellationToken"/> |
| | 771 | | /// </param> |
| | 772 | | /// <returns> |
| | 773 | | /// <see cref="Response"/> |
| | 774 | | /// </returns> |
| | 775 | | [ForwardsClientCalls] |
| | 776 | | public virtual Response DeleteQueue( |
| | 777 | | string queueName, |
| | 778 | | CancellationToken cancellationToken = default) => |
| 6 | 779 | | GetQueueClient(queueName).Delete(cancellationToken); |
| | 780 | |
|
| | 781 | | /// <summary> |
| | 782 | | /// Deletes a queue. |
| | 783 | | /// |
| | 784 | | /// For more information, see |
| | 785 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-queue3"> |
| | 786 | | /// Delete Queue</see>. |
| | 787 | | /// </summary> |
| | 788 | | /// <param name="queueName"> |
| | 789 | | /// The name of the queue to delete. |
| | 790 | | /// </param> |
| | 791 | | /// <param name="cancellationToken"> |
| | 792 | | /// <see cref="CancellationToken"/> |
| | 793 | | /// </param> |
| | 794 | | /// <returns> |
| | 795 | | /// <see cref="Response"/> |
| | 796 | | /// </returns> |
| | 797 | | [ForwardsClientCalls] |
| | 798 | | public virtual async Task<Response> DeleteQueueAsync( |
| | 799 | | string queueName, |
| | 800 | | CancellationToken cancellationToken = default) => |
| 6 | 801 | | await GetQueueClient(queueName) |
| 6 | 802 | | .DeleteAsync(cancellationToken) |
| 6 | 803 | | .ConfigureAwait(false); |
| | 804 | | #endregion DeleteQueue |
| | 805 | | } |
| | 806 | | } |