Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Partial.cs
1using System.Collections.Generic;
2using System.Xml;
5
7{
8 public class Partial : Rule
9 {
10 private string[] names = null;
11 private int mask = -1;
12
13 public Partial()
14 : base()
15 {
16 }
17
18 [DefaultValueNull]
19 public string[] Names
20 {
21 get => this.names;
22 set => this.names = value;
23 }
24
25 [DefaultValue(-1)]
26 public int Mask
27 {
28 get => this.mask;
29 set => this.mask = value;
30 }
31
32 public override bool? Evaluate(Context Context)
33 {
34 bool? b = base.Evaluate(Context);
35 if (b.HasValue && !b.Value)
36 return false;
37
38 Context.Types = (FieldType)((int)Context.Types & this.mask);
39 if (Context.Types == 0)
40 return false;
41
42 if (!(this.names is null))
43 {
44 Dictionary<string, bool> Names = new Dictionary<string, bool>();
45
46 foreach (string Field in this.names)
47 {
48 if (Context.Names == null || Context.Names.ContainsKey(Field))
49 Names[Field] = true;
50 }
51
52 if (Names.Count == 0)
53 return false;
54
55 Context.Names = Names;
56 }
57
58 return true;
59 }
60
65 public override void Export(XmlWriter Output)
66 {
67 Output.WriteStartElement("Partial", RuleNamespace);
68 Output.WriteAttributeString("mask", this.mask.ToString());
69
70 if (!(this.names is null))
71 {
72 foreach (string Name in this.names)
73 Output.WriteElementString("Name", Name);
74 }
75
76 base.ExportChildren(Output);
77
78 Output.WriteEndElement();
79 }
80 }
81}
override void Export(XmlWriter Output)
Exports the rule.
Definition: Partial.cs:65
override? bool Evaluate(Context Context)
Tries to evaluate the rule.
Definition: Partial.cs:32
Abstract base class for rules.
Definition: Rule.cs:12
const string RuleNamespace
http://waher.se/Schema/Provisioning/Rules.xsd
Definition: Rule.cs:16
Base class for all sensor data fields.
Definition: Field.cs:20
FieldType
Field Type flags
Definition: FieldType.cs:10