Compare commits

..

No commits in common. "d89ca0a2ef0c52f5fee45969f54d8586fce3173f" and "67c23b357f49ba2de8becb020ad859db7c8fce52" have entirely different histories.

7 changed files with 20 additions and 28 deletions

View File

@ -1,6 +1,6 @@
namespace Logging; namespace Logging;
public readonly struct LogMessage public class LogMessage
{ {
public DateTime logTime { get; } public DateTime logTime { get; }
public string caller { get; } public string caller { get; }

View File

@ -6,6 +6,7 @@ public class MemoryLogger : LoggerBase
{ {
private readonly SortedList<DateTime, LogMessage> _logMessages = new(); private readonly SortedList<DateTime, LogMessage> _logMessages = new();
private int _lastLogMessageIndex = 0; private int _lastLogMessageIndex = 0;
private bool _lockLogMessages = false;
public MemoryLogger(Encoding? encoding = null) : base(encoding) public MemoryLogger(Encoding? encoding = null) : base(encoding)
{ {
@ -14,9 +15,12 @@ public class MemoryLogger : LoggerBase
protected override void Write(LogMessage value) protected override void Write(LogMessage value)
{ {
lock (_logMessages) if (!_lockLogMessages)
{ {
_logMessages.Add(DateTime.Now, value); _lockLogMessages = true;
while(!_logMessages.TryAdd(DateTime.Now, value))
Thread.Sleep(10);
_lockLogMessages = false;
} }
} }
@ -37,9 +41,11 @@ public class MemoryLogger : LoggerBase
for (int retIndex = 0; retIndex < ret.Length; retIndex++) for (int retIndex = 0; retIndex < ret.Length; retIndex++)
{ {
lock (_logMessages) if (!_lockLogMessages)
{ {
_lockLogMessages = true;
ret[retIndex] = _logMessages.GetValueAtIndex(_logMessages.Count - retLength + retIndex).ToString(); ret[retIndex] = _logMessages.GetValueAtIndex(_logMessages.Count - retLength + retIndex).ToString();
_lockLogMessages = false;
} }
} }
@ -57,9 +63,11 @@ public class MemoryLogger : LoggerBase
{ {
try try
{ {
lock(_logMessages) if (!_lockLogMessages)
{ {
_lockLogMessages = true;
ret.Add(_logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString()); ret.Add(_logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString());
_lockLogMessages = false;
} }
} }
catch (NullReferenceException e)//Called when LogMessage has not finished writing catch (NullReferenceException e)//Called when LogMessage has not finished writing

View File

@ -24,7 +24,7 @@ public class DownloadChapter : Job
public override string ToString() public override string ToString()
{ {
return $"{id} Chapter: {chapter}"; return $"DownloadChapter {id} {chapter}";
} }
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal() protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()

View File

@ -28,7 +28,7 @@ public class DownloadNewChapters : Job
public override string ToString() public override string ToString()
{ {
return $"{id} Manga: {manga}"; return $"DownloadChapter {id} {manga}";
} }
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal() protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()

View File

@ -18,7 +18,7 @@ public class Mangaworld: MangaConnector
public override Manga[] GetManga(string publicationTitle = "") public override Manga[] GetManga(string publicationTitle = "")
{ {
Log($"Searching Publications. Term=\"{publicationTitle}\""); Log($"Searching Publications. Term=\"{publicationTitle}\"");
string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower(); string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
string requestUrl = $"https://www.mangaworld.bz/archive?keyword={sanitizedTitle}"; string requestUrl = $"https://www.mangaworld.bz/archive?keyword={sanitizedTitle}";
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, 1); downloadClient.MakeRequest(requestUrl, 1);
@ -34,9 +34,6 @@ public class Mangaworld: MangaConnector
private Manga[] ParsePublicationsFromHtml(HtmlDocument document) private Manga[] ParsePublicationsFromHtml(HtmlDocument document)
{ {
if (!document.DocumentNode.SelectSingleNode("//div[@class='comics-grid']").ChildNodes
.Any(node => node.HasClass("entry")))
return Array.Empty<Manga>();
List<string> urls = document.DocumentNode List<string> urls = document.DocumentNode
.SelectNodes( .SelectNodes(
@ -137,8 +134,8 @@ public class Mangaworld: MangaConnector
foreach (HtmlNode volNode in document.DocumentNode.SelectNodes( foreach (HtmlNode volNode in document.DocumentNode.SelectNodes(
"//div[contains(concat(' ',normalize-space(@class),' '),'chapters-wrapper')]//div[contains(concat(' ',normalize-space(@class),' '),'volume-element')]")) "//div[contains(concat(' ',normalize-space(@class),' '),'chapters-wrapper')]//div[contains(concat(' ',normalize-space(@class),' '),'volume-element')]"))
{ {
string volume = volNode.SelectNodes("div").First(node => node.HasClass("volume")).SelectSingleNode("p").InnerText.Split(' ')[^1]; string volume = volNode.SelectSingleNode("//p[contains(concat(' ',normalize-space(@class),' '),'volume-name')]").InnerText.Split(' ')[^1];
foreach (HtmlNode chNode in volNode.SelectNodes("div").First(node => node.HasClass("volume-chapters")).SelectNodes("div")) foreach (HtmlNode chNode in volNode.SelectNodes("//div[contains(concat(' ',normalize-space(@class),' '),'volume-chapters')]/div[@class='chapter']"))
{ {
string number = chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText.Split(" ")[^1]; string number = chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText.Split(" ")[^1];
string url = chNode.SelectSingleNode("a").GetAttributeValue("href", ""); string url = chNode.SelectSingleNode("a").GetAttributeValue("href", "");

View File

@ -13,8 +13,6 @@ public partial class Tranga : GlobalBase
public Tranga(Logger? logger, TrangaSettings settings) : base(logger, settings) public Tranga(Logger? logger, TrangaSettings settings) : base(logger, settings)
{ {
Log("\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n");
Log(settings.ToString());
keepRunning = true; keepRunning = true;
_connectors = new HashSet<MangaConnector>() _connectors = new HashSet<MangaConnector>()
{ {

View File

@ -23,13 +23,13 @@ public class TrangaSettings
string lockFilePath = $"{settingsFilePath}.lock"; string lockFilePath = $"{settingsFilePath}.lock";
if (File.Exists(settingsFilePath) && !File.Exists(lockFilePath)) if (File.Exists(settingsFilePath) && !File.Exists(lockFilePath))
{//Load from settings file {//Load from settings file
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose); //lock settingsfile FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose);
string settingsStr = File.ReadAllText(settingsFilePath); string settingsStr = File.ReadAllText(settingsFilePath);
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!; TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
this.downloadLocation = downloadLocation ?? settings.downloadLocation; this.downloadLocation = downloadLocation ?? settings.downloadLocation;
this.workingDirectory = workingDirectory ?? settings.workingDirectory; this.workingDirectory = workingDirectory ?? settings.workingDirectory;
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber; this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
lockFile.Close(); //unlock settingsfile lockFile.Close();
} }
else if(!File.Exists(settingsFilePath)) else if(!File.Exists(settingsFilePath))
{//No settings file exists {//No settings file exists
@ -132,15 +132,4 @@ public class TrangaSettings
{ {
return Path.Join(this.coverImageCache, manga.coverFileNameInCache); return Path.Join(this.coverImageCache, manga.coverFileNameInCache);
} }
public override string ToString()
{
return $"TrangaSettings:\n" +
$"\tDownloadLocation: {downloadLocation}\n" +
$"\tworkingDirectory: {workingDirectory}\n" +
$"\tjobsFolderPath: {jobsFolderPath}\n" +
$"\tsettingsFilePath: {settingsFilePath}\n" +
$"\t\tnotificationConnectors: {notificationConnectorsFilePath}\n" +
$"\t\tlibraryConnectors: {libraryConnectorsFilePath}\n";
}
} }