/
QueueAttribute.cs
72 lines (67 loc) · 3.08 KB
/
QueueAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Diagnostics;
using Azure.Storage.Queues;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.WebJobs.Description;
using Microsoft.Azure.WebJobs.Host;
namespace Microsoft.Azure.WebJobs
{
#pragma warning disable CA1200 // Avoid using cref tags with a prefix
/// <summary>
/// Attribute used to bind a parameter to an Azure Queue.
/// </summary>
/// <remarks>
/// The method parameter type can be one of the following:
/// <list type="bullet">
/// <item><description><see cref="QueueClient"/></description></item>
/// <item><description><see cref="QueueMessage"/> (out parameter)</description></item>
/// <item><description><see cref="string"/> (out parameter)</description></item>
/// <item><description><see cref="T:byte[]"/> (out parameter)</description></item>
/// <item><description><see cref="BinaryData"/> (out parameter)</description></item>
/// <item><description>A user-defined type (out parameter, serialized as JSON)</description></item>
/// <item><description><see cref="ICollector{T}"/> of these types (to enqueue multiple messages via <see cref="ICollector{T}.Add"/></description></item>
/// <item><description><see cref="IAsyncCollector{T}"/> of these types (to enqueue multiple messages via <see cref="IAsyncCollector{T}.AddAsync(T, System.Threading.CancellationToken)"/></description></item>
/// </list>
///
/// By default the extension Base64-encodes outgoing messages.
/// This behavior can be changed by setting <see cref="QueuesOptions.MessageEncoding"/>.
/// For example, to configure Azure Functions to perform no base64 encoding/decoding, specify the following in host.json.
/// <code>
/// "extensions": {
/// "queues": {
/// "messageEncoding": "none"
/// }
/// }
/// </code>
/// </remarks>
#pragma warning restore CA1200 // Avoid using cref tags with a prefix
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
[DebuggerDisplay("{QueueName,nq}")]
[ConnectionProvider(typeof(StorageAccountAttribute))]
[Binding]
public class QueueAttribute : Attribute, IConnectionProvider
{
private readonly string _queueName;
/// <summary>Initializes a new instance of the <see cref="QueueAttribute"/> class.</summary>
/// <param name="queueName">The name of the queue to which to bind.</param>
public QueueAttribute(string queueName)
{
_queueName = queueName;
}
/// <summary>
/// Gets the name of the queue to which to bind.
/// </summary>
[AutoResolve]
public string QueueName
{
get { return _queueName; }
}
/// <summary>
/// Gets or sets the app setting name that contains the Azure Storage connection string.
/// </summary>
public string Connection { get; set; }
}
}