Better/More logging

This commit is contained in:
glax 2023-05-21 01:57:56 +02:00
parent 06a8e4e895
commit e02b00e0ef
3 changed files with 22 additions and 11 deletions

View File

@ -21,7 +21,7 @@ public class MangaDex : Connector
public override Publication[] GetPublications(string publicationTitle = "")
{
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications");
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
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
@ -128,7 +128,7 @@ public class MangaDex : Connector
public override Chapter[] GetChapters(Publication publication, string language = "")
{
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters");
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters {publication.sortName} (language={language})");
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
@ -183,7 +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}");
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.volumeNumber}-{chapter.chapterNumber}");
//Request URLs for Chapter-Images
DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'");

View File

@ -15,6 +15,7 @@ public static class TaskExecutor
/// <param name="taskManager">Parent</param>
/// <param name="trangaTask">Task to execute</param>
/// <param name="chapterCollection">Current chapterCollection to update</param>
/// <param name="logger"></param>
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection, Logger? logger)
{
@ -25,7 +26,7 @@ public static class TaskExecutor
return;
}
trangaTask.state = TrangaTask.ExecutionState.Running;
logger?.WriteLine("TaskExecutor", $"Executing Task {trangaTask}");
logger?.WriteLine("TaskExecutor", $"Starting Task {trangaTask}");
//Connector is not needed for all tasks
Connector? connector = null;
@ -49,9 +50,9 @@ public static class TaskExecutor
break;
}
logger?.WriteLine("TaskExecutor", $"Task executed! {trangaTask}");
trangaTask.state = TrangaTask.ExecutionState.Waiting;
logger?.WriteLine("TaskExecutor", $"Task finished! {trangaTask}");
trangaTask.lastExecuted = DateTime.Now;
trangaTask.state = TrangaTask.ExecutionState.Waiting;
}
/// <summary>

View File

@ -60,6 +60,7 @@ public class TaskManager
/// </summary>
private void TaskCheckerThread()
{
logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread.");
while (_continueRunning)
{
//Check if previous tasks have finished and execute new tasks
@ -120,7 +121,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");
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null)
throw new ArgumentException($"connectorName can not be null for task {task}");
@ -154,7 +155,7 @@ public class TaskManager
_allTasks.Add(newTask);
}
}
logger?.WriteLine(this.GetType().ToString(), newTask.ToString());
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask.ToString()}");
ExportData(Directory.GetCurrentDirectory());
return newTask;
@ -168,15 +169,23 @@ public class TaskManager
/// <param name="publication">Publication that was used</param>
public void RemoveTask(TrangaTask.Task task, string? connectorName, Publication? publication)
{
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task}");
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
if (task == TrangaTask.Task.UpdateKomgaLibrary)
{
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task}");
}
else if (connectorName is null)
throw new ArgumentException($"connectorName can not be null for Task {task}");
else
_allTasks.RemoveWhere(trangaTask =>
{
if(_allTasks.RemoveWhere(trangaTask =>
trangaTask.task == task && trangaTask.connectorName == connectorName &&
trangaTask.publication?.downloadUrl == publication?.downloadUrl);
trangaTask.publication?.downloadUrl == publication?.downloadUrl) > 0)
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.downloadUrl}.");
else
logger?.WriteLine(this.GetType().ToString(), $"No Task {task} {publication?.sortName} {publication?.downloadUrl} could be found.");
}
ExportData(Directory.GetCurrentDirectory());
}
@ -231,6 +240,7 @@ public class TaskManager
//Wait for tasks to finish
while(_allTasks.Any(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Enqueued))
Thread.Sleep(10);
logger?.WriteLine(this.GetType().ToString(), "Tasks finished. Bye!");
Environment.Exit(0);
}