diff --git a/.editorconfig b/.editorconfig
index 55aff3e..29e791c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -3,3 +3,6 @@
# MA0003: Add argument name to improve readability
dotnet_diagnostic.MA0003.severity = none
csharp_style_prefer_switch_expression=false:suggestion
+
+# MA0051: Method is too long
+dotnet_diagnostic.MA0051.severity = silent
diff --git a/.gitmodules b/.gitmodules
index 648ccf2..9033f1b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,5 +16,5 @@
[submodule "external/capnproto-dotnetcore"]
path = external/capnproto-dotnetcore
url = https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
- branch = main
+ branch = master
ignore = all
diff --git a/Borepin/Borepin.Android/Borepin.Android.csproj b/Borepin/Borepin.Android/Borepin.Android.csproj
index 5902707..6f628be 100644
--- a/Borepin/Borepin.Android/Borepin.Android.csproj
+++ b/Borepin/Borepin.Android/Borepin.Android.csproj
@@ -68,7 +68,7 @@
8.1.97
-
+
@@ -76,6 +76,11 @@
+
+
+
+
+
@@ -87,6 +92,10 @@
+
+ {3251FCE9-FEA3-4662-8BEB-636BE6732D48}
+ FabAccessAPI
+
{F93856BD-0C8D-4469-A8DB-6E513002BFD7}
Borepin
diff --git a/Borepin/Borepin.Android/PlatformInitializer.cs b/Borepin/Borepin.Android/PlatformInitializer.cs
index 7d8bdc6..ac5fbc0 100644
--- a/Borepin/Borepin.Android/PlatformInitializer.cs
+++ b/Borepin/Borepin.Android/PlatformInitializer.cs
@@ -1,4 +1,5 @@
using Borepin.Droid.Services;
+using Borepin.Service;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
using Prism;
@@ -13,6 +14,8 @@ namespace Borepin.Droid
containerRegistry.Register();
containerRegistry.Register();
containerRegistry.Register();
+
+ containerRegistry.RegisterSingleton();
}
}
}
\ No newline at end of file
diff --git a/Borepin/Borepin.Android/Services/APIBindedService.cs b/Borepin/Borepin.Android/Services/APIBindedService.cs
new file mode 100644
index 0000000..e84859c
--- /dev/null
+++ b/Borepin/Borepin.Android/Services/APIBindedService.cs
@@ -0,0 +1,50 @@
+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
+ }
+}
\ No newline at end of file
diff --git a/Borepin/Borepin.Android/Services/APIBinder.cs b/Borepin/Borepin.Android/Services/APIBinder.cs
new file mode 100644
index 0000000..5deeb3b
--- /dev/null
+++ b/Borepin/Borepin.Android/Services/APIBinder.cs
@@ -0,0 +1,18 @@
+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
+ }
+}
\ No newline at end of file
diff --git a/Borepin/Borepin.Android/Services/APIService.cs b/Borepin/Borepin.Android/Services/APIService.cs
new file mode 100644
index 0000000..cee9bb1
--- /dev/null
+++ b/Borepin/Borepin.Android/Services/APIService.cs
@@ -0,0 +1,23 @@
+using Borepin.Service;
+using FabAccessAPI;
+
+namespace Borepin.Droid.Services
+{
+ public class APIService : IAPIService
+ {
+ #region Private Members
+ private readonly IAPI _API;
+ #endregion
+
+ #region Constructors
+ public APIService()
+ {
+ _API = new API();
+ }
+ #endregion
+ public IAPI GetAPI()
+ {
+ return _API;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Borepin/Borepin.Android/Services/APIServiceConnection.cs b/Borepin/Borepin.Android/Services/APIServiceConnection.cs
new file mode 100644
index 0000000..319d008
--- /dev/null
+++ b/Borepin/Borepin.Android/Services/APIServiceConnection.cs
@@ -0,0 +1,32 @@
+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
+ }
+}
\ No newline at end of file
diff --git a/Borepin/Borepin.Android/Services/APIService_New.cs b/Borepin/Borepin.Android/Services/APIService_New.cs
new file mode 100644
index 0000000..1defae9
--- /dev/null
+++ b/Borepin/Borepin.Android/Services/APIService_New.cs
@@ -0,0 +1,28 @@
+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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Borepin/Borepin.GTK/Borepin.GTK.csproj b/Borepin/Borepin.GTK/Borepin.GTK.csproj
index 88376b3..1d5964f 100644
--- a/Borepin/Borepin.GTK/Borepin.GTK.csproj
+++ b/Borepin/Borepin.GTK/Borepin.GTK.csproj
@@ -42,8 +42,8 @@
False
..\..\..\..\..\..\..\Program Files (x86)\GtkSharp\2.12\lib\gtk-sharp-2.0\atk-sharp.dll
-
- ..\..\packages\DryIoc.dll.5.0.0\lib\net45\DryIoc.dll
+
+ ..\..\packages\DryIoc.dll.5.0.2\lib\net45\DryIoc.dll
False
diff --git a/Borepin/Borepin.GTK/app.config b/Borepin/Borepin.GTK/app.config
index 6d5260f..66373bc 100644
--- a/Borepin/Borepin.GTK/app.config
+++ b/Borepin/Borepin.GTK/app.config
@@ -12,7 +12,7 @@
-
+
diff --git a/Borepin/Borepin.GTK/packages.config b/Borepin/Borepin.GTK/packages.config
index dc56bb3..fa48c82 100644
--- a/Borepin/Borepin.GTK/packages.config
+++ b/Borepin/Borepin.GTK/packages.config
@@ -1,6 +1,6 @@
-
+
diff --git a/Borepin/Borepin.UWP/Borepin.UWP.csproj b/Borepin/Borepin.UWP/Borepin.UWP.csproj
index b554349..620bb6d 100644
--- a/Borepin/Borepin.UWP/Borepin.UWP.csproj
+++ b/Borepin/Borepin.UWP/Borepin.UWP.csproj
@@ -98,6 +98,7 @@
+
@@ -181,9 +182,17 @@
-
+
+
+ {c587aac3-50a7-4871-a50d-7880b6f24ef6}
+ Capnp.Net.Runtime
+
+
+ {3251FCE9-FEA3-4662-8BEB-636BE6732D48}
+ FabAccessAPI
+
{64ED6CAA-99A0-4EC4-B976-DCBD571F05D7}
Borepin
diff --git a/Borepin/Borepin.UWP/PlatformInitializer.cs b/Borepin/Borepin.UWP/PlatformInitializer.cs
index 08027a6..9eacb3c 100644
--- a/Borepin/Borepin.UWP/PlatformInitializer.cs
+++ b/Borepin/Borepin.UWP/PlatformInitializer.cs
@@ -3,6 +3,7 @@ using Prism;
using Prism.Ioc;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
+using Borepin.Service;
namespace Borepin.UWP
{
@@ -13,6 +14,8 @@ namespace Borepin.UWP
containerRegistry.Register();
containerRegistry.Register();
containerRegistry.Register();
+
+ containerRegistry.RegisterSingleton();
}
}
}
diff --git a/Borepin/Borepin.UWP/Services/APIService.cs b/Borepin/Borepin.UWP/Services/APIService.cs
new file mode 100644
index 0000000..f985225
--- /dev/null
+++ b/Borepin/Borepin.UWP/Services/APIService.cs
@@ -0,0 +1,23 @@
+using Borepin.Service;
+using FabAccessAPI;
+
+namespace Borepin.UWP.Services
+{
+ public class APIService : IAPIService
+ {
+ #region Private Members
+ private readonly IAPI _API;
+ #endregion
+
+ #region Constructors
+ public APIService()
+ {
+ _API = new API();
+ }
+ #endregion
+ public IAPI GetAPI()
+ {
+ return _API;
+ }
+ }
+}
diff --git a/Borepin/Borepin.iOS/Borepin.iOS.csproj b/Borepin/Borepin.iOS/Borepin.iOS.csproj
index 4f1a820..5a52689 100644
--- a/Borepin/Borepin.iOS/Borepin.iOS.csproj
+++ b/Borepin/Borepin.iOS/Borepin.iOS.csproj
@@ -81,6 +81,7 @@
+
@@ -185,13 +186,17 @@
8.1.97
-
+
5.0.0.2401
+
+ {3251FCE9-FEA3-4662-8BEB-636BE6732D48}
+ FabAccessAPI
+
{F93856BD-0C8D-4469-A8DB-6E513002BFD7}
Borepin
diff --git a/Borepin/Borepin.iOS/PlatformInitializer.cs b/Borepin/Borepin.iOS/PlatformInitializer.cs
index ff22291..26a09b8 100644
--- a/Borepin/Borepin.iOS/PlatformInitializer.cs
+++ b/Borepin/Borepin.iOS/PlatformInitializer.cs
@@ -1,4 +1,5 @@
using Borepin.iOS.Services;
+using Borepin.Service;
using Borepin.Service.Storage;
using Borepin.Service.Versioning;
using Prism;
@@ -13,6 +14,8 @@ namespace Borepin.iOS
containerRegistry.Register();
containerRegistry.Register();
containerRegistry.Register();
+
+ containerRegistry.RegisterSingleton();
}
}
}
\ No newline at end of file
diff --git a/Borepin/Borepin.iOS/Services/APIService.cs b/Borepin/Borepin.iOS/Services/APIService.cs
new file mode 100644
index 0000000..f311dab
--- /dev/null
+++ b/Borepin/Borepin.iOS/Services/APIService.cs
@@ -0,0 +1,23 @@
+using Borepin.Service;
+using FabAccessAPI;
+
+namespace Borepin.iOS.Services
+{
+ public class APIService : IAPIService
+ {
+ #region Private Members
+ private readonly IAPI _API;
+ #endregion
+
+ #region Constructors
+ public APIService()
+ {
+ _API = new API();
+ }
+ #endregion
+ public IAPI GetAPI()
+ {
+ return _API;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Borepin/Borepin.macOS/Borepin.macOS.csproj b/Borepin/Borepin.macOS/Borepin.macOS.csproj
index ea2c31f..9130cc0 100644
--- a/Borepin/Borepin.macOS/Borepin.macOS.csproj
+++ b/Borepin/Borepin.macOS/Borepin.macOS.csproj
@@ -59,8 +59,8 @@
-
- ..\..\packages\DryIoc.dll.5.0.0\lib\netstandard2.1\DryIoc.dll
+
+ ..\..\packages\DryIoc.dll.5.0.2\lib\netstandard2.1\DryIoc.dll
..\..\packages\Prism.Core.8.1.97\lib\netstandard2.0\Prism.dll
diff --git a/Borepin/Borepin.macOS/app.config b/Borepin/Borepin.macOS/app.config
index 9218e1a..5cf16ce 100644
--- a/Borepin/Borepin.macOS/app.config
+++ b/Borepin/Borepin.macOS/app.config
@@ -8,7 +8,7 @@
-
+
diff --git a/Borepin/Borepin.macOS/packages.config b/Borepin/Borepin.macOS/packages.config
index 869649c..fdabcd9 100644
--- a/Borepin/Borepin.macOS/packages.config
+++ b/Borepin/Borepin.macOS/packages.config
@@ -1,6 +1,6 @@
-
+
diff --git a/Borepin/Borepin/App.xaml.cs b/Borepin/Borepin/App.xaml.cs
index 177c56b..3a6e172 100644
--- a/Borepin/Borepin/App.xaml.cs
+++ b/Borepin/Borepin/App.xaml.cs
@@ -4,14 +4,14 @@ using Borepin.Page;
using Xamarin.Forms;
using Borepin.Dialog;
using Borepin.DialogModel;
-using Borepin.Service.BFFH;
using Prism;
using Borepin.Page.SetUpProcess;
using Borepin.PageModel.SetUpProcess;
using Borepin.Page.AddServerProcess;
using Borepin.PageModel.AddServerProcess;
using System;
-using Prism.Navigation;
+using Borepin.Service.Storage;
+using NLog;
namespace Borepin
{
@@ -19,18 +19,16 @@ namespace Borepin
{
public App(IPlatformInitializer platformInitializer) : base(platformInitializer)
{
-
+ var config = new NLog.Config.LoggingConfiguration();
+ var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
+ config.AddRule(LogLevel.Trace, LogLevel.Fatal, logconsole);
+ LogManager.Configuration = config;
}
protected override async void OnInitialized()
{
InitializeComponent();
- INavigationParameters parameters = new NavigationParameters()
- {
- { "instance", 0 },
- };
-
await NavigationService.NavigateAsync(new Uri("https://borepin.fab-access.org/StartPage")).ConfigureAwait(false);
}
@@ -47,8 +45,8 @@ namespace Borepin
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
- containerRegistry.RegisterForNavigation("ScanPage");
- containerRegistry.RegisterForNavigation("ScanURNPage");
+ containerRegistry.RegisterForNavigation();
+ containerRegistry.RegisterForNavigation();
#endregion
#region Register Sequence Navigation
@@ -65,7 +63,13 @@ namespace Borepin
#endregion
#region Register Service
- containerRegistry.RegisterSingleton();
+ containerRegistry.RegisterSingleton();
+
+ // NEED PLATFORM SPECIFIC SERVICE
+ // IPreferenceStorageService
+ // ISecretStorageService
+ // IVersioningService
+ // IAPIService
#endregion
}
}
diff --git a/Borepin/Borepin/Base/ConnectionModelBase.cs b/Borepin/Borepin/Base/ConnectionModelBase.cs
index e999e7d..685f478 100644
--- a/Borepin/Borepin/Base/ConnectionModelBase.cs
+++ b/Borepin/Borepin/Base/ConnectionModelBase.cs
@@ -1,9 +1,8 @@
-using Borepin.Service.BFFH;
-using Borepin.Service.BFFH.Exceptions;
+using Borepin.Service;
+using FabAccessAPI;
using Prism.Navigation;
using Prism.Services;
using System.Threading.Tasks;
-using Xamarin.Forms;
namespace Borepin.Base
{
@@ -13,15 +12,74 @@ namespace Borepin.Base
public abstract class ConnectionModelBase : PageModelBase
{
#region Private Fields
- protected readonly IPageDialogService _PageDialogService;
- protected readonly IBFFHService _BFFHService;
+ protected readonly IAPI _API;
#endregion
#region Constructors
- protected ConnectionModelBase(INavigationService navigationService, IPageDialogService pageDialogService, IBFFHService bFFHService) : base(navigationService)
+ protected ConnectionModelBase(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService)
{
- _PageDialogService = pageDialogService;
- _BFFHService = bFFHService;
+ _API = apiService.GetAPI();
+ _API.ConnectionStatusChanged += OnConnectionStatusChanged;
+
+ IsConnected = _API.IsConnected;
+ }
+ #endregion
+
+ #region Methods
+ public async void OnConnectionStatusChanged(object sender, ConnectionStatusChange args)
+ {
+ switch(args)
+ {
+ case ConnectionStatusChange.Connected:
+ IsConnected = true;
+ try
+ {
+ await LoadAPIData().ConfigureAwait(false);
+ }
+ catch
+ {
+ IsConnected = false;
+ await _API.Disconnect().ConfigureAwait(false);
+ _API.UnbindAllEvents();
+ }
+ 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:
+ IsConnected = false;
+ break;
+ }
+ }
+
+ public virtual Task LoadAPIData()
+ {
+ return Task.CompletedTask;
+ }
+ public virtual Task ReloadAPIData()
+ {
+ return Task.CompletedTask;
}
#endregion
@@ -37,36 +95,23 @@ namespace Borepin.Base
}
#endregion
- #region Methods
- ///
- /// Checks connection to Server.
- /// Display message if Connection is lost.
- ///
- /// True if connection is ok.
- public async Task CheckConnection()
+ #region INavigationAware
+ public override async Task OnNavigatedToVirtual(INavigationParameters parameters)
{
- try
- {
- if(_BFFHService.CurrentConnection != null && !_BFFHService.IsConnected)
- {
- await _BFFHService.Reconnect().ConfigureAwait(false);
- }
- else if(_BFFHService.CurrentConnection == null)
- {
- return false;
- }
+ await base.OnNavigatedToVirtual(parameters).ConfigureAwait(false);
- return true;
- }
- catch (ReconnectingFailedException)
+ if(_API.IsConnected)
{
- Device.BeginInvokeOnMainThread(async () =>
+ try
{
- await _PageDialogService.DisplayAlertAsync("Connection failed", "Lost connection to server.", "Ok").ConfigureAwait(false);
- });
-
- IsConnected = false;
- return false;
+ await LoadAPIData().ConfigureAwait(false);
+ }
+ catch
+ {
+ IsConnected = false;
+ await _API.Disconnect().ConfigureAwait(false);
+ _API.UnbindAllEvents();
+ }
}
}
#endregion
diff --git a/Borepin/Borepin/Base/Exceptions/InstanceIncorrectException.cs b/Borepin/Borepin/Base/Exceptions/InstanceIncorrectException.cs
new file mode 100644
index 0000000..632b89e
--- /dev/null
+++ b/Borepin/Borepin/Base/Exceptions/InstanceIncorrectException.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace Borepin.Base.Exceptions
+{
+ public class InstanceIncorrectException : Exception
+ {
+ public InstanceIncorrectException()
+ {
+
+ }
+
+ public InstanceIncorrectException(string message) : base(message)
+ {
+
+ }
+
+ public InstanceIncorrectException(string message, Exception inner) : base(message, inner)
+ {
+
+ }
+ }
+}
diff --git a/Borepin/Borepin/Base/PageModelBase.cs b/Borepin/Borepin/Base/PageModelBase.cs
index 8e51506..fa85739 100644
--- a/Borepin/Borepin/Base/PageModelBase.cs
+++ b/Borepin/Borepin/Base/PageModelBase.cs
@@ -1,5 +1,7 @@
-using Prism.Mvvm;
+using NLog;
+using Prism.Mvvm;
using Prism.Navigation;
+using Prism.Services;
using System.Threading.Tasks;
namespace Borepin.Base
@@ -9,12 +11,18 @@ namespace Borepin.Base
///
public abstract class PageModelBase : BindableBase, INavigationAware
{
+ #region Logger
+ protected static readonly Logger Log = LogManager.GetCurrentClassLogger();
+ #endregion
+
#region Private Fields
protected readonly INavigationService _NavigationService;
+ protected readonly IPageDialogService _PageDialogService;
- protected PageModelBase(INavigationService navigationService)
+ protected PageModelBase(INavigationService navigationService, IPageDialogService pageDialogService)
{
_NavigationService = navigationService;
+ _PageDialogService = pageDialogService;
}
#endregion
@@ -30,17 +38,57 @@ namespace Borepin.Base
}
#endregion
- #region Data
- ///
- /// Load Data async
- ///
- ///
- public abstract Task LoadData();
+ #region Mehtods
+ public virtual Task LoadInstance(object instance)
+ {
+ return Task.CompletedTask;
+ }
+
+ public virtual Task LoadFromParameters(INavigationParameters parameters)
+ {
+ return Task.CompletedTask;
+ }
+
+ public virtual Task