-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
RuleProperties.cs
146 lines (127 loc) · 4.84 KB
/
RuleProperties.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Azure.Core;
namespace Azure.Messaging.ServiceBus.Administration
{
/// <summary>
/// Represents the properties of a rule.
/// </summary>
public sealed class RuleProperties : IEquatable<RuleProperties>
{
/// <summary>
/// Gets the name of the default rule on the subscription.
/// </summary>
/// <remarks>
/// Whenever a new subscription is created, a default rule is always added.
/// The default rule is a <see cref="TrueRuleFilter"/> which will enable all messages in the topic to reach subscription.
/// </remarks>
public const string DefaultRuleName = "$Default";
private RuleFilter _filter;
/// <summary>
/// Initializes a new instance of the <see cref="RuleProperties" /> class with default values.
/// </summary>
internal RuleProperties()
: this(DefaultRuleName, TrueRuleFilter.Default)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RuleProperties" /> class with the specified name.
/// </summary>
internal RuleProperties(string name)
: this(name, TrueRuleFilter.Default)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RuleProperties" /> class with the specified name and filter expression.
/// </summary>
/// <param name="name"></param>
/// <param name="filter">The filter expression used to match messages.</param>
internal RuleProperties(string name, RuleFilter filter)
{
Argument.AssertNotNull(filter, nameof(filter));
Filter = filter;
Name = name;
}
internal RuleProperties(CreateRuleOptions options)
{
Filter = options.Filter;
Action = options.Action;
Name = options.Name;
}
/// <summary>
/// Gets or sets the filter expression used to match messages.
/// </summary>
/// <value>The filter expression used to match messages.</value>
/// <exception cref="System.ArgumentNullException">null (Nothing in Visual Basic) is assigned.</exception>
public RuleFilter Filter
{
get => _filter;
set
{
Argument.AssertNotNull(value, nameof(Filter));
_filter = value;
}
}
/// <summary>
/// Gets or sets the action to perform if the message satisfies the filtering expression.
/// </summary>
/// <value>The action to perform if the message satisfies the filtering expression.</value>
public RuleAction Action { get; set; }
/// <summary>
/// Gets or sets the name of the rule.
/// </summary>
/// <value>Returns a <see cref="System.String" /> Representing the name of the rule.</value>
/// <remarks>Max allowed length of rule name is 50 chars.</remarks>
public string Name { get; internal set; }
// TODO: Implement for AMQP
internal DateTime CreatedAt { get; set; }
/// <inheritdoc/>
public override int GetHashCode()
{
int hash = 13;
unchecked
{
hash = (hash * 7) + _filter?.GetHashCode() ?? 0;
hash = (hash * 7) + Action?.GetHashCode() ?? 0;
}
return hash;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
var other = obj as RuleProperties;
return Equals(other);
}
/// <inheritdoc/>
public bool Equals(RuleProperties other)
{
if (other is RuleProperties otherProperties
&& string.Equals(Name, otherProperties.Name, StringComparison.OrdinalIgnoreCase)
&& (Filter == null || Filter.Equals(otherProperties.Filter))
&& (Action == null || Action.Equals(otherProperties.Action)))
{
return true;
}
return false;
}
/// <summary>Compares two <see cref="RuleProperties"/> values for equality.</summary>
public static bool operator ==(RuleProperties left, RuleProperties right)
{
if (ReferenceEquals(left, right))
{
return true;
}
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
{
return false;
}
return left.Equals(right);
}
/// <summary>Compares two <see cref="RuleProperties"/> values for inequality.</summary>
public static bool operator !=(RuleProperties left, RuleProperties right)
{
return !(left == right);
}
}
}