+31
-8
@@ -25,9 +25,10 @@ namespace Elwig {
|
||||
|
||||
protected static App CurrentApp;
|
||||
public static int NumWindows => CurrentApp.Windows.Count;
|
||||
public static bool ForceShutdown { get; private set; } = false;
|
||||
public static bool ForceShutdown { get; set; } = false;
|
||||
|
||||
private readonly DispatcherTimer _autoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
|
||||
private readonly DispatcherTimer _autoBackupTimer = new() { Interval = TimeSpan.FromMinutes(10) };
|
||||
public readonly SerialPortWatcher SerialPortWatcher = new();
|
||||
|
||||
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Elwig");
|
||||
@@ -74,7 +75,7 @@ namespace Elwig {
|
||||
Config = new(Path.GetFullPath(args[1]));
|
||||
}
|
||||
|
||||
ContextTimer.Tick += (object? sender, EventArgs evt) => {
|
||||
ContextTimer.Tick += (sender, evt) => {
|
||||
var ch = CurrentLastWrite;
|
||||
if (ch > LastChanged) {
|
||||
LastChanged = ch;
|
||||
@@ -106,9 +107,8 @@ namespace Elwig {
|
||||
|
||||
Dictionary<string, (string, string, int?, string?, string?, string?, string?, string?)> branches = [];
|
||||
using (var ctx = new AppDbContext()) {
|
||||
branches = ctx.FetchBranches()
|
||||
.ToDictionaryAsync(b => b.Name.ToLower(), b => (b.ZwstId, b.Name, b.PostalDest?.AtPlz?.Plz, b.PostalDest?.AtPlz?.Ort.Name, b.Address, b.PhoneNr, b.FaxNr, b.MobileNr))
|
||||
.GetAwaiter().GetResult();
|
||||
branches = await ctx.FetchBranches()
|
||||
.ToDictionaryAsync(b => b.Name.ToLower(), b => (b.ZwstId, b.Name, b.PostalDest?.AtPlz?.Plz, b.PostalDest?.AtPlz?.Ort.Name, b.Address, b.PhoneNr, b.FaxNr, b.MobileNr));
|
||||
try {
|
||||
Client = new(ctx);
|
||||
} catch (Exception exc) {
|
||||
@@ -124,9 +124,23 @@ namespace Elwig {
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
Utils.RunBackground("PDF Initialization", () => Pdf.Init());
|
||||
Utils.RunBackground("PDF Initialization", async () => Pdf.Init());
|
||||
Utils.RunBackground("JSON Schema Initialization", BillingData.Init);
|
||||
|
||||
if (Config.BackupAuto) {
|
||||
Utils.RunBackground("Automatisches Backup", async () => {
|
||||
Directory.CreateDirectory(Config.BackupPath);
|
||||
await Task.Delay(500);
|
||||
await BackupService.TryDatabaseBackup();
|
||||
});
|
||||
_autoBackupTimer.Tick += new EventHandler((sender, evt) => {
|
||||
Utils.RunBackground("Automatisches Backup", async () => {
|
||||
await BackupService.TryDatabaseBackup();
|
||||
});
|
||||
});
|
||||
_autoBackupTimer.Start();
|
||||
}
|
||||
|
||||
if (Config.UpdateAuto && Config.UpdateUrl != null) {
|
||||
if (Utils.HasInternetConnectivity()) {
|
||||
Utils.RunBackground("Auto Updater", async () => {
|
||||
@@ -190,12 +204,21 @@ namespace Elwig {
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private async void Application_Exit(object sender, ExitEventArgs evt) {
|
||||
public async Task OnClosing() {
|
||||
try {
|
||||
await BackupService.TryDatabaseBackup();
|
||||
} catch (Exception exc) {
|
||||
InteractionService.ShowException("Automatisches Backup", exc);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs evt) {
|
||||
SerialPortWatcher.Dispose();
|
||||
foreach (var s in EventScales) {
|
||||
s.Dispose();
|
||||
}
|
||||
await Pdf.Cleanup();
|
||||
Pdf.Cleanup();
|
||||
base.OnExit(evt);
|
||||
}
|
||||
|
||||
public static void SetBranch(Branch b) {
|
||||
|
||||
Reference in New Issue
Block a user