From e28a5c1560669757d06eff8da30a21da4fc55b30 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 6 Dec 2024 11:40:00 +0100 Subject: [PATCH] Throw sensible error if user without port assignment logs on --- src/BreCalClient/MainWindow.xaml.cs | 60 ++++++++++++------- .../Resources/Resources.Designer.cs | 9 +++ src/BreCalClient/Resources/Resources.de.resx | 3 + src/BreCalClient/Resources/Resources.resx | 3 + 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 04e4427..af1fe99 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -168,15 +168,25 @@ namespace BreCalClient { if (_loginResult.Id > 0) { - Mouse.OverrideCursor = Cursors.Wait; - this.busyIndicator.IsBusy = false; + Mouse.OverrideCursor = Cursors.Wait; this._userApi.Configuration.ApiKey["Authorization"] = _loginResult.Token; this._shipcallApi.Configuration.ApiKey["Authorization"] = _loginResult.Token; this._timesApi.Configuration.ApiKey["Authorization"] = _loginResult.Token; this._staticApi.Configuration.ApiKey["Authorization"] = _loginResult.Token; this._shipApi.Configuration.ApiKey["Authorization"] = _loginResult.Token; - this.LoadStaticLists(); - this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}"; + bool loadingSuccessful = await this.LoadStaticLists(); + if (loadingSuccessful) + { + this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}"; + this.busyIndicator.IsBusy = false; + } + else + { + Mouse.OverrideCursor = null; + textUsername.Text = ""; + textPassword.Password = ""; + textUsername.Focus(); + } } } labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}"; @@ -341,7 +351,7 @@ namespace BreCalClient { this.Dispatcher.Invoke(new Action(() => { - ShowErrorDialog(ex.Message, "Error saving user information"); + ShowErrorDialog(ex.Message, "Error saving user information"); })); } } @@ -387,7 +397,7 @@ namespace BreCalClient this.searchFilterControl.SetBerths(berths); this.SearchFilterControl_SearchFilterChanged(); - } + } private async void comboBoxSortOrder_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { @@ -428,16 +438,23 @@ namespace BreCalClient #region network operations - private async void LoadStaticLists() + private async Task LoadStaticLists() { - if (_loginResult == null) return; + if (_loginResult == null) return false; BreCalLists.InitializePorts(await _staticApi.GetPortsAsync()); BreCalLists.InitializeBerths(await _staticApi.BerthsGetAsync()); BreCalLists.InitializeShips(await _shipApi.ShipsGetAsync()); BreCalLists.InitializeParticipants(await _staticApi.ParticipantsGetAsync()); - this.searchFilterControl.SetBerths(BreCalLists.Berths); + if(BreCalLists.Participants.Count == 0) + { + MessageBox.Show(BreCalClient.Resources.Resources.textNoPortAssigned, BreCalClient.Resources.Resources.textError, MessageBoxButton.OK, MessageBoxImage.Error); + Mouse.OverrideCursor = Cursors.Wait; + return false; + } + + this.searchFilterControl.SetBerths(BreCalLists.Berths); foreach (Participant participant in BreCalLists.Participants) { @@ -472,8 +489,8 @@ namespace BreCalClient SearchFilterModel.filterMap[_loginResult.Id] = currentFilter; } this.searchFilterControl.SetFilterFromModel(currentFilter); - - if (currentFilter.Ports != null) + + if ((currentFilter.Ports != null) && (this.comboBoxPorts.ItemsSource != null)) { foreach (Port p in this.comboBoxPorts.ItemsSource) { @@ -485,13 +502,14 @@ namespace BreCalClient _ = Task.Run(() => RefreshShipcalls()); _ = Task.Run(() => RefreshShips()); + return true; } public async Task RefreshShips() { while (true) - { + { Thread.Sleep(SHIPS_UPDATE_INTERVAL_SECONDS * 1000); BreCalLists.InitializeShips(await _shipApi.ShipsGetAsync()); } @@ -706,7 +724,7 @@ namespace BreCalClient // first add everything this._visibleControlModels.AddRange(_allShipcallsDict.Values); - // now remove elements whose filter criteria are met + // now remove elements whose filter criteria are met if(sfm.Berths.Count > 0 ) { @@ -1122,24 +1140,24 @@ namespace BreCalClient if (msg.error_field != null) { caption = $"{caption}: {msg.error_field}"; - } - + } + if(msg.error_description != null) { - message = msg.error_description; - } + message = msg.error_description; + } } } catch (Exception) { } - } + } _log.ErrorFormat("{0} - {1}", caption, message); - + Dispatcher.Invoke(new Action(() => { MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error); })); - + } private void EnableControlsForParticipant() @@ -1157,6 +1175,6 @@ namespace BreCalClient } #endregion - + } } diff --git a/src/BreCalClient/Resources/Resources.Designer.cs b/src/BreCalClient/Resources/Resources.Designer.cs index 9749834..7a002ab 100644 --- a/src/BreCalClient/Resources/Resources.Designer.cs +++ b/src/BreCalClient/Resources/Resources.Designer.cs @@ -875,6 +875,15 @@ namespace BreCalClient.Resources { } } + /// + /// Looks up a localized string similar to No port assigned to this participant. + /// + public static string textNoPortAssigned { + get { + return ResourceManager.GetString("textNoPortAssigned", resourceCulture); + } + } + /// /// Looks up a localized string similar to Not rotated. /// diff --git a/src/BreCalClient/Resources/Resources.de.resx b/src/BreCalClient/Resources/Resources.de.resx index 3573053..c28930b 100644 --- a/src/BreCalClient/Resources/Resources.de.resx +++ b/src/BreCalClient/Resources/Resources.de.resx @@ -553,4 +553,7 @@ Wenn eine Ende-Zeit angegeben wird, muss auch eine Start-Zeit angegeben werden + + Es ist keine Hafenzuordnung vorhanden + \ No newline at end of file diff --git a/src/BreCalClient/Resources/Resources.resx b/src/BreCalClient/Resources/Resources.resx index 2681a29..0a0154d 100644 --- a/src/BreCalClient/Resources/Resources.resx +++ b/src/BreCalClient/Resources/Resources.resx @@ -601,4 +601,7 @@ If an end time is set, a start time is also required + + No port assigned to this participant + \ No newline at end of file