Added: BFFHInstanceService

This commit is contained in:
TheJoKlLa 2021-01-24 23:56:27 +01:00
parent 8e3ba1881b
commit 9347a6160f
19 changed files with 357 additions and 464 deletions

View File

@ -4,6 +4,7 @@ using Borepin.PageModel;
using Borepin.Page;
using Xamarin.Forms;
using Borepin.Service;
using Borepin.Service.ServerInstances;
namespace Borepin
{
@ -36,8 +37,13 @@ namespace Borepin
containerRegistry.RegisterForNavigation<LoginPasswordPage, LoginPasswordPageModel>();
containerRegistry.RegisterForNavigation<HostSelectPage, HostSelectPageModel>();
containerRegistry.RegisterForNavigation<LoginChoosePage, LoginChoosePageModel>();
containerRegistry.RegisterForNavigation<ServerInstancesPage, ServerInstancesPageModel>();
BFFHInstanceService bffhInstanceService = new BFFHInstanceService();
containerRegistry.RegisterInstance<IBFFHInstanceService>(bffhInstanceService);
containerRegistry.RegisterInstance<BFFHService>(new BFFHService(bffhInstanceService));
containerRegistry.RegisterInstance<BFFHService>(new BFFHService());
}
}
}

View File

@ -20,6 +20,7 @@
<Warning Text="$(MSBuildProjectFile) is Multilingual build enabled, but the Multilingual App Toolkit is unavailable during the build. If building with Visual Studio, please check to ensure that toolkit is properly installed." />
</Target>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Prism.DryIoc.Forms" Version="8.0.0.1909" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
@ -66,6 +67,9 @@
<EmbeddedResource Update="Page\MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\ServerInstancesPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Page\SettingsPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
@ -80,10 +84,14 @@
<EmbeddedResource Update="Styles\LightTheme.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="View\HostView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Base\" />
<Folder Include="Behaviour\" />
<Folder Include="Page\LoginDialog\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\FabAccessAPI\FabAccessAPI.csproj" />

View File

@ -0,0 +1,12 @@
using System;
namespace Borepin.Model
{
public class BFFHInstance
{
public Uri Address { get; set; }
public string Name { get; set; } = "";
public string Description { get; set; } = "";
}
}

View File

@ -9,6 +9,7 @@
<StackLayout>
<Button Text="Machines" Command="{Binding NavigateCommand}" CommandParameter="MachinesPage" />
<Button Text="Settings" Command="{Binding NavigateCommand}" CommandParameter="SettingsPage" />
<Button Text="Servers" Command="{Binding NavigateCommand}" CommandParameter="ServerInstancesPage" />
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>

View 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.ServerInstancesPage">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>

View 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
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ServerInstancesPage : ContentPage
{
public ServerInstancesPage()
{
InitializeComponent();
}
}
}

View File

@ -1,4 +1,5 @@
using Borepin.Service;
using Borepin.Service.ServerInstances;
using Prism.Mvvm;
using Prism.Navigation;
using System;
@ -14,11 +15,13 @@ namespace Borepin.PageModel
public class HostSelectPageModel : BindableBase
{
private INavigationService _NavigationService;
private IBFFHInstanceService _BFFHInstanceService;
private BFFHService _BFFHService;
public HostSelectPageModel(INavigationService navigationService, BFFHService bffhService)
public HostSelectPageModel(INavigationService navigationService, BFFHService bffhService, IBFFHInstanceService bffhInstanceService)
{
_NavigationService = navigationService;
_BFFHInstanceService = bffhInstanceService;
_BFFHService = bffhService;
UseHostCommand = new Command(UseHostCommandExecuted);
@ -29,15 +32,7 @@ namespace Borepin.PageModel
private async Task LoadData()
{
ObservableCollection<Uri> hosts_list = await _BFFHService.GetKnownHostsAsync();
ObservableCollection<string> host_string_list = new ObservableCollection<string>();
foreach(Uri host in hosts_list)
{
host_string_list.Add(host.ToString());
}
KnownHost_List = host_string_list;
}
private string _Host;

View File

@ -2,10 +2,6 @@
using Borepin.Service;
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
@ -14,12 +10,12 @@ namespace Borepin.PageModel
public class MachinePageModel : BindableBase, INavigationAware
{
private INavigationService _NavigationService;
private BFFHInterface _BFFHInterface;
private BFFHService _BFFHService;
public MachinePageModel(INavigationService navigationService)
public MachinePageModel(INavigationService navigationService, BFFHService bffhService)
{
_NavigationService = navigationService;
_BFFHInterface = BFFHActiveInterface.Interface;
_BFFHService = bffhService;
ReserveMachineCommand = new Command(ReserveMachineCommandExecuted);
UseMachineCommand = new Command(UseMachineCommandExecuted);
@ -51,8 +47,8 @@ namespace Borepin.PageModel
private void ReserveMachineCommandExecuted()
{
_BFFHInterface.ReserveMachine(Machine.ID);
UpdateMachine();
//_BFFHInterface.ReserveMachine(Machine.ID);
//UpdateMachine();
}
@ -65,8 +61,8 @@ namespace Borepin.PageModel
private void UseMachineCommandExecuted()
{
_BFFHInterface.UseMachine(Machine.ID);
UpdateMachine();
//_BFFHInterface.UseMachine(Machine.ID);
//UpdateMachine();
}
private ICommand _GiveBackMachineCommand;
@ -78,8 +74,8 @@ namespace Borepin.PageModel
private void GiveBackMachineCommandExecuted()
{
_BFFHInterface.GiveBackMachine(Machine.ID);
UpdateMachine();
//_BFFHInterface.GiveBackMachine(Machine.ID);
//UpdateMachine();
}
private ICommand _DisableMachineCommand;
@ -91,16 +87,16 @@ namespace Borepin.PageModel
private void DisableMachineCommandExecuted()
{
if(Machine.State == MachineStates.Disabled)
{
_BFFHInterface.SetStateForce(Machine.ID, MachineStates.Free);
}
else
{
_BFFHInterface.SetStateForce(Machine.ID, MachineStates.Disabled);
}
//if(Machine.State == MachineStates.Disabled)
//{
// _BFFHInterface.SetStateForce(Machine.ID, MachineStates.Free);
//}
//else
//{
// _BFFHInterface.SetStateForce(Machine.ID, MachineStates.Disabled);
//}
UpdateMachine();
//UpdateMachine();
}
private ICommand _BlockMachineCommand;
@ -112,43 +108,43 @@ namespace Borepin.PageModel
private void BlockMachineCommandExecuted()
{
if (Machine.State == MachineStates.Blocked)
{
_BFFHInterface.SetStateForce(Machine.ID, MachineStates.Free);
}
else
{
_BFFHInterface.SetStateForce(Machine.ID, MachineStates.Blocked);
}
//if (Machine.State == MachineStates.Blocked)
//{
// _BFFHInterface.SetStateForce(Machine.ID, MachineStates.Free);
//}
//else
//{
// _BFFHInterface.SetStateForce(Machine.ID, MachineStates.Blocked);
//}
UpdateMachine();
//UpdateMachine();
}
public bool CanUse
{
get
{
if(Machine == null)
{
return false;
}
//if(Machine == null)
//{
// return false;
//}
if(Machine.State == MachineStates.Free)
{
return true;
}
//if(Machine.State == MachineStates.Free)
//{
// return true;
//}
if(Machine.State == MachineStates.Reserved)
{
if(Machine.User == _BFFHInterface.ActiveUser)
{
return true;
}
else if(_BFFHInterface.IsAdmin())
{
return true;
}
}
//if(Machine.State == MachineStates.Reserved)
//{
// if(Machine.User == _BFFHInterface.ActiveUser)
// {
// return true;
// }
// else if(_BFFHInterface.IsAdmin())
// {
// return true;
// }
//}
return false;
}
@ -158,15 +154,15 @@ namespace Borepin.PageModel
{
get
{
if (Machine == null)
{
return false;
}
//if (Machine == null)
//{
// return false;
//}
if (Machine.State == MachineStates.Free)
{
return true;
}
//if (Machine.State == MachineStates.Free)
//{
// return true;
//}
return false;
}
@ -176,15 +172,15 @@ namespace Borepin.PageModel
{
get
{
if (Machine == null)
{
return false;
}
//if (Machine == null)
//{
// return false;
//}
if (Machine.State == MachineStates.InUse && Machine.User == _BFFHInterface.ActiveUser)
{
return true;
}
//if (Machine.State == MachineStates.InUse && Machine.User == _BFFHInterface.ActiveUser)
//{
// return true;
//}
return false;
}
@ -194,15 +190,15 @@ namespace Borepin.PageModel
{
get
{
if (_BFFHInterface == null)
{
return false;
}
//if (_BFFHInterface == null)
//{
// return false;
//}
if (_BFFHInterface.IsAdmin())
{
return true;
}
//if (_BFFHInterface.IsAdmin())
//{
// return true;
//}
return false;
}
@ -210,11 +206,11 @@ namespace Borepin.PageModel
public void UpdateMachine()
{
Machine = BFFHService_OLD.GetMachine(Machine.ID);
//Machine = BFFHService_OLD.GetMachine(Machine.ID);
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanUse"));
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanReserve"));
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanGiveBack"));
//OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanUse"));
//OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanReserve"));
//OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("CanGiveBack"));
}
public void OnNavigatedFrom(INavigationParameters parameters)
@ -224,25 +220,25 @@ namespace Borepin.PageModel
public void OnNavigatedTo(INavigationParameters parameters)
{
string machineID = parameters["machineID"] as string;
//string machineID = parameters["machineID"] as string;
if(machineID == null)
{
_IsValid = false;
return;
}
//if(machineID == null)
//{
// _IsValid = false;
// return;
//}
try
{
Machine = BFFHService_OLD.GetMachine(machineID);
IsValid = true;
//try
//{
// Machine = BFFHService_OLD.GetMachine(machineID);
// IsValid = true;
UpdateMachine();
}
catch
{
_IsValid = false;
}
// UpdateMachine();
//}
//catch
//{
// _IsValid = false;
//}
}
}
}

View File

@ -1,11 +1,7 @@
using Borepin.Model;
using Borepin.Service;
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;
@ -19,8 +15,6 @@ namespace Borepin.PageModel
{
_NavigationService = navigationService;
GoToMachineCommand = new Command<object>(GoToMachineCommandExecuted);
MachineList = new ObservableCollection<Machine>(BFFHService_OLD.GetMachines());
}
private ICommand _GoToMachineCommand;

View File

@ -0,0 +1,35 @@
using Borepin.Model;
using Borepin.Service.ServerInstances;
using Prism.Mvvm;
using Prism.Navigation;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace Borepin.PageModel
{
public class ServerInstancesPageModel : BindableBase
{
private INavigationService _NavigationService;
private IBFFHInstanceService _BFFHInstanceService;
public ServerInstancesPageModel(INavigationService navigationService, IBFFHInstanceService bffhInstanceService)
{
_NavigationService = navigationService;
_BFFHInstanceService = bffhInstanceService;
LoadData();
}
private async Task LoadData()
{
_ServerInstance_List = new ObservableCollection<BFFHInstance>(await _BFFHInstanceService.GetBFFHInstances());
}
private ObservableCollection<BFFHInstance> _ServerInstance_List;
public ObservableCollection<BFFHInstance> ServerInstance_List
{
get => _ServerInstance_List;
set => SetProperty(ref _ServerInstance_List, value);
}
}
}

View File

@ -2,30 +2,26 @@
using System.Collections.Generic;
using FabAccessAPI;
using Capnp.Rpc;
using Borepin.Service.Hosts;
using Borepin.Service.Credentials;
using Borepin.Model;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Borepin.Service.ServerInstances;
namespace Borepin.Service
{
public class BFFHService
{
public Uri ConnectedHost;
private Connection _Connection;
private HostService _HostService;
private IBFFHInstanceService _BFFHInstanceService;
private CredentialsService _CredentialsService;
public BFFHService()
{
_HostService = new HostService();
_CredentialsService = new CredentialsService();
}
private Connection _Connection;
public async Task<ObservableCollection<Uri>> GetKnownHostsAsync()
public Uri ConnectedHost { get; private set; }
public BFFHService(IBFFHInstanceService bffhInstanceService)
{
return await _HostService.GetKnownHostsAsync();
_BFFHInstanceService = bffhInstanceService;
_CredentialsService = new CredentialsService();
}
public void Connect(Uri host)
@ -40,7 +36,7 @@ namespace Borepin.Service
Connection connection_test = new Connection(rpcClient);
_HostService.LogHostAsync(host);
_BFFHInstanceService.AddBFFHInstance(new BFFHInstance() { Address = host });
_Connection = connection_test;
ConnectedHost = host;

View File

@ -1,75 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace Borepin.Service.Hosts
{
public class HostService : IHostService
{
public List<Uri> KnownHosts { get; set; }
public HostService()
{
KnownHosts = new List<Uri>();
LoadKnownHosts();
}
public Task<ObservableCollection<Uri>> GetKnownHostsAsync()
{
return Task.FromResult(new ObservableCollection<Uri>(KnownHosts));
}
public Task<bool> LogHostAsync(Uri host)
{
if (KnownHosts.Contains(host))
{
return Task.FromResult(true);
}
KnownHosts.Add(host);
return SaveKnownHosts();
}
public Task<bool> LoadKnownHosts()
{
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);
}
KnownHosts = knownhost_list;
return Task.FromResult(true);
}
public Task<bool> SaveKnownHosts()
{
string knownhosts = "";
foreach(Uri host in KnownHosts)
{
knownhosts += "," + host.ToString();
}
Preferences.Set("knownhosts", knownhosts);
return Task.FromResult(true);
}
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
namespace Borepin.Service.Hosts
{
public interface IHostService
{
Task<ObservableCollection<Uri>> GetKnownHostsAsync();
Task<bool> LogHostAsync(Uri host);
}
}

View File

@ -1,250 +0,0 @@
using Borepin.Model;
using System;
using System.Collections.Generic;
using System.Text;
namespace Borepin.Service
{
public static class BFFHDataService
{
public static List<Machine> _Machines;
public static List<User> _Users;
static BFFHDataService()
{
_Users = new List<User>()
{
new User()
{
ID = "0",
Name = "Nick Wise (Admin)",
OriginalWorkshop = "fvm.fab-access.org"
},
new User()
{
ID = "1",
Name = "Tamia Langley",
OriginalWorkshop = "fvm.fab-access.org"
},
new User()
{
ID = "2",
Name = "Jay James",
OriginalWorkshop = "fvm.fab-access.org"
},
new User()
{
ID = "3",
Name = "Darragh Ellwood",
OriginalWorkshop = "happylab.fab-access.org"
},
new User()
{
ID = "4",
Name = "Mila-Rose Mcknight",
OriginalWorkshop = "motionlab.fab-access.org"
}
};
_Machines = new List<Machine>()
{
new Machine()
{
ID = "MakerRobo UP",
Description = "MakerRobo UP is a 3D Printer from Bangladesh",
State = MachineStates.Free,
User = null
},
new Machine()
{
ID = "LS-1080-K 150W",
Description = "Laser cutting and engraving" + "\n" +
"Cutting Area: 1000 x 800 mm" + "\n" +
"Materials: wood, cardboard, PMMA, textiles, etc." + "\n" +
"Supported files: DXF, AI, EPS, JPG, BMP",
State = MachineStates.InUse,
User = _Users.Find(x => x.ID == "1")
},
new Machine()
{
ID = "Fireball V90",
Description = "The V90 is a high performance, general purpose machine, suitable for many uses such as clock making, plaques, RC aircraft parts and more. 12x18x3 working space.",
State = MachineStates.ToCheck,
User = _Users.Find(x => x.ID == "0")
},
new Machine()
{
ID = "IRB 1600-145 kg",
Description = "Robotic Arm",
State = MachineStates.Blocked,
User = null
},
new Machine()
{
ID = "Carmine 1.09",
Description = "Primesense",
State = MachineStates.Disabled,
User = null
},
new Machine()
{
ID = "Zmorph 2.0SX Multitool",
Description = "FabLab in a box ",
State = MachineStates.Reserved,
User = _Users.Find(x => x.ID == "2")
},
new Machine()
{
ID = "CubePro Duo",
Description = "The CubePro features the largest-in-class build platform with ultra high-resolution. With prints 2.5 times larger than any other desktop prosumer and hobbyist printer (11.2 x 10.6 x 9.06 or 285.4mm x 270.4mm x 230mm) with ultra high-resolution settings of 70-micron thin print layers, professional quality printing has never been so large or easy.",
State = MachineStates.Free,
User = null
},
};
}
}
public static class BFFHActiveInterface
{
public static BFFHInterface Interface;
}
public class BFFHInterface
{
public readonly User ActiveUser;
public BFFHInterface(string userID)
{
ActiveUser = BFFHDataService._Users.Find(x => x.ID == userID);
}
public void UseMachine(string machineID)
{
Machine machinetouse = BFFHDataService._Machines.Find(x => x.ID == machineID);
if (machinetouse == null)
{
throw new Exception("Unknown Machine");
}
int index = BFFHDataService._Machines.IndexOf(machinetouse);
if (machinetouse.State == MachineStates.Free)
{
machinetouse.State = MachineStates.InUse;
machinetouse.User = ActiveUser;
}
if(machinetouse.State == MachineStates.Reserved && machinetouse.User == ActiveUser)
{
machinetouse.State = MachineStates.InUse;
machinetouse.User = ActiveUser;
}
BFFHDataService._Machines[index] = machinetouse;
}
public void ReserveMachine(string machineID)
{
Machine machinetouse = BFFHDataService._Machines.Find(x => x.ID == machineID);
if (machinetouse == null)
{
throw new Exception("Unknown Machine");
}
int index = BFFHDataService._Machines.IndexOf(machinetouse);
if (machinetouse.State == MachineStates.Free)
{
machinetouse.State = MachineStates.Reserved;
machinetouse.User = ActiveUser;
}
BFFHDataService._Machines[index] = machinetouse;
}
public void GiveBackMachine(string machineID)
{
Machine machinetogiveback = BFFHDataService._Machines.Find(x => x.ID == machineID);
if (machinetogiveback == null)
{
throw new Exception("Unknown Machine");
}
int index = BFFHDataService._Machines.IndexOf(machinetogiveback);
if (machinetogiveback.State == MachineStates.InUse)
{
machinetogiveback.State = MachineStates.Free;
machinetogiveback.User = null;
}
BFFHDataService._Machines[index] = machinetogiveback;
}
public void SetStateForce(string machineID, MachineStates state)
{
if(IsAdmin())
{
Machine machinetosetstate = BFFHDataService._Machines.Find(x => x.ID == machineID);
if (machinetosetstate == null)
{
throw new Exception("Unknown Machine");
}
int index = BFFHDataService._Machines.IndexOf(machinetosetstate);
machinetosetstate.State = state;
BFFHDataService._Machines[index] = machinetosetstate;
}
else
{
throw new Exception("Forbidden");
}
}
public bool IsAdmin()
{
return ActiveUser.ID == BFFHService_OLD.AdminID;
}
}
public static class BFFHService_OLD
{
public static readonly string Host = "fvm.fab-access.org";
public static readonly string AdminID = "0";
public static BFFHInterface Auth(string userID)
{
if(BFFHDataService._Users.Find(x => x.ID == userID) == null)
{
throw new Exception("Authentication failed");
}
return new BFFHInterface(userID);
}
public static List<Machine> GetMachines()
{
return BFFHDataService._Machines;
}
public static List<User> GetUsers()
{
return BFFHDataService._Users;
}
public static Machine GetMachine(string machineID)
{
Machine m = BFFHDataService._Machines.Find(x => x.ID == machineID);
if (m == null)
{
throw new Exception("Unknown Machine");
}
return m;
}
}
}

View File

@ -0,0 +1,98 @@
using Borepin.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Essentials;
namespace Borepin.Service.ServerInstances
{
/// <summary>
/// Save connected BFFHInstances in Xamarin.Essentials.Preferences
/// </summary>
public class BFFHInstanceService : IBFFHInstanceService
{
private List<BFFHInstance> _BFFHInstance_List;
public Task<List<BFFHInstance>> GetBFFHInstances()
{
List<BFFHInstance> bffhInstances = JsonConvert.DeserializeObject<List<BFFHInstance>>(Preferences.Get("bffhinstances", "[]"));
_BFFHInstance_List = bffhInstances;
return Task.FromResult(bffhInstances);
}
public Task<bool> AddBFFHInstance(BFFHInstance instance)
{
if(_BFFHInstance_List == null)
{
GetBFFHInstances();
}
if(_BFFHInstance_List.Find(x => x.Address == instance.Address) != null)
{
return Task.FromResult(true);
}
_BFFHInstance_List.Add(instance);
SaveList();
return Task.FromResult(true);
}
public Task<bool> UpdateBFFHInstance(BFFHInstance instance)
{
if (_BFFHInstance_List == null)
{
GetBFFHInstances();
}
if (_BFFHInstance_List.Find(x => x.Address == instance.Address) == null)
{
throw new ArgumentException("BFFH Instance does not exist");
}
foreach (BFFHInstance bffh in _BFFHInstance_List.Where(x => x.Address == instance.Address))
{
bffh.Name = instance.Name;
bffh.Description = instance.Description;
}
SaveList();
return Task.FromResult(true);
}
private Task<bool> SaveList()
{
Preferences.Set("bffhinstances", JsonConvert.SerializeObject(_BFFHInstance_List));
return Task.FromResult(true);
}
public Task<bool> RemoveBFFHInstance(BFFHInstance instance)
{
if (_BFFHInstance_List == null)
{
GetBFFHInstances();
}
_BFFHInstance_List.RemoveAll(x => x.Address == instance.Address);
SaveList();
return Task.FromResult(true);
}
public Task<bool> RemoveAllBFFHInstances()
{
Preferences.Remove("bffhinstances");
_BFFHInstance_List.Clear();
return Task.FromResult(true);
}
}
}

View File

@ -0,0 +1,18 @@
using Borepin.Model;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Borepin.Service.ServerInstances
{
public interface IBFFHInstanceService
{
Task<List<BFFHInstance>> GetBFFHInstances();
Task<bool> AddBFFHInstance(BFFHInstance instance);
Task<bool> UpdateBFFHInstance(BFFHInstance instance);
Task<bool> RemoveBFFHInstance(BFFHInstance instance);
Task<bool> RemoveAllBFFHInstances();
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Borepin.View.HostView">
<ContentView.Content>
<StackLayout>
<Label Text="Hello Xamarin.Forms!" />
</StackLayout>
</ContentView.Content>
</ContentView>

View 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.View
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class HostView : ContentView
{
public HostView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace Borepin.ViewModel
{
public class HostViewModel : BindableObject
{
}
}