glax
6de6d060c4
TrangaTask include information on what to execute where, do not execute tasks. TaskExecutor executes Tasks on information from TrangaTask
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace Tranga;
|
|
|
|
public struct TrangaTask
|
|
{
|
|
[JsonInclude]public TimeSpan reoccurrence { get; }
|
|
[JsonInclude]public DateTime lastExecuted { get; set; }
|
|
[JsonInclude]public Connector connector { get; }
|
|
[JsonInclude]public Task task { get; }
|
|
[JsonInclude]public Publication publication { get; }
|
|
[JsonInclude]public string language { get; }
|
|
|
|
public TrangaTask(Connector connector, Task task, Publication publication, TimeSpan reoccurrence, string language = "")
|
|
{
|
|
this.reoccurrence = reoccurrence;
|
|
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
|
this.connector = connector;
|
|
this.task = task;
|
|
this.publication = publication;
|
|
this.language = language;
|
|
}
|
|
|
|
public bool ShouldExecute(bool willBeExecuted)
|
|
{
|
|
bool ret = (DateTime.Now - lastExecuted) > reoccurrence;
|
|
if (ret && willBeExecuted)
|
|
lastExecuted = DateTime.Now;
|
|
return ret;
|
|
}
|
|
|
|
public enum Task
|
|
{
|
|
UpdatePublications,
|
|
UpdateChapters,
|
|
DownloadNewChapters
|
|
}
|
|
} |