mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-18 22:33:18 +02:00
When creating Jobs with null as recurrence time, set it to zero Job.NextExecution() removed the recurrence check
70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Tranga.MangaConnectors;
|
|
|
|
namespace Tranga.Jobs;
|
|
|
|
public class JobJsonConverter : JsonConverter
|
|
{
|
|
private GlobalBase _clone;
|
|
private MangaConnectorJsonConverter _mangaConnectorJsonConverter;
|
|
|
|
internal JobJsonConverter(GlobalBase clone, MangaConnectorJsonConverter mangaConnectorJsonConverter)
|
|
{
|
|
this._clone = clone;
|
|
this._mangaConnectorJsonConverter = mangaConnectorJsonConverter;
|
|
}
|
|
|
|
public override bool CanConvert(Type objectType)
|
|
{
|
|
return (objectType == typeof(Job));
|
|
}
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
|
{
|
|
JObject jo = JObject.Load(reader);
|
|
if (jo.ContainsKey("manga"))//DownloadNewChapters
|
|
{
|
|
return new DownloadNewChapters(this._clone,
|
|
jo.GetValue("mangaConnector")!.ToObject<MangaConnector>(JsonSerializer.Create(new JsonSerializerSettings()
|
|
{
|
|
Converters =
|
|
{
|
|
this._mangaConnectorJsonConverter
|
|
}
|
|
}))!,
|
|
jo.GetValue("manga")!.ToObject<Manga>(),
|
|
jo.GetValue("lastExecution")!.ToObject<DateTime>(),
|
|
jo.GetValue("recurring")!.Value<bool>(),
|
|
jo.GetValue("recurrenceTime")!.ToObject<TimeSpan?>(),
|
|
jo.GetValue("parentJobId")!.Value<string?>());
|
|
}
|
|
|
|
if (jo.ContainsKey("chapter"))//DownloadChapter
|
|
{
|
|
return new DownloadChapter(this._clone,
|
|
jo.GetValue("mangaConnector")!.ToObject<MangaConnector>(JsonSerializer.Create(new JsonSerializerSettings()
|
|
{
|
|
Converters =
|
|
{
|
|
this._mangaConnectorJsonConverter
|
|
}
|
|
}))!,
|
|
jo.GetValue("chapter")!.ToObject<Chapter>(),
|
|
DateTime.UnixEpoch,
|
|
jo.GetValue("parentJobId")!.Value<string?>());
|
|
}
|
|
|
|
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");
|
|
}
|
|
} |