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;
2using System.Collections;
3using System.Threading.Tasks;
4using Waher.Events;
7
9{
14 {
15 private readonly IResultSetEnumerator e;
16 private readonly ScriptNode[] columns;
17 private readonly Variables variables;
18 private readonly int count;
19 private IElement[] record;
20 private ObjectProperties properties = null;
21
29 {
30 this.e = ItemEnumerator;
31 this.columns = Columns;
32 this.variables = Variables;
33 this.count = this.columns?.Length ?? 0;
34 }
35
39 public object Current => this.e.Current;
40
44 public IElement[] CurrentRecord => this.record;
45
49 public virtual bool MoveNext()
50 {
51 return this.MoveNextAsync().Result;
52 }
53
60 public virtual async Task<bool> MoveNextAsync()
61 {
62 if (!await this.e.MoveNextAsync())
63 return false;
64
65 int i;
66 object Item = this.e.Current;
67 IElement Element = Item as IElement;
68
69 if (this.properties is null)
70 this.properties = new ObjectProperties(Element?.AssociatedObjectValue ?? Item, this.variables);
71 else
72 this.properties.Object = Element?.AssociatedObjectValue ?? Item;
73
74 if (this.columns is null)
75 this.record = new IElement[1] { Element ?? Expression.Encapsulate(Item) };
76 else
77 {
78 this.record = new IElement[this.count];
79
80 for (i = 0; i < this.count; i++)
81 {
82 try
83 {
84 this.record[i] = await this.columns[i].EvaluateAsync(this.properties);
85 }
86 catch (Exception ex)
87 {
88 ex = Log.UnnestException(ex);
89 this.record[i] = Expression.Encapsulate(ex);
90 }
91 }
92 }
93
94 return true;
95 }
96
100 public virtual void Reset()
101 {
102 this.e.Reset();
103 }
104
105 }
106}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Definition: Log.cs:818
Base class for all types of elements.
Definition: Element.cs:13
abstract object AssociatedObjectValue
Associated object value.
Definition: Element.cs:46
Class managing a script expression.
Definition: Expression.cs:39
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:4955
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Enumerator that limits the return set to a maximum number of records.
virtual async Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
RecordEnumerator(IResultSetEnumerator ItemEnumerator, ScriptNode[] Columns, Variables Variables)
Enumerator that limits the return set to a maximum number of records.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20