From d5c9c5ba960b4040ab670af60a3cf90fb67ada5b Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 10 Jun 2023 16:00:16 +0200 Subject: [PATCH] Redid progress calcuation on DownloadNewChaptersTask and DownloadChapterTask --- Tranga/TrangaTask.cs | 2 +- Tranga/TrangaTasks/DownloadChapterTask.cs | 8 -------- Tranga/TrangaTasks/DownloadNewChaptersTask.cs | 15 +-------------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/Tranga/TrangaTask.cs b/Tranga/TrangaTask.cs index 3dd5397..7fdd8e8 100644 --- a/Tranga/TrangaTask.cs +++ b/Tranga/TrangaTask.cs @@ -35,7 +35,7 @@ public abstract class TrangaTask [Newtonsoft.Json.JsonIgnore] public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now); - [Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; protected set; } + [Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; } public enum ExecutionState { diff --git a/Tranga/TrangaTasks/DownloadChapterTask.cs b/Tranga/TrangaTasks/DownloadChapterTask.cs index d6b3f6e..97c12b4 100644 --- a/Tranga/TrangaTasks/DownloadChapterTask.cs +++ b/Tranga/TrangaTasks/DownloadChapterTask.cs @@ -35,14 +35,6 @@ public class DownloadChapterTask : TrangaTask this.parentTask.state = ExecutionState.Waiting; taskManager.DeleteTask(this); } - - public new float IncrementProgress(float amount) - { - this.progress += amount; - this.lastChange = DateTime.Now; - parentTask?.IncrementProgress(amount); - return this.progress; - } public override string ToString() { diff --git a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs index 5b6837e..1f4451f 100644 --- a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs +++ b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs @@ -9,6 +9,7 @@ public class DownloadNewChaptersTask : TrangaTask public Publication publication { get; } public string language { get; } [JsonIgnore]private HashSet childTasks { get; } + [JsonIgnore]public new double progress => childTasks.Count > 0 ? childTasks.Sum(childTask => childTask.progress) / childTasks.Count : 0; public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence) { @@ -17,20 +18,6 @@ public class DownloadNewChaptersTask : TrangaTask this.language = language; this.childTasks = new(); } - - public new float IncrementProgress(float amount) - { - this.progress += amount / this.childTasks.Count; - this.lastChange = DateTime.Now; - return this.progress; - } - - public new float DecrementProgress(float amount) - { - this.progress -= amount / this.childTasks.Count; - this.lastChange = DateTime.Now; - return this.progress; - } protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null) {