2023-05-17 23:23:01 +02:00
|
|
|
|
namespace Tranga;
|
|
|
|
|
|
|
|
|
|
public class TrangaTask
|
|
|
|
|
{
|
|
|
|
|
private readonly Action _taskAction;
|
|
|
|
|
private Task? _task;
|
|
|
|
|
public bool lastExecutedSuccessfully => _task is not null && _task.IsCompleted;
|
|
|
|
|
public TimeSpan reoccurrence { get; }
|
|
|
|
|
public DateTime lastExecuted { get; private set; }
|
|
|
|
|
|
|
|
|
|
public TrangaTask(Action taskAction, TimeSpan reoccurrence)
|
|
|
|
|
{
|
|
|
|
|
this._taskAction = taskAction;
|
|
|
|
|
this.reoccurrence = reoccurrence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Abort()
|
|
|
|
|
{
|
|
|
|
|
if(_task is not null && !_task.IsCompleted)
|
|
|
|
|
_task.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute()
|
|
|
|
|
{
|
|
|
|
|
lastExecuted = DateTime.Now;
|
|
|
|
|
_task = new (_taskAction);
|
|
|
|
|
_task.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 16:21:02 +02:00
|
|
|
|
public static TrangaTask CreateDownloadChapterTask(Connector connector, Publication publication, Chapter chapter, TimeSpan reoccurrence)
|
2023-05-17 23:23:01 +02:00
|
|
|
|
{
|
|
|
|
|
void TaskAction()
|
|
|
|
|
{
|
2023-05-18 16:21:02 +02:00
|
|
|
|
connector.DownloadChapter(publication, chapter);
|
2023-05-17 23:23:01 +02:00
|
|
|
|
}
|
|
|
|
|
return new TrangaTask(TaskAction, reoccurrence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static TrangaTask CreateUpdateChaptersTask(Connector connector, Publication publication, TimeSpan reoccurrence)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TrangaTask CreateUpdatePublicationsTask(Connector connector, TimeSpan reoccurrence)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|