Compare commits

..

5 Commits

Author SHA1 Message Date
61024bcee9 UserDictionary and variable readonly 2023-08-27 01:22:39 +02:00
ea1b8749a6 Removed unnecessary check 2023-08-27 01:22:21 +02:00
2fcab1f1b1 More Logging 2023-08-27 01:22:08 +02:00
bbd716383a Added ToString overrides 2023-08-27 01:21:23 +02:00
6e1a0ab06c Corrected order of constructor (GlobalBase clone) 2023-08-27 01:15:02 +02:00
19 changed files with 70 additions and 25 deletions

View File

@ -2,7 +2,9 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=altnames/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=authorsartists/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=jjob/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lunasea/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mangakatana/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>

View File

@ -36,6 +36,10 @@ public readonly struct Chapter
this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
}
public override string ToString()
{
return $"Chapter {parentPublication.sortName} {parentPublication.internalId} {chapterNumber} {name}";
}
/// <summary>
/// Checks if a chapter-archive is already present

View File

@ -49,6 +49,7 @@ public abstract class GlobalBase
protected void AddNotificationConnector(NotificationConnector notificationConnector)
{
Log($"Adding {notificationConnector}");
notificationConnectors.RemoveWhere(nc => nc.GetType() == notificationConnector.GetType());
notificationConnectors.Add(notificationConnector);
@ -59,6 +60,7 @@ public abstract class GlobalBase
protected void DeleteNotificationConnector(NotificationConnector.NotificationManagerType notificationManagerType)
{
Log($"Removing {notificationManagerType}");
notificationConnectors.RemoveWhere(nc => nc.notificationManagerType == notificationManagerType);
}
@ -70,6 +72,7 @@ public abstract class GlobalBase
protected void AddLibraryConnector(LibraryConnector libraryConnector)
{
Log($"Adding {libraryConnector}");
libraryConnectors.RemoveWhere(lc => lc.GetType() == libraryConnector.GetType());
libraryConnectors.Add(libraryConnector);
@ -80,6 +83,7 @@ public abstract class GlobalBase
protected void DeleteLibraryConnector(LibraryConnector.LibraryType libraryType)
{
Log($"Removing {libraryType}");
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType);
}

View File

@ -17,6 +17,11 @@ public class DownloadChapter : Job
return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), chapter.parentPublication.internalId, chapter.chapterNumber)));
}
public override string ToString()
{
return $"DownloadChapter {id} {chapter}";
}
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()
{
Task downloadTask = new(delegate

View File

@ -17,6 +17,11 @@ public class DownloadNewChapters : Job
return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), publication.internalId)));
}
public override string ToString()
{
return $"DownloadChapter {id} {publication}";
}
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()
{
Chapter[] chapters = mangaConnector.GetNewChapters(publication);

View File

@ -15,22 +15,22 @@ public class JobBoss : GlobalBase
public void AddJob(Job job)
{
Log($"Added {job}");
this.jobs.Add(job);
}
public void RemoveJob(Job job)
{
Log($"Removing {job}");
job.Cancel();
this.jobs.Remove(job);
}
public void RemoveJobs(IEnumerable<Job> jobs)
public void RemoveJobs(IEnumerable<Job> jobsToRemove)
{
foreach (Job job in jobs)
{
job.Cancel();
this.jobs.Remove(job);
}
Log($"Removing {jobsToRemove.Count()} jobs.");
foreach (Job job in jobsToRemove)
RemoveJob(job);
}
public IEnumerable<Job> GetJobsLike(string? connectorName = null, string? internalId = null, string? chapterNumber = null)

View File

@ -17,6 +17,11 @@ public class Kavita : LibraryConnector
{
}
public override string ToString()
{
return $"Kavita {baseUrl}";
}
private static string GetToken(string baseUrl, string username, string password)
{
HttpClient client = new()
@ -37,7 +42,7 @@ public class Kavita : LibraryConnector
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
if (result is not null)
return result["token"]!.GetValue<string>();
else return "";
else throw new Exception("Did not receive token.");
}
public override void UpdateLibrary()

View File

@ -20,6 +20,11 @@ public class Komga : LibraryConnector
{
}
public override string ToString()
{
return $"Komga {baseUrl}";
}
public override void UpdateLibrary()
{
Log("Updating libraries.");

View File

@ -20,7 +20,7 @@ internal class DownloadClient : GlobalBase
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
private readonly Dictionary<byte, TimeSpan> _rateLimit;
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, GlobalBase clone) : base(clone)
public DownloadClient(GlobalBase clone, Dictionary<byte, int> rateLimitRequestsPerMinute) : base(clone)
{
_lastExecutedRateLimit = new();
_rateLimit = new();
@ -60,6 +60,7 @@ internal class DownloadClient : GlobalBase
if(referrer is not null)
requestMessage.Headers.Referrer = new Uri(referrer);
_lastExecutedRateLimit[requestType] = DateTime.Now;
Log($"Requesting {requestType} {url}");
response = Client.Send(requestMessage);
}
catch (HttpRequestException e)

View File

@ -18,8 +18,7 @@ public abstract class MangaConnector : GlobalBase
protected MangaConnector(GlobalBase clone) : base(clone)
{
if (!Directory.Exists(settings.coverImageCache))
Directory.CreateDirectory(settings.coverImageCache);
Directory.CreateDirectory(settings.coverImageCache);
}
public abstract string name { get; } //Name of the Connector (e.g. Website)

View File

@ -21,14 +21,14 @@ public class MangaDex : MangaConnector
public MangaDex(GlobalBase clone) : base(clone)
{
name = "MangaDex";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
this.downloadClient = new DownloadClient(clone, new Dictionary<byte, int>()
{
{(byte)RequestType.Manga, 250},
{(byte)RequestType.Feed, 250},
{(byte)RequestType.AtHomeServer, 40},
{(byte)RequestType.CoverUrl, 250},
{(byte)RequestType.Author, 250}
}, clone);
});
}
public override Publication[] GetPublications(string publicationTitle = "")

View File

@ -13,10 +13,10 @@ public class MangaKatana : MangaConnector
public MangaKatana(GlobalBase clone) : base(clone)
{
this.name = "MangaKatana";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
this.downloadClient = new DownloadClient(clone, new Dictionary<byte, int>()
{
{1, 60}
}, clone);
});
}
public override Publication[] GetPublications(string publicationTitle = "")

View File

@ -13,10 +13,10 @@ public class Manganato : MangaConnector
public Manganato(GlobalBase clone) : base(clone)
{
this.name = "Manganato";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
this.downloadClient = new DownloadClient(clone, new Dictionary<byte, int>()
{
{1, 60}
}, clone);
});
}
public override Publication[] GetPublications(string publicationTitle = "")

View File

@ -18,10 +18,10 @@ public class Mangasee : MangaConnector
public Mangasee(GlobalBase clone) : base(clone)
{
this.name = "Mangasee";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
this.downloadClient = new DownloadClient(clone, new Dictionary<byte, int>()
{
{ 1, 60 }
}, clone);
});
Task d = new Task(DownloadBrowser);
d.Start();

View File

@ -17,6 +17,11 @@ public class Gotify : NotificationConnector
this.appToken = appToken;
}
public override string ToString()
{
return $"Gotify {endpoint}";
}
public override void SendNotification(string title, string notificationText)
{
Log($"Sending notification: {title} - {notificationText}");
@ -28,7 +33,7 @@ public class Gotify : NotificationConnector
if (!response.IsSuccessStatusCode)
{
StreamReader sr = new (response.Content.ReadAsStream());
logger?.WriteLine(this.GetType().ToString(), $"{response.StatusCode}: {sr.ReadToEnd()}");
Log($"{response.StatusCode}: {sr.ReadToEnd()}");
}
}

View File

@ -15,6 +15,11 @@ public class LunaSea : NotificationConnector
this.id = id;
}
public override string ToString()
{
return $"LunaSea {id}";
}
public override void SendNotification(string title, string notificationText)
{
Log($"Sending notification: {title} - {notificationText}");

View File

@ -2,7 +2,7 @@
public abstract class NotificationConnector : GlobalBase
{
public NotificationManagerType notificationManagerType;
public readonly NotificationManagerType notificationManagerType;
protected NotificationConnector(GlobalBase clone, NotificationManagerType notificationManagerType) : base(clone)
{

View File

@ -58,6 +58,11 @@ public struct Publication
this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f;
}
public override string ToString()
{
return $"Publication {sortName} {internalId}";
}
public string CreatePublicationFolder(string downloadDirectory)
{
string publicationFolder = Path.Join(downloadDirectory, this.folderName);

View File

@ -397,9 +397,9 @@ public class Server : GlobalBase
: Array.Empty<byte>());
response.OutputStream.Close();
}
catch (HttpListenerException)
catch (HttpListenerException e)
{
Log(e.ToString());
}
}
}