2
0

Remove sortNumber-field from Chapter

API: Change Tasks/Progress chapterSortNumber to ChapterNumber
This commit is contained in:
glax 2023-06-27 23:06:37 +02:00
parent b3e1d39d0f
commit 25a6ceff10
3 changed files with 6 additions and 13 deletions

View File

@ -323,7 +323,7 @@ public class RequestHandler
variables.TryGetValue("taskType", out string? taskType2); variables.TryGetValue("taskType", out string? taskType2);
variables.TryGetValue("connectorName", out string? connectorName4); variables.TryGetValue("connectorName", out string? connectorName4);
variables.TryGetValue("publicationId", out string? publicationId); 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) if (taskType2 is null || connectorName4 is null || publicationId is null)
return null; return null;
Connector? connector = Connector? connector =
@ -337,10 +337,10 @@ public class RequestHandler
if (pTask is TrangaTask.Task.MonitorPublication) if (pTask is TrangaTask.Task.MonitorPublication)
{ {
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault(); 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, task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId,
chapterSortNumber: chapterSortNumber).FirstOrDefault(); chapterNumber: chapterNumber).FirstOrDefault();
} }
if (task is null) if (task is null)
return null; return null;

View File

@ -14,7 +14,6 @@ public struct Chapter
public string? chapterNumber { get; } public string? chapterNumber { get; }
public string url { get; } public string url { get; }
public string fileName { get; } public string fileName { get; }
public string sortNumber { get; }
private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*"); private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url) public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
@ -23,12 +22,6 @@ public struct Chapter
this.volumeNumber = volumeNumber; this.volumeNumber = volumeNumber;
this.chapterNumber = chapterNumber; this.chapterNumber = chapterNumber;
this.url = url; 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 chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : ""; string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : "";

View File

@ -179,7 +179,7 @@ public class TaskManager
return Array.Empty<TrangaTask>(); return Array.Empty<TrangaTask>();
} }
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? chapterNumber = null)
{ {
switch (taskType) switch (taskType)
{ {
@ -215,12 +215,12 @@ public class TaskManager
mTask is DownloadChapterTask dct && dct.connectorName == connectorName && mTask is DownloadChapterTask dct && dct.connectorName == connectorName &&
dct.ToString().Contains(searchString, StringComparison.InvariantCultureIgnoreCase)); 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 => return _allTasks.Where(mTask =>
mTask is DownloadChapterTask dct && dct.connectorName == connectorName && mTask is DownloadChapterTask dct && dct.connectorName == connectorName &&
dct.publication.internalId == internalId && dct.publication.internalId == internalId &&
dct.chapter.sortNumber == chapterSortNumber); dct.chapter.chapterNumber == chapterNumber);
} }
else else
return _allTasks.Where(mTask => return _allTasks.Where(mTask =>