Catch exceptions on history updates

This commit is contained in:
Daniel Schick 2024-04-29 07:56:57 +02:00
parent c705b4396f
commit 3579d779e8
2 changed files with 48 additions and 34 deletions

View File

@ -4,6 +4,8 @@
using BreCalClient.misc.Api; using BreCalClient.misc.Api;
using BreCalClient.misc.Model; using BreCalClient.misc.Model;
using log4net;
using log4net.Core;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
@ -22,6 +24,7 @@ namespace BreCalClient
private readonly ConcurrentDictionary<int, ShipcallControlModel> _shipcalls; private readonly ConcurrentDictionary<int, ShipcallControlModel> _shipcalls;
private readonly StaticApi _staticApi; private readonly StaticApi _staticApi;
private readonly static ILog _log = LogManager.GetLogger(typeof(HistoryDialog));
#endregion #endregion
@ -68,15 +71,18 @@ namespace BreCalClient
private async void RefreshHistory() private async void RefreshHistory()
{ {
List<History> allHistories = new(); List<History> allHistories = new();
this.stackPanel.Children.Clear();
try
{
foreach (int shipcall_id in _shipcalls.Keys) foreach (int shipcall_id in _shipcalls.Keys)
{ {
List<History> shipcallHistory = await _staticApi.HistoryGetAsync(shipcall_id); List<History> shipcallHistory = await _staticApi.HistoryGetAsync(shipcall_id);
System.Diagnostics.Trace.WriteLine($"{shipcallHistory.Count} history elements loaded for shipcall {shipcall_id}"); System.Diagnostics.Trace.WriteLine($"{shipcallHistory.Count} history elements loaded for shipcall {shipcall_id}");
allHistories.AddRange( shipcallHistory ); allHistories.AddRange(shipcallHistory);
} }
this.stackPanel.Children.Clear();
// sort all entries // sort all entries
allHistories.Sort((x, y) => { return y.Timestamp.CompareTo(x.Timestamp); }); allHistories.Sort((x, y) => { return y.Timestamp.CompareTo(x.Timestamp); });
@ -97,7 +103,7 @@ namespace BreCalClient
if (_shipcalls[history.ShipcallId].Shipcall != null) if (_shipcalls[history.ShipcallId].Shipcall != null)
{ {
ShipcallType? type = _shipcalls[history.ShipcallId].Shipcall?.Type; ShipcallType? type = _shipcalls[history.ShipcallId].Shipcall?.Type;
if (type != null) calltype = (string) (enumToStringConverter.Convert(type ?? ShipcallType.Undefined, typeof(ShipcallType), new(), System.Globalization.CultureInfo.CurrentCulture) ?? ""); if (type != null) calltype = (string)(enumToStringConverter.Convert(type ?? ShipcallType.Undefined, typeof(ShipcallType), new(), System.Globalization.CultureInfo.CurrentCulture) ?? "");
} }
} }
@ -107,6 +113,14 @@ namespace BreCalClient
} }
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;
}
catch (Exception e)
{
// Here we rather not show a dialog box since it may confuse the user
_log.Error(e.ToString());
}
} }
bool FilterShipcall(int shipcallId) bool FilterShipcall(int shipcallId)

View File

@ -38,7 +38,7 @@ namespace BreCalClient
#region Fields #region Fields
private static Int32 _uiUpdateRunning = 0; private static int _uiUpdateRunning = 0;
private Credentials? _credentials; private Credentials? _credentials;