2023-06-15 18:25:32 +02:00
|
|
|
|
using Logging;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using Tranga.NotificationManagers;
|
|
|
|
|
|
|
|
|
|
namespace Tranga;
|
|
|
|
|
|
|
|
|
|
public abstract class NotificationManager
|
|
|
|
|
{
|
2023-07-09 21:38:49 +02:00
|
|
|
|
protected Logger? logger;
|
2023-06-20 14:59:08 +02:00
|
|
|
|
public NotificationManagerType notificationManagerType;
|
2023-06-15 18:25:32 +02:00
|
|
|
|
|
|
|
|
|
protected NotificationManager(NotificationManagerType notificationManagerType, Logger? logger = null)
|
|
|
|
|
{
|
|
|
|
|
this.notificationManagerType = notificationManagerType;
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 18:50:02 +02:00
|
|
|
|
public enum NotificationManagerType : byte { Gotify = 0, LunaSea = 1 }
|
2023-06-15 18:25:32 +02:00
|
|
|
|
|
|
|
|
|
public abstract void SendNotification(string title, string notificationText);
|
2023-07-09 21:38:49 +02:00
|
|
|
|
|
|
|
|
|
public void AddLogger(Logger pLogger)
|
|
|
|
|
{
|
|
|
|
|
this.logger = pLogger;
|
|
|
|
|
}
|
2023-06-15 18:25:32 +02:00
|
|
|
|
|
|
|
|
|
public class NotificationManagerJsonConverter : JsonConverter
|
|
|
|
|
{
|
|
|
|
|
public override bool CanConvert(Type objectType)
|
|
|
|
|
{
|
|
|
|
|
return (objectType == typeof(NotificationManager));
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-19 11:27:07 +02:00
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue,
|
|
|
|
|
JsonSerializer serializer)
|
2023-06-15 18:25:32 +02:00
|
|
|
|
{
|
|
|
|
|
JObject jo = JObject.Load(reader);
|
|
|
|
|
if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationManagerType.Gotify)
|
|
|
|
|
return jo.ToObject<Gotify>(serializer)!;
|
2023-06-19 11:27:07 +02:00
|
|
|
|
else if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationManagerType.LunaSea)
|
|
|
|
|
return jo.ToObject<LunaSea>(serializer)!;
|
2023-06-15 18:25:32 +02:00
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|