This commit is contained in:
TheJoKlLa 2021-01-23 23:35:29 +01:00
parent 1ad79b7c03
commit 2344bb92b9
11 changed files with 2060 additions and 49 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,8 @@ namespace Borepin
containerRegistry.RegisterForNavigation<LoginPasswordPage, LoginPasswordPageModel>();
containerRegistry.RegisterForNavigation<HostSelectPage, HostSelectPageModel>();
containerRegistry.RegisterForNavigation<LoginChoosePage, LoginChoosePageModel>();
containerRegistry.RegisterInstance<BFFHService>(new BFFHService());
}
}
}

View File

@ -24,6 +24,7 @@
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
<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\MachinesPage.xaml.cs">
@ -84,4 +85,7 @@
<Folder Include="Base\" />
<Folder Include="Behaviour\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FabAccessAPI\FabAccessAPI.csproj" />
</ItemGroup>
</Project>

View File

@ -1,14 +1,20 @@
<?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.HostSelectPage">
x:Class="Borepin.Page.HostSelectPage"
xmlns:customControl="clr-namespace:EntryAutoComplete;assembly=EntryAutoComplete">
<NavigationPage.TitleView>
<Label Text="FabAccess" FontAttributes="Bold" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" VerticalOptions="FillAndExpand" FontSize="Medium" TextColor="{StaticResource FirstColor}"/>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout Padding="20">
<Label Text="Host" Style="{StaticResource LabelStyle_PropertyTitle}"></Label>
<Entry Text="{Binding Host}"/>
<customControl:EntryAutoComplete
VerticalOptions="CenterAndExpand"
Placeholder="Entry host ..."
ItemsSource="{Binding KnownHost_List}"
SearchText="{Binding Host}"
MaximumVisibleElements="5"/>
<Button Text="Detect local host" Command="{Binding DetectHostCommand}" Style="{StaticResource ButtonStyle_Primary}"/>
<Button Text="Select Host" Command="{Binding UseHostCommand}" Style="{StaticResource ButtonStyle_Primary}"/>

View File

@ -12,10 +12,12 @@ namespace Borepin.PageModel
public class HostSelectPageModel : BindableBase
{
private INavigationService _NavigationService;
private BFFHService _BFFHService;
public HostSelectPageModel(INavigationService navigationService)
public HostSelectPageModel(INavigationService navigationService, BFFHService bffhService)
{
_NavigationService = navigationService;
_BFFHService = bffhService;
UseHostCommand = new Command(UseHostCommandExecuted);
DetectHostCommand = new Command(DetectHostCommandExecuted);
@ -28,6 +30,20 @@ namespace Borepin.PageModel
set => SetProperty(ref _Host, value);
}
private List<string> _KnownHost_List;
public List<string> KnownHost_List
{
get
{
List<string> list = new List<string>();
foreach(Uri host in _BFFHService.KnownHost)
{
list.Add(host.ToString());
}
return list;
}
}
private ICommand _UseHostCommand;
public ICommand UseHostCommand
{
@ -37,6 +53,14 @@ namespace Borepin.PageModel
private async void UseHostCommandExecuted()
{
UriBuilder builder = new UriBuilder(Host);
if(builder.Port == 80)
{
builder.Port = 59661;
}
_BFFHService.Connect(builder.Uri);
INavigationResult result = await _NavigationService.NavigateAsync($"LoginChoosePage");
if (!result.Success)
{
@ -54,7 +78,7 @@ namespace Borepin.PageModel
private void DetectHostCommandExecuted()
{
// Use Demo Host
Host = "demo.fab-access.org";
Host = "127.0.0.1";
}
}
}

View File

@ -12,10 +12,22 @@ namespace Borepin.PageModel
public class LoginPasswordPageModel : BindableBase
{
private INavigationService _NavigationService;
private BFFHService _BFFHService;
public LoginPasswordPageModel(INavigationService navigationService)
private bool _KnownCredentials = false;
private string _KnownUsername = "";
public LoginPasswordPageModel(INavigationService navigationService, BFFHService bffhService)
{
_NavigationService = navigationService;
_BFFHService = bffhService;
_KnownUsername = bffhService.LoadUsername();
if(_KnownUsername != null)
{
Username = _KnownUsername;
Password = "********";
}
AuthenticateCommand = new Command(AuthenticateCommandExecuted);
}
@ -43,7 +55,14 @@ namespace Borepin.PageModel
private async void AuthenticateCommandExecuted()
{
BFFHActiveInterface.Interface = BFFHService.Auth(Username);
if(_KnownUsername == Username)
{
_BFFHService.Authenticate();
}
else
{
_BFFHService.Authenticate(Username, Password);
}
var result = await _NavigationService.NavigateAsync("//MainPage/NavigationPage/MachinesPage");

View File

@ -210,7 +210,7 @@ namespace Borepin.PageModel
public void UpdateMachine()
{
Machine = BFFHService.GetMachine(Machine.ID);
Machine = BFFHService_OLD.GetMachine(Machine.ID);
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanUse"));
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanReserve"));
@ -234,7 +234,7 @@ namespace Borepin.PageModel
try
{
Machine = BFFHService.GetMachine(machineID);
Machine = BFFHService_OLD.GetMachine(machineID);
IsValid = true;
UpdateMachine();

View File

@ -20,7 +20,7 @@ namespace Borepin.PageModel
_navigationService = navigationService;
GoToMachineCommand = new Command<object>(GoToMachineCommandExecuted);
MachineList = new ObservableCollection<Machine>(BFFHService.GetMachines());
MachineList = new ObservableCollection<Machine>(BFFHService_OLD.GetMachines());
}
private ICommand _GoToMachineCommand;

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using Xamarin.Essentials;
using FabAccessAPI;
using Capnp.Rpc;
using Xamarin.Forms;
namespace Borepin.Service
{
public class BFFHService
{
public Uri SelectedHost;
private Connection _Connection;
public List<Uri> KnownHost
{
get
{
string knownhosts = Preferences.Get("bffh_knownhost", "");
List<Uri> knownhost_list = new List<Uri>();
string[] split = knownhosts.Split(',');
foreach(string host in split)
{
if(host == "")
{
continue;
}
Uri host_new = new Uri(host);
knownhost_list.Add(host_new);
}
return knownhost_list;
}
}
private void KnownHost_Add(Uri address)
{
if(KnownHost.Contains(address))
{
return;
}
string knownhosts = Preferences.Get("bffh_knownhost", "");
knownhosts += "," + address.ToString();
Preferences.Set("bffh_knownhost", knownhosts);
}
public void Connect()
{
if (SelectedHost == null)
{
throw new System.Exception("No Host selected");
}
Connect(SelectedHost);
}
public void Connect(Uri address)
{
if(_Connection != null)
{
throw new System.Exception("Still connected");
}
var rpcClient = new TcpRpcClient();
rpcClient.Connect(address.Host, address.Port);
Connection connection_test = new Connection(rpcClient);
KnownHost_Add(address);
_Connection = connection_test;
SelectedHost = address;
}
public void Disconnect()
{
_Connection.RpcClient?.Dispose();
_Connection = null;
}
public string LoadUsername()
{
string username = null;
Device.BeginInvokeOnMainThread(async () => {
username = await SecureStorage.GetAsync(string.Format("bffh_username_{0}", SelectedHost.ToString()));
});
return username;
}
private string LoadPassword()
{
return SecureStorage.GetAsync(string.Format("bffh_password_{0}", SelectedHost.ToString())).Result;
}
private void AddUsername(string username)
{
Device.BeginInvokeOnMainThread(async () => {
await SecureStorage.SetAsync(string.Format("bffh_username_{0}", SelectedHost.ToString()), username);
});
}
private void AddPasword(string password)
{
Device.BeginInvokeOnMainThread(async () => {
await SecureStorage.SetAsync(string.Format("bffh_password_{0}", SelectedHost.ToString()), password);
});
}
public void Authenticate()
{
string username = LoadUsername();
string password = LoadPassword();
_Connection.Auth("PLAIN", new Dictionary<string, object> { { "Username", username }, { "Password", password } });
}
public void Authenticate(string username, string password)
{
_Connection.Auth("PLAIN", new Dictionary<string, object> { { "Username", username }, { "Password", password } });
AddUsername(username);
AddPasword(password);
}
}
}

View File

@ -205,12 +205,12 @@ namespace Borepin.Service
public bool IsAdmin()
{
return ActiveUser.ID == BFFHService.AdminID;
return ActiveUser.ID == BFFHService_OLD.AdminID;
}
}
public static class BFFHService
public static class BFFHService_OLD
{
public static readonly string Host = "fvm.fab-access.org";
public static readonly string AdminID = "0";

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>