Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NodeRule.cs
1using System;
2using System.Text;
3using System.Xml;
7
9{
13 [TypeName(TypeNameSerialization.None)]
14 [ArchivingTime]
15 [Index("JID", "NodeID", "SourceID", "Partition")]
16 public abstract class NodeRule
17 {
18 private Guid objectId = Guid.Empty;
20 private string nodeId = string.Empty;
21 private string sourceId = string.Empty;
22 private string partition = string.Empty;
23 private Rule[] rules = null;
24
28 public NodeRule()
29 {
30 }
31
35 [ObjectId]
36 public Guid ObjectId
37 {
38 get => this.objectId;
39 set => this.objectId = value;
40 }
41
46 {
47 get => this.jid;
48 set => this.jid = value;
49 }
50
54 public string NodeID
55 {
56 get => this.nodeId;
57 set => this.nodeId = value;
58 }
59
63 public string SourceID
64 {
65 get => this.sourceId;
66 set => this.sourceId = value;
67 }
68
72 public string Partition
73 {
74 get => this.partition;
75 set => this.partition = value;
76 }
77
81 [DefaultValueNull]
82 public Rule[] Rules
83 {
84 get => this.rules;
85 set => this.rules = value;
86 }
87
92 public void AddChildRule(Rule Rule)
93 {
94 if (this.rules is null)
95 this.rules = new Rule[] { Rule };
96 else
97 {
98 int c = this.rules.Length;
99 Array.Resize(ref this.rules, c + 1);
100 this.rules[c] = Rule;
101 }
102 }
103
108 public abstract void Export(XmlWriter Output);
109
110 protected virtual void ExportContent(XmlWriter Output)
111 {
112 Output.WriteAttributeString("jid", this.jid);
113
114 if (!string.IsNullOrEmpty(this.nodeId))
115 Output.WriteAttributeString("id", this.nodeId);
116
117 if (!string.IsNullOrEmpty(this.sourceId))
118 Output.WriteAttributeString("src", this.sourceId);
119
120 if (!string.IsNullOrEmpty(this.partition))
121 Output.WriteAttributeString("pt", this.partition);
122
123 if (!(this.rules is null))
124 {
125 foreach (Rule Rule in this.rules)
126 Rule.Export(Output);
127 }
128 }
129
134 public string ExportXml()
135 {
136 StringBuilder sb = new StringBuilder();
137 XmlWriterSettings Settings = XML.WriterSettings(true, true);
138
139 using (XmlWriter w = XmlWriter.Create(sb, Settings))
140 {
141 this.Export(w);
142 }
143
144 return sb.ToString();
145 }
146
147 }
148}
Helps with common XML-related tasks.
Definition: XML.cs:19
static XmlWriterSettings WriterSettings(bool Indent, bool OmitXmlDeclaration)
Gets an XML writer settings object.
Definition: XML.cs:1177
Represents a case-insensitive string.
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
Abstract base class for node rules.
Definition: NodeRule.cs:17
abstract void Export(XmlWriter Output)
Exports the rule.
CaseInsensitiveString JID
JID of sensor.
Definition: NodeRule.cs:46
NodeRule()
Abstract base class for node rules.
Definition: NodeRule.cs:28
string ExportXml()
Exports the rule as an XML string.
Definition: NodeRule.cs:134
void AddChildRule(Rule Rule)
Adds a child rule.
Definition: NodeRule.cs:92
Abstract base class for rules.
Definition: Rule.cs:12
abstract void Export(XmlWriter Output)
Exports the rule.
TypeNameSerialization
How the type name should be serialized.