2
0

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

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

View File

@ -183,7 +183,7 @@ public abstract class Connector
string extension = split[^1];
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
parentTask.progress += 1f / imageUrls.Length;
parentTask.IncrementProgress(1f / imageUrls.Length);
}
if(comicInfoPath is not null)

View File

@ -21,7 +21,7 @@ public abstract class TrangaTask
public DateTime lastExecuted { get; set; }
public Task task { get; }
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
[Newtonsoft.Json.JsonIgnore]public float progress { get; set; }
[Newtonsoft.Json.JsonIgnore]public float progress { get; protected set; }
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
public enum ExecutionState
@ -39,6 +39,12 @@ public abstract class TrangaTask
this.progress = 0f;
}
public float IncrementProgress(float amount)
{
this.progress += amount;
return this.progress;
}
/// <summary>
/// BL for concrete Tasks
/// </summary>

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}";

View File

@ -1,4 +1,5 @@
using Logging;
using Newtonsoft.Json;
namespace Tranga.TrangaTasks;
@ -7,34 +8,38 @@ public class DownloadNewChaptersTask : TrangaTask
public string connectorName { get; }
public Publication publication { get; }
public string language { get; }
[JsonIgnore]private int childTaskAmount { get; set; }
public DownloadNewChaptersTask(Task task, string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(task, reoccurrence)
{
this.connectorName = connectorName;
this.publication = publication;
this.language = language;
childTaskAmount = 0;
}
public new float IncrementProgress(float amount)
{
this.progress += amount / this.childTaskAmount;
return this.progress;
}
protected override void ExecuteTask(TaskManager taskManager, Logger? logger)
{
Publication pub = publication!;
Connector connector = taskManager.GetConnector(this.connectorName);
this.progress = 0.1f;
//Check if Publication already has a Folder
pub.CreatePublicationFolder(taskManager.settings.downloadLocation);
this.progress = 0.2f;
List<Chapter> newChapters = GetNewChaptersList(connector, pub, language!, ref taskManager.chapterCollection);
this.progress = 0.6f;
this.childTaskAmount = newChapters.Count;
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);
this.progress = 0.7f;
pub.SaveSeriesInfoJson(connector.downloadLocation);
this.progress = 0.8f;
foreach (Chapter newChapter in newChapters)
taskManager.AddTask(new DownloadChapterTask(Task.DownloadChapter, this.connectorName!, pub, newChapter, this.language));
this.progress = 1f;
taskManager.AddTask(new DownloadChapterTask(Task.DownloadChapter, this.connectorName!, pub, newChapter, this.language, this));
}
/// <summary>