From 85ae6767ae0e2fc29587ee9cf4813acd2f5cecac Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Thu, 19 Jan 2023 01:31:07 +0100 Subject: [PATCH 1/4] Fixed: InvalidCredentials Alert --- .../AddServerProcess/AuthPlainPageModel.cs | 18 ++++++++- Borepin/Borepin/PageModel/ScanURNPageModel.cs | 2 +- Borepin/Borepin/PageModel/StartPageModel.cs | 40 +++++++++++++------ .../Resources/Text/TextResource.Designer.cs | 22 +++++++++- .../Borepin/Resources/Text/TextResource.resx | 8 +++- 5 files changed, 72 insertions(+), 18 deletions(-) diff --git a/Borepin/Borepin/PageModel/AddServerProcess/AuthPlainPageModel.cs b/Borepin/Borepin/PageModel/AddServerProcess/AuthPlainPageModel.cs index 4a323b9..81612c4 100644 --- a/Borepin/Borepin/PageModel/AddServerProcess/AuthPlainPageModel.cs +++ b/Borepin/Borepin/PageModel/AddServerProcess/AuthPlainPageModel.cs @@ -79,6 +79,12 @@ namespace Borepin.PageModel.AddServerProcess public async Task AuthenticateCommandExecute() { IsBusy = true; + if(Username == null || Username == String.Empty || Password == null || Password == String.Empty) + { + IsBusy = false; + return; + } + Username = Username.Trim(); _ConnectionData = new ConnectionData() @@ -116,6 +122,16 @@ namespace Borepin.PageModel.AddServerProcess }); return; } + catch (InvalidCredentialsException) + { + Device.BeginInvokeOnMainThread(async () => + { + await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_CredentialsInvalid, Resources.Text.TextResource.OK).ConfigureAwait(false); + + IsBusy = false; + }); + return; + } catch (AuthenticationFailedException) { Device.BeginInvokeOnMainThread(async () => @@ -126,7 +142,7 @@ namespace Borepin.PageModel.AddServerProcess }); return; } - catch(Exception) + catch(Exception ex) { Device.BeginInvokeOnMainThread(async () => { diff --git a/Borepin/Borepin/PageModel/ScanURNPageModel.cs b/Borepin/Borepin/PageModel/ScanURNPageModel.cs index 7974fa4..e047c23 100644 --- a/Borepin/Borepin/PageModel/ScanURNPageModel.cs +++ b/Borepin/Borepin/PageModel/ScanURNPageModel.cs @@ -109,7 +109,7 @@ namespace Borepin.PageModel { Device.BeginInvokeOnMainThread(async () => { - await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT, Resources.Text.TextResource.Alert_QRInvalid, Resources.Text.TextResource.OK).ConfigureAwait(false); + await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT, Resources.Text.TextResource.ALERT_QRInvalid, Resources.Text.TextResource.OK).ConfigureAwait(false); IsScanning = true; }); return; diff --git a/Borepin/Borepin/PageModel/StartPageModel.cs b/Borepin/Borepin/PageModel/StartPageModel.cs index 646d0f4..4c7bfef 100644 --- a/Borepin/Borepin/PageModel/StartPageModel.cs +++ b/Borepin/Borepin/PageModel/StartPageModel.cs @@ -69,23 +69,37 @@ namespace Borepin.PageModel } }); } - catch(Exception ex) + catch (ConnectingFailedException) { - if (ex is AuthenticationFailedException) + Device.BeginInvokeOnMainThread(async () => { - Device.BeginInvokeOnMainThread(async () => - { - await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_AuthServer, Resources.Text.TextResource.OK).ConfigureAwait(false); - }); - } - else if (ex is ConnectingFailedException) + await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_UnableServer, Resources.Text.TextResource.OK).ConfigureAwait(false); + }); + } + catch (AuthenticationFailedException) + { + Device.BeginInvokeOnMainThread(async () => { - Device.BeginInvokeOnMainThread(async () => - { - await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_UnableServer, Resources.Text.TextResource.OK).ConfigureAwait(false); - }); - } + await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_AuthServer, Resources.Text.TextResource.OK).ConfigureAwait(false); + }); + } + catch (InvalidCredentialsException) + { + Device.BeginInvokeOnMainThread(async () => + { + await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_CredentialsInvalid, Resources.Text.TextResource.OK).ConfigureAwait(false); + }); + } + catch (Exception) + { + Device.BeginInvokeOnMainThread(async () => + { + await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_UnexpectedError, Resources.Text.TextResource.ALERT_UnableServer, Resources.Text.TextResource.OK).ConfigureAwait(false); + }); + } + if (_API.IsConnected == false) + { Device.BeginInvokeOnMainThread(async () => { INavigationResult result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage").ConfigureAwait(false); diff --git a/Borepin/Borepin/Resources/Text/TextResource.Designer.cs b/Borepin/Borepin/Resources/Text/TextResource.Designer.cs index 1dc0baf..3b7573e 100644 --- a/Borepin/Borepin/Resources/Text/TextResource.Designer.cs +++ b/Borepin/Borepin/Resources/Text/TextResource.Designer.cs @@ -188,6 +188,15 @@ namespace Borepin.Resources.Text { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Credentials are invalid. ähnelt. + /// + internal static string ALERT_CredentialsInvalid { + get { + return ResourceManager.GetString("ALERT_CredentialsInvalid", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Connection already exist. Please delete old Connection before adding the new Connection. ähnelt. /// @@ -209,9 +218,9 @@ namespace Borepin.Resources.Text { /// /// Sucht eine lokalisierte Zeichenfolge, die QR Code is invalid ähnelt. /// - internal static string Alert_QRInvalid { + internal static string ALERT_QRInvalid { get { - return ResourceManager.GetString("Alert_QRInvalid", resourceCulture); + return ResourceManager.GetString("ALERT_QRInvalid", resourceCulture); } } @@ -450,6 +459,15 @@ namespace Borepin.Resources.Text { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Unlock ähnelt. + /// + internal static string MachinePage_Unlock { + get { + return ResourceManager.GetString("MachinePage_Unlock", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Use ähnelt. /// diff --git a/Borepin/Borepin/Resources/Text/TextResource.resx b/Borepin/Borepin/Resources/Text/TextResource.resx index fd73670..faa73d3 100644 --- a/Borepin/Borepin/Resources/Text/TextResource.resx +++ b/Borepin/Borepin/Resources/Text/TextResource.resx @@ -161,13 +161,16 @@ You can also put down several servers and then connect to the desired server. Connection failed + + Credentials are invalid. + Connection already exist. Please delete old Connection before adding the new Connection. Password is invalid. - + QR Code is invalid @@ -249,6 +252,9 @@ Ask in your Space if you can be trained on the machine to be unlocked for the ma Open Wiki + + Unlock + Use From f78668879bd53992d635c8d37c258a311afd2b5f Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Sat, 21 Jan 2023 15:14:02 +0100 Subject: [PATCH 2/4] Added: ConnectionStateView --- Borepin/Borepin/View/ConnectionStateView.xaml | 25 +++++++++++++++++++ .../Borepin/View/ConnectionStateView.xaml.cs | 20 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Borepin/Borepin/View/ConnectionStateView.xaml create mode 100644 Borepin/Borepin/View/ConnectionStateView.xaml.cs diff --git a/Borepin/Borepin/View/ConnectionStateView.xaml b/Borepin/Borepin/View/ConnectionStateView.xaml new file mode 100644 index 0000000..fae3a98 --- /dev/null +++ b/Borepin/Borepin/View/ConnectionStateView.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Borepin/Borepin/View/ConnectionStateView.xaml.cs b/Borepin/Borepin/View/ConnectionStateView.xaml.cs new file mode 100644 index 0000000..7118278 --- /dev/null +++ b/Borepin/Borepin/View/ConnectionStateView.xaml.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace Borepin.View +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class ConnectionStateView : ContentView + { + public ConnectionStateView() + { + InitializeComponent(); + } + } +} \ No newline at end of file From b2cce15464cac2b8cd7fdfa6ba2dc89a8cdf5c85 Mon Sep 17 00:00:00 2001 From: TheJoKlLa Date: Wed, 25 Jan 2023 01:48:54 +0100 Subject: [PATCH 3/4] 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 @@ - - - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/Borepin/Borepin/Page/MachinePage.xaml b/Borepin/Borepin/Page/MachinePage.xaml index 3a0576f..99ebf23 100644 --- a/Borepin/Borepin/Page/MachinePage.xaml +++ b/Borepin/Borepin/Page/MachinePage.xaml @@ -3,51 +3,61 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Borepin.Page.MachinePage" xmlns:converters="clr-namespace:Borepin.Converter" - xmlns:resource_text="clr-namespace:Borepin.Resources.Text" + xmlns:resource_text="clr-namespace:Borepin.Resources.Text" + xmlns:views="clr-namespace:Borepin.View" Title="{x:Static resource_text:TextResource.TITLE_Machine}"> - - + + - + + + - - - + + + + + + + + +