2024-03-12 14:05:27 -04:00
|
|
|
using CommonSocketLibrary.Common;
|
2024-03-15 08:27:35 -04:00
|
|
|
using CommonSocketLibrary.Socket.Manager;
|
2024-03-12 14:05:27 -04:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-03-12 14:05:27 -04:00
|
|
|
|
2024-03-15 08:27:35 -04:00
|
|
|
namespace TwitchChatTTS.Hermes.Socket.Managers
|
2024-03-12 14:05:27 -04:00
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
public class HermesHandlerManager : WebSocketHandlerManager
|
2024-03-12 14:05:27 -04:00
|
|
|
{
|
2024-06-16 20:19:31 -04:00
|
|
|
public HermesHandlerManager(ILogger logger, IServiceProvider provider) : base(logger)
|
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
//Add(provider.GetRequiredService<HeartbeatHandler>());
|
2024-06-16 20:19:31 -04:00
|
|
|
try
|
|
|
|
{
|
2024-03-12 14:05:27 -04:00
|
|
|
var basetype = typeof(IWebSocketHandler);
|
|
|
|
var assembly = GetType().Assembly;
|
2024-03-15 08:27:35 -04:00
|
|
|
var types = assembly.GetTypes().Where(t => t.IsClass && basetype.IsAssignableFrom(t) && t.AssemblyQualifiedName?.Contains(".Hermes.") == true);
|
2024-03-12 14:05:27 -04:00
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
foreach (var type in types)
|
|
|
|
{
|
2024-03-15 08:27:35 -04:00
|
|
|
var key = "hermes-" + type.Name.Replace("Handlers", "Hand#lers")
|
2024-03-12 14:05:27 -04:00
|
|
|
.Replace("Handler", "")
|
|
|
|
.Replace("Hand#lers", "Handlers")
|
|
|
|
.ToLower();
|
|
|
|
var handler = provider.GetKeyedService<IWebSocketHandler>(key);
|
2024-06-16 20:19:31 -04:00
|
|
|
if (handler == null)
|
|
|
|
{
|
|
|
|
logger.Error("Failed to find hermes websocket handler: " + type.AssemblyQualifiedName);
|
2024-03-12 14:05:27 -04:00
|
|
|
continue;
|
|
|
|
}
|
2024-06-16 20:19:31 -04:00
|
|
|
|
|
|
|
Logger.Debug($"Linked type {type.AssemblyQualifiedName} to hermes websocket handlers.");
|
2024-03-12 14:05:27 -04:00
|
|
|
Add(handler);
|
|
|
|
}
|
2024-06-16 20:19:31 -04:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.Error(e, "Failed to load hermes websocket handler types.");
|
2024-03-12 14:05:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|