Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PrivilegePattern.cs
1using System;
2using System.Text.RegularExpressions;
3using Waher.Events;
5
7{
11 [TypeName(TypeNameSerialization.None)]
12 public sealed class PrivilegePattern
13 {
14 private string expression = string.Empty;
15 private bool include = true;
16 private Regex regex = null;
17
22 {
23 }
24
30 public PrivilegePattern(string Pattern, bool Include)
31 {
32 this.expression = Pattern;
33 this.regex = new Regex(Pattern, RegexOptions.Singleline);
34 this.include = Include;
35 }
36
40 public string Expression
41 {
42 get => this.expression;
43 set
44 {
45 this.expression = value;
46
47 try
48 {
49 this.regex = new Regex(this.expression, RegexOptions.Singleline);
50 }
51 catch (Exception ex)
52 {
53 Log.Error("Invalid regular expression:\r\n" + this.expression + "\r\n\r\nError reported.\r\n" + ex.Message);
54 this.regex = null;
55 }
56 }
57 }
58
62 [DefaultValue(true)]
63 public bool Include
64 {
65 get => this.include;
66 set => this.include = value;
67 }
68
74 public bool? IsIncluded(string Privilege)
75 {
76 if (this.regex is null)
77 return null;
78
79 Match M = this.regex.Match(Privilege);
80
81 if (M.Success && M.Index == 0 && M.Length == Privilege.Length)
82 return this.include;
83 else
84 return null;
85 }
86 }
87}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
Definition: Log.cs:682
Corresponds to a privilege in the system.
Definition: Privilege.cs:17
Contains a reference to a privilege
string Expression
Privilege ID regular expression to match against.
PrivilegePattern(string Pattern, bool Include)
Contains a reference to a privilege
PrivilegePattern()
Contains a reference to a privilege
bool? IsIncluded(string Privilege)
If the privilege is included.
bool Include
If privileges matching the pattern are included (true) or excluded (false).
TypeNameSerialization
How the type name should be serialized.