From 4240a1eb6a564b74462f426419d3e250621f91ec Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 27 Aug 2023 01:01:20 +0200 Subject: [PATCH] Added methods to search for jobs, and remove multiple jobs. --- Tranga/Jobs/JobBoss.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index f688613..5838c7a 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -24,6 +24,45 @@ public class JobBoss : GlobalBase this.jobs.Remove(job); } + public void RemoveJobs(IEnumerable jobs) + { + foreach (Job job in jobs) + { + job.Cancel(); + this.jobs.Remove(job); + } + } + + public IEnumerable GetJobsLike(string? connectorName = null, string? internalId = null, string? chapterNumber = null) + { + IEnumerable ret = this.jobs; + if (connectorName is not null) + ret = ret.Where(job => job.mangaConnector.name == connectorName); + + if (internalId is not null && chapterNumber is not null) + ret = ret.Where(jjob => + { + if (jjob is not DownloadChapter job) + return false; + return job.chapter.parentPublication.internalId == internalId && + job.chapter.chapterNumber == chapterNumber; + }); + else if (internalId is not null) + ret = ret.Where(jjob => + { + if (jjob is not DownloadNewChapters job) + return false; + return job.publication.internalId == internalId; + }); + return ret; + } + + public IEnumerable GetJobsLike(MangaConnector? mangaConnector = null, Publication? publication = null, + Chapter? chapter = null) + { + return GetJobsLike(mangaConnector?.name, publication?.internalId, chapter?.chapterNumber); + } + private bool QueueContainsJob(Job job) { mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue());