Update: API Connection in BFFHService

This commit is contained in:
TheJoKlLa 2022-03-14 22:52:46 +01:00
parent 2eebf91aab
commit 9103a5959f
5 changed files with 41 additions and 57 deletions

View File

@ -30,7 +30,7 @@ namespace Borepin.Model
Manager = new UserVisualize(_Machine.Manager);
Manager.LoadData();
MachineInfoExtended machineInfoExtended = (await _Machine.Info.GetMachineInfoExtended().ConfigureAwait(false)).Item1;
MachineInfoExtended machineInfoExtended = await _Machine.Manage.GetMachineInfoExtended().ConfigureAwait(false);
if(machineInfoExtended != null)
{
if (machineInfoExtended.CurrentUser == null || machineInfoExtended.CurrentUser.Username == null)
@ -43,13 +43,13 @@ namespace Borepin.Model
CurrentUser.LoadData();
}
if (machineInfoExtended.TransferUser == null || machineInfoExtended.TransferUser.Username == null)
if (machineInfoExtended.LastUser == null || machineInfoExtended.LastUser.Username == null)
{
LastUser = null;
}
else
{
LastUser = new UserVisualize(machineInfoExtended.TransferUser);
LastUser = new UserVisualize(machineInfoExtended.LastUser);
LastUser.LoadData();
}
}
@ -61,7 +61,7 @@ namespace Borepin.Model
CanUse = !((UseInterface_Proxy)_Machine.Use).IsNull;
CanInUse = !((InUseInterface_Proxy) _Machine.Inuse).IsNull;
CanTransfer = !((TransferInterface_Proxy) _Machine.Transfer).IsNull;
CanTakeOver = !((TakeoverInterface_Proxy) _Machine.Takeover).IsNull;
CanCheck = !((CheckInterface_Proxy) _Machine.Check).IsNull;
CanManage = !((ManageInterface_Proxy) _Machine.Manage).IsNull;
CanAdmin = !((AdminInterface_Proxy) _Machine.Admin).IsNull;
@ -140,7 +140,7 @@ namespace Borepin.Model
}
private bool _CanTransfer;
public bool CanTransfer
public bool CanTakeOver
{
get => _CanTransfer;
set => SetProperty(ref _CanTransfer, value);

View File

@ -49,10 +49,10 @@ namespace Borepin.PageModel
IsConnected = true;
IMachineSystem machineSystem = await _BFFHService.GetMachineSystemInterface().ConfigureAwait(false);
IMachineSystem machineSystem = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
MachineSystem.IInfoInterface machine_infoInterface = await machineSystem.Info().ConfigureAwait(false);
IUserSystem userSystem = await _BFFHService.GetUserSystemInterface().ConfigureAwait(false);
IUserSystem userSystem = (await _BFFHService.GetSession().ConfigureAwait(false)).UserSystem;
UserSystem.IInfoInterface user_infoInterface = await userSystem.Info().ConfigureAwait(false);
User user_self = (await user_infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
@ -66,7 +66,7 @@ namespace Borepin.PageModel
{
MachineListItemViewModel new_viewmodel = new MachineListItemViewModel(machine)
{
IsUserAssigned = true
IsUserAssigned = true,
};
viewmodel_list_user_assigned.Add(new_viewmodel);
}
@ -156,10 +156,10 @@ namespace Borepin.PageModel
return;
}
IMachineSystem machineInterface = await _BFFHService.GetMachineSystemInterface().ConfigureAwait(false);
IMachineSystem machineInterface = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
MachineSystem.IInfoInterface infoInterface = await machineInterface.Info().ConfigureAwait(false);
Machine machine = (await infoInterface.GetMachineURN(result.Parameters.GetValue<string>("value")).ConfigureAwait(false)).Item1;
Machine machine = await infoInterface.GetMachineURN(result.Parameters.GetValue<string>("value")).ConfigureAwait(false);
if(machine == null)
{

View File

@ -43,7 +43,7 @@ namespace Borepin.PageModel
IMachineSystem machineSystem;
try
{
machineSystem = await _BFFHService.GetMachineSystemInterface().ConfigureAwait(false);
machineSystem = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
}
catch(ReconnectingFailedException)
{
@ -54,7 +54,7 @@ namespace Borepin.PageModel
IInfoInterface info = await machineSystem.Info().ConfigureAwait(false);
_Machine = (await info.GetMachine(_ID).ConfigureAwait(false)).Item1;
_Machine = await info.GetMachine(_ID).ConfigureAwait(false);
MachineItem = new MachineVisualize(_Machine);
MachineItem.LoadData();

View File

@ -9,6 +9,7 @@ using Borepin.Model.Storage;
using Borepin.Service.BFFH.Exceptions;
using Borepin.Service.Storage.Exceptions;
using Capnp.Rpc;
using FabAccessAPI.Exceptions;
namespace Borepin.Service.BFFH
{
@ -60,12 +61,7 @@ namespace Borepin.Service.BFFH
}
#endregion
#region Methods
private void StateChanged(Object sender, ConnectionStateEventArgs e)
{
}
#region Method
/// <summary>
/// Get all known Connections from Storage
/// </summary>
@ -110,17 +106,16 @@ namespace Borepin.Service.BFFH
{
try
{
Capnp.Rpc.TcpRpcClient rpcClient = new Capnp.Rpc.TcpRpcClient();
rpcClient.Connect(connection.Address.Host, connection.Address.Port);
await rpcClient.WhenConnected.ConfigureAwait(false);
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
rpcClient.Dispose();
return true;
}
catch
{
return false;
}
return true;
}
/// <summary>
@ -152,11 +147,11 @@ namespace Borepin.Service.BFFH
try
{
Capnp.Rpc.TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
_APIConnection = new FabAccessAPI.Connection(rpcClient);
}
catch (Capnp.Rpc.RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
catch (RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
{
throw new ConnectingFailedException("Connecting failed", exception);
}
@ -191,11 +186,11 @@ namespace Borepin.Service.BFFH
try
{
Capnp.Rpc.TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
_APIConnection = new FabAccessAPI.Connection(rpcClient);
}
catch (Capnp.Rpc.RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
catch (RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
{
throw new ConnectingFailedException("Connecting failed", exception);
}
@ -237,11 +232,11 @@ namespace Borepin.Service.BFFH
try
{
Capnp.Rpc.TcpRpcClient rpcClient = await _ConnectAsync(_CurrentConnection.Address.Host, _CurrentConnection.Address.Port).ConfigureAwait(false);
TcpRpcClient rpcClient = await _ConnectAsync(_CurrentConnection.Address.Host, _CurrentConnection.Address.Port).ConfigureAwait(false);
_APIConnection = new FabAccessAPI.Connection(rpcClient);
}
catch (Capnp.Rpc.RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
catch (RpcException exception) when (string.Equals(exception.Message, "TcpRpcClient is unable to connect", StringComparison.Ordinal))
{
throw new ReconnectingFailedException("Connecting failed", new ConnectingFailedException("Connecting failed", exception));
}
@ -270,34 +265,14 @@ namespace Borepin.Service.BFFH
}
#region FabAccess API Systems
public async Task<IMachineSystem> GetMachineSystemInterface()
public async Task<Session> GetSession()
{
if (!IsConnected)
{
await Reconnect().ConfigureAwait(false);
}
return await _APIConnection.AccessMachineSystem().ConfigureAwait(false);
}
public async Task<IUserSystem> GetUserSystemInterface()
{
if (!IsConnected)
{
await Reconnect().ConfigureAwait(false);
}
return await _APIConnection.AccessUserSystem().ConfigureAwait(false);
}
public async Task<IPermissionSystem> GetPermissionSystemInterface()
{
if (!IsConnected)
{
await Reconnect().ConfigureAwait(false);
}
return await _APIConnection.AccessPermissionSystem().ConfigureAwait(false);
return _APIConnection.Session;
}
#endregion
#endregion
@ -306,16 +281,27 @@ namespace Borepin.Service.BFFH
private async Task<TcpRpcClient> _ConnectAsync(string host, int port)
{
TcpRpcClient rpcClient = new TcpRpcClient();
rpcClient.ConnectionStateChanged += StateChanged;
rpcClient.Connect(host, port);
await rpcClient.WhenConnected.ConfigureAwait(false);
return rpcClient;
}
private Task<bool> _AuthenticatePlainAsync(string username, string password)
private async Task<bool> _AuthenticatePlainAsync(string username, string password)
{
return _APIConnection.Auth("PLAIN", new Dictionary<string, object>(StringComparer.Ordinal) { { "Username", username }, { "Password", password } });
try
{
await _APIConnection.Auth("PLAIN", new Dictionary<string, object>(StringComparer.Ordinal) { { "Username", username }, { "Password", password } }).ConfigureAwait(false);
return await Task.FromResult(true).ConfigureAwait(false);
}
catch(InvalidCredentialsException)
{
return await Task.FromResult(true).ConfigureAwait(false);
}
catch (AuthenticatingFailedException)
{
return await Task.FromResult(true).ConfigureAwait(false);
}
}
#endregion
}

View File

@ -22,8 +22,6 @@ namespace Borepin.Service.BFFH
Task Disconnect();
Task<IMachineSystem> GetMachineSystemInterface();
Task<IPermissionSystem> GetPermissionSystemInterface();
Task<IUserSystem> GetUserSystemInterface();
Task<Session> GetSession();
}
}