diff --git a/src/BreCalClient/HistoryDialog.xaml.cs b/src/BreCalClient/HistoryDialog.xaml.cs index ce6cb2b..27b31d2 100644 --- a/src/BreCalClient/HistoryDialog.xaml.cs +++ b/src/BreCalClient/HistoryDialog.xaml.cs @@ -4,6 +4,8 @@ using BreCalClient.misc.Api; using BreCalClient.misc.Model; +using log4net; +using log4net.Core; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -22,6 +24,7 @@ namespace BreCalClient private readonly ConcurrentDictionary _shipcalls; private readonly StaticApi _staticApi; + private readonly static ILog _log = LogManager.GetLogger(typeof(HistoryDialog)); #endregion @@ -68,45 +71,56 @@ namespace BreCalClient private async void RefreshHistory() { List allHistories = new(); - this.stackPanel.Children.Clear(); - - foreach (int shipcall_id in _shipcalls.Keys) + + try { - List shipcallHistory = await _staticApi.HistoryGetAsync(shipcall_id); - System.Diagnostics.Trace.WriteLine($"{shipcallHistory.Count} history elements loaded for shipcall {shipcall_id}"); - allHistories.AddRange( shipcallHistory ); - } - - // sort all entries - allHistories.Sort((x, y) => { return y.Timestamp.CompareTo(x.Timestamp); }); - - EnumToStringConverter enumToStringConverter = new(); - - // create controls for all entries - foreach (History history in allHistories) - { - if (FilterShipcall(history.ShipcallId)) continue; - string shipname = ""; - Ship? ship = this._shipcalls[history.ShipcallId].Ship; - if (ship != null) - shipname = ship.Name; - string etaetd = "", calltype = ""; - if (_shipcalls.ContainsKey(history.ShipcallId)) + foreach (int shipcall_id in _shipcalls.Keys) { - etaetd = _shipcalls[history.ShipcallId].GetETAETD(); - if (_shipcalls[history.ShipcallId].Shipcall != null) - { - ShipcallType? type = _shipcalls[history.ShipcallId].Shipcall?.Type; - if (type != null) calltype = (string) (enumToStringConverter.Convert(type ?? ShipcallType.Undefined, typeof(ShipcallType), new(), System.Globalization.CultureInfo.CurrentCulture) ?? ""); - } + List shipcallHistory = await _staticApi.HistoryGetAsync(shipcall_id); + System.Diagnostics.Trace.WriteLine($"{shipcallHistory.Count} history elements loaded for shipcall {shipcall_id}"); + allHistories.AddRange(shipcallHistory); } - HistoryControl hc = new(shipname, history, calltype, etaetd); - hc.HistorySelected += (x) => { HistoryItemSelected?.Invoke(x); }; // bubble event - this.stackPanel.Children.Add(hc); + this.stackPanel.Children.Clear(); + + // sort all entries + allHistories.Sort((x, y) => { return y.Timestamp.CompareTo(x.Timestamp); }); + + EnumToStringConverter enumToStringConverter = new(); + + // create controls for all entries + foreach (History history in allHistories) + { + if (FilterShipcall(history.ShipcallId)) continue; + string shipname = ""; + Ship? ship = this._shipcalls[history.ShipcallId].Ship; + if (ship != null) + shipname = ship.Name; + string etaetd = "", calltype = ""; + if (_shipcalls.ContainsKey(history.ShipcallId)) + { + etaetd = _shipcalls[history.ShipcallId].GetETAETD(); + if (_shipcalls[history.ShipcallId].Shipcall != null) + { + ShipcallType? type = _shipcalls[history.ShipcallId].Shipcall?.Type; + if (type != null) calltype = (string)(enumToStringConverter.Convert(type ?? ShipcallType.Undefined, typeof(ShipcallType), new(), System.Globalization.CultureInfo.CurrentCulture) ?? ""); + } + } + + HistoryControl hc = new(shipname, history, calltype, etaetd); + hc.HistorySelected += (x) => { HistoryItemSelected?.Invoke(x); }; // bubble event + this.stackPanel.Children.Add(hc); + } + + Mouse.OverrideCursor = null; + + } + catch (Exception e) + { + // Here we rather not show a dialog box since it may confuse the user + _log.Error(e.ToString()); } - Mouse.OverrideCursor = null; } bool FilterShipcall(int shipcallId) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 51c9f1b..e707445 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -38,7 +38,7 @@ namespace BreCalClient #region Fields - private static Int32 _uiUpdateRunning = 0; + private static int _uiUpdateRunning = 0; private Credentials? _credentials;