-
Notifications
You must be signed in to change notification settings - Fork 356
/
DisableAttribute.cs
71 lines (65 loc) · 2.96 KB
/
DisableAttribute.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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
namespace Microsoft.Azure.WebJobs
{
/// <summary>
/// Attribute that can be applied to job functions, trigger parameters and classes
/// to conditionally disable triggered functions.
/// <remarks>
/// <para>
/// For example, by using this attribute, you can dynamically disable functions temporarily
/// by changing application settings. Note that the disable check is done on startup only.
/// If a <see cref="DisableAttribute"/> in the hierarchy (Parameter/Method/Class) exists and
/// indicates that the function should be disabled, the listener for that function will not be
/// started. The attribute only affects triggered functions.
/// </para>
/// <para>
/// Additionally, when running in an Azure Web App, you can set app setting WEBJOBS_STOPPED to 1
/// to completely disable the JobHost. In this case the JobHost won't even be started.
/// </para>
/// </remarks>
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Parameter)]
public sealed class DisableAttribute : Attribute
{
/// <summary>
/// Constructs a new instance.
/// </summary>
public DisableAttribute()
{
}
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="settingName">The name of an application setting or environment variable that
/// governs whether the function(s) should be disabled. If the specified setting exists and its
/// value is "1" or "True", the function will be disabled. The setting name can contain binding
/// parameters (e.g. {MethodName}, {MethodShortName}, %test%, etc.).</param>
public DisableAttribute(string settingName)
{
SettingName = settingName;
}
/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="providerType">A Type which implements a method named "IsDisabled" taking
/// a <see cref="System.Reflection.MethodInfo"/> and returning <see cref="bool"/>. This
/// function will be called to determine whether the target function should be disabled.
/// </param>
public DisableAttribute(Type providerType)
{
ProviderType = providerType;
}
/// <summary>
/// Gets the name of the application setting or environment variable that will
/// be used to determine whether the function(s) should be disabled.
/// </summary>
public string SettingName { get; private set; }
/// <summary>
/// Gets the custom <see cref="Type"/> that will be invoked to determine
/// whether the function(s) should be disabled.
/// </summary>
public Type ProviderType { get; private set; }
}
}