• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Jericho / Picton / 256

15 Dec 2024 08:18PM UTC coverage: 45.968% (+0.5%) from 45.479%
256

push

appveyor

Jericho
Merge branch 'release/9.3.0'

171 of 372 relevant lines covered (45.97%)

1787.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/Source/Picton/Extensions/QueueClientExtensions.cs
1
using Azure;
2
using Azure.Storage.Queues;
3
using Azure.Storage.Queues.Models;
4
using System;
5
using System.Collections.Generic;
6
using System.Threading;
7
using System.Threading.Tasks;
8

9
namespace Picton
10
{
11
        /// <summary>
12
        /// Contains extension methods for the <see cref="QueueClient"/> class.
13
        /// </summary>
14
        public static class QueueClientExtensions
15
        {
16
                private static readonly IDictionary<string, string> EmptyDictionary = new Dictionary<string, string>();
×
17

18
                /// <summary>
19
                /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be invisible
20
                /// to Dequeue and Peek operations.
21
                ///
22
                /// A message must be in a format that can be included in an XML request with UTF-8 encoding.
23
                /// Otherwise <see cref="QueueClientOptions.MessageEncoding"/> option can be set to <see cref="QueueMessageEncoding.Base64"/> to handle non compliant messages.
24
                /// The encoded message can be up to 64 KiB in size for versions 2011-08-18 and newer, or 8 KiB in size for previous versions.
25
                /// </summary>
26
                /// <remarks>The queue will be created if it doesn't already exist.</remarks>
27
                /// <param name="queue">The queue client.</param>
28
                /// <param name="messageText">Message text.</param>
29
                /// <param name="visibilityTimeout">Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days.</param>
30
                /// <param name="timeToLive">The time-to-live interval for the message.</param>
31
                /// <param name="cancellationToken">The cancellation token.</param>
32
                /// <returns>The <see cref="SendReceipt"/>.</returns>
33
                public static Task<SendReceipt> SafeSendMessageAsync(this QueueClient queue, string messageText, TimeSpan? visibilityTimeout = default, TimeSpan? timeToLive = default, CancellationToken cancellationToken = default)
34
                {
35
                        return queue.SafeSendMessageAsync(BinaryData.FromString(messageText), visibilityTimeout, timeToLive, cancellationToken);
5✔
36
                }
37

38
                /// <summary>
39
                /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be invisible
40
                /// to Dequeue and Peek operations.
41
                ///
42
                /// A message must be in a format that can be included in an XML request with UTF-8 encoding.
43
                /// Otherwise <see cref="QueueClientOptions.MessageEncoding"/> option can be set to <see cref="QueueMessageEncoding.Base64"/> to handle non compliant messages.
44
                /// The encoded message can be up to 64 KiB in size for versions 2011-08-18 and newer, or 8 KiB in size for previous versions.
45
                /// </summary>
46
                /// <remarks>The queue will be created if it doesn't already exist.</remarks>
47
                /// <param name="queue">The queue client.</param>
48
                /// <param name="message">Message.</param>
49
                /// <param name="visibilityTimeout">Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days.</param>
50
                /// <param name="timeToLive">Specifies the time-to-live interval for the message.</param>
51
                /// <param name="cancellationToken">The cancellation token.</param>
52
                /// <returns>The <see cref="SendReceipt"/>.</returns>
53
                public static Task<SendReceipt> SafeSendMessageAsync(this QueueClient queue, byte[] message, TimeSpan? visibilityTimeout = default, TimeSpan? timeToLive = default, CancellationToken cancellationToken = default)
54
                {
55
                        return queue.SafeSendMessageAsync(BinaryData.FromBytes(message), visibilityTimeout, timeToLive, cancellationToken);
×
56
                }
57

58
                /// <summary>
59
                /// Adds a new message to the back of a queue. The visibility timeout specifies how long the message should be invisible
60
                /// to Dequeue and Peek operations.
61
                ///
62
                /// A message must be in a format that can be included in an XML request with UTF-8 encoding.
63
                /// Otherwise <see cref="QueueClientOptions.MessageEncoding"/> option can be set to <see cref="QueueMessageEncoding.Base64"/> to handle non compliant messages.
64
                /// The encoded message can be up to 64 KiB in size for versions 2011-08-18 and newer, or 8 KiB in size for previous versions.
65
                /// </summary>
66
                /// <remarks>The queue will be created if it doesn't already exist.</remarks>
67
                /// <param name="queue">The queue client.</param>
68
                /// <param name="message">Message.</param>
69
                /// <param name="visibilityTimeout">Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days.</param>
70
                /// <param name="timeToLive">The time-to-live interval for the message.</param>
71
                /// <param name="cancellationToken">The cancellation token.</param>
72
                /// <returns>The <see cref="SendReceipt"/>.</returns>
73
                public static async Task<SendReceipt> SafeSendMessageAsync(this QueueClient queue, BinaryData message, TimeSpan? visibilityTimeout = default, TimeSpan? timeToLive = default, CancellationToken cancellationToken = default)
74
                {
75
                        if (queue == null) throw new ArgumentNullException(nameof(queue));
76

77
                        Response<SendReceipt> response;
78
                        try
79
                        {
80
                                response = await queue.SendMessageAsync(message, visibilityTimeout, timeToLive, cancellationToken = default).ConfigureAwait(false);
81
                        }
82
                        catch (RequestFailedException rfe) when (rfe.ErrorCode == "QueueNotFound")
83
                        {
84
                                await queue.CreateIfNotExistsAsync(QueueClientExtensions.EmptyDictionary, cancellationToken).ConfigureAwait(false);
85
                                response = await queue.SendMessageAsync(message, visibilityTimeout, timeToLive, cancellationToken).ConfigureAwait(false);
86
                        }
87

88
                        return response.Value;
89
                }
90
        }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc