2using System.Collections.Generic;
4using System.Reflection;
5using System.Runtime.ExceptionServices;
6using System.Threading.Tasks;
20 private readonly List<object> objects =
new List<object>();
23 private int nrObjectsInBulk = 0;
24 private int nrObjectsFailed = 0;
45 public override Task<bool>
Start()
47 PropertyInfo PI =
Database.
Provider.GetType().GetProperty(
"DeleteObsoleteKeys");
48 if (!(PI is
null) && PI.PropertyType == typeof(
bool))
58 public override Task<bool>
End()
60 PropertyInfo PI =
Database.
Provider.GetType().GetProperty(
"DeleteObsoleteKeys");
61 if (!(PI is
null) && PI.PropertyType == typeof(
bool))
74 if (!await base.StartCollection(CollectionName))
79 this.nrObjectsInBulk = 0;
90 int c = this.objects.Count;
100 this.nrObjectsFailed += this.objects.Count;
103 this.objects.Clear();
105 this.nrObjectsInBulk += c;
110 return await base.EndCollection();
129 public override async Task<string>
StartObject(
string ObjectId,
string TypeName)
131 ObjectId = await base.StartObject(ObjectId, TypeName);
142 if (!(this.obj is
null))
144 this.objects.Add(this.obj);
147 int c = this.objects.Count;
157 this.nrObjectsFailed += this.objects.Count;
160 this.objects.Clear();
162 this.nrObjectsInBulk += c;
163 if (this.nrObjectsInBulk >= 1000)
167 this.nrObjectsInBulk = 0;
172 return await base.EndObject();
181 public override Task<bool>
ReportProperty(
string PropertyName,
object PropertyValue)
183 if (!(this.obj is
null))
187 if (PropertyValue is
string s)
192 else if (PropertyValue is Guid
id)
196 if (this.
objectIdMap.TryGetValue(s, out
string s2))
198 if (Guid.TryParse(s2, out
id))
204 else if (PropertyValue is
byte[] bin)
208 if (this.
objectIdMap.TryGetValue(s, out
string s2))
210 if (Guid.TryParse(s2, out
id))
218 else if (bin2.Length == 16)
219 PropertyValue =
new Guid(bin2);
221 PropertyValue = bin2;
227 this.obj[PropertyName] = PropertyValue;
230 return base.ReportProperty(PropertyName, PropertyValue);
243 if (!await base.StartEntry(ObjectId, TypeName,
EntryType, EntryTimestamp))
260 else if (!(this.obj is
null))
264 switch (this.entryType)
270 else if (!Obj2.
Equals(
this.obj))
281 this.nrObjectsInBulk++;
282 if (this.nrObjectsInBulk >= 1000)
286 this.nrObjectsInBulk = 0;
290 return await base.EndEntry();
303 foreach (
string Folder
in Rec.Folders)
306 Directory.Delete(Folder2,
true);
310 return base.StartFiles();
321 await base.ExportFile(
FileName, File);
323 string Folder = Path.GetDirectoryName(
FileName);
324 if (!Directory.Exists(Folder))
325 Directory.CreateDirectory(Folder);
329 using (FileStream f = System.IO.File.Create(
FileName))
331 await File.CopyToAsync(f);
336 using (FileStream f = System.IO.File.OpenRead(
FileName))
338 if (File.Length == f.Length)
342 byte[] Buf1 =
new byte[65536];
343 byte[] Buf2 =
new byte[65536];
344 long l = File.Length;
348 while ((c = (
int)Math.Min(l - File.Position, 65536)) > 0)
350 await File.ReadAllAsync(Buf1, 0, c);
351 await f.ReadAllAsync(Buf2, 0, c);
353 for (i = 0; i < c; i++)
355 if (Buf1[i] != Buf2[i])
364 ExceptionDispatchInfo.Capture(ex).Throw();
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Information about an exportable folder category
Static class managing data export.
static FolderCategory[] GetRegisteredFolders()
Gets registered exportable folders.
Static class managing the runtime environment of the IoT Gateway.
static string RootFolder
Web root folder.
Class restoring the contents of a backup file.
int NrObjectsFailed
Number of objects that have not been possible to import.
override Task< bool > End()
Ends export
override Task< bool > StartFiles()
Starts export of files.
override async Task< string > StartObject(string ObjectId, string TypeName)
Is called when an object is started.
override async Task< bool > ExportFile(string FileName, Stream File)
Export file.
override async Task< bool > StartEntry(string ObjectId, string TypeName, EntryType EntryType, DateTimeOffset EntryTimestamp)
Is called when an entry is started.
override Task< bool > Start()
Starts export
override async Task< bool > EndObject()
Is called when an object is finished.
override async Task< bool > EndEntry()
Is called when an entry is finished.
override async Task< bool > StartCollection(string CollectionName)
Is called when a collection is started.
override async Task< bool > EndIndex()
Is called when an index in a collection is finished.
override async Task< bool > EndCollection()
Is called when a collection is finished.
override Task< bool > ReportProperty(string PropertyName, object PropertyValue)
Is called when a property is reported.
RestoreBackupFile(string FileName, Dictionary< string, string > ObjectIdMap)
Class restoring the contents of a backup file.
Class validating the status of a backup file.
string FileName
Name of file
string objectId
ID of current object being exported.
Dictionary< string, string > ObjectIdMap
Object ID mapping, if available.
List< string > index
Current index being exported.
string collectionName
Current collection being exported.
readonly bool mapObjectIds
If Object IDs are mapped.
readonly Dictionary< string, string > objectIdMap
Object ID map, if available
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task EndBulk()
Ends bulk-processing of data. Must be called once for every call to StartBulk.
static IDatabaseProvider Provider
Registered database provider.
static Task StartBulk()
Starts bulk-proccessing of data. Must be followed by a call to EndBulk.
Generic object. Contains a sequence of properties.
override bool Equals(object obj)
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).
Task Update(object Object)
Updates an object in the database.
Task< object > TryLoadObject(string CollectionName, object ObjectId)
Tries to load an object given its Object ID ObjectId and its collection name CollectionName .
Task AddIndex(string CollectionName, string[] FieldNames)
Adds an index to a collection, if one does not already exist.
Task Delete(object Object)
Deletes an object in the database.
Task Start()
Called when processing starts.
Task Clear(string CollectionName)
Clears a collection of all objects.
Task Insert(object Object)
Inserts an object into the database.
EntryType
Ledger entry type.