mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-06-14 07:47:54 +02:00
Moved class to appropriate namespaces
This commit is contained in:
56
Tranga/NotificationManagers/NotificationManager.cs
Normal file
56
Tranga/NotificationManagers/NotificationManager.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tranga.NotificationManagers;
|
||||
|
||||
public abstract class NotificationManager
|
||||
{
|
||||
protected Logger? logger;
|
||||
public NotificationManagerType notificationManagerType;
|
||||
|
||||
protected NotificationManager(NotificationManagerType notificationManagerType, Logger? logger = null)
|
||||
{
|
||||
this.notificationManagerType = notificationManagerType;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public enum NotificationManagerType : byte { Gotify = 0, LunaSea = 1 }
|
||||
|
||||
public abstract void SendNotification(string title, string notificationText);
|
||||
|
||||
public void AddLogger(Logger pLogger)
|
||||
{
|
||||
this.logger = pLogger;
|
||||
}
|
||||
|
||||
public class NotificationManagerJsonConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof(NotificationManager));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationManagerType.Gotify)
|
||||
return jo.ToObject<Gotify>(serializer)!;
|
||||
else if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationManagerType.LunaSea)
|
||||
return jo.ToObject<LunaSea>(serializer)!;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
/// <summary>
|
||||
/// Don't call this
|
||||
/// </summary>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new Exception("Dont call this");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user