| | 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.Globalization; |
| | 7 | | using System.Linq; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | | using Azure.Core; |
| | 11 | | using Azure.Core.Pipeline; |
| | 12 | | using Azure.Storage.Cryptography; |
| | 13 | | using Azure.Storage.Queues.Models; |
| | 14 | | using Azure.Storage.Queues.Specialized; |
| | 15 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 16 | |
|
| | 17 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 18 | |
|
| | 19 | | namespace Azure.Storage.Queues |
| | 20 | | { |
| | 21 | | /// <summary> |
| | 22 | | /// A QueueClient represents a URI to the Azure Storage Queue service allowing you to manipulate a queue. |
| | 23 | | /// </summary> |
| | 24 | | public class QueueClient |
| | 25 | | { |
| | 26 | | /// <summary> |
| | 27 | | /// The Uri endpoint used by the object. |
| | 28 | | /// </summary> |
| | 29 | | private readonly Uri _uri; |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Gets the Uri endpoint used by the object. |
| | 33 | | /// </summary> |
| 624 | 34 | | public virtual Uri Uri => _uri; |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// The Uri endpoint used by the object's messages. |
| | 38 | | /// </summary> |
| | 39 | | private readonly Uri _messagesUri; |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets the Uri endpoint used by the object's messages. |
| | 43 | | /// </summary> |
| 188 | 44 | | protected virtual Uri MessagesUri => _messagesUri; |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// The HttpPipeline used to send REST requests. |
| | 48 | | /// </summary> |
| | 49 | | private readonly HttpPipeline _pipeline; |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Gets the HttpPipeline used to send REST requests. |
| | 53 | | /// </summary> |
| 1488 | 54 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// The version of the service to use when sending requests. |
| | 58 | | /// </summary> |
| | 59 | | private readonly QueueClientOptions.ServiceVersion _version; |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// The version of the service to use when sending requests. |
| | 63 | | /// </summary> |
| 724 | 64 | | internal virtual QueueClientOptions.ServiceVersion Version => _version; |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 68 | | /// every request. |
| | 69 | | /// </summary> |
| | 70 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 74 | | /// every request. |
| | 75 | | /// </summary> |
| 724 | 76 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// The <see cref="QueueClientSideEncryptionOptions"/> to be used when sending/receiving requests. |
| | 80 | | /// </summary> |
| | 81 | | private readonly QueueClientSideEncryptionOptions _clientSideEncryption; |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// The <see cref="QueueClientSideEncryptionOptions"/> to be used when sending/receiving requests. |
| | 85 | | /// </summary> |
| 160 | 86 | | internal virtual QueueClientSideEncryptionOptions ClientSideEncryption => _clientSideEncryption; |
| | 87 | |
|
| 160 | 88 | | internal bool UsingClientSideEncryption => ClientSideEncryption != default; |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// QueueMaxMessagesPeek indicates the maximum number of messages |
| | 92 | | /// you can retrieve with each call to Peek. |
| | 93 | | /// </summary> |
| 0 | 94 | | public virtual int MaxPeekableMessages => Constants.Queue.MaxMessagesDequeue; |
| | 95 | |
|
| | 96 | | /// <summary> |
| | 97 | | /// Gets the maximum number of bytes allowed for a message's UTF-8 text. |
| | 98 | | /// </summary> |
| 0 | 99 | | public virtual int MessageMaxBytes => Constants.Queue.QueueMessageMaxBytes; |
| | 100 | |
|
| | 101 | | /// <summary> |
| | 102 | | /// The Storage account name corresponding to the queue client. |
| | 103 | | /// </summary> |
| | 104 | | private string _accountName; |
| | 105 | |
|
| | 106 | | /// <summary> |
| | 107 | | /// Gets the Storage account name corresponding to the queue client. |
| | 108 | | /// </summary> |
| | 109 | | public virtual string AccountName |
| | 110 | | { |
| | 111 | | get |
| | 112 | | { |
| 8 | 113 | | SetNameFieldsIfNull(); |
| 8 | 114 | | return _accountName; |
| | 115 | | } |
| | 116 | | } |
| | 117 | |
|
| | 118 | | /// <summary> |
| | 119 | | /// The name of the queue. |
| | 120 | | /// </summary> |
| | 121 | | private string _name; |
| | 122 | |
|
| | 123 | | /// <summary> |
| | 124 | | /// Gets the name of the queue. |
| | 125 | | /// </summary> |
| | 126 | | public virtual string Name |
| | 127 | | { |
| | 128 | | get |
| | 129 | | { |
| 28 | 130 | | SetNameFieldsIfNull(); |
| 28 | 131 | | return _name; |
| | 132 | | } |
| | 133 | | } |
| | 134 | |
|
| | 135 | | #region ctors |
| | 136 | | /// <summary> |
| | 137 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 138 | | /// class for mocking. |
| | 139 | | /// </summary> |
| 296 | 140 | | protected QueueClient() |
| | 141 | | { |
| 296 | 142 | | } |
| | 143 | |
|
| | 144 | | /// <summary> |
| | 145 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 146 | | /// class. |
| | 147 | | /// </summary> |
| | 148 | | /// <param name="connectionString"> |
| | 149 | | /// A connection string includes the authentication information |
| | 150 | | /// required for your application to access data in an Azure Storage |
| | 151 | | /// account at runtime. |
| | 152 | | /// |
| | 153 | | /// For more information, see |
| | 154 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 155 | | /// Configure Azure Storage connection strings</see>. |
| | 156 | | /// </param> |
| | 157 | | /// <param name="queueName"> |
| | 158 | | /// The name of the queue in the storage account to reference. |
| | 159 | | /// </param> |
| | 160 | | public QueueClient(string connectionString, string queueName) |
| 4 | 161 | | : this(connectionString, queueName, null) |
| | 162 | | { |
| 4 | 163 | | } |
| | 164 | |
|
| | 165 | | /// <summary> |
| | 166 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 167 | | /// class. |
| | 168 | | /// </summary> |
| | 169 | | /// <param name="connectionString"> |
| | 170 | | /// A connection string includes the authentication information |
| | 171 | | /// required for your application to access data in an Azure Storage |
| | 172 | | /// account at runtime. |
| | 173 | | /// |
| | 174 | | /// For more information, see |
| | 175 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 176 | | /// Configure Azure Storage connection strings</see>. |
| | 177 | | /// </param> |
| | 178 | | /// <param name="queueName"> |
| | 179 | | /// The name of the queue in the storage account to reference. |
| | 180 | | /// </param> |
| | 181 | | /// <param name="options"> |
| | 182 | | /// Optional client options that define the transport pipeline |
| | 183 | | /// policies for authentication, retries, etc., that are applied to |
| | 184 | | /// every request. |
| | 185 | | /// </param> |
| 16 | 186 | | public QueueClient(string connectionString, string queueName, QueueClientOptions options) |
| | 187 | | { |
| 16 | 188 | | var conn = StorageConnectionString.Parse(connectionString); |
| 16 | 189 | | var builder = |
| 16 | 190 | | new QueueUriBuilder(conn.QueueEndpoint) |
| 16 | 191 | | { |
| 16 | 192 | | QueueName = queueName |
| 16 | 193 | | }; |
| 16 | 194 | | _uri = builder.ToUri(); |
| 16 | 195 | | _messagesUri = _uri.AppendToPath(Constants.Queue.MessagesUri); |
| 16 | 196 | | options ??= new QueueClientOptions(); |
| 16 | 197 | | _pipeline = options.Build(conn.Credentials); |
| 16 | 198 | | _version = options.Version; |
| 16 | 199 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 16 | 200 | | _clientSideEncryption = QueueClientSideEncryptionOptions.CloneFrom(options._clientSideEncryptionOptions); |
| 16 | 201 | | } |
| | 202 | |
|
| | 203 | | /// <summary> |
| | 204 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 205 | | /// class. |
| | 206 | | /// </summary> |
| | 207 | | /// <param name="queueUri"> |
| | 208 | | /// A <see cref="Uri"/> referencing the queue that includes the |
| | 209 | | /// name of the account, and the name of the queue. |
| | 210 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net/{queue_name}". |
| | 211 | | /// </param> |
| | 212 | | /// <param name="options"> |
| | 213 | | /// Optional client options that define the transport pipeline |
| | 214 | | /// policies for authentication, retries, etc., that are applied to |
| | 215 | | /// every request. |
| | 216 | | /// </param> |
| | 217 | | public QueueClient(Uri queueUri, QueueClientOptions options = default) |
| 36 | 218 | | : this(queueUri, (HttpPipelinePolicy)null, options) |
| | 219 | | { |
| 36 | 220 | | } |
| | 221 | |
|
| | 222 | | /// <summary> |
| | 223 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 224 | | /// class. |
| | 225 | | /// </summary> |
| | 226 | | /// <param name="queueUri"> |
| | 227 | | /// A <see cref="Uri"/> referencing the queue that includes the |
| | 228 | | /// name of the account, and the name of the queue. |
| | 229 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net/{queue_name}". |
| | 230 | | /// </param> |
| | 231 | | /// <param name="credential"> |
| | 232 | | /// The shared key credential used to sign requests. |
| | 233 | | /// </param> |
| | 234 | | /// <param name="options"> |
| | 235 | | /// Optional client options that define the transport pipeline |
| | 236 | | /// policies for authentication, retries, etc., that are applied to |
| | 237 | | /// every request. |
| | 238 | | /// </param> |
| | 239 | | public QueueClient(Uri queueUri, StorageSharedKeyCredential credential, QueueClientOptions options = default) |
| 8 | 240 | | : this(queueUri, credential.AsPolicy(), options) |
| | 241 | | { |
| 8 | 242 | | } |
| | 243 | |
|
| | 244 | | /// <summary> |
| | 245 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 246 | | /// class. |
| | 247 | | /// </summary> |
| | 248 | | /// <param name="queueUri"> |
| | 249 | | /// A <see cref="Uri"/> referencing the queue that includes the |
| | 250 | | /// name of the account, and the name of the queue. |
| | 251 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net/{queue_name}". |
| | 252 | | /// </param> |
| | 253 | | /// <param name="credential"> |
| | 254 | | /// The token credential used to sign requests. |
| | 255 | | /// </param> |
| | 256 | | /// <param name="options"> |
| | 257 | | /// Optional client options that define the transport pipeline |
| | 258 | | /// policies for authentication, retries, etc., that are applied to |
| | 259 | | /// every request. |
| | 260 | | /// </param> |
| | 261 | | public QueueClient(Uri queueUri, TokenCredential credential, QueueClientOptions options = default) |
| 4 | 262 | | : this(queueUri, credential.AsPolicy(), options) |
| | 263 | | { |
| 4 | 264 | | Errors.VerifyHttpsTokenAuth(queueUri); |
| 0 | 265 | | } |
| | 266 | |
|
| | 267 | | /// <summary> |
| | 268 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 269 | | /// class. |
| | 270 | | /// </summary> |
| | 271 | | /// <param name="queueUri"> |
| | 272 | | /// A <see cref="Uri"/> referencing the queue that includes the |
| | 273 | | /// name of the account, and the name of the queue. |
| | 274 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net/{queue_name}". |
| | 275 | | /// </param> |
| | 276 | | /// <param name="authentication"> |
| | 277 | | /// An optional authentication policy used to sign requests. |
| | 278 | | /// </param> |
| | 279 | | /// <param name="options"> |
| | 280 | | /// Optional client options that define the transport pipeline |
| | 281 | | /// policies for authentication, retries, etc., that are applied to |
| | 282 | | /// every request. |
| | 283 | | /// </param> |
| 48 | 284 | | internal QueueClient(Uri queueUri, HttpPipelinePolicy authentication, QueueClientOptions options) |
| | 285 | | { |
| 48 | 286 | | _uri = queueUri; |
| 48 | 287 | | _messagesUri = queueUri.AppendToPath(Constants.Queue.MessagesUri); |
| 48 | 288 | | options ??= new QueueClientOptions(); |
| 48 | 289 | | _pipeline = options.Build(authentication); |
| 48 | 290 | | _version = options.Version; |
| 48 | 291 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 48 | 292 | | _clientSideEncryption = QueueClientSideEncryptionOptions.CloneFrom(options._clientSideEncryptionOptions); |
| 48 | 293 | | } |
| | 294 | |
|
| | 295 | | /// <summary> |
| | 296 | | /// Initializes a new instance of the <see cref="QueueClient"/> |
| | 297 | | /// class. |
| | 298 | | /// </summary> |
| | 299 | | /// <param name="queueUri"> |
| | 300 | | /// A <see cref="Uri"/> referencing the queue that includes the |
| | 301 | | /// name of the account, and the name of the queue. |
| | 302 | | /// This is likely to be similar to "https://{account_name}.queue.core.windows.net/{queue_name}". |
| | 303 | | /// </param> |
| | 304 | | /// <param name="pipeline"> |
| | 305 | | /// The transport pipeline used to send every request. |
| | 306 | | /// </param> |
| | 307 | | /// <param name="version"> |
| | 308 | | /// The version of the service to use when sending requests. |
| | 309 | | /// </param> |
| | 310 | | /// <param name="clientDiagnostics"> |
| | 311 | | /// The <see cref="ClientDiagnostics"/> instance used to create |
| | 312 | | /// diagnostic scopes every request. |
| | 313 | | /// </param> |
| | 314 | | /// <param name="encryptionOptions"> |
| | 315 | | /// Options for client-side encryption. |
| | 316 | | /// </param> |
| 276 | 317 | | internal QueueClient( |
| 276 | 318 | | Uri queueUri, |
| 276 | 319 | | HttpPipeline pipeline, |
| 276 | 320 | | QueueClientOptions.ServiceVersion version, |
| 276 | 321 | | ClientDiagnostics clientDiagnostics, |
| 276 | 322 | | ClientSideEncryptionOptions encryptionOptions) |
| | 323 | | { |
| 276 | 324 | | _uri = queueUri; |
| 276 | 325 | | _messagesUri = queueUri.AppendToPath(Constants.Queue.MessagesUri); |
| 276 | 326 | | _pipeline = pipeline; |
| 276 | 327 | | _version = version; |
| 276 | 328 | | _clientDiagnostics = clientDiagnostics; |
| 276 | 329 | | _clientSideEncryption = QueueClientSideEncryptionOptions.CloneFrom(encryptionOptions); |
| 276 | 330 | | } |
| | 331 | | #endregion ctors |
| | 332 | |
|
| | 333 | | /// <summary> |
| | 334 | | /// Sets the various name fields if they are currently null. |
| | 335 | | /// </summary> |
| | 336 | | private void SetNameFieldsIfNull() |
| | 337 | | { |
| 36 | 338 | | if (_name == null || _accountName == null) |
| | 339 | | { |
| 24 | 340 | | var builder = new QueueUriBuilder(Uri); |
| 24 | 341 | | _name = builder.QueueName; |
| 24 | 342 | | _accountName = builder.AccountName; |
| | 343 | | } |
| 36 | 344 | | } |
| | 345 | |
|
| | 346 | | #region Create |
| | 347 | | /// <summary> |
| | 348 | | /// Creates a queue. |
| | 349 | | /// |
| | 350 | | /// For more information, see |
| | 351 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 352 | | /// Create Queue</see>. |
| | 353 | | /// </summary> |
| | 354 | | /// <param name="metadata"> |
| | 355 | | /// Optional <see cref="Metadata"/>. |
| | 356 | | /// </param> |
| | 357 | | /// <param name="cancellationToken"> |
| | 358 | | /// <see cref="CancellationToken"/> |
| | 359 | | /// </param> |
| | 360 | | /// <returns> |
| | 361 | | /// <see cref="Response" /> |
| | 362 | | /// </returns> |
| | 363 | | public virtual Response Create( |
| | 364 | | Metadata metadata = default, |
| | 365 | | CancellationToken cancellationToken = default) => |
| 104 | 366 | | CreateInternal( |
| 104 | 367 | | metadata, |
| 104 | 368 | | false, // async |
| 104 | 369 | | cancellationToken) |
| 104 | 370 | | .EnsureCompleted(); |
| | 371 | |
|
| | 372 | | /// <summary> |
| | 373 | | /// Creates a queue. |
| | 374 | | /// |
| | 375 | | /// For more information, see |
| | 376 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 377 | | /// Create Queue</see>. |
| | 378 | | /// </summary> |
| | 379 | | /// <param name="metadata"> |
| | 380 | | /// Optional <see cref="Metadata"/>. |
| | 381 | | /// </param> |
| | 382 | | /// <param name="cancellationToken"> |
| | 383 | | /// <see cref="CancellationToken"/> |
| | 384 | | /// </param> |
| | 385 | | /// <returns> |
| | 386 | | /// <see cref="Response"/> |
| | 387 | | /// </returns> |
| | 388 | | public virtual async Task<Response> CreateAsync( |
| | 389 | | Metadata metadata = default, |
| | 390 | | CancellationToken cancellationToken = default) => |
| 108 | 391 | | await CreateInternal( |
| 108 | 392 | | metadata, |
| 108 | 393 | | true, // async |
| 108 | 394 | | cancellationToken) |
| 108 | 395 | | .ConfigureAwait(false); |
| | 396 | |
|
| | 397 | | /// <summary> |
| | 398 | | /// Creates a queue. |
| | 399 | | /// |
| | 400 | | /// For more information, see |
| | 401 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 402 | | /// Create Queue</see>. |
| | 403 | | /// </summary> |
| | 404 | | /// <param name="metadata"> |
| | 405 | | /// Optional <see cref="Metadata"/>. |
| | 406 | | /// </param> |
| | 407 | | /// <param name="async"> |
| | 408 | | /// Whether to invoke the operation asynchronously. |
| | 409 | | /// </param> |
| | 410 | | /// <param name="cancellationToken"> |
| | 411 | | /// <see cref="CancellationToken"/> |
| | 412 | | /// </param> |
| | 413 | | /// <param name="operationName"> |
| | 414 | | /// Optional. To indicate if the name of the operation. |
| | 415 | | /// </param> |
| | 416 | | /// <returns> |
| | 417 | | /// <see cref="Response"/> |
| | 418 | | /// </returns> |
| | 419 | | private async Task<Response> CreateInternal( |
| | 420 | | Metadata metadata, |
| | 421 | | bool async, |
| | 422 | | CancellationToken cancellationToken, |
| | 423 | | string operationName = default) |
| | 424 | | { |
| 228 | 425 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 426 | | { |
| | 427 | | Pipeline.LogMethodEnter( |
| | 428 | | nameof(QueueClient), |
| | 429 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 430 | | try |
| | 431 | | { |
| 228 | 432 | | return await QueueRestClient.Queue.CreateAsync( |
| 228 | 433 | | ClientDiagnostics, |
| 228 | 434 | | Pipeline, |
| 228 | 435 | | Uri, |
| 228 | 436 | | version: Version.ToVersionString(), |
| 228 | 437 | | metadata: metadata, |
| 228 | 438 | | async: async, |
| 228 | 439 | | operationName: operationName ?? $"{nameof(QueueClient)}.{nameof(Create)}", |
| 228 | 440 | | cancellationToken: cancellationToken) |
| 228 | 441 | | .ConfigureAwait(false); |
| | 442 | | } |
| 16 | 443 | | catch (Exception ex) |
| | 444 | | { |
| | 445 | | Pipeline.LogException(ex); |
| 16 | 446 | | throw; |
| | 447 | | } |
| | 448 | | finally |
| | 449 | | { |
| | 450 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 451 | | } |
| | 452 | | } |
| 212 | 453 | | } |
| | 454 | | #endregion Create |
| | 455 | |
|
| | 456 | | #region CreateIfNotExists |
| | 457 | | /// <summary> |
| | 458 | | /// The <see cref="CreateIfNotExists"/> |
| | 459 | | /// operation creates a new queue under the specified account. |
| | 460 | | /// If the queue already exists, it is not changed. |
| | 461 | | /// |
| | 462 | | /// For more information, see |
| | 463 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 464 | | /// Create Queue</see>. |
| | 465 | | /// </summary> |
| | 466 | | /// <param name="metadata"> |
| | 467 | | /// Optional custom metadata to set for this queue. |
| | 468 | | /// </param> |
| | 469 | | /// <param name="cancellationToken"> |
| | 470 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 471 | | /// notifications that the operation should be cancelled. |
| | 472 | | /// </param> |
| | 473 | | /// <returns> |
| | 474 | | /// If the queue does not already exist, a <see cref="Response"/> |
| | 475 | | /// describing the newly created queue. If the queue already exists, <c>null</c>. |
| | 476 | | /// </returns> |
| | 477 | | /// <remarks> |
| | 478 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 479 | | /// a failure occurs. |
| | 480 | | /// </remarks> |
| | 481 | | public virtual Response CreateIfNotExists( |
| | 482 | | Metadata metadata = default, |
| | 483 | | CancellationToken cancellationToken = default) => |
| 8 | 484 | | CreateIfNotExistsInternal( |
| 8 | 485 | | metadata, |
| 8 | 486 | | async: false, |
| 8 | 487 | | cancellationToken).EnsureCompleted(); |
| | 488 | |
|
| | 489 | | /// <summary> |
| | 490 | | /// The <see cref="CreateIfNotExistsAsync"/> |
| | 491 | | /// operation creates a new queue under the specified account. |
| | 492 | | /// If the queue already exists, it is not changed. |
| | 493 | | /// |
| | 494 | | /// For more information, see |
| | 495 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 496 | | /// Create Queue</see>. |
| | 497 | | /// </summary> |
| | 498 | | /// <param name="metadata"> |
| | 499 | | /// Optional custom metadata to set for this queue. |
| | 500 | | /// </param> |
| | 501 | | /// <param name="cancellationToken"> |
| | 502 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 503 | | /// notifications that the operation should be cancelled. |
| | 504 | | /// </param> |
| | 505 | | /// <returns> |
| | 506 | | /// If the queue does not already exist, a <see cref="Response"/> |
| | 507 | | /// describing the newly created queue. If the queue already exists, <c>null</c>. |
| | 508 | | /// </returns> |
| | 509 | | /// <remarks> |
| | 510 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 511 | | /// a failure occurs. |
| | 512 | | /// </remarks> |
| | 513 | | public virtual async Task<Response> CreateIfNotExistsAsync( |
| | 514 | | Metadata metadata = default, |
| | 515 | | CancellationToken cancellationToken = default) => |
| 8 | 516 | | await CreateIfNotExistsInternal( |
| 8 | 517 | | metadata, |
| 8 | 518 | | async: true, |
| 8 | 519 | | cancellationToken).ConfigureAwait(false); |
| | 520 | |
|
| | 521 | | /// <summary> |
| | 522 | | /// The <see cref="CreateIfNotExistsInternal"/> |
| | 523 | | /// operation creates a new queue under the specified account. |
| | 524 | | /// If the queue already exists, it is not changed. |
| | 525 | | /// |
| | 526 | | /// For more information, see |
| | 527 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-queue4"> |
| | 528 | | /// Create Queue</see>. |
| | 529 | | /// </summary> |
| | 530 | | /// <param name="metadata"> |
| | 531 | | /// Optional custom metadata to set for this queue. |
| | 532 | | /// </param> |
| | 533 | | /// <param name="async"> |
| | 534 | | /// Whether to invoke the operation asynchronously. |
| | 535 | | /// </param> |
| | 536 | | /// <param name="cancellationToken"> |
| | 537 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 538 | | /// notifications that the operation should be cancelled. |
| | 539 | | /// </param> |
| | 540 | | /// <returns> |
| | 541 | | /// If the queue does not already exist, a <see cref="Response"/> |
| | 542 | | /// describing the newly created queue. If the queue already exists, <c>null</c>. |
| | 543 | | /// </returns> |
| | 544 | | /// <remarks> |
| | 545 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 546 | | /// a failure occurs. |
| | 547 | | /// </remarks> |
| | 548 | | private async Task<Response> CreateIfNotExistsInternal( |
| | 549 | | Metadata metadata, |
| | 550 | | bool async, |
| | 551 | | CancellationToken cancellationToken) |
| | 552 | | { |
| 16 | 553 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 554 | | { |
| | 555 | | Pipeline.LogMethodEnter( |
| | 556 | | nameof(QueueClient), |
| | 557 | | message: |
| | 558 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 559 | | $"{nameof(metadata)}: {metadata}"); |
| | 560 | | Response response; |
| | 561 | | try |
| | 562 | | { |
| 16 | 563 | | response = await CreateInternal( |
| 16 | 564 | | metadata, |
| 16 | 565 | | async, |
| 16 | 566 | | cancellationToken, |
| 16 | 567 | | $"{nameof(QueueClient)}.{nameof(CreateIfNotExists)}") |
| 16 | 568 | | .ConfigureAwait(false); |
| | 569 | |
|
| 8 | 570 | | if (response.Status == Constants.Queue.StatusCodeNoContent) |
| | 571 | | { |
| 4 | 572 | | response = default; |
| | 573 | | } |
| 8 | 574 | | } |
| | 575 | | catch (RequestFailedException storageRequestFailedException) |
| 8 | 576 | | when (storageRequestFailedException.ErrorCode == QueueErrorCode.QueueAlreadyExists) |
| | 577 | | { |
| 4 | 578 | | response = default; |
| 4 | 579 | | } |
| 4 | 580 | | catch (Exception ex) |
| | 581 | | { |
| | 582 | | Pipeline.LogException(ex); |
| 4 | 583 | | throw; |
| | 584 | | } |
| | 585 | | finally |
| | 586 | | { |
| | 587 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 588 | | } |
| 12 | 589 | | return response; |
| | 590 | | } |
| 12 | 591 | | } |
| | 592 | | #endregion CreateIfNotExists |
| | 593 | |
|
| | 594 | | #region Exists |
| | 595 | | /// <summary> |
| | 596 | | /// The <see cref="Exists"/> operation can be called on a |
| | 597 | | /// <see cref="QueueClient"/> to see if the associated queue |
| | 598 | | /// exists on the storage account in the storage service. |
| | 599 | | /// </summary> |
| | 600 | | /// <param name="cancellationToken"> |
| | 601 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 602 | | /// notifications that the operation should be cancelled. |
| | 603 | | /// </param> |
| | 604 | | /// <returns> |
| | 605 | | /// Returns true if the queue exists. |
| | 606 | | /// </returns> |
| | 607 | | /// <remarks> |
| | 608 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 609 | | /// a failure occurs. |
| | 610 | | /// </remarks> |
| | 611 | | public virtual Response<bool> Exists( |
| | 612 | | CancellationToken cancellationToken = default) => |
| 6 | 613 | | ExistsInternal( |
| 6 | 614 | | async: false, |
| 6 | 615 | | cancellationToken).EnsureCompleted(); |
| | 616 | |
|
| | 617 | | /// <summary> |
| | 618 | | /// The <see cref="ExistsAsync"/> operation can be called on a |
| | 619 | | /// <see cref="QueueClient"/> to see if the associated queue |
| | 620 | | /// exists on the storage account in the storage service. |
| | 621 | | /// </summary> |
| | 622 | | /// <param name="cancellationToken"> |
| | 623 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 624 | | /// notifications that the operation should be cancelled. |
| | 625 | | /// </param> |
| | 626 | | /// <returns> |
| | 627 | | /// Returns true if the queue exists. |
| | 628 | | /// </returns> |
| | 629 | | /// <remarks> |
| | 630 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 631 | | /// a failure occurs. |
| | 632 | | /// </remarks> |
| | 633 | | public virtual async Task<Response<bool>> ExistsAsync( |
| | 634 | | CancellationToken cancellationToken = default) => |
| 6 | 635 | | await ExistsInternal( |
| 6 | 636 | | async: true, |
| 6 | 637 | | cancellationToken).ConfigureAwait(false); |
| | 638 | |
|
| | 639 | | /// <summary> |
| | 640 | | /// The <see cref="ExistsInternal"/> operation can be called on a |
| | 641 | | /// <see cref="QueueClient"/> to see if the associated queue |
| | 642 | | /// exists on the storage account in the storage service. |
| | 643 | | /// </summary> |
| | 644 | | /// <param name="async"> |
| | 645 | | /// Whether to invoke the operation asynchronously. |
| | 646 | | /// </param> |
| | 647 | | /// <param name="cancellationToken"> |
| | 648 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 649 | | /// notifications that the operation should be cancelled. |
| | 650 | | /// </param> |
| | 651 | | /// <returns> |
| | 652 | | /// Returns true if the queue exists. |
| | 653 | | /// </returns> |
| | 654 | | /// <remarks> |
| | 655 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 656 | | /// a failure occurs. |
| | 657 | | /// </remarks> |
| | 658 | | private async Task<Response<bool>> ExistsInternal( |
| | 659 | | bool async, |
| | 660 | | CancellationToken cancellationToken) |
| | 661 | | { |
| 12 | 662 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 663 | | { |
| | 664 | | Pipeline.LogMethodEnter( |
| | 665 | | nameof(QueueClient), |
| | 666 | | message: |
| | 667 | | $"{nameof(Uri)}: {Uri}"); |
| | 668 | |
|
| | 669 | | try |
| | 670 | | { |
| 12 | 671 | | Response<QueueProperties> response = await GetPropertiesInternal( |
| 12 | 672 | | async: async, |
| 12 | 673 | | operationName: $"{nameof(QueueClient)}.{nameof(Exists)}", |
| 12 | 674 | | cancellationToken: cancellationToken) |
| 12 | 675 | | .ConfigureAwait(false); |
| | 676 | |
|
| 4 | 677 | | return Response.FromValue(true, response.GetRawResponse()); |
| | 678 | | } |
| | 679 | | catch (RequestFailedException storageRequestFailedException) |
| 8 | 680 | | when (storageRequestFailedException.ErrorCode == QueueErrorCode.QueueNotFound) |
| | 681 | | { |
| 4 | 682 | | return Response.FromValue(false, default); |
| | 683 | | } |
| 4 | 684 | | catch (Exception ex) |
| | 685 | | { |
| | 686 | | Pipeline.LogException(ex); |
| 4 | 687 | | throw; |
| | 688 | | } |
| | 689 | | finally |
| | 690 | | { |
| | 691 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 692 | | } |
| | 693 | | } |
| 8 | 694 | | } |
| | 695 | | #endregion Exists |
| | 696 | |
|
| | 697 | | #region DeleteIfExists |
| | 698 | | /// <summary> |
| | 699 | | /// The <see cref="DeleteIfExists"/> operation deletes the specified |
| | 700 | | /// queue if it exists. |
| | 701 | | /// |
| | 702 | | /// For more information, see |
| | 703 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/delete-queue3"> |
| | 704 | | /// Delete Queue</see>. |
| | 705 | | /// </summary> |
| | 706 | | /// <param name="cancellationToken"> |
| | 707 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 708 | | /// notifications that the operation should be cancelled. |
| | 709 | | /// </param> |
| | 710 | | /// <returns> |
| | 711 | | /// A <see cref="Response"/> Returns true if queue exists and was |
| | 712 | | /// deleted, return false otherwise. |
| | 713 | | /// </returns> |
| | 714 | | /// <remarks> |
| | 715 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 716 | | /// a failure occurs. |
| | 717 | | /// </remarks> |
| | 718 | | public virtual Response<bool> DeleteIfExists( |
| | 719 | | CancellationToken cancellationToken = default) => |
| 6 | 720 | | DeleteIfExistsInternal( |
| 6 | 721 | | async: false, |
| 6 | 722 | | cancellationToken).EnsureCompleted(); |
| | 723 | |
|
| | 724 | | /// <summary> |
| | 725 | | /// The <see cref="DeleteIfExistsAsync"/> operation deletes the specified |
| | 726 | | /// queue if it exists. |
| | 727 | | /// |
| | 728 | | /// For more information, see |
| | 729 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/delete-queue3"> |
| | 730 | | /// Delete Queue</see>. |
| | 731 | | /// </summary> |
| | 732 | | /// <param name="cancellationToken"> |
| | 733 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 734 | | /// notifications that the operation should be cancelled. |
| | 735 | | /// </param> |
| | 736 | | /// <returns> |
| | 737 | | /// A <see cref="Response"/> Returns true if queue exists and was |
| | 738 | | /// deleted, return false otherwise. |
| | 739 | | /// </returns> |
| | 740 | | /// <remarks> |
| | 741 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 742 | | /// a failure occurs. |
| | 743 | | /// </remarks> |
| | 744 | | public virtual async Task<Response<bool>> DeleteIfExistsAsync( |
| | 745 | | CancellationToken cancellationToken = default) => |
| 6 | 746 | | await DeleteIfExistsInternal( |
| 6 | 747 | | async: true, |
| 6 | 748 | | cancellationToken).ConfigureAwait(false); |
| | 749 | |
|
| | 750 | | /// <summary> |
| | 751 | | /// The <see cref="DeleteIfExistsInternal"/> operation deletes the specified |
| | 752 | | /// queue if it exists. |
| | 753 | | /// |
| | 754 | | /// For more information, see |
| | 755 | | /// <see href="https://docs.microsoft.com/en-us/rest/api/storageservices/delete-queue3"> |
| | 756 | | /// Delete Queue</see>. |
| | 757 | | /// </summary> |
| | 758 | | /// <param name="async"> |
| | 759 | | /// Whether to invoke the operation asynchronously. |
| | 760 | | /// </param> |
| | 761 | | /// <param name="cancellationToken"> |
| | 762 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 763 | | /// notifications that the operation should be cancelled. |
| | 764 | | /// </param> |
| | 765 | | /// <returns> |
| | 766 | | /// A <see cref="Response"/> Returns true if queue exists and was |
| | 767 | | /// deleted, return false otherwise. |
| | 768 | | /// </returns> |
| | 769 | | /// <remarks> |
| | 770 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 771 | | /// a failure occurs. |
| | 772 | | /// </remarks> |
| | 773 | | private async Task<Response<bool>> DeleteIfExistsInternal( |
| | 774 | | bool async, |
| | 775 | | CancellationToken cancellationToken) |
| | 776 | | { |
| 12 | 777 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 778 | | { |
| | 779 | | Pipeline.LogMethodEnter( |
| | 780 | | nameof(QueueClient), |
| | 781 | | message: |
| | 782 | | $"{nameof(Uri)}: {Uri}"); |
| | 783 | | try |
| | 784 | | { |
| 12 | 785 | | Response response = await DeleteInternal( |
| 12 | 786 | | async, |
| 12 | 787 | | cancellationToken, |
| 12 | 788 | | $"{nameof(QueueClient)}.{nameof(DeleteIfExists)}") |
| 12 | 789 | | .ConfigureAwait(false); |
| 4 | 790 | | return Response.FromValue(true, response); |
| | 791 | | } |
| | 792 | | catch (RequestFailedException storageRequestFailedException) |
| 8 | 793 | | when (storageRequestFailedException.ErrorCode == QueueErrorCode.QueueNotFound) |
| | 794 | | { |
| 4 | 795 | | return Response.FromValue(false, default); |
| | 796 | | } |
| 4 | 797 | | catch (Exception ex) |
| | 798 | | { |
| | 799 | | Pipeline.LogException(ex); |
| 4 | 800 | | throw; |
| | 801 | | } |
| | 802 | | finally |
| | 803 | | { |
| | 804 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 805 | | } |
| | 806 | | } |
| 8 | 807 | | } |
| | 808 | | #endregion DeleteIfExists |
| | 809 | |
|
| | 810 | | #region Delete |
| | 811 | | /// <summary> |
| | 812 | | /// Deletes a queue. |
| | 813 | | /// |
| | 814 | | /// For more information, see |
| | 815 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-queue3"> |
| | 816 | | /// Delete Queue</see>. |
| | 817 | | /// </summary> |
| | 818 | | /// <param name="cancellationToken"> |
| | 819 | | /// <see cref="CancellationToken"/> |
| | 820 | | /// </param> |
| | 821 | | /// <returns> |
| | 822 | | /// <see cref="Response"/> |
| | 823 | | /// </returns> |
| | 824 | | public virtual Response Delete( |
| | 825 | | CancellationToken cancellationToken = default) => |
| 100 | 826 | | DeleteInternal( |
| 100 | 827 | | false, // async |
| 100 | 828 | | cancellationToken) |
| 100 | 829 | | .EnsureCompleted(); |
| | 830 | |
|
| | 831 | | /// <summary> |
| | 832 | | /// Deletes a queue. |
| | 833 | | /// |
| | 834 | | /// For more information, see |
| | 835 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-queue3"> |
| | 836 | | /// Delete Queue</see>. |
| | 837 | | /// </summary> |
| | 838 | | /// <param name="cancellationToken"> |
| | 839 | | /// <see cref="CancellationToken"/> |
| | 840 | | /// </param> |
| | 841 | | /// <returns> |
| | 842 | | /// <see cref="Response"/> |
| | 843 | | /// </returns> |
| | 844 | | public virtual async Task<Response> DeleteAsync( |
| | 845 | | CancellationToken cancellationToken = default) => |
| 104 | 846 | | await DeleteInternal( |
| 104 | 847 | | true, // async |
| 104 | 848 | | cancellationToken) |
| 104 | 849 | | .ConfigureAwait(false); |
| | 850 | |
|
| | 851 | | /// <summary> |
| | 852 | | /// Deletes a queue. |
| | 853 | | /// |
| | 854 | | /// For more information, see |
| | 855 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-queue3"> |
| | 856 | | /// Delete Queue</see>. |
| | 857 | | /// </summary> |
| | 858 | | /// <param name="async"> |
| | 859 | | /// Whether to invoke the operation asynchronously. |
| | 860 | | /// </param> |
| | 861 | | /// <param name="cancellationToken"> |
| | 862 | | /// <see cref="CancellationToken"/> |
| | 863 | | /// </param> |
| | 864 | | /// <param name="operationName"> |
| | 865 | | /// Optional. To indicate if the name of the operation. |
| | 866 | | /// </param> |
| | 867 | | /// <returns> |
| | 868 | | /// <see cref="Response"/> |
| | 869 | | /// </returns> |
| | 870 | | private async Task<Response> DeleteInternal( |
| | 871 | | bool async, |
| | 872 | | CancellationToken cancellationToken, |
| | 873 | | string operationName = default) |
| | 874 | | { |
| 216 | 875 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 876 | | { |
| | 877 | | Pipeline.LogMethodEnter( |
| | 878 | | nameof(QueueClient), |
| | 879 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 880 | | try |
| | 881 | | { |
| 216 | 882 | | return await QueueRestClient.Queue.DeleteAsync( |
| 216 | 883 | | ClientDiagnostics, |
| 216 | 884 | | Pipeline, |
| 216 | 885 | | Uri, |
| 216 | 886 | | version: Version.ToVersionString(), |
| 216 | 887 | | async: async, |
| 216 | 888 | | operationName: operationName ?? $"{nameof(QueueClient)}.{nameof(Delete)}", |
| 216 | 889 | | cancellationToken: cancellationToken) |
| 216 | 890 | | .ConfigureAwait(false); |
| | 891 | | } |
| 12 | 892 | | catch (Exception ex) |
| | 893 | | { |
| | 894 | | Pipeline.LogException(ex); |
| 12 | 895 | | throw; |
| | 896 | | } |
| | 897 | | finally |
| | 898 | | { |
| | 899 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 900 | | } |
| | 901 | | } |
| 204 | 902 | | } |
| | 903 | | #endregion Delete |
| | 904 | |
|
| | 905 | | #region GetProperties |
| | 906 | | /// <summary> |
| | 907 | | /// Retrieves queue properties and user-defined metadata and properties on the specified queue. |
| | 908 | | /// Metadata is associated with the queue as name-values pairs. |
| | 909 | | /// |
| | 910 | | /// For more information, see |
| | 911 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-metadata"> |
| | 912 | | /// Get Queue Metadata</see>. |
| | 913 | | /// </summary> |
| | 914 | | /// <param name="cancellationToken"> |
| | 915 | | /// <see cref="CancellationToken"/> |
| | 916 | | /// </param> |
| | 917 | | /// <returns> |
| | 918 | | /// <see cref="Response{QueueProperties}"/> |
| | 919 | | /// </returns> |
| | 920 | | public virtual Response<QueueProperties> GetProperties( |
| | 921 | | CancellationToken cancellationToken = default) => |
| 14 | 922 | | GetPropertiesInternal( |
| 14 | 923 | | false, // async |
| 14 | 924 | | cancellationToken) |
| 14 | 925 | | .EnsureCompleted(); |
| | 926 | |
|
| | 927 | | /// <summary> |
| | 928 | | /// Retrieves queue properties and user-defined metadata and properties on the specified queue. |
| | 929 | | /// Metadata is associated with the queue as name-values pairs. |
| | 930 | | /// |
| | 931 | | /// For more information, see |
| | 932 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-metadata"> |
| | 933 | | /// Get Queue Metadata</see>. |
| | 934 | | /// </summary> |
| | 935 | | /// <param name="cancellationToken"> |
| | 936 | | /// <see cref="CancellationToken"/> |
| | 937 | | /// </param> |
| | 938 | | /// <returns> |
| | 939 | | /// <see cref="Response{QueueProperties}"/> |
| | 940 | | /// </returns> |
| | 941 | | public virtual async Task<Response<QueueProperties>> GetPropertiesAsync( |
| | 942 | | CancellationToken cancellationToken = default) => |
| 30 | 943 | | await GetPropertiesInternal( |
| 30 | 944 | | true, // async |
| 30 | 945 | | cancellationToken) |
| 30 | 946 | | .ConfigureAwait(false); |
| | 947 | |
|
| | 948 | | /// <summary> |
| | 949 | | /// Retrieves queue properties and user-defined metadata and properties on the specified queue. |
| | 950 | | /// Metadata is associated with the queue as name-values pairs. |
| | 951 | | /// |
| | 952 | | /// For more information, see |
| | 953 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-metadata"> |
| | 954 | | /// Get Queue Metadata</see>. |
| | 955 | | /// </summary> |
| | 956 | | /// <param name="async"> |
| | 957 | | /// Whether to invoke the operation asynchronously. |
| | 958 | | /// </param> |
| | 959 | | /// <param name="cancellationToken"> |
| | 960 | | /// <see cref="CancellationToken"/> |
| | 961 | | /// </param> |
| | 962 | | /// <param name="operationName"> |
| | 963 | | /// Optional. To indicate if the name of the operation. |
| | 964 | | /// </param> |
| | 965 | | /// <returns> |
| | 966 | | /// <see cref="Response{QueueProperties}"/> |
| | 967 | | /// </returns> |
| | 968 | | private async Task<Response<QueueProperties>> GetPropertiesInternal( |
| | 969 | | bool async, |
| | 970 | | CancellationToken cancellationToken, |
| | 971 | | string operationName = default) |
| | 972 | | { |
| 56 | 973 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 974 | | { |
| | 975 | | Pipeline.LogMethodEnter( |
| | 976 | | nameof(QueueClient), |
| | 977 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 978 | | try |
| | 979 | | { |
| 56 | 980 | | return await QueueRestClient.Queue.GetPropertiesAsync( |
| 56 | 981 | | ClientDiagnostics, |
| 56 | 982 | | Pipeline, |
| 56 | 983 | | Uri, |
| 56 | 984 | | version: Version.ToVersionString(), |
| 56 | 985 | | async: async, |
| 56 | 986 | | operationName: operationName ?? $"{nameof(QueueClient)}.{nameof(GetProperties)}", |
| 56 | 987 | | cancellationToken: cancellationToken) |
| 56 | 988 | | .ConfigureAwait(false); |
| | 989 | | } |
| 16 | 990 | | catch (Exception ex) |
| | 991 | | { |
| | 992 | | Pipeline.LogException(ex); |
| 16 | 993 | | throw; |
| | 994 | | } |
| | 995 | | finally |
| | 996 | | { |
| | 997 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 998 | | } |
| | 999 | | } |
| 40 | 1000 | | } |
| | 1001 | | #endregion GetProperties |
| | 1002 | |
|
| | 1003 | | #region SetMetadata |
| | 1004 | | /// <summary> |
| | 1005 | | /// Sets user-defined metadata on the specified queue. Metadata is associated with the queue as name-value pairs |
| | 1006 | | /// |
| | 1007 | | /// For more information, see |
| | 1008 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-metadata"> |
| | 1009 | | /// Set Queue Metadata</see>. |
| | 1010 | | /// </summary> |
| | 1011 | | /// <param name="metadata"> |
| | 1012 | | /// <see cref="Metadata"/> |
| | 1013 | | /// </param> |
| | 1014 | | /// <param name="cancellationToken"> |
| | 1015 | | /// <see cref="CancellationToken"/> |
| | 1016 | | /// </param> |
| | 1017 | | /// <returns> |
| | 1018 | | /// <see cref="Response"/> |
| | 1019 | | /// </returns> |
| | 1020 | | public virtual Response SetMetadata( |
| | 1021 | | Metadata metadata, |
| | 1022 | | CancellationToken cancellationToken = default) => |
| 6 | 1023 | | SetMetadataInternal( |
| 6 | 1024 | | metadata, |
| 6 | 1025 | | false, // async |
| 6 | 1026 | | cancellationToken) |
| 6 | 1027 | | .EnsureCompleted(); |
| | 1028 | |
|
| | 1029 | | /// <summary> |
| | 1030 | | /// Sets user-defined metadata on the specified queue. Metadata is associated with the queue as name-value pairs |
| | 1031 | | /// |
| | 1032 | | /// For more information, see |
| | 1033 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-metadata"> |
| | 1034 | | /// Set Queue Metadata</see>. |
| | 1035 | | /// </summary> |
| | 1036 | | /// <param name="metadata"> |
| | 1037 | | /// <see cref="Metadata"/> |
| | 1038 | | /// </param> |
| | 1039 | | /// <param name="cancellationToken"> |
| | 1040 | | /// <see cref="CancellationToken"/> |
| | 1041 | | /// </param> |
| | 1042 | | /// <returns> |
| | 1043 | | /// <see cref="Response"/> |
| | 1044 | | /// </returns> |
| | 1045 | | public virtual async Task<Response> SetMetadataAsync( |
| | 1046 | | Metadata metadata, |
| | 1047 | | CancellationToken cancellationToken = default) => |
| 6 | 1048 | | await SetMetadataInternal( |
| 6 | 1049 | | metadata, |
| 6 | 1050 | | true, // async |
| 6 | 1051 | | cancellationToken) |
| 6 | 1052 | | .ConfigureAwait(false); |
| | 1053 | |
|
| | 1054 | | /// <summary> |
| | 1055 | | /// Sets user-defined metadata on the specified queue. Metadata is associated with the queue as name-value pairs |
| | 1056 | | /// |
| | 1057 | | /// For more information, see |
| | 1058 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-metadata"> |
| | 1059 | | /// Set Queue Metadata</see>. |
| | 1060 | | /// </summary> |
| | 1061 | | /// <param name="metadata"> |
| | 1062 | | /// <see cref="Metadata"/> |
| | 1063 | | /// </param> |
| | 1064 | | /// <param name="async"> |
| | 1065 | | /// Whether to invoke the operation asynchronously. |
| | 1066 | | /// </param> |
| | 1067 | | /// <param name="cancellationToken"> |
| | 1068 | | /// <see cref="CancellationToken"/> |
| | 1069 | | /// </param> |
| | 1070 | | /// <returns> |
| | 1071 | | /// <see cref="Response"/> |
| | 1072 | | /// </returns> |
| | 1073 | | private async Task<Response> SetMetadataInternal( |
| | 1074 | | Metadata metadata, |
| | 1075 | | bool async, |
| | 1076 | | CancellationToken cancellationToken) |
| | 1077 | | { |
| 12 | 1078 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1079 | | { |
| | 1080 | | Pipeline.LogMethodEnter( |
| | 1081 | | nameof(QueueClient), |
| | 1082 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1083 | | try |
| | 1084 | | { |
| 12 | 1085 | | return await QueueRestClient.Queue.SetMetadataAsync( |
| 12 | 1086 | | ClientDiagnostics, |
| 12 | 1087 | | Pipeline, |
| 12 | 1088 | | Uri, |
| 12 | 1089 | | version: Version.ToVersionString(), |
| 12 | 1090 | | metadata: metadata, |
| 12 | 1091 | | async: async, |
| 12 | 1092 | | cancellationToken: cancellationToken) |
| 12 | 1093 | | .ConfigureAwait(false); |
| | 1094 | | } |
| 4 | 1095 | | catch (Exception ex) |
| | 1096 | | { |
| | 1097 | | Pipeline.LogException(ex); |
| 4 | 1098 | | throw; |
| | 1099 | | } |
| | 1100 | | finally |
| | 1101 | | { |
| | 1102 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1103 | | } |
| | 1104 | | } |
| 8 | 1105 | | } |
| | 1106 | | #endregion SetMetadata |
| | 1107 | |
|
| | 1108 | | #region GetAccessPolicy |
| | 1109 | | /// <summary> |
| | 1110 | | /// Returns details about any stored access policies specified on the queue that may be used with |
| | 1111 | | /// Shared Access Signatures. |
| | 1112 | | /// |
| | 1113 | | /// For more information, see |
| | 1114 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-acl"> |
| | 1115 | | /// Get Queue ACL</see>. |
| | 1116 | | /// </summary> |
| | 1117 | | /// <param name="cancellationToken"> |
| | 1118 | | /// <see cref="CancellationToken"/> |
| | 1119 | | /// </param> |
| | 1120 | | /// <returns> |
| | 1121 | | /// <see cref="Response{T}"/> of <see cref="IEnumerable{SignedIdentifier}" /> |
| | 1122 | | /// </returns> |
| | 1123 | | public virtual Response<IEnumerable<QueueSignedIdentifier>> GetAccessPolicy( |
| | 1124 | | CancellationToken cancellationToken = default) => |
| 4 | 1125 | | GetAccessPolicyInternal( |
| 4 | 1126 | | false, // async |
| 4 | 1127 | | cancellationToken) |
| 4 | 1128 | | .EnsureCompleted(); |
| | 1129 | |
|
| | 1130 | | /// <summary> |
| | 1131 | | /// Returns details about any stored access policies specified on the queue that may be used with |
| | 1132 | | /// Shared Access Signatures. |
| | 1133 | | /// |
| | 1134 | | /// For more information, see |
| | 1135 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-acl"> |
| | 1136 | | /// Get Queue ACL</see>. |
| | 1137 | | /// </summary> |
| | 1138 | | /// <param name="cancellationToken"> |
| | 1139 | | /// <see cref="CancellationToken"/> |
| | 1140 | | /// </param> |
| | 1141 | | /// <returns> |
| | 1142 | | /// <see cref="Response{T}"/> of <see cref="IEnumerable{SignedIdentifier}" /> |
| | 1143 | | /// </returns> |
| | 1144 | | public virtual async Task<Response<IEnumerable<QueueSignedIdentifier>>> GetAccessPolicyAsync( |
| | 1145 | | CancellationToken cancellationToken = default) => |
| 4 | 1146 | | await GetAccessPolicyInternal( |
| 4 | 1147 | | true, // async |
| 4 | 1148 | | cancellationToken) |
| 4 | 1149 | | .ConfigureAwait(false); |
| | 1150 | |
|
| | 1151 | | /// <summary> |
| | 1152 | | /// Returns details about any stored access policies specified on the queue that may be used with |
| | 1153 | | /// Shared Access Signatures. |
| | 1154 | | /// |
| | 1155 | | /// For more information, see |
| | 1156 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-queue-acl"> |
| | 1157 | | /// Get Queue ACL</see>. |
| | 1158 | | /// </summary> |
| | 1159 | | /// <param name="async"> |
| | 1160 | | /// Whether to invoke the operation asynchronously. |
| | 1161 | | /// </param> |
| | 1162 | | /// <param name="cancellationToken"> |
| | 1163 | | /// <see cref="CancellationToken"/> |
| | 1164 | | /// </param> |
| | 1165 | | /// <returns> |
| | 1166 | | /// <see cref="Response{T}"/> of <see cref="IEnumerable{SignedIdentifier}" /> |
| | 1167 | | /// </returns> |
| | 1168 | | private async Task<Response<IEnumerable<QueueSignedIdentifier>>> GetAccessPolicyInternal( |
| | 1169 | | bool async, |
| | 1170 | | CancellationToken cancellationToken) |
| | 1171 | | { |
| 8 | 1172 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1173 | | { |
| | 1174 | | Pipeline.LogMethodEnter( |
| | 1175 | | nameof(QueueClient), |
| | 1176 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1177 | | try |
| | 1178 | | { |
| 8 | 1179 | | return await QueueRestClient.Queue.GetAccessPolicyAsync( |
| 8 | 1180 | | ClientDiagnostics, |
| 8 | 1181 | | Pipeline, |
| 8 | 1182 | | Uri, |
| 8 | 1183 | | version: Version.ToVersionString(), |
| 8 | 1184 | | async: async, |
| 8 | 1185 | | cancellationToken: cancellationToken) |
| 8 | 1186 | | .ConfigureAwait(false); |
| | 1187 | | } |
| 4 | 1188 | | catch (Exception ex) |
| | 1189 | | { |
| | 1190 | | Pipeline.LogException(ex); |
| 4 | 1191 | | throw; |
| | 1192 | | } |
| | 1193 | | finally |
| | 1194 | | { |
| | 1195 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1196 | | } |
| | 1197 | | } |
| 4 | 1198 | | } |
| | 1199 | | #endregion GetAccessPolicy |
| | 1200 | |
|
| | 1201 | | #region SetAccessPolicy |
| | 1202 | | /// <summary> |
| | 1203 | | /// SetAccessPolicyAsync sets stored access policies for the queue that may be used with Shared Access Signature |
| | 1204 | | /// |
| | 1205 | | /// For more information, see |
| | 1206 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-acl"> |
| | 1207 | | /// Set Queue ACL</see>. |
| | 1208 | | /// </summary> |
| | 1209 | | /// <param name="permissions"> |
| | 1210 | | /// IEnumerable of <see cref="QueueSignedIdentifier"/> |
| | 1211 | | /// </param> |
| | 1212 | | /// <param name="cancellationToken"> |
| | 1213 | | /// <see cref="CancellationToken"/> |
| | 1214 | | /// </param> |
| | 1215 | | /// <returns> |
| | 1216 | | /// <see cref="Response"/> |
| | 1217 | | /// </returns> |
| | 1218 | | public virtual Response SetAccessPolicy( |
| | 1219 | | IEnumerable<QueueSignedIdentifier> permissions, |
| | 1220 | | CancellationToken cancellationToken = default) => |
| 8 | 1221 | | SetAccessPolicyInternal( |
| 8 | 1222 | | permissions, |
| 8 | 1223 | | false, // async |
| 8 | 1224 | | cancellationToken) |
| 8 | 1225 | | .EnsureCompleted(); |
| | 1226 | |
|
| | 1227 | | /// <summary> |
| | 1228 | | /// SetAccessPolicyAsync sets stored access policies for the queue that may be used with Shared Access Signature |
| | 1229 | | /// |
| | 1230 | | /// For more information, see |
| | 1231 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-acl"> |
| | 1232 | | /// Set Queue ACL</see>. |
| | 1233 | | /// </summary> |
| | 1234 | | /// <param name="permissions"> |
| | 1235 | | /// IEnumerable of <see cref="QueueSignedIdentifier"/> |
| | 1236 | | /// </param> |
| | 1237 | | /// <param name="cancellationToken"> |
| | 1238 | | /// <see cref="CancellationToken"/> |
| | 1239 | | /// </param> |
| | 1240 | | /// <returns> |
| | 1241 | | /// <see cref="Response"/> |
| | 1242 | | /// </returns> |
| | 1243 | | public virtual async Task<Response> SetAccessPolicyAsync( |
| | 1244 | | IEnumerable<QueueSignedIdentifier> permissions, |
| | 1245 | | CancellationToken cancellationToken = default) => |
| 8 | 1246 | | await SetAccessPolicyInternal( |
| 8 | 1247 | | permissions, |
| 8 | 1248 | | true, // async |
| 8 | 1249 | | cancellationToken) |
| 8 | 1250 | | .ConfigureAwait(false); |
| | 1251 | |
|
| | 1252 | | /// <summary> |
| | 1253 | | /// SetAccessPolicyInternal sets stored access policies for the queue that may be used with Shared Access Signat |
| | 1254 | | /// |
| | 1255 | | /// For more information, see |
| | 1256 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-queue-acl"> |
| | 1257 | | /// Set Queue ACL</see>. |
| | 1258 | | /// </summary> |
| | 1259 | | /// <param name="permissions"> |
| | 1260 | | /// IEnumerable of <see cref="QueueSignedIdentifier"/> |
| | 1261 | | /// </param> |
| | 1262 | | /// <param name="async"> |
| | 1263 | | /// Whether to invoke the operation asynchronously. |
| | 1264 | | /// </param> |
| | 1265 | | /// <param name="cancellationToken"> |
| | 1266 | | /// <see cref="CancellationToken"/> |
| | 1267 | | /// </param> |
| | 1268 | | /// <returns> |
| | 1269 | | /// <see cref="Response"/> |
| | 1270 | | /// </returns> |
| | 1271 | | private async Task<Response> SetAccessPolicyInternal( |
| | 1272 | | IEnumerable<QueueSignedIdentifier> permissions, |
| | 1273 | | bool async, |
| | 1274 | | CancellationToken cancellationToken) |
| | 1275 | | { |
| 16 | 1276 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1277 | | { |
| | 1278 | | Pipeline.LogMethodEnter( |
| | 1279 | | nameof(QueueClient), |
| | 1280 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1281 | | try |
| | 1282 | | { |
| 16 | 1283 | | return await QueueRestClient.Queue.SetAccessPolicyAsync( |
| 16 | 1284 | | ClientDiagnostics, |
| 16 | 1285 | | Pipeline, |
| 16 | 1286 | | Uri, |
| 16 | 1287 | | version: Version.ToVersionString(), |
| 16 | 1288 | | permissions: permissions, |
| 16 | 1289 | | async: async, |
| 16 | 1290 | | cancellationToken: cancellationToken) |
| 16 | 1291 | | .ConfigureAwait(false); |
| | 1292 | | } |
| 4 | 1293 | | catch (Exception ex) |
| | 1294 | | { |
| | 1295 | | Pipeline.LogException(ex); |
| 4 | 1296 | | throw; |
| | 1297 | | } |
| | 1298 | | finally |
| | 1299 | | { |
| | 1300 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1301 | | } |
| | 1302 | | } |
| 12 | 1303 | | } |
| | 1304 | | #endregion SetAccessPolicy |
| | 1305 | |
|
| | 1306 | | #region ClearMessages |
| | 1307 | | /// <summary> |
| | 1308 | | /// Deletes all messages from a queue. |
| | 1309 | | /// |
| | 1310 | | /// For more information, see |
| | 1311 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/clear-messages"> |
| | 1312 | | /// Clear Messages</see>. |
| | 1313 | | /// </summary> |
| | 1314 | | /// <param name="cancellationToken"> |
| | 1315 | | /// <see cref="CancellationToken"/>. |
| | 1316 | | /// </param> |
| | 1317 | | /// <returns> |
| | 1318 | | /// <see cref="Response"/> |
| | 1319 | | /// </returns> |
| | 1320 | | public virtual Response ClearMessages( |
| | 1321 | | CancellationToken cancellationToken = default) => |
| 4 | 1322 | | ClearMessagesInternal( |
| 4 | 1323 | | false, // async |
| 4 | 1324 | | cancellationToken) |
| 4 | 1325 | | .EnsureCompleted(); |
| | 1326 | |
|
| | 1327 | | /// <summary> |
| | 1328 | | /// Deletes all messages from a queue. |
| | 1329 | | /// |
| | 1330 | | /// For more information, see |
| | 1331 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/clear-messages"> |
| | 1332 | | /// Clear Messages</see>. |
| | 1333 | | /// </summary> |
| | 1334 | | /// <param name="cancellationToken"> |
| | 1335 | | /// <see cref="CancellationToken"/>. |
| | 1336 | | /// </param> |
| | 1337 | | /// <returns> |
| | 1338 | | /// <see cref="Response"/> |
| | 1339 | | /// </returns> |
| | 1340 | | public virtual async Task<Response> ClearMessagesAsync( |
| | 1341 | | CancellationToken cancellationToken = default) => |
| 4 | 1342 | | await ClearMessagesInternal( |
| 4 | 1343 | | true, // async |
| 4 | 1344 | | cancellationToken) |
| 4 | 1345 | | .ConfigureAwait(false); |
| | 1346 | |
|
| | 1347 | | /// <summary> |
| | 1348 | | /// Deletes all messages from a queue. |
| | 1349 | | /// |
| | 1350 | | /// For more information, see |
| | 1351 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/clear-messages"> |
| | 1352 | | /// Clear Messages</see>. |
| | 1353 | | /// </summary> |
| | 1354 | | /// <param name="async"> |
| | 1355 | | /// Whether to invoke the operation asynchronously. |
| | 1356 | | /// </param> |
| | 1357 | | /// <param name="cancellationToken"> |
| | 1358 | | /// <see cref="CancellationToken"/>. |
| | 1359 | | /// </param> |
| | 1360 | | /// <returns> |
| | 1361 | | /// <see cref="Response"/> |
| | 1362 | | /// </returns> |
| | 1363 | | private async Task<Response> ClearMessagesInternal( |
| | 1364 | | bool async, |
| | 1365 | | CancellationToken cancellationToken) |
| | 1366 | | { |
| 8 | 1367 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1368 | | { |
| | 1369 | | Pipeline.LogMethodEnter( |
| | 1370 | | nameof(QueueClient), |
| | 1371 | | message: $"Uri: {MessagesUri}"); |
| | 1372 | | try |
| | 1373 | | { |
| 8 | 1374 | | return await QueueRestClient.Messages.ClearAsync( |
| 8 | 1375 | | ClientDiagnostics, |
| 8 | 1376 | | Pipeline, |
| 8 | 1377 | | MessagesUri, |
| 8 | 1378 | | version: Version.ToVersionString(), |
| 8 | 1379 | | async: async, |
| 8 | 1380 | | operationName: $"{nameof(QueueClient)}.{nameof(ClearMessages)}", |
| 8 | 1381 | | cancellationToken: cancellationToken) |
| 8 | 1382 | | .ConfigureAwait(false); |
| | 1383 | | } |
| 4 | 1384 | | catch (Exception ex) |
| | 1385 | | { |
| | 1386 | | Pipeline.LogException(ex); |
| 4 | 1387 | | throw; |
| | 1388 | | } |
| | 1389 | | finally |
| | 1390 | | { |
| | 1391 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1392 | | } |
| | 1393 | | } |
| 4 | 1394 | | } |
| | 1395 | | #endregion ClearMessages |
| | 1396 | |
|
| | 1397 | | #region SendMessage |
| | 1398 | | /// <summary> |
| | 1399 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1400 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1401 | | /// |
| | 1402 | | /// For more information, see |
| | 1403 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1404 | | /// Put Message</see>. |
| | 1405 | | /// </summary> |
| | 1406 | | /// <param name="messageText"> |
| | 1407 | | /// Message text. |
| | 1408 | | /// </param> |
| | 1409 | | /// <returns> |
| | 1410 | | /// <see cref="Response{SendReceipt}"/> |
| | 1411 | | /// </returns> |
| | 1412 | | public virtual Response<SendReceipt> SendMessage(string messageText) => |
| 46 | 1413 | | SendMessage( |
| 46 | 1414 | | messageText, |
| 46 | 1415 | | null); // Pass anything else so we don't recurse on this overload |
| | 1416 | |
|
| | 1417 | | /// <summary> |
| | 1418 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1419 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1420 | | /// |
| | 1421 | | /// For more information, see |
| | 1422 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1423 | | /// Put Message</see>. |
| | 1424 | | /// </summary> |
| | 1425 | | /// <param name="messageText"> |
| | 1426 | | /// Message text. |
| | 1427 | | /// </param> |
| | 1428 | | /// <returns> |
| | 1429 | | /// <see cref="Response{SendReceipt}"/> |
| | 1430 | | /// </returns> |
| | 1431 | | public virtual async Task<Response<SendReceipt>> SendMessageAsync(string messageText) => |
| 46 | 1432 | | await SendMessageAsync( |
| 46 | 1433 | | messageText, |
| 46 | 1434 | | null) // Pass anything else so we don't recurse on this overload |
| 46 | 1435 | | .ConfigureAwait(false); |
| | 1436 | |
|
| | 1437 | | /// <summary> |
| | 1438 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1439 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1440 | | /// |
| | 1441 | | /// For more information, see |
| | 1442 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1443 | | /// Put Message</see>. |
| | 1444 | | /// </summary> |
| | 1445 | | /// <param name="messageText"> |
| | 1446 | | /// Message text. |
| | 1447 | | /// </param> |
| | 1448 | | /// <param name="cancellationToken"> |
| | 1449 | | /// Optional <see cref="CancellationToken"/>. |
| | 1450 | | /// </param> |
| | 1451 | | /// <returns> |
| | 1452 | | /// <see cref="Response{SendReceipt}"/> |
| | 1453 | | /// </returns> |
| | 1454 | | public virtual Response<SendReceipt> SendMessage(string messageText, CancellationToken cancellationToken = defau |
| 0 | 1455 | | SendMessage( |
| 0 | 1456 | | messageText, |
| 0 | 1457 | | cancellationToken: cancellationToken, |
| 0 | 1458 | | visibilityTimeout: default); // Pass anything else so we don't recurse on this overload |
| | 1459 | |
|
| | 1460 | | /// <summary> |
| | 1461 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1462 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1463 | | /// |
| | 1464 | | /// For more information, see |
| | 1465 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1466 | | /// Put Message</see>. |
| | 1467 | | /// </summary> |
| | 1468 | | /// <param name="messageText"> |
| | 1469 | | /// Message text. |
| | 1470 | | /// </param> |
| | 1471 | | /// <param name="cancellationToken"> |
| | 1472 | | /// Optional <see cref="CancellationToken"/>. |
| | 1473 | | /// </param> |
| | 1474 | | /// <returns> |
| | 1475 | | /// <see cref="Response{SendReceipt}"/> |
| | 1476 | | /// </returns> |
| | 1477 | | public virtual async Task<Response<SendReceipt>> SendMessageAsync(string messageText, CancellationToken cancella |
| 0 | 1478 | | await SendMessageAsync(messageText, |
| 0 | 1479 | | cancellationToken: cancellationToken, |
| 0 | 1480 | | visibilityTimeout: default) // Pass anything else so we don't recurse on this overload |
| 0 | 1481 | | .ConfigureAwait(false); |
| | 1482 | |
|
| | 1483 | | /// <summary> |
| | 1484 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1485 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1486 | | /// |
| | 1487 | | /// For more information, see |
| | 1488 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1489 | | /// Put Message</see>. |
| | 1490 | | /// </summary> |
| | 1491 | | /// <param name="messageText"> |
| | 1492 | | /// Message text. |
| | 1493 | | /// </param> |
| | 1494 | | /// <param name="visibilityTimeout"> |
| | 1495 | | /// Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days. |
| | 1496 | | /// </param> |
| | 1497 | | /// <param name="timeToLive"> |
| | 1498 | | /// Optional. Specifies the time-to-live interval for the message |
| | 1499 | | /// </param> |
| | 1500 | | /// <param name="cancellationToken"> |
| | 1501 | | /// Optional <see cref="CancellationToken"/>. |
| | 1502 | | /// </param> |
| | 1503 | | /// <returns> |
| | 1504 | | /// <see cref="Response{SendReceipt}"/> |
| | 1505 | | /// </returns> |
| | 1506 | | public virtual Response<SendReceipt> SendMessage( |
| | 1507 | | string messageText, |
| | 1508 | | TimeSpan? visibilityTimeout = default, |
| | 1509 | | TimeSpan? timeToLive = default, |
| | 1510 | | CancellationToken cancellationToken = default) => |
| 52 | 1511 | | SendMessageInternal( |
| 52 | 1512 | | messageText, |
| 52 | 1513 | | visibilityTimeout, |
| 52 | 1514 | | timeToLive, |
| 52 | 1515 | | false, // async |
| 52 | 1516 | | cancellationToken) |
| 52 | 1517 | | .EnsureCompleted(); |
| | 1518 | |
|
| | 1519 | | /// <summary> |
| | 1520 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1521 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1522 | | /// |
| | 1523 | | /// For more information, see |
| | 1524 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1525 | | /// Put Message</see>. |
| | 1526 | | /// </summary> |
| | 1527 | | /// <param name="messageText"> |
| | 1528 | | /// Message text. |
| | 1529 | | /// </param> |
| | 1530 | | /// <param name="visibilityTimeout"> |
| | 1531 | | /// Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days. |
| | 1532 | | /// </param> |
| | 1533 | | /// <param name="timeToLive"> |
| | 1534 | | /// Optional. Specifies the time-to-live interval for the message |
| | 1535 | | /// </param> |
| | 1536 | | /// <param name="cancellationToken"> |
| | 1537 | | /// Optional <see cref="CancellationToken"/>. |
| | 1538 | | /// </param> |
| | 1539 | | /// <returns> |
| | 1540 | | /// <see cref="Response{SendReceipt}"/> |
| | 1541 | | /// </returns> |
| | 1542 | | public virtual async Task<Response<SendReceipt>> SendMessageAsync( |
| | 1543 | | string messageText, |
| | 1544 | | TimeSpan? visibilityTimeout = default, |
| | 1545 | | TimeSpan? timeToLive = default, |
| | 1546 | | CancellationToken cancellationToken = default) => |
| 52 | 1547 | | await SendMessageInternal( |
| 52 | 1548 | | messageText, |
| 52 | 1549 | | visibilityTimeout, |
| 52 | 1550 | | timeToLive, |
| 52 | 1551 | | true, // async |
| 52 | 1552 | | cancellationToken) |
| 52 | 1553 | | .ConfigureAwait(false); |
| | 1554 | |
|
| | 1555 | | /// <summary> |
| | 1556 | | /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be i |
| | 1557 | | /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in siz |
| | 1558 | | /// |
| | 1559 | | /// For more information, see |
| | 1560 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/put-message"> |
| | 1561 | | /// Put Message</see>. |
| | 1562 | | /// </summary> |
| | 1563 | | /// <param name="messageText"> |
| | 1564 | | /// Message text. |
| | 1565 | | /// </param> |
| | 1566 | | /// <param name="visibilityTimeout"> |
| | 1567 | | /// Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days. |
| | 1568 | | /// </param> |
| | 1569 | | /// <param name="timeToLive"> |
| | 1570 | | /// Optional. Specifies the time-to-live interval for the message |
| | 1571 | | /// </param> |
| | 1572 | | /// <param name="async"> |
| | 1573 | | /// Whether to invoke the operation asynchronously. |
| | 1574 | | /// </param> |
| | 1575 | | /// <param name="cancellationToken"> |
| | 1576 | | /// Optional <see cref="CancellationToken"/>. |
| | 1577 | | /// </param> |
| | 1578 | | /// <returns> |
| | 1579 | | /// <see cref="Response{SendMessageResult}"/> |
| | 1580 | | /// </returns> |
| | 1581 | | private async Task<Response<SendReceipt>> SendMessageInternal( |
| | 1582 | | string messageText, |
| | 1583 | | TimeSpan? visibilityTimeout, |
| | 1584 | | TimeSpan? timeToLive, |
| | 1585 | | bool async, |
| | 1586 | | CancellationToken cancellationToken) |
| | 1587 | | { |
| 104 | 1588 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1589 | | { |
| | 1590 | | Pipeline.LogMethodEnter( |
| | 1591 | | nameof(QueueClient), |
| | 1592 | | message: |
| | 1593 | | $"Uri: {MessagesUri}\n" + |
| | 1594 | | $"{nameof(visibilityTimeout)}: {visibilityTimeout}\n" + |
| | 1595 | | $"{nameof(timeToLive)}: {timeToLive}"); |
| | 1596 | | try |
| | 1597 | | { |
| 104 | 1598 | | messageText = UsingClientSideEncryption |
| 104 | 1599 | | ? await new QueueClientSideEncryptor(new ClientSideEncryptor(ClientSideEncryption)) |
| 104 | 1600 | | .ClientSideEncryptInternal(messageText, async, cancellationToken).ConfigureAwait(false) |
| 104 | 1601 | | : messageText; |
| | 1602 | |
|
| 104 | 1603 | | Response<IEnumerable<SendReceipt>> messages = |
| 104 | 1604 | | await QueueRestClient.Messages.EnqueueAsync( |
| 104 | 1605 | | ClientDiagnostics, |
| 104 | 1606 | | Pipeline, |
| 104 | 1607 | | MessagesUri, |
| 104 | 1608 | | message: new QueueSendMessage { MessageText = messageText }, |
| 104 | 1609 | | version: Version.ToVersionString(), |
| 104 | 1610 | | visibilitytimeout: (int?)visibilityTimeout?.TotalSeconds, |
| 104 | 1611 | | messageTimeToLive: (int?)timeToLive?.TotalSeconds, |
| 104 | 1612 | | async: async, |
| 104 | 1613 | | operationName: $"{nameof(QueueClient)}.{nameof(SendMessage)}", |
| 104 | 1614 | | cancellationToken: cancellationToken) |
| 104 | 1615 | | .ConfigureAwait(false); |
| | 1616 | | // The service returns a sequence of messages, but the |
| | 1617 | | // sequence only ever has one value so we'll unwrap it |
| 100 | 1618 | | return Response.FromValue(messages.Value.FirstOrDefault(), messages.GetRawResponse()); |
| | 1619 | | } |
| 4 | 1620 | | catch (Exception ex) |
| | 1621 | | { |
| | 1622 | | Pipeline.LogException(ex); |
| 4 | 1623 | | throw; |
| | 1624 | | } |
| | 1625 | | finally |
| | 1626 | | { |
| | 1627 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1628 | | } |
| | 1629 | | } |
| 100 | 1630 | | } |
| | 1631 | | #endregion SendMessage |
| | 1632 | |
|
| | 1633 | | #region ReceiveMessages |
| | 1634 | | /// <summary> |
| | 1635 | | /// Receives one or more messages from the front of the queue. |
| | 1636 | | /// |
| | 1637 | | /// For more information, see |
| | 1638 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1639 | | /// Get Messages</see>. |
| | 1640 | | /// </summary> |
| | 1641 | | /// <returns> |
| | 1642 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1643 | | /// </returns> |
| 4 | 1644 | | public virtual Response<QueueMessage[]> ReceiveMessages() => ReceiveMessages(null); // Pass anything else so we |
| | 1645 | |
|
| | 1646 | | /// <summary> |
| | 1647 | | /// Retrieves one or more messages from the front of the queue. |
| | 1648 | | /// |
| | 1649 | | /// For more information, see |
| | 1650 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1651 | | /// Get Messages</see>. |
| | 1652 | | /// </summary> |
| | 1653 | | /// <returns> |
| | 1654 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1655 | | /// </returns> |
| | 1656 | | public virtual async Task<Response<QueueMessage[]>> ReceiveMessagesAsync() => |
| 4 | 1657 | | await ReceiveMessagesAsync(null) // Pass anything else so we don't recurse on this overload |
| 4 | 1658 | | .ConfigureAwait(false); |
| | 1659 | |
|
| | 1660 | | /// <summary> |
| | 1661 | | /// Receives one or more messages from the front of the queue. |
| | 1662 | | /// |
| | 1663 | | /// For more information, see |
| | 1664 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1665 | | /// Get Messages</see>. |
| | 1666 | | /// </summary> |
| | 1667 | | /// <param name="cancellationToken"> |
| | 1668 | | /// Optional <see cref="CancellationToken"/> |
| | 1669 | | /// </param> |
| | 1670 | | /// <returns> |
| | 1671 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1672 | | /// </returns> |
| | 1673 | | public virtual Response<QueueMessage[]> ReceiveMessages(CancellationToken cancellationToken = default) => |
| 0 | 1674 | | ReceiveMessages( |
| 0 | 1675 | | cancellationToken: cancellationToken, |
| 0 | 1676 | | visibilityTimeout: null); // Pass anything else so we don't recurse on this overload |
| | 1677 | |
|
| | 1678 | | /// <summary> |
| | 1679 | | /// Retrieves one or more messages from the front of the queue. |
| | 1680 | | /// |
| | 1681 | | /// For more information, see |
| | 1682 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1683 | | /// Get Messages</see>. |
| | 1684 | | /// </summary> |
| | 1685 | | /// <param name="cancellationToken"> |
| | 1686 | | /// Optional <see cref="CancellationToken"/> |
| | 1687 | | /// </param> |
| | 1688 | | /// <returns> |
| | 1689 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1690 | | /// </returns> |
| | 1691 | | public virtual async Task<Response<QueueMessage[]>> ReceiveMessagesAsync(CancellationToken cancellationToken = d |
| 0 | 1692 | | await ReceiveMessagesAsync( |
| 0 | 1693 | | cancellationToken: cancellationToken, |
| 0 | 1694 | | visibilityTimeout: null) // Pass anything else so we don't recurse on this overload |
| 0 | 1695 | | .ConfigureAwait(false); |
| | 1696 | |
|
| | 1697 | | /// <summary> |
| | 1698 | | /// Receives one or more messages from the front of the queue. |
| | 1699 | | /// |
| | 1700 | | /// For more information, see |
| | 1701 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1702 | | /// Get Messages</see>. |
| | 1703 | | /// </summary> |
| | 1704 | | /// <param name="maxMessages"> |
| | 1705 | | /// Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a |
| | 1706 | | /// If fewer are visible, the visible messages are returned. By default, a single message is retrieved from the |
| | 1707 | | /// </param> |
| | 1708 | | /// <param name="visibilityTimeout"> |
| | 1709 | | /// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value |
| | 1710 | | /// </param> |
| | 1711 | | /// <param name="cancellationToken"> |
| | 1712 | | /// Optional <see cref="CancellationToken"/> |
| | 1713 | | /// </param> |
| | 1714 | | /// <returns> |
| | 1715 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1716 | | /// </returns> |
| | 1717 | | public virtual Response<QueueMessage[]> ReceiveMessages( |
| | 1718 | | int? maxMessages = default, |
| | 1719 | | TimeSpan? visibilityTimeout = default, |
| | 1720 | | CancellationToken cancellationToken = default) => |
| 8 | 1721 | | ReceiveMessagesInternal( |
| 8 | 1722 | | maxMessages, |
| 8 | 1723 | | visibilityTimeout, |
| 8 | 1724 | | false, // async |
| 8 | 1725 | | cancellationToken) |
| 8 | 1726 | | .EnsureCompleted(); |
| | 1727 | |
|
| | 1728 | | /// <summary> |
| | 1729 | | /// Retrieves one or more messages from the front of the queue. |
| | 1730 | | /// |
| | 1731 | | /// For more information, see |
| | 1732 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1733 | | /// Get Messages</see>. |
| | 1734 | | /// </summary> |
| | 1735 | | /// <param name="maxMessages"> |
| | 1736 | | /// Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a |
| | 1737 | | /// If fewer are visible, the visible messages are returned. By default, a single message is retrieved from the |
| | 1738 | | /// </param> |
| | 1739 | | /// <param name="visibilityTimeout"> |
| | 1740 | | /// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value |
| | 1741 | | /// </param> |
| | 1742 | | /// <param name="cancellationToken"> |
| | 1743 | | /// Optional <see cref="CancellationToken"/> |
| | 1744 | | /// </param> |
| | 1745 | | /// <returns> |
| | 1746 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1747 | | /// </returns> |
| | 1748 | | public virtual async Task<Response<QueueMessage[]>> ReceiveMessagesAsync( |
| | 1749 | | int? maxMessages = default, |
| | 1750 | | TimeSpan? visibilityTimeout = default, |
| | 1751 | | CancellationToken cancellationToken = default) => |
| 8 | 1752 | | await ReceiveMessagesInternal( |
| 8 | 1753 | | maxMessages, |
| 8 | 1754 | | visibilityTimeout, |
| 8 | 1755 | | true, // async |
| 8 | 1756 | | cancellationToken) |
| 8 | 1757 | | .ConfigureAwait(false); |
| | 1758 | |
|
| | 1759 | | /// <summary> |
| | 1760 | | /// Retrieves one or more messages from the front of the queue. |
| | 1761 | | /// |
| | 1762 | | /// For more information, see |
| | 1763 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-messages"> |
| | 1764 | | /// Get Messages</see>. |
| | 1765 | | /// </summary> |
| | 1766 | | /// <param name="maxMessages"> |
| | 1767 | | /// Optional. A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a |
| | 1768 | | /// If fewer are visible, the visible messages are returned. By default, a single message is retrieved from the |
| | 1769 | | /// </param> |
| | 1770 | | /// <param name="visibilityTimeout"> |
| | 1771 | | /// Optional. Specifies the new visibility timeout value, in seconds, relative to server time. The default value |
| | 1772 | | /// </param> |
| | 1773 | | /// <param name="async"> |
| | 1774 | | /// Whether to invoke the operation asynchronously. |
| | 1775 | | /// </param> |
| | 1776 | | /// <param name="cancellationToken"> |
| | 1777 | | /// Optional <see cref="CancellationToken"/> |
| | 1778 | | /// </param> |
| | 1779 | | /// <returns> |
| | 1780 | | /// <see cref="Response{T}"/> where T is an array of <see cref="QueueMessage"/> |
| | 1781 | | /// </returns> |
| | 1782 | | private async Task<Response<QueueMessage[]>> ReceiveMessagesInternal( |
| | 1783 | | int? maxMessages, |
| | 1784 | | TimeSpan? visibilityTimeout, |
| | 1785 | | bool async, |
| | 1786 | | CancellationToken cancellationToken) |
| | 1787 | | { |
| 16 | 1788 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1789 | | { |
| | 1790 | | Pipeline.LogMethodEnter( |
| | 1791 | | nameof(QueueClient), |
| | 1792 | | message: |
| | 1793 | | $"Uri: {MessagesUri}\n" + |
| | 1794 | | $"{nameof(maxMessages)}: {maxMessages}\n" + |
| | 1795 | | $"{nameof(visibilityTimeout)}: {visibilityTimeout}"); |
| | 1796 | | try |
| | 1797 | | { |
| 16 | 1798 | | var response = await QueueRestClient.Messages.DequeueAsync( |
| 16 | 1799 | | ClientDiagnostics, |
| 16 | 1800 | | Pipeline, |
| 16 | 1801 | | MessagesUri, |
| 16 | 1802 | | version: Version.ToVersionString(), |
| 16 | 1803 | | numberOfMessages: maxMessages, |
| 16 | 1804 | | visibilitytimeout: (int?)visibilityTimeout?.TotalSeconds, |
| 16 | 1805 | | async: async, |
| 16 | 1806 | | operationName: $"{nameof(QueueClient)}.{nameof(ReceiveMessages)}", |
| 16 | 1807 | | cancellationToken: cancellationToken) |
| 16 | 1808 | | .ConfigureAwait(false); |
| | 1809 | |
|
| | 1810 | | // Return an exploding Response on 304 |
| 12 | 1811 | | if (response.IsUnavailable()) |
| | 1812 | | { |
| 0 | 1813 | | return response.GetRawResponse().AsNoBodyResponse<QueueMessage[]>(); |
| | 1814 | | } |
| 12 | 1815 | | else if (UsingClientSideEncryption) |
| | 1816 | | { |
| 0 | 1817 | | return Response.FromValue( |
| 0 | 1818 | | await new QueueClientSideDecryptor(ClientSideEncryption) |
| 0 | 1819 | | .ClientSideDecryptMessagesInternal(response.Value.ToArray(), async, cancellationToken).C |
| 0 | 1820 | | response.GetRawResponse()); |
| | 1821 | | } |
| | 1822 | | else |
| | 1823 | | { |
| 12 | 1824 | | return Response.FromValue(response.Value.ToArray(), response.GetRawResponse()); |
| | 1825 | | } |
| | 1826 | | } |
| 4 | 1827 | | catch (Exception ex) |
| | 1828 | | { |
| | 1829 | | Pipeline.LogException(ex); |
| 4 | 1830 | | throw; |
| | 1831 | | } |
| | 1832 | | finally |
| | 1833 | | { |
| | 1834 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1835 | | } |
| | 1836 | | } |
| 12 | 1837 | | } |
| | 1838 | | #endregion ReceiveMessages |
| | 1839 | |
|
| | 1840 | | #region PeekMessages |
| | 1841 | | /// <summary> |
| | 1842 | | /// Retrieves one or more messages from the front of the queue but does not alter the visibility of the message. |
| | 1843 | | /// |
| | 1844 | | /// For more information, see |
| | 1845 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/peek-messages"> |
| | 1846 | | /// Peek Messages</see>. |
| | 1847 | | /// </summary> |
| | 1848 | | /// <param name="maxMessages"> |
| | 1849 | | /// Optional. A nonzero integer value that specifies the number of messages to peek from the queue, up to a maxi |
| | 1850 | | /// By default, a single message is peeked from the queue with this operation. |
| | 1851 | | /// </param> |
| | 1852 | | /// <param name="cancellationToken"> |
| | 1853 | | /// Optional <see cref="CancellationToken"/> |
| | 1854 | | /// </param> |
| | 1855 | | /// <returns> |
| | 1856 | | /// <see cref="Response{T}"/> where T is an array of <see cref="PeekedMessage"/> |
| | 1857 | | /// </returns> |
| | 1858 | | public virtual Response<PeekedMessage[]> PeekMessages( |
| | 1859 | | int? maxMessages = default, |
| | 1860 | | CancellationToken cancellationToken = default) => |
| 10 | 1861 | | PeekMessagesInternal( |
| 10 | 1862 | | maxMessages, |
| 10 | 1863 | | false, // async |
| 10 | 1864 | | cancellationToken) |
| 10 | 1865 | | .EnsureCompleted(); |
| | 1866 | |
|
| | 1867 | | /// <summary> |
| | 1868 | | /// Retrieves one or more messages from the front of the queue but does not alter the visibility of the message. |
| | 1869 | | /// |
| | 1870 | | /// For more information, see |
| | 1871 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/peek-messages"> |
| | 1872 | | /// Peek Messages</see>. |
| | 1873 | | /// </summary> |
| | 1874 | | /// <param name="maxMessages"> |
| | 1875 | | /// Optional. A nonzero integer value that specifies the number of messages to peek from the queue, up to a maxi |
| | 1876 | | /// By default, a single message is peeked from the queue with this operation. |
| | 1877 | | /// </param> |
| | 1878 | | /// <param name="cancellationToken"> |
| | 1879 | | /// Optional <see cref="CancellationToken"/> |
| | 1880 | | /// </param> |
| | 1881 | | /// <returns> |
| | 1882 | | /// <see cref="Response{T}"/> where T is an array of <see cref="PeekedMessage"/> |
| | 1883 | | /// </returns> |
| | 1884 | | public virtual async Task<Response<PeekedMessage[]>> PeekMessagesAsync( |
| | 1885 | | int? maxMessages = default, |
| | 1886 | | CancellationToken cancellationToken = default) => |
| 18 | 1887 | | await PeekMessagesInternal( |
| 18 | 1888 | | maxMessages, |
| 18 | 1889 | | true, // async |
| 18 | 1890 | | cancellationToken) |
| 18 | 1891 | | .ConfigureAwait(false); |
| | 1892 | |
|
| | 1893 | | /// <summary> |
| | 1894 | | /// Retrieves one or more messages from the front of the queue but does not alter the visibility of the message. |
| | 1895 | | /// |
| | 1896 | | /// For more information, see |
| | 1897 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/peek-messages"> |
| | 1898 | | /// Peek Messages</see>. |
| | 1899 | | /// </summary> |
| | 1900 | | /// <param name="maxMessages"> |
| | 1901 | | /// Optional. A nonzero integer value that specifies the number of messages to peek from the queue, up to a maxi |
| | 1902 | | /// By default, a single message is peeked from the queue with this operation. |
| | 1903 | | /// </param> |
| | 1904 | | /// <param name="async"> |
| | 1905 | | /// Whether to invoke the operation asynchronously. |
| | 1906 | | /// </param> |
| | 1907 | | /// <param name="cancellationToken"> |
| | 1908 | | /// Optional <see cref="CancellationToken"/> |
| | 1909 | | /// </param> |
| | 1910 | | /// <returns> |
| | 1911 | | /// <see cref="Response{T}"/> where T is an array of <see cref="PeekedMessage"/> |
| | 1912 | | /// </returns> |
| | 1913 | | private async Task<Response<PeekedMessage[]>> PeekMessagesInternal( |
| | 1914 | | int? maxMessages, |
| | 1915 | | bool async, |
| | 1916 | | CancellationToken cancellationToken) |
| | 1917 | | { |
| 28 | 1918 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 1919 | | { |
| | 1920 | | Pipeline.LogMethodEnter( |
| | 1921 | | nameof(QueueClient), |
| | 1922 | | message: |
| | 1923 | | $"Uri: {MessagesUri}\n" + |
| | 1924 | | $"{nameof(maxMessages)}: {maxMessages}"); |
| | 1925 | | try |
| | 1926 | | { |
| 28 | 1927 | | Response<IEnumerable<PeekedMessage>> response = await QueueRestClient.Messages.PeekAsync( |
| 28 | 1928 | | ClientDiagnostics, |
| 28 | 1929 | | Pipeline, |
| 28 | 1930 | | MessagesUri, |
| 28 | 1931 | | version: Version.ToVersionString(), |
| 28 | 1932 | | numberOfMessages: maxMessages, |
| 28 | 1933 | | async: async, |
| 28 | 1934 | | operationName: $"{nameof(QueueClient)}.{nameof(PeekMessages)}", |
| 28 | 1935 | | cancellationToken: cancellationToken) |
| 28 | 1936 | | .ConfigureAwait(false); |
| | 1937 | |
|
| | 1938 | | // Return an exploding Response on 304 |
| 24 | 1939 | | if (response.IsUnavailable()) |
| | 1940 | | { |
| 0 | 1941 | | return response.GetRawResponse().AsNoBodyResponse<PeekedMessage[]>(); |
| | 1942 | | } |
| 24 | 1943 | | else if (UsingClientSideEncryption) |
| | 1944 | | { |
| 0 | 1945 | | return Response.FromValue( |
| 0 | 1946 | | await new QueueClientSideDecryptor(ClientSideEncryption) |
| 0 | 1947 | | .ClientSideDecryptMessagesInternal(response.Value.ToArray(), async, cancellationToken).C |
| 0 | 1948 | | response.GetRawResponse()); |
| | 1949 | | } |
| | 1950 | | else |
| | 1951 | | { |
| 24 | 1952 | | return Response.FromValue(response.Value.ToArray(), response.GetRawResponse()); |
| | 1953 | | } |
| | 1954 | | } |
| 4 | 1955 | | catch (Exception ex) |
| | 1956 | | { |
| | 1957 | | Pipeline.LogException(ex); |
| 4 | 1958 | | throw; |
| | 1959 | | } |
| | 1960 | | finally |
| | 1961 | | { |
| | 1962 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 1963 | | } |
| | 1964 | | } |
| 24 | 1965 | | } |
| | 1966 | | #endregion PeekMessages |
| | 1967 | |
|
| | 1968 | | /// <summary> |
| | 1969 | | /// Get the URI to a specific message given its ID. |
| | 1970 | | /// </summary> |
| | 1971 | | /// <param name="messageId">ID of the message.</param> |
| | 1972 | | /// <returns>URI to the given message.</returns> |
| | 1973 | | private Uri GetMessageUri(string messageId) => |
| 32 | 1974 | | MessagesUri.AppendToPath(messageId.ToString(CultureInfo.InvariantCulture)); |
| | 1975 | |
|
| | 1976 | | #region DeleteMessage |
| | 1977 | | /// <summary> |
| | 1978 | | /// Permanently removes the specified message from its queue. |
| | 1979 | | /// |
| | 1980 | | /// For more information, see |
| | 1981 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-message2"> |
| | 1982 | | /// Delete Message</see>. |
| | 1983 | | /// </summary> |
| | 1984 | | /// <param name="messageId">ID of the message to delete.</param> |
| | 1985 | | /// <param name="popReceipt"> |
| | 1986 | | /// Required. A valid pop receipt value returned from an earlier call to the Get Messages or Update Message oper |
| | 1987 | | /// </param> |
| | 1988 | | /// <param name="cancellationToken"> |
| | 1989 | | /// Optional <see cref="CancellationToken"/>. |
| | 1990 | | /// </param> |
| | 1991 | | /// <returns> |
| | 1992 | | /// <see cref="Response"/>. |
| | 1993 | | /// </returns> |
| | 1994 | | public virtual Response DeleteMessage( |
| | 1995 | | string messageId, |
| | 1996 | | string popReceipt, |
| | 1997 | | CancellationToken cancellationToken = default) => |
| 6 | 1998 | | DeleteMessageInternal( |
| 6 | 1999 | | messageId, |
| 6 | 2000 | | popReceipt, |
| 6 | 2001 | | false, // async |
| 6 | 2002 | | cancellationToken) |
| 6 | 2003 | | .EnsureCompleted(); |
| | 2004 | |
|
| | 2005 | | /// <summary> |
| | 2006 | | /// Permanently removes the specified message from its queue. |
| | 2007 | | /// |
| | 2008 | | /// For more information, see |
| | 2009 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-message2"> |
| | 2010 | | /// Delete Message</see>. |
| | 2011 | | /// </summary> |
| | 2012 | | /// <param name="messageId">ID of the message to delete.</param> |
| | 2013 | | /// <param name="popReceipt"> |
| | 2014 | | /// Required. A valid pop receipt value returned from an earlier call to the Get Messages or Update Message oper |
| | 2015 | | /// </param> |
| | 2016 | | /// <param name="cancellationToken"> |
| | 2017 | | /// Optional <see cref="CancellationToken"/>. |
| | 2018 | | /// </param> |
| | 2019 | | /// <returns> |
| | 2020 | | /// <see cref="Response"/>. |
| | 2021 | | /// </returns> |
| | 2022 | | public virtual async Task<Response> DeleteMessageAsync( |
| | 2023 | | string messageId, |
| | 2024 | | string popReceipt, |
| | 2025 | | CancellationToken cancellationToken = default) => |
| 6 | 2026 | | await DeleteMessageInternal( |
| 6 | 2027 | | messageId, |
| 6 | 2028 | | popReceipt, |
| 6 | 2029 | | true, // async |
| 6 | 2030 | | cancellationToken) |
| 6 | 2031 | | .ConfigureAwait(false); |
| | 2032 | |
|
| | 2033 | | /// <summary> |
| | 2034 | | /// Permanently removes the specified message from its queue. |
| | 2035 | | /// |
| | 2036 | | /// For more information, see |
| | 2037 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-message2"> |
| | 2038 | | /// Delete Message</see>. |
| | 2039 | | /// </summary> |
| | 2040 | | /// <param name="messageId">ID of the message to delete.</param> |
| | 2041 | | /// <param name="popReceipt"> |
| | 2042 | | /// Required. A valid pop receipt value returned from an earlier call to the Get Messages or Update Message oper |
| | 2043 | | /// </param> |
| | 2044 | | /// <param name="async"> |
| | 2045 | | /// Whether to invoke the operation asynchronously. |
| | 2046 | | /// </param> |
| | 2047 | | /// <param name="cancellationToken"> |
| | 2048 | | /// Optional <see cref="CancellationToken"/>. |
| | 2049 | | /// </param> |
| | 2050 | | /// <returns> |
| | 2051 | | /// <see cref="Response"/>. |
| | 2052 | | /// </returns> |
| | 2053 | | private async Task<Response> DeleteMessageInternal( |
| | 2054 | | string messageId, |
| | 2055 | | string popReceipt, |
| | 2056 | | bool async, |
| | 2057 | | CancellationToken cancellationToken) |
| | 2058 | | { |
| 12 | 2059 | | Uri uri = GetMessageUri(messageId); |
| 12 | 2060 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 2061 | | { |
| | 2062 | | Pipeline.LogMethodEnter( |
| | 2063 | | nameof(QueueClient), |
| | 2064 | | message: |
| | 2065 | | $"Uri: {uri}\n" + |
| | 2066 | | $"{nameof(popReceipt)}: {popReceipt}"); |
| | 2067 | | try |
| | 2068 | | { |
| 12 | 2069 | | return await QueueRestClient.MessageId.DeleteAsync( |
| 12 | 2070 | | ClientDiagnostics, |
| 12 | 2071 | | Pipeline, |
| 12 | 2072 | | uri, |
| 12 | 2073 | | popReceipt: popReceipt, |
| 12 | 2074 | | version: Version.ToVersionString(), |
| 12 | 2075 | | async: async, |
| 12 | 2076 | | operationName: $"{nameof(QueueClient)}.{nameof(DeleteMessage)}", |
| 12 | 2077 | | cancellationToken: cancellationToken) |
| 12 | 2078 | | .ConfigureAwait(false); |
| | 2079 | | } |
| 4 | 2080 | | catch (Exception ex) |
| | 2081 | | { |
| | 2082 | | Pipeline.LogException(ex); |
| 4 | 2083 | | throw; |
| | 2084 | | } |
| | 2085 | | finally |
| | 2086 | | { |
| | 2087 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 2088 | | } |
| | 2089 | | } |
| 8 | 2090 | | } |
| | 2091 | | #endregion DeleteMessage |
| | 2092 | |
|
| | 2093 | | #region UpdateMessage |
| | 2094 | | /// <summary> |
| | 2095 | | /// Changes a message's visibility timeout and contents. The message content must be a UTF-8 encoded string that |
| | 2096 | | /// |
| | 2097 | | /// For more information, see |
| | 2098 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/update-message"> |
| | 2099 | | /// Update Message</see>. |
| | 2100 | | /// </summary> |
| | 2101 | | /// <param name="messageId">ID of the message to update.</param> |
| | 2102 | | /// <param name="popReceipt"> |
| | 2103 | | /// Required. Specifies the valid pop receipt value returned from an earlier call to the Get Messages or Update |
| | 2104 | | /// </param> |
| | 2105 | | /// <param name="messageText"> |
| | 2106 | | /// Optional. Updated message text. |
| | 2107 | | /// </param> |
| | 2108 | | /// <param name="visibilityTimeout"> |
| | 2109 | | /// Required. Specifies the new visibility timeout value, in seconds, relative to server time. The new value mus |
| | 2110 | | /// or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a valu |
| | 2111 | | /// expiry time. A message can be updated until it has been deleted or has expired. |
| | 2112 | | /// </param> |
| | 2113 | | /// <param name="cancellationToken"> |
| | 2114 | | /// Optional <see cref="CancellationToken"/>. |
| | 2115 | | /// </param> |
| | 2116 | | /// <returns> |
| | 2117 | | /// <see cref="Response{UpdateReceipt}"/>. |
| | 2118 | | /// </returns> |
| | 2119 | | public virtual Response<UpdateReceipt> UpdateMessage( |
| | 2120 | | string messageId, |
| | 2121 | | string popReceipt, |
| | 2122 | | string messageText = null, |
| | 2123 | | TimeSpan visibilityTimeout = default, |
| | 2124 | | CancellationToken cancellationToken = default) => |
| 10 | 2125 | | UpdateMessageInternal( |
| 10 | 2126 | | messageText, |
| 10 | 2127 | | messageId, |
| 10 | 2128 | | popReceipt, |
| 10 | 2129 | | visibilityTimeout, |
| 10 | 2130 | | false, // async |
| 10 | 2131 | | cancellationToken) |
| 10 | 2132 | | .EnsureCompleted(); |
| | 2133 | |
|
| | 2134 | | /// <summary> |
| | 2135 | | /// Changes a message's visibility timeout and contents. The message content must be a UTF-8 encoded string that |
| | 2136 | | /// |
| | 2137 | | /// For more information, see |
| | 2138 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/update-message"> |
| | 2139 | | /// Update Message</see>. |
| | 2140 | | /// </summary> |
| | 2141 | | /// <param name="messageId">ID of the message to update.</param> |
| | 2142 | | /// <param name="popReceipt"> |
| | 2143 | | /// Required. Specifies the valid pop receipt value returned from an earlier call to the Get Messages or Update |
| | 2144 | | /// </param> |
| | 2145 | | /// <param name="messageText"> |
| | 2146 | | /// Optional. Updated message text. |
| | 2147 | | /// </param> |
| | 2148 | | /// <param name="visibilityTimeout"> |
| | 2149 | | /// Required. Specifies the new visibility timeout value, in seconds, relative to server time. The new value mus |
| | 2150 | | /// or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a valu |
| | 2151 | | /// expiry time. A message can be updated until it has been deleted or has expired. |
| | 2152 | | /// </param> |
| | 2153 | | /// <param name="cancellationToken"> |
| | 2154 | | /// Optional <see cref="CancellationToken"/>. |
| | 2155 | | /// </param> |
| | 2156 | | /// <returns> |
| | 2157 | | /// <see cref="Response{UpdateReceipt}"/>. |
| | 2158 | | /// </returns> |
| | 2159 | | public virtual async Task<Response<UpdateReceipt>> UpdateMessageAsync( |
| | 2160 | | string messageId, |
| | 2161 | | string popReceipt, |
| | 2162 | | string messageText = null, |
| | 2163 | | TimeSpan visibilityTimeout = default, |
| | 2164 | | CancellationToken cancellationToken = default) => |
| 10 | 2165 | | await UpdateMessageInternal( |
| 10 | 2166 | | messageText, |
| 10 | 2167 | | messageId, |
| 10 | 2168 | | popReceipt, |
| 10 | 2169 | | visibilityTimeout, |
| 10 | 2170 | | true, // async |
| 10 | 2171 | | cancellationToken) |
| 10 | 2172 | | .ConfigureAwait(false); |
| | 2173 | |
|
| | 2174 | | /// <summary> |
| | 2175 | | /// Changes a message's visibility timeout and contents. The message content must be a UTF-8 encoded string that |
| | 2176 | | /// |
| | 2177 | | /// For more information, see |
| | 2178 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/update-message"> |
| | 2179 | | /// Update Message</see>. |
| | 2180 | | /// </summary> |
| | 2181 | | /// <param name="messageText"> |
| | 2182 | | /// Updated message text. |
| | 2183 | | /// </param> |
| | 2184 | | /// <param name="messageId">ID of the message to update.</param> |
| | 2185 | | /// <param name="popReceipt"> |
| | 2186 | | /// Required. Specifies the valid pop receipt value returned from an earlier call to the Get Messages or Update |
| | 2187 | | /// </param> |
| | 2188 | | /// <param name="visibilityTimeout"> |
| | 2189 | | /// Required. Specifies the new visibility timeout value, in seconds, relative to server time. The new value mus |
| | 2190 | | /// or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a valu |
| | 2191 | | /// expiry time. A message can be updated until it has been deleted or has expired. |
| | 2192 | | /// </param> |
| | 2193 | | /// <param name="async"> |
| | 2194 | | /// Whether to invoke the operation asynchronously. |
| | 2195 | | /// </param> |
| | 2196 | | /// <param name="cancellationToken"> |
| | 2197 | | /// Optional <see cref="CancellationToken"/>. |
| | 2198 | | /// </param> |
| | 2199 | | /// <returns> |
| | 2200 | | /// <see cref="Response{UpdateReceipt}"/>. |
| | 2201 | | /// </returns> |
| | 2202 | | private async Task<Response<UpdateReceipt>> UpdateMessageInternal( |
| | 2203 | | string messageText, |
| | 2204 | | string messageId, |
| | 2205 | | string popReceipt, |
| | 2206 | | TimeSpan visibilityTimeout, |
| | 2207 | | bool async, |
| | 2208 | | CancellationToken cancellationToken) |
| | 2209 | | { |
| 20 | 2210 | | Uri uri = GetMessageUri(messageId); |
| 20 | 2211 | | using (Pipeline.BeginLoggingScope(nameof(QueueClient))) |
| | 2212 | | { |
| | 2213 | | Pipeline.LogMethodEnter( |
| | 2214 | | nameof(QueueClient), |
| | 2215 | | message: |
| | 2216 | | $"Uri: {uri}\n" + |
| | 2217 | | $"{nameof(popReceipt)}: {popReceipt}" + |
| | 2218 | | $"{nameof(visibilityTimeout)}: {visibilityTimeout}"); |
| | 2219 | | try |
| | 2220 | | { |
| 20 | 2221 | | messageText = UsingClientSideEncryption && messageText != default |
| 20 | 2222 | | ? await new QueueClientSideEncryptor(new ClientSideEncryptor(ClientSideEncryption)) |
| 20 | 2223 | | .ClientSideEncryptInternal(messageText, async, cancellationToken).ConfigureAwait(false) |
| 20 | 2224 | | : messageText; |
| | 2225 | |
|
| 20 | 2226 | | return await QueueRestClient.MessageId.UpdateAsync( |
| 20 | 2227 | | ClientDiagnostics, |
| 20 | 2228 | | Pipeline, |
| 20 | 2229 | | uri, |
| 20 | 2230 | | message: new QueueSendMessage { MessageText = messageText }, |
| 20 | 2231 | | popReceipt: popReceipt, |
| 20 | 2232 | | visibilitytimeout: (int)visibilityTimeout.TotalSeconds, |
| 20 | 2233 | | version: Version.ToVersionString(), |
| 20 | 2234 | | async: async, |
| 20 | 2235 | | operationName: $"{nameof(QueueClient)}.{nameof(UpdateMessage)}", |
| 20 | 2236 | | cancellationToken: cancellationToken) |
| 20 | 2237 | | .ConfigureAwait(false); |
| | 2238 | | } |
| 4 | 2239 | | catch (Exception ex) |
| | 2240 | | { |
| | 2241 | | Pipeline.LogException(ex); |
| 4 | 2242 | | throw; |
| | 2243 | | } |
| | 2244 | | finally |
| | 2245 | | { |
| | 2246 | | Pipeline.LogMethodExit(nameof(QueueClient)); |
| | 2247 | | } |
| | 2248 | | } |
| 16 | 2249 | | } |
| | 2250 | | #endregion UpdateMessage |
| | 2251 | | } |
| | 2252 | | } |
| | 2253 | |
|
| | 2254 | | namespace Azure.Storage.Queues.Specialized |
| | 2255 | | { |
| | 2256 | | /// <summary> |
| | 2257 | | /// Add methods to <see cref="Queues"/> clients. |
| | 2258 | | /// </summary> |
| | 2259 | | public static partial class SpecializedQueueExtensions |
| | 2260 | | { |
| | 2261 | | /// <summary> |
| | 2262 | | /// Creates a new instance of the <see cref="QueueClient"/> class, maintaining all the same |
| | 2263 | | /// internals but specifying new <see cref="ClientSideEncryptionOptions"/>. |
| | 2264 | | /// </summary> |
| | 2265 | | /// <param name="client">Client to base off of.</param> |
| | 2266 | | /// <param name="clientSideEncryptionOptions">New encryption options. Setting this to <code>default</code> will |
| | 2267 | | /// <returns>New instance with provided options and same internals otherwise.</returns> |
| | 2268 | | public static QueueClient WithClientSideEncryptionOptions(this QueueClient client, ClientSideEncryptionOptions c |
| | 2269 | | => new QueueClient( |
| | 2270 | | client.Uri, |
| | 2271 | | client.Pipeline, |
| | 2272 | | client.Version, |
| | 2273 | | client.ClientDiagnostics, |
| | 2274 | | clientSideEncryptionOptions); |
| | 2275 | | } |
| | 2276 | | } |