diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs
index 6cd8a10..4663a29 100644
--- a/Tranga/TrangaTask.cs
+++ b/Tranga/TrangaTask.cs
@@ -36,13 +36,29 @@ public abstract class TrangaTask
this.task = task;
this.language = language;
}
-
+
///
- /// Should call StartExecutionChores and EndExecutionChores
+ /// BL for concrete Tasks
///
///
///
- public abstract void Execute(TaskManager taskManager, Logger? logger);
+ protected abstract void ExecuteTask(TaskManager taskManager, Logger? logger);
+
+ ///
+ /// Execute the task
+ ///
+ /// Should be the parent taskManager
+ ///
+ public void Execute(TaskManager taskManager, Logger? logger)
+ {
+ logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}");
+ this.state = ExecutionState.Running;
+ ExecuteTask(taskManager, logger);
+ this.lastExecuted = DateTime.Now;
+ this.state = ExecutionState.Waiting;
+ logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
+
+ }
/// True if elapsed time since last execution is greater than set interval
public bool ShouldExecute()
@@ -50,19 +66,6 @@ public abstract class TrangaTask
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
}
- protected void StartExecutionChores(Logger? logger)
- {
- logger?.WriteLine(this.GetType().ToString(), $"Executing Task {this}");
- this.state = ExecutionState.Running;
- }
-
- protected void EndExecutionChores(Logger? logger)
- {
- logger?.WriteLine(this.GetType().ToString(), $"Finished Executing Task {this}");
- this.lastExecuted = DateTime.Now;
- this.state = ExecutionState.Waiting;
- }
-
public enum Task : byte
{
DownloadNewChapters = 2,
diff --git a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
index 41d2106..7be44d2 100644
--- a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
+++ b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs
@@ -8,9 +8,8 @@ public class DownloadNewChaptersTask : TrangaTask
{
}
- public override void Execute(TaskManager taskManager, Logger? logger)
+ protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
{
- StartExecutionChores(logger);
Publication pub = (Publication)this.publication!;
Connector connector = taskManager.GetConnector(this.connectorName);
@@ -26,8 +25,6 @@ public class DownloadNewChaptersTask : TrangaTask
foreach(Chapter newChapter in newChapters)
connector.DownloadChapter(pub, newChapter);
-
- EndExecutionChores(logger);
}
///
diff --git a/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs b/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs
index c066347..af076fb 100644
--- a/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs
+++ b/Tranga/TrangaTasks/UpdateKomgaLibraryTask.cs
@@ -8,9 +8,8 @@ public class UpdateKomgaLibraryTask : TrangaTask
{
}
- public override void Execute(TaskManager taskManager, Logger? logger)
+ protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
{
- StartExecutionChores(logger);
if (taskManager.komga is null)
return;
Komga komga = taskManager.komga;
@@ -18,6 +17,5 @@ public class UpdateKomgaLibraryTask : TrangaTask
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
foreach (Komga.KomgaLibrary lib in allLibraries)
komga.UpdateLibrary(lib.id);
- EndExecutionChores(logger);
}
}
\ No newline at end of file