From 4d1e43e7b33db8186ac0bc38c4b8144d55717848 Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 26 Aug 2023 02:40:24 +0200 Subject: [PATCH] Job: add Id --- Tranga/Jobs/DownloadChapter.cs | 8 +++++++- Tranga/Jobs/DownloadNewChapters.cs | 8 +++++++- Tranga/Jobs/Job.cs | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Tranga/Jobs/DownloadChapter.cs b/Tranga/Jobs/DownloadChapter.cs index 61048bd..c9674b6 100644 --- a/Tranga/Jobs/DownloadChapter.cs +++ b/Tranga/Jobs/DownloadChapter.cs @@ -1,4 +1,5 @@ -using Tranga.MangaConnectors; +using System.Text; +using Tranga.MangaConnectors; namespace Tranga.Jobs; @@ -10,6 +11,11 @@ public class DownloadChapter : Job { this.chapter = chapter; } + + protected override string GetId() + { + return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), chapter.parentPublication.internalId, chapter.chapterNumber))); + } protected override IEnumerable ExecuteReturnSubTasksInternal() { diff --git a/Tranga/Jobs/DownloadNewChapters.cs b/Tranga/Jobs/DownloadNewChapters.cs index 1baeeb4..82fd440 100644 --- a/Tranga/Jobs/DownloadNewChapters.cs +++ b/Tranga/Jobs/DownloadNewChapters.cs @@ -1,4 +1,5 @@ -using Tranga.MangaConnectors; +using System.Text; +using Tranga.MangaConnectors; namespace Tranga.Jobs; @@ -11,6 +12,11 @@ public class DownloadNewChapters : Job this.publication = publication; } + protected override string GetId() + { + return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), publication.internalId))); + } + protected override IEnumerable ExecuteReturnSubTasksInternal() { Chapter[] chapters = mangaConnector.GetNewChapters(publication); diff --git a/Tranga/Jobs/Job.cs b/Tranga/Jobs/Job.cs index e302052..4024b6d 100644 --- a/Tranga/Jobs/Job.cs +++ b/Tranga/Jobs/Job.cs @@ -10,6 +10,7 @@ public abstract class Job : GlobalBase public TimeSpan? recurrenceTime { get; set; } public DateTime? lastExecution { get; private set; } public DateTime nextExecution => NextExecution(); + public string id => GetId(); public Job(GlobalBase clone, MangaConnector connector, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone) { @@ -21,6 +22,8 @@ public abstract class Job : GlobalBase this.recurrenceTime = recurrenceTime; } + protected abstract string GetId(); + public Job(GlobalBase clone, MangaConnector connector, ProgressToken progressToken, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone) { this.mangaConnector = connector;