add server status & capabilities
This commit is contained in:
@@ -20,7 +20,7 @@ public class ApiServer : IApiServer
|
||||
protected readonly Dictionary<Type, IApiMessageSerializer> serializers = [];
|
||||
protected readonly Dictionary<ThreadHolder, IDataManager> managers = [];
|
||||
protected HttpListener httpListener;
|
||||
protected int restartAttempts = 0;
|
||||
protected uint restartAttempts = 0;
|
||||
protected DateTime lastRestartAttempt;
|
||||
protected SemaphoreSlim? semaphore;
|
||||
protected bool doListen;
|
||||
@@ -36,6 +36,10 @@ public class ApiServer : IApiServer
|
||||
protected record PrivateMessageHandler(string Url, bool UseRegEx, Delegate Handler, PrivateParameterInfo[] Parameters, ApiMessageHandlerAttribute Attribute);
|
||||
protected record PrivateApiResult(ApiResult Original, object? ResultContent);
|
||||
|
||||
public int HandlersCount => handlers.Count;
|
||||
public int ManagersCount => managers.Count;
|
||||
public uint RestartAttempts => restartAttempts;
|
||||
|
||||
public string ApiUrl { get; }
|
||||
public uint ApiVersion { get; set; } = 1;
|
||||
public virtual bool EnableAuth { get; set; }
|
||||
@@ -112,11 +116,6 @@ public class ApiServer : IApiServer
|
||||
Receive();
|
||||
}
|
||||
|
||||
public virtual void Stop()
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
|
||||
public virtual void Stop(bool graceful)
|
||||
{
|
||||
Log.Info("Stopping listener");
|
||||
@@ -184,6 +183,15 @@ public class ApiServer : IApiServer
|
||||
semaphore.Release();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<string> GetEndpoints()
|
||||
{
|
||||
return handlers.SelectMany(n => n.Attribute.Methods.Select(m => new
|
||||
{
|
||||
n.Attribute.Route,
|
||||
Method = m,
|
||||
})).OrderBy(n => n.Route).ThenBy(n => n.Method).Select(n => $"{n.Method} {n.Route}");
|
||||
}
|
||||
|
||||
public virtual void RegisterHandler<T>(T instance) where T : class
|
||||
{
|
||||
// Initialize
|
||||
|
||||
Reference in New Issue
Block a user