Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FieldAggregatorEnumerator.cs
1using System;
4using System.Threading.Tasks;
9
11{
16 {
17 private readonly KeyValuePair<string, ScriptNode>[] additionalFields;
18 private readonly bool[] additionalFieldAsynchronous;
19 private readonly IResultSetEnumerator e;
20 private readonly Variables variables;
21 private readonly int count;
22 private ObjectProperties objectVariables = null;
23 private object current = null;
24
33 KeyValuePair<string, int>[] AdditionalFields, ScriptNode[] Columns)
34 {
35 this.e = ItemEnumerator;
36 this.variables = Variables;
37
38 this.count = AdditionalFields.Length;
39
40 this.additionalFieldAsynchronous = new bool[this.count];
41 this.additionalFields = new KeyValuePair<string, ScriptNode>[this.count];
42
43 for (int i = 0; i < this.count; i++)
44 {
45 KeyValuePair<string, int> P = AdditionalFields[i];
46 ScriptNode Node = Columns[P.Value];
47
48 this.additionalFields[i] = new KeyValuePair<string, ScriptNode>(P.Key, Node);
49 this.additionalFieldAsynchronous[i] = Node.IsAsynchronous;
50 }
51 }
52
56 public object Current => this.current;
57
61 public void Dispose()
62 {
63 this.e.Dispose();
64 }
65
69 public bool MoveNext()
70 {
71 return this.MoveNextAsync().Result;
72 }
73
80 public async Task<bool> MoveNextAsync()
81 {
82 KeyValuePair<string, ScriptNode> P;
83 int i;
84
85 if (!await this.e.MoveNextAsync())
86 return false;
87
88 this.current = this.e.Current;
89
90 if (this.objectVariables is null)
91 this.objectVariables = new ObjectProperties(this.current, this.variables);
92 else
93 this.objectVariables.Object = this.e.Current;
94
95 if (this.current is GenericObject GenObj)
96 {
97 for (i = 0; i < this.count; i++)
98 {
99 P = this.additionalFields[i];
100
101 if (this.additionalFieldAsynchronous[i])
102 GenObj[P.Key] = await P.Value.EvaluateAsync(this.objectVariables);
103 else
104 GenObj[P.Key] = P.Value.Evaluate(this.objectVariables);
105 }
106 }
107 else if (this.current is GroupObject GroupObj)
108 {
109 for (i = 0; i < this.count; i++)
110 {
111 P = this.additionalFields[i];
112
113 if (this.additionalFieldAsynchronous[i])
114 GroupObj[P.Key] = await P.Value.EvaluateAsync(this.objectVariables);
115 else
116 GroupObj[P.Key] = P.Value.Evaluate(this.objectVariables);
117 }
118 }
119 else
120 {
121 GroupObject Obj = new GroupObject(Array.Empty<object>(), Array.Empty<IElement>(),
122 Array.Empty<ScriptNode>(), this.objectVariables);
123
124 for (i = 0; i < this.count; i++)
125 {
126 P = this.additionalFields[i];
127
128 if (this.additionalFieldAsynchronous[i])
129 Obj[P.Key] = await P.Value.EvaluateAsync(this.objectVariables);
130 else
131 Obj[P.Key] = P.Value.Evaluate(this.objectVariables);
132 }
133
134 this.current = Obj;
135 }
136
137 return true;
138 }
139
143 public void Reset()
144 {
145 this.e.Reset();
146 this.current = null;
147 }
148 }
149}
Generic object. Contains a sequence of properties.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
virtual bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: ScriptNode.cs:142
async Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
FieldAggregatorEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, KeyValuePair< string, int >[] AdditionalFields, ScriptNode[] Columns)
Enumerator that adds fields to enumerated items.
Represents a collection of objects grouped together useing a GROUP BY construct.
Definition: GroupObject.cs:12
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21