Merge branch 'fix/morethings' into 'main'

Fix/morethings

See merge request fabinfra/fabaccess/borepin!76
This commit is contained in:
TheJoKlLa 2023-01-31 14:19:42 +00:00
commit b6402c78ab
19 changed files with 87 additions and 349 deletions

View File

@ -76,11 +76,7 @@
<Compile Include="PlatformInitializer.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\APIBinder.cs" />
<Compile Include="Services\APIBindedService.cs" />
<Compile Include="Services\APIService.cs" />
<Compile Include="Services\APIService_New.cs" />
<Compile Include="Services\APIServiceConnection.cs" />
<Compile Include="Services\BrowserService.cs" />
<Compile Include="Services\PreferenceStorageService.cs" />
<Compile Include="Services\SecretStorage.cs" />

View File

@ -1,50 +0,0 @@
using Android.App;
using Android.Content;
using Android.OS;
using FabAccessAPI;
namespace Borepin.Droid.Services
{
[Service(Name= "org.fab_infra.fabaccess.APIService")]
public class APIBindedService : Android.App.Service
{
#region Private Members
private IAPI _API;
#endregion
#region Members
public IBinder Binder { get; private set; }
#endregion
#region Methods
public IAPI GetAPI()
{
return _API;
}
public override void OnCreate()
{
base.OnCreate();
_API = new API();
}
public override IBinder OnBind(Intent intent)
{
Binder = new APIBinder(this);
return Binder;
}
public override bool OnUnbind(Intent intent)
{
return base.OnUnbind(intent);
}
public override void OnDestroy()
{
Binder = null;
_API = null;
base.OnDestroy();
}
#endregion
}
}

View File

@ -1,18 +0,0 @@
using Android.OS;
namespace Borepin.Droid.Services
{
public class APIBinder : Binder
{
#region Constructors
public APIBinder(APIBindedService service)
{
Service = service;
}
#endregion
#region Members
public APIBindedService Service { get; private set; }
#endregion
}
}

View File

@ -1,32 +0,0 @@
using Android.Content;
using Android.OS;
using FabAccessAPI;
namespace Borepin.Droid.Services
{
class APIServiceConnection : Java.Lang.Object, IServiceConnection
{
#region Members
public bool IsConnected
{
get
{
return Binder != null;
}
}
public APIBinder Binder { get; private set; } = null;
#endregion
#region Methods
public void OnServiceConnected(ComponentName name, IBinder service)
{
Binder = service as APIBinder;
}
public void OnServiceDisconnected(ComponentName name)
{
Binder = null;
}
#endregion
}
}

View File

@ -1,28 +0,0 @@
using Android.App;
using Android.Content;
using Borepin.Service;
using FabAccessAPI;
namespace Borepin.Droid.Services
{
public class APIService_New : IAPIService
{
#region Private Members
private readonly APIServiceConnection _APIServiceConnection;
#endregion
#region Constructors
public APIService_New()
{
Context context = Application.Context;
Intent service = new Intent(context, typeof(APIBindedService));
context.BindService(service, _APIServiceConnection, Bind.AutoCreate);
}
#endregion
public IAPI GetAPI()
{
return _APIServiceConnection?.Binder?.Service?.GetAPI();
}
}
}

View File

@ -65,7 +65,6 @@ namespace Borepin
#region Register Dialog
containerRegistry.RegisterDialog<ConfirmDialog, ConfirmDialogModel>();
containerRegistry.RegisterDialog<ScanDialog, ScanDialogModel>();
#endregion
#region Register Service

View File

@ -99,9 +99,6 @@
<EmbeddedResource Update="Dialog\ConfirmDialog.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Dialog\ScanDialog.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\AddServerProcess\SelectServerPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
x:Class="Borepin.Dialog.ScanDialog"
xmlns:resource_text="clr-namespace:Borepin.Resources.Text">
<ContentView.Content>
<StackLayout IsVisible="{Binding IsVisible}">
<zxing:ZXingScannerView Result="{Binding ScanResult, Mode=TwoWay}" ScanResultCommand="{Binding ScannedCommand}" IsScanning="{Binding IsScanning}" WidthRequest="300" HeightRequest="500" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>
<Button Text="{x:Static resource_text:TextResource.CANCEL}" Command="{Binding AbortCommand}"/>
</StackLayout>
</ContentView.Content>
</ContentView>

View File

@ -1,20 +0,0 @@
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.Dialog
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ScanDialog : ContentView
{
public ScanDialog()
{
InitializeComponent();
}
}
}

View File

@ -1,111 +0,0 @@
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Windows.Input;
using ZXing;
namespace Borepin.DialogModel
{
public class ScanDialogModel : BindableBase, IDialogAware
{
#region Private Fields
private object _Instance;
#endregion
#region Constructors
public ScanDialogModel()
{
AbortCommand = new DelegateCommand(AbortCommandExecute);
ScannedCommand = new DelegateCommand(ScannedCommandExecute);
IsVisible = true;
IsScanning = true;
}
#endregion
#region Fields
public event Action<IDialogParameters> RequestClose;
public bool CanCloseDialog()
{
return true;
}
private Result _ScanResult;
public Result ScanResult
{
get => _ScanResult;
set => SetProperty(ref _ScanResult, value);
}
private bool _IsScanning;
public bool IsScanning
{
get => _IsScanning;
set => SetProperty(ref _IsScanning, value);
}
private bool _IsVisible;
public bool IsVisible
{
get => _IsVisible;
set => SetProperty(ref _IsVisible, value);
}
#endregion
#region Commands
private ICommand _ScannedCommand;
public ICommand ScannedCommand
{
get => _ScannedCommand;
set => SetProperty(ref _ScannedCommand, value);
}
public void ScannedCommandExecute()
{
IsScanning = false;
IsVisible = false;
IDialogParameters parameters = new DialogParameters()
{
{ "result", "scanned" },
{ "value", ScanResult.Text },
{ "instance", _Instance },
};
RequestClose(parameters);
}
private ICommand _AbortCommand;
public ICommand AbortCommand
{
get => _AbortCommand;
set => SetProperty(ref _AbortCommand, value);
}
public void AbortCommandExecute()
{
IsScanning = false;
IsVisible = false;
IDialogParameters parameters = new DialogParameters()
{
{ "result", "abort" },
{ "instance", _Instance },
};
RequestClose(parameters);
}
#endregion
#region IDialogAware
public void OnDialogClosed()
{
}
public void OnDialogOpened(IDialogParameters parameters)
{
_Instance = parameters.GetValue<object>("instance");
}
#endregion
}
}

View File

@ -6,7 +6,15 @@
x:Class="Borepin.Page.ScanPage">
<ContentPage.Content>
<StackLayout IsVisible="{Binding IsVisible}">
<zxing:ZXingScannerView Result="{Binding ScanResult, Mode=TwoWay}" ScanResultCommand="{Binding ScannedCommand}" IsScanning="{Binding IsScanning}" WidthRequest="300" HeightRequest="500" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Options="{Binding ScanOptions}"/>
<zxing:ZXingScannerView
Result="{Binding ScanResult, Mode=TwoWay}"
ScanResultCommand="{Binding ScannedCommand}"
IsScanning="{Binding IsScanning}"
Options="{Binding ScanOptions}"
WidthRequest="300"
HeightRequest="500"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"/>
<Button Text="{x:Static resource_text:TextResource.CANCEL}" Command="{Binding CancelCommand}"/>
</StackLayout>
</ContentPage.Content>

View File

@ -6,7 +6,15 @@
x:Class="Borepin.Page.ScanURNPage">
<ContentPage.Content>
<StackLayout IsVisible="{Binding IsVisible}">
<zxing:ZXingScannerView Result="{Binding ScanResult, Mode=TwoWay}" ScanResultCommand="{Binding ScannedCommand}" IsScanning="{Binding IsScanning}" WidthRequest="300" HeightRequest="500" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Options="{Binding ScanOptions}"/>
<zxing:ZXingScannerView
Result="{Binding ScanResult, Mode=TwoWay}"
ScanResultCommand="{Binding ScannedCommand}"
IsScanning="{Binding IsScanning}"
Options="{Binding ScanOptions}"
WidthRequest="300"
HeightRequest="500"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"/>
<Button Text="{x:Static resource_text:TextResource.CANCEL}" Command="{Binding CancelCommand}"/>
</StackLayout>
</ContentPage.Content>

View File

@ -10,9 +10,9 @@
<ActivityIndicator IsRunning="{Binding IsBusy}"/>
</StackLayout>
<ActivityIndicator IsRunning="{Binding IsBusy}"/>
<StackLayout IsVisible="{Binding IsConnecting}" VerticalOptions="CenterAndExpand">
<StackLayout IsVisible="{Binding RunConnecting}" VerticalOptions="CenterAndExpand">
<Label Text="{x:Static resource_text:TextResource.StartPage_Connecting}" Style="{StaticResource Style_Label_Text_Center}"/>
<ActivityIndicator IsRunning="{Binding IsConnecting}"/>
<ActivityIndicator IsRunning="{Binding RunConnecting}"/>
</StackLayout>
</StackLayout>
</ContentPage.Content>

View File

@ -5,6 +5,7 @@ using System.Windows.Input;
using Borepin.Base;
using Borepin.Base.Exceptions;
using Borepin.Service;
using Borepin.Service.ErrorMessage;
using Borepin.Service.Storage;
using FabAccessAPI;
using FabAccessAPI.Exceptions;
@ -21,12 +22,14 @@ namespace Borepin.PageModel.AddServerProcess
#region Private Fields
private ConnectionData _ConnectionData;
private readonly ILoginStorageService _LoginStorageService;
private readonly IErrorMessageService _ErrorMessageService;
#endregion
#region Constructors
public AuthPlainPageModel(INavigationService navigationService, IAPIService apiService, IPageDialogService pageDialogService, ILoginStorageService loginStorageService) : base(navigationService, pageDialogService, apiService)
public AuthPlainPageModel(INavigationService navigationService, IAPIService apiService, IPageDialogService pageDialogService, ILoginStorageService loginStorageService, IErrorMessageService errorMessageService) : base(navigationService, pageDialogService, apiService)
{
_LoginStorageService = loginStorageService;
_ErrorMessageService = errorMessageService;
AuthenticateCommand = new DelegateCommand(async () => await AuthenticateCommandExecute().ConfigureAwait(false));
}
@ -113,46 +116,13 @@ namespace Borepin.PageModel.AddServerProcess
{
await _API.Connect(_ConnectionData).ConfigureAwait(false);
}
catch (ConnectionException)
catch (Exception exception)
{
Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_UnableServer, Resources.Text.TextResource.OK).ConfigureAwait(false);
IsBusy = false;
});
_ErrorMessageService.DisplayConnectFailedMessage(exception);
IsBusy = false;
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 () =>
{
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_AuthServer, Resources.Text.TextResource.OK).ConfigureAwait(false);
IsBusy = false;
});
return;
}
catch(Exception ex)
{
Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_UnexpectedError, Resources.Text.TextResource.OK).ConfigureAwait(false);
IsBusy = false;
});
return;
}
await _LoginStorageService.Add(_ConnectionData).ConfigureAwait(false);
await _LoginStorageService.UpdateTimestamp(_ConnectionData).ConfigureAwait(false);

View File

