From 980349449b15f73ac31535cad063fff81e455273 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 15 Nov 2023 14:52:02 +0100 Subject: [PATCH] Removed exception message if everything is ok again --- src/BreCalClient/MainWindow.xaml.cs | 71 +++++++++++++++-------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index f9e31c6..e10a165 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -1,6 +1,6 @@ // Copyright (c) 2023 schick Informatik // Description: Bremen calling main window -// +// using System; using System.Collections.Generic; @@ -38,7 +38,7 @@ namespace BreCalClient private readonly ConcurrentDictionary _allShipcallsDict = new(); private readonly ConcurrentDictionary _allShipCallsControlDict = new(); - private readonly List _visibleControlModels = new(); + private readonly List _visibleControlModels = new(); private readonly DefaultApi _api; private CancellationTokenSource _tokenSource = new(); @@ -71,7 +71,7 @@ namespace BreCalClient { InitializeComponent(); _api = new DefaultApi(Properties.Settings.Default.API_URL); - _api.Configuration.ApiKeyPrefix["Authorization"] = "Bearer"; + _api.Configuration.ApiKeyPrefix["Authorization"] = "Bearer"; } #endregion @@ -84,14 +84,14 @@ namespace BreCalClient labelVersion.Text = "V. " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; if (!string.IsNullOrEmpty(Properties.Settings.Default.APP_TITLE)) this.Title = Properties.Settings.Default.APP_TITLE; - searchFilterControl.SearchFilterChanged += SearchFilterControl_SearchFilterChanged; + searchFilterControl.SearchFilterChanged += SearchFilterControl_SearchFilterChanged; searchFilterControl.LogoImageClicked += () => { - Process.Start("explorer", Properties.Settings.Default.LOGO_IMAGE_URL); + Process.Start("explorer", Properties.Settings.Default.LOGO_IMAGE_URL); }; this.comboBoxSortOrder.ItemsSource = Enum.GetValues(typeof(Extensions.SortOrder)); this.comboBoxSortOrder.SelectedIndex = (int)_sortOrder; - } + } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { @@ -147,9 +147,9 @@ namespace BreCalClient if (_loginResult != null) { if (_loginResult.Id > 0) - { - this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token; - } + { + this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token; + } } else { @@ -169,7 +169,7 @@ namespace BreCalClient private void buttonNew_Click(object sender, RoutedEventArgs e) { - EditShipcallControl esc = new(); + EditShipcallControl esc = new(); if (esc.ShowDialog() ?? false) { @@ -187,8 +187,8 @@ namespace BreCalClient _refreshImmediately = true; // set flag to avoid timer loop termination _tokenSource.Cancel(); // force timer loop end } - } - } + } + } private void buttonInfo_Click(object sender, RoutedEventArgs e) { @@ -251,7 +251,7 @@ namespace BreCalClient this.UpdateUI(); } - #endregion + #endregion #region network operations @@ -262,14 +262,14 @@ namespace BreCalClient BreCalLists.InitializeParticipants(await _api.ParticipantsGetAsync()); this.searchFilterControl.SetBerths(BreCalLists.Berths); - + foreach (Participant participant in BreCalLists.Participants) - { + { if (_loginResult?.ParticipantId == participant.Id) { App.Participant = participant; EnableControlsForParticipant(); - } + } } this.searchFilterControl.SetAgencies(BreCalLists.Participants_Agent); @@ -282,7 +282,7 @@ namespace BreCalClient } _ = Task.Run(() => RefreshShipcalls()); - } + } public async Task RefreshShipcalls() { @@ -307,10 +307,11 @@ namespace BreCalClient { labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}"; labelGeneralStatus.Text = $"Ok"; + labelStatusBar.Text = ""; })); } catch (Exception ex) - { + { this.Dispatcher.Invoke(new Action(() => { labelGeneralStatus.Text = $"Connection {ConnectionStatus.FAILED}"; @@ -337,7 +338,7 @@ namespace BreCalClient { Shipcall = shipcall, Times = currentTimes - }; + }; this.AddShipcall(scm); } else @@ -346,8 +347,8 @@ namespace BreCalClient _allShipcallsDict[shipcall.Id].Shipcall = shipcall; _allShipcallsDict[shipcall.Id].Times = currentTimes; UpdateShipcall(_allShipcallsDict[shipcall.Id]); - } - } + } + } List existingIds = new(this._allShipcallsDict.Keys); @@ -400,7 +401,7 @@ namespace BreCalClient ShipcallControl sc = new() { Height = 120, - ShipcallControlModel = scm + ShipcallControlModel = scm }; sc.EditTimesRequested += Sc_EditTimesRequested; sc.EditRequested += Sc_EditRequested; @@ -408,7 +409,7 @@ namespace BreCalClient sc.RefreshData(); this._allShipCallsControlDict[scm.Shipcall.Id] = sc; }); - } + } private static void UpdateShipcall(ShipcallControlModel scm) { @@ -440,7 +441,7 @@ namespace BreCalClient _visibleControlModels.Remove(removeModel); this._allShipCallsControlDict.Remove(shipcallId, out _); - this._allShipcallsDict.Remove(shipcallId, out _); + this._allShipcallsDict.Remove(shipcallId, out _); } private void FilterShipcalls() @@ -483,7 +484,7 @@ namespace BreCalClient return !sfm.Agencies.Contains(agency.Id); } return true; - }); + }); } if(sfm.Categories.Count > 0 ) @@ -520,18 +521,18 @@ namespace BreCalClient { _ = this._visibleControlModels.RemoveAll(x => x.Shipcall?.Canceled ?? false); } - + switch(this._sortOrder) { case Extensions.SortOrder.SHIP_NAME: - this._visibleControlModels.Sort((x, y) => { if (x.Ship == null) return 0; if (y.Ship == null) return 0; return x.Ship.Name.CompareTo(y.Ship.Name); }); + this._visibleControlModels.Sort((x, y) => { if (x.Ship == null) return 0; if (y.Ship == null) return 0; return x.Ship.Name.CompareTo(y.Ship.Name); }); break; case Extensions.SortOrder.MODIFIED: this._visibleControlModels.Sort((x, y) => { if (x.Shipcall == null) return 0; if (y.Shipcall == null) return 0; return DateTime.Compare(x.Shipcall.Modified ?? x.Shipcall.Created, y.Shipcall.Modified ?? x.Shipcall.Created); }); break; case Extensions.SortOrder.ETA_ETD: this._visibleControlModels.Sort((x, y) => - { + { if (x.Shipcall == null) return 0; if (y.Shipcall == null) return 0; DateTime xDate = (x.Shipcall.Type == (int) Extensions.TypeEnum.Incoming) ? x.Eta ?? DateTime.Now : x.Etd ?? DateTime.Now; @@ -541,7 +542,7 @@ namespace BreCalClient break; default: break; - } + } } @@ -586,7 +587,7 @@ namespace BreCalClient #region control event handler private async void Sc_EditRequested(ShipcallControl obj) - { + { if (obj.ShipcallControlModel != null) { EditShipcallControl esc = new() @@ -632,7 +633,7 @@ namespace BreCalClient if (times != null) { etc.Times = times; - wasEdit = true; + wasEdit = true; } else { @@ -698,7 +699,7 @@ namespace BreCalClient { editControl.Times = times; wasEdit = true; - } + } else { if(editControl.ShipcallModel.AssignedParticipants.ContainsKey(ParticipantType.AGENCY)) @@ -726,7 +727,7 @@ namespace BreCalClient await _api.TimesPutAsync(editControl.Times); } else - { + { if ((sc.ShipcallControlModel != null) && (sc.ShipcallControlModel.Shipcall != null)) { editControl.Times.ShipcallId = sc.ShipcallControlModel.Shipcall.Id; @@ -761,7 +762,7 @@ namespace BreCalClient Dispatcher.Invoke(new Action(() => { MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error); - })); + })); } private void EnableControlsForParticipant() @@ -771,6 +772,6 @@ namespace BreCalClient } #endregion - + } }