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;
49 return this.output.StartLedger(Provider);
58 return this.output.EndLedger();
68 this.startedCollection = CollectionName;
69 this.startedCollectionExported =
false;
71 return Task.FromResult(
true);
80 if (this.startedCollectionExported)
82 if (!await this.output.EndCollection())
85 this.startedCollectionExported =
false;
88 this.startedCollection =
null;
100 this.startedBlock = BlockID;
101 this.startedBlockExported =
false;
102 this.hasBlockMetaData =
false;
104 return Task.FromResult(
true);
115 this.blockMetaData[Key] = Value;
116 this.hasBlockMetaData =
true;
118 return Task.FromResult(
true);
127 if (this.startedBlockExported)
129 if (!await this.output.EndBlock())
132 this.startedBlockExported =
false;
135 if (this.hasBlockMetaData)
137 this.blockMetaData.Clear();
138 this.hasBlockMetaData =
false;
141 this.startedBlock =
null;
180 if (!await this.OutputPendingInfo())
183 this.includeCurrentEntry =
true;
185 return await this.output.StartEntry(ObjectId, TypeName,
EntryType, EntryTimestamp);
189 this.includeCurrentEntry =
false;
194 private async Task<bool> OutputPendingInfo()
196 if (!this.startedCollectionExported && !(this.startedCollection is
null))
198 if (!await this.output.StartCollection(
this.startedCollection))
201 this.startedCollectionExported =
true;
204 if (!this.startedBlockExported && !(this.startedBlock is
null))
206 if (!await this.output.StartBlock(
this.startedBlock))
209 this.startedBlockExported =
true;
211 if (this.hasBlockMetaData)
213 foreach (KeyValuePair<string, object> P
in this.blockMetaData)
215 if (!await this.output.BlockMetaData(P.Key, P.Value))
219 this.blockMetaData.Clear();
220 this.hasBlockMetaData =
false;
233 public virtual Task<bool>
ReportProperty(
string PropertyName,
object PropertyValue)
235 if (this.includeCurrentEntry)
236 return this.output.ReportProperty(PropertyName, PropertyValue);
238 return Task.FromResult(
true);
247 if (this.includeCurrentEntry)
249 this.includeCurrentEntry =
false;
250 if (!await this.output.EndEntry())
266 if (!await this.OutputPendingInfo())
269 if (!await this.output.CollectionCleared(EntryTimestamp))
284 return this.output.ReportError(Message);
286 return Task.FromResult(
true);
297 return this.output.ReportException(Exception);
299 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.
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 > StartLedger(ILedgerProvider Provider)
Is called when export of ledger is started.
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 providers that can be plugged into the static Ledger class.
Interface for ledger exports.
EntryType
Ledger entry type.