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