Compare commits
No commits in common. "553a77320db86e8596b1729837ee03a0cef88458" and "d659a269870a637122ee253641c70e7da206ecc4" have entirely different histories.
553a77320d
...
d659a26987
@ -37,7 +37,7 @@ public static class Tranga_Cli
|
||||
switch (menu)
|
||||
{
|
||||
case 1:
|
||||
PrintTasks(taskManager.GetAllTasks());
|
||||
PrintTasks(taskManager);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
@ -61,14 +61,8 @@ public static class Tranga_Cli
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 4:
|
||||
ExecuteTask(taskManager);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
default:
|
||||
selection = Menu(taskManager, folderPath);
|
||||
selection = Menu(folderPath);
|
||||
switch (selection)
|
||||
{
|
||||
case ConsoleKey.L:
|
||||
@ -80,9 +74,6 @@ public static class Tranga_Cli
|
||||
case ConsoleKey.D:
|
||||
menu = 3;
|
||||
break;
|
||||
case ConsoleKey.E:
|
||||
menu = 4;
|
||||
break;
|
||||
default:
|
||||
menu = 0;
|
||||
break;
|
||||
@ -90,65 +81,40 @@ public static class Tranga_Cli
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (taskManager.GetAllTasks().Any(task => task.isBeingExecuted))
|
||||
{
|
||||
Console.WriteLine("Force quit (Even with running tasks?) y/N");
|
||||
selection = Console.ReadKey().Key;
|
||||
taskManager.Shutdown(selection == ConsoleKey.Y);
|
||||
}else
|
||||
taskManager.Shutdown(false);
|
||||
taskManager.Shutdown();
|
||||
}
|
||||
|
||||
private static ConsoleKey Menu(TaskManager taskManager, string folderPath)
|
||||
private static ConsoleKey Menu(string folderPath)
|
||||
{
|
||||
int taskCount = taskManager.GetAllTasks().Length;
|
||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted);
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
||||
Console.WriteLine($"Download Folder: {folderPath}");
|
||||
Console.WriteLine("Select Option:");
|
||||
Console.WriteLine("L: List tasks");
|
||||
Console.WriteLine("C: Create Task");
|
||||
Console.WriteLine("D: Delete Task");
|
||||
Console.WriteLine("E: Execute Task now");
|
||||
Console.WriteLine("Q: Exit with saving");
|
||||
ConsoleKey selection = Console.ReadKey().Key;
|
||||
Console.WriteLine();
|
||||
return selection;
|
||||
}
|
||||
|
||||
private static void PrintTasks(TrangaTask[] tasks)
|
||||
private static int PrintTasks(TaskManager taskManager)
|
||||
{
|
||||
int taskCount = tasks.Length;
|
||||
int taskRunningCount = tasks.Count(task => task.isBeingExecuted);
|
||||
Console.Clear();
|
||||
int tIndex = 0;
|
||||
Console.WriteLine($"Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
||||
foreach(TrangaTask trangaTask in tasks)
|
||||
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.reoccurrence} - {trangaTask.publication?.sortName} - {trangaTask.connectorName} - {trangaTask.lastExecuted} - {(trangaTask.isBeingExecuted ? "Running" : "Waiting")}");
|
||||
}
|
||||
|
||||
private static void ExecuteTask(TaskManager taskManager)
|
||||
{
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
PrintTasks(tasks);
|
||||
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
||||
int tIndex = 0;
|
||||
Console.WriteLine("Tasks:");
|
||||
foreach(TrangaTask trangaTask in tasks)
|
||||
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.reoccurrence} - {trangaTask.publication?.sortName} - {trangaTask.connectorName} - {trangaTask.lastExecuted}");
|
||||
return tasks.Length;
|
||||
}
|
||||
|
||||
private static void RemoveTask(TaskManager taskManager)
|
||||
{
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
PrintTasks(tasks);
|
||||
int length = PrintTasks(taskManager);
|
||||
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
Console.WriteLine($"Select Task (0-{length}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
|
@ -7,10 +7,6 @@ public static class TaskExecutor
|
||||
Connector? connector = connectors.FirstOrDefault(c => c.name == trangaTask.connectorName);
|
||||
if (connector is null)
|
||||
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
|
||||
|
||||
if (trangaTask.isBeingExecuted)
|
||||
return;
|
||||
trangaTask.isBeingExecuted = true;
|
||||
trangaTask.lastExecuted = DateTime.Now;
|
||||
|
||||
switch (trangaTask.task)
|
||||
@ -25,8 +21,6 @@ public static class TaskExecutor
|
||||
UpdatePublications(connector, chapterCollection);
|
||||
break;
|
||||
}
|
||||
|
||||
trangaTask.isBeingExecuted = false;
|
||||
}
|
||||
|
||||
private static void UpdatePublications(Connector connector, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
|
@ -34,15 +34,6 @@ public class TaskManager
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteTaskNow(TrangaTask task)
|
||||
{
|
||||
Task t = new Task(() =>
|
||||
{
|
||||
TaskExecutor.Execute(this.connectors, task, this._chapterCollection);
|
||||
});
|
||||
t.Start();
|
||||
}
|
||||
|
||||
public void AddTask(TrangaTask.Task task, string connectorName, Publication? publication, TimeSpan reoccurrence,
|
||||
string language = "")
|
||||
{
|
||||
@ -85,21 +76,13 @@ public class TaskManager
|
||||
return this._chapterCollection.Keys.ToArray();
|
||||
}
|
||||
|
||||
public void Shutdown(bool force = false)
|
||||
public void Shutdown()
|
||||
{
|
||||
_continueRunning = false;
|
||||
ExportTasks(Directory.GetCurrentDirectory());
|
||||
|
||||
if(force)
|
||||
Environment.Exit(_allTasks.Count(task => task.isBeingExecuted));
|
||||
|
||||
//Wait for tasks to finish
|
||||
while(_allTasks.Any(task => task.isBeingExecuted))
|
||||
Thread.Sleep(10);
|
||||
|
||||
}
|
||||
|
||||
private HashSet<TrangaTask> ImportTasks(string importFolderPath)
|
||||
public HashSet<TrangaTask> ImportTasks(string importFolderPath)
|
||||
{
|
||||
string filePath = Path.Join(importFolderPath, "tasks.json");
|
||||
if (!File.Exists(filePath))
|
||||
@ -115,7 +98,7 @@ public class TaskManager
|
||||
return importTasks.ToHashSet();
|
||||
}
|
||||
|
||||
private void ExportTasks(string exportFolderPath)
|
||||
public void ExportTasks(string exportFolderPath)
|
||||
{
|
||||
string filePath = Path.Join(exportFolderPath, "tasks.json");
|
||||
string toWrite = JsonConvert.SerializeObject(_allTasks.ToArray());
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tranga;
|
||||
namespace Tranga;
|
||||
|
||||
public class TrangaTask
|
||||
{
|
||||
@ -10,7 +8,6 @@ public class TrangaTask
|
||||
public Task task { get; }
|
||||
public Publication? publication { get; }
|
||||
public string language { get; }
|
||||
[JsonIgnore]public bool isBeingExecuted { get; set; }
|
||||
|
||||
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user