From 65779731fda904061f345625b52f1eb1602920e2 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 28 Aug 2024 17:04:04 +0200 Subject: [PATCH 1/3] Show the content of the message info from the failure exception --- src/BreCalClient/MainWindow.xaml.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 475c8ac..2e848b1 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -23,6 +23,8 @@ using Polly; using System.Net.Http; using System.Net; using System.Windows.Input; +using System.Text.RegularExpressions; +using Newtonsoft.Json.Linq; namespace BreCalClient @@ -1058,13 +1060,27 @@ namespace BreCalClient private void ShowErrorDialog(string message, string caption) { + // Example: + // Error calling ShipcallUpdate: {\"message\": \"PUT Requests for shipcalls can only be issued by an assigned AGENCY or BSMD users + // (if the special-flag is enabled). Assigned Agency: ShipcallParticipantMap(id=628, shipcall_id=115, participant_id=10, + // type=8, created=datetime.datetime(2024, 8, 28, 15, 13, 14), modified=None) with Flags: 42\"} + Match m = Regex.Match(message, "\\{(.*)\\}"); + if ((m != null) && (m.Success)) + { + dynamic? msg = JsonConvert.DeserializeObject(m.Value); + if(msg != null) + { + message = msg.message; + } + } + _log.ErrorFormat("{0} - {1}", caption, message); - /* + Dispatcher.Invoke(new Action(() => { MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Error); })); - */ + } private void EnableControlsForParticipant() From b154f73ce9ab2a44a5636f4bbbe3914cab23cced Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 28 Aug 2024 17:35:58 +0200 Subject: [PATCH 2/3] Convenience: If creating a new ship fails, the ship is shown again when the dialog is re-opened --- src/BreCalClient/MainWindow.xaml.cs | 2 +- src/BreCalClient/ShipListDialog.xaml.cs | 11 +++++++---- src/BreCalClient/ShipModel.cs | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 2e848b1..cf689e6 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -1065,7 +1065,7 @@ namespace BreCalClient // (if the special-flag is enabled). Assigned Agency: ShipcallParticipantMap(id=628, shipcall_id=115, participant_id=10, // type=8, created=datetime.datetime(2024, 8, 28, 15, 13, 14), modified=None) with Flags: 42\"} Match m = Regex.Match(message, "\\{(.*)\\}"); - if ((m != null) && (m.Success)) + if ((m != null) && m.Success) { dynamic? msg = JsonConvert.DeserializeObject(m.Value); if(msg != null) diff --git a/src/BreCalClient/ShipListDialog.xaml.cs b/src/BreCalClient/ShipListDialog.xaml.cs index df7d112..a4149e2 100644 --- a/src/BreCalClient/ShipListDialog.xaml.cs +++ b/src/BreCalClient/ShipListDialog.xaml.cs @@ -90,7 +90,9 @@ namespace BreCalClient private async void DataGridShips_CreateRequested() { - ShipModel shipModel = new(new Ship()); + + ShipModel shipModel = new((ShipModel.LastEditShip != null) ? ShipModel.LastEditShip : new Ship()); + EditShipDialog esd = new() { Ship = shipModel.Ship @@ -111,14 +113,15 @@ namespace BreCalClient if(!BreCalLists.ShipLookupDict.TryAdd(id.VarId, shipModel)) BreCalLists.ShipLookupDict[id.VarId] = shipModel; this.dataGridShips.ItemsSource = BreCalLists.AllShips; + ShipModel.LastEditShip = null; } } catch (Exception ex) { - MessageBox.Show(ex.Message); + ShipModel.LastEditShip = shipModel.Ship; + MessageBox.Show(ex.Message); } - } - + } } #endregion diff --git a/src/BreCalClient/ShipModel.cs b/src/BreCalClient/ShipModel.cs index 4f06e21..9f11673 100644 --- a/src/BreCalClient/ShipModel.cs +++ b/src/BreCalClient/ShipModel.cs @@ -16,6 +16,8 @@ namespace BreCalClient public Ship Ship { get; private set; } + public static Ship? LastEditShip { get; set; } + public string TugCompany { get { if(this.Ship.ParticipantId.HasValue) From 99052efd076a030b429fd7f9d7b67956b728a65c Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 28 Aug 2024 17:39:19 +0200 Subject: [PATCH 3/3] Fixed shipcall POST documentation for canceled field --- docs/ApiValidationRules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ApiValidationRules.md b/docs/ApiValidationRules.md index 40788b7..c080ae0 100644 --- a/docs/ApiValidationRules.md +++ b/docs/ApiValidationRules.md @@ -105,7 +105,7 @@ Usually the "Z" is missing at the end indicating local time. | tidal_window_from | value must be in the future | | tidal_window_to | value must be in the future, value must be > tidal_window_from | | recommended_tugs | 0 < value < 10 | - | canceled | may not be set on POST | + | canceled | optional on POST | | evaluation | may not be set | | evaluation_message | may not be set | | created / modified | may not be set |