@ -2,10 +2,12 @@
using Prism.Commands;
using Prism.Navigation;
using Prism.Services;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using ZXing;
using ZXing.Mobile;
namespace Borepin.PageModel
{
@ -40,6 +42,23 @@ namespace Borepin.PageModel
#endregion
#region Fields
public MobileBarcodeScanningOptions ScanOptions
{
get
{
return new MobileBarcodeScanningOptions()
{
PossibleFormats = new List<BarcodeFormat>()
{
BarcodeFormat.QR_CODE,
BarcodeFormat.EAN_13,
},
AutoRotate = true,
DelayBetweenContinuousScans = 300,
};
}
}
private Result _ScanResult;
public Result ScanResult
{
@ -73,7 +92,6 @@ namespace Borepin.PageModel
public void ScannedCommandExecute()
{
IsScanning = false;
IsVisible = false;
INavigationParameters parameters = new NavigationParameters()
{
@ -96,7 +114,6 @@ namespace Borepin.PageModel
public async Task CancelCommandExecute()
{
IsScanning = false;
IsVisible = false;
INavigationParameters parameters = new NavigationParameters()
{

View File

@ -34,14 +34,14 @@ namespace Borepin.PageModel
return new MobileBarcodeScanningOptions()
{
PossibleFormats = new List<BarcodeFormat>()
{
{
BarcodeFormat.QR_CODE,
BarcodeFormat.EAN_13,
// TODO add more Barcode Formats if needed
},
AutoRotate = true,
DelayBetweenContinuousScans = 300,
};
}
//set => SetProperty(ref _ScanOptions, value);
}
private Result _ScanResult;
@ -146,7 +146,6 @@ namespace Borepin.PageModel
public async Task CancelCommandExecute()
{
IsScanning = false;
IsVisible = false;
await _NavigationService.GoBackAsync().ConfigureAwait(false);
}

View File

@ -32,11 +32,11 @@ namespace Borepin.PageModel
#endregion
#region Fields
private bool _IsConnecting;
public bool IsConnecting
private bool _RunConnecting;
public bool RunConnecting
{
get => _IsConnecting;
set => SetProperty(ref _IsConnecting, value);
get => _RunConnecting;
set => SetProperty(ref _RunConnecting, value);
}
#endregion
@ -60,7 +60,7 @@ namespace Borepin.PageModel
else if(connectionData_Default != null)
{
IsBusy = false;
IsConnecting = true;
RunConnecting = true;
try
{
await _API.Connect(connectionData_Default).ConfigureAwait(false);

View File

@ -6,6 +6,7 @@ using NLog;
using S22.Sasl;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
@ -336,28 +337,43 @@ namespace FabAccessAPI
return true;
}
/// <summary>
/// Injects SSL as Midlayer in TCPRPCConnection
/// </summary>
/// <exception cref="ConnectionException"></exception>
private Stream InjectSSL(Stream tcpstream)
{
SslStream sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
try
{
sslStream.ReadTimeout = 2000;
sslStream.AuthenticateAsClient("bffhd");
sslStream.ReadTimeout = -1;
return sslStream;
}
catch (System.Security.Authentication.AuthenticationException exception)
{
sslStream.Close();
Log.Warn(exception);
throw new ConnectionException("TLS failed", exception);
}
catch(IOException exception)
{
sslStream.Close();
Log.Warn(exception);
throw new ConnectionException("TLS failed", new Exceptions.TimeoutException("TLS timeout", exception));
}
}
/// <summary>
/// Connect async to a server with ConnectionData
/// </summary>
/// <exception cref="ConnectionException">Based on RPC Exception</exception>
private async Task _ConnectAsync(TcpRpcClient tcprpcClient, ConnectionData connectionData)
{
tcprpcClient.InjectMidlayer((tcpstream) =>
{
var sslStream = new SslStream(tcpstream, false, new RemoteCertificateValidationCallback(_RemoteCertificateValidationCallback));
try
{
sslStream.AuthenticateAsClient("bffhd");
return sslStream;
}
catch (System.Security.Authentication.AuthenticationException exception)
{
sslStream.Close();
Log.Warn(exception);
throw new ConnectionException("TLS failed", exception);
}
});
tcprpcClient.InjectMidlayer(InjectSSL);
try
{
Task timeoutTask = Task.Delay(3000);

@ -1 +1 @@
Subproject commit a70eecd99112b16902128b8b4b2c95b2721fdf0e
Subproject commit 1be9ffbf8acbc9770f2d5b67c961fb60e49e5ec5