using System;
using System.Threading;
using System.Threading.Tasks;
namespace Wino.Core.Domain.Interfaces;
///
/// Simple wrapper class to maintain compatibility with the original WinoServerResponse structure.
///
/// Type of the expected response.
public class WinoServerResponse
{
public bool IsSuccess { get; set; }
public string Message { get; set; }
public T Data { get; set; }
public static WinoServerResponse CreateSuccessResponse(T data)
{
return new WinoServerResponse
{
IsSuccess = true,
Data = data
};
}
public static WinoServerResponse CreateErrorResponse(string message)
{
return new WinoServerResponse
{
IsSuccess = false,
Message = message
};
}
public void ThrowIfFailed()
{
if (!IsSuccess)
throw new InvalidOperationException(Message);
}
}
///
/// Connection status enum to maintain compatibility.
///
public enum WinoServerConnectionStatus
{
None,
Connecting,
Connected,
Disconnected,
Failed
}
public interface IWinoServerConnectionManager
{
///
/// When the connection status changes, this event will be triggered.
///
event EventHandler StatusChanged;
///
/// Gets the connection status.
///
WinoServerConnectionStatus Status { get; }
///
/// Launches Full Trust process (Wino Server) and awaits connection completion.
/// If connection is not established in 10 seconds, it will return false.
/// If the server process is already running, it'll connect to existing one.
/// If the server process is not running, it'll be launched and connection establishment is awaited.
///
/// Whether connection is established or not.
Task ConnectAsync();
///
/// Queues a new user request to be processed by Wino Server.
/// Healthy connection must present before calling this method.
///
/// Request to queue for synchronizer in the server.
/// Account id to queueu request for.
Task QueueRequestAsync(IRequestBase request, Guid accountId);
///
/// Returns response from server for the given request.
///
/// Response type.
/// Request type.
/// Request type.
/// Response received from the server for the given TResponse type.
Task> GetResponseAsync(TRequestType clientMessage, CancellationToken cancellationToken = default) where TRequestType : IClientMessage;
///
/// Handle for connecting to the server.
/// If the server is already running, it'll connect to existing one.
/// Callers can await this handle to wait for connection establishment.
///
TaskCompletionSource ConnectingHandle { get; }
}
public interface IWinoServerConnectionManager : IWinoServerConnectionManager, IInitializeAsync
{
///
/// Existing connection handle to the server of TAppServiceConnection type.
///
TAppServiceConnection Connection { get; set; }
}