From 1f8e8fb74021e831bfee57d176d4eb6e35cbde6d Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 18 May 2023 21:03:03 +0200 Subject: [PATCH] Fixed Capitalization Added fields for serialization --- Tranga/TaskManager.cs | 2 +- Tranga/TrangaTask.cs | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 4d6885d..eae4af6 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -14,7 +14,7 @@ public class TaskManager taskChecker.Start(); } - public void AddTask(Connector connector, TrangaTask.availableTasks task, TimeSpan reoccurrence, Publication? publication = null, string language = "en") + public void AddTask(Connector connector, TrangaTask.AvailableTasks task, TimeSpan reoccurrence, Publication? publication = null, string language = "en") { this._allTasks.Add(new TrangaTask(connector, task, reoccurrence, publication, language)); } diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index d7ef34a..e5b82e0 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -1,30 +1,36 @@ -namespace Tranga; +using System.Text.Json.Serialization; + +namespace Tranga; public class TrangaTask { - public TimeSpan reoccurrence { get; } - public DateTime lastExecuted { get; private set; } - public Connector connector { get; } - public availableTasks availableTaskToExecute { get; } - public enum availableTasks + [JsonInclude]public TimeSpan reoccurrence { get; } + [JsonInclude]public DateTime lastExecuted { get; private set; } + [JsonIgnore] private Connector connector { get; } + [JsonInclude] public string connectorName; + [JsonInclude]public AvailableTasks task { get; } + public enum AvailableTasks { - downloadNewChapters, - updateChapters, - updatePublications + DownloadNewChapters, + UpdateChapters, + UpdatePublications }; - public Publication? publication { get; } - public string language { get; } + [JsonIgnore]public Publication? publication { get; } + [JsonInclude]public string? publicationIdentifier; + [JsonInclude]public string language { get; } - public TrangaTask(Connector connector, availableTasks availableTask, TimeSpan reoccurrence, Publication? publication = null, string language = "en") + public TrangaTask(Connector connector, AvailableTasks task, TimeSpan reoccurrence, Publication? publication = null, string language = "en") { this.connector = connector; - this.availableTaskToExecute = availableTask; + this.connectorName = connector.name; + this.task = task; this.lastExecuted = DateTime.Now.Subtract(reoccurrence); this.reoccurrence = reoccurrence; this.publication = publication; + this.publicationIdentifier = publication?.downloadUrl; this.language = language; - if (publication is null && availableTask is availableTasks.updateChapters or availableTasks.downloadNewChapters) + if (publication is null && task is AvailableTasks.UpdateChapters or AvailableTasks.DownloadNewChapters) { if (publication is null) throw new ArgumentException( @@ -34,15 +40,15 @@ public class TrangaTask public void Execute(ref Dictionary chapterCollection) { - switch (this.availableTaskToExecute) + switch (this.task) { - case availableTasks.updateChapters: + case AvailableTasks.UpdateChapters: UpdateChapters(ref chapterCollection); break; - case availableTasks.updatePublications: + case AvailableTasks.UpdatePublications: UpdatePublications(ref chapterCollection); break; - case availableTasks.downloadNewChapters: + case AvailableTasks.DownloadNewChapters: DownloadNewChapters(UpdateChapters(ref chapterCollection)); break; }