mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
Update: API Connection in BFFHService
This commit is contained in:
parent
2eebf91aab
commit
9103a5959f
@ -30,7 +30,7 @@ namespace Borepin.Model
|
|||||||
Manager = new UserVisualize(_Machine.Manager);
|
Manager = new UserVisualize(_Machine.Manager);
|
||||||
Manager.LoadData();
|
Manager.LoadData();
|
||||||
|
|
||||||
MachineInfoExtended machineInfoExtended = (await _Machine.Info.GetMachineInfoExtended().ConfigureAwait(false)).Item1;
|
MachineInfoExtended machineInfoExtended = await _Machine.Manage.GetMachineInfoExtended().ConfigureAwait(false);
|
||||||
if(machineInfoExtended != null)
|
if(machineInfoExtended != null)
|
||||||
{
|
{
|
||||||
if (machineInfoExtended.CurrentUser == null || machineInfoExtended.CurrentUser.Username == null)
|
if (machineInfoExtended.CurrentUser == null || machineInfoExtended.CurrentUser.Username == null)
|
||||||
@ -43,13 +43,13 @@ namespace Borepin.Model
|
|||||||
CurrentUser.LoadData();
|
CurrentUser.LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (machineInfoExtended.TransferUser == null || machineInfoExtended.TransferUser.Username == null)
|
if (machineInfoExtended.LastUser == null || machineInfoExtended.LastUser.Username == null)
|
||||||
{
|
{
|
||||||
LastUser = null;
|
LastUser = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LastUser = new UserVisualize(machineInfoExtended.TransferUser);
|
LastUser = new UserVisualize(machineInfoExtended.LastUser);
|
||||||
LastUser.LoadData();
|
LastUser.LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ namespace Borepin.Model
|
|||||||
|
|
||||||
CanUse = !((UseInterface_Proxy)_Machine.Use).IsNull;
|
CanUse = !((UseInterface_Proxy)_Machine.Use).IsNull;
|
||||||
CanInUse = !((InUseInterface_Proxy) _Machine.Inuse).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;
|
CanCheck = !((CheckInterface_Proxy) _Machine.Check).IsNull;
|
||||||
CanManage = !((ManageInterface_Proxy) _Machine.Manage).IsNull;
|
CanManage = !((ManageInterface_Proxy) _Machine.Manage).IsNull;
|
||||||
CanAdmin = !((AdminInterface_Proxy) _Machine.Admin).IsNull;
|
CanAdmin = !((AdminInterface_Proxy) _Machine.Admin).IsNull;
|
||||||
@ -140,7 +140,7 @@ namespace Borepin.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool _CanTransfer;
|
private bool _CanTransfer;
|
||||||
public bool CanTransfer
|
public bool CanTakeOver
|
||||||
{
|
{
|
||||||
get => _CanTransfer;
|
get => _CanTransfer;
|
||||||
set => SetProperty(ref _CanTransfer, value);
|
set => SetProperty(ref _CanTransfer, value);
|
||||||
|
@ -49,10 +49,10 @@ namespace Borepin.PageModel
|
|||||||
|
|
||||||
IsConnected = true;
|
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);
|
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);
|
UserSystem.IInfoInterface user_infoInterface = await userSystem.Info().ConfigureAwait(false);
|
||||||
User user_self = (await user_infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
User user_self = (await user_infoInterface.GetUserSelf().ConfigureAwait(false)).Item1;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ namespace Borepin.PageModel
|
|||||||
{
|
{
|
||||||
MachineListItemViewModel new_viewmodel = new MachineListItemViewModel(machine)
|
MachineListItemViewModel new_viewmodel = new MachineListItemViewModel(machine)
|
||||||
{
|
{
|
||||||
IsUserAssigned = true
|
IsUserAssigned = true,
|
||||||
};
|
};
|
||||||
viewmodel_list_user_assigned.Add(new_viewmodel);
|
viewmodel_list_user_assigned.Add(new_viewmodel);
|
||||||
}
|
}
|
||||||
@ -156,10 +156,10 @@ namespace Borepin.PageModel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMachineSystem machineInterface = await _BFFHService.GetMachineSystemInterface().ConfigureAwait(false);
|
IMachineSystem machineInterface = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
|
||||||
MachineSystem.IInfoInterface infoInterface = await machineInterface.Info().ConfigureAwait(false);
|
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)
|
if(machine == null)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ namespace Borepin.PageModel
|
|||||||
IMachineSystem machineSystem;
|
IMachineSystem machineSystem;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
machineSystem = await _BFFHService.GetMachineSystemInterface().ConfigureAwait(false);
|
machineSystem = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
|
||||||
}
|
}
|
||||||
catch(ReconnectingFailedException)
|
catch(ReconnectingFailedException)
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ namespace Borepin.PageModel
|
|||||||
|
|
||||||
IInfoInterface info = await machineSystem.Info().ConfigureAwait(false);
|
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 = new MachineVisualize(_Machine);
|
||||||
MachineItem.LoadData();
|
MachineItem.LoadData();
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ using Borepin.Model.Storage;
|
|||||||
using Borepin.Service.BFFH.Exceptions;
|
using Borepin.Service.BFFH.Exceptions;
|
||||||
using Borepin.Service.Storage.Exceptions;
|
using Borepin.Service.Storage.Exceptions;
|
||||||
using Capnp.Rpc;
|
using Capnp.Rpc;
|
||||||
|
using FabAccessAPI.Exceptions;
|
||||||
|
|
||||||
namespace Borepin.Service.BFFH
|
namespace Borepin.Service.BFFH
|
||||||
{
|
{
|
||||||
@ -60,12 +61,7 @@ namespace Borepin.Service.BFFH
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Method
|
||||||
private void StateChanged(Object sender, ConnectionStateEventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all known Connections from Storage
|
/// Get all known Connections from Storage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -110,17 +106,16 @@ namespace Borepin.Service.BFFH
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Capnp.Rpc.TcpRpcClient rpcClient = new Capnp.Rpc.TcpRpcClient();
|
|
||||||
rpcClient.Connect(connection.Address.Host, connection.Address.Port);
|
TcpRpcClient rpcClient = await _ConnectAsync(connection.Address.Host, connection.Address.Port).ConfigureAwait(false);
|
||||||
await rpcClient.WhenConnected.ConfigureAwait(false);
|
|
||||||
rpcClient.Dispose();
|
rpcClient.Dispose();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -152,11 +147,11 @@ namespace Borepin.Service.BFFH
|
|||||||
|
|
||||||
try
|
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);
|
_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);
|
throw new ConnectingFailedException("Connecting failed", exception);
|
||||||
}
|
}
|
||||||
@ -191,11 +186,11 @@ namespace Borepin.Service.BFFH
|
|||||||
|
|
||||||
try
|
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);
|
_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);
|
throw new ConnectingFailedException("Connecting failed", exception);
|
||||||
}
|
}
|
||||||
@ -237,11 +232,11 @@ namespace Borepin.Service.BFFH
|
|||||||
|
|
||||||
try
|
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);
|
_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));
|
throw new ReconnectingFailedException("Connecting failed", new ConnectingFailedException("Connecting failed", exception));
|
||||||
}
|
}
|
||||||
@ -270,34 +265,14 @@ namespace Borepin.Service.BFFH
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region FabAccess API Systems
|
#region FabAccess API Systems
|
||||||
public async Task<IMachineSystem> GetMachineSystemInterface()
|
public async Task<Session> GetSession()
|
||||||
{
|
{
|
||||||
if (!IsConnected)
|
if (!IsConnected)
|
||||||
{
|
{
|
||||||
await Reconnect().ConfigureAwait(false);
|
await Reconnect().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await _APIConnection.AccessMachineSystem().ConfigureAwait(false);
|
return _APIConnection.Session;
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
@ -306,16 +281,27 @@ namespace Borepin.Service.BFFH
|
|||||||
private async Task<TcpRpcClient> _ConnectAsync(string host, int port)
|
private async Task<TcpRpcClient> _ConnectAsync(string host, int port)
|
||||||
{
|
{
|
||||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
TcpRpcClient rpcClient = new TcpRpcClient();
|
||||||
rpcClient.ConnectionStateChanged += StateChanged;
|
|
||||||
rpcClient.Connect(host, port);
|
rpcClient.Connect(host, port);
|
||||||
await rpcClient.WhenConnected.ConfigureAwait(false);
|
await rpcClient.WhenConnected.ConfigureAwait(false);
|
||||||
|
|
||||||
return rpcClient;
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@ namespace Borepin.Service.BFFH
|
|||||||
Task Disconnect();
|
Task Disconnect();
|
||||||
|
|
||||||
|
|
||||||
Task<IMachineSystem> GetMachineSystemInterface();
|
Task<Session> GetSession();
|
||||||
Task<IPermissionSystem> GetPermissionSystemInterface();
|
|
||||||
Task<IUserSystem> GetUserSystemInterface();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user