App: Do not use FileSystemWatcher any more
This commit is contained in:
@ -60,10 +60,9 @@ namespace Elwig {
|
||||
public static ClientParameters Client { get; set; }
|
||||
|
||||
public static Dispatcher MainDispatcher { get; private set; }
|
||||
private readonly FileSystemWatcher Watcher = new(Path.GetDirectoryName(Config.DatabaseFile) ?? "C:\\") {
|
||||
NotifyFilter = NotifyFilters.LastWrite,
|
||||
Filter = "*.sqlite3",
|
||||
};
|
||||
private DateTime LastChanged;
|
||||
private static DateTime CurrentLastWrite => File.GetLastWriteTime(Config.DatabaseFile);
|
||||
private readonly DispatcherTimer ContextTimer = new() { Interval = TimeSpan.FromSeconds(2) };
|
||||
|
||||
public App() : base() {
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
@ -73,11 +72,16 @@ namespace Elwig {
|
||||
Scales = [];
|
||||
CurrentApp = this;
|
||||
OverrideCulture();
|
||||
Watcher.Changed += new FileSystemEventHandler(OnChanged);
|
||||
Watcher.EnableRaisingEvents = true;
|
||||
|
||||
ContextTimer.Tick += (object? sender, EventArgs evt) => {
|
||||
if (CurrentLastWrite > LastChanged) {
|
||||
LastChanged = CurrentLastWrite;
|
||||
OnContextChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void OnChanged(object source, FileSystemEventArgs e) {
|
||||
private static void OnContextChanged() {
|
||||
MainDispatcher.BeginInvoke(async () => await HintContextChange());
|
||||
}
|
||||
|
||||
@ -112,6 +116,9 @@ namespace Elwig {
|
||||
return;
|
||||
}
|
||||
|
||||
LastChanged = CurrentLastWrite;
|
||||
ContextTimer.Start();
|
||||
|
||||
Dictionary<string, (string, string, int?, string?, string?, string?, string?, string?)> branches = [];
|
||||
using (var ctx = new AppDbContext()) {
|
||||
branches = ctx.Branches.ToDictionary(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));
|
||||
@ -193,6 +200,7 @@ namespace Elwig {
|
||||
}
|
||||
|
||||
public static async Task HintContextChange() {
|
||||
CurrentApp.LastChanged = CurrentLastWrite;
|
||||
foreach (Window w in CurrentApp.Windows) {
|
||||
if (w is not ContextWindow c) continue;
|
||||
await c.HintContextChange();
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Elwig.Helpers;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
|
Reference in New Issue
Block a user