mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 23:31:48 +01:00
95 lines
2.6 KiB
C#
95 lines
2.6 KiB
C#
using Borepin.Service;
|
|
using Prism.Mvvm;
|
|
using Prism.Navigation;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Borepin.PageModel
|
|
{
|
|
public class HostSelectPageModel : BindableBase
|
|
{
|
|
private INavigationService _NavigationService;
|
|
private BFFHService _BFFHService;
|
|
|
|
public HostSelectPageModel(INavigationService navigationService, BFFHService bffhService)
|
|
{
|
|
_NavigationService = navigationService;
|
|
_BFFHService = bffhService;
|
|
|
|
UseHostCommand = new Command(UseHostCommandExecuted);
|
|
DetectHostCommand = new Command(DetectHostCommandExecuted);
|
|
|
|
LoadData();
|
|
}
|
|
|
|
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;
|
|
public string Host
|
|
{
|
|
get => _Host;
|
|
set => SetProperty(ref _Host, value);
|
|
}
|
|
|
|
private ObservableCollection<string> _KnownHost_List;
|
|
public ObservableCollection<string> KnownHost_List
|
|
{
|
|
get => _KnownHost_List;
|
|
set => SetProperty(ref _KnownHost_List, value);
|
|
}
|
|
|
|
private ICommand _UseHostCommand;
|
|
public ICommand UseHostCommand
|
|
{
|
|
get => _UseHostCommand;
|
|
set => SetProperty(ref _UseHostCommand, value);
|
|
}
|
|
|
|
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)
|
|
{
|
|
System.Diagnostics.Debugger.Break();
|
|
}
|
|
}
|
|
|
|
private ICommand _DetectHostCommand;
|
|
public ICommand DetectHostCommand
|
|
{
|
|
get => _DetectHostCommand;
|
|
set => SetProperty(ref _DetectHostCommand, value);
|
|
}
|
|
|
|
private void DetectHostCommandExecuted()
|
|
{
|
|
// Use Demo Host
|
|
Host = "127.0.0.1:59661";
|
|
}
|
|
}
|
|
}
|