Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ExportToJson.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
9
11{
16 {
17 private readonly List<IElement> collections = new List<IElement>();
18 private readonly List<IElement> blocksInCollection = new List<IElement>();
19 private readonly List<IElement> eventsInBlock = new List<IElement>();
20 private Dictionary<string, IElement> currentCollection = null;
21 private Dictionary<string, IElement> currentBlock = null;
22 private Dictionary<string, IElement> currentEntry = null;
23 private Dictionary<string, IElement> propertiesInEvent = null;
24
28 public ExportToJson()
29 {
30 }
31
37 {
38 return new ObjectVector(this.collections.ToArray());
39 }
40
45 public Task<bool> StartLedger()
46 {
47 return Task.FromResult(true);
48 }
49
54 public Task<bool> EndLedger()
55 {
56 return Task.FromResult(true);
57 }
58
64 public Task<bool> StartCollection(string CollectionName)
65 {
66 this.currentCollection = new Dictionary<string, IElement>()
67 {
68 { "Name", new StringValue(CollectionName) }
69 };
70
71 this.blocksInCollection.Clear();
72
73 return Task.FromResult(true);
74 }
75
80 public Task<bool> EndCollection()
81 {
82 if (this.blocksInCollection.Count > 0)
83 {
84 this.currentCollection["Blocks"] = new ObjectVector(this.blocksInCollection.ToArray());
85 this.collections.Add(new ObjectValue(this.currentCollection));
86 }
87
88 return Task.FromResult(true);
89 }
90
96 public Task<bool> StartBlock(string BlockID)
97 {
98 this.currentBlock = new Dictionary<string, IElement>()
99 {
100 { "Id", new StringValue(BlockID) }
101 };
102
103 this.eventsInBlock.Clear();
104
105 return Task.FromResult(true);
106 }
107
114 public Task<bool> BlockMetaData(string Key, object Value)
115 {
116 this.currentBlock[Key] = Expression.Encapsulate(Value);
117 return Task.FromResult(true);
118 }
119
124 public Task<bool> EndBlock()
125 {
126 if (this.eventsInBlock.Count > 0)
127 {
128 this.currentBlock["Events"] = new ObjectVector(this.eventsInBlock.ToArray());
129 this.blocksInCollection.Add(new ObjectValue(this.currentBlock));
130 }
131
132 return Task.FromResult(true);
133 }
134
143 public Task<bool> StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
144 {
145 this.propertiesInEvent = new Dictionary<string, IElement>();
146 this.currentEntry = new Dictionary<string, IElement>()
147 {
148 { "ObjectId", new ObjectValue(ObjectId) },
149 { "TypeName", new ObjectValue(TypeName) },
150 { "EntryType", new ObjectValue(EntryType) },
151 { "Timestamp", new ObjectValue(EntryTimestamp) },
152 { "this", new ObjectValue(this.propertiesInEvent) }
153 };
154
155 return Task.FromResult(true);
156 }
157
164 public Task<bool> ReportProperty(string PropertyName, object PropertyValue)
165 {
166 this.propertiesInEvent[PropertyName] = Expression.Encapsulate(PropertyValue);
167 return Task.FromResult(true);
168 }
169
174 public Task<bool> EndEntry()
175 {
176 this.eventsInBlock.Add(new ObjectValue(this.currentEntry));
177 return Task.FromResult(true);
178 }
179
185 public Task<bool> CollectionCleared(DateTimeOffset EntryTimestamp)
186 {
187 return Task.FromResult(true);
188 }
189
195 public Task<bool> ReportError(string Message)
196 {
197 return Task.FromResult(true);
198 }
199
205 public Task<bool> ReportException(Exception Exception)
206 {
207 return Task.FromResult(true);
208 }
209 }
210}
Class managing a script expression.
Definition: Expression.cs:39
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:4955
Export is serialized into object form.
Definition: ExportToJson.cs:16
Task< bool > StartLedger()
Is called when export of ledger is started.
Definition: ExportToJson.cs:45
Task< bool > ReportProperty(string PropertyName, object PropertyValue)
Is called when a property is reported.
Task< bool > EndCollection()
Is called when a collection is finished.
Definition: ExportToJson.cs:80
Task< bool > CollectionCleared(DateTimeOffset EntryTimestamp)
Is called when the collection has been cleared.
Task< bool > ReportError(string Message)
Is called when an error is reported.
ExportToJson()
Export is serialized into object form.
Definition: ExportToJson.cs:28
Task< bool > EndBlock()
Is called when a block in a collection is finished.
Task< bool > EndEntry()
Is called when an entry is finished.
Task< bool > ReportException(Exception Exception)
Is called when an exception has occurred.
Task< bool > BlockMetaData(string Key, object Value)
Reports block meta-data.
Task< bool > StartBlock(string BlockID)
Is called when a block in a collection is started.
Definition: ExportToJson.cs:96
IVector ToVector()
Returns an array of exported objects.
Definition: ExportToJson.cs:36
Task< bool > EndLedger()
Is called when export of ledger is finished.
Definition: ExportToJson.cs:54
Task< bool > StartCollection(string CollectionName)
Is called when a collection is started.
Definition: ExportToJson.cs:64
Task< bool > StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
Is called when an entry is started.
Basic interface for vectors.
Definition: IVector.cs:9
EntryType
Ledger entry type.
Definition: ILedgerEntry.cs:9