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.Threading.Tasks;
10
12{
17 {
18 private readonly ChunkedList<IElement> elements = new ChunkedList<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
71 public Task<bool> StartLedger(ILedgerProvider Provider)
72 {
73 this.height = 0;
74 this.elements.Clear();
75
76 return Task.FromResult(true);
77 }
78
83 public Task<bool> EndLedger()
84 {
85 return Task.FromResult(true);
86 }
87
93 public Task<bool> StartCollection(string CollectionName)
94 {
95 return Task.FromResult(true);
96 }
97
102 public Task<bool> EndCollection()
103 {
104 return Task.FromResult(true);
105 }
106
112 public Task<bool> StartBlock(string BlockID)
113 {
114 return Task.FromResult(true);
115 }
116
123 public Task<bool> BlockMetaData(string Key, object Value)
124 {
125 return Task.FromResult(true);
126 }
127
132 public Task<bool> EndBlock()
133 {
134 return Task.FromResult(true);
135 }
136
145 public Task<bool> StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
146 {
147 return Task.FromResult(true);
148 }
149
156 public Task<bool> ReportProperty(string PropertyName, object PropertyValue)
157 {
158 return Task.FromResult(true);
159 }
160
165 public async Task<bool> EndEntry()
166 {
167 if (this.variables is null)
168 return false;
169
170 foreach (ScriptNode Ref in this.columns)
171 {
172 try
173 {
174 IElement E;
175
176 if (Ref.IsAsynchronous)
177 E = await Ref.EvaluateAsync(this.variables);
178 else
179 E = Ref.Evaluate(this.variables);
180
181 this.elements.Add(E);
182 }
183 catch (Exception ex)
184 {
185 this.elements.Add(new ObjectValue(ex));
186 }
187 }
188
189 this.height++;
190
191 return true;
192 }
193
199 public Task<bool> CollectionCleared(DateTimeOffset EntryTimestamp)
200 {
201 return Task.FromResult(true);
202 }
203
209 public Task<bool> ReportError(string Message)
210 {
211 return Task.FromResult(true);
212 }
213
219 public Task<bool> ReportException(Exception Exception)
220 {
221 return Task.FromResult(true);
222 }
223 }
224}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
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 > StartLedger(ILedgerProvider Provider)
Is called when export of ledger is started.
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.
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
Interface for ledger providers that can be plugged into the static Ledger class.
Basic interface for all types of elements.
Definition: IElement.cs:21
EntryType
Ledger entry type.
Definition: ILedgerEntry.cs:9