From b2cce15464cac2b8cd7fdfa6ba2dc89a8cdf5c85 Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Wed, 25 Jan 2023 01:48:54 +0100 Subject: [PATCH] Added: API Heartbeat --- Borepin/Borepin/Base/ConnectionModelBase.cs | 60 ++- Borepin/Borepin/Page/MachineListPage.xaml | 7 +- .../AddServerProcess/AuthPlainPageModel.cs | 7 +- .../ChooseAuthTypePageModel.cs | 2 +- .../AddServerProcess/SelectServerPageModel.cs | 4 +- Borepin/Borepin/PageModel/ServerPageModel.cs | 11 +- Borepin/Borepin/PageModel/StartPageModel.cs | 3 +- Borepin/Borepin/View/ConnectionStateView.xaml | 8 +- FabAccessAPI/API.cs | 378 ++++++++++++------ FabAccessAPI/ConnectionData.cs | 8 +- FabAccessAPI/ConnectionStatusChange.cs | 23 -- FabAccessAPI/ConnectionStatusChanged.cs | 20 + .../Exceptions/AuthenticationException.cs | 26 ++ .../Exceptions/ConnectingFailedException.cs | 22 - .../Exceptions/ConnectionException.cs | 26 ++ .../AuthenticationFailedException.cs | 2 +- .../{ => SASL}/BadMechanismException.cs | 2 +- .../{ => SASL}/InvalidCredentialsException.cs | 2 +- FabAccessAPI/Exceptions/TimeoutException.cs | 25 ++ FabAccessAPI/IAPI.cs | 79 ++-- FabAccessAPI/Mechanism.cs | 24 -- FabAccessAPI/SASLMechanismEnum.cs | 24 ++ .../{ConnectionInfo.cs => ServerData.cs} | 2 +- FabAccessAPI_Test/API_Test.cs | 54 ++- FabAccessAPI_Test/API_TestEnv/User_Test.cs | 1 + FabAccessAPI_Test/TestEnv.cs | 6 +- 26 files changed, 522 insertions(+), 304 deletions(-) delete mode 100644 FabAccessAPI/ConnectionStatusChange.cs create mode 100644 FabAccessAPI/ConnectionStatusChanged.cs create mode 100644 FabAccessAPI/Exceptions/AuthenticationException.cs delete mode 100644 FabAccessAPI/Exceptions/ConnectingFailedException.cs create mode 100644 FabAccessAPI/Exceptions/ConnectionException.cs rename FabAccessAPI/Exceptions/{ => SASL}/AuthenticationFailedException.cs (94%) rename FabAccessAPI/Exceptions/{ => SASL}/BadMechanismException.cs (90%) rename FabAccessAPI/Exceptions/{ => SASL}/InvalidCredentialsException.cs (90%) create mode 100644 FabAccessAPI/Exceptions/TimeoutException.cs delete mode 100644 FabAccessAPI/Mechanism.cs create mode 100644 FabAccessAPI/SASLMechanismEnum.cs rename FabAccessAPI/{ConnectionInfo.cs => ServerData.cs} (88%) diff --git a/Borepin/Borepin/Base/ConnectionModelBase.cs b/Borepin/Borepin/Base/ConnectionModelBase.cs index a07360e..aed8945 100644 --- a/Borepin/Borepin/Base/ConnectionModelBase.cs +++ b/Borepin/Borepin/Base/ConnectionModelBase.cs @@ -1,5 +1,6 @@ using Borepin.Service; using FabAccessAPI; +using NLog; using Prism.Navigation; using Prism.Services; using System; @@ -30,12 +31,13 @@ namespace Borepin.Base #endregion #region Methods - public async void OnConnectionStatusChanged(object sender, ConnectionStatusChange args) + public async void OnConnectionStatusChanged(object sender, ConnectionStatusChanged args) { switch(args) { - case ConnectionStatusChange.Connected: + case ConnectionStatusChanged.Connected: IsConnected = true; + IsConnecting = false; try { await LoadAPIData().ConfigureAwait(false); @@ -44,35 +46,16 @@ namespace Borepin.Base { IsConnected = false; await _API.Disconnect().ConfigureAwait(false); - _API.UnbindAllEvents(); + _API.UnbindEventHandler(); } break; - case ConnectionStatusChange.Reconnected: - try - { - await ReloadAPIData().ConfigureAwait(false); - } - catch - { - IsConnected = false; - await _API.Disconnect().ConfigureAwait(false); - _API.UnbindAllEvents(); - } - break; - case ConnectionStatusChange.ConnectionLoss: - try - { - await _API.Reconnect().ConfigureAwait(false); - } - catch - { - IsConnected = false; - await _API.Disconnect().ConfigureAwait(false); - _API.UnbindAllEvents(); - } - break; - case ConnectionStatusChange.Disconnected: + case ConnectionStatusChanged.ConnectionLoss: IsConnected = false; + IsConnecting = true; + break; + case ConnectionStatusChanged.Disconnected: + IsConnected = false; + IsConnecting = false; break; } } @@ -81,22 +64,28 @@ namespace Borepin.Base { return Task.CompletedTask; } - public virtual Task ReloadAPIData() - { - return Task.CompletedTask; - } #endregion #region Fields /// /// PageModel is Connected /// - private bool _IsConnected = true; + private bool _IsConnected = false; public bool IsConnected { get => _IsConnected; set => SetProperty(ref _IsConnected, value); } + + /// + /// PageModel is Connecting + /// + private bool _IsConnecting = false; + public bool IsConnecting + { + get => _IsConnecting; + set => SetProperty(ref _IsConnecting, value); + } #endregion #region INavigationAware @@ -110,11 +99,12 @@ namespace Borepin.Base { await LoadAPIData().ConfigureAwait(false); } - catch(Exception ex) + catch(Exception exception) { IsConnected = false; await _API.Disconnect().ConfigureAwait(false); - _API.UnbindAllEvents(); + _API.UnbindEventHandler(); + Log.Error("LoadAPIData failed", exception); } } } diff --git a/Borepin/Borepin/Page/MachineListPage.xaml b/Borepin/Borepin/Page/MachineListPage.xaml index 5b47d51..08fcd0a 100644 --- a/Borepin/Borepin/Page/MachineListPage.xaml +++ b/Borepin/Borepin/Page/MachineListPage.xaml @@ -17,9 +17,7 @@ - - - +