2023-05-19 19:20:06 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace Tranga;
|
2023-05-18 21:08:09 +02:00
|
|
|
|
|
2023-05-19 20:03:17 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores information on Task
|
|
|
|
|
/// </summary>
|
2023-05-19 16:27:56 +02:00
|
|
|
|
public class TrangaTask
|
2023-05-19 14:00:30 +02:00
|
|
|
|
{
|
2023-05-20 01:06:12 +02:00
|
|
|
|
// ReSharper disable once CommentTypo ...tell me why!
|
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
|
2023-05-19 16:23:37 +02:00
|
|
|
|
public TimeSpan reoccurrence { get; }
|
|
|
|
|
public DateTime lastExecuted { get; set; }
|
|
|
|
|
public string connectorName { get; }
|
|
|
|
|
public Task task { get; }
|
|
|
|
|
public Publication? publication { get; }
|
|
|
|
|
public string language { get; }
|
2023-05-19 19:20:06 +02:00
|
|
|
|
[JsonIgnore]public bool isBeingExecuted { get; set; }
|
2023-05-19 14:00:30 +02:00
|
|
|
|
|
2023-05-19 16:27:56 +02:00
|
|
|
|
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
|
2023-05-17 23:23:01 +02:00
|
|
|
|
{
|
2023-05-19 16:27:56 +02:00
|
|
|
|
if (task != Task.UpdatePublications && publication is null)
|
|
|
|
|
throw new ArgumentException($"Publication has to be not null for task {task}");
|
|
|
|
|
this.publication = publication;
|
2023-05-18 21:08:09 +02:00
|
|
|
|
this.reoccurrence = reoccurrence;
|
2023-05-19 14:00:30 +02:00
|
|
|
|
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
2023-05-19 16:27:56 +02:00
|
|
|
|
this.connectorName = connectorName;
|
2023-05-19 14:00:30 +02:00
|
|
|
|
this.task = task;
|
|
|
|
|
this.language = language;
|
2023-05-18 21:08:09 +02:00
|
|
|
|
}
|
2023-05-17 23:23:01 +02:00
|
|
|
|
|
2023-05-19 20:03:17 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
2023-05-19 16:27:56 +02:00
|
|
|
|
public bool ShouldExecute()
|
2023-05-17 23:23:01 +02:00
|
|
|
|
{
|
2023-05-19 16:27:56 +02:00
|
|
|
|
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence;
|
2023-05-17 23:23:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 14:00:30 +02:00
|
|
|
|
public enum Task
|
2023-05-17 23:23:01 +02:00
|
|
|
|
{
|
2023-05-19 14:00:30 +02:00
|
|
|
|
UpdatePublications,
|
|
|
|
|
UpdateChapters,
|
|
|
|
|
DownloadNewChapters
|
2023-05-17 23:23:01 +02:00
|
|
|
|
}
|
2023-05-20 00:37:31 +02:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{task}\t{lastExecuted}\t{reoccurrence}\t{(isBeingExecuted ? "running" : "waiting")}\t{connectorName}\t{publication?.sortName}";
|
|
|
|
|
}
|
2023-05-17 23:23:01 +02:00
|
|
|
|
}
|