Added taskId to trangaTask and parentTaskId to DownloadChapterTask as unique identifier to attach ChildTasks to ParentTask on deserialization.
This commit is contained in:
parent
6eaba07801
commit
c8e27921ab
@ -428,6 +428,16 @@ 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,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@ -20,6 +21,7 @@ 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 DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||
@ -50,6 +52,7 @@ 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)
|
||||
|
@ -9,7 +9,9 @@ public class DownloadChapterTask : TrangaTask
|
||||
public Publication publication { get; }
|
||||
public string language { get; }
|
||||
public Chapter chapter { get; }
|
||||
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; init; }
|
||||
[JsonIgnore]public DownloadNewChaptersTask? parentTask { get; set; }
|
||||
public string? parentTaskId { get; set; }
|
||||
|
||||
|
||||
public DownloadChapterTask(Task task, string connectorName, Publication publication, Chapter chapter, string language = "en", DownloadNewChaptersTask? parentTask = null) : base(task, TimeSpan.Zero)
|
||||
{
|
||||
@ -18,6 +20,7 @@ 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)
|
||||
|
@ -62,6 +62,11 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user