mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-06-11 11:03:23 +02:00
Added more new API Class
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using Capnp.Rpc;
|
||||
using FabAccessAPI.Exceptions;
|
||||
using FabAccessAPI.Schema;
|
||||
using NLog;
|
||||
using S22.Sasl;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -14,6 +15,10 @@ namespace FabAccessAPI
|
||||
{
|
||||
public class API : IAPI
|
||||
{
|
||||
#region Logger
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
private TcpRpcClient _TcpRpcClient;
|
||||
private IBootstrap _Bootstrap;
|
||||
@ -40,11 +45,14 @@ namespace FabAccessAPI
|
||||
|
||||
if (args.LastState == ConnectionState.Initializing && args.NewState == ConnectionState.Active)
|
||||
{
|
||||
Log.Trace("TcpRpcClient Event Connected");
|
||||
eventHandler(this, ConnectionStatusChange.Connected);
|
||||
}
|
||||
if (args.LastState == ConnectionState.Active && args.NewState == ConnectionState.Down)
|
||||
{
|
||||
Log.Trace("TcpRpcClient Event ConnectionLoss");
|
||||
eventHandler(this, ConnectionStatusChange.ConnectionLoss);
|
||||
_TcpRpcClient = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -98,11 +106,14 @@ namespace FabAccessAPI
|
||||
|
||||
Session = await _Authenticate(connectionData).ConfigureAwait(false);
|
||||
ConnectionData = connectionData;
|
||||
|
||||
Log.Info("API connected");
|
||||
}
|
||||
catch(System.Exception)
|
||||
catch(System.Exception ex)
|
||||
{
|
||||
await Disconnect().ConfigureAwait(false);
|
||||
throw;
|
||||
Log.Warn(ex, "API connecting failed");
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +132,8 @@ namespace FabAccessAPI
|
||||
|
||||
ConnectionStatusChanged?.Invoke(this, ConnectionStatusChange.Disconnected);
|
||||
|
||||
Log.Info("API disconnected");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@ -132,6 +145,7 @@ namespace FabAccessAPI
|
||||
}
|
||||
|
||||
ConnectionStatusChanged?.Invoke(this, ConnectionStatusChange.Reconnected);
|
||||
Log.Info("API reconnected");
|
||||
}
|
||||
|
||||
public async Task<ConnectionInfo> TestConnection(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null)
|
||||
|
@ -12,8 +12,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.118" />
|
||||
<PackageReference Include="log4net" Version="2.0.14" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||
<PackageReference Include="NLog" Version="4.7.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -37,7 +37,7 @@ namespace FabAccessAPI
|
||||
/// Connect to BFFH Server
|
||||
/// </summary>
|
||||
/// <param name="connectionData"></param>
|
||||
Task Connect(ConnectionData connectionData, TcpRpcClient tcpRpcClient);
|
||||
Task Connect(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null);
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect from BFFH Server
|
||||
@ -53,6 +53,6 @@ namespace FabAccessAPI
|
||||
/// Connect to Server and get ConnectionInfo.
|
||||
/// The Connection is not maintained.
|
||||
/// </summary>
|
||||
Task<ConnectionInfo> TestConnection(ConnectionData connectionData, TcpRpcClient tcpRpcClient);
|
||||
Task<ConnectionInfo> TestConnection(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user