2
0

Compare commits

..

4 Commits

Author SHA1 Message Date
2b18dc9d4f Added TrangaTask.ToString 2023-05-20 00:37:31 +02:00
247c06872e Formatting 2023-05-20 00:37:18 +02:00
854bb71771 Print the created task 2023-05-20 00:37:10 +02:00
3f72e527fa AddTask returns the created Task 2023-05-20 00:36:52 +02:00
3 changed files with 12 additions and 5 deletions

View File

@ -55,8 +55,8 @@ public static class Tranga_Cli
if(task != TrangaTask.Task.UpdatePublications) if(task != TrangaTask.Task.UpdatePublications)
publication = SelectPublication(connector); publication = SelectPublication(connector);
TimeSpan reoccurrence = SelectReoccurrence(); TimeSpan reoccurrence = SelectReoccurrence();
taskManager.AddTask(task, connector.name, publication, reoccurrence, "en"); TrangaTask newTask = taskManager.AddTask(task, connector.name, publication, reoccurrence, "en");
Console.WriteLine($"{task} - {reoccurrence} - {publication?.sortName} - {connector.name}"); Console.WriteLine(newTask);
Console.WriteLine("Press any key."); Console.WriteLine("Press any key.");
Console.ReadKey(); Console.ReadKey();
menu = 0; menu = 0;
@ -160,7 +160,7 @@ public static class Tranga_Cli
int tIndex = 0; int tIndex = 0;
Console.WriteLine($"Tasks (Running/Total): {taskRunningCount}/{taskCount}"); Console.WriteLine($"Tasks (Running/Total): {taskRunningCount}/{taskCount}");
foreach(TrangaTask trangaTask in tasks) foreach(TrangaTask trangaTask in tasks)
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.reoccurrence} - {trangaTask.publication?.sortName} - {trangaTask.connectorName} - {trangaTask.lastExecuted} - {(trangaTask.isBeingExecuted ? "Running" : "Waiting")}"); Console.WriteLine($"{tIndex++:000}: {trangaTask.ToString()}");
} }
private static void ExecuteTaskNow(TaskManager taskManager) private static void ExecuteTaskNow(TaskManager taskManager)

View File

@ -67,7 +67,7 @@ public class TaskManager
/// <param name="reoccurrence">Time-Interval between Executions</param> /// <param name="reoccurrence">Time-Interval between Executions</param>
/// <param name="language">language, should Task require parameter. Can be empty</param> /// <param name="language">language, should Task require parameter. Can be empty</param>
/// <exception cref="ArgumentException">Is thrown when connectorName is not a available Connector</exception> /// <exception cref="ArgumentException">Is thrown when connectorName is not a available Connector</exception>
public void AddTask(TrangaTask.Task task, string connectorName, Publication? publication, TimeSpan reoccurrence, public TrangaTask AddTask(TrangaTask.Task task, string connectorName, Publication? publication, TimeSpan reoccurrence,
string language = "") string language = "")
{ {
//Get appropriate Connector from available Connectors for TrangaTask //Get appropriate Connector from available Connectors for TrangaTask
@ -75,15 +75,17 @@ public class TaskManager
if (connector is null) if (connector is null)
throw new ArgumentException($"Connector {connectorName} is not a known connector."); throw new ArgumentException($"Connector {connectorName} is not a known connector.");
TrangaTask newTask = new TrangaTask(connector.name, task, publication, reoccurrence, language);
//Check if same task already exists //Check if same task already exists
if (!_allTasks.Any(trangaTask => trangaTask.task != task && trangaTask.connectorName != connector.name && if (!_allTasks.Any(trangaTask => trangaTask.task != task && trangaTask.connectorName != connector.name &&
trangaTask.publication?.downloadUrl != publication?.downloadUrl)) trangaTask.publication?.downloadUrl != publication?.downloadUrl))
{ {
if(task != TrangaTask.Task.UpdatePublications) if(task != TrangaTask.Task.UpdatePublications)
_chapterCollection.Add((Publication)publication!, new List<Chapter>()); _chapterCollection.Add((Publication)publication!, new List<Chapter>());
_allTasks.Add(new TrangaTask(connector.name, task, publication, reoccurrence, language)); _allTasks.Add(newTask);
ExportTasks(Directory.GetCurrentDirectory()); ExportTasks(Directory.GetCurrentDirectory());
} }
return newTask;
} }
/// <summary> /// <summary>

View File

@ -42,4 +42,9 @@ public class TrangaTask
UpdateChapters, UpdateChapters,
DownloadNewChapters DownloadNewChapters
} }
public override string ToString()
{
return $"{task}\t{lastExecuted}\t{reoccurrence}\t{(isBeingExecuted ? "running" : "waiting")}\t{connectorName}\t{publication?.sortName}";
}
} }