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;
2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
8
10{
15 {
16 private readonly KeyValuePair<string, ScriptNode>[] additionalFields;
17 private readonly IResultSetEnumerator e;
18 private readonly Variables variables;
19 private ObjectProperties objectVariables = null;
20 private object current = null;
21
28 public FieldAggregatorEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, KeyValuePair<string, ScriptNode>[] AdditionalFields)
29 {
30 this.e = ItemEnumerator;
31 this.variables = Variables;
32 this.additionalFields = AdditionalFields;
33 }
34
38 public object Current => this.current;
39
43 public bool MoveNext()
44 {
45 return this.MoveNextAsync().Result;
46 }
47
54 public async Task<bool> MoveNextAsync()
55 {
56 if (!await this.e.MoveNextAsync())
57 return false;
58
59 this.current = this.e.Current;
60
61 if (this.objectVariables is null)
62 this.objectVariables = new ObjectProperties(this.current, this.variables);
63 else
64 this.objectVariables.Object = this.e.Current;
65
66 if (this.current is GenericObject GenObj)
67 {
68 foreach (KeyValuePair<string, ScriptNode> P in this.additionalFields)
69 GenObj[P.Key] = P.Value.Evaluate(this.objectVariables);
70 }
71 else if (this.current is GroupObject GroupObj)
72 {
73 foreach (KeyValuePair<string, ScriptNode> P in this.additionalFields)
74 GroupObj[P.Key] = P.Value.Evaluate(this.objectVariables);
75 }
76 else
77 {
78 GroupObject Obj = new GroupObject(new object[] { this.current }, new object[0], new ScriptNode[0], this.objectVariables);
79
80 foreach (KeyValuePair<string, ScriptNode> P in this.additionalFields)
81 Obj[P.Key] = P.Value.Evaluate(this.objectVariables);
82
83 this.current = Obj;
84 }
85
86 return true;
87 }
88
92 public void Reset()
93 {
94 this.e.Reset();
95 this.current = null;
96 }
97 }
98}
Generic object. Contains a sequence of properties.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
async Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
FieldAggregatorEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, KeyValuePair< string, ScriptNode >[] AdditionalFields)
Enumerator that adds fields to enumerated items.
Represents a collection of objects grouped together useing a GROUP BY construct.
Definition: GroupObject.cs:13
Collection of variables.
Definition: Variables.cs:25