diff --git a/Borepin/Borepin/PageModel/AddServerProcess/HostSelectPageModel.cs b/Borepin/Borepin/PageModel/AddServerProcess/HostSelectPageModel.cs index 6e37b2b..ce0cf38 100644 --- a/Borepin/Borepin/PageModel/AddServerProcess/HostSelectPageModel.cs +++ b/Borepin/Borepin/PageModel/AddServerProcess/HostSelectPageModel.cs @@ -64,7 +64,13 @@ namespace Borepin.PageModel.AddServerProcess Address = builder.Uri }; + if(_BFFHService.ActiveConnection != null) + { + await _BFFHService.Disconnect(); + } await _BFFHService.Connect(connection); + + INavigationResult result = await _NavigationService.NavigateAsync("AddServerProcess_LoginChoosePage"); if(!result.Success) diff --git a/Borepin/Borepin/PageModel/ServerPageModel.cs b/Borepin/Borepin/PageModel/ServerPageModel.cs index 119fdd0..47c261e 100644 --- a/Borepin/Borepin/PageModel/ServerPageModel.cs +++ b/Borepin/Borepin/PageModel/ServerPageModel.cs @@ -71,7 +71,7 @@ namespace Borepin.PageModel if(IsConnected) { - _BFFHService.Disconnect(); + await _BFFHService.Disconnect(); IsConnected = false; } @@ -113,7 +113,7 @@ namespace Borepin.PageModel if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection) { - _BFFHService.Disconnect(); + await _BFFHService.Disconnect(); } await _ConnectionService.RemoveConnection(connection); diff --git a/Borepin/Borepin/Service/BFFH/BFFHService.cs b/Borepin/Borepin/Service/BFFH/BFFHService.cs index 184d5ab..f97b948 100644 --- a/Borepin/Borepin/Service/BFFH/BFFHService.cs +++ b/Borepin/Borepin/Service/BFFH/BFFHService.cs @@ -1,13 +1,27 @@ using Borepin.Model; using Borepin.Service.Credentials; using System.Threading.Tasks; -using Capnp.Rpc; using System.Collections.Generic; using FabAccessAPI.Schema; -using System.Net.Http; +using System; namespace Borepin.Service.BFFH { + public class ConnectionActiveException : Exception + { + public ConnectionActiveException() + { + } + + public ConnectionActiveException(string message) : base(message) + { + } + + public ConnectionActiveException(string message, Exception inner) : base(message, inner) + { + } + } + public class BFFHService : IBFFHService { private readonly ICredentialService _CredentialService; @@ -27,10 +41,10 @@ namespace Borepin.Service.BFFH { if (_Connection != null || ActiveConnection != null) { - throw new System.Exception("Still connected"); + throw new ConnectionActiveException(); } - TcpRpcClient rpcClient = new TcpRpcClient(); + Capnp.Rpc.TcpRpcClient rpcClient = new Capnp.Rpc.TcpRpcClient(); rpcClient.Connect(connection.Address.Host, connection.Address.Port); @@ -43,11 +57,13 @@ namespace Borepin.Service.BFFH ActiveConnection = connection; } - public void Disconnect() + public async Task Disconnect() { _Connection.RpcClient?.Dispose(); _Connection = null; ActiveConnection = null; + + await Task.CompletedTask; } public bool CanAuthenticate() diff --git a/Borepin/Borepin/Service/BFFH/IBFFHService.cs b/Borepin/Borepin/Service/BFFH/IBFFHService.cs index b4a6682..21dc290 100644 --- a/Borepin/Borepin/Service/BFFH/IBFFHService.cs +++ b/Borepin/Borepin/Service/BFFH/IBFFHService.cs @@ -31,7 +31,7 @@ namespace Borepin.Service.BFFH /// /// Disconnect from BFFH Instance /// - void Disconnect(); + Task Disconnect(); ///