85 lines
3.2 KiB
C#
Raw Permalink Normal View History

2023-01-25 01:48:54 +01:00
using System;
2022-05-11 15:02:17 +02:00
using System.Threading.Tasks;
2023-01-25 01:48:54 +01:00
using Capnp.Rpc;
using FabAccessAPI.Exceptions;
using FabAccessAPI.Schema;
2022-05-10 13:35:23 +02:00
namespace FabAccessAPI
{
2023-01-25 01:48:54 +01:00
/// <summary>
/// Service to connect to a server and maintain the connection
/// </summary>
2022-05-10 13:35:23 +02:00
public interface IAPI
{
2023-01-25 01:48:54 +01:00
#region Information about a connection and the server
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// State of the conneciton, is the API-Service connecting to a server
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
bool IsConnecting { get; }
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// State of the conneciton, is the API-Service connected to a server
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
bool IsConnected { get; }
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Information about the connection
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
/// <exception cref="InvalidOperationException"> When API-Service is not connected or trying to connected to a server </exception>
ConnectionData ConnectionData { get; }
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Information about the server
/// Is only avalible if the API-Service is connected
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
/// <exception cref="InvalidOperationException"> When API-Service is not connected </exception>
ServerData ServerData { get; }
#endregion
2022-05-10 13:35:23 +02:00
2023-01-25 01:48:54 +01:00
#region Methods to connect to server
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Connect to server with ConnectionData
/// If connection lost, the API-Server will try to reconnect
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
/// <param name="connectionData"> Data to establish a connection to a server </param>
/// <exception cref="ConnectionException"> When API-Service can not connect to a server </exception>
/// <exception cref="AuthenticationException"> When API-Service can connect to a server but can not authenticate </exception>
/// <exception cref="InvalidOperationException"> When API-Service is allready connected </exception>
Task Connect(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null);
2022-05-10 13:35:23 +02:00
2022-05-17 23:23:47 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Disconnect from a server
2022-05-17 23:23:47 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
/// <exception cref="InvalidOperationException"> When API-Service is not connected or trying to connect </exception>
Task Disconnect();
2022-05-17 23:23:47 +02:00
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Try to connect to a server and get ServerData
/// The connection is not maintained
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
/// <exception cref="ConnectionException"> When API-Service can not connect to a server </exception>
Task<ServerData> TryToConnect(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null);
#endregion
2022-05-10 13:35:23 +02:00
2023-01-25 01:48:54 +01:00
#region Session
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Get session after connection
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
/// <exception cref="InvalidOperationException"> When API-Service is not connected </exception>
Session Session { get; }
#endregion
2022-05-10 13:35:23 +02:00
2023-01-25 01:48:54 +01:00
#region Events
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Event on changes in connection status
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
event EventHandler<ConnectionStatusChanged> ConnectionStatusChanged;
2022-05-10 13:35:23 +02:00
/// <summary>
2023-01-25 01:48:54 +01:00
/// Unbind all handlers from EventHandler<ConnectionStatusChanged>
2022-05-10 13:35:23 +02:00
/// </summary>
2023-01-25 01:48:54 +01:00
void UnbindEventHandler();
#endregion
2022-05-10 13:35:23 +02:00
}
}