From 124c644db12bd7cce5b6ace39b4624c7b56449fb Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 19 May 2023 20:03:17 +0200 Subject: [PATCH] Added summary for TaskExecutor, TaskManager, TrangaTask --- Tranga/TaskExecutor.cs | 13 +++++++++++++ Tranga/TaskManager.cs | 43 ++++++++++++++++++++++++++++++++++++++++++ Tranga/TrangaTask.cs | 7 +++++++ 3 files changed, 63 insertions(+) diff --git a/Tranga/TaskExecutor.cs b/Tranga/TaskExecutor.cs index deb5666..4f55ef3 100644 --- a/Tranga/TaskExecutor.cs +++ b/Tranga/TaskExecutor.cs @@ -1,7 +1,20 @@ namespace Tranga; +/// +/// Executes TrangaTasks +/// Based on the TrangaTask.Task a method is called. +/// The chapterCollection is updated with new Publications/Chapters. +/// public static class TaskExecutor { + + /// + /// Executes TrangaTask. + /// + /// List of all available Connectors + /// Task to execute + /// Current chapterCollection to update + /// Is thrown when there is no Connector available with the name of the TrangaTask.connectorName public static void Execute(Connector[] connectors, TrangaTask trangaTask, Dictionary> chapterCollection) { Connector? connector = connectors.FirstOrDefault(c => c.name == trangaTask.connectorName); diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 02bb3d3..6a510e1 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -3,6 +3,10 @@ using Tranga.Connectors; namespace Tranga; +/// +/// Manages all TrangaTasks. +/// Provides a Threaded environment to execute Tasks, and still manage the Task-Collection +/// public class TaskManager { private readonly Dictionary> _chapterCollection; @@ -11,6 +15,10 @@ public class TaskManager private readonly Connector[] connectors; private readonly string folderPath; + /// + /// + /// + /// Local path to save data (Manga) to public TaskManager(string folderPath) { this.folderPath = folderPath; @@ -34,6 +42,10 @@ public class TaskManager } } + /// + /// Forces the execution of a given task + /// + /// Task to execute public void ExecuteTaskNow(TrangaTask task) { if (!this._allTasks.Contains(task)) @@ -46,6 +58,15 @@ public class TaskManager t.Start(); } + /// + /// Creates and adds a new Task to the task-Collection + /// + /// TrangaTask.Task to later execute + /// Name of the connector to use + /// Publication to execute Task on, can be null in case of unrelated Task + /// Time-Interval between Executions + /// language, should Task require parameter. Can be empty + /// Is thrown when connectorName is not a available Connector public void AddTask(TrangaTask.Task task, string connectorName, Publication? publication, TimeSpan reoccurrence, string language = "") { @@ -63,6 +84,12 @@ public class TaskManager } } + /// + /// Removes Task from task-collection + /// + /// TrangaTask.Task type + /// Name of Connector that was used + /// Publication that was used public void RemoveTask(TrangaTask.Task task, string connectorName, Publication? publication) { _allTasks.RemoveWhere(trangaTask => @@ -71,11 +98,19 @@ public class TaskManager ExportTasks(Directory.GetCurrentDirectory()); } + /// + /// + /// + /// All available Connectors public Dictionary GetAvailableConnectors() { return this.connectors.ToDictionary(connector => connector.name, connector => connector); } + /// + /// + /// + /// All TrangaTasks in task-collection public TrangaTask[] GetAllTasks() { TrangaTask[] ret = new TrangaTask[_allTasks.Count]; @@ -83,11 +118,19 @@ public class TaskManager return ret; } + /// + /// + /// + /// All added Publications public Publication[] GetAllPublications() { return this._chapterCollection.Keys.ToArray(); } + /// + /// Shuts down the taskManager. + /// + /// If force is true, tasks are aborted. public void Shutdown(bool force = false) { _continueRunning = false; diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index 946068f..ee308b9 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -2,6 +2,9 @@ namespace Tranga; +/// +/// Stores information on Task +/// public class TrangaTask { public TimeSpan reoccurrence { get; } @@ -24,6 +27,10 @@ public class TrangaTask this.language = language; } + /// + /// + /// + /// True if elapsed time since last execution is greater than set interval public bool ShouldExecute() { return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence;