Fix Bug where all tasks would be deleted...

This commit is contained in:
glax 2023-06-05 20:52:21 +02:00
parent bbf05e3dec
commit a2e9a3f34a
2 changed files with 9 additions and 9 deletions

View File

@ -79,9 +79,8 @@ app.MapPost("/Tasks/Create", (string taskType, string? connectorName, string? pu
app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) => app.MapDelete("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
{ {
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType); TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
taskManager.DeleteTask(task, connectorName, publication); taskManager.DeleteTask(task, connectorName, publicationId);
}); });
app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) => app.MapGet("/Tasks/Get", (string taskType, string? connectorName, string? searchString) =>

View File

@ -208,9 +208,9 @@ public class TaskManager
/// <param name="task">TrangaTask.Task type</param> /// <param name="task">TrangaTask.Task type</param>
/// <param name="connectorName">Name of Connector that was used</param> /// <param name="connectorName">Name of Connector that was used</param>
/// <param name="publication">Publication that was used</param> /// <param name="publication">Publication that was used</param>
public void DeleteTask(TrangaTask.Task task, string? connectorName, Publication? publication) public void DeleteTask(TrangaTask.Task task, string? connectorName, string? publicationId)
{ {
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}"); logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publicationId}");
switch (task) switch (task)
{ {
@ -220,12 +220,13 @@ public class TaskManager
_allTasks.RemoveWhere(trangaTask => trangaTask.task is TrangaTask.Task.UpdateLibraries); _allTasks.RemoveWhere(trangaTask => trangaTask.task is TrangaTask.Task.UpdateLibraries);
break; break;
case TrangaTask.Task.DownloadNewChapters: case TrangaTask.Task.DownloadNewChapters:
if(connectorName is null || publication is null) if(connectorName is null || publicationId is null)
logger?.WriteLine(this.GetType().ToString(), "connectorName and publication can not be null"); logger?.WriteLine(this.GetType().ToString(), "connectorName and publication can not be null");
_allTasks.RemoveWhere(mTask => else
mTask.GetType() == typeof(DownloadNewChaptersTask) && _allTasks.RemoveWhere(mTask =>
((DownloadNewChaptersTask)mTask).publication.internalId != publication!.Value.publicationId && mTask.GetType() == typeof(DownloadNewChaptersTask) &&
((DownloadNewChaptersTask)mTask).connectorName != connectorName!); ((DownloadNewChaptersTask)mTask).publication.internalId != publicationId &&
((DownloadNewChaptersTask)mTask).connectorName != connectorName!);
break; break;
} }
ExportDataAndSettings(); ExportDataAndSettings();