From 5f0712c7997da5d2b3234d401e3cc761765588f5 Mon Sep 17 00:00:00 2001 From: puls200 Date: Wed, 18 Oct 2023 18:48:47 +0200 Subject: [PATCH] Added some styles for evaluation result and tried to solve sync problems --- src/BreCalClient/BreCalClient.csproj | 6 + src/BreCalClient/MainWindow.xaml.cs | 37 +- .../Resources/Resources.Designer.cs | 30 ++ src/BreCalClient/Resources/Resources.resx | 9 + src/BreCalClient/Resources/check.png | Bin 0 -> 1076 bytes src/BreCalClient/Resources/delete2.png | Bin 0 -> 1787 bytes src/BreCalClient/Resources/sign_warning.png | Bin 0 -> 1305 bytes src/BreCalClient/ShipcallControl.xaml | 59 ++- src/BreCalClient/ShipcallControl.xaml.cs | 383 ++++++++++-------- src/BreCalClient/ShipcallControlModel.cs | 21 +- 10 files changed, 312 insertions(+), 233 deletions(-) create mode 100644 src/BreCalClient/Resources/check.png create mode 100644 src/BreCalClient/Resources/delete2.png create mode 100644 src/BreCalClient/Resources/sign_warning.png diff --git a/src/BreCalClient/BreCalClient.csproj b/src/BreCalClient/BreCalClient.csproj index 09f93b2..466eb14 100644 --- a/src/BreCalClient/BreCalClient.csproj +++ b/src/BreCalClient/BreCalClient.csproj @@ -24,14 +24,17 @@ + + + @@ -72,14 +75,17 @@ + + + MSBuild:Compile diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 97415e5..49aae06 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -16,7 +16,7 @@ using BreCalClient.misc.Client; using BreCalClient.misc.Model; using static BreCalClient.Extensions; -using System.Runtime.Serialization; +using System.Collections.Concurrent; namespace BreCalClient { @@ -31,11 +31,13 @@ namespace BreCalClient #region Fields + private static Int32 _uiUpdateRunning = 0; + private Timer? _timer; private Credentials? _credentials; - private readonly Dictionary _allShipcallsDict = new(); - private readonly Dictionary _allShipCallsControlDict = new(); + private readonly ConcurrentDictionary _allShipcallsDict = new(); + private readonly ConcurrentDictionary _allShipCallsControlDict = new(); private readonly List _visibleControlModels = new(); private readonly DefaultApi _api; @@ -412,8 +414,8 @@ namespace BreCalClient ShipcallControlModel removeModel = this._allShipcallsDict[shipcallId]; _visibleControlModels.Remove(removeModel); - this._allShipCallsControlDict.Remove(shipcallId); - this._allShipcallsDict.Remove(shipcallId); + this._allShipCallsControlDict.Remove(shipcallId, out _); + this._allShipcallsDict.Remove(shipcallId, out _); } private void FilterShipcalls() @@ -514,16 +516,29 @@ namespace BreCalClient this.Dispatcher.Invoke(new Action(() => { - this.stackPanel.Children.Clear(); - foreach(ShipcallControlModel visibleModel in this._visibleControlModels) + if (Interlocked.CompareExchange(ref _uiUpdateRunning, 1, 0) == 1) return; + + try { - if (visibleModel.Shipcall == null) continue; // should not happen - if(this._allShipCallsControlDict.ContainsKey(visibleModel.Shipcall.Id)) + this.stackPanel.Children.Clear(); + foreach (ShipcallControlModel visibleModel in this._visibleControlModels) { - this._allShipCallsControlDict[visibleModel.Shipcall.Id].RefreshData(); - this.stackPanel.Children.Add(this._allShipCallsControlDict[visibleModel.Shipcall.Id]); + if (visibleModel.Shipcall == null) continue; // should not happen + if (this._allShipCallsControlDict.ContainsKey(visibleModel.Shipcall.Id)) + { + this._allShipCallsControlDict[visibleModel.Shipcall.Id].RefreshData(); + this.stackPanel.Children.Add(this._allShipCallsControlDict[visibleModel.Shipcall.Id]); + } } } + catch(Exception e) { + _log.ErrorFormat("Exception running ui update: {0}", e.ToString()); + } + finally + { + _uiUpdateRunning = 0; + } + })); } diff --git a/src/BreCalClient/Resources/Resources.Designer.cs b/src/BreCalClient/Resources/Resources.Designer.cs index 5c8f167..66aadc9 100644 --- a/src/BreCalClient/Resources/Resources.Designer.cs +++ b/src/BreCalClient/Resources/Resources.Designer.cs @@ -110,6 +110,16 @@ namespace BreCalClient.Resources { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] check { + get { + object obj = ResourceManager.GetObject("check", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -160,6 +170,16 @@ namespace BreCalClient.Resources { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] delete2 { + get { + object obj = ResourceManager.GetObject("delete2", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -190,6 +210,16 @@ namespace BreCalClient.Resources { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] sign_warning { + get { + object obj = ResourceManager.GetObject("sign_warning", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized string similar to Agencies. /// diff --git a/src/BreCalClient/Resources/Resources.resx b/src/BreCalClient/Resources/Resources.resx index 78c37b9..1bad839 100644 --- a/src/BreCalClient/Resources/Resources.resx +++ b/src/BreCalClient/Resources/Resources.resx @@ -133,6 +133,9 @@ arrow_up_red.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + check.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + clipboard.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -148,6 +151,9 @@ delete.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + delete2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + emergency_stop_button.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -157,6 +163,9 @@ ship2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + sign_warning.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Agencies diff --git a/src/BreCalClient/Resources/check.png b/src/BreCalClient/Resources/check.png new file mode 100644 index 0000000000000000000000000000000000000000..5d739b138db080171a8532684d6c2299143c9bb0 GIT binary patch literal 1076 zcmV-41k3x0P)r#DIq9UTKUE*o%4S=y$fWo5&PxP-;qvKUP? zewZ3H)8O<2NG~e`ak|+UV`ki(aq*IckD8d6EHUvKhnd*F2fi6tRN#ZY$@}5`@cy3X zeV*t4JTLLTS!y$(*YMO;t%dqd%a`ohTzVa$R-4F=y(2v2Q_bKcdXcr!-J1iq611k4 zEZ7g-gGc6uF+AOa_ET0E>Q%RNA{E{!{thiqO_}BGczE^*k_tTdx)=M-SkOLUhTg7P z+z?%BrJlUIjl)ATNsQ$BaB#8-9k21&pS7WGs1lsOytRI~jXGrTsEWtZF{E-qL^I9k zp0uDRFF?3|D_AS@5n&`s*99-Pl0L0%%WugE8Kc<&#Ih~u&4}omx50IyT7lEobyk8~ z7hEL}RciB=8}d^DJa{&Wc%~I{-htrT5}KdCSAkRC>a9fes*9|J7PVG#N+XtZ+?HNL zFdB2oCyk>##`A+1Ot+)|tP7!n9i3?lIFb29CsE>RcrCF*Z6R-n$tti;YKgUx_pQa( zS?HH*WFy9B;)qZ0MJVTie8G;;drnk(OaIVH^nulv1cEKEqZYhlCOkg(0OV)=FnE}v zPNYx%#R-WD-_=-J9Lt3r)?)h96KLIY&L-Yc?TkwJqWy11D2;3 z2s5F+ZQfXs>gVjt;_l~62*2Y+aL$RYDJ%A#sYClKwb&LYg(+Bx1GA`hqj4Y3|{eK;Gz@qydAwW5<+t>MBnuxqQDPd-v!6G zQf(sh#=jPk#z{I@8}ohVB#*>3--@>f3$B$Nz2rgSOFz1E0(3n6mA-+{u1l#EZqlW9 z&_DOiib#IZgqZT0*kvycf9A)KayI(PmN+-*+fbJ@xR`*!t-2Y0-;JXS0VEaAQ(y0a z^~l!c#6Ghrb42f^Wn*L6QsP=8M!#u8*R%jmX=21qg4wi5$T^u*^*(Jet{72_{k|N& zO&{hJ4%JD6>&{zB$R7Jo{x<#u3c!PYC+%L<0000hbVXQnLvL_-a%pF1bO1wdaCvfR uXJ~XFsUR{iFgPtTFflP8NlrsgQd1yDZDL3ejv-F~0000kXp- literal 0 HcmV?d00001 diff --git a/src/BreCalClient/Resources/delete2.png b/src/BreCalClient/Resources/delete2.png new file mode 100644 index 0000000000000000000000000000000000000000..d31437aea0c5133de5cc27caab2fbdf8b4f606ce GIT binary patch literal 1787 zcmVJ^tjaI6N zO92}^s0KL}3{YqlL9~>%6ncqm>2}$B-@e0n5BL!!EzWx1XzWL^xndR{>pS}C` z<>?V+0bo2WOH#hW;YbDp1pPs8C>*ZWb;E6omkzF4vb6qTKA3-c`H{;tG!~9-PfJam zm6n#uhC(59wzZ9Y9DHxQN1}QEMS~QA#Jw52`?L`MYOL@alIQ>~P-e?LN4Aw6zF8bi1 z0m@yKo8ldgZ8p1&xq8rrr}FZUn4AnFx9G+V#nyv+EYmZ?Xb}{LyXW z#*K-;w!Z>}L_Nk! zN;p@nk}qGrx}A>CX112?AC!OQxH-_d88D^YuBQ6+#NQiB8x%1pP^mKF}bL?1)60;@=PN!9mNFV@%fYfZ< zh;Vf^`jd=#x~H4gdgzP)Tj(eJ(y8JPCs(AA%^1Kz2WsDM$Q@XZXb}1oEO?sHOA7 zgkjQ0X8JU#WPN>}UNO!rrVhsJQbNJfVU7;uyt^F{LTPrR5(?n*>SbuF{tA#JXcQ=G z(`J$@N!A2NRM`^~z>~6~;V|U%bof1eE6Rpv}no>M`5b3%?&jQl>rJ=8)4598W8WmxrFJB2hDG@?a(*3~` z@I!q3aWq|TFze=K*(iIY;n!=bH2oR)%?eVAjtLX2ImA#=72iE*CyzrQS~zMr)+Qn| zH5Ipaylv4ErE{4jYv~@W0o$vY(ajY7cpRmFH_}z^#7C(tImT zQge{mGBVJ0$b|%|5ljKG%zYzz`jOb0KP&@Jg_S2yp~8z$@AiOMu@aZAT!GK)IeM_H zwAs>~!ZVxCpE>RGjLwH=`~=9}d#GJlgi~|p!1%EaG<|4_>d=&!WjbZXQ*%kTThMm$ z1iHv!j26<}QKJzkEX3LGP6oj-oBlSgUzj_$h*qF$?S>7Et^7k|G+zf#O5p4^(jqw| zWx=FK6wE+^$Ium~Na^0BwH)D+j7CypI^=b4=}&y(i5x8$d{;M&IR#E9_t=yv7&&4j_}KlOpb}L#8XIxx`~_UQ`V)01 z^QFkfy;fU$w)ubks`%?uP*9K?)Ab_S!%x#j%cs?uZUs=)yBy2b^Bm_kY_`hlSFSWZ z%*P+Y&lRcIs73Su001j=MObu0Z*X~XX=iA307GwZd2(rIXmlW{ATls8I4v?TF)<)X dPD4*pQy@oeVn`5Agnl$AlmF!8N zY#X27CE0tKhB0G^1k_Hzci+I)H!5b0t{*ne4G+P~ULz0=5sXH`^y2vA)Yq1d+_JWO z@qGca=HLcx-Wt<5mt;=|wi`vH1EGVw*kH2R9!AySEL|-{_6Y%jW$fFytYeuq)dqPI;D8Pdk=BhV5j*I|bl{v z0MyI#i-uQ~MHW{L9f{6#;tyA#^w)qtSBwpg&7m(YaQ4hkT)5EA{)4B$a{fGpSRj44 z@fR^BOZCuhsw=J8%jU$#sBl19rav{`PWJqOC<`~x1-cKEokNrjS(`_jst89)v8*W5 zCJzVg+|2uP5eqjw9_0+c)0*kcSrzd4x621DgVIY^ziW40`y4w^j-!rXj1QxHU~Irb zl!Z?eVwD4aJbe*k9E`C*98ea@IG`L-eF=2W9$eRE_d7vtX@iK}A0bWh`X_Yv{RpB^ z0w_TQL~^$!=4KShy(Te;2ndK6LAWUP9U#jM9J>rxSAD;#9gBW z5rftSg8>a<4B8mDIiJe|x5ownv>3z~dXt&V#YFa_j&x$lfBqx+1B&mj$a5wNKmY&$ zD|AIzbVF}&d2(rIXmkKWZ*X~XX=iA3AgLfSFfceRGB7bQAW2R`Pf}ALM{QzA5RM^F P00000NkvXXu0mjf_JUkx literal 0 HcmV?d00001 diff --git a/src/BreCalClient/ShipcallControl.xaml b/src/BreCalClient/ShipcallControl.xaml index d034112..a81e73a 100644 --- a/src/BreCalClient/ShipcallControl.xaml +++ b/src/BreCalClient/ShipcallControl.xaml @@ -2,18 +2,16 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:BreCalClient" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:p = "clr-namespace:BreCalClient.Resources" xmlns:sets="clr-namespace:BreCalClient.Properties" - xmlns:db="clr-namespace:BreCalClient;assembly=BreCalClient" - xmlns:db2="clr-namespace:BreCalClient.misc.Model;assembly=BreCalClient" + xmlns:db="clr-namespace:BreCalClient;assembly=BreCalTestClient" mc:Ignorable="d" d:DesignHeight="120" d:DesignWidth="800" Loaded="UserControl_Loaded"> - + @@ -40,14 +38,35 @@ - + + @@ -211,34 +230,6 @@ - - diff --git a/src/BreCalClient/ShipcallControl.xaml.cs b/src/BreCalClient/ShipcallControl.xaml.cs index 00b541c..b0865bd 100644 --- a/src/BreCalClient/ShipcallControl.xaml.cs +++ b/src/BreCalClient/ShipcallControl.xaml.cs @@ -3,13 +3,13 @@ // using BreCalClient.misc.Model; +using log4net; using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; - namespace BreCalClient { /// @@ -25,6 +25,7 @@ namespace BreCalClient Participant? _terminal; Participant? _tug; Participant? _port_administration; + private static readonly ILog _log = LogManager.GetLogger(typeof(ShipcallControl)); #endregion @@ -60,208 +61,242 @@ namespace BreCalClient public void RefreshData() { - if (this.ShipcallControlModel != null) + try { - string agentName = ""; - string? name; - _agency = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.AGENCY); - name = _agency?.Name; - if (name != null) agentName = name; - this.labelAgent.Content = name ?? "- / -"; - - _mooring = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.MOORING); - name = _mooring?.Name; - this.labelMooring.Content = name ?? "- / -"; - - _pilot = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PILOT); - name = _pilot?.Name; - this.labelPilot.Content = name ?? "- / - "; - - _tug = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TUG); - name = _tug?.Name; - this.labelTug.Content = name ?? "- / - "; - - _port_administration = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PORT_ADMINISTRATION); - name = _port_administration?.Name; - this.labelPortAuthority.Content = name ?? "- / - "; - - _terminal = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TERMINAL); - name = _terminal?.Name; - this.labelTerminal.Content = name ?? "- / - "; - - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == _terminal?.Id)) + if (this.ShipcallControlModel != null) { - this.labelTerminal.FontWeight = FontWeights.Bold; - this.labelTerminal.Foreground = Brushes.LightYellow; - } + string agentName = ""; + string? name; + _agency = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.AGENCY); + name = _agency?.Name; + if (name != null) agentName = name; + this.labelAgent.Content = name ?? "- / -"; - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == _pilot?.Id)) - { - this.labelPilot.FontWeight = FontWeights.Bold; - this.labelPilot.Foreground = Brushes.LightYellow; - } + _mooring = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.MOORING); + name = _mooring?.Name; + this.labelMooring.Content = name ?? "- / -"; - if ((App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == _agency?.Id)) || - (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) && (_agency != null) && _agency.IsFlagSet(Extensions.ParticipantFlag.ALLOW_BSMD))) - { - this.labelAgent.FontWeight = FontWeights.Bold; - this.labelAgent.Foreground = Brushes.LightYellow; - } + _pilot = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PILOT); + name = _pilot?.Name; + this.labelPilot.Content = name ?? "- / - "; - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == _mooring?.Id)) - { - this.labelMooring.FontWeight = FontWeights.Bold; - this.labelMooring.Foreground = Brushes.LightYellow; - } + _tug = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TUG); + name = _tug?.Name; + this.labelTug.Content = name ?? "- / - "; - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == _port_administration?.Id)) - { - this.labelPortAuthority.FontWeight = FontWeights.Bold; - this.labelPortAuthority.Foreground = Brushes.LightYellow; - } + _port_administration = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.PORT_ADMINISTRATION); + name = _port_administration?.Name; + this.labelPortAuthority.Content = name ?? "- / - "; - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == _tug?.Id)) - { - this.labelTug.FontWeight = FontWeights.Bold; - this.labelTug.Foreground = Brushes.LightYellow; - } + _terminal = this.ShipcallControlModel.GetParticipantForType(Extensions.ParticipantType.TERMINAL); + name = _terminal?.Name; + this.labelTerminal.Content = name ?? "- / - "; - if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD)) - { - this.labelShipName.FontWeight = FontWeights.Bold; - this.labelShipName.Foreground = Brushes.LightYellow; - } - - this.labelShipName.Content = this.ShipcallControlModel?.Ship?.Name; - switch (this.ShipcallControlModel?.Shipcall?.Type) - { - case 1: // incoming - this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_down_red.png")); - break; - case 2: // outgoing - this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_up_blue.png")); - break; - case 3: // shifting - this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_right_green.png")); - break; - default: - break; - } - - this.textBlockBerth.Text = this.ShipcallControlModel?.Berth; - this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign; - if ((this.ShipcallControlModel?.Shipcall?.Type == 1) || (this.ShipcallControlModel?.Shipcall?.Type == 3)) - { - this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta?.ToString("dd.MM. HH:mm"); - } - if (this.ShipcallControlModel?.Shipcall?.Type == 2) - { - this.labelETA.Text = "ETD"; - this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Etd?.ToString("dd.MM. HH:mm"); - } - - this.textBlockIMO.Text = this.ShipcallControlModel?.Ship?.Imo.ToString(); - this.textBlockLengthWidth.Text = $"{this.ShipcallControlModel?.Ship?.Length} / {this.ShipcallControlModel?.Ship?.Width}"; - - // rename labels if this is not an incoming - // must be here because there may not be a times record for each participant (yet) - - if (this.ShipcallControlModel?.Shipcall?.Type != 1) - { - this.labelETAETDAgent.Content = "ETD"; - this.labelETAETDMooring.Content = "ETD"; - this.labelETAETDPilot.Content = "ETD"; - this.labelETAETDPortAuthority.Content = "ETD"; - this.labelETAETDTug.Content = "ETD"; - this.labelETAETDTerminal.Content = BreCalClient.Resources.Resources.textOperationsEnd; - } - - foreach (Times times in this.ShipcallControlModel.Times) - { - string? berthText = null; - if ((BreCalLists.Berths != null) && times.BerthId.HasValue) + if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TERMINAL) && (App.Participant.Id == _terminal?.Id)) { - Berth? berth = BreCalLists.Berths.Find((x) => x.Id == times.BerthId); - berthText = berth?.Name; + this.labelTerminal.FontWeight = FontWeights.Bold; + this.labelTerminal.Foreground = Brushes.LightYellow; } - if (berthText == null) + + if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PILOT) && (App.Participant.Id == _pilot?.Id)) { - if (this.ShipcallControlModel?.Shipcall?.Type == (int)Extensions.TypeEnum.Outgoing) - { - Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel.Shipcall?.DepartureBerthId); - berthText = berth?.Name; - } - else - { - Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel?.Shipcall?.ArrivalBerthId); - berthText = berth?.Name; - } + this.labelPilot.FontWeight = FontWeights.Bold; + this.labelPilot.Foreground = Brushes.LightYellow; } - if (times.ParticipantType == (int)Extensions.ParticipantType.AGENCY) + if ((App.Participant.IsTypeFlagSet(Extensions.ParticipantType.AGENCY) && (App.Participant.Id == _agency?.Id)) || + (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD) && (_agency != null) && _agency.IsFlagSet(Extensions.ParticipantFlag.ALLOW_BSMD))) { - this.labelAgencyBerth.Content = berthText; - this.labelAgencyETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockAgencyRemarks.Text = times.Remarks; - this.textBlockAgencyBerthRemarks.Text = times.BerthInfo; - if (this.ShipcallControlModel?.Shipcall?.Type != 1) - { - this.labelAgencyETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - } + this.labelAgent.FontWeight = FontWeights.Bold; + this.labelAgent.Foreground = Brushes.LightYellow; } - if (times.ParticipantType == (int)Extensions.ParticipantType.MOORING) + if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.MOORING) && (App.Participant.Id == _mooring?.Id)) { - this.labelMooringETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockMooringRemarks.Text = times.Remarks; - if (this.ShipcallControlModel?.Shipcall?.Type != 1) - { - this.labelMooringETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.labelMooring.FontWeight = FontWeights.Bold; + this.labelMooring.Foreground = Brushes.LightYellow; + } + + if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.PORT_ADMINISTRATION) && (App.Participant.Id == _port_administration?.Id)) + { + this.labelPortAuthority.FontWeight = FontWeights.Bold; + this.labelPortAuthority.Foreground = Brushes.LightYellow; + } + + if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.TUG) && (App.Participant.Id == _tug?.Id)) + { + this.labelTug.FontWeight = FontWeights.Bold; + this.labelTug.Foreground = Brushes.LightYellow; + } + + if (App.Participant.IsTypeFlagSet(Extensions.ParticipantType.BSMD)) + { + this.labelShipName.FontWeight = FontWeights.Bold; + this.labelShipName.Foreground = Brushes.LightYellow; + } + + this.labelShipName.Content = this.ShipcallControlModel?.Ship?.Name; + switch (this.ShipcallControlModel?.Shipcall?.Type) + { + case 1: // incoming + this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_down_red.png")); + break; + case 2: // outgoing + this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_up_blue.png")); + break; + case 3: // shifting + this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_right_green.png")); + break; + default: + break; + } + + if (this.ShipcallControlModel?.Shipcall?.Evaluation != null) + { + ShipcallControlModel.TrafficLightMode resultColor = (ShipcallControlModel.TrafficLightMode) (this.ShipcallControlModel?.Shipcall?.Evaluation ?? 0); // der nullable Operator hier ist so doof, die VS validation blickts einfach nicht + switch (resultColor) + { + case ShipcallControlModel.TrafficLightMode.GREEN: + this.Background = Brushes.LightGreen; + break; + case ShipcallControlModel.TrafficLightMode.YELLOW: + this.Background= Brushes.LightYellow; + break; + case ShipcallControlModel.TrafficLightMode.RED: + this.Background = new SolidColorBrush(Color.FromArgb(200, 255, 100, 100)); + break; + default: + this.Background = Brushes.Transparent; + break; } } - if (times.ParticipantType == (int)Extensions.ParticipantType.PORT_ADMINISTRATION) - { - this.labelPortAuthorityETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockPortAuthorityRemarks.Text = times.Remarks; - if (this.ShipcallControlModel?.Shipcall?.Type != 1) - { - this.labelPortAuthorityETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - } + if (!string.IsNullOrEmpty(this.ShipcallControlModel?.Shipcall?.EvaluationMessage)) + this.imageEvaluation.ToolTip = this.ShipcallControlModel?.Shipcall?.EvaluationMessage; + + this.textBlockBerth.Text = this.ShipcallControlModel?.Berth; + this.textBlockCallsign.Text = this.ShipcallControlModel?.Ship?.Callsign; + if ((this.ShipcallControlModel?.Shipcall?.Type == 1) || (this.ShipcallControlModel?.Shipcall?.Type == 3)) + { + this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Eta?.ToString("dd.MM. HH:mm"); + } + if (this.ShipcallControlModel?.Shipcall?.Type == 2) + { + this.labelETA.Text = "ETD"; + this.textBlockETA.Text = this.ShipcallControlModel?.Shipcall?.Etd?.ToString("dd.MM. HH:mm"); } - if (times.ParticipantType == (int)Extensions.ParticipantType.PILOT) - { - this.labelPilotETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockPilotRemarks.Text = times.Remarks; - if (this.ShipcallControlModel?.Shipcall?.Type != 1) - { - this.labelPilotETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - } + this.textBlockIMO.Text = this.ShipcallControlModel?.Ship?.Imo.ToString(); + this.textBlockLengthWidth.Text = $"{this.ShipcallControlModel?.Ship?.Length} / {this.ShipcallControlModel?.Ship?.Width}"; + + // rename labels if this is not an incoming + // must be here because there may not be a times record for each participant (yet) + + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelETAETDAgent.Content = "ETD"; + this.labelETAETDMooring.Content = "ETD"; + this.labelETAETDPilot.Content = "ETD"; + this.labelETAETDPortAuthority.Content = "ETD"; + this.labelETAETDTug.Content = "ETD"; + this.labelETAETDTerminal.Content = BreCalClient.Resources.Resources.textOperationsEnd; } - if (times.ParticipantType == (int)Extensions.ParticipantType.TUG) - { - this.labelTugETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockTugRemarks.Text = times.Remarks; - if (this.ShipcallControlModel?.Shipcall?.Type != 1) + if (this.ShipcallControlModel != null) + { + foreach (Times times in this.ShipcallControlModel.Times) { - this.labelTugETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - } - } + string? berthText = null; + if ((BreCalLists.Berths != null) && times.BerthId.HasValue) + { + Berth? berth = BreCalLists.Berths.Find((x) => x.Id == times.BerthId); + berthText = berth?.Name; + } + if (berthText == null) + { + if (this.ShipcallControlModel?.Shipcall?.Type == (int)Extensions.TypeEnum.Outgoing) + { + Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel.Shipcall?.DepartureBerthId); + berthText = berth?.Name; + } + else + { + Berth? berth = BreCalLists.Berths?.Find((x) => x.Id == this.ShipcallControlModel?.Shipcall?.ArrivalBerthId); + berthText = berth?.Name; + } + } - if (times.ParticipantType == (int)Extensions.ParticipantType.TERMINAL) - { - this.labelOperationsStart.Content = times.OperationsStart.HasValue ? times.OperationsStart.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; - this.textBlockTerminalRemarks.Text = times.Remarks; - if (this.ShipcallControlModel?.Shipcall?.Type != 1) - { - this.labelOperationsStart.Content = times.OperationsEnd.HasValue ? times.OperationsEnd.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + if (times.ParticipantType == (int)Extensions.ParticipantType.AGENCY) + { + this.labelAgencyBerth.Content = berthText; + this.labelAgencyETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockAgencyRemarks.Text = times.Remarks; + this.textBlockAgencyBerthRemarks.Text = times.BerthInfo; + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelAgencyETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + } + } + + if (times.ParticipantType == (int)Extensions.ParticipantType.MOORING) + { + this.labelMooringETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockMooringRemarks.Text = times.Remarks; + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelMooringETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + } + } + + if (times.ParticipantType == (int)Extensions.ParticipantType.PORT_ADMINISTRATION) + { + this.labelPortAuthorityETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockPortAuthorityRemarks.Text = times.Remarks; + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelPortAuthorityETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + } + } + + if (times.ParticipantType == (int)Extensions.ParticipantType.PILOT) + { + this.labelPilotETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockPilotRemarks.Text = times.Remarks; + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelPilotETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + } + } + + if (times.ParticipantType == (int)Extensions.ParticipantType.TUG) + { + this.labelTugETAETDValue.Content = times.EtaBerth.HasValue ? times.EtaBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockTugRemarks.Text = times.Remarks; + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelTugETAETDValue.Content = times.EtdBerth.HasValue ? times.EtdBerth.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + } + } + + if (times.ParticipantType == (int)Extensions.ParticipantType.TERMINAL) + { + this.labelOperationsStart.Content = times.OperationsStart.HasValue ? times.OperationsStart.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + this.textBlockTerminalRemarks.Text = times.Remarks; + if (this.ShipcallControlModel?.Shipcall?.Type != 1) + { + this.labelOperationsStart.Content = times.OperationsEnd.HasValue ? times.OperationsEnd.Value.ToString("dd.MM.yyyy HH:mm") : "- / -"; + } + this.textBlockTerminalBerthRemarks.Text = times.BerthInfo; + } } - this.textBlockTerminalBerthRemarks.Text = times.BerthInfo; } + this.DataContext = this.ShipcallControlModel; } - } + } + catch (Exception ex) + { + _log.ErrorFormat("Something went wrong during data refresh: {0}", ex.ToString()); + } } #endregion diff --git a/src/BreCalClient/ShipcallControlModel.cs b/src/BreCalClient/ShipcallControlModel.cs index f3148d0..5685733 100644 --- a/src/BreCalClient/ShipcallControlModel.cs +++ b/src/BreCalClient/ShipcallControlModel.cs @@ -55,24 +55,17 @@ namespace BreCalClient { get { - if (IsFlagSet(StatusFlags.RED)) + TrafficLightMode tlm = TrafficLightMode.OFF; + + if (this.Shipcall != null) { - if (IsFlagSet((StatusFlags)StatusFlags.YELLOW)) + if(this.Shipcall.Evaluation.HasValue) { - if (IsFlagSet(StatusFlags.GREEN)) - { - return TrafficLightMode.ALL; - } - return TrafficLightMode.RED_YELLOW; + tlm = (TrafficLightMode)this.Shipcall.Evaluation; } - return TrafficLightMode.RED; } - if (IsFlagSet(StatusFlags.YELLOW)) - return TrafficLightMode.YELLOW; - if (IsFlagSet(StatusFlags.GREEN)) - return TrafficLightMode.GREEN; - return TrafficLightMode.OFF; - } + return tlm; + } } #endregion