Fixed Create new Connection while Connected

This commit is contained in:
TheJoKlLa 2021-09-19 22:30:38 +02:00
parent ec482af4bc
commit aab362b2c0
4 changed files with 30 additions and 8 deletions

View File

@ -64,8 +64,14 @@ namespace Borepin.PageModel.AddServerProcess
Address = builder.Uri Address = builder.Uri
}; };
if(_BFFHService.ActiveConnection != null)
{
await _BFFHService.Disconnect();
}
await _BFFHService.Connect(connection); await _BFFHService.Connect(connection);
INavigationResult result = await _NavigationService.NavigateAsync("AddServerProcess_LoginChoosePage"); INavigationResult result = await _NavigationService.NavigateAsync("AddServerProcess_LoginChoosePage");
if(!result.Success) if(!result.Success)
{ {

View File

@ -71,7 +71,7 @@ namespace Borepin.PageModel
if(IsConnected) if(IsConnected)
{ {
_BFFHService.Disconnect(); await _BFFHService.Disconnect();
IsConnected = false; IsConnected = false;
} }
@ -113,7 +113,7 @@ namespace Borepin.PageModel
if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection) if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection)
{ {
_BFFHService.Disconnect(); await _BFFHService.Disconnect();
} }
await _ConnectionService.RemoveConnection(connection); await _ConnectionService.RemoveConnection(connection);

View File

@ -1,13 +1,27 @@
using Borepin.Model; using Borepin.Model;
using Borepin.Service.Credentials; using Borepin.Service.Credentials;
using System.Threading.Tasks; using System.Threading.Tasks;
using Capnp.Rpc;
using System.Collections.Generic; using System.Collections.Generic;
using FabAccessAPI.Schema; using FabAccessAPI.Schema;
using System.Net.Http; using System;
namespace Borepin.Service.BFFH 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 public class BFFHService : IBFFHService
{ {
private readonly ICredentialService _CredentialService; private readonly ICredentialService _CredentialService;
@ -27,10 +41,10 @@ namespace Borepin.Service.BFFH
{ {
if (_Connection != null || ActiveConnection != null) 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); rpcClient.Connect(connection.Address.Host, connection.Address.Port);
@ -43,11 +57,13 @@ namespace Borepin.Service.BFFH
ActiveConnection = connection; ActiveConnection = connection;
} }
public void Disconnect() public async Task Disconnect()
{ {
_Connection.RpcClient?.Dispose(); _Connection.RpcClient?.Dispose();
_Connection = null; _Connection = null;
ActiveConnection = null; ActiveConnection = null;
await Task.CompletedTask;
} }
public bool CanAuthenticate() public bool CanAuthenticate()

View File

@ -31,7 +31,7 @@ namespace Borepin.Service.BFFH
/// <summary> /// <summary>
/// Disconnect from BFFH Instance /// Disconnect from BFFH Instance
/// </summary> /// </summary>
void Disconnect(); Task Disconnect();
/// <summary> /// <summary>