Add automatic database backups
Test / Run tests (push) Successful in 2m46s

This commit is contained in:
2026-08-24 20:52:50 +02:00
parent 7d5d7d9307
commit 70e1e7c73a
4 changed files with 222 additions and 0 deletions
+16
View File
@@ -28,6 +28,8 @@ namespace Elwig {
public static bool ForceShutdown { get; private set; } = false;
private readonly DispatcherTimer _autoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
private readonly DispatcherTimer _autoBackupTimer = new() { Interval = TimeSpan.FromHours(1) };
private DatabaseBackupService? _databaseBackupService;
public readonly SerialPortWatcher SerialPortWatcher = new();
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Elwig");
@@ -101,6 +103,13 @@ namespace Elwig {
return;
}
if (Config.DatabaseBackup) {
_databaseBackupService = new DatabaseBackupService(Config.DatabaseFile);
await _databaseBackupService.RunIfNeededAsync();
_autoBackupTimer.Tick += OnAutoBackupTimer;
_autoBackupTimer.Start();
}
LastChanged = CurrentLastWrite;
ContextTimer.Start();
@@ -191,6 +200,7 @@ namespace Elwig {
}
private async void Application_Exit(object sender, ExitEventArgs evt) {
_autoBackupTimer.Stop();
SerialPortWatcher.Dispose();
foreach (var s in EventScales) {
s.Dispose();
@@ -198,6 +208,12 @@ namespace Elwig {
await Pdf.Cleanup();
}
private async void OnAutoBackupTimer(object? sender, EventArgs evt) {
if (_databaseBackupService != null) {
await _databaseBackupService.RunIfNeededAsync();
}
}
public static void SetBranch(Branch b) {
SetBranch((b.ZwstId, b.Name, b.PostalDest?.AtPlz?.Plz, b.PostalDest?.AtPlz?.Ort.Name, b.Address, b.PhoneNr, b.FaxNr, b.MobileNr));
}