2using System.Collections.Generic;
4using System.Threading.Tasks;
19 protected List<string>
index =
new List<string>();
46 private readonly
string fileName;
47 private readonly
int objectIdByteCount;
48 private long nrCollections = 0;
49 private long nrIndices = 0;
50 private long nrBlocks = 0;
51 private long nrObjects = 0;
52 private long nrEntries = 0;
53 private long nrProperties = 0;
54 private long nrFiles = 0;
55 private long nrFileBytes = 0;
68 this.objectIdMap =
ObjectIdMap ??
new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
69 this.mapObjectIds =
true;
73 this.objectIdMap =
null;
74 this.mapObjectIds =
false;
146 return Task.FromResult(
true);
153 public virtual Task<bool>
End()
155 return Task.FromResult(
true);
164 return Task.FromResult(
true);
173 return Task.FromResult(
true);
182 return Task.FromResult(
true);
191 return Task.FromResult(
true);
201 this.collectionName = CollectionName;
202 this.nrCollections++;
204 return Task.FromResult(
true);
213 this.collectionName =
null;
214 return Task.FromResult(
true);
225 return Task.FromResult(
true);
234 return Task.FromResult(
true);
246 this.index.Add(FieldName);
248 this.index.Add(
"-" + FieldName);
250 return Task.FromResult(
true);
261 return Task.FromResult(
true);
270 return Task.FromResult(
true);
281 return Task.FromResult(
true);
290 public virtual Task<string>
StartObject(
string ObjectId,
string TypeName)
292 this.objectId = this.MapObjectId(ObjectId);
293 this.typeName = TypeName;
296 return Task.FromResult(ObjectId);
299 private string MapObjectId(
string ObjectId)
301 if (this.mapObjectIds)
303 string ObjectId0 = ObjectId;
305 if (!this.objectIdMap.TryGetValue(ObjectId0, out ObjectId))
310 if (System.Guid.TryParse(ObjectId0, out Guid Guid))
311 A = Guid.ToByteArray();
315 if (!(A is
null) && (c = A.Length) !=
this.objectIdByteCount)
317 if (c > this.objectIdByteCount)
321 for (i = this.objectIdByteCount; i < c; i++)
324 ObjectId =
new Guid(A).ToString();
328 Array.Resize(ref A, this.objectIdByteCount);
334 Array.Resize(ref A, this.objectIdByteCount);
336 if (this.objectIdByteCount == 16)
337 ObjectId =
new Guid(A).ToString();
342 while (this.objectIdMap.ContainsKey(ObjectId))
344 if (this.objectIdByteCount == 16)
345 ObjectId = Guid.NewGuid().ToString();
353 this.objectIdMap[ObjectId0] = ObjectId;
356 ObjectId = ObjectId0;
369 this.objectId =
null;
370 this.typeName =
null;
372 return Task.FromResult(
true);
385 this.objectId = this.MapObjectId(ObjectId);
386 this.typeName = TypeName;
389 return Task.FromResult(
true);
398 this.objectId =
null;
399 this.typeName =
null;
401 return Task.FromResult(
true);
422 public virtual Task<bool>
ReportProperty(
string PropertyName,
object PropertyValue)
425 return Task.FromResult(
true);
434 return Task.FromResult(
true);
443 return Task.FromResult(
true);
455 this.nrFileBytes += File.Length;
457 return Task.FromResult(
true);
467 return Task.FromResult(
true);
477 return Task.FromResult(
true);
487 return Task.FromResult(
true);
Static class managing the runtime environment of the IoT Gateway.
static byte[] NextBytes(int NrBytes)
Generates an array of random bytes.
Class validating the status of a backup file.
virtual Task< bool > EndIndex()
Is called when an index in a collection is finished.
long NrFiles
Number of files processed.
virtual Task< bool > EndBlock()
Is called when a block in a collection is finished.
string FileName
Name of file
virtual Task< bool > StartLedger()
Is called when export of ledger is started.
long NrEntries
Number of entries processed.
string objectId
ID of current object being exported.
virtual Task< bool > Start()
Starts export
Dictionary< string, string > ObjectIdMap
Object ID mapping, if available.
virtual Task< bool > EndCollection()
Is called when a collection is finished.
long NrCollections
Number of collections processed.
virtual void Dispose()
IDisposable.Dispose
virtual Task< bool > StartCollection(string CollectionName)
Is called when a collection is started.
virtual Task< bool > StartIndex()
Is called when an index in a collection is started.
string typeName
Type Name of current object being exported.
virtual Task< bool > End()
Ends export
long NrIndices
Number of indices processed.
List< string > index
Current index being exported.
ValidateBackupFile(string FileName, Dictionary< string, string > ObjectIdMap)
Class validating the status of a backup file.
string[] CollectionNames
Optional array of collection nmes to export. If null, all collections will be exported.
virtual Task< bool > EndLedger()
Is called when export of ledger is finished.
virtual Task< bool > StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
Is called when an entry is started.
virtual Task< bool > ReportProperty(string PropertyName, object PropertyValue)
Is called when a property is reported.
string collectionName
Current collection being exported.
virtual Task< bool > EndDatabase()
Is called when export of database is finished.
readonly bool mapObjectIds
If Object IDs are mapped.
long NrBlocks
Number of blocks processed.
virtual Task< string > StartObject(string ObjectId, string TypeName)
Is called when an object is started.
virtual Task< bool > UpdateClient(bool ForceUpdate)
If any clients should be updated about export status.
long NrFileBytes
Number of file byets processed.
virtual Task< bool > ExportFile(string FileName, Stream File)
Export file.
virtual Task< bool > BlockMetaData(string Key, object Value)
Reports block meta-data.
virtual Task< bool > StartFiles()
Starts export of files.
virtual Task< bool > ReportIndexField(string FieldName, bool Ascending)
Is called when a field in an index is reported.
virtual Task< bool > ReportException(Exception Exception)
Is called when an exception has occurred.
long NrProperties
Number of propeties processed.
virtual Task< bool > ReportError(string Message)
Is called when an error is reported.
readonly Dictionary< string, string > objectIdMap
Object ID map, if available
long NrObjects
Number of objects processed.
virtual Task< bool > StartDatabase()
Is called when export of database is started.
virtual Task< bool > EndFiles()
Ends export of files.
virtual Task< bool > EndEntry()
Is called when an entry is finished.
virtual async Task< bool > CollectionCleared(DateTimeOffset EntryTimestamp)
Is called when a collection has been cleared.
virtual Task< bool > StartBlock(string BlockID)
Is called when a block in a collection is started.
virtual Task< bool > EndObject()
Is called when an object is finished.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static IDatabaseProvider Provider
Registered database provider.
Contains methods for simple hash calculations.
static byte[] StringToBinary(string s)
Parses a hex string.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
int ObjectIdByteCount
Number of bytes used by an Object ID.
EntryType
Ledger entry type.