Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ExportToTable.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
10
12{
17 {
18 private readonly LinkedList<IElement> elements = new LinkedList<IElement>();
19 private readonly ScriptNode[] columns;
20 private readonly int width;
21 private int height;
22 private Variables variables;
23
28 public ExportToTable(ScriptNode[] Columns)
29 {
30 this.columns = Columns;
31 this.width = this.columns.Length;
32 }
33
38 {
39 get => this.variables;
40 internal set => this.variables = value;
41 }
42
48 {
49 string[] Headers = new string[this.width];
50 int i;
51
52 for (i = 0; i < this.width; i++)
53 {
54 if (this.columns[i] is VariableReference Ref)
55 Headers[i] = Ref.VariableName;
56 else
57 Headers[i] = "c" + (i + 1).ToString();
58 }
59
60 return new ObjectMatrix(this.height, this.width, this.elements)
61 {
62 ColumnNames = Headers
63 };
64 }
65
70 public Task<bool> StartLedger()
71 {
72 this.height = 0;
73 this.elements.Clear();
74
75 return Task.FromResult(true);
76 }
77
82 public Task<bool> EndLedger()
83 {
84 return Task.FromResult(true);
85 }
86
92 public Task<bool> StartCollection(string CollectionName)
93 {
94 return Task.FromResult(true);
95 }
96
101 public Task<bool> EndCollection()
102 {
103 return Task.FromResult(true);
104 }
105
111 public Task<bool> StartBlock(string BlockID)
112 {
113 return Task.FromResult(true);
114 }
115
122 public Task<bool> BlockMetaData(string Key, object Value)
123 {
124 return Task.FromResult(true);
125 }
126
131 public Task<bool> EndBlock()
132 {
133 return Task.FromResult(true);
134 }
135
144 public Task<bool> StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
145 {
146 return Task.FromResult(true);
147 }
148
155 public Task<bool> ReportProperty(string PropertyName, object PropertyValue)
156 {
157 return Task.FromResult(true);
158 }
159
164 public async Task<bool> EndEntry()
165 {
166 if (this.variables is null)
167 return false;
168
169 foreach (ScriptNode Ref in this.columns)
170 {
171 try
172 {
173 IElement E;
174
175 if (Ref.IsAsynchronous)
176 E = await Ref.EvaluateAsync(this.variables);
177 else
178 E = Ref.Evaluate(this.variables);
179
180 this.elements.AddLast(E);
181 }
182 catch (Exception ex)
183 {
184 this.elements.AddLast(new ObjectValue(ex));
185 }
186 }
187
188 this.height++;
189
190 return true;
191 }
192
198 public Task<bool> CollectionCleared(DateTimeOffset EntryTimestamp)
199 {
200 return Task.FromResult(true);
201 }
202
208 public Task<bool> ReportError(string Message)
209 {
210 return Task.FromResult(true);
211 }
212
218 public Task<bool> ReportException(Exception Exception)
219 {
220 return Task.FromResult(true);
221 }
222 }
223}
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
virtual bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: ScriptNode.cs:142
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Represents a variable reference.
Task< bool > StartBlock(string BlockID)
Is called when a block in a collection is started.
Task< bool > EndLedger()
Is called when export of ledger is finished.
ObjectMatrix ToMatrix()
Converts the exported information into an object matrix with column headers.
Task< bool > EndCollection()
Is called when a collection is finished.
Task< bool > BlockMetaData(string Key, object Value)
Reports block meta-data.
Task< bool > StartCollection(string CollectionName)
Is called when a collection is started.
Task< bool > ReportError(string Message)
Is called when an error is reported.
async Task< bool > EndEntry()
Is called when an entry is finished.
Task< bool > ReportException(Exception Exception)
Is called when an exception has occurred.
Task< bool > ReportProperty(string PropertyName, object PropertyValue)
Is called when a property is reported.
Task< bool > StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
Is called when an entry is started.
Task< bool > StartLedger()
Is called when export of ledger is started.
ExportToTable(ScriptNode[] Columns)
Export is serialized into object form.
Task< bool > CollectionCleared(DateTimeOffset EntryTimestamp)
Is called when the collection has been cleared.
Task< bool > EndBlock()
Is called when a block in a collection is finished.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
EntryType
Ledger entry type.
Definition: ILedgerEntry.cs:9