diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs index 5494860..9013f76 100644 --- a/misc/BreCalApi.cs +++ b/misc/BreCalApi.cs @@ -1,8 +1,8 @@ //---------------------- // -// Generated REST API Client Code Generator v1.16.0.0 on 10.12.2024 08:56:03 -// Using the tool OpenAPI Generator v7.9.0 +// Generated REST API Client Code Generator v1.17.0.0 on 19.12.2024 11:34:56 +// Using the tool OpenAPI Generator v7.10.0 // //---------------------- @@ -3829,7 +3829,7 @@ namespace BreCalClient.misc.Client if (response.Headers != null) { var filePath = string.IsNullOrEmpty(_configuration.TempFolderPath) - ? Path.GetTempPath() + ? global::System.IO.Path.GetTempPath() : _configuration.TempFolderPath; var regex = new Regex(@"Content-Disposition=.*filename=['""]?([^'""\s]+)['""]?$"); foreach (var header in response.Headers) @@ -4069,7 +4069,7 @@ namespace BreCalClient.misc.Client var bytes = ClientUtils.ReadAsBytes(file); var fileStream = file as FileStream; if (fileStream != null) - request.AddFile(fileParam.Key, bytes, Path.GetFileName(fileStream.Name)); + request.AddFile(fileParam.Key, bytes, global::System.IO.Path.GetFileName(fileStream.Name)); else request.AddFile(fileParam.Key, bytes, "no_file_name_provided"); } @@ -4139,7 +4139,7 @@ namespace BreCalClient.misc.Client var clientOptions = new RestClientOptions(baseUrl) { ClientCertificates = configuration.ClientCertificates, - MaxTimeout = configuration.Timeout, + Timeout = configuration.Timeout, Proxy = configuration.Proxy, UserAgent = configuration.UserAgent, UseDefaultCredentials = configuration.UseDefaultCredentials, @@ -4209,11 +4209,11 @@ namespace BreCalClient.misc.Client return result; } } - private RestResponse DeserializeRestResponseFromPolicy(RestClient client, RestRequest request, PolicyResult policyResult) + private async Task> DeserializeRestResponseFromPolicyAsync(RestClient client, RestRequest request, PolicyResult policyResult, CancellationToken cancellationToken = default) { if (policyResult.Outcome == OutcomeType.Successful) { - return client.Deserialize(policyResult.Result); + return await client.Deserialize(policyResult.Result, cancellationToken); } else { @@ -4243,7 +4243,7 @@ namespace BreCalClient.misc.Client { var policy = RetryConfiguration.RetryPolicy; var policyResult = policy.ExecuteAndCapture(() => client.Execute(request)); - return Task.FromResult(DeserializeRestResponseFromPolicy(client, request, policyResult)); + return DeserializeRestResponseFromPolicyAsync(client, request, policyResult); } else { @@ -4264,7 +4264,7 @@ namespace BreCalClient.misc.Client { var policy = RetryConfiguration.AsyncRetryPolicy; var policyResult = await policy.ExecuteAndCaptureAsync((ct) => client.ExecuteAsync(request, ct), cancellationToken).ConfigureAwait(false); - return DeserializeRestResponseFromPolicy(client, request, policyResult); + return await DeserializeRestResponseFromPolicyAsync(client, request, policyResult, cancellationToken); } else { @@ -5000,7 +5000,7 @@ namespace BreCalClient.misc.Client { }; // Setting Timeout has side effects (forces ApiClient creation). - Timeout = 100000; + Timeout = TimeSpan.FromSeconds(100); } /// /// Initializes a new instance of the class @@ -5072,9 +5072,9 @@ namespace BreCalClient.misc.Client /// public virtual IDictionary DefaultHeaders { get; set; } /// - /// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds. + /// Gets or sets the HTTP timeout of ApiClient. Defaults to 100 seconds. /// - public virtual int Timeout { get; set; } + public virtual TimeSpan Timeout { get; set; } /// /// Gets or sets the proxy /// @@ -5713,10 +5713,10 @@ namespace BreCalClient.misc.Client /// Temp folder path. string TempFolderPath { get; } /// - /// Gets the HTTP connection timeout (in milliseconds) + /// Gets the HTTP connection timeout. /// /// HTTP connection timeout. - int Timeout { get; } + TimeSpan Timeout { get; } /// /// Gets the proxy. /// @@ -7097,24 +7097,26 @@ namespace BreCalClient.misc.Model public partial class Notification : IValidatableObject { /// - /// Gets or Sets NotificationType + /// Gets or Sets Type /// - [DataMember(Name = "notification_type", EmitDefaultValue = true)] - public NotificationType? NotificationType { get; set; } + [DataMember(Name = "type", EmitDefaultValue = true)] + public NotificationType? Type { get; set; } /// /// Initializes a new instance of the class. /// /// id. /// shipcallId. - /// notificationType. + /// participantId. + /// type. /// message. /// Readonly field set by the database when notification was created. /// Readonly field set by the database when notification was last modified. - public Notification(int id = default(int), int shipcallId = default(int), NotificationType? notificationType = default(NotificationType?), string message = default(string), DateTime created = default(DateTime), DateTime? modified = default(DateTime?)) + public Notification(int id = default(int), int shipcallId = default(int), int? participantId = default(int?), NotificationType? type = default(NotificationType?), string message = default(string), DateTime created = default(DateTime), DateTime? modified = default(DateTime?)) { this.Id = id; this.ShipcallId = shipcallId; - this.NotificationType = notificationType; + this.ParticipantId = participantId; + this.Type = type; this.Message = message; this.Created = created; this.Modified = modified; @@ -7136,6 +7138,14 @@ namespace BreCalClient.misc.Model [DataMember(Name = "shipcall_id", EmitDefaultValue = true)] public int ShipcallId { get; set; } /// + /// Gets or Sets ParticipantId + /// + /* + 9 + */ + [DataMember(Name = "participant_id", EmitDefaultValue = true)] + public int? ParticipantId { get; set; } + /// /// Gets or Sets Message /// /* @@ -7171,7 +7181,8 @@ namespace BreCalClient.misc.Model sb.Append("class Notification {\n"); sb.Append(" Id: ").Append(Id).Append("\n"); sb.Append(" ShipcallId: ").Append(ShipcallId).Append("\n"); - sb.Append(" NotificationType: ").Append(NotificationType).Append("\n"); + sb.Append(" ParticipantId: ").Append(ParticipantId).Append("\n"); + sb.Append(" Type: ").Append(Type).Append("\n"); sb.Append(" Message: ").Append(Message).Append("\n"); sb.Append(" Created: ").Append(Created).Append("\n"); sb.Append(" Modified: ").Append(Modified).Append("\n"); diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index a51bd29..da638ee 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -1550,7 +1550,11 @@ components: type: integer example: 5 nullable: false - notification_type: + participant_id: + type: integer + example: 9 + nullable: true + type: $ref: '#/components/schemas/NotificationType' message: type: string @@ -1569,7 +1573,8 @@ components: example: id: 42 shipcall_id: 5 - notification_type: next24h + participant_id: 9 + type: next24h message: Shipcall may be relevant to you in the next 24 hours created: '2023-08-21T08:23:35Z' modified: '2023-08-21T08:23:35Z' @@ -1581,13 +1586,14 @@ components: example: - id: 42 shipcall_id: 5 - notification_type: time_conflict + participant_id: 9 + type: time_conflict message: Entry XY violates rule Z created: '2023-08-21T08:23:35Z' modified: '2023-08-21T08:23:35Z' - id: 43 shipcall_id: 7 - notification_type: time_conflict + type: time_conflict message: Entry AB violates rule C created: '2023-08-21T08:23:35Z' modified: '2023-08-21T08:23:35Z' diff --git a/misc/version.txt b/misc/version.txt index 1f0cf6b..c5e2be3 100644 --- a/misc/version.txt +++ b/misc/version.txt @@ -1 +1 @@ -1.7.0.0 \ No newline at end of file +1.7.0.3 \ No newline at end of file diff --git a/src/BreCalClient/AboutDialog.xaml b/src/BreCalClient/AboutDialog.xaml index 06def3e..5e75673 100644 --- a/src/BreCalClient/AboutDialog.xaml +++ b/src/BreCalClient/AboutDialog.xaml @@ -30,6 +30,7 @@ + @@ -47,7 +48,7 @@ Informatikbüro Daniel Schick - + + diff --git a/src/BreCalClient/AppNotificationPart.xaml.cs b/src/BreCalClient/AppNotificationPart.xaml.cs new file mode 100644 index 0000000..b717fd7 --- /dev/null +++ b/src/BreCalClient/AppNotificationPart.xaml.cs @@ -0,0 +1,51 @@ +using BreCalClient.misc.Model; +using System.Windows; +using System.Windows.Media; +using ToastNotifications.Core; + +namespace BreCalClient +{ + /// + /// Interaction logic for NotificationPart.xaml + /// + public partial class AppNotificationPart : NotificationDisplayPart + { + public AppNotificationPart(AppNotificationMessage appNotification) + { + InitializeComponent(); + Bind(appNotification); + + if (appNotification.Options.Tag is AppNotification ap) + { + switch (ap.NotificationType) + { + case "TimeConflict": + this.ContentWrapper.Background = Brushes.Red; + break; + case "TimeConflictResolved": + this.ContentWrapper.Background = Brushes.Green; + break; + case "Assignment": + this.ContentWrapper.Background = Brushes.Blue; + break; + case "Next24h": + this.ContentWrapper.Background = Brushes.DarkOrange; + break; + case "Unassigned": + this.ContentWrapper.Background = Brushes.Gray; + break; + default: + break; + + } + } + + } + + private void OnClose(object sender, RoutedEventArgs e) + { + Notification.Close(); + } + + } +} diff --git a/src/BreCalClient/BreCalClient.csproj b/src/BreCalClient/BreCalClient.csproj index 1493944..22cc7e2 100644 --- a/src/BreCalClient/BreCalClient.csproj +++ b/src/BreCalClient/BreCalClient.csproj @@ -8,8 +8,8 @@ True BreCalClient.App ..\..\misc\brecal.snk - 1.7.0.0 - 1.7.0.0 + 1.7.0.3 + 1.7.0.3 Bremen calling client A Windows WPF client for the Bremen calling API. containership.ico @@ -26,6 +26,7 @@ + @@ -84,6 +85,7 @@ + @@ -118,10 +120,12 @@ - + - - + + + + diff --git a/src/BreCalClient/HistoryDialog.xaml.cs b/src/BreCalClient/HistoryDialog.xaml.cs index ce6cb2b..f827de0 100644 --- a/src/BreCalClient/HistoryDialog.xaml.cs +++ b/src/BreCalClient/HistoryDialog.xaml.cs @@ -1,5 +1,5 @@ // Copyright (c) 2024- schick Informatik -// Description: Window to show (complete) list of current shipcall histories +// Description: // using BreCalClient.misc.Api; diff --git a/src/BreCalClient/MainWindow.xaml b/src/BreCalClient/MainWindow.xaml index dd169f8..f7f14eb 100644 --- a/src/BreCalClient/MainWindow.xaml +++ b/src/BreCalClient/MainWindow.xaml @@ -124,6 +124,8 @@ + + @@ -157,19 +159,25 @@ + + + + - - + + - + - - + + diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index cb0056b..be19337 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -36,8 +36,11 @@ namespace BreCalClient public partial class MainWindow : Window { private readonly ILog _log = LogManager.GetLogger(typeof(MainWindow)); + private readonly ToastViewModel _vm; + private const int SHIPCALL_UPDATE_INTERVAL_SECONDS = 30; private const int SHIPS_UPDATE_INTERVAL_SECONDS = 120; + private const int CHECK_NOTIFICATIONS_INTERVAL_SECONDS = 5; private const int PROGRESS_STEPS = 50; #region Fields @@ -68,6 +71,7 @@ namespace BreCalClient // private bool _filterChanged = false; // private bool _sequenceChanged = false; private HistoryDialog? _historyDialog; + private NotificationDialog? _notificationDialog; #endregion @@ -122,6 +126,13 @@ namespace BreCalClient RetryConfiguration.AsyncRetryPolicy = retryPolicy; this.generalProgressStatus.Maximum = PROGRESS_STEPS; + _vm = new ToastViewModel(); + this.Unloaded += MainWindow_Unloaded; + } + + private void MainWindow_Unloaded(object sender, RoutedEventArgs e) + { + _vm.OnUnloaded(); } #endregion @@ -443,6 +454,21 @@ namespace BreCalClient } } + private void buttonNotifications_Click(object sender, RoutedEventArgs e) + { + if (_notificationDialog == null) + { + _notificationDialog = new NotificationDialog(); + _notificationDialog.AppNotifications = AppNotification.AppNotifications; + _notificationDialog.Closed += (sender, e) => { this._notificationDialog = null; }; + _notificationDialog.Show(); + } + else + { + _notificationDialog.Activate(); + } + } + private void buttonManualRefresh_Click(object sender, RoutedEventArgs e) { _refreshImmediately = true; // set flag to avoid timer loop termination @@ -510,6 +536,7 @@ namespace BreCalClient _ = Task.Run(() => RefreshShipcalls()); _ = Task.Run(() => RefreshShips()); + _ = Task.Run(() => CheckNotifications()); } @@ -633,6 +660,19 @@ namespace BreCalClient } } + public async Task CheckNotifications() + { + while (true) + { + Thread.Sleep(CHECK_NOTIFICATIONS_INTERVAL_SECONDS * 1000); + if (_loginResult?.NotifyPopup ?? false) + { + List notifications = await _staticApi.NotificationsGetAsync(); + AppNotification.UpdateNotifications(notifications, _allShipcallsDict, _vm); + } + } + } + #endregion #region basic operations diff --git a/src/BreCalClient/NotificationDialog.xaml b/src/BreCalClient/NotificationDialog.xaml new file mode 100644 index 0000000..6fab214 --- /dev/null +++ b/src/BreCalClient/NotificationDialog.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +