Catch exceptions on history updates
This commit is contained in:
parent
c705b4396f
commit
3579d779e8
@ -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<int, ShipcallControlModel> _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<History> allHistories = new();
|
||||
this.stackPanel.Children.Clear();
|
||||
|
||||
foreach (int shipcall_id in _shipcalls.Keys)
|
||||
|
||||
try
|
||||
{
|
||||
List<History> 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<History> 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)
|
||||
|
||||
@ -38,7 +38,7 @@ namespace BreCalClient
|
||||
|
||||
#region Fields
|
||||
|
||||
private static Int32 _uiUpdateRunning = 0;
|
||||
private static int _uiUpdateRunning = 0;
|
||||
|
||||
private Credentials? _credentials;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user