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 CreateInstance() + { + return Task.FromResult(null); + } + #endregion #region INavigationAware - public abstract void OnNavigatedTo(INavigationParameters parameters); - public abstract void OnNavigatedFrom(INavigationParameters parameters); + public async void OnNavigatedTo(INavigationParameters parameters) + { + await OnNavigatedToVirtual(parameters).ConfigureAwait(false); + IsBusy = false; + } + public async void OnNavigatedFrom(INavigationParameters parameters) + { + await OnNavigatedFromVirtual(parameters).ConfigureAwait(false); + } + + public virtual async Task OnNavigatedToVirtual(INavigationParameters parameters) + { + if (parameters.ContainsKey("instance")) + { + await LoadInstance(parameters.GetValue("instance")).ConfigureAwait(false); + } + else + { + Log.Trace("No instance"); + await LoadInstance(null).ConfigureAwait(false); + } + + await LoadFromParameters(parameters).ConfigureAwait(false); + } + public virtual async Task OnNavigatedFromVirtual(INavigationParameters parameters) + { + object instance = await CreateInstance().ConfigureAwait(false); + if (instance != null) + { + parameters.Add("instance", instance); + } + } #endregion } } \ No newline at end of file diff --git a/Borepin/Borepin/Borepin.csproj b/Borepin/Borepin/Borepin.csproj index 6f5458e..56d5203 100644 --- a/Borepin/Borepin/Borepin.csproj +++ b/Borepin/Borepin/Borepin.csproj @@ -21,17 +21,23 @@ + + + + + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -47,6 +53,15 @@ SelectServerPage.xaml + + ScanURNPage.xaml + + + UserPage.xaml + + + UserListPage.xaml + MachineListPage.xaml @@ -62,11 +77,6 @@ StartPage.xaml - - True - True - Resources.resx - True True @@ -78,6 +88,9 @@ MachineListItemView.xaml + + UserListItemView.xaml + @@ -119,10 +132,6 @@ MSBuild:UpdateDesignTimeXaml - - ResXFileCodeGenerator - Resources.Designer.cs - ResXFileCodeGenerator TextResource.Designer.cs diff --git a/Borepin/Borepin/Converter/MachineStateColorConverter.cs b/Borepin/Borepin/Converter/MachineStateColorConverter.cs index a587b28..1857137 100644 --- a/Borepin/Borepin/Converter/MachineStateColorConverter.cs +++ b/Borepin/Borepin/Converter/MachineStateColorConverter.cs @@ -1,4 +1,5 @@ -using System; +using FabAccessAPI.Schema; +using System; using System.Globalization; using Xamarin.Forms; @@ -8,9 +9,9 @@ namespace Borepin.Converter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - switch((FabAccessAPI.Schema.Machine.MachineState)value) + switch((Machine.MachineState)value) { - case (FabAccessAPI.Schema.Machine.MachineState.free): + case Machine.MachineState.free: return (Color)Application.Current.Resources["FirstColor"]; default: return (Color)Application.Current.Resources["SixthColor"]; diff --git a/Borepin/Borepin/Converter/MachineStateStringConverter.cs b/Borepin/Borepin/Converter/MachineStateStringConverter.cs index 6ffc35b..89253bd 100644 --- a/Borepin/Borepin/Converter/MachineStateStringConverter.cs +++ b/Borepin/Borepin/Converter/MachineStateStringConverter.cs @@ -1,4 +1,5 @@ -using System; +using FabAccessAPI.Schema; +using System; using System.Globalization; using Xamarin.Forms; @@ -8,20 +9,22 @@ namespace Borepin.Converter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - switch((FabAccessAPI.Schema.Machine.MachineState)value) + switch((Machine.MachineState)value) { - case (FabAccessAPI.Schema.Machine.MachineState.free): + case Machine.MachineState.free: return "Free"; - case (FabAccessAPI.Schema.Machine.MachineState.inUse): + case Machine.MachineState.inUse: return "In Use"; - case (FabAccessAPI.Schema.Machine.MachineState.toCheck): + case Machine.MachineState.toCheck: return "To Check"; - case (FabAccessAPI.Schema.Machine.MachineState.reserved): + case Machine.MachineState.reserved: return "Reserved"; - case (FabAccessAPI.Schema.Machine.MachineState.blocked): + case Machine.MachineState.blocked: return "Blocked"; - case (FabAccessAPI.Schema.Machine.MachineState.disabled): + case Machine.MachineState.disabled: return "Disabled"; + case Machine.MachineState.totakeover: + return "ToTakeOver"; default: return "Unknown"; } diff --git a/Borepin/Borepin/Helpers/TranslateExtension.cs b/Borepin/Borepin/Helpers/TranslateExtension.cs deleted file mode 100644 index 77139d0..0000000 --- a/Borepin/Borepin/Helpers/TranslateExtension.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Plugin.Multilingual; -using System; -using System.Reflection; -using System.Resources; -using Xamarin.Forms; -using Xamarin.Forms.Xaml; - -namespace Borepin.Helpers -{ - [ContentProperty("Text")] - public class TranslateExtension : IMarkupExtension - { - const string _ResourceId = "Borepin.Resources.Text.TextResource"; - - static readonly Lazy _Resmgr = new Lazy(() => new ResourceManager(_ResourceId, typeof(TranslateExtension).GetTypeInfo().Assembly)); - - public string Text { get; set; } - - public object ProvideValue(IServiceProvider serviceProvider) - { - if (Text == null) - { - return ""; - } - - System.Globalization.CultureInfo ci = CrossMultilingual.Current.CurrentCultureInfo; - - string translation = _Resmgr.Value.GetString(Text, ci); - - if (translation == null) - { - -#if DEBUG - //throw new ArgumentException( - // String.Format("Key '{0}' was not found in resources '{1}' for culture '{2}'.", Text, ResourceId, ci.Name), - // "Text"); - translation = "!MISSING TEXT!"; -#else - translation = Text; // returns the key, which GETS DISPLAYED TO THE USER -#endif - } - return translation; - } - } -} diff --git a/Borepin/Borepin/Model/AuthenticationTyp.cs b/Borepin/Borepin/Model/AuthenticationTyp.cs deleted file mode 100644 index 1a0d9f7..0000000 --- a/Borepin/Borepin/Model/AuthenticationTyp.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Borepin.Model -{ - public enum AuthenticationTyp - { - PLAIN, - } -} diff --git a/Borepin/Borepin/Model/BFFHInstance.cs b/Borepin/Borepin/Model/BFFHInstance.cs deleted file mode 100644 index c924f8a..0000000 --- a/Borepin/Borepin/Model/BFFHInstance.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -namespace Borepin.Model -{ - public class BFFHInstance - { - public Uri Address { get; set; } - - public string Name { get; set; } = ""; - - public string Description { get; set; } = ""; - } -} diff --git a/Borepin/Borepin/Model/Connection.cs b/Borepin/Borepin/Model/Connection.cs deleted file mode 100644 index 4d11ae4..0000000 --- a/Borepin/Borepin/Model/Connection.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Borepin.Model -{ - /// - /// Class to contain all Information about a Connection - /// - public class Connection - { - #region Constructors - public Connection() - { - Address = new Uri("http://127.0.0.1:59661"); - } - - public Connection(Connection connection) - { - ConnectionTyp = connection.ConnectionTyp; - AuthenticationTyp = connection.AuthenticationTyp; - Address = connection.Address; - Username = connection.Username; - LastTime = connection.LastTime; - } - #endregion - - #region Members - /// - /// Type of Connection - /// - public ConnectionTyp ConnectionTyp { get; set; } = ConnectionTyp.SINGLE; - - /// - /// Type of Authentication - /// - public AuthenticationTyp AuthenticationTyp { get; set; } = AuthenticationTyp.PLAIN; - - /// - /// Address to Host - /// - public Uri Address { get; set; } - - /// - /// Username for Connection - /// - public string Username { get; set; } = ""; - - /// - /// Last Timestamp connection was successfully established - /// - public DateTime LastTime { get; set; } - #endregion - - #region Methods - #region Equals and HashCode - public override bool Equals(object obj) - { - return obj is Connection connection && - EqualityComparer.Default.Equals(Address, connection.Address) && - string.Equals(Username, connection.Username, StringComparison.Ordinal) && - ConnectionTyp == connection.ConnectionTyp && - AuthenticationTyp == connection.AuthenticationTyp; - } - - public override int GetHashCode() - { - int hashCode = -904541792; - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Address); - hashCode = hashCode * -1521134295 + LastTime.GetHashCode(); - hashCode = hashCode * -1521134295 + StringComparer.Ordinal.GetHashCode(Username); - hashCode = hashCode * -1521134295 + ConnectionTyp.GetHashCode(); - hashCode = hashCode * -1521134295 + AuthenticationTyp.GetHashCode(); - return hashCode; - } - #endregion - #endregion - } -} \ No newline at end of file diff --git a/Borepin/Borepin/Model/ConnectionDataVisualize.cs b/Borepin/Borepin/Model/ConnectionDataVisualize.cs new file mode 100644 index 0000000..2654090 --- /dev/null +++ b/Borepin/Borepin/Model/ConnectionDataVisualize.cs @@ -0,0 +1,53 @@ +using FabAccessAPI; +using Prism.Mvvm; + +namespace Borepin.Model +{ + public class ConnectionDataVisualize : BindableBase + { + #region Private Fields + public readonly ConnectionData _ConnectionData; + #endregion + + #region Constructors + public ConnectionDataVisualize(ConnectionData connectionData) + { + _ConnectionData = connectionData; + + LoadData(); + } + #endregion + + #region Methods + public void LoadData() + { + Host = _ConnectionData.Host.Host; + Port = _ConnectionData.Host.Port; + Username = _ConnectionData.Username; + } + #endregion + + #region Fields + private string _Host; + public string Host + { + get => _Host; + set => SetProperty(ref _Host, value); + } + + private int _Port; + public int Port + { + get => _Port; + set => SetProperty(ref _Port, value); + } + + private string _Username; + public string Username + { + get => _Username; + set => SetProperty(ref _Username, value); + } + #endregion + } +} diff --git a/Borepin/Borepin/Model/ConnectionTyp.cs b/Borepin/Borepin/Model/ConnectionTyp.cs deleted file mode 100644 index 5b5115b..0000000 --- a/Borepin/Borepin/Model/ConnectionTyp.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Borepin.Model -{ - public enum ConnectionTyp - { - SINGLE, - FEDERATED, - } -} diff --git a/Borepin/Borepin/Model/Connection_Plain.cs b/Borepin/Borepin/Model/Connection_Plain.cs deleted file mode 100644 index 4dec051..0000000 --- a/Borepin/Borepin/Model/Connection_Plain.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Borepin.Model -{ - public class Connection_Plain : Connection - { - #region Constructors - public Connection_Plain(Connection connection) : base(connection) - { - - } - #endregion - - #region Members - /// - /// Password for Connection - /// - public string Password { get; set; } = ""; - #endregion - } -} diff --git a/Borepin/Borepin/Model/ListItem.cs b/Borepin/Borepin/Model/ListItem.cs deleted file mode 100644 index 6410fc8..0000000 --- a/Borepin/Borepin/Model/ListItem.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Borepin.Model -{ - public class ListItem - { - public string Value1 { get; set; } - } -} diff --git a/Borepin/Borepin/Model/MachineVisualize.cs b/Borepin/Borepin/Model/MachineVisualize.cs index 0b4442c..2c51d6d 100644 --- a/Borepin/Borepin/Model/MachineVisualize.cs +++ b/Borepin/Borepin/Model/MachineVisualize.cs @@ -73,6 +73,7 @@ namespace Borepin.Model CanCheck = !((CheckInterface_Proxy)_Machine.Check).IsNull; CanManage = !((ManageInterface_Proxy)_Machine.Manage).IsNull; CanAdmin = !((AdminInterface_Proxy)_Machine.Admin).IsNull; + CanNotUseByPermission = State == MachineState.free && CanUse == false; } #endregion @@ -174,6 +175,13 @@ namespace Borepin.Model get => _CanAdmin; set => SetProperty(ref _CanAdmin, value); } + + private bool _CanNotUseByPermission; + public bool CanNotUseByPermission + { + get => _CanNotUseByPermission; + set => SetProperty(ref _CanNotUseByPermission, value); + } #endregion } } diff --git a/Borepin/Borepin/Model/Storage/ConnectionCredentialStorage.cs b/Borepin/Borepin/Model/Storage/ConnectionCredentialStorage.cs deleted file mode 100644 index 9105876..0000000 --- a/Borepin/Borepin/Model/Storage/ConnectionCredentialStorage.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Globalization; -using System.Threading.Tasks; -using Borepin.Service.Storage; -using Borepin.Service.Storage.Exceptions; - -namespace Borepin.Model.Storage -{ - /// - /// Store Credentials for Connection in SecureStorageService - /// - public class ConnectionCredentialStorage - { - #region Private Fields - private readonly ISecretStorageService _SecretStorageService; - #endregion - - #region Constructors - public ConnectionCredentialStorage(ISecretStorageService secretService) - { - _SecretStorageService = secretService; - } - #endregion - - #region Methods - /// - /// Get Password for Connection from SecureStorageService - /// - /// - /// - public async Task GetPassword(Connection connection) - { - if (connection.AuthenticationTyp != AuthenticationTyp.PLAIN) - { - throw new ArgumentException("AuthenticationTyp is not PLAIN", nameof(connection)); - } - - string password = await _SecretStorageService.GetAsync(string.Format(CultureInfo.InvariantCulture, "bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username)).ConfigureAwait(false); - if (password == null) - { - throw new MissingConnectionException(); - } - - return password; - } - - /// - /// Add Password for Connection to SecureStorageService - /// - public async Task AddCredentials(Connection connection, string password) - { - await _SecretStorageService.SetAsync(string.Format(CultureInfo.InvariantCulture, "bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username), password).ConfigureAwait(false); - } - - /// - /// Remove Password for Connection from SecureStorageService - /// - public Task RemoveCredentials(Connection connection) - { - _SecretStorageService.Remove(string.Format(CultureInfo.InvariantCulture, "bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username)); - - return Task.CompletedTask; - } - - /// - /// Remove all Connections from SecureStorage - /// - public Task RemoveAllCredentials() - { - _SecretStorageService.RemoveAll(); - - return Task.CompletedTask; - } - #endregion - } -} diff --git a/Borepin/Borepin/Model/Storage/ConnectionStorage.cs b/Borepin/Borepin/Model/Storage/ConnectionStorage.cs deleted file mode 100644 index 3c8de2c..0000000 --- a/Borepin/Borepin/Model/Storage/ConnectionStorage.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Borepin.Service.Storage; -using Borepin.Service.Storage.Exceptions; -using Newtonsoft.Json; - -namespace Borepin.Model.Storage -{ - /// - /// Store Connection in PreferenceStorageService - /// - public class ConnectionStorage - { - #region Private Fields - private readonly IPreferenceStorageService _PreferenceService; - #endregion - - #region Constructors - public ConnectionStorage(IPreferenceStorageService preferenceService) - { - _PreferenceService = preferenceService; - } - #endregion - - #region Methods - /// - /// Get Connection List from Storage - /// - /// - public Task> GetConnectionList() - { - return Task.FromResult(_LoadConnectionFormStorage()); - } - - /// - /// Add Connection to Storage - /// - /// - public Task AddConnection(Connection connection) - { - IList connection_list = _LoadConnectionFormStorage(); - - if (connection_list.Contains(connection)) - { - throw new DuplicateConnectionException(); - } - - connection_list.Add(connection); - - _SaveConnectionToStorage(connection_list); - - return Task.FromResult(true); - } - - /// - /// Remove Connection from Storage - /// - public Task RemoveConnection(Connection connection) - { - IList connection_list = _LoadConnectionFormStorage(); - - if (!connection_list.Contains(connection)) - { - throw new MissingConnectionException(); - } - - while(connection_list.Contains(connection)) - { - connection_list.Remove(connection); - } - - _SaveConnectionToStorage(connection_list); - - return Task.FromResult(true); - } - - /// - /// Remove All Connection from Storage - /// - public Task RemoveAllConnections() - { - _SaveConnectionToStorage(new List()); - - return Task.FromResult(true); - } - - /// - /// Update Connections Timestamp in Storage - /// - /// - public Task UpdateConnectionTimestamp(Connection connection) - { - IList connection_list = _LoadConnectionFormStorage(); - - if (!connection_list.Contains(connection)) - { - throw new MissingConnectionException(); - } - - int index = connection_list.IndexOf(connection); - Connection connection_update = connection_list[index]; - connection_update.LastTime = DateTime.UtcNow; - connection_list[index] = connection_update; - - _SaveConnectionToStorage(connection_list); - - return Task.FromResult(true); - } - #endregion - - #region Private Methodss - private IList _LoadConnectionFormStorage() - { - List connection_list; - try - { - connection_list = JsonConvert.DeserializeObject>(_PreferenceService.Get("connection_list", "[]")); - } - catch (JsonSerializationException) - { - connection_list = new List(); - _PreferenceService.Set("connection_list", JsonConvert.SerializeObject(connection_list)); - } - - return connection_list; - } - - private void _SaveConnectionToStorage(IList connection_list) - { - _PreferenceService.Set("connection_list", JsonConvert.SerializeObject(connection_list)); - } - #endregion - } -} diff --git a/Borepin/Borepin/Model/Storage/Exceptions/MissingCredentialsException.cs b/Borepin/Borepin/Model/Storage/Exceptions/MissingCredentialsException.cs deleted file mode 100644 index f924028..0000000 --- a/Borepin/Borepin/Model/Storage/Exceptions/MissingCredentialsException.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Borepin.Model.Storage.Exceptions -{ - public class MissingCredentialsException : Exception - { - public MissingCredentialsException() - { - - } - - public MissingCredentialsException(string message) : base(message) - { - - } - - public MissingCredentialsException(string message, Exception inner) : base(message, inner) - { - - } - } -} diff --git a/Borepin/Borepin/MultilingualResources/Borepin.de.xlf b/Borepin/Borepin/MultilingualResources/Borepin.de.xlf deleted file mode 100644 index ee215de..0000000 --- a/Borepin/Borepin/MultilingualResources/Borepin.de.xlf +++ /dev/null @@ -1,40 +0,0 @@ - - - -
- -
- - - -
- -
- -
- - - - Automate your Space with FabAccess - Automate your Space with FabAccess - - - Welcome - Welcome - - - Begin working - Begin working - - - Login to your Space - Login to your Space - - - Wenn du dieses Logo siehst, dann kannst du es scannen - Wenn du dieses Logo siehst, dann kannst du es scannen - - - -
-
\ No newline at end of file diff --git a/Borepin/Borepin/MultilingualResources/Borepin.en.xlf b/Borepin/Borepin/MultilingualResources/Borepin.en.xlf deleted file mode 100644 index ae8fdc1..0000000 --- a/Borepin/Borepin/MultilingualResources/Borepin.en.xlf +++ /dev/null @@ -1,40 +0,0 @@ - - - -
- -
- - - -
- -
- -
- - - - Automate your Space with FabAccess - Automate your Space with FabAccess - - - Welcome - Welcome - - - Begin working - Begin working - - - Login to your Space - Login to your Space - - - Wenn du dieses Logo siehst, dann kannst du es scannen - Wenn du dieses Logo siehst, dann kannst du es scannen - - - -
-
\ No newline at end of file diff --git a/Borepin/Borepin/Page/AddServerProcess/AuthPlainPage.xaml b/Borepin/Borepin/Page/AddServerProcess/AuthPlainPage.xaml index 9c4b58a..010fd30 100644 --- a/Borepin/Borepin/Page/AddServerProcess/AuthPlainPage.xaml +++ b/Borepin/Borepin/Page/AddServerProcess/AuthPlainPage.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Borepin.Page.AddServerProcess.AuthPlainPage" xmlns:converters="clr-namespace:Borepin.Converter" + xmlns:resource_text="clr-namespace:Borepin.Resources.Text" Title="Connect to Server"> @@ -15,13 +16,13 @@ - + - + - + diff --git a/Borepin/Borepin/Page/MachineListPage.xaml b/Borepin/Borepin/Page/MachineListPage.xaml index a7842a8..b16e169 100644 --- a/Borepin/Borepin/Page/MachineListPage.xaml +++ b/Borepin/Borepin/Page/MachineListPage.xaml @@ -4,6 +4,7 @@ xmlns:views="clr-namespace:Borepin.View" x:Class="Borepin.Page.MachineListPage" xmlns:converters="clr-namespace:Borepin.Converter" + xmlns:resource_text="clr-namespace:Borepin.Resources.Text" Title="Machines">