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;
3using System.Threading.Tasks;
10
12{
17 {
18 private readonly ChunkedList<IElement> collections = new ChunkedList<IElement>();
19 private readonly ChunkedList<IElement> blocksInCollection = new ChunkedList<IElement>();
20 private readonly ChunkedList<IElement> eventsInBlock = new ChunkedList<IElement>();
21 private Dictionary<string, IElement> currentCollection = null;
22 private Dictionary<string, IElement> currentBlock = null;
23 private Dictionary<string, IElement> currentEntry = null;
24 private Dictionary<string, IElement> propertiesInEvent = null;
25
29 public ExportToJson()
30 {
31 }
32
38 {
39 return new ObjectVector(this.collections.ToArray());
40 }
41
47 public Task<bool> StartLedger(ILedgerProvider Provider)
48 {
49 return Task.FromResult(true);
50 }
51
56 public Task<bool> EndLedger()
57 {
58 return Task.FromResult(true);
59 }
60
66 public Task<bool> StartCollection(string CollectionName)
67 {
68 this.currentCollection = new Dictionary<string, IElement>()
69 {
70 { "Name", new StringValue(CollectionName) }
71 };
72
73 this.blocksInCollection.Clear();
74
75 return Task.FromResult(true);
76 }
77
82 public Task<bool> EndCollection()
83 {
84 if (this.blocksInCollection.Count > 0)
85 {
86 this.currentCollection["Blocks"] = new ObjectVector(this.blocksInCollection.ToArray());
87 this.collections.Add(new ObjectValue(this.currentCollection));
88 }
89
90 return Task.FromResult(true);
91 }
92
98 public Task<bool> StartBlock(string BlockID)
99 {
100 this.currentBlock = new Dictionary<string, IElement>()
101 {
102 { "Id", new StringValue(BlockID) }
103 };
104
105 this.eventsInBlock.Clear();
106
107 return Task.FromResult(true);
108 }
109
116 public Task<bool> BlockMetaData(string Key, object Value)
117 {
118 this.currentBlock[Key] = Expression.Encapsulate(Value);
119 return Task.FromResult(true);
120 }
121
126 public Task<bool> EndBlock()
127 {
128 if (this.eventsInBlock.Count > 0)
129 {
130 this.currentBlock["Events"] = new ObjectVector(this.eventsInBlock.ToArray());
131 this.blocksInCollection.Add(new ObjectValue(this.currentBlock));
132 }
133
134 return Task.FromResult(true);
135 }
136
145 public Task<bool> StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
146 {
147 this.propertiesInEvent = new Dictionary<string, IElement>();
148 this.currentEntry = new Dictionary<string, IElement>()
149 {
150 { "ObjectId", new ObjectValue(ObjectId) },
151 { "TypeName", new ObjectValue(TypeName) },
152 { "EntryType", new ObjectValue(EntryType) },
153 { "Timestamp", new ObjectValue(EntryTimestamp) },
154 { "this", new ObjectValue(this.propertiesInEvent) }
155 };
156
157 return Task.FromResult(true);
158 }
159
166 public Task<bool> ReportProperty(string PropertyName, object PropertyValue)
167 {
168 this.propertiesInEvent[PropertyName] = Expression.Encapsulate(PropertyValue);
169 return Task.FromResult(true);
170 }
171
176 public Task<bool> EndEntry()
177 {
178 this.eventsInBlock.Add(new ObjectValue(this.currentEntry));
179 return Task.FromResult(true);
180 }
181
187 public Task<bool> CollectionCleared(DateTimeOffset EntryTimestamp)
188 {
189 return Task.FromResult(true);
190 }
191
197 public Task<bool> ReportError(string Message)
198 {
199 return Task.FromResult(true);
200 }
201
207 public Task<bool> ReportException(Exception Exception)
208 {
209 return Task.FromResult(true);
210 }
211 }
212}
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
Class managing a script expression.
Definition: Expression.cs:41
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:5241
Export is serialized into object form.
Definition: ExportToJson.cs:17
Task< bool > ReportProperty(string PropertyName, object PropertyValue)
Is called when a property is reported.
Task< bool > StartLedger(ILedgerProvider Provider)
Is called when export of ledger is started.
Definition: ExportToJson.cs:47
Task< bool > EndCollection()
Is called when a collection is finished.
Definition: ExportToJson.cs:82
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:29
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:98
IVector ToVector()
Returns an array of exported objects.
Definition: ExportToJson.cs:37
Task< bool > EndLedger()
Is called when export of ledger is finished.
Definition: ExportToJson.cs:56
Task< bool > StartCollection(string CollectionName)
Is called when a collection is started.
Definition: ExportToJson.cs:66
Task< bool > StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
Is called when an entry is started.
Interface for ledger providers that can be plugged into the static Ledger class.
Basic interface for vectors.
Definition: IVector.cs:9
EntryType
Ledger entry type.
Definition: ILedgerEntry.cs:9