Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GroupEnumerator.cs
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
8
10{
15 {
16 private readonly ScriptNode[] groupBy;
17 private readonly ScriptNode[] groupNames;
18 private readonly Variables variables;
19 private readonly IResultSetEnumerator e;
20 private bool processLast = false;
21 private GroupObject current = null;
22 private ObjectProperties objectVariables = null;
23
31 public GroupEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, ScriptNode[] GroupBy, ScriptNode[] GroupNames)
32 {
33 this.e = ItemEnumerator;
34 this.variables = Variables;
35 this.groupBy = GroupBy;
36 this.groupNames = GroupNames;
37 }
38
42 public object Current => this.current;
43
47 public bool MoveNext()
48 {
49 return this.MoveNextAsync().Result;
50 }
51
58 public async Task<bool> MoveNextAsync()
59 {
60 List<object> Objects = null;
61 IElement E;
62 object[] Last = null;
63 int i, c = this.groupBy.Length;
64 object o1, o2;
65
66 while (this.processLast || await this.e.MoveNextAsync())
67 {
68 this.processLast = false;
69
70 if (this.objectVariables is null)
71 this.objectVariables = new ObjectProperties(this.e.Current, this.variables);
72 else
73 this.objectVariables.Object = this.e.Current;
74
75 if (Last is null)
76 {
77 Last = new object[c];
78
79 for (i = 0; i < c; i++)
80 {
81 E = this.groupBy[i].Evaluate(this.objectVariables);
82 Last[i] = E.AssociatedObjectValue;
83 }
84 }
85 else
86 {
87 for (i = 0; i < c; i++)
88 {
89 E = this.groupBy[i].Evaluate(this.objectVariables);
90
91 o1 = Last[i];
93
94 if (o1 is null ^ o2 is null)
95 break;
96
97 if (!(o1 is null) && !o1.Equals(o2))
98 break;
99 }
100
101 if (i < c)
102 {
103 this.processLast = true;
104 break;
105 }
106 }
107
108 if (Objects is null)
109 Objects = new List<object>();
110
111 Objects.Add(this.e.Current);
112 }
113
114 if (Objects is null)
115 return false;
116
117 this.current = new GroupObject(Objects.ToArray(), Last, this.groupNames, this.variables);
118
119 return true;
120 }
121
125 public void Reset()
126 {
127 this.e.Reset();
128 this.processLast = false;
129 this.current = null;
130 }
131 }
132}
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Enumerator that groups items into groups, and returns aggregated elements.
async Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
GroupEnumerator(IResultSetEnumerator ItemEnumerator, Variables Variables, ScriptNode[] GroupBy, ScriptNode[] GroupNames)
Enumerator that groups items into groups, and returns aggregated elements.
Represents a collection of objects grouped together useing a GROUP BY construct.
Definition: GroupObject.cs:13
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