Compare commits
No commits in common. "9fd8bf17413542a11bf7f4611affd6ac812a4b7c" and "4fcaca1a6e48980fd32305ef8027549175bf236b" have entirely different histories.
9fd8bf1741
...
4fcaca1a6e
@ -252,7 +252,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.IncrementProgress(1.0 / imageUrls.Length);
|
||||
parentTask.IncrementProgress(1f / imageUrls.Length);
|
||||
if (cancellationToken?.IsCancellationRequested??false)
|
||||
return;
|
||||
}
|
||||
|
@ -428,16 +428,6 @@ public class TaskManager
|
||||
this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!;
|
||||
}
|
||||
|
||||
foreach (TrangaTask task in this._allTasks.Where(task => task.GetType() == typeof(DownloadChapterTask)))
|
||||
{
|
||||
DownloadChapterTask dcTask = (DownloadChapterTask)task;
|
||||
IEnumerable<TrangaTask> dncTasks = this._allTasks.Where(pTask => pTask.GetType() == typeof(DownloadNewChaptersTask));
|
||||
DownloadNewChaptersTask? parentTask = (DownloadNewChaptersTask?)dncTasks.FirstOrDefault(pTask => pTask.taskId.Equals(dcTask.parentTaskId));
|
||||
dcTask.parentTask = parentTask;
|
||||
parentTask?.AddChildTask(dcTask);
|
||||
}
|
||||
|
||||
|
||||
if (File.Exists(settings.knownPublicationsPath))
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Importing known publications from {settings.knownPublicationsPath}");
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@ -21,9 +20,8 @@ public abstract class TrangaTask
|
||||
public TimeSpan reoccurrence { get; }
|
||||
public DateTime lastExecuted { get; set; }
|
||||
public Task task { get; }
|
||||
public string taskId { get; set; }
|
||||
[Newtonsoft.Json.JsonIgnore]public ExecutionState state { get; set; }
|
||||
[Newtonsoft.Json.JsonIgnore]public double progress { get; protected set; }
|
||||
[Newtonsoft.Json.JsonIgnore]public float progress { get; protected set; }
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
||||
|
||||
@ -35,7 +33,7 @@ public abstract class TrangaTask
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public TimeSpan executionApproximatelyRemaining => this.executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; protected set; }
|
||||
|
||||
public enum ExecutionState
|
||||
{
|
||||
@ -52,17 +50,16 @@ public abstract class TrangaTask
|
||||
this.progress = 0f;
|
||||
this.executionStarted = DateTime.Now;
|
||||
this.lastChange = DateTime.MaxValue;
|
||||
this.taskId = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(this.executionStarted.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
|
||||
public double IncrementProgress(double amount)
|
||||
public float IncrementProgress(float amount)
|
||||
{
|
||||
this.progress += amount;
|
||||
this.lastChange = DateTime.Now;
|
||||
return this.progress;
|
||||
}
|
||||
|
||||
public double DecrementProgress(double amount)
|
||||
public float DecrementProgress(float amount)
|
||||
{
|
||||
this.progress -= amount;
|
||||
this.lastChange = DateTime.Now;
|
||||
|
@ -9,9 +9,7 @@ public class DownloadChapterTask : TrangaTask
|
||||
public Publication publication { get; }
|
||||
public string language { get; }
|
||||
public Chapter chapter { get; }
|
||||
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; set; }
|
||||
public string? parentTaskId { get; set; }
|
||||
|
||||
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; init; }
|
||||
|
||||
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
|
||||
{
|
||||
@ -20,21 +18,24 @@ public class DownloadChapterTask : TrangaTask
|
||||
this.publication = publication;
|
||||
this.language = language;
|
||||
this.parentTask = parentTask;
|
||||
this.parentTaskId = parentTask?.taskId;
|
||||
}
|
||||
|
||||
protected override void ExecuteTask(TaskManager taskManager, Logger? logger, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
if (cancellationToken?.IsCancellationRequested??false)
|
||||
return;
|
||||
if(this.parentTask is not null)
|
||||
this.parentTask.state = ExecutionState.Running;
|
||||
Connector connector = taskManager.GetConnector(this.connectorName);
|
||||
connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
|
||||
if(this.parentTask is not null)
|
||||
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()
|
||||
{
|
||||
|
@ -9,7 +9,6 @@ public class DownloadNewChaptersTask : TrangaTask
|
||||
public Publication publication { get; }
|
||||
public string language { get; }
|
||||
[JsonIgnore]private HashSet<DownloadChapterTask> 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)
|
||||
{
|
||||
@ -18,6 +17,20 @@ 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)
|
||||
{
|
||||
@ -49,11 +62,6 @@ public class DownloadNewChaptersTask : TrangaTask
|
||||
this.childTasks.Remove(failed);
|
||||
this.childTasks.Add(newTask);
|
||||
}
|
||||
|
||||
public void AddChildTask(DownloadChapterTask childTask)
|
||||
{
|
||||
this.childTasks.Add(childTask);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the available Chapters of a Publication
|
||||
|
@ -367,8 +367,14 @@ function ShowTasksQueue(){
|
||||
tagTasksRunning.innerText = json.length;
|
||||
json.forEach(task => {
|
||||
downloadTasksOutput.appendChild(CreateProgressChild(task));
|
||||
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
||||
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||
|
||||
if(task.chapter != undefined){
|
||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).value = task.progress;
|
||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||
}else{
|
||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}`).value = task.progress;
|
||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -395,13 +401,11 @@ function CreateProgressChild(task){
|
||||
|
||||
|
||||
var progress = document.createElement("progress");
|
||||
progress.id = `progress${task.taskId.replaceAll('=','')}`;
|
||||
child.appendChild(progress);
|
||||
|
||||
var progressStr = document.createElement("span");
|
||||
progressStr.innerText = "00.00%";
|
||||
progressStr.className = "progressStr";
|
||||
progressStr.id = `progressStr${task.taskId.replaceAll('=','')}`;
|
||||
child.appendChild(progressStr);
|
||||
|
||||
if(task.chapter != undefined){
|
||||
@ -414,6 +418,12 @@ function CreateProgressChild(task){
|
||||
chapterName.className = "chapterName";
|
||||
chapterName.innerText = task.chapter.name;
|
||||
child.appendChild(chapterName);
|
||||
|
||||
progress.id = `progress${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`;
|
||||
progressStr.id = `progressStr${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`;
|
||||
}else{
|
||||
progress.id = `progress${task.publication.internalId.replace('=','')}`;
|
||||
progressStr.id = `progressStr${task.publication.internalId.replace('=','')}`;
|
||||
}
|
||||
|
||||
|
||||
@ -484,8 +494,13 @@ setInterval(() => {
|
||||
setInterval(() => {
|
||||
GetRunningTasks().then((json) => {
|
||||
json.forEach(task => {
|
||||
document.querySelector(`#progress${task.taskId.replaceAll('=','')}`).value = task.progress;
|
||||
document.querySelector(`#progressStr${task.taskId.replaceAll('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||
if(task.chapter != undefined){
|
||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).value = task.progress;
|
||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}-${task.chapter.chapterNumber}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||
}else{
|
||||
document.querySelector(`#progress${task.publication.internalId.replace('=','')}`).value = task.progress;
|
||||
document.querySelector(`#progressStr${task.publication.internalId.replace('=','')}`).innerText = task.progress.toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
|
||||
}
|
||||
});
|
||||
});
|
||||
},500);
|
Loading…
Reference in New Issue
Block a user