Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConditionalEnumerator.cs
1using System;
2using System.Collections;
3using System.Threading.Tasks;
7
9{
14 {
15 private readonly ScriptNode conditions;
16 private readonly Variables variables;
17 private readonly IResultSetEnumerator e;
18 private ObjectProperties properties = null;
19
27 {
28 this.e = ItemEnumerator;
29 this.variables = Variables;
30 this.conditions = Conditions;
31 }
32
36 public object Current => this.e.Current;
37
41 public bool MoveNext()
42 {
43 while (this.e.MoveNext())
44 {
45 if (this.MatchesCondition())
46 return true;
47 }
48
49 return false;
50 }
51
55 public async Task<bool> MoveNextAsync()
56 {
57 while (await this.e.MoveNextAsync())
58 {
59 if (await this.MatchesConditionAsync())
60 return true;
61 }
62
63 return false;
64 }
65
66 private bool MatchesCondition()
67 {
68 try
69 {
70 if (this.properties is null)
71 this.properties = new ObjectProperties(this.e.Current, this.variables);
72 else
73 this.properties.Object = this.e.Current;
74
75 IElement E = this.conditions.Evaluate(this.properties);
76 if (!(E.AssociatedObjectValue is bool B) || !B)
77 return false;
78
79 return true;
80 }
81 catch (Exception)
82 {
83 return false;
84 }
85 }
86
87 private async Task<bool> MatchesConditionAsync()
88 {
89 try
90 {
91 if (this.properties is null)
92 this.properties = new ObjectProperties(this.e.Current, this.variables);
93 else
94 this.properties.Object = this.e.Current;
95
96 IElement E = await this.conditions.EvaluateAsync(this.properties);
97 if (!(E.AssociatedObjectValue is bool B) || !B)
98 return false;
99
100 return true;
101 }
102 catch (Exception)
103 {
104 return false;
105 }
106 }
107
111 public void Reset()
112 {
113 this.e.Reset();
114 }
115 }
116}
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Enumerator that only returns elements matching a set of conditions.
async Task< bool > MoveNextAsync()
IAsyncEnumerator.MoveNextAsync
ConditionalEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, ScriptNode Conditions)
Enumerator that only returns elements matching a set of conditions.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33