namespace Tranga; public static class TaskExecutor { public static void Execute(TrangaTask trangaTask, Dictionary> chapterCollection) { switch (trangaTask.task) { case TrangaTask.Task.DownloadNewChapters: DownloadNewChapters(trangaTask.connector, trangaTask.publication, trangaTask.language, chapterCollection); break; case TrangaTask.Task.UpdateChapters: UpdateChapters(trangaTask.connector, trangaTask.publication, trangaTask.language, chapterCollection); break; case TrangaTask.Task.UpdatePublications: UpdatePublications(trangaTask.connector, chapterCollection); break; } } private static void UpdatePublications(Connector connector, Dictionary> chapterCollection) { Publication[] publications = connector.GetPublications(); foreach (Publication publication in publications) chapterCollection.TryAdd(publication, new List()); } private static void DownloadNewChapters(Connector connector, Publication publication, string language, Dictionary> chapterCollection) { List newChapters = UpdateChapters(connector, publication, language, chapterCollection); foreach(Chapter newChapter in newChapters) connector.DownloadChapter(publication, newChapter); } private static List UpdateChapters(Connector connector, Publication publication, string language, Dictionary> chapterCollection) { List newChaptersList = new(); if (!chapterCollection.ContainsKey(publication)) return newChaptersList; List currentChapters = chapterCollection[publication]; Chapter[] newChapters = connector.GetChapters(publication, language); newChaptersList = newChapters.ToList() .ExceptBy(currentChapters.Select(cChapter => cChapter.url), nChapter => nChapter.url).ToList(); return newChaptersList; } }