rename MessageSerializer to ApiMessageSerializer

This commit is contained in:
2024-10-17 10:10:00 +02:00
parent 9c1723cb0e
commit 8a8407d86e
7 changed files with 17 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ namespace Pilz.Net.Api;
public class ApiServer(string apiUrl) : IApiServer
{
protected readonly Dictionary<string, Delegate> handlers = [];
protected readonly Dictionary<Type, IMessageSerializer> serializers = [];
protected readonly Dictionary<Type, IApiMessageSerializer> serializers = [];
protected readonly HttpListener httpListener = new();
public event OnCheckAuthenticationEventHandler? OnCheckAuthentication;
@@ -20,7 +20,7 @@ public class ApiServer(string apiUrl) : IApiServer
public virtual bool EnableAuth { get; set; }
public IMessageSerializer Serializer { get; set; } = new DefaultMessageSerializer();
public IApiMessageSerializer Serializer { get; set; } = new DefaultApiMessageSerializer();
public ILogger Log { get; set; } = NullLogger.Instance;
@@ -58,7 +58,7 @@ public class ApiServer(string apiUrl) : IApiServer
var method = handler.Method;
// Sanity checks
if (method.GetCustomAttribute<MessageHandlerAttribute>() is not MessageHandlerAttribute attribute
if (method.GetCustomAttribute<ApiMessageHandlerAttribute>() is not ApiMessageHandlerAttribute attribute
|| !method.ReturnType.IsAssignableTo(typeof(ApiResult)))
{
if (throwOnError)
@@ -155,7 +155,7 @@ public class ApiServer(string apiUrl) : IApiServer
// Get handler
Log.Debug("Find handler");
if (!handlers.TryGetValue(url, out var handler)
|| handler.Method.GetCustomAttribute<MessageHandlerAttribute>() is not MessageHandlerAttribute attribute)
|| handler.Method.GetCustomAttribute<ApiMessageHandlerAttribute>() is not ApiMessageHandlerAttribute attribute)
return null;
// Check authentication
@@ -220,13 +220,13 @@ public class ApiServer(string apiUrl) : IApiServer
return [.. objs];
}
protected virtual IMessageSerializer GetSerializer(Type? t)
protected virtual IApiMessageSerializer GetSerializer(Type? t)
{
if (t is not null)
{
if (serializers.TryGetValue(t, out var s) && s is not null)
return s;
else if (Activator.CreateInstance(t) is IMessageSerializer ss)
else if (Activator.CreateInstance(t) is IApiMessageSerializer ss)
{
serializers.Add(t, ss);
return ss;