Compare commits
No commits in common. "d62b0bdf34ea4e7bde24cc72b09cc2892862baaf" and "497ec74b9a8bd2d15f61375d88115e666b733b9e" have entirely different histories.
d62b0bdf34
...
497ec74b9a
@ -1,19 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class FileLogger : LoggerBase
|
|
||||||
{
|
|
||||||
private string logFilePath { get; }
|
|
||||||
|
|
||||||
public FileLogger(string logFilePath, TextWriter? stdOut, Encoding? encoding = null) : base (stdOut, encoding)
|
|
||||||
{
|
|
||||||
this.logFilePath = logFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Write(LogMessage logMessage)
|
|
||||||
{
|
|
||||||
File.AppendAllText(logFilePath, logMessage.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class FormattedConsoleLogger : LoggerBase
|
|
||||||
{
|
|
||||||
|
|
||||||
public FormattedConsoleLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, encoding)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Write(LogMessage message)
|
|
||||||
{
|
|
||||||
//Nothing to do yet
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class Logger : TextWriter
|
|
||||||
{
|
|
||||||
public override Encoding Encoding { get; }
|
|
||||||
public enum LoggerType
|
|
||||||
{
|
|
||||||
FileLogger,
|
|
||||||
ConsoleLogger,
|
|
||||||
MemoryLogger
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileLogger? _fileLogger;
|
|
||||||
private FormattedConsoleLogger? _formattedConsoleLogger;
|
|
||||||
private MemoryLogger? _memoryLogger;
|
|
||||||
private TextWriter? stdOut;
|
|
||||||
|
|
||||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
|
||||||
{
|
|
||||||
this.Encoding = encoding ?? Encoding.ASCII;
|
|
||||||
this.stdOut = stdOut ?? null;
|
|
||||||
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
|
||||||
_fileLogger = new FileLogger(logFilePath, null, encoding);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_fileLogger = null;
|
|
||||||
throw new ArgumentException($"logFilePath can not be null for LoggerType {LoggerType.FileLogger}");
|
|
||||||
}
|
|
||||||
_formattedConsoleLogger = enabledLoggers.Contains(LoggerType.ConsoleLogger) ? new FormattedConsoleLogger(null, encoding) : null;
|
|
||||||
_memoryLogger = enabledLoggers.Contains(LoggerType.MemoryLogger) ? new MemoryLogger(null, encoding) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteLine(string caller, string? value)
|
|
||||||
{
|
|
||||||
value = value is null ? Environment.NewLine : string.Concat(value, Environment.NewLine);
|
|
||||||
|
|
||||||
Write(caller, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(string caller, string? value)
|
|
||||||
{
|
|
||||||
if (value is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_fileLogger?.Write(caller, value);
|
|
||||||
_memoryLogger?.Write(caller, value);
|
|
||||||
_formattedConsoleLogger?.Write(caller, value);
|
|
||||||
|
|
||||||
stdOut?.Write(value);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public abstract class LoggerBase : TextWriter
|
|
||||||
{
|
|
||||||
public override Encoding Encoding { get; }
|
|
||||||
private TextWriter? stdOut { get; }
|
|
||||||
|
|
||||||
public LoggerBase(TextWriter? stdOut, Encoding? encoding = null)
|
|
||||||
{
|
|
||||||
this.Encoding = encoding ?? Encoding.ASCII;
|
|
||||||
this.stdOut = stdOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteLine(string caller, string? value)
|
|
||||||
{
|
|
||||||
value = value is null ? Environment.NewLine : string.Join(value, Environment.NewLine);
|
|
||||||
|
|
||||||
LogMessage message = new LogMessage(DateTime.Now, caller, value);
|
|
||||||
|
|
||||||
Write(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(string caller, string? value)
|
|
||||||
{
|
|
||||||
if (value is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LogMessage message = new LogMessage(DateTime.Now, caller, value);
|
|
||||||
|
|
||||||
stdOut?.Write(message.ToString());
|
|
||||||
|
|
||||||
Write(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void Write(LogMessage message);
|
|
||||||
|
|
||||||
public class LogMessage
|
|
||||||
{
|
|
||||||
public DateTime logTime { get; }
|
|
||||||
public string caller { get; }
|
|
||||||
public string value { get; }
|
|
||||||
|
|
||||||
public LogMessage(DateTime now, string caller, string value)
|
|
||||||
{
|
|
||||||
this.logTime = now;
|
|
||||||
this.caller = caller;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToShortTimeString()}";
|
|
||||||
return $"[{dateTimeString}] {caller,-30} | {value}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,42 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class MemoryLogger : LoggerBase
|
|
||||||
{
|
|
||||||
private SortedList<DateTime, LogMessage> logMessages = new();
|
|
||||||
|
|
||||||
public MemoryLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, encoding)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Write(LogMessage value)
|
|
||||||
{
|
|
||||||
logMessages.Add(value.logTime, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] GetLogMessage()
|
|
||||||
{
|
|
||||||
string[] ret = new string[logMessages.Count];
|
|
||||||
for (int logMessageIndex = 0; logMessageIndex < ret.Length; logMessageIndex++)
|
|
||||||
{
|
|
||||||
DateTime logTime = logMessages.GetValueAtIndex(logMessageIndex).logTime;
|
|
||||||
string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToShortTimeString()}";
|
|
||||||
string callerString = logMessages.GetValueAtIndex(logMessageIndex).caller.ToString();
|
|
||||||
string value = $"[{dateTimeString}] {callerString} | {logMessages.GetValueAtIndex(logMessageIndex).value}";
|
|
||||||
ret[logMessageIndex] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] Tail(uint length)
|
|
||||||
{
|
|
||||||
string[] ret = new string[length];
|
|
||||||
for (int logMessageIndex = logMessages.Count - 1; logMessageIndex > logMessageIndex - length; logMessageIndex--)
|
|
||||||
ret[logMessageIndex] = logMessages.GetValueAtIndex(logMessageIndex).ToString();
|
|
||||||
|
|
||||||
return ret.Reverse().ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Logging;
|
|
||||||
using Tranga;
|
using Tranga;
|
||||||
|
using Tranga.Connectors;
|
||||||
|
|
||||||
namespace Tranga_CLI;
|
namespace Tranga_CLI;
|
||||||
|
|
||||||
@ -14,10 +14,6 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
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("Tranga_CLI", "Loading Settings.");
|
|
||||||
TaskManager.SettingsData settings;
|
TaskManager.SettingsData settings;
|
||||||
string settingsPath = Path.Join(Directory.GetCurrentDirectory(), "data.json");
|
string settingsPath = Path.Join(Directory.GetCurrentDirectory(), "data.json");
|
||||||
if (File.Exists(settingsPath))
|
if (File.Exists(settingsPath))
|
||||||
@ -26,7 +22,6 @@ public static class Tranga_Cli
|
|||||||
settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), null, new HashSet<TrangaTask>());
|
settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), null, new HashSet<TrangaTask>());
|
||||||
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "User Input");
|
|
||||||
Console.WriteLine($"Output folder path [{settings.downloadLocation}]:");
|
Console.WriteLine($"Output folder path [{settings.downloadLocation}]:");
|
||||||
string? tmpPath = Console.ReadLine();
|
string? tmpPath = Console.ReadLine();
|
||||||
while(tmpPath is null)
|
while(tmpPath is null)
|
||||||
@ -65,56 +60,54 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
} while (key != ConsoleKey.Enter);
|
} while (key != ConsoleKey.Enter);
|
||||||
|
|
||||||
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass, logger);
|
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loaded.");
|
TaskMode(settings);
|
||||||
TaskMode(settings, logger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TaskMode(TaskManager.SettingsData settings, Logger logger)
|
private static void TaskMode(TaskManager.SettingsData settings)
|
||||||
{
|
{
|
||||||
TaskManager taskManager = new (settings, logger);
|
TaskManager taskManager = new (settings);
|
||||||
ConsoleKey selection = PrintMenu(taskManager, settings.downloadLocation, logger);
|
ConsoleKey selection = PrintMenu(taskManager, settings.downloadLocation);
|
||||||
while (selection != ConsoleKey.Q)
|
while (selection != ConsoleKey.Q)
|
||||||
{
|
{
|
||||||
switch (selection)
|
switch (selection)
|
||||||
{
|
{
|
||||||
case ConsoleKey.L:
|
case ConsoleKey.L:
|
||||||
PrintTasks(taskManager.GetAllTasks(), logger);
|
PrintTasks(taskManager.GetAllTasks());
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.C:
|
case ConsoleKey.C:
|
||||||
CreateTask(taskManager, settings, logger);
|
CreateTask(taskManager, settings);
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.D:
|
case ConsoleKey.D:
|
||||||
RemoveTask (taskManager, logger);
|
RemoveTask (taskManager);
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.E:
|
case ConsoleKey.E:
|
||||||
ExecuteTaskNow(taskManager, logger);
|
ExecuteTaskNow(taskManager);
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.S:
|
case ConsoleKey.S:
|
||||||
SearchTasks(taskManager, logger);
|
SearchTasks(taskManager);
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.R:
|
case ConsoleKey.R:
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running).ToArray(), logger);
|
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running).ToArray());
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
selection = PrintMenu(taskManager, settings.downloadLocation, logger);
|
selection = PrintMenu(taskManager, settings.downloadLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Exiting.");
|
|
||||||
if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running))
|
if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Force quit (Even with running tasks?) y/N");
|
Console.WriteLine("Force quit (Even with running tasks?) y/N");
|
||||||
@ -127,7 +120,7 @@ public static class Tranga_Cli
|
|||||||
taskManager.Shutdown(false);
|
taskManager.Shutdown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConsoleKey PrintMenu(TaskManager taskManager, string folderPath, Logger logger)
|
private static ConsoleKey PrintMenu(TaskManager taskManager, string folderPath)
|
||||||
{
|
{
|
||||||
int taskCount = taskManager.GetAllTasks().Length;
|
int taskCount = taskManager.GetAllTasks().Length;
|
||||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||||
@ -143,13 +136,12 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine($"{"U: Update this Screen",-30}{"Q: Exit",-30}");
|
Console.WriteLine($"{"U: Update this Screen",-30}{"Q: Exit",-30}");
|
||||||
ConsoleKey selection = Console.ReadKey().Key;
|
ConsoleKey selection = Console.ReadKey().Key;
|
||||||
logger.WriteLine("Tranga_CLI", $"Menu selection: {selection}");
|
Console.WriteLine();
|
||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PrintTasks(TrangaTask[] tasks, Logger logger)
|
private static void PrintTasks(TrangaTask[] tasks)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Printing Tasks");
|
|
||||||
int taskCount = tasks.Length;
|
int taskCount = tasks.Length;
|
||||||
int taskRunningCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Running);
|
int taskRunningCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||||
int taskEnqueuedCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
int taskEnqueuedCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||||
@ -164,10 +156,9 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateTask(TaskManager taskManager, TaskManager.SettingsData settings, Logger logger)
|
private static void CreateTask(TaskManager taskManager, TaskManager.SettingsData settings)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
|
TrangaTask.Task? tmpTask = SelectTaskType();
|
||||||
TrangaTask.Task? tmpTask = SelectTaskType(logger);
|
|
||||||
if (tmpTask is null)
|
if (tmpTask is null)
|
||||||
return;
|
return;
|
||||||
TrangaTask.Task task = (TrangaTask.Task)tmpTask!;
|
TrangaTask.Task task = (TrangaTask.Task)tmpTask!;
|
||||||
@ -175,7 +166,7 @@ public static class Tranga_Cli
|
|||||||
Connector? connector = null;
|
Connector? connector = null;
|
||||||
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
if (task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||||
{
|
{
|
||||||
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray());
|
||||||
if (connector is null)
|
if (connector is null)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -183,31 +174,27 @@ public static class Tranga_Cli
|
|||||||
Publication? publication = null;
|
Publication? publication = null;
|
||||||
if (task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
if (task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||||
{
|
{
|
||||||
publication = SelectPublication(connector!, logger);
|
publication = SelectPublication(connector!);
|
||||||
if (publication is null)
|
if (publication is null)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
TimeSpan reoccurrence = SelectReoccurrence();
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
||||||
Console.WriteLine(newTask);
|
Console.WriteLine(newTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ExecuteTaskNow(TaskManager taskManager, Logger logger)
|
private static void ExecuteTaskNow(TaskManager taskManager)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||||
if (tasks.Length < 1)
|
if (tasks.Length < 1)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("There are no available Tasks.");
|
Console.WriteLine("There are no available Tasks.");
|
||||||
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PrintTasks(tasks, logger);
|
PrintTasks(tasks);
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Selecting Task to Execute");
|
|
||||||
Console.WriteLine("Enter q to abort");
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||||
|
|
||||||
@ -219,38 +206,32 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("aborted.");
|
Console.WriteLine("aborted.");
|
||||||
logger.WriteLine("Tranga_CLI", "aborted");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveTask(TaskManager taskManager, Logger logger)
|
private static void RemoveTask(TaskManager taskManager)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Remove Task");
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||||
if (tasks.Length < 1)
|
if (tasks.Length < 1)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("There are no available Tasks.");
|
Console.WriteLine("There are no available Tasks.");
|
||||||
logger.WriteLine("Tranga_CLI", "No available Tasks");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PrintTasks(tasks, logger);
|
PrintTasks(tasks);
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Selecting Task");
|
|
||||||
Console.WriteLine("Enter q to abort");
|
Console.WriteLine("Enter q to abort");
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||||
|
|
||||||
@ -262,26 +243,22 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("aborted.");
|
Console.WriteLine("aborted.");
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
private static TrangaTask.Task? SelectTaskType()
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select TaskType");
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
||||||
|
|
||||||
@ -301,7 +278,6 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("aborted.");
|
Console.WriteLine("aborted.");
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,22 +290,19 @@ public static class Tranga_Cli
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TimeSpan SelectReoccurrence(Logger logger)
|
private static TimeSpan SelectReoccurrence()
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Reoccurrence");
|
|
||||||
Console.WriteLine("Select reoccurrence Timer (Format hh:mm:ss):");
|
Console.WriteLine("Select reoccurrence Timer (Format hh:mm:ss):");
|
||||||
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Connector? SelectConnector(string folderPath, Connector[] connectors, Logger logger)
|
private static Connector? SelectConnector(string folderPath, Connector[] connectors)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
|
||||||
int cIndex = 0;
|
int cIndex = 0;
|
||||||
@ -348,7 +321,6 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("aborted.");
|
Console.WriteLine("aborted.");
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,16 +332,13 @@ public static class Tranga_Cli
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Publication? SelectPublication(Connector connector, Logger logger)
|
private static Publication? SelectPublication(Connector connector)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Publication");
|
|
||||||
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine($"Connector: {connector.name}");
|
Console.WriteLine($"Connector: {connector.name}");
|
||||||
Console.WriteLine("Publication search query (leave empty for all):");
|
Console.WriteLine("Publication search query (leave empty for all):");
|
||||||
@ -393,7 +362,6 @@ public static class Tranga_Cli
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("aborted.");
|
Console.WriteLine("aborted.");
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,19 +373,17 @@ public static class Tranga_Cli
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
Console.WriteLine($"Exception: {e.Message}");
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SearchTasks(TaskManager taskManager, Logger logger)
|
private static void SearchTasks(TaskManager taskManager)
|
||||||
{
|
{
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Search task");
|
|
||||||
string? query = Console.ReadLine();
|
string? query = Console.ReadLine();
|
||||||
while (query is null || query.Length < 1)
|
while (query is null || query.Length < 1)
|
||||||
query = Console.ReadLine();
|
query = Console.ReadLine();
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
||||||
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray(), logger);
|
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tr
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{6284C936-4E90-486B-BC46-0AFAD85AD8EE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{6284C936-4E90-486B-BC46-0AFAD85AD8EE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -26,9 +24,5 @@ Global
|
|||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Logging;
|
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -14,13 +13,10 @@ public abstract class Connector
|
|||||||
internal string downloadLocation { get; } //Location of local files
|
internal string downloadLocation { get; } //Location of local files
|
||||||
protected DownloadClient downloadClient { get; }
|
protected DownloadClient downloadClient { get; }
|
||||||
|
|
||||||
protected Logger? logger;
|
protected Connector(string downloadLocation, uint downloadDelay)
|
||||||
|
|
||||||
protected Connector(string downloadLocation, uint downloadDelay, Logger? logger)
|
|
||||||
{
|
{
|
||||||
this.downloadLocation = downloadLocation;
|
this.downloadLocation = downloadLocation;
|
||||||
this.downloadClient = new DownloadClient(downloadDelay);
|
this.downloadClient = new DownloadClient(downloadDelay);
|
||||||
this.logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||||
@ -62,7 +58,6 @@ public abstract class Connector
|
|||||||
/// <param name="publication">Publication to save series.json for</param>
|
/// <param name="publication">Publication to save series.json for</param>
|
||||||
public void SaveSeriesInfo(Publication publication)
|
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
|
//Check if Publication already has a Folder and a series.json
|
||||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||||
if(!Directory.Exists(publicationFolder))
|
if(!Directory.Exists(publicationFolder))
|
||||||
@ -78,9 +73,8 @@ public abstract class Connector
|
|||||||
/// See ComicInfo.xml
|
/// See ComicInfo.xml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>XML-string</returns>
|
/// <returns>XML-string</returns>
|
||||||
protected static string CreateComicInfo(Publication publication, Chapter chapter, Logger? logger)
|
protected static string CreateComicInfo(Publication publication, Chapter chapter)
|
||||||
{
|
{
|
||||||
logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} Chapter {chapter.sortNumber}");
|
|
||||||
XElement comicInfo = new XElement("ComicInfo",
|
XElement comicInfo = new XElement("ComicInfo",
|
||||||
new XElement("Tags", string.Join(',',publication.tags)),
|
new XElement("Tags", string.Join(',',publication.tags)),
|
||||||
new XElement("LanguageISO", publication.originalLanguage),
|
new XElement("LanguageISO", publication.originalLanguage),
|
||||||
@ -130,9 +124,8 @@ public abstract class Connector
|
|||||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, Logger? logger, string? comicInfoPath = null)
|
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine("Connector", "Downloading Images");
|
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
|
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
|
||||||
string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray());
|
string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray());
|
||||||
@ -158,7 +151,6 @@ public abstract class Connector
|
|||||||
if(comicInfoPath is not null)
|
if(comicInfoPath is not null)
|
||||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||||
|
|
||||||
logger?.WriteLine("Connector", "Creating archive");
|
|
||||||
//ZIP-it and ship-it
|
//ZIP-it and ship-it
|
||||||
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
||||||
Directory.Delete(tempFolder, true); //Cleanup
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
|
@ -2,26 +2,24 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using Logging;
|
|
||||||
|
|
||||||
namespace Tranga.Connectors;
|
namespace Tranga.Connectors;
|
||||||
public class MangaDex : Connector
|
public class MangaDex : Connector
|
||||||
{
|
{
|
||||||
public override string name { get; }
|
public override string name { get; }
|
||||||
|
|
||||||
public MangaDex(string downloadLocation, uint downloadDelay, Logger? logger) : base(downloadLocation, downloadDelay, logger)
|
public MangaDex(string downloadLocation, uint downloadDelay) : base(downloadLocation, downloadDelay)
|
||||||
{
|
{
|
||||||
name = "MangaDex";
|
name = "MangaDex";
|
||||||
}
|
}
|
||||||
|
|
||||||
public MangaDex(string downloadLocation, Logger? logger) : base(downloadLocation, 750, logger)
|
public MangaDex(string downloadLocation) : base(downloadLocation, 750)
|
||||||
{
|
{
|
||||||
name = "MangaDex";
|
name = "MangaDex";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Publication[] GetPublications(string publicationTitle = "")
|
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
|
const int limit = 100; //How many values we want returned at once
|
||||||
int offset = 0; //"Page"
|
int offset = 0; //"Page"
|
||||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||||
@ -128,7 +126,6 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
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
|
const int limit = 100; //How many values we want returned at once
|
||||||
int offset = 0; //"Page"
|
int offset = 0; //"Page"
|
||||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||||
@ -183,7 +180,6 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
public override void DownloadChapter(Publication publication, Chapter chapter)
|
public override void DownloadChapter(Publication publication, Chapter chapter)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {chapter.sortNumber}");
|
|
||||||
//Request URLs for Chapter-Images
|
//Request URLs for Chapter-Images
|
||||||
DownloadClient.RequestResult requestResult =
|
DownloadClient.RequestResult requestResult =
|
||||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'");
|
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'");
|
||||||
@ -202,15 +198,14 @@ public class MangaDex : Connector
|
|||||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||||
|
|
||||||
string comicInfoPath = Path.GetTempFileName();
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter, logger));
|
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
|
||||||
|
|
||||||
//Download Chapter-Images
|
//Download Chapter-Images
|
||||||
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, logger, comicInfoPath);
|
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, comicInfoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DownloadCover(Publication publication)
|
public override void DownloadCover(Publication publication)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Download cover {publication.sortName}");
|
|
||||||
//Check if Publication already has a Folder and cover
|
//Check if Publication already has a Folder and cover
|
||||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||||
if(!Directory.Exists(publicationFolder))
|
if(!Directory.Exists(publicationFolder))
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
@ -14,27 +13,23 @@ public class Komga
|
|||||||
{
|
{
|
||||||
public string baseUrl { get; }
|
public string baseUrl { get; }
|
||||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||||
|
|
||||||
private Logger? logger;
|
|
||||||
|
|
||||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
||||||
/// <param name="username">Komga Username</param>
|
/// <param name="username">Komga Username</param>
|
||||||
/// <param name="password">Komga password, will be base64 encoded. yea</param>
|
/// <param name="password">Komga password, will be base64 encoded. yea</param>
|
||||||
public Komga(string baseUrl, string username, string password, Logger? logger)
|
public Komga(string baseUrl, string username, string password)
|
||||||
{
|
{
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
|
this.auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
|
||||||
this.logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
||||||
/// <param name="auth">Base64 string of username and password (username):(password)</param>
|
/// <param name="auth">Base64 string of username and password (username):(password)</param>
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public Komga(string baseUrl, string auth, Logger? logger)
|
public Komga(string baseUrl, string auth)
|
||||||
{
|
{
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
this.logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -43,7 +38,6 @@ public class Komga
|
|||||||
/// <returns>Array of KomgaLibraries</returns>
|
/// <returns>Array of KomgaLibraries</returns>
|
||||||
public KomgaLibrary[] GetLibraries()
|
public KomgaLibrary[] GetLibraries()
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
|
||||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
||||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
@ -69,7 +63,6 @@ public class Komga
|
|||||||
/// <returns>true if successful</returns>
|
/// <returns>true if successful</returns>
|
||||||
public bool UpdateLibrary(string libraryId)
|
public bool UpdateLibrary(string libraryId)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
|
||||||
return NetClient.MakePost($"{baseUrl}/api/v1/libraries/{libraryId}/scan", auth);
|
return NetClient.MakePost($"{baseUrl}/api/v1/libraries/{libraryId}/scan", auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using Logging;
|
namespace Tranga;
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes TrangaTasks
|
/// Executes TrangaTasks
|
||||||
@ -16,16 +14,12 @@ public static class TaskExecutor
|
|||||||
/// <param name="trangaTask">Task to execute</param>
|
/// <param name="trangaTask">Task to execute</param>
|
||||||
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
||||||
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
|
/// <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)
|
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||||
{
|
{
|
||||||
//Only execute task if it is not already being executed.
|
//Only execute task if it is not already being executed.
|
||||||
if (trangaTask.state == TrangaTask.ExecutionState.Running)
|
if (trangaTask.state == TrangaTask.ExecutionState.Running)
|
||||||
{
|
|
||||||
logger?.WriteLine("TaskExecutor", $"Task already running {trangaTask}");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
trangaTask.state = TrangaTask.ExecutionState.Running;
|
trangaTask.state = TrangaTask.ExecutionState.Running;
|
||||||
logger?.WriteLine("TaskExecutor", $"Executing Task {trangaTask}");
|
|
||||||
|
|
||||||
//Connector is not needed for all tasks
|
//Connector is not needed for all tasks
|
||||||
Connector? connector = null;
|
Connector? connector = null;
|
||||||
@ -48,8 +42,7 @@ public static class TaskExecutor
|
|||||||
UpdateKomgaLibrary(taskManager);
|
UpdateKomgaLibrary(taskManager);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger?.WriteLine("TaskExecutor", $"Task executed! {trangaTask}");
|
|
||||||
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
||||||
trangaTask.lastExecuted = DateTime.Now;
|
trangaTask.lastExecuted = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Logging;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Tranga.Connectors;
|
using Tranga.Connectors;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
@ -16,23 +15,20 @@ public class TaskManager
|
|||||||
private readonly Connector[] _connectors;
|
private readonly Connector[] _connectors;
|
||||||
private Dictionary<Connector, List<TrangaTask>> tasksToExecute = new();
|
private Dictionary<Connector, List<TrangaTask>> tasksToExecute = new();
|
||||||
private string downloadLocation { get; }
|
private string downloadLocation { get; }
|
||||||
private Logger? logger { get; }
|
|
||||||
|
|
||||||
public Komga? komga { get; }
|
public Komga? komga { get; private set; }
|
||||||
|
|
||||||
/// <param name="folderPath">Local path to save data (Manga) to</param>
|
/// <param name="folderPath">Local path to save data (Manga) to</param>
|
||||||
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
||||||
/// <param name="komgaUsername">The Komga username</param>
|
/// <param name="komgaUsername">The Komga username</param>
|
||||||
/// <param name="komgaPassword">The Komga password</param>
|
/// <param name="komgaPassword">The Komga password</param>
|
||||||
/// <param name="logger"></param>
|
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;
|
this.downloadLocation = folderPath;
|
||||||
|
|
||||||
if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null)
|
if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null)
|
||||||
this.komga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword, logger);
|
this.komga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword);
|
||||||
this._connectors = new Connector[]{ new MangaDex(folderPath, logger) };
|
this._connectors = new Connector[]{ new MangaDex(folderPath) };
|
||||||
foreach(Connector cConnector in this._connectors)
|
foreach(Connector cConnector in this._connectors)
|
||||||
tasksToExecute.Add(cConnector, new List<TrangaTask>());
|
tasksToExecute.Add(cConnector, new List<TrangaTask>());
|
||||||
_allTasks = new HashSet<TrangaTask>();
|
_allTasks = new HashSet<TrangaTask>();
|
||||||
@ -41,10 +37,9 @@ public class TaskManager
|
|||||||
taskChecker.Start();
|
taskChecker.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskManager(SettingsData settings, Logger? logger = null)
|
public TaskManager(SettingsData settings)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation) };
|
||||||
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, logger) };
|
|
||||||
foreach(Connector cConnector in this._connectors)
|
foreach(Connector cConnector in this._connectors)
|
||||||
tasksToExecute.Add(cConnector, new List<TrangaTask>());
|
tasksToExecute.Add(cConnector, new List<TrangaTask>());
|
||||||
this.downloadLocation = settings.downloadLocation;
|
this.downloadLocation = settings.downloadLocation;
|
||||||
@ -79,7 +74,6 @@ public class TaskManager
|
|||||||
ExecuteTaskNow(task);
|
ExecuteTaskNow(task);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Task due: {task}");
|
|
||||||
tasksToExecute[GetConnector(task.connectorName!)].Add(task);
|
tasksToExecute[GetConnector(task.connectorName!)].Add(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,10 +90,9 @@ public class TaskManager
|
|||||||
if (!this._allTasks.Contains(task))
|
if (!this._allTasks.Contains(task))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Forcing Execution: {task}");
|
|
||||||
Task t = new Task(() =>
|
Task t = new Task(() =>
|
||||||
{
|
{
|
||||||
TaskExecutor.Execute(this, task, this._chapterCollection, logger);
|
TaskExecutor.Execute(this, task, this._chapterCollection);
|
||||||
});
|
});
|
||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
@ -116,7 +109,6 @@ public class TaskManager
|
|||||||
public TrangaTask 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 = "")
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task");
|
|
||||||
if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null)
|
if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null)
|
||||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||||
|
|
||||||
@ -150,7 +142,6 @@ public class TaskManager
|
|||||||
_allTasks.Add(newTask);
|
_allTasks.Add(newTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger?.WriteLine(this.GetType().ToString(), newTask.ToString());
|
|
||||||
ExportData(Directory.GetCurrentDirectory());
|
ExportData(Directory.GetCurrentDirectory());
|
||||||
|
|
||||||
return newTask;
|
return newTask;
|
||||||
@ -164,7 +155,6 @@ public class TaskManager
|
|||||||
/// <param name="publication">Publication that was used</param>
|
/// <param name="publication">Publication that was used</param>
|
||||||
public void RemoveTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
public void RemoveTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task}");
|
|
||||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
||||||
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
||||||
else if (connectorName is null)
|
else if (connectorName is null)
|
||||||
@ -217,7 +207,6 @@ public class TaskManager
|
|||||||
/// <param name="force">If force is true, tasks are aborted.</param>
|
/// <param name="force">If force is true, tasks are aborted.</param>
|
||||||
public void Shutdown(bool force = false)
|
public void Shutdown(bool force = false)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})");
|
|
||||||
_continueRunning = false;
|
_continueRunning = false;
|
||||||
ExportData(Directory.GetCurrentDirectory());
|
ExportData(Directory.GetCurrentDirectory());
|
||||||
|
|
||||||
@ -252,7 +241,6 @@ public class TaskManager
|
|||||||
/// <param name="exportFolderPath">Folder path, filename will be data.json</param>
|
/// <param name="exportFolderPath">Folder path, filename will be data.json</param>
|
||||||
private void ExportData(string exportFolderPath)
|
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);
|
SettingsData data = new SettingsData(this.downloadLocation, this.komga, this._allTasks);
|
||||||
|
|
||||||
string exportPath = Path.Join(exportFolderPath, "data.json");
|
string exportPath = Path.Join(exportFolderPath, "data.json");
|
||||||
|
@ -10,8 +10,4 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user