2using System.Collections.Generic;
3using System.Threading.Tasks;
14 private readonly Dictionary<string, object> blockMetaData =
new Dictionary<string, object>();
16 private string startedCollection =
null;
17 private string startedBlock =
null;
18 private bool startedCollectionExported =
false;
19 private bool startedBlockExported =
false;
20 private bool hasBlockMetaData =
false;
21 private bool includeCurrentEntry =
false;
48 return this.output.StartLedger();
57 return this.output.EndLedger();
67 this.startedCollection = CollectionName;
68 this.startedCollectionExported =
false;
70 return Task.FromResult(
true);
79 if (this.startedCollectionExported)
81 if (!await this.output.EndCollection())
84 this.startedCollectionExported =
false;
87 this.startedCollection =
null;
99 this.startedBlock = BlockID;
100 this.startedBlockExported =
false;
101 this.hasBlockMetaData =
false;
103 return Task.FromResult(
true);
114 this.blockMetaData[Key] = Value;
115 this.hasBlockMetaData =
true;
117 return Task.FromResult(
true);
126 if (this.startedBlockExported)
128 if (!await this.output.EndBlock())
131 this.startedBlockExported =
false;
134 if (this.hasBlockMetaData)
136 this.blockMetaData.Clear();
137 this.hasBlockMetaData =
false;
140 this.startedBlock =
null;
179 if (!await this.OutputPendingInfo())
182 this.includeCurrentEntry =
true;
184 return await this.output.StartEntry(ObjectId, TypeName,
EntryType, EntryTimestamp);
188 this.includeCurrentEntry =
false;
193 private async Task<bool> OutputPendingInfo()
195 if (!this.startedCollectionExported && !(this.startedCollection is
null))
197 if (!await this.output.StartCollection(
this.startedCollection))
200 this.startedCollectionExported =
true;
203 if (!this.startedBlockExported && !(this.startedBlock is
null))
205 if (!await this.output.StartBlock(
this.startedBlock))
208 this.startedBlockExported =
true;
210 if (this.hasBlockMetaData)
212 foreach (KeyValuePair<string, object> P
in this.blockMetaData)
214 if (!await this.output.BlockMetaData(P.Key, P.Value))
218 this.blockMetaData.Clear();
219 this.hasBlockMetaData =
false;
232 public virtual Task<bool>
ReportProperty(
string PropertyName,
object PropertyValue)
234 if (this.includeCurrentEntry)
235 return this.output.ReportProperty(PropertyName, PropertyValue);
237 return Task.FromResult(
true);
246 if (this.includeCurrentEntry)
248 this.includeCurrentEntry =
false;
249 if (!await this.output.EndEntry())
265 if (!await this.OutputPendingInfo())
268 if (!await this.output.CollectionCleared(EntryTimestamp))
283 return this.output.ReportError(Message);
285 return Task.FromResult(
true);
296 return this.output.ReportException(Exception);
298 return Task.FromResult(
true);
Abstract base class for ledger exports with custom entry filter rules.
virtual Task< bool > ReportProperty(string PropertyName, object PropertyValue)
Is called when a property is reported.
virtual Task< bool > StartCollection(string CollectionName)
Is called when a collection is started.
async Task< bool > EndCollection()
Is called when a collection is finished.
Task< bool > StartLedger()
Is called when export of ledger is started.
string StartedBlock
Block that is currently being processed.
CustomEntryExport(ILedgerExport Output)
Abstract base class for ledger exports with custom entry filter rules.
async Task< bool > CollectionCleared(DateTimeOffset EntryTimestamp)
Is called when the collection has been cleared.
Task< bool > ReportException(Exception Exception)
Is called when an exception has occurred.
Task< bool > ReportError(string Message)
Is called when an error is reported.
abstract bool IncludeNonEntryEvent()
If a non-entry event should be included.
virtual async Task< bool > StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
Is called when an entry is started.
virtual Task< bool > StartBlock(string BlockID)
Is called when a block in a collection is started.
virtual Task< bool > BlockMetaData(string Key, object Value)
Reports block meta-data.
virtual bool ContinueExport()
If export should be continued or not.
string StartedCollection
Collection that is currently being processed.
async Task< bool > EndBlock()
Is called when a block in a collection is finished.
Task< bool > EndLedger()
Is called when export of ledger is finished.
abstract bool IncludeEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
If an entry should be included.
virtual async Task< bool > EndEntry()
Is called when an entry is finished.
Interface for ledger exports.
EntryType
Ledger entry type.