Added: API Heartbeat

This commit is contained in:
TheJoKlLa
2023-01-25 01:48:54 +01:00
parent f78668879b
commit b2cce15464
26 changed files with 522 additions and 304 deletions

View File

@ -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
/// <summary>
/// PageModel is Connected
/// </summary>
private bool _IsConnected = true;
private bool _IsConnected = false;
public bool IsConnected
{
get => _IsConnected;
set => SetProperty(ref _IsConnected, value);
}
/// <summary>
/// PageModel is Connecting
/// </summary>
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);
}
}
}

View File

@ -17,9 +17,7 @@
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Padding="20">
<StackLayout IsVisible="{Binding IsBusy}">
<ActivityIndicator IsRunning="{Binding IsBusy}"></ActivityIndicator>
</StackLayout>
<views:ConnectionStateView/>
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
<StackLayout IsVisible="{Binding IsConnected}">
<Button Text="{x:Static resource_text:TextResource.SCANQR}" Command="{Binding ScanCodeCommand}" Style="{StaticResource Style_Button_Primary}">
@ -48,9 +46,6 @@
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}">
<Label Text="{x:Static resource_text:TextResource.PLEASECONNECTTOSERVER}" ></Label>
</StackLayout>
</StackLayout>
</StackLayout>
</ContentPage.Content>

View File

@ -8,6 +8,7 @@ using Borepin.Service;
using Borepin.Service.Storage;
using FabAccessAPI;
using FabAccessAPI.Exceptions;
using FabAccessAPI.Exceptions.SASL;
using Prism.Commands;
using Prism.Navigation;
using Prism.Services;
@ -90,7 +91,7 @@ namespace Borepin.PageModel.AddServerProcess
_ConnectionData = new ConnectionData()
{
Host = _ConnectionData.Host,
Mechanism = Mechanism.PLAIN,
Mechanism = SASLMechanismEnum.PLAIN,
Username = Username,
Properties = new Dictionary<string, object>(StringComparer.Ordinal)
{
@ -104,7 +105,7 @@ namespace Borepin.PageModel.AddServerProcess
if (_API.IsConnected)
{
await _API.Disconnect().ConfigureAwait(true);
_API.UnbindAllEvents();
_API.UnbindEventHandler();
}
}
@ -112,7 +113,7 @@ namespace Borepin.PageModel.AddServerProcess
{
await _API.Connect(_ConnectionData).ConfigureAwait(false);
}
catch (ConnectingFailedException)
catch (ConnectionException)
{
Device.BeginInvokeOnMainThread(async () =>
{

View File

@ -51,7 +51,7 @@ namespace Borepin.PageModel.AddServerProcess
}
public async void AuthPlainCommandExecute()
{
_ConnectionData.Mechanism = Mechanism.PLAIN;
_ConnectionData.Mechanism = SASLMechanismEnum.PLAIN;
INavigationResult result = await _NavigationService.NavigateAsync("AddServerProcess_AuthPlainPage").ConfigureAwait(false);
if(result.Exception != null)

View File

@ -118,9 +118,9 @@ namespace Borepin.PageModel.AddServerProcess
try
{
API api = new API();
await api.TestConnection(_ConnectionData).ConfigureAwait(false);
await api.TryToConnect(_ConnectionData).ConfigureAwait(false);
}
catch(ConnectingFailedException)
catch(ConnectionException)
{
Device.BeginInvokeOnMainThread(async () =>
{

View File

@ -4,6 +4,7 @@ using Borepin.Service;
using Borepin.Service.Storage;
using FabAccessAPI;
using FabAccessAPI.Exceptions;
using FabAccessAPI.Exceptions.SASL;
using Prism.Commands;
using Prism.Navigation;
using Prism.Services;
@ -51,7 +52,7 @@ namespace Borepin.PageModel
throw new InstanceIncorrectException();
}
if(_API.ConnectionData != null && Connection_Item != null)
if(_API.IsConnected && Connection_Item != null)
{
InstanceIsActiveConnection = Connection_Item.Equals(_API.ConnectionData);
}
@ -124,14 +125,14 @@ namespace Borepin.PageModel
if(_API.IsConnected)
{
await _API.Disconnect().ConfigureAwait(true);
_API.UnbindAllEvents();
_API.UnbindEventHandler();
}
try
{
await _API.Connect(Connection_Item).ConfigureAwait(false);
}
catch(ConnectingFailedException)
catch(ConnectionException)
{
Device.BeginInvokeOnMainThread(async () =>
{
@ -184,7 +185,7 @@ namespace Borepin.PageModel
}
public async Task DisonnectCommandExecute()
{
_API.UnbindAllEvents();
_API.UnbindEventHandler();
await _API.Disconnect().ConfigureAwait(false);
await LoadInstance(Connection_Item).ConfigureAwait(false);
@ -215,7 +216,7 @@ namespace Borepin.PageModel
if(string.Equals(result.Parameters.GetValue<string>("result"), "confirm", StringComparison.Ordinal))
{
await _API.Disconnect().ConfigureAwait(false);
_API.UnbindAllEvents();
_API.UnbindEventHandler();
await _LoginStorageService.Remove(result.Parameters.GetValue<ConnectionData>("instance")).ConfigureAwait(false);
Device.BeginInvokeOnMainThread(async () =>

View File

@ -3,6 +3,7 @@ using Borepin.Service;
using Borepin.Service.Storage;
using FabAccessAPI;
using FabAccessAPI.Exceptions;
using FabAccessAPI.Exceptions.SASL;
using Prism.AppModel;
using Prism.Navigation;
using Prism.Services;
@ -69,7 +70,7 @@ namespace Borepin.PageModel
}
});
}
catch (ConnectingFailedException)
catch (ConnectionException)
{
Device.BeginInvokeOnMainThread(async () =>
{

View File

@ -16,9 +16,11 @@
<ActivityIndicator IsRunning="{Binding IsBusy}"></ActivityIndicator>
</StackLayout>
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
<Label Text="No Connection to Server" IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}"/>
<Label Text="Reconnecting to Server ..." IsVisible="{Binding IsReconnecting}"/>
<Label Text="Please connect to Server." IsVisible="{Binding IsReconnecting, Converter={StaticResource InvertBoolConverter}}"/>
<StackLayout IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}">
<Label Text="No Connection to Server"/>
<Label Text="Connecting to Server ..." IsVisible="{Binding IsConnecting}"/>
<Label Text="Please select a Server." IsVisible="{Binding IsConnecting, Converter={StaticResource InvertBoolConverter}}"/>
</StackLayout>
</StackLayout>
</StackLayout>
</ContentView.Content>