Compare commits
No commits in common. "abc66511d882443b752dee7cbd05d928dfbce23e" and "0f9ac60fcd78f04c087429aeaea5eab6b9c5aced" have entirely different histories.
abc66511d8
...
0f9ac60fcd
@ -1,5 +1,4 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Logging;
|
using Logging;
|
||||||
@ -19,10 +18,7 @@ public class Server
|
|||||||
public Server(int port, TaskManager taskManager, Logger? logger = null)
|
public Server(int port, TaskManager taskManager, Logger? logger = null)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
this._listener.Prefixes.Add($"http://*:{port}/");
|
||||||
this._listener.Prefixes.Add($"http://*:{port}/");
|
|
||||||
else
|
|
||||||
this._listener.Prefixes.Add($"http://localhost:{port}/");
|
|
||||||
this._requestHandler = new RequestHandler(taskManager, this);
|
this._requestHandler = new RequestHandler(taskManager, this);
|
||||||
Listen();
|
Listen();
|
||||||
}
|
}
|
||||||
@ -54,21 +50,12 @@ public class Server
|
|||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.HttpMethod == "OPTIONS")
|
_requestHandler.HandleRequest(request, response);
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.OK, response);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_requestHandler.HandleRequest(request, response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
internal void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||||
{
|
{
|
||||||
if (!response.OutputStream.CanWrite)
|
|
||||||
return;
|
|
||||||
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
||||||
response.StatusCode = (int)statusCode;
|
response.StatusCode = (int)statusCode;
|
||||||
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
||||||
|
@ -81,15 +81,23 @@ public class TaskManager
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (TrangaTask failedDownloadChapterTask in _allTasks.Where(taskQuery =>
|
TrangaTask[] failedDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||||
taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray())
|
taskQuery.state is TrangaTask.ExecutionState.Failed && taskQuery is DownloadChapterTask).ToArray();
|
||||||
|
foreach (TrangaTask failedDownloadChapterTask in failedDownloadChapterTasks)
|
||||||
{
|
{
|
||||||
DeleteTask(failedDownloadChapterTask);
|
DeleteTask(failedDownloadChapterTask);
|
||||||
TrangaTask newTask = failedDownloadChapterTask.Clone();
|
TrangaTask newTask = failedDownloadChapterTask.Clone();
|
||||||
failedDownloadChapterTask.parentTask?.AddChildTask(newTask);
|
failedDownloadChapterTask.parentTask?.AddChildTask(newTask);
|
||||||
AddTask(newTask);
|
AddTask(newTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrangaTask[] successfulDownloadChapterTasks = _allTasks.Where(taskQuery =>
|
||||||
|
taskQuery.state is TrangaTask.ExecutionState.Success && taskQuery is DownloadChapterTask).ToArray();
|
||||||
|
foreach(TrangaTask successfulDownloadChapterTask in successfulDownloadChapterTasks)
|
||||||
|
{
|
||||||
|
DeleteTask(successfulDownloadChapterTask);
|
||||||
|
}
|
||||||
|
|
||||||
if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting))
|
if(waitingTasksCount != _allTasks.Count(task => task.state is TrangaTask.ExecutionState.Waiting))
|
||||||
ExportDataAndSettings();
|
ExportDataAndSettings();
|
||||||
@ -158,8 +166,6 @@ public class TaskManager
|
|||||||
_runningDownloadChapterTasks[cRemoveTask].Cancel();
|
_runningDownloadChapterTasks[cRemoveTask].Cancel();
|
||||||
_runningDownloadChapterTasks.Remove(cRemoveTask);
|
_runningDownloadChapterTasks.Remove(cRemoveTask);
|
||||||
}
|
}
|
||||||
foreach(TrangaTask childTask in removeTask.childTasks)
|
|
||||||
DeleteTask(childTask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null)
|
public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null)
|
||||||
|
@ -22,14 +22,14 @@ public abstract class TrangaTask
|
|||||||
public DateTime lastExecuted { get; set; }
|
public DateTime lastExecuted { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; }
|
[Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; }
|
||||||
public Task task { get; }
|
public Task task { get; }
|
||||||
public string taskId { get; init; }
|
public string taskId { get; }
|
||||||
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
[Newtonsoft.Json.JsonIgnore] public TrangaTask? parentTask { get; set; }
|
||||||
public string? parentTaskId { get; set; }
|
public string? parentTaskId { get; set; }
|
||||||
[Newtonsoft.Json.JsonIgnore] internal HashSet<TrangaTask> childTasks { get; }
|
[Newtonsoft.Json.JsonIgnore] protected HashSet<TrangaTask> childTasks { get; }
|
||||||
public double progress => GetProgress();
|
public double progress => GetProgress();
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; internal set; }
|
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; private set; }
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => lastChange.Add(GetRemainingTime());
|
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => progress != 0 ? lastChange.Add(GetRemainingTime()) : DateTime.MaxValue;
|
||||||
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
|
||||||
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);
|
||||||
|
|
||||||
@ -72,16 +72,9 @@ public abstract class TrangaTask
|
|||||||
this.state = ExecutionState.Running;
|
this.state = ExecutionState.Running;
|
||||||
this.executionStarted = DateTime.Now;
|
this.executionStarted = DateTime.Now;
|
||||||
this.lastChange = DateTime.Now;
|
this.lastChange = DateTime.Now;
|
||||||
if(parentTask is not null && parentTask.childTasks.All(ct => ct.state is ExecutionState.Waiting))
|
|
||||||
parentTask.executionStarted = DateTime.Now;
|
|
||||||
|
|
||||||
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
HttpStatusCode statusCode = ExecuteTask(taskManager, logger, cancellationToken);
|
||||||
|
|
||||||
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
while(childTasks.Any(ct => ct.state is ExecutionState.Enqueued or ExecutionState.Running))
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
foreach(TrangaTask childTask in this.childTasks.ToArray())
|
|
||||||
taskManager.DeleteTask(childTask);
|
|
||||||
|
|
||||||
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
if ((int)statusCode >= 200 && (int)statusCode < 300)
|
||||||
{
|
{
|
||||||
this.lastExecuted = DateTime.Now;
|
this.lastExecuted = DateTime.Now;
|
||||||
@ -113,10 +106,10 @@ public abstract class TrangaTask
|
|||||||
|
|
||||||
private TimeSpan GetRemainingTime()
|
private TimeSpan GetRemainingTime()
|
||||||
{
|
{
|
||||||
if(progress == 0 || state is ExecutionState.Enqueued or ExecutionState.Waiting or ExecutionState.Failed || lastChange == DateTime.MaxValue)
|
if(progress == 0 || lastChange == DateTime.MaxValue || executionStarted == DateTime.UnixEpoch)
|
||||||
return DateTime.MaxValue.Subtract(lastChange).Subtract(TimeSpan.FromHours(1));
|
return TimeSpan.Zero;
|
||||||
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
TimeSpan elapsed = lastChange.Subtract(executionStarted);
|
||||||
return elapsed.Divide(progress).Multiply(1 - progress);
|
return elapsed.Divide(progress).Subtract(elapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Task : byte
|
public enum Task : byte
|
||||||
|
@ -47,9 +47,6 @@ public class DownloadChapterTask : TrangaTask
|
|||||||
internal void IncrementProgress(double amount)
|
internal void IncrementProgress(double amount)
|
||||||
{
|
{
|
||||||
this._dctProgress += amount;
|
this._dctProgress += amount;
|
||||||
this.lastChange = DateTime.Now;
|
|
||||||
if(this.parentTask is not null)
|
|
||||||
this.parentTask.lastChange = DateTime.Now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -195,7 +195,7 @@ function DownloadChapterTaskClick(){
|
|||||||
|
|
||||||
function DeleteTaskClick(){
|
function DeleteTaskClick(){
|
||||||
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
|
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
|
||||||
DeleteTask("MonitorPublication", taskToDelete.connectorName, toEditId);
|
DeleteTask("DownloadNewChapters", taskToDelete.connectorName, toEditId);
|
||||||
HidePublicationPopup();
|
HidePublicationPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user