diff --git a/src/BreCalClient/App.xaml.cs b/src/BreCalClient/App.xaml.cs
index e85a282..c44620d 100644
--- a/src/BreCalClient/App.xaml.cs
+++ b/src/BreCalClient/App.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using BreCalClient.misc.Model;
+using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -13,5 +14,6 @@ namespace BreCalClient
///
public partial class App : Application
{
+ public static Participant Participant { get; set; } = new Participant();
}
}
diff --git a/src/BreCalClient/Extensions.cs b/src/BreCalClient/Extensions.cs
new file mode 100644
index 0000000..eae3ed0
--- /dev/null
+++ b/src/BreCalClient/Extensions.cs
@@ -0,0 +1,62 @@
+// Copyright (c) 2023 schick Informatik
+// Description: some helpers
+//
+
+using BreCalClient.misc.Model;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BreCalClient
+{
+ internal static class Extensions
+ {
+
+ #region Enum
+
+ ///
+ /// Copied from models clunky I know
+ ///
+ [Flags]
+ public enum ParticipantType
+ {
+ [Description("not assigned")]
+ NONE = 0,
+ [Description("BSMD")]
+ BSMD = 1,
+ [Description("Terminal")]
+ TERMINAL = 2,
+ [Description("Lotsen")]
+ PILOT = 4,
+ [Description("Agentur")]
+ AGENCY = 8,
+ [Description("Festmacher")]
+ MOORING = 16,
+ [Description("Hafenamt")]
+ PORT_ADMINISTRATION = 32,
+ [Description("Schlepper")]
+ TUG = 64,
+ }
+
+ #endregion
+
+ #region public helper
+
+ public static bool IsFlagSet(this Participant participant, ParticipantType flag)
+ {
+ return (participant.Type & (uint)flag) != 0;
+ }
+
+ public static void SetFlag(this Participant participant, bool value, ParticipantType flag)
+ {
+ if (value) participant.Type |= (int)flag;
+ else participant.Type &= (int)~flag;
+ }
+
+ #endregion
+
+ }
+}
diff --git a/src/BreCalClient/MainWindow.xaml b/src/BreCalClient/MainWindow.xaml
index 6fe04e5..44f992b 100644
--- a/src/BreCalClient/MainWindow.xaml
+++ b/src/BreCalClient/MainWindow.xaml
@@ -57,6 +57,7 @@
+
diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs
index e88b3c3..1d721e6 100644
--- a/src/BreCalClient/MainWindow.xaml.cs
+++ b/src/BreCalClient/MainWindow.xaml.cs
@@ -22,15 +22,17 @@ namespace BreCalClient
public partial class MainWindow : Window
{
private const int SHIPCALL_UPDATE_INTERVAL_SECONDS = 30;
- private DefaultApi _api;
- private ObservableCollection _controlModels = new();
+ private readonly DefaultApi _api;
+ private readonly ObservableCollection _controlModels = new();
private List _ships = new();
- private ConcurrentDictionary _shipLookupDict = new();
+ private readonly ConcurrentDictionary _shipLookupDict = new();
private List _berths = new();
- private ConcurrentDictionary _berthLookupDict = new();
+ private readonly ConcurrentDictionary _berthLookupDict = new();
private List _participants = new();
- private Dictionary _participantLookupDict = new();
- private CancellationTokenSource _tokenSource = new CancellationTokenSource();
+ private readonly Dictionary _participantLookupDict = new();
+ private readonly Dictionary _shipCallControlDict = new();
+ private readonly CancellationTokenSource _tokenSource = new();
+ private LoginResult? _loginResult;
public MainWindow()
{
@@ -64,13 +66,13 @@ namespace BreCalClient
try
{
- LoginResult loginResult = await _api.LoginPostAsync(credentials);
- if(loginResult != null)
+ _loginResult = await _api.LoginPostAsync(credentials);
+ if(_loginResult != null)
{
- if(loginResult.Id > 0)
+ if(_loginResult.Id > 0)
{
this.busyIndicator.IsBusy = false;
- this._api.Configuration.ApiKey["Authorization"] = loginResult.Token;
+ this._api.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this.LoadStaticLists();
}
}
@@ -104,79 +106,95 @@ namespace BreCalClient
foreach(var ship in this._ships)
_shipLookupDict[ship.Id] = ship;
this._participants = await _api.ParticipantsGetAsync();
- List agencies = new List();
+
foreach (Participant participant in this._participants)
{
this._participantLookupDict[participant.Id] = participant;
-
+ if (_loginResult?.ParticipantId == participant.Id)
+ {
+ App.Participant = participant;
+ EnableControlsForParticipant();
+ }
}
_ = Task.Run(() => RefreshShipcalls());
}
+ private void EnableControlsForParticipant()
+ {
+ if (App.Participant.IsFlagSet(Extensions.ParticipantType.BSMD))
+ this.buttonNew.Visibility = Visibility.Visible;
+ }
public async Task RefreshShipcalls()
{
while (!_tokenSource.Token.IsCancellationRequested)
{
List shipcalls = await _api.ShipcallsGetAsync();
- foreach (Shipcall shipcall in shipcalls)
+ if (shipcalls != null)
{
- ShipcallControlModel? selectedSCMModel = null;
-
- foreach(ShipcallControlModel scm in this._controlModels)
+ foreach (Shipcall shipcall in shipcalls)
{
- if(scm.Shipcall?.Id == shipcall.Id)
+ ShipcallControlModel? selectedSCMModel = null;
+
+ foreach (ShipcallControlModel scm in this._controlModels)
{
- selectedSCMModel = scm;
- break;
+ if (scm.Shipcall?.Id == shipcall.Id)
+ {
+ selectedSCMModel = scm;
+ break;
+ }
+ }
+
+ if (selectedSCMModel != null)
+ {
+ selectedSCMModel.Shipcall = shipcall;
+ }
+ else
+ {
+ // no: create new entry
+ selectedSCMModel = new ShipcallControlModel();
+ selectedSCMModel.Shipcall = shipcall;
+ if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
+ selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
+ if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))
+ selectedSCMModel.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name1;
+
+ _controlModels.Add(selectedSCMModel);
+ this.Dispatcher.Invoke(new Action(() =>
+ {
+ ShipcallControl sc = new ShipcallControl();
+ sc.Height = 120;
+ sc.ShipcallControlModel = selectedSCMModel;
+ sc.TimesRequested += Sc_TimesRequested;
+ sc.EditRequested += Sc_EditRequested;
+ this.stackPanel.Children.Add(sc);
+ this._shipCallControlDict[shipcall.Id] = sc;
+ }));
+ }
+
+ selectedSCMModel.AssignParticipants(this._participants);
+ this.Dispatcher.Invoke((Action)(() =>
+ {
+ this._shipCallControlDict[shipcall.Id].RefreshData();
+ }));
+
+ }
+
+ List removeList = new();
+ foreach (ShipcallControlModel scm in this._controlModels)
+ {
+ if (shipcalls.Find(s => s.Id == scm.Shipcall?.Id) == null) // the model is no longer in the search result
+ {
+ if((scm.Shipcall != null) && this._shipCallControlDict.ContainsKey(scm.Shipcall.Id))
+ {
+ this.Dispatcher.Invoke((Action)(() =>
+ {
+ this.stackPanel.Children.Remove(this._shipCallControlDict[scm.Shipcall.Id]);
+ }));
+ this._shipCallControlDict.Remove(scm.Shipcall.Id);
+ }
}
}
-
- if(selectedSCMModel != null)
- {
- selectedSCMModel.Shipcall = shipcall;
- }
- else
- {
- // no: create new entry
- selectedSCMModel = new ShipcallControlModel();
- selectedSCMModel.Shipcall = shipcall;
- if (this._shipLookupDict.ContainsKey(shipcall.ShipId))
- selectedSCMModel.Ship = this._shipLookupDict[shipcall.ShipId];
- if (this._berthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))
- selectedSCMModel.Berth = this._berthLookupDict[shipcall.ArrivalBerthId ?? 0].Name1;
-
- _controlModels.Add(selectedSCMModel);
- this.Dispatcher.Invoke(new Action(() =>
- {
- ShipcallControl sc = new ShipcallControl();
- sc.Height = 120;
- sc.ShipcallControlModel = selectedSCMModel;
- sc.TimesRequested += Sc_TimesRequested;
- sc.EditRequested += Sc_EditRequested;
- this.stackPanel.Children.Add(sc);
- }));
- }
- selectedSCMModel.AssignParticipants(this._participants);
- }
-
- List removeList = new();
- foreach (ShipcallControlModel scm in this._controlModels)
- {
- if(shipcalls.Find(s => s.Id == scm.Shipcall?.Id) == null)
- {
- foreach (ShipcallControl sc in this.stackPanel.Children)
- if (sc.ShipcallControlModel?.Shipcall?.Id == scm.Shipcall?.Id)
- removeList.Add(sc);
- }
- }
-
- foreach(ShipcallControl sc in removeList)
- {
- this.Dispatcher.Invoke(new Action(() =>
- {
- this.stackPanel.Children.Remove(sc);
- }));
}
await Task.Delay(TimeSpan.FromSeconds(SHIPCALL_UPDATE_INTERVAL_SECONDS), _tokenSource.Token);
diff --git a/src/BreCalClient/Resources/Resources.Designer.cs b/src/BreCalClient/Resources/Resources.Designer.cs
index 5b11248..af500fb 100644
--- a/src/BreCalClient/Resources/Resources.Designer.cs
+++ b/src/BreCalClient/Resources/Resources.Designer.cs
@@ -278,6 +278,15 @@ namespace BreCalClient.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to New...
+ ///
+ public static string textNewDots {
+ get {
+ return ResourceManager.GetString("textNewDots", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Password.
///
diff --git a/src/BreCalClient/Resources/Resources.de.resx b/src/BreCalClient/Resources/Resources.de.resx
index a1f1af6..4a14091 100644
--- a/src/BreCalClient/Resources/Resources.de.resx
+++ b/src/BreCalClient/Resources/Resources.de.resx
@@ -181,6 +181,9 @@
Anmelden
+
+ Neu..
+
Passwort
diff --git a/src/BreCalClient/Resources/Resources.resx b/src/BreCalClient/Resources/Resources.resx
index b7875c9..e014eb2 100644
--- a/src/BreCalClient/Resources/Resources.resx
+++ b/src/BreCalClient/Resources/Resources.resx
@@ -187,6 +187,9 @@
Login
+
+ New..
+
Password
diff --git a/src/BreCalClient/ShipcallControl.xaml b/src/BreCalClient/ShipcallControl.xaml
index 4455cb0..012b51e 100644
--- a/src/BreCalClient/ShipcallControl.xaml
+++ b/src/BreCalClient/ShipcallControl.xaml
@@ -89,17 +89,17 @@
-
-
-
-
-
-
diff --git a/src/BreCalClient/ShipcallControl.xaml.cs b/src/BreCalClient/ShipcallControl.xaml.cs
index 509eb4a..dd596a1 100644
--- a/src/BreCalClient/ShipcallControl.xaml.cs
+++ b/src/BreCalClient/ShipcallControl.xaml.cs
@@ -42,14 +42,39 @@ namespace BreCalClient
#endregion
+ #region public methods
+
+ public void RefreshData()
+ {
+ if (this.ShipcallControlModel == null) return;
+ string? name;
+ name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.AGENCY);
+ if (name != null)
+ this.labelAgent.Content = name;
+ name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.MOORING);
+ if (name != null)
+ this.labelMooring.Content = name;
+ name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.PILOT);
+ if (name != null)
+ this.labelPilot.Content = name;
+ name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.TUG);
+ if (name != null)
+ this.labelTug.Content = name;
+ name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.PORT_ADMINISTRATION);
+ if (name != null)
+ this.labelPortAuthority.Content = name;
+ name = this.ShipcallControlModel.GetParticipantNameForType(Extensions.ParticipantType.TERMINAL);
+ if (name != null)
+ this.labelTerminal.Content = name;
+ }
+
+ #endregion
+
#region event handler
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
- this.DataContext = this.ShipcallControlModel;
- if (this.ShipcallControlModel == null) return;
- this.labelAgent.Content = this.ShipcallControlModel.AssignedParticipants.ContainsKey(8) ? this.ShipcallControlModel.AssignedParticipants[8].Name : string.Empty;
- this.labelMooring.Content = this.ShipcallControlModel.AssignedParticipants.ContainsKey(16) ? this.ShipcallControlModel.AssignedParticipants[16].Name : string.Empty;
+ this.DataContext = this.ShipcallControlModel;
}
private void buttonListTimes_Click(object sender, RoutedEventArgs e)
@@ -80,20 +105,3 @@ namespace BreCalClient
}
}
-/*
- * Description("not assigned")]
- NONE = 0,
- [Description("BSMD")]
- BSMD = 1,
- [Description("Terminal")]
- TERMINAL = 2,
- [Description("Lotsen")]
- PILOT = 4,
- [Description("Agentur")]
- AGENCY = 8,
- [Description("Festmacher")]
- MOORING = 16,
- [Description("Hafenamt")]
- PORT_ADMINISTRATION = 32,
- [Description("Schlepper")]
- TUG = 64,*/
diff --git a/src/BreCalClient/ShipcallControlModel.cs b/src/BreCalClient/ShipcallControlModel.cs
index 1d7e077..b69389f 100644
--- a/src/BreCalClient/ShipcallControlModel.cs
+++ b/src/BreCalClient/ShipcallControlModel.cs
@@ -2,9 +2,12 @@
// Description: Container model for shipcall related info
//
+using BreCalClient.misc.Client;
using BreCalClient.misc.Model;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
namespace BreCalClient
{
@@ -15,6 +18,8 @@ namespace BreCalClient
public class ShipcallControlModel
{
+ #region Enumerations
+
public enum TrafficLightMode
{
OFF,
@@ -33,7 +38,9 @@ namespace BreCalClient
YELLOW,
BLINK_1,
BLINK_2
- };
+ };
+
+ #endregion
public Shipcall? Shipcall { get; set; }
public Ship? Ship { get; set; }
@@ -84,6 +91,16 @@ namespace BreCalClient
}
}
+ internal string? GetParticipantNameForType(Extensions.ParticipantType participantType)
+ {
+ foreach(Participant p in AssignedParticipants.Values)
+ {
+ if (p.IsFlagSet(participantType))
+ return p.Name;
+ }
+ return null;
+ }
+
#region private helper
private bool IsFlagSet(StatusFlags flag)
@@ -92,7 +109,7 @@ namespace BreCalClient
return (this.Shipcall.Flags & (int) flag) != 0;
}
- #endregion
+ #endregion
}
}