From 6872df4278f25a0b3e6494550798c1b73d0c05a2 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 22 Sep 2023 15:31:48 +0200 Subject: [PATCH 01/12] Increased token timeout to 2 hours, introduced a background task to refresh token at about 70 min interval --- src/BreCalClient/MainWindow.xaml.cs | 37 +++++++++++++++++++++++++---- src/server/BreCal/impl/login.py | 2 +- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 61f6fe5..5bb87dd 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows; +using log4net; using static BreCalClient.Extensions; namespace BreCalClient @@ -23,12 +24,15 @@ namespace BreCalClient /// public partial class MainWindow : Window { + private ILog _log = LogManager.GetLogger(typeof(MainWindow)); private const int SHIPCALL_UPDATE_INTERVAL_SECONDS = 30; #region Fields - + private Timer _timer; + Credentials _credentials; + private readonly Dictionary _allShipcallsDict = new(); private readonly Dictionary _allShipCallsControlDict = new(); @@ -109,12 +113,11 @@ namespace BreCalClient return; } - Credentials credentials = new(username: textUsername.Text.Trim(), - password: textPassword.Password.Trim()); + _credentials = new(username: textUsername.Text.Trim(), password: textPassword.Password.Trim()); try { - _loginResult = await _api.LoginPostAsync(credentials); + _loginResult = await _api.LoginPostAsync(_credentials); if (_loginResult != null) { if (_loginResult.Id > 0) @@ -122,7 +125,8 @@ namespace BreCalClient this.busyIndicator.IsBusy = false; this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token; this.LoadStaticLists(); - this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}"; + this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}"; + _timer = new Timer(RefreshToken, null, 4000000, Timeout.Infinite); } } labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}"; @@ -139,6 +143,29 @@ namespace BreCalClient } } + private void RefreshToken(object? state) + { + try + { + _loginResult = _api.LoginPost(_credentials); + if (_loginResult != null) + { + if (_loginResult.Id > 0) + { + this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token; + } + } + else + { + _log.Error("Token refresh: Renewed login returned empty login result"); + } + } + catch (Exception ex) + { + _log.ErrorFormat("Error refreshing token: {0}", ex.Message); + } + } + private void buttonExit_Click(object sender, RoutedEventArgs e) { this.Close(); diff --git a/src/server/BreCal/impl/login.py b/src/server/BreCal/impl/login.py index cef9e4c..c8c7e8d 100644 --- a/src/server/BreCal/impl/login.py +++ b/src/server/BreCal/impl/login.py @@ -28,7 +28,7 @@ def GetUser(options): "user_name": data[0].user_name, "user_phone": data[0].user_phone } - token = jwt_handler.generate_jwt(payload=result, lifetime=60) # generate token valid 60 mins + token = jwt_handler.generate_jwt(payload=result, lifetime=120) # generate token valid 60 mins result["token"] = token # add token to user data return json.dumps(result), 200, {'Content-Type': 'application/json; charset=utf-8'} From 2f0ca85c19cabbce4f2715a715ac566637fd3a7f Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 22 Sep 2023 16:21:53 +0200 Subject: [PATCH 02/12] fixed saving of new shipcalls, reversed logic of cancelled ship filter --- src/BreCalClient/EditShipcallControl.xaml.cs | 4 +++- src/BreCalClient/MainWindow.xaml.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs index a823011..ed8b092 100644 --- a/src/BreCalClient/EditShipcallControl.xaml.cs +++ b/src/BreCalClient/EditShipcallControl.xaml.cs @@ -80,6 +80,7 @@ namespace BreCalClient this.comboBoxArrivalBerth.ItemsSource = this.Berths; this.comboBoxDepartureBerth.ItemsSource = this.Berths; + if (this.ShipcallModel.Shipcall == null) this.ShipcallModel.Shipcall = new(); this.CopyToControls(); this.EnableControls(); @@ -167,6 +168,7 @@ namespace BreCalClient this.ShipcallModel.Shipcall.Etd = this.datePickerETD.Value ?? DateTime.Now.AddDays(1); this.ShipcallModel.Shipcall.Anchored = this.checkBoxAnchored.IsChecked; this.ShipcallModel.Shipcall.ShipId = ((Ship)this.comboBoxShip.SelectedItem).Id; + this.ShipcallModel.Ship = (Ship)this.comboBoxShip.SelectedItem; this.ShipcallModel.Shipcall.ArrivalBerthId = (this.comboBoxArrivalBerth.SelectedItem != null) ? ((Berth)this.comboBoxArrivalBerth.SelectedItem).Id : null; this.ShipcallModel.Shipcall.DepartureBerthId = (this.comboBoxDepartureBerth.SelectedItem != null) ? ((Berth)this.comboBoxDepartureBerth.SelectedItem).Id : null; this.ShipcallModel.Shipcall.Bunkering = this.checkBoxBunkering.IsChecked; @@ -185,7 +187,7 @@ namespace BreCalClient { this.ShipcallModel.Shipcall.PierSide = (this.comboBoxPierside.SelectedIndex == 0) ? true : false; } - + // remove all and add selected participants this.ShipcallModel.Shipcall.Participants.Clear(); this.ShipcallModel.AssignedParticipants.Clear(); diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 5bb87dd..7c7b9a5 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -475,7 +475,7 @@ namespace BreCalClient if(!_showCanceled ?? true) // canceled calls are filtered by default { - this._visibleControlModels.RemoveAll(x => x.Shipcall?.Canceled ?? true); + this._visibleControlModels.RemoveAll(x => x.Shipcall?.Canceled ?? false); } if (this._sortOrder != null) From 31ddcbb33695ec7899f40a688661e595e9849410 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 22 Sep 2023 16:30:25 +0200 Subject: [PATCH 03/12] When applying the search filter use also the ships name in the free text input --- src/BreCalClient/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 7c7b9a5..edfbb34 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -450,7 +450,7 @@ namespace BreCalClient if(!string.IsNullOrEmpty(sfm.SearchString)) { - this._visibleControlModels.RemoveAll(x => !x.ContainsRemarkText(sfm.SearchString)); + this._visibleControlModels.RemoveAll(x => !(x.ContainsRemarkText(sfm.SearchString) || (x.Ship?.Name.Contains(sfm.SearchString, StringComparison.InvariantCultureIgnoreCase) ?? false))); } if(sfm.ShipLengthTo != null) From aca7908d4cf46c594ae4082dffb57c3410d87b2a Mon Sep 17 00:00:00 2001 From: puls200 Date: Mon, 25 Sep 2023 15:05:42 +0200 Subject: [PATCH 04/12] =?UTF-8?q?=C3=9Cberarbeitung=20Dialog=20Anlaufbearb?= =?UTF-8?q?eitung=20Pt.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditTimesAgencyIncomingControl.xaml | 54 ++++++++++++ .../EditTimesAgencyIncomingControl.xaml.cs | 81 ++++++++++++++++++ .../EditTimesAgencyOutgoingControl.xaml | 51 ++++++++++++ .../EditTimesAgencyOutgoingControl.xaml.cs | 82 ++++++++++++++++++ .../EditTimesAgencyShiftingControl.xaml | 52 ++++++++++++ .../EditTimesAgencyShiftingControl.xaml.cs | 83 +++++++++++++++++++ .../Resources/Resources.Designer.cs | 27 ++++++ src/BreCalClient/Resources/Resources.de.resx | 9 ++ src/BreCalClient/Resources/Resources.resx | 9 ++ 9 files changed, 448 insertions(+) create mode 100644 src/BreCalClient/EditTimesAgencyIncomingControl.xaml create mode 100644 src/BreCalClient/EditTimesAgencyIncomingControl.xaml.cs create mode 100644 src/BreCalClient/EditTimesAgencyOutgoingControl.xaml create mode 100644 src/BreCalClient/EditTimesAgencyOutgoingControl.xaml.cs create mode 100644 src/BreCalClient/EditTimesAgencyShiftingControl.xaml create mode 100644 src/BreCalClient/EditTimesAgencyShiftingControl.xaml.cs diff --git a/src/BreCalClient/EditTimesAgencyIncomingControl.xaml b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml new file mode 100644 index 0000000..999230c --- /dev/null +++ b/src/BreCalClient/EditTimesAgencyIncomingControl.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +