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);
165 return Task.FromResult(
true);
174 return Task.FromResult(
true);
184 return Task.FromResult(
true);
193 return Task.FromResult(
true);
203 this.collectionName = CollectionName;
204 this.nrCollections++;
206 return Task.FromResult(
true);
215 this.collectionName =
null;
216 return Task.FromResult(
true);
227 return Task.FromResult(
true);
236 return Task.FromResult(
true);
248 this.index.Add(FieldName);
250 this.index.Add(
"-" + FieldName);
252 return Task.FromResult(
true);
263 return Task.FromResult(
true);
272 return Task.FromResult(
true);
283 return Task.FromResult(
true);
292 public virtual Task<string>
StartObject(
string ObjectId,
string TypeName)
294 this.objectId = this.MapObjectId(ObjectId);
295 this.typeName = TypeName;
298 return Task.FromResult(ObjectId);
301 private string MapObjectId(
string ObjectId)
303 if (this.mapObjectIds)
305 string ObjectId0 = ObjectId;
307 if (!this.objectIdMap.TryGetValue(ObjectId0, out ObjectId))
312 if (
System.Guid.TryParse(ObjectId0, out Guid Guid))
313 A = Guid.ToByteArray();
317 if (!(A is
null) && (c = A.Length) !=
this.objectIdByteCount)
319 if (c > this.objectIdByteCount)
323 for (i = this.objectIdByteCount; i < c; i++)
326 ObjectId =
new Guid(A).ToString();
330 Array.Resize(ref A, this.objectIdByteCount);
336 Array.Resize(ref A, this.objectIdByteCount);
338 if (this.objectIdByteCount == 16)
339 ObjectId =
new Guid(A).ToString();
344 while (this.objectIdMap.ContainsKey(ObjectId))
346 if (this.objectIdByteCount == 16)
347 ObjectId = Guid.NewGuid().ToString();
355 this.objectIdMap[ObjectId0] = ObjectId;
358 ObjectId = ObjectId0;
371 this.objectId =
null;
372 this.typeName =
null;
374 return Task.FromResult(
true);
387 this.objectId = this.MapObjectId(ObjectId);
388 this.typeName = TypeName;
391 return Task.FromResult(
true);
400 this.objectId =
null;
401 this.typeName =
null;
403 return Task.FromResult(
true);
424 public virtual Task<bool>
ReportProperty(
string PropertyName,
object PropertyValue)
427 return Task.FromResult(
true);
436 return Task.FromResult(
true);
445 return Task.FromResult(
true);
457 this.nrFileBytes += File.Length;
459 return Task.FromResult(
true);
469 return Task.FromResult(
true);
479 return Task.FromResult(
true);
489 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
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 > StartDatabase(IDatabaseProvider Provider)
Is called when export of database is started.
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.
virtual Task< bool > StartLedger(ILedgerProvider Provider)
Is called when export of ledger is started.
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 > 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).
Interface for database providers that can be plugged into the static Database class.
int ObjectIdByteCount
Number of bytes used by an Object ID.
Interface for ledger providers that can be plugged into the static Ledger class.
EntryType
Ledger entry type.