Merged API and CLI into one.

This commit is contained in:
glax 2023-07-31 00:31:19 +02:00
parent fa19d3da14
commit 140074208f
11 changed files with 108 additions and 276 deletions

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tranga\Tranga.csproj" />
</ItemGroup>
</Project>

View File

@ -1,52 +0,0 @@
using System.Runtime.InteropServices;
using Logging;
using Tranga;
using Tranga.NotificationManagers;
using Tranga.LibraryManagers;
namespace API;
public static class Program
{
public static void Main(string[] args)
{
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
Directory.CreateDirectory(logsFolderPath);
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
logger.WriteLine("Tranga",value: "\n"+
"-------------------------------------------\n"+
" Starting Tranga-API\n"+
"-------------------------------------------");
logger.WriteLine("Tranga", "Loading settings.");
TrangaSettings settings;
if (File.Exists(settingsFilePath))
settings = TrangaSettings.LoadSettings(settingsFilePath);
else
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath);
Directory.CreateDirectory(settings.workingDirectory);
Directory.CreateDirectory(settings.downloadLocation);
Directory.CreateDirectory(settings.coverImageCache);
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
logger.WriteLine("Tranga", "Loading Taskmanager.");
TaskManager taskManager = new (settings, logger);
Server server = new (6531, taskManager);
foreach(NotificationManager nm in taskManager.commonObjects.notificationManagers)
nm.SendNotification("Tranga-API", "Started Tranga-API");
}
}

View File

@ -2,8 +2,10 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
WORKDIR /src
COPY . /src/
RUN dotnet restore /src/API/API.csproj
COPY Tranga /src/Tranga
COPY Logging /src/Logging
COPY Tranga.sln /src
RUN dotnet restore /src/Tranga/Tranga.csproj
RUN dotnet publish -c Release -o /publish
FROM glax/tranga-base:latest as runtime

View File

@ -30,7 +30,7 @@ public class Logger : TextWriter
{
_formattedConsoleLogger = new FormattedConsoleLogger(stdOut, encoding);
}
else
else if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is null)
{
_formattedConsoleLogger = null;
throw new ArgumentException($"stdOut can not be null for LoggerType {LoggerType.ConsoleLogger}");

View File

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Tranga_CLI</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Tranga\Tranga.csproj" />
</ItemGroup>
</Project>

View File

@ -2,12 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -18,17 +14,9 @@ Global
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Debug|Any CPU.Build.0 = Debug|Any CPU
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.ActiveCfg = Release|Any CPU
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.Build.0 = Release|Any CPU
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4899E3B2-B259-479A-B43E-042D043E9501}.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
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -5,7 +5,7 @@ using Tranga;
using Tranga.Connectors;
using Tranga.TrangaTasks;
namespace API;
namespace Tranga.API;
public class RequestHandler
{

View File

@ -6,12 +6,13 @@ using Logging;
using Newtonsoft.Json;
using Tranga;
namespace API;
namespace Tranga.API;
public class Server
{
private readonly HttpListener _listener = new ();
private readonly RequestHandler _requestHandler;
private readonly TaskManager _taskManager;
internal readonly Logger? logger;
private readonly Regex _validUrl =
@ -19,12 +20,14 @@ public class Server
public Server(int port, TaskManager taskManager, Logger? logger = null)
{
this.logger = logger;
this._taskManager = taskManager;
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
this._listener.Prefixes.Add($"http://*:{port}/");
else
this._listener.Prefixes.Add($"http://localhost:{port}/");
this._requestHandler = new RequestHandler(taskManager, this);
Listen();
Thread listenThread = new Thread(Listen);
listenThread.Start();
}
private void Listen()
@ -32,7 +35,7 @@ public class Server
this._listener.Start();
foreach (string prefix in this._listener.Prefixes)
this.logger?.WriteLine(this.GetType().ToString(), $"Listening on {prefix}");
while (this._listener.IsListening)
while (this._listener.IsListening && _taskManager._continueRunning)
{
HttpListenerContext context = this._listener.GetContextAsync().Result;
Task t = new (() =>

View File

@ -13,7 +13,7 @@ public class TaskManager
public HashSet<Publication> collection = new();
private HashSet<TrangaTask> _allTasks = new();
private readonly Dictionary<TrangaTask, CancellationTokenSource> _runningTasks = new ();
private bool _continueRunning = true;
public bool _continueRunning = true;
private readonly Connector[] _connectors;
public TrangaSettings settings { get; }
public CommonObjects commonObjects { get; init; }

View File

@ -1,139 +1,59 @@
using System.Globalization;
using System.Runtime.InteropServices;
using Logging;
using Tranga;
using Tranga.API;
using Tranga.Connectors;
using Tranga.LibraryManagers;
using Tranga.NotificationManagers;
using Tranga.TrangaTasks;
namespace Tranga_CLI;
namespace Tranga;
/*
* This is written with pure hatred for readability.
* At some point do this properly.
* Read at own risk.
*/
public static class Tranga_Cli
public static class Tranga
{
public static void Main(string[] args)
{
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga");
string logsFolderPath = Path.Join(applicationFolderPath, "logs");
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/log/Tranga" : Path.Join(applicationFolderPath, "log");
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
Directory.CreateDirectory(applicationFolderPath);
Directory.CreateDirectory(logsFolderPath);
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, Console.Out, Console.Out.Encoding, logFilePath);
Console.WriteLine($"Logfile-Path: {logFilePath}");
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
logger.WriteLine("Tranga",value: "\n"+
"-------------------------------------------\n"+
" Starting Tranga-API\n"+
"-------------------------------------------");
logger.WriteLine("Tranga", "Loading settings.");
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath);
TrangaSettings settings = File.Exists(settingsFilePath)
? TrangaSettings.LoadSettings(settingsFilePath)
: new TrangaSettings(downloadFolderPath, applicationFolderPath);
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>(), logger);
Directory.CreateDirectory(settings.workingDirectory);
Directory.CreateDirectory(settings.downloadLocation);
Directory.CreateDirectory(settings.coverImageCache);
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
settings.logger?.WriteLine("Tranga_CLI", "User Input");
Console.WriteLine($"Output folder path [{settings.downloadLocation}]:");
string? tmpPath = Console.ReadLine();
while(tmpPath is null)
tmpPath = Console.ReadLine();
if (tmpPath.Length > 0)
settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, tmpPath);
logger.WriteLine("Tranga", "Loading Taskmanager.");
TaskManager taskManager = new (settings, logger);
Console.WriteLine($"Komga BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Komga))?.baseUrl}]:");
string? tmpUrlKomga = Console.ReadLine();
while (tmpUrlKomga is null)
tmpUrlKomga = Console.ReadLine();
if (tmpUrlKomga.Length > 0)
{
Console.WriteLine("Username:");
string? tmpKomgaUser = Console.ReadLine();
while (tmpKomgaUser is null || tmpKomgaUser.Length < 1)
tmpKomgaUser = Console.ReadLine();
Server _ = new (6531, taskManager);
foreach(NotificationManager nm in taskManager.commonObjects.notificationManagers)
nm.SendNotification("Tranga-API", "Started Tranga-API");
Console.WriteLine("Password:");
string tmpKomgaPass = string.Empty;
ConsoleKey key;
do
{
var keyInfo = Console.ReadKey(intercept: true);
key = keyInfo.Key;
if (key == ConsoleKey.Backspace && tmpKomgaPass.Length > 0)
{
Console.Write("\b \b");
tmpKomgaPass = tmpKomgaPass[0..^1];
}
else if (!char.IsControl(keyInfo.KeyChar))
{
Console.Write("*");
tmpKomgaPass += keyInfo.KeyChar;
}
} while (key != ConsoleKey.Enter);
settings.UpdateSettings(TrangaSettings.UpdateField.Komga, tmpUrlKomga, tmpKomgaUser, tmpKomgaPass);
TaskMode(taskManager, logger);
}
Console.WriteLine($"Kavita BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Kavita))?.baseUrl}]:");
string? tmpUrlKavita = Console.ReadLine();
while (tmpUrlKavita is null)
tmpUrlKavita = Console.ReadLine();
if (tmpUrlKavita.Length > 0)
private static void TaskMode(TaskManager taskManager, Logger logger)
{
Console.WriteLine("Username:");
string? tmpKavitaUser = Console.ReadLine();
while (tmpKavitaUser is null || tmpKavitaUser.Length < 1)
tmpKavitaUser = Console.ReadLine();
Console.WriteLine("Password:");
string tmpKavitaPass = string.Empty;
ConsoleKey key;
do
{
var keyInfo = Console.ReadKey(intercept: true);
key = keyInfo.Key;
if (key == ConsoleKey.Backspace && tmpKavitaPass.Length > 0)
{
Console.Write("\b \b");
tmpKavitaPass = tmpKavitaPass[0..^1];
}
else if (!char.IsControl(keyInfo.KeyChar))
{
Console.Write("*");
tmpKavitaPass += keyInfo.KeyChar;
}
} while (key != ConsoleKey.Enter);
settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, tmpUrlKavita, tmpKavitaUser, tmpKavitaPass);
}
Console.WriteLine($"Gotify BaseURL [{((Gotify?)settings.notificationManagers.FirstOrDefault(lm => lm.GetType() == typeof(Gotify)))?.endpoint}]:");
string? tmpGotifyUrl = Console.ReadLine();
while (tmpGotifyUrl is null)
tmpGotifyUrl = Console.ReadLine();
if (tmpGotifyUrl.Length > 0)
{
Console.WriteLine("AppToken:");
string? tmpGotifyAppToken = Console.ReadLine();
while (tmpGotifyAppToken is null || tmpGotifyAppToken.Length < 1)
tmpGotifyAppToken = Console.ReadLine();
settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, tmpGotifyUrl, tmpGotifyAppToken);
}
logger.WriteLine("Tranga_CLI", "Loaded.");
foreach(NotificationManager nm in settings.notificationManagers)
nm.SendNotification("Tranga", "Loaded.");
TaskMode(settings, logger);
}
private static void TaskMode(TrangaSettings settings, Logger logger)
{
TaskManager taskManager = new (settings);
ConsoleKey selection = ConsoleKey.EraseEndOfFile;
PrintMenu(taskManager, taskManager.settings.downloadLocation);
while (selection != ConsoleKey.Q)
@ -160,22 +80,22 @@ public static class Tranga_Cli
Console.ReadKey();
break;
case ConsoleKey.C:
CreateTask(taskManager, logger);
CreateTask(taskManager);
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
case ConsoleKey.D:
DeleteTask(taskManager, logger);
DeleteTask(taskManager);
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
case ConsoleKey.E:
ExecuteTaskNow(taskManager, logger);
ExecuteTaskNow(taskManager);
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
case ConsoleKey.S:
SearchTasks(taskManager, logger);
SearchTasks(taskManager);
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
@ -259,9 +179,9 @@ public static class Tranga_Cli
Console.WriteLine($"{"",-30}{"F: Show Log",-30}{"Q: Exit",-30}");
}
private static void PrintTasks(TrangaTask[] tasks, Logger logger)
private static void PrintTasks(TrangaTask[] tasks, Logger? logger)
{
logger.WriteLine("Tranga_CLI", "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);
@ -280,19 +200,19 @@ public static class Tranga_Cli
}
private static TrangaTask[] SelectTasks(TrangaTask[] tasks, Logger logger)
private static TrangaTask[] SelectTasks(TrangaTask[] tasks, Logger? logger)
{
logger.WriteLine("Tranga_CLI", "Menu: Select task");
logger?.WriteLine("Tranga_CLI", "Menu: Select task");
if (tasks.Length < 1)
{
Console.Clear();
Console.WriteLine("There are no available Tasks.");
logger.WriteLine("Tranga_CLI", "No available Tasks.");
logger?.WriteLine("Tranga_CLI", "No available Tasks.");
return Array.Empty<TrangaTask>();
}
PrintTasks(tasks, logger);
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
logger?.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
Console.WriteLine("Enter q to abort");
Console.WriteLine($"Select Task(s) (0-{tasks.Length - 1}):");
@ -304,7 +224,7 @@ public static class Tranga_Cli
{
Console.Clear();
Console.WriteLine("aborted.");
logger.WriteLine("Tranga_CLI", "aborted");
logger?.WriteLine("Tranga_CLI", "aborted");
return Array.Empty<TrangaTask>();
}
@ -330,7 +250,7 @@ public static class Tranga_Cli
if (connector is null)
return;
Publication? publication = SelectPublication(taskManager, connector, logger);
Publication? publication = SelectPublication(taskManager, connector);
if (publication is null)
return;
@ -386,10 +306,10 @@ public static class Tranga_Cli
}
}
private static void CreateTask(TaskManager taskManager, Logger logger)
private static void CreateTask(TaskManager taskManager)
{
logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
TrangaTask.Task? tmpTask = SelectTaskType(logger);
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "Menu: Creating Task");
TrangaTask.Task? tmpTask = SelectTaskType(taskManager.commonObjects.logger);
if (tmpTask is null)
return;
TrangaTask.Task task = (TrangaTask.Task)tmpTask;
@ -397,7 +317,7 @@ public static class Tranga_Cli
Connector? connector = null;
if (task != TrangaTask.Task.UpdateLibraries)
{
connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), taskManager.commonObjects.logger);
if (connector is null)
return;
}
@ -405,22 +325,22 @@ public static class Tranga_Cli
Publication? publication = null;
if (task != TrangaTask.Task.UpdateLibraries)
{
publication = SelectPublication(taskManager, connector!, logger);
publication = SelectPublication(taskManager, connector!);
if (publication is null)
return;
}
if (task is TrangaTask.Task.MonitorPublication)
{
TimeSpan reoccurrence = SelectReoccurrence(logger);
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
TimeSpan reoccurrence = SelectReoccurrence(taskManager.commonObjects.logger);
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
TrangaTask newTask = new MonitorPublicationTask(connector!.name, (Publication)publication!, reoccurrence, "en");
taskManager.AddTask(newTask);
Console.WriteLine(newTask);
}else if (task is TrangaTask.Task.DownloadChapter)
{
foreach (Chapter chapter in SelectChapters(connector!, (Publication)publication!, logger))
foreach (Chapter chapter in SelectChapters(connector!, (Publication)publication!, taskManager.commonObjects.logger))
{
TrangaTask newTask = new DownloadChapterTask(connector!.name, (Publication)publication, chapter, "en");
taskManager.AddTask(newTask);
@ -429,31 +349,31 @@ public static class Tranga_Cli
}
}
private static void ExecuteTaskNow(TaskManager taskManager, Logger logger)
private static void ExecuteTaskNow(TaskManager taskManager)
{
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "Menu: Executing Task");
TrangaTask[] tasks = taskManager.GetAllTasks().Where(nTask => nTask.state is not TrangaTask.ExecutionState.Running).ToArray();
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
TrangaTask[] selectedTasks = SelectTasks(tasks, taskManager.commonObjects.logger);
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
foreach(TrangaTask task in selectedTasks)
taskManager.ExecuteTaskNow(task);
}
private static void DeleteTask(TaskManager taskManager, Logger logger)
private static void DeleteTask(TaskManager taskManager)
{
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "Menu: Delete Task");
TrangaTask[] tasks = taskManager.GetAllTasks();
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
TrangaTask[] selectedTasks = SelectTasks(tasks, taskManager.commonObjects.logger);
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
foreach(TrangaTask task in selectedTasks)
taskManager.DeleteTask(task);
}
private static TrangaTask.Task? SelectTaskType(Logger logger)
private static TrangaTask.Task? SelectTaskType(Logger? logger)
{
logger.WriteLine("Tranga_CLI", "Menu: Select TaskType");
logger?.WriteLine("Tranga_CLI", "Menu: Select TaskType");
Console.Clear();
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
@ -473,7 +393,7 @@ public static class Tranga_Cli
{
Console.Clear();
Console.WriteLine("aborted.");
logger.WriteLine("Tranga_CLI", "aborted.");
logger?.WriteLine("Tranga_CLI", "aborted.");
return null;
}
@ -486,22 +406,22 @@ public static class Tranga_Cli
catch (Exception e)
{
Console.WriteLine($"Exception: {e.Message}");
logger.WriteLine("Tranga_CLI", e.Message);
logger?.WriteLine("Tranga_CLI", e.Message);
}
return null;
}
private static TimeSpan SelectReoccurrence(Logger logger)
private static TimeSpan SelectReoccurrence(Logger? logger)
{
logger.WriteLine("Tranga_CLI", "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 Chapter[] SelectChapters(Connector connector, Publication publication, Logger logger)
private static Chapter[] SelectChapters(Connector connector, Publication publication, Logger? logger)
{
logger.WriteLine("Tranga_CLI", "Menu: Select Chapters");
logger?.WriteLine("Tranga_CLI", "Menu: Select Chapters");
Chapter[] availableChapters = connector.GetChapters(publication, "en");
int cIndex = 0;
Console.WriteLine("Chapters:");
@ -540,9 +460,9 @@ public static class Tranga_Cli
return connector.SelectChapters(publication, selectedChapters);
}
private static Connector? SelectConnector(Connector[] connectors, Logger logger)
private static Connector? SelectConnector(Connector[] connectors, Logger? logger)
{
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
logger?.WriteLine("Tranga_CLI", "Menu: Select Connector");
Console.Clear();
int cIndex = 0;
@ -561,7 +481,7 @@ public static class Tranga_Cli
{
Console.Clear();
Console.WriteLine("aborted.");
logger.WriteLine("Tranga_CLI", "aborted.");
logger?.WriteLine("Tranga_CLI", "aborted.");
return null;
}
@ -573,15 +493,15 @@ public static class Tranga_Cli
catch (Exception e)
{
Console.WriteLine($"Exception: {e.Message}");
logger.WriteLine("Tranga_CLI", e.Message);
logger?.WriteLine("Tranga_CLI", e.Message);
}
return null;
}
private static Publication? SelectPublication(TaskManager taskManager, Connector connector, Logger logger)
private static Publication? SelectPublication(TaskManager taskManager, Connector connector)
{
logger.WriteLine("Tranga_CLI", "Menu: Select Publication");
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "Menu: Select Publication");
Console.Clear();
Console.WriteLine($"Connector: {connector.name}");
@ -592,7 +512,7 @@ public static class Tranga_Cli
if (publications.Length < 1)
{
logger.WriteLine("Tranga_CLI", "No publications returned");
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "No publications returned");
Console.WriteLine($"No publications for query '{query}' returned;");
return null;
}
@ -613,7 +533,7 @@ public static class Tranga_Cli
{
Console.Clear();
Console.WriteLine("aborted.");
logger.WriteLine("Tranga_CLI", "aborted.");
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "aborted.");
return null;
}
@ -625,21 +545,21 @@ public static class Tranga_Cli
catch (Exception e)
{
Console.WriteLine($"Exception: {e.Message}");
logger.WriteLine("Tranga_CLI", e.Message);
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", e.Message);
}
return null;
}
private static void SearchTasks(TaskManager taskManager, Logger logger)
private static void SearchTasks(TaskManager taskManager)
{
logger.WriteLine("Tranga_CLI", "Menu: Search task");
taskManager.commonObjects.logger?.WriteLine("Tranga_CLI", "Menu: Search task");
Console.Clear();
Console.WriteLine("Enter search query:");
string? query = Console.ReadLine();
while (query is null || query.Length < 4)
query = Console.ReadLine();
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray(), logger);
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray(), taskManager.commonObjects.logger);
}
}

View File

@ -4,6 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
@ -16,4 +17,11 @@
<ProjectReference Include="..\Logging\Logging.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
<DependentUpon>Dockerfile</DependentUpon>
</Content>
</ItemGroup>
</Project>