From d62b0bdf34ea4e7bde24cc72b09cc2892862baaf Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 20 May 2023 22:10:24 +0200 Subject: [PATCH] Changed Logger to accept string as caller Added Logger to all relevant methods --- Logging/Logger.cs | 4 +-- Logging/LoggerBase.cs | 13 ++++--- Tranga-CLI/Tranga_Cli.cs | 66 +++++++++++++++++------------------ Tranga/Connector.cs | 14 ++++++-- Tranga/Connectors/MangaDex.cs | 13 ++++--- Tranga/Komga.cs | 11 ++++-- Tranga/TaskExecutor.cs | 13 +++++-- Tranga/TaskManager.cs | 28 ++++++++++----- 8 files changed, 100 insertions(+), 62 deletions(-) diff --git a/Logging/Logger.cs b/Logging/Logger.cs index 96e2ab3..365c690 100644 --- a/Logging/Logger.cs +++ b/Logging/Logger.cs @@ -33,14 +33,14 @@ public class Logger : TextWriter _memoryLogger = enabledLoggers.Contains(LoggerType.MemoryLogger) ? new MemoryLogger(null, encoding) : null; } - public void WriteLine(object caller, string? value) + public void WriteLine(string caller, string? value) { value = value is null ? Environment.NewLine : string.Concat(value, Environment.NewLine); Write(caller, value); } - public void Write(object caller, string? value) + public void Write(string caller, string? value) { if (value is null) return; diff --git a/Logging/LoggerBase.cs b/Logging/LoggerBase.cs index e800791..a395f3d 100644 --- a/Logging/LoggerBase.cs +++ b/Logging/LoggerBase.cs @@ -13,7 +13,7 @@ public abstract class LoggerBase : TextWriter this.stdOut = stdOut; } - public void WriteLine(object caller, string? value) + public void WriteLine(string caller, string? value) { value = value is null ? Environment.NewLine : string.Join(value, Environment.NewLine); @@ -22,7 +22,7 @@ public abstract class LoggerBase : TextWriter Write(message); } - public void Write(object caller, string? value) + public void Write(string caller, string? value) { if (value is null) return; @@ -39,21 +39,20 @@ public abstract class LoggerBase : TextWriter public class LogMessage { public DateTime logTime { get; } - public Type caller { get; } + public string caller { get; } public string value { get; } - public LogMessage(DateTime now, object caller, string value) + public LogMessage(DateTime now, string caller, string value) { this.logTime = now; - this.caller = caller.GetType(); + this.caller = caller; this.value = value; } public override string ToString() { string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToShortTimeString()}"; - string callerString = caller.ToString(); - return $"[{dateTimeString}] {callerString,-15} | {value}"; + return $"[{dateTimeString}] {caller,-30} | {value}"; } } } \ No newline at end of file diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index 8cf185a..7905c09 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -17,7 +17,7 @@ public static class Tranga_Cli Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.MemoryLogger }, null, null, Path.Join(Directory.GetCurrentDirectory(), $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt")); - logger.WriteLine(Type.Missing, "Loading Settings."); + logger.WriteLine("Tranga_CLI", "Loading Settings."); TaskManager.SettingsData settings; string settingsPath = Path.Join(Directory.GetCurrentDirectory(), "data.json"); if (File.Exists(settingsPath)) @@ -26,7 +26,7 @@ public static class Tranga_Cli settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), null, new HashSet()); - logger.WriteLine(Type.Missing, "User Input"); + logger.WriteLine("Tranga_CLI", "User Input"); Console.WriteLine($"Output folder path [{settings.downloadLocation}]:"); string? tmpPath = Console.ReadLine(); while(tmpPath is null) @@ -65,16 +65,16 @@ public static class Tranga_Cli } } while (key != ConsoleKey.Enter); - settings.komga = new Komga(tmpUrl, tmpUser, tmpPass); + settings.komga = new Komga(tmpUrl, tmpUser, tmpPass, logger); } - logger.WriteLine(Type.Missing, "Loaded."); + logger.WriteLine("Tranga_CLI", "Loaded."); TaskMode(settings, logger); } private static void TaskMode(TaskManager.SettingsData settings, Logger logger) { - TaskManager taskManager = new (settings); + TaskManager taskManager = new (settings, logger); ConsoleKey selection = PrintMenu(taskManager, settings.downloadLocation, logger); while (selection != ConsoleKey.Q) { @@ -114,7 +114,7 @@ public static class Tranga_Cli selection = PrintMenu(taskManager, settings.downloadLocation, logger); } - logger.WriteLine(Type.Missing, "Exiting."); + logger.WriteLine("Tranga_CLI", "Exiting."); if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running)) { Console.WriteLine("Force quit (Even with running tasks?) y/N"); @@ -143,13 +143,13 @@ public static class Tranga_Cli Console.WriteLine(); Console.WriteLine($"{"U: Update this Screen",-30}{"Q: Exit",-30}"); ConsoleKey selection = Console.ReadKey().Key; - logger.WriteLine(Type.Missing, $"Menu selection: {selection}"); + logger.WriteLine("Tranga_CLI", $"Menu selection: {selection}"); return selection; } private static void PrintTasks(TrangaTask[] tasks, Logger logger) { - logger.WriteLine(Type.Missing, "Printing Tasks"); + logger.WriteLine("Tranga_CLI", "Printing Tasks"); int taskCount = tasks.Length; int taskRunningCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Running); int taskEnqueuedCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Enqueued); @@ -166,7 +166,7 @@ public static class Tranga_Cli private static void CreateTask(TaskManager taskManager, TaskManager.SettingsData settings, Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Creating Task"); + logger.WriteLine("Tranga_CLI", "Menu: Creating Task"); TrangaTask.Task? tmpTask = SelectTaskType(logger); if (tmpTask is null) return; @@ -189,25 +189,25 @@ public static class Tranga_Cli } TimeSpan reoccurrence = SelectReoccurrence(logger); - logger.WriteLine(Type.Missing, "Sending Task to TaskManager"); + logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager"); TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en"); Console.WriteLine(newTask); } private static void ExecuteTaskNow(TaskManager taskManager, Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Executing Task"); + logger.WriteLine("Tranga_CLI", "Menu: Executing Task"); TrangaTask[] tasks = taskManager.GetAllTasks(); if (tasks.Length < 1) { Console.Clear(); Console.WriteLine("There are no available Tasks."); - logger.WriteLine(Type.Missing, "No available Tasks."); + logger.WriteLine("Tranga_CLI", "No available Tasks."); return; } PrintTasks(tasks, logger); - logger.WriteLine(Type.Missing, "Selecting Task to Execute"); + logger.WriteLine("Tranga_CLI", "Selecting Task to Execute"); Console.WriteLine("Enter q to abort"); Console.WriteLine($"Select Task (0-{tasks.Length - 1}):"); @@ -219,38 +219,38 @@ public static class Tranga_Cli { Console.Clear(); Console.WriteLine("aborted."); - logger.WriteLine(Type.Missing, "aborted"); + logger.WriteLine("Tranga_CLI", "aborted"); return; } try { int selectedTaskIndex = Convert.ToInt32(selectedTask); - logger.WriteLine(Type.Missing, "Sending Task to TaskManager"); + logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager"); taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]); } catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); - logger.WriteLine(Type.Missing, e.Message); + logger.WriteLine("Tranga_CLI", e.Message); } } private static void RemoveTask(TaskManager taskManager, Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Remove Task"); + logger.WriteLine("Tranga_CLI", "Menu: Remove Task"); TrangaTask[] tasks = taskManager.GetAllTasks(); if (tasks.Length < 1) { Console.Clear(); Console.WriteLine("There are no available Tasks."); - logger.WriteLine(Type.Missing, "No available Tasks"); + logger.WriteLine("Tranga_CLI", "No available Tasks"); return; } PrintTasks(tasks, logger); - logger.WriteLine(Type.Missing, "Selecting Task"); + logger.WriteLine("Tranga_CLI", "Selecting Task"); Console.WriteLine("Enter q to abort"); Console.WriteLine($"Select Task (0-{tasks.Length - 1}):"); @@ -262,26 +262,26 @@ public static class Tranga_Cli { Console.Clear(); Console.WriteLine("aborted."); - logger.WriteLine(Type.Missing, "aborted."); + logger.WriteLine("Tranga_CLI", "aborted."); return; } try { int selectedTaskIndex = Convert.ToInt32(selectedTask); - logger.WriteLine(Type.Missing, "Sending Task to TaskManager"); + logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager"); taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication); } catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); - logger.WriteLine(Type.Missing, e.Message); + logger.WriteLine("Tranga_CLI", e.Message); } } private static TrangaTask.Task? SelectTaskType(Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Select TaskType"); + logger.WriteLine("Tranga_CLI", "Menu: Select TaskType"); Console.Clear(); string[] taskNames = Enum.GetNames(); @@ -301,7 +301,7 @@ public static class Tranga_Cli { Console.Clear(); Console.WriteLine("aborted."); - logger.WriteLine(Type.Missing, "aborted."); + logger.WriteLine("Tranga_CLI", "aborted."); return null; } @@ -314,7 +314,7 @@ public static class Tranga_Cli catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); - logger.WriteLine(Type.Missing, e.Message); + logger.WriteLine("Tranga_CLI", e.Message); } return null; @@ -322,14 +322,14 @@ public static class Tranga_Cli private static TimeSpan SelectReoccurrence(Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Select Reoccurrence"); + logger.WriteLine("Tranga_CLI", "Menu: Select Reoccurrence"); Console.WriteLine("Select reoccurrence Timer (Format hh:mm:ss):"); return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US")); } private static Connector? SelectConnector(string folderPath, Connector[] connectors, Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Select Connector"); + logger.WriteLine("Tranga_CLI", "Menu: Select Connector"); Console.Clear(); int cIndex = 0; @@ -348,7 +348,7 @@ public static class Tranga_Cli { Console.Clear(); Console.WriteLine("aborted."); - logger.WriteLine(Type.Missing, "aborted."); + logger.WriteLine("Tranga_CLI", "aborted."); return null; } @@ -360,7 +360,7 @@ public static class Tranga_Cli catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); - logger.WriteLine(Type.Missing, e.Message); + logger.WriteLine("Tranga_CLI", e.Message); } return null; @@ -368,7 +368,7 @@ public static class Tranga_Cli private static Publication? SelectPublication(Connector connector, Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Select Publication"); + logger.WriteLine("Tranga_CLI", "Menu: Select Publication"); Console.Clear(); Console.WriteLine($"Connector: {connector.name}"); @@ -393,7 +393,7 @@ public static class Tranga_Cli { Console.Clear(); Console.WriteLine("aborted."); - logger.WriteLine(Type.Missing, "aborted."); + logger.WriteLine("Tranga_CLI", "aborted."); return null; } @@ -405,7 +405,7 @@ public static class Tranga_Cli catch (Exception e) { Console.WriteLine($"Exception: {e.Message}"); - logger.WriteLine(Type.Missing, e.Message); + logger.WriteLine("Tranga_CLI", e.Message); } return null; @@ -413,7 +413,7 @@ public static class Tranga_Cli private static void SearchTasks(TaskManager taskManager, Logger logger) { - logger.WriteLine(Type.Missing, "Menu: Search task"); + logger.WriteLine("Tranga_CLI", "Menu: Search task"); string? query = Console.ReadLine(); while (query is null || query.Length < 1) query = Console.ReadLine(); diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index 293c8c1..cc65458 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -1,6 +1,7 @@ using System.IO.Compression; using System.Net; using System.Xml.Linq; +using Logging; namespace Tranga; @@ -13,10 +14,13 @@ public abstract class Connector internal string downloadLocation { get; } //Location of local files protected DownloadClient downloadClient { get; } - protected Connector(string downloadLocation, uint downloadDelay) + protected Logger? logger; + + protected Connector(string downloadLocation, uint downloadDelay, Logger? logger) { this.downloadLocation = downloadLocation; this.downloadClient = new DownloadClient(downloadDelay); + this.logger = logger; } public abstract string name { get; } //Name of the Connector (e.g. Website) @@ -58,6 +62,7 @@ public abstract class Connector /// Publication to save series.json for public void SaveSeriesInfo(Publication publication) { + logger?.WriteLine(this.GetType().ToString(), $"Saving series.json for {publication.sortName}"); //Check if Publication already has a Folder and a series.json string publicationFolder = Path.Join(downloadLocation, publication.folderName); if(!Directory.Exists(publicationFolder)) @@ -73,8 +78,9 @@ public abstract class Connector /// See ComicInfo.xml /// /// XML-string - protected static string CreateComicInfo(Publication publication, Chapter chapter) + protected static string CreateComicInfo(Publication publication, Chapter chapter, Logger? logger) { + logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} Chapter {chapter.sortNumber}"); XElement comicInfo = new XElement("ComicInfo", new XElement("Tags", string.Join(',',publication.tags)), new XElement("LanguageISO", publication.originalLanguage), @@ -124,8 +130,9 @@ public abstract class Connector /// Full path to save archive to (without file ending .cbz) /// DownloadClient of the connector /// Path of the generate Chapter ComicInfo.xml, if it was generated - protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null) + protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, Logger? logger, string? comicInfoPath = null) { + logger?.WriteLine("Connector", "Downloading Images"); //Check if Publication Directory already exists string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar); string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray()); @@ -151,6 +158,7 @@ public abstract class Connector if(comicInfoPath is not null) File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml")); + logger?.WriteLine("Connector", "Creating archive"); //ZIP-it and ship-it ZipFile.CreateFromDirectory(tempFolder, fullPath); Directory.Delete(tempFolder, true); //Cleanup diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 554f5a8..ce1f24d 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -2,24 +2,26 @@ using System.Net; using System.Text.Json; using System.Text.Json.Nodes; +using Logging; namespace Tranga.Connectors; public class MangaDex : Connector { public override string name { get; } - public MangaDex(string downloadLocation, uint downloadDelay) : base(downloadLocation, downloadDelay) + public MangaDex(string downloadLocation, uint downloadDelay, Logger? logger) : base(downloadLocation, downloadDelay, logger) { name = "MangaDex"; } - public MangaDex(string downloadLocation) : base(downloadLocation, 750) + public MangaDex(string downloadLocation, Logger? logger) : base(downloadLocation, 750, logger) { name = "MangaDex"; } public override Publication[] GetPublications(string publicationTitle = "") { + logger?.WriteLine(this.GetType().ToString(), $"Getting Publications"); const int limit = 100; //How many values we want returned at once int offset = 0; //"Page" int total = int.MaxValue; //How many total results are there, is updated on first request @@ -126,6 +128,7 @@ public class MangaDex : Connector public override Chapter[] GetChapters(Publication publication, string language = "") { + logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters"); const int limit = 100; //How many values we want returned at once int offset = 0; //"Page" int total = int.MaxValue; //How many total results are there, is updated on first request @@ -180,6 +183,7 @@ public class MangaDex : Connector public override void DownloadChapter(Publication publication, Chapter chapter) { + logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.sortNumber}"); //Request URLs for Chapter-Images DownloadClient.RequestResult requestResult = downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'"); @@ -198,14 +202,15 @@ public class MangaDex : Connector imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue()}"); string comicInfoPath = Path.GetTempFileName(); - File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter)); + File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter, logger)); //Download Chapter-Images - DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, comicInfoPath); + DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, logger, comicInfoPath); } public override void DownloadCover(Publication publication) { + logger?.WriteLine(this.GetType().ToString(), $"Download cover {publication.sortName}"); //Check if Publication already has a Folder and cover string publicationFolder = Path.Join(downloadLocation, publication.folderName); if(!Directory.Exists(publicationFolder)) diff --git a/Tranga/Komga.cs b/Tranga/Komga.cs index dd9095e..317234c 100644 --- a/Tranga/Komga.cs +++ b/Tranga/Komga.cs @@ -1,5 +1,6 @@ using System.Net.Http.Headers; using System.Text.Json.Nodes; +using Logging; using Newtonsoft.Json; using JsonSerializer = System.Text.Json.JsonSerializer; @@ -13,23 +14,27 @@ public class Komga { public string baseUrl { get; } public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems + + private Logger? logger; /// Base-URL of Komga instance, no trailing slashes(/) /// Komga Username /// Komga password, will be base64 encoded. yea - public Komga(string baseUrl, string username, string password) + public Komga(string baseUrl, string username, string password, Logger? logger) { this.baseUrl = baseUrl; this.auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")); + this.logger = logger; } /// Base-URL of Komga instance, no trailing slashes(/) /// Base64 string of username and password (username):(password) [JsonConstructor] - public Komga(string baseUrl, string auth) + public Komga(string baseUrl, string auth, Logger? logger) { this.baseUrl = baseUrl; this.auth = auth; + this.logger = logger; } /// @@ -38,6 +43,7 @@ public class Komga /// Array of KomgaLibraries public KomgaLibrary[] GetLibraries() { + logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries"); Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth); JsonArray? result = JsonSerializer.Deserialize(data); if (result is null) @@ -63,6 +69,7 @@ public class Komga /// true if successful public bool UpdateLibrary(string libraryId) { + logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries"); return NetClient.MakePost($"{baseUrl}/api/v1/libraries/{libraryId}/scan", auth); } diff --git a/Tranga/TaskExecutor.cs b/Tranga/TaskExecutor.cs index 2d42a72..d225409 100644 --- a/Tranga/TaskExecutor.cs +++ b/Tranga/TaskExecutor.cs @@ -1,4 +1,6 @@ -namespace Tranga; +using Logging; + +namespace Tranga; /// /// Executes TrangaTasks @@ -14,12 +16,16 @@ public static class TaskExecutor /// 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(TaskManager taskManager, TrangaTask trangaTask, Dictionary> chapterCollection) + public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary> chapterCollection, Logger? logger) { //Only execute task if it is not already being executed. if (trangaTask.state == TrangaTask.ExecutionState.Running) + { + logger?.WriteLine("TaskExecutor", $"Task already running {trangaTask}"); return; + } trangaTask.state = TrangaTask.ExecutionState.Running; + logger?.WriteLine("TaskExecutor", $"Executing Task {trangaTask}"); //Connector is not needed for all tasks Connector? connector = null; @@ -42,7 +48,8 @@ public static class TaskExecutor UpdateKomgaLibrary(taskManager); break; } - + + logger?.WriteLine("TaskExecutor", $"Task executed! {trangaTask}"); trangaTask.state = TrangaTask.ExecutionState.Waiting; trangaTask.lastExecuted = DateTime.Now; } diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 54f6860..c718985 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Logging; +using Newtonsoft.Json; using Tranga.Connectors; namespace Tranga; @@ -15,20 +16,23 @@ public class TaskManager private readonly Connector[] _connectors; private Dictionary> tasksToExecute = new(); private string downloadLocation { get; } + private Logger? logger { get; } - public Komga? komga { get; private set; } + public Komga? komga { get; } /// Local path to save data (Manga) to /// The Url of the Komga-instance that you want to update /// The Komga username /// The Komga password - public TaskManager(string folderPath, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null) + /// + public TaskManager(string folderPath, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null, Logger? logger = null) { + this.logger = logger; this.downloadLocation = folderPath; if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null) - this.komga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword); - this._connectors = new Connector[]{ new MangaDex(folderPath) }; + this.komga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword, logger); + this._connectors = new Connector[]{ new MangaDex(folderPath, logger) }; foreach(Connector cConnector in this._connectors) tasksToExecute.Add(cConnector, new List()); _allTasks = new HashSet(); @@ -37,9 +41,10 @@ public class TaskManager taskChecker.Start(); } - public TaskManager(SettingsData settings) + public TaskManager(SettingsData settings, Logger? logger = null) { - this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation) }; + this.logger = logger; + this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, logger) }; foreach(Connector cConnector in this._connectors) tasksToExecute.Add(cConnector, new List()); this.downloadLocation = settings.downloadLocation; @@ -74,6 +79,7 @@ public class TaskManager ExecuteTaskNow(task); else { + logger?.WriteLine(this.GetType().ToString(), $"Task due: {task}"); tasksToExecute[GetConnector(task.connectorName!)].Add(task); } } @@ -90,9 +96,10 @@ public class TaskManager if (!this._allTasks.Contains(task)) return; + logger?.WriteLine(this.GetType().ToString(), $"Forcing Execution: {task}"); Task t = new Task(() => { - TaskExecutor.Execute(this, task, this._chapterCollection); + TaskExecutor.Execute(this, task, this._chapterCollection, logger); }); t.Start(); } @@ -109,6 +116,7 @@ public class TaskManager public TrangaTask AddTask(TrangaTask.Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence, string language = "") { + logger?.WriteLine(this.GetType().ToString(), $"Adding new Task"); if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null) throw new ArgumentException($"connectorName can not be null for task {task}"); @@ -142,6 +150,7 @@ public class TaskManager _allTasks.Add(newTask); } } + logger?.WriteLine(this.GetType().ToString(), newTask.ToString()); ExportData(Directory.GetCurrentDirectory()); return newTask; @@ -155,6 +164,7 @@ public class TaskManager /// Publication that was used public void RemoveTask(TrangaTask.Task task, string? connectorName, Publication? publication) { + logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task}"); if (task == TrangaTask.Task.UpdateKomgaLibrary) _allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary); else if (connectorName is null) @@ -207,6 +217,7 @@ public class TaskManager /// If force is true, tasks are aborted. public void Shutdown(bool force = false) { + logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})"); _continueRunning = false; ExportData(Directory.GetCurrentDirectory()); @@ -241,6 +252,7 @@ public class TaskManager /// Folder path, filename will be data.json private void ExportData(string exportFolderPath) { + logger?.WriteLine(this.GetType().ToString(), $"Exporting data to data.json"); SettingsData data = new SettingsData(this.downloadLocation, this.komga, this._allTasks); string exportPath = Path.Join(exportFolderPath, "data.json");