Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RecordEnumerator.cs
1using System;
3using System.Threading.Tasks;
4using Waher.Events;
7
9{
14 {
15 private readonly IResultSetEnumerator e;
16 private readonly ScriptNode[] columns;
17 private readonly bool[] columnAsynchronous;
18 private readonly Variables variables;
19 private readonly int count;
20 private IElement[] record;
21 private ObjectProperties properties = null;
22
30 {
31 this.e = ItemEnumerator;
32 this.columns = Columns;
33 this.variables = Variables;
34 this.count = this.columns?.Length ?? 0;
35 this.columnAsynchronous = new bool[this.count];
36
37 for (int i = 0; i < this.count; i++)
38 this.columnAsynchronous[i] = this.columns[i].IsAsynchronous;
39 }
40
44 public object Current => this.e.Current;
45
49 public IElement[] CurrentRecord => this.record;
50
54 public void Dispose()
55 {
56 this.e.Dispose();
57 }
58
62 public virtual bool MoveNext()
63 {
64 return this.MoveNextAsync().Result;
65 }
66
73 public virtual async Task<bool> MoveNextAsync()
74 {
75 if (!await this.e.MoveNextAsync())
76 return false;
77
78 int i;
79 object Item = this.e.Current;
80 IElement Element = Item as IElement;
81
82 if (this.properties is null)
83 this.properties = new ObjectProperties(Element?.AssociatedObjectValue ?? Item, this.variables);
84 else
85 this.properties.Object = Element?.AssociatedObjectValue ?? Item;
86
87 if (this.columns is null)
88 this.record = new IElement[1] { Element ?? Expression.Encapsulate(Item) };
89 else
90 {
91 this.record = new IElement[this.count];
92
93 for (i = 0; i < this.count; i++)
94 {
95 try
96 {
97 if (this.columnAsynchronous[i])
98 this.record[i] = await this.columns[i].EvaluateAsync(this.properties);
99 else
100 this.record[i] = this.columns[i].Evaluate(this.properties);
101 }
102 catch (Exception ex)
103 {
104 ex = Log.UnnestException(ex);
105 this.record[i] = Expression.Encapsulate(ex);
106 }
107 }
108 }
109
110 return true;
111 }
112
116 public virtual void Reset()
117 {
118 this.e.Reset();
119 }
120
121 }
122}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:828
Base class for all types of elements.
Definition: Element.cs:14
abstract object AssociatedObjectValue
Associated object value.
Definition: Element.cs:43
Class managing a script expression.
Definition: Expression.cs:41
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:5241
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Enumerator that returns a tabular result set.
virtual async Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
RecordEnumerator(IResultSetEnumerator ItemEnumerator, ScriptNode[] Columns, Variables Variables)
Enumerator that returns a tabular result set.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21