-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathEventLevelFilter.cs
105 lines (93 loc) · 2.88 KB
/
EventLevelFilter.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
namespace Waher.Events.Filter
{
/// <summary>
/// Filters events based on their <see cref="EventLevel"/> value.
/// </summary>
public class EventLevelFilter : ICustomEventFilter
{
/// <summary>
/// Filters events based on their <see cref="EventLevel"/> value.
/// </summary>
/// <param name="AllowType">If the type (i.e. all levels) are allowed or not.</param>
public EventLevelFilter(bool AllowType)
: this(AllowType, AllowType, AllowType)
{
}
/// <summary>
/// Filters events based on their <see cref="EventLevel"/> value.
/// </summary>
/// <param name="FromLevel">From what event level events are allowed.</param>
public EventLevelFilter(EventLevel FromLevel)
: this(FromLevel <= EventLevel.Major, FromLevel <= EventLevel.Medium, FromLevel <= EventLevel.Minor)
{
}
/// <summary>
/// Filters events based on their <see cref="EventLevel"/> value.
/// </summary>
/// <param name="AllowMajor">If major events are allowed.</param>
/// <param name="AllowMedium">If medium events are allowed.</param>
/// <param name="AllowMinor">If minor events are allowed.</param>
public EventLevelFilter(bool AllowMajor, bool AllowMedium, bool AllowMinor)
{
this.AllowMajor = AllowMajor;
this.AllowMedium = AllowMedium;
this.AllowMinor = AllowMinor;
}
/// <summary>
/// Filters events based on their <see cref="EventLevel"/> value.
/// </summary>
/// <param name="AllowType">If the type (i.e. all levels) are allowed or not.</param>
public static implicit operator EventLevelFilter(bool AllowType)
{
return new EventLevelFilter(AllowType);
}
/// <summary>
/// Filters events based on their <see cref="EventLevel"/> value.
/// </summary>
/// <param name="FromLevel">From what event level events are allowed.</param>
public static implicit operator EventLevelFilter(EventLevel FromLevel)
{
return new EventLevelFilter(FromLevel);
}
/// <summary>
/// If major events are allowed.
/// </summary>
public bool AllowMajor { get; set; }
/// <summary>
/// If medium events are allowed.
/// </summary>
public bool AllowMedium { get; set; }
/// <summary>
/// If minor events are allowed.
/// </summary>
public bool AllowMinor { get; set; }
/// <summary>
/// Checks if an event is allowed.
/// </summary>
/// <param name="Event">Event to check.</param>
/// <returns>If event is allowed.</returns>
public bool IsAllowed(Event Event)
{
return this.IsAllowed(Event.Level);
}
/// <summary>
/// Checks if an event level is allowed.
/// </summary>
/// <param name="Level">Event level.</param>
/// <returns>If allowed.</returns>
public bool IsAllowed(EventLevel Level)
{
switch (Level)
{
case EventLevel.Major:
return this.AllowMajor;
case EventLevel.Medium:
return this.AllowMedium;
case EventLevel.Minor:
return this.AllowMinor;
default:
return false;
}
}
}
}