mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
Added: IPlatformInitializer
This commit is contained in:
parent
effc059fa7
commit
5e0dd63bf9
@ -62,8 +62,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="MainApplication.cs" />
|
||||
<Compile Include="PlatformInitializer.cs" />
|
||||
<Compile Include="Resources\Resource.designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\PreferenceService.cs" />
|
||||
<Compile Include="Services\SecretService.cs" />
|
||||
<Compile Include="SplashActivity.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -16,7 +16,7 @@ namespace Borepin.Droid
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
||||
LoadApplication(new App());
|
||||
LoadApplication(new App(new PlatformInitializer()));
|
||||
}
|
||||
}
|
||||
}
|
16
Borepin/Borepin.Android/PlatformInitializer.cs
Normal file
16
Borepin/Borepin.Android/PlatformInitializer.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Borepin.Droid.Services;
|
||||
using Borepin.Service;
|
||||
using Prism;
|
||||
using Prism.Ioc;
|
||||
|
||||
namespace Borepin.Droid
|
||||
{
|
||||
public class PlatformInitializer : IPlatformInitializer
|
||||
{
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.Register<IPreferenceService, PreferenceService>();
|
||||
containerRegistry.Register<ISecretService, SecretService>();
|
||||
}
|
||||
}
|
||||
}
|
1900
Borepin/Borepin.Android/Resources/Resource.designer.cs
generated
1900
Borepin/Borepin.Android/Resources/Resource.designer.cs
generated
File diff suppressed because it is too large
Load Diff
33
Borepin/Borepin.Android/Services/PreferenceService.cs
Normal file
33
Borepin/Borepin.Android/Services/PreferenceService.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Borepin.Service;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.Droid.Services
|
||||
{
|
||||
public class PreferenceService : IPreferenceService
|
||||
{
|
||||
public void Clear()
|
||||
{
|
||||
Preferences.Clear();
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return Preferences.ContainsKey(key);
|
||||
}
|
||||
|
||||
public string Get(string key, string defaultValue)
|
||||
{
|
||||
return Preferences.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
{
|
||||
Preferences.Remove(key);
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
Preferences.Set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
29
Borepin/Borepin.Android/Services/SecretService.cs
Normal file
29
Borepin/Borepin.Android/Services/SecretService.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Borepin.Service;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.Droid.Services
|
||||
{
|
||||
public class SecretService : ISecretService
|
||||
{
|
||||
public Task<string> GetAsync(string key)
|
||||
{
|
||||
return SecureStorage.GetAsync(key);
|
||||
}
|
||||
|
||||
public bool Remove(string key)
|
||||
{
|
||||
return SecureStorage.Remove(key);
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
SecureStorage.RemoveAll();
|
||||
}
|
||||
|
||||
public Task SetAsync(string key, string value)
|
||||
{
|
||||
return SecureStorage.SetAsync(key, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -106,6 +106,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PlatformInitializer.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
13
Borepin/Borepin.GTK/PlatformInitializer.cs
Normal file
13
Borepin/Borepin.GTK/PlatformInitializer.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Prism;
|
||||
using Prism.Ioc;
|
||||
|
||||
namespace Borepin.GTK
|
||||
{
|
||||
public class PlatformInitializer : IPlatformInitializer
|
||||
{
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
using Borepin;
|
||||
using System;
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.GTK;
|
||||
|
||||
namespace GameOfLife.GTK
|
||||
namespace Borepin.GTK
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
@ -13,10 +12,9 @@ namespace GameOfLife.GTK
|
||||
Gtk.Application.Init();
|
||||
Forms.Init();
|
||||
|
||||
var app = new App();
|
||||
var window = new FormsWindow();
|
||||
window.LoadApplication(app);
|
||||
window.SetApplicationTitle("Game of Life");
|
||||
window.LoadApplication(new App(new PlatformInitializer()));
|
||||
window.SetApplicationTitle("FabAccess");
|
||||
window.Show();
|
||||
|
||||
Gtk.Application.Run();
|
||||
|
@ -95,7 +95,10 @@
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="PlatformInitializer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\PreferenceService.cs" />
|
||||
<Compile Include="Services\SecretService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
|
@ -6,7 +6,7 @@
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
LoadApplication(new Borepin.App());
|
||||
LoadApplication(new Borepin.App(new PlatformInitializer()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
Borepin/Borepin.UWP/PlatformInitializer.cs
Normal file
16
Borepin/Borepin.UWP/PlatformInitializer.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Borepin.UWP.Services;
|
||||
using Borepin.Service;
|
||||
using Prism;
|
||||
using Prism.Ioc;
|
||||
|
||||
namespace Borepin.UWP
|
||||
{
|
||||
public class PlatformInitializer : IPlatformInitializer
|
||||
{
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.Register<IPreferenceService, PreferenceService>();
|
||||
containerRegistry.Register<ISecretService, SecretService>();
|
||||
}
|
||||
}
|
||||
}
|
33
Borepin/Borepin.UWP/Services/PreferenceService.cs
Normal file
33
Borepin/Borepin.UWP/Services/PreferenceService.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Borepin.Service;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.UWP.Services
|
||||
{
|
||||
public class PreferenceService : IPreferenceService
|
||||
{
|
||||
public void Clear()
|
||||
{
|
||||
Preferences.Clear();
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return Preferences.ContainsKey(key);
|
||||
}
|
||||
|
||||
public string Get(string key, string defaultValue)
|
||||
{
|
||||
return Preferences.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
{
|
||||
Preferences.Remove(key);
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
Preferences.Set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
29
Borepin/Borepin.UWP/Services/SecretService.cs
Normal file
29
Borepin/Borepin.UWP/Services/SecretService.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Borepin.Service;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.UWP.Services
|
||||
{
|
||||
public class SecretService : ISecretService
|
||||
{
|
||||
public Task<string> GetAsync(string key)
|
||||
{
|
||||
return SecureStorage.GetAsync(key);
|
||||
}
|
||||
|
||||
public bool Remove(string key)
|
||||
{
|
||||
return SecureStorage.Remove(key);
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
SecureStorage.RemoveAll();
|
||||
}
|
||||
|
||||
public Task SetAsync(string key, string value)
|
||||
{
|
||||
return SecureStorage.SetAsync(key, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
|
||||
using Foundation;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace Borepin.iOS
|
||||
@ -20,7 +19,7 @@ namespace Borepin.iOS
|
||||
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
|
||||
{
|
||||
global::Xamarin.Forms.Forms.Init();
|
||||
LoadApplication(new App());
|
||||
LoadApplication(new App(new PlatformInitializer()));
|
||||
|
||||
return base.FinishedLaunching(app, options);
|
||||
}
|
||||
|
@ -74,8 +74,11 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="Services\PreferenceService.cs" />
|
||||
<Compile Include="Services\SecretService.cs" />
|
||||
<None Include="Entitlements.plist" />
|
||||
<None Include="Info.plist" />
|
||||
<Compile Include="PlatformInitializer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="CNFC\Card.cs" />
|
||||
<Compile Include="CNFC\Hardware.cs" />
|
||||
|
16
Borepin/Borepin.iOS/PlatformInitializer.cs
Normal file
16
Borepin/Borepin.iOS/PlatformInitializer.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Borepin.iOS.Services;
|
||||
using Borepin.Service;
|
||||
using Prism;
|
||||
using Prism.Ioc;
|
||||
|
||||
namespace Borepin.iOS
|
||||
{
|
||||
public class PlatformInitializer : IPlatformInitializer
|
||||
{
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.Register<IPreferenceService, PreferenceService>();
|
||||
containerRegistry.Register<ISecretService, SecretService>();
|
||||
}
|
||||
}
|
||||
}
|
33
Borepin/Borepin.iOS/Services/PreferenceService.cs
Normal file
33
Borepin/Borepin.iOS/Services/PreferenceService.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Borepin.Service;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.iOS.Services
|
||||
{
|
||||
public class PreferenceService : IPreferenceService
|
||||
{
|
||||
public void Clear()
|
||||
{
|
||||
Preferences.Clear();
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return Preferences.ContainsKey(key);
|
||||
}
|
||||
|
||||
public string Get(string key, string defaultValue)
|
||||
{
|
||||
return Preferences.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
{
|
||||
Preferences.Remove(key);
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
Preferences.Set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
29
Borepin/Borepin.iOS/Services/SecretService.cs
Normal file
29
Borepin/Borepin.iOS/Services/SecretService.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Borepin.Service;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.iOS.Services
|
||||
{
|
||||
public class SecretService : ISecretService
|
||||
{
|
||||
public Task<string> GetAsync(string key)
|
||||
{
|
||||
return SecureStorage.GetAsync(key);
|
||||
}
|
||||
|
||||
public bool Remove(string key)
|
||||
{
|
||||
return SecureStorage.Remove(key);
|
||||
}
|
||||
|
||||
public void RemoveAll()
|
||||
{
|
||||
SecureStorage.RemoveAll();
|
||||
}
|
||||
|
||||
public Task SetAsync(string key, string value)
|
||||
{
|
||||
return SecureStorage.SetAsync(key, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,15 +8,17 @@ namespace Borepin.macOS
|
||||
[Register("AppDelegate")]
|
||||
public class AppDelegate : FormsApplicationDelegate
|
||||
{
|
||||
NSWindow window;
|
||||
readonly NSWindow window;
|
||||
public AppDelegate()
|
||||
{
|
||||
var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;
|
||||
|
||||
var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
|
||||
window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
|
||||
window.Title = "Xamarin.Forms on Mac!"; // choose your own Title here
|
||||
window.TitleVisibility = NSWindowTitleVisibility.Hidden;
|
||||
window = new NSWindow(rect, style, NSBackingStore.Buffered, false)
|
||||
{
|
||||
Title = "Xamarin.Forms on Mac!", // choose your own Title here
|
||||
TitleVisibility = NSWindowTitleVisibility.Hidden
|
||||
};
|
||||
}
|
||||
|
||||
public override NSWindow MainWindow
|
||||
@ -27,7 +29,7 @@ namespace Borepin.macOS
|
||||
public override void DidFinishLaunching(NSNotification notification)
|
||||
{
|
||||
Forms.Init();
|
||||
LoadApplication(new App());
|
||||
LoadApplication(new App(new PlatformInitializer()));
|
||||
base.DidFinishLaunching(notification);
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="PlatformInitializer.cs" />
|
||||
<Compile Include="ViewController.cs" />
|
||||
<Compile Include="ViewController.designer.cs">
|
||||
<DependentUpon>ViewController.cs</DependentUpon>
|
||||
|
13
Borepin/Borepin.macOS/PlatformInitializer.cs
Normal file
13
Borepin/Borepin.macOS/PlatformInitializer.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Prism;
|
||||
using Prism.Ioc;
|
||||
|
||||
namespace Borepin.macOS
|
||||
{
|
||||
public class PlatformInitializer : IPlatformInitializer
|
||||
{
|
||||
public void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -9,17 +9,13 @@ using Borepin.Service.BFFH;
|
||||
using Borepin.Service.Credentials;
|
||||
using System.Collections.Generic;
|
||||
using Borepin.Model;
|
||||
using Prism;
|
||||
|
||||
namespace Borepin
|
||||
{
|
||||
public partial class App
|
||||
{
|
||||
private IConnectionService _ConnectionService;
|
||||
private ICredentialService _CredentialService;
|
||||
private IBFFHService _BFFHService;
|
||||
|
||||
|
||||
public App()
|
||||
public App(IPlatformInitializer platformInitializer) : base(platformInitializer)
|
||||
{
|
||||
|
||||
}
|
||||
@ -28,18 +24,7 @@ namespace Borepin
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Prism.Navigation.INavigationResult result;
|
||||
List<Connection> connection_list = await _ConnectionService.GetConnectionList();
|
||||
if (connection_list.Count == 0)
|
||||
{
|
||||
result = await NavigationService.NavigateAsync("/NavigationPage/HostSelectPage");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage");
|
||||
}
|
||||
|
||||
//result = await NavigationService.NavigateAsync("/NavigationPage/TestPage");
|
||||
Prism.Navigation.INavigationResult result = await NavigationService.NavigateAsync("/MainPage/NavigationPage/TestPage");
|
||||
if (!result.Success)
|
||||
{
|
||||
System.Diagnostics.Debugger.Break();
|
||||
@ -66,13 +51,9 @@ namespace Borepin
|
||||
containerRegistry.RegisterDialog<ConfirmDialog, ConfirmDialogModel>();
|
||||
|
||||
// Register Service
|
||||
_ConnectionService = new ConnectionService();
|
||||
_CredentialService = new CredentialService();
|
||||
_BFFHService = new BFFHService(_CredentialService);
|
||||
|
||||
containerRegistry.RegisterInstance<IConnectionService>(_ConnectionService);
|
||||
containerRegistry.RegisterInstance<ICredentialService>(_CredentialService);
|
||||
containerRegistry.RegisterInstance<IBFFHService>(_BFFHService);
|
||||
containerRegistry.Register<IConnectionService, ConnectionService>();
|
||||
containerRegistry.Register<ICredentialService, CredentialService>();
|
||||
containerRegistry.RegisterSingleton<IBFFHService, BFFHService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,7 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Prism.DryIoc.Forms" Version="7.2.0.1422" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.7.0.1351" />
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
|
||||
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
|
||||
<PackageReference Include="Xamarin.Forms.EntryAutoComplete" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Page\MachineListPage.xaml.cs">
|
||||
@ -82,6 +80,9 @@
|
||||
<EmbeddedResource Update="Page\SettingsPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Page\SetUpProcess\WelcomePage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Page\TestPage.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
|
12
Borepin/Borepin/Page/SetUpProcess/WelcomePage.xaml
Normal file
12
Borepin/Borepin/Page/SetUpProcess/WelcomePage.xaml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Borepin.Page.SetUpProcess.WelcomePage">
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<Label Text="Welcome to Xamarin.Forms!"
|
||||
VerticalOptions="CenterAndExpand"
|
||||
HorizontalOptions="CenterAndExpand" />
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
20
Borepin/Borepin/Page/SetUpProcess/WelcomePage.xaml.cs
Normal file
20
Borepin/Borepin/Page/SetUpProcess/WelcomePage.xaml.cs
Normal file
@ -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.Page.SetUpProcess
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class WelcomePage : ContentPage
|
||||
{
|
||||
public WelcomePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -84,7 +84,7 @@ namespace Borepin.PageModel
|
||||
private void DetectHostCommandExecuted()
|
||||
{
|
||||
// Use Demo Host
|
||||
Host = "192.168.178.20:59661";
|
||||
Host = "127.0.0.1:59661";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,10 @@ namespace Borepin.PageModel
|
||||
|
||||
CanUse = MachineItem.MInfo.State == FabAccessAPI.Schema.State.free;
|
||||
|
||||
if (GiveBack == null)
|
||||
{
|
||||
GiveBack = await MachineItem.Instance.GetGiveBack();
|
||||
}
|
||||
//if (GiveBack == null)
|
||||
//{
|
||||
// GiveBack = await MachineItem.Instance.GetGiveBack();
|
||||
//}
|
||||
|
||||
CanGiveBack = GiveBack != null;
|
||||
|
||||
|
@ -3,20 +3,28 @@ using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.Service.Connections
|
||||
{
|
||||
public class ConnectionService : IConnectionService
|
||||
{
|
||||
#region Private Properties
|
||||
private readonly IPreferenceService _PreferenceService;
|
||||
#endregion
|
||||
|
||||
public ConnectionService(IPreferenceService preferenceService)
|
||||
{
|
||||
_PreferenceService = preferenceService;
|
||||
}
|
||||
|
||||
public Task<List<Connection>> GetConnectionList()
|
||||
{
|
||||
return Task.FromResult(JsonConvert.DeserializeObject<List<Connection>>(Preferences.Get("connection_list", "[]")));
|
||||
return Task.FromResult(JsonConvert.DeserializeObject<List<Connection>>(_PreferenceService.Get("connection_list", "[]")));
|
||||
}
|
||||
|
||||
public Task<bool> AddConnection(Connection connection)
|
||||
{
|
||||
List<Connection> connection_list = JsonConvert.DeserializeObject<List<Connection>>(Preferences.Get("connection_list", "[]"));
|
||||
List<Connection> connection_list = JsonConvert.DeserializeObject<List<Connection>>(_PreferenceService.Get("connection_list", "[]"));
|
||||
|
||||
if(connection_list.Contains(connection))
|
||||
{
|
||||
@ -25,14 +33,14 @@ namespace Borepin.Service.Connections
|
||||
|
||||
connection_list.Add(connection);
|
||||
|
||||
Preferences.Set("connection_list", JsonConvert.SerializeObject(connection_list));
|
||||
_PreferenceService.Set("connection_list", JsonConvert.SerializeObject(connection_list));
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task<bool> RemoveConnection(Connection connection)
|
||||
{
|
||||
List<Connection> connection_list = JsonConvert.DeserializeObject<List<Connection>>(Preferences.Get("connection_list", "[]"));
|
||||
List<Connection> connection_list = JsonConvert.DeserializeObject<List<Connection>>(_PreferenceService.Get("connection_list", "[]"));
|
||||
|
||||
if (!connection_list.Contains(connection))
|
||||
{
|
||||
@ -41,14 +49,14 @@ namespace Borepin.Service.Connections
|
||||
|
||||
connection_list.RemoveAll(x => x.Equals(connection));
|
||||
|
||||
Preferences.Set("connection_list", JsonConvert.SerializeObject(connection_list));
|
||||
_PreferenceService.Set("connection_list", JsonConvert.SerializeObject(connection_list));
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task<bool> LogConnect(Connection connection)
|
||||
{
|
||||
List<Connection> connection_list = JsonConvert.DeserializeObject<List<Connection>>(Preferences.Get("connection_list", "[]"));
|
||||
List<Connection> connection_list = JsonConvert.DeserializeObject<List<Connection>>(_PreferenceService.Get("connection_list", "[]"));
|
||||
|
||||
if (!connection_list.Contains(connection))
|
||||
{
|
||||
@ -60,7 +68,7 @@ namespace Borepin.Service.Connections
|
||||
connection_update.LastTime = DateTime.UtcNow;
|
||||
connection_list[index] = connection_update;
|
||||
|
||||
Preferences.Set("connection_list", JsonConvert.SerializeObject(connection_list));
|
||||
_PreferenceService.Set("connection_list", JsonConvert.SerializeObject(connection_list));
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
@ -1,12 +1,22 @@
|
||||
using Borepin.Model;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace Borepin.Service.Credentials
|
||||
{
|
||||
public class CredentialService : ICredentialService
|
||||
{
|
||||
#region Private Properties
|
||||
private readonly ISecretService _SecretService;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public CredentialService(ISecretService secretService)
|
||||
{
|
||||
_SecretService = secretService;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public async Task<string> GetPasswordAsync(Connection connection)
|
||||
{
|
||||
if (connection.AuthenticationTyp != AuthenticationTyp.PLAIN)
|
||||
@ -14,19 +24,19 @@ namespace Borepin.Service.Credentials
|
||||
throw new ArgumentException("AuthenticationTyp is not PLAIN");
|
||||
}
|
||||
|
||||
return await SecureStorage.GetAsync(string.Format("bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username));
|
||||
return await _SecretService.GetAsync(string.Format("bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username));
|
||||
}
|
||||
|
||||
public async Task<bool> AddCredentialsAsync(Connection connection, string password)
|
||||
{
|
||||
await SecureStorage.SetAsync(string.Format("bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username), password);
|
||||
await _SecretService.SetAsync(string.Format("bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username), password);
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveCredentialsAsync(Connection connection)
|
||||
{
|
||||
SecureStorage.Remove(string.Format("bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username));
|
||||
_SecretService.Remove(string.Format("bffh_password_{0}_{1}", connection.Address.ToString(), connection.Username));
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
15
Borepin/Borepin/Service/IPreferenceService.cs
Normal file
15
Borepin/Borepin/Service/IPreferenceService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace Borepin.Service
|
||||
{
|
||||
public interface IPreferenceService
|
||||
{
|
||||
void Clear();
|
||||
|
||||
bool ContainsKey(string key);
|
||||
|
||||
string Get(string key, string defaultValue);
|
||||
|
||||
void Remove(string key);
|
||||
|
||||
void Set(string key, string value);
|
||||
}
|
||||
}
|
15
Borepin/Borepin/Service/ISecretService.cs
Normal file
15
Borepin/Borepin/Service/ISecretService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Borepin.Service
|
||||
{
|
||||
public interface ISecretService
|
||||
{
|
||||
Task<string> GetAsync(string key);
|
||||
|
||||
bool Remove(string key);
|
||||
|
||||
void RemoveAll();
|
||||
|
||||
Task SetAsync(string key, string value);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user