Changed taskProgress increment to call method that updates progress accordingly (with parent-tasks being also updated)

This commit is contained in:
2023-06-06 20:54:21 +02:00
parent 5b4a3b9d7c
commit 17ce820cf3
4 changed files with 32 additions and 10 deletions

View File

@ -1,4 +1,5 @@
using Logging;
using Newtonsoft.Json;
namespace Tranga.TrangaTasks;
@ -8,12 +9,15 @@ public class DownloadChapterTask : TrangaTask
public Publication publication { get; }
public string language { get; }
public Chapter chapter { get; }
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en") : base(task, TimeSpan.Zero)
[JsonIgnore]private DownloadNewChaptersTask? parentTask { get; init; }
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
{
this.chapter = chapter;
this.connectorName = connectorName;
this.publication = publication;
this.language = language;
this.parentTask = parentTask;
}
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
@ -24,6 +28,13 @@ public class DownloadChapterTask : TrangaTask
taskManager.DeleteTask(this);
}
public new float IncrementProgress(float amount)
{
this.progress += amount;
parentTask?.IncrementProgress(amount);
return this.progress;
}
public override string ToString()
{
return $"{base.ToString()}, {connectorName}, {publication.sortName} {publication.internalId}, Vol.{chapter.volumeNumber} Ch.{chapter.chapterNumber}";