From 3eccbaa8b869f1cac9af01f73d585a83bafd2b4e Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Tue, 13 Jul 2021 17:46:06 +0200 Subject: [PATCH] only create filter provider if download is complete --- EDDB/API.cs | 14 +++++++++++--- MainWindow.xaml.cs | 15 ++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/EDDB/API.cs b/EDDB/API.cs index 76b75ea..bddb66f 100644 --- a/EDDB/API.cs +++ b/EDDB/API.cs @@ -10,6 +10,10 @@ namespace NonaBGS.EDDB { private string systems_file = null; + public delegate void DatabaseAvailableDelegate(); + + public event DatabaseAvailableDelegate SystemsAvailable; + public string SystemsFile => systems_file; public string Cache { @@ -27,13 +31,15 @@ namespace NonaBGS.EDDB { client.DownloadDataCompleted += Client_DownloadDataCompleted; } - private void DownloadFile(string url, string file) { - client.DownloadFileAsync(new Uri(url), file); + private void DownloadFile(string url, string file, DatabaseAvailableDelegate notifier) { + client.DownloadFileAsync(new Uri(url), file, notifier); } public void Download(bool force) { if (!HaveSystemsFile || force) { - DownloadFile(EDDB_SYSTEMS_ARCHIVE, systems_file); + DownloadFile(EDDB_SYSTEMS_ARCHIVE, systems_file, SystemsAvailable); + } else if (HaveSystemsFile) { + SystemsAvailable?.Invoke(); } } @@ -54,6 +60,8 @@ namespace NonaBGS.EDDB { } private void Client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { + DatabaseAvailableDelegate notifier = e.UserState as DatabaseAvailableDelegate; + notifier?.Invoke(); } } } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 1d87232..d4bb90b 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -20,8 +20,6 @@ namespace NonaBGS { private Report report = new Report(); private Config config = new Config(); private API api = null; - private PopulatedSystems systems_db = null; - private SystemSuggestionProvider systems_provider = null; public Config Config => config; @@ -54,12 +52,19 @@ namespace NonaBGS { Log(e.Message); } + api.SystemsAvailable += Api_SystemsAvailable; + try { SyncDatabases(); + } catch (Exception e) { + Log(e.Message); + } + } - systems_db = api.MakePopulatedSystems(); - systems_provider = new SystemSuggestionProvider(systems_db); - system.Provider = systems_provider; + private void Api_SystemsAvailable() { + try { + var systems_db = api.MakePopulatedSystems(); + system.Provider = new SystemSuggestionProvider(systems_db); } catch (Exception e) { Log(e.Message); }