From 25a6ceff10c3f436ce9d4a8518877335732433ec Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 27 Jun 2023 23:06:37 +0200 Subject: [PATCH] Remove sortNumber-field from Chapter API: Change Tasks/Progress chapterSortNumber to ChapterNumber --- API/RequestHandler.cs | 6 +++--- Tranga/Chapter.cs | 7 ------- Tranga/TaskManager.cs | 6 +++--- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/API/RequestHandler.cs b/API/RequestHandler.cs index 27d5cad..625da3d 100644 --- a/API/RequestHandler.cs +++ b/API/RequestHandler.cs @@ -323,7 +323,7 @@ public class RequestHandler variables.TryGetValue("taskType", out string? taskType2); variables.TryGetValue("connectorName", out string? connectorName4); variables.TryGetValue("publicationId", out string? publicationId); - variables.TryGetValue("chapterSortNumber", out string? chapterSortNumber); + variables.TryGetValue("chapterNumber", out string? chapterNumber); if (taskType2 is null || connectorName4 is null || publicationId is null) return null; Connector? connector = @@ -337,10 +337,10 @@ public class RequestHandler if (pTask is TrangaTask.Task.MonitorPublication) { task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault(); - }else if (pTask is TrangaTask.Task.DownloadChapter && chapterSortNumber is not null) + }else if (pTask is TrangaTask.Task.DownloadChapter && chapterNumber is not null) { task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId, - chapterSortNumber: chapterSortNumber).FirstOrDefault(); + chapterNumber: chapterNumber).FirstOrDefault(); } if (task is null) return null; diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 3808261..c36ad3a 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -14,7 +14,6 @@ public struct Chapter public string? chapterNumber { get; } public string url { get; } public string fileName { get; } - public string sortNumber { get; } private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*"); public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url) @@ -23,12 +22,6 @@ public struct Chapter this.volumeNumber = volumeNumber; this.chapterNumber = chapterNumber; this.url = url; - NumberFormatInfo nfi = new NumberFormatInfo() - { - NumberDecimalSeparator = "." - }; - sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber ?? "1") * Convert.ToDecimal(this.chapterNumber, nfi), 1) - .ToString(nfi); string chapterName = string.Concat(LegalCharacters.Matches(name ?? "")); string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : ""; diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index a246251..f03f1fd 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -179,7 +179,7 @@ public class TaskManager return Array.Empty(); } - public IEnumerable GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterSortNumber = null) + public IEnumerable GetTasksMatching(TrangaTask.Task taskType, string? connectorName = null, string? searchString = null, string? internalId = null, string? chapterNumber = null) { switch (taskType) { @@ -215,12 +215,12 @@ public class TaskManager mTask is DownloadChapterTask dct && dct.connectorName == connectorName && dct.ToString().Contains(searchString, StringComparison.InvariantCultureIgnoreCase)); } - else if (internalId is not null && chapterSortNumber is not null) + else if (internalId is not null && chapterNumber is not null) { return _allTasks.Where(mTask => mTask is DownloadChapterTask dct && dct.connectorName == connectorName && dct.publication.internalId == internalId && - dct.chapter.sortNumber == chapterSortNumber); + dct.chapter.chapterNumber == chapterNumber); } else return _allTasks.Where(mTask =>