mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
132 lines
3.6 KiB
C#
132 lines
3.6 KiB
C#
using Borepin.Base;
|
|
using Borepin.Service.BFFH;
|
|
using Prism.Navigation;
|
|
using Prism.Services;
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Borepin.PageModel.AddServerProcess
|
|
{
|
|
public class HostSelectPageModel : PageModelBase
|
|
{
|
|
#region Private Properties
|
|
private readonly IBFFHService _BFFHService;
|
|
private readonly IPageDialogService _PageDialogService;
|
|
#endregion
|
|
|
|
#region Constructors
|
|
public HostSelectPageModel(INavigationService navigationService, IBFFHService bffhService, IPageDialogService pageDialogService) : base(navigationService)
|
|
{
|
|
_BFFHService = bffhService;
|
|
_PageDialogService = pageDialogService;
|
|
|
|
UseHostCommand = new Command(UseHostCommandExecuted);
|
|
DetectHostCommand = new Command(DetectHostCommandExecuted);
|
|
|
|
Task.Run(LoadData);
|
|
}
|
|
#endregion
|
|
|
|
#region LoadData
|
|
public override Task LoadData()
|
|
{
|
|
IsBusy = false;
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
#endregion
|
|
|
|
#region Properties
|
|
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);
|
|
}
|
|
#endregion
|
|
|
|
#region Commands
|
|
private ICommand _UseHostCommand;
|
|
public ICommand UseHostCommand
|
|
{
|
|
get => _UseHostCommand;
|
|
set => SetProperty(ref _UseHostCommand, value);
|
|
}
|
|
|
|
private async void UseHostCommandExecuted()
|
|
{
|
|
IsBusy = true;
|
|
|
|
UriBuilder builder = new UriBuilder(Host);
|
|
if(builder.Port == 80)
|
|
{
|
|
builder.Port = 59661;
|
|
}
|
|
|
|
Model.Connection connection = new Model.Connection()
|
|
{
|
|
Address = builder.Uri
|
|
};
|
|
|
|
if(_BFFHService.ActiveConnection != null)
|
|
{
|
|
await _BFFHService.Disconnect();
|
|
}
|
|
|
|
try
|
|
{
|
|
await _BFFHService.Connect(connection);
|
|
}
|
|
catch (Capnp.Rpc.RpcException exception) when (exception.Message == "TcpRpcClient is unable to connect")
|
|
{
|
|
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok");
|
|
|
|
IsBusy = false;
|
|
return;
|
|
}
|
|
|
|
INavigationResult result = await _NavigationService.NavigateAsync("AddServerProcess_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";
|
|
}
|
|
#endregion
|
|
|
|
#region INavigationAware
|
|
public override void OnNavigatedFrom(INavigationParameters parameters)
|
|
{
|
|
|
|
}
|
|
|
|
public override void OnNavigatedTo(INavigationParameters parameters)
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
}
|