mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-18 07:39:13 +02:00
Sync reason System.Reflection.MethodBase.GetCurrentMethod()?.Name
This commit is contained in:
@@ -71,7 +71,7 @@ public class FileLibraryController(MangaContext context) : Controller
|
||||
//TODO Path check
|
||||
library.BasePath = newBasePath;
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class FileLibraryController(MangaContext context) : Controller
|
||||
//TODO Name check
|
||||
library.LibraryName = newName;
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class FileLibraryController(MangaContext context) : Controller
|
||||
Schema.MangaContext.FileLibrary library = new (requestData.BasePath, requestData.LibraryName);
|
||||
context.FileLibraries.Add(library);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
|
||||
return TypedResults.Created(string.Empty, library.Key);
|
||||
@@ -140,7 +140,7 @@ public class FileLibraryController(MangaContext context) : Controller
|
||||
|
||||
context.FileLibraries.Remove(library);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ public class LibraryConnectorController(LibraryContext context) : Controller
|
||||
|
||||
context.LibraryConnectors.Add(connector);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Created(string.Empty, connector.Key);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public class LibraryConnectorController(LibraryContext context) : Controller
|
||||
|
||||
context.LibraryConnectors.Remove(connector);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public class MaintenanceController(MangaContext mangaContext) : Controller
|
||||
|
||||
mangaContext.Mangas.RemoveRange(noDownloads);
|
||||
|
||||
if(await mangaContext.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await mangaContext.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ public class MangaConnectorController(MangaContext context) : Controller
|
||||
|
||||
connector.Enabled = Enabled;
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
@@ -154,7 +154,7 @@ public class MangaController(MangaContext context) : Controller
|
||||
|
||||
context.Mangas.Remove(manga);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
@@ -420,7 +420,7 @@ public class MangaController(MangaContext context) : Controller
|
||||
return TypedResults.NotFound(nameof(MangaId));
|
||||
|
||||
manga.IgnoreChaptersBefore = chapterThreshold;
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
|
||||
return TypedResults.Ok();
|
||||
@@ -488,7 +488,7 @@ public class MangaController(MangaContext context) : Controller
|
||||
}
|
||||
|
||||
mcId.UseForDownload = IsRequested;
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
|
||||
DownloadCoverFromMangaconnectorWorker downloadCover = new(mcId);
|
||||
|
@@ -91,7 +91,7 @@ public class MetadataFetcherController(MangaContext context) : Controller
|
||||
MetadataEntry entry = fetcher.CreateMetadataEntry(manga, Identifier);
|
||||
context.MetadataEntries.Add(entry);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok(entry);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class MetadataFetcherController(MangaContext context) : Controller
|
||||
|
||||
context.Remove(entry);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ public class NotificationConnectorController(NotificationsContext context) : Con
|
||||
context.NotificationConnectors.Add(newConnector);
|
||||
context.Notifications.Add(new ("Added new Notification Connector!", newConnector.Name, NotificationUrgency.High));
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Created(string.Empty, newConnector.Name);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class NotificationConnectorController(NotificationsContext context) : Con
|
||||
|
||||
context.NotificationConnectors.Remove(connector);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType()) is { success: false } result)
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
}
|
||||
|
@@ -116,33 +116,34 @@ app.UseMiddleware<RequestTimeMiddleware>();
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
MangaContext context = scope.ServiceProvider.GetRequiredService<MangaContext>();
|
||||
context.Database.Migrate();
|
||||
|
||||
await context.Database.MigrateAsync(CancellationToken.None);
|
||||
|
||||
if (!context.FileLibraries.Any())
|
||||
context.FileLibraries.Add(new (Tranga.Settings.DefaultDownloadLocation, "Default FileLibrary"));
|
||||
|
||||
await context.Sync(CancellationToken.None);
|
||||
{
|
||||
await context.FileLibraries.AddAsync(new (Tranga.Settings.DefaultDownloadLocation, "Default FileLibrary"), CancellationToken.None);
|
||||
await context.Sync(CancellationToken.None, reason: "Add default library");
|
||||
}
|
||||
}
|
||||
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
NotificationsContext context = scope.ServiceProvider.GetRequiredService<NotificationsContext>();
|
||||
context.Database.Migrate();
|
||||
await context.Database.MigrateAsync(CancellationToken.None);
|
||||
|
||||
context.Notifications.RemoveRange(context.Notifications);
|
||||
string[] emojis = ["(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)"
|
||||
];
|
||||
context.Notifications.Add(new Notification("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High));
|
||||
await context.Notifications.AddAsync(new ("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High), CancellationToken.None);
|
||||
|
||||
await context.Sync(CancellationToken.None);
|
||||
await context.Sync(CancellationToken.None, reason: "Startup notification");
|
||||
}
|
||||
|
||||
using (IServiceScope scope = app.Services.CreateScope())
|
||||
{
|
||||
LibraryContext context = scope.ServiceProvider.GetRequiredService<LibraryContext>();
|
||||
context.Database.Migrate();
|
||||
await context.Database.MigrateAsync(CancellationToken.None);
|
||||
|
||||
await context.Sync(CancellationToken.None);
|
||||
await context.Sync(CancellationToken.None, reason: "Startup library");
|
||||
}
|
||||
|
||||
Tranga.ServiceProvider = app.Services;
|
||||
|
@@ -84,7 +84,7 @@ public class Chapter : Identifiable, IComparable<Chapter>
|
||||
|
||||
//TODO Log here
|
||||
this.Downloaded = File.Exists(chapter.FullArchiveFilePath);
|
||||
await context.Sync(token??CancellationToken.None, GetType());
|
||||
await context.Sync(token??CancellationToken.None, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name);
|
||||
return this.Downloaded;
|
||||
}
|
||||
|
||||
|
@@ -85,7 +85,7 @@ public class MyAnimeList : MetadataFetcher
|
||||
dbManga.Authors.Clear();
|
||||
dbManga.Authors = resultData.Authors.Select(a => new Author(a.Name)).ToList();
|
||||
|
||||
await dbContext.Sync(token, GetType());
|
||||
await dbContext.Sync(token, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name);
|
||||
}
|
||||
|
||||
}
|
@@ -23,10 +23,10 @@ public abstract class TrangaBaseContext<T> : DbContext where T : DbContext
|
||||
}, Array.Empty<string>(), LogLevel.Warning, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category | DbContextLoggerOptions.UtcTime);
|
||||
}
|
||||
|
||||
internal async Task<(bool success, string? exceptionMessage)> Sync(CancellationToken token, Type? trigger = null)
|
||||
internal async Task<(bool success, string? exceptionMessage)> Sync(CancellationToken token, Type? trigger = null, string? reason = null)
|
||||
{
|
||||
int changesCount = ChangeTracker.Entries().Count(e => e.State is not EntityState.Unchanged and not EntityState.Detached);
|
||||
Log.Debug($"Syncing {changesCount} changes {GetType().Name} {trigger?.Name}...");
|
||||
Log.Debug($"Syncing {changesCount} changes {GetType().Name} {trigger?.Name} {reason}...");
|
||||
if (changesCount < 1)
|
||||
return (true, null);
|
||||
try
|
||||
|
@@ -221,7 +221,7 @@ public static class Tranga
|
||||
context.Mangas.Add(manga);
|
||||
}
|
||||
|
||||
if (await context.Sync(token) is { success: false })
|
||||
if (await context.Sync(token, reason: System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false })
|
||||
return false;
|
||||
|
||||
DownloadCoverFromMangaconnectorWorker downloadCoverWorker = new (addMcId);
|
||||
|
@@ -67,7 +67,7 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
||||
{
|
||||
Log.Info($"No imageUrls for chapter {chapter}");
|
||||
mangaConnectorId.UseForDownload = false; // Do not try to download from this again
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } result)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), "Disable Id") is { success: false } result)
|
||||
Log.Error(result.exceptionMessage);
|
||||
return [];
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
||||
Directory.Delete(tempFolder, true); //Cleanup
|
||||
|
||||
DbContext.Entry(chapter).Property(c => c.Downloaded).CurrentValue = true;
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
Log.Debug($"Downloaded chapter {chapter}.");
|
||||
|
@@ -37,7 +37,7 @@ public class DownloadCoverFromMangaconnectorWorker(MangaConnectorId<Manga> mcId,
|
||||
}
|
||||
DbContext.Entry(mangaConnectorId.Obj).Property(m => m.CoverFileNameInCache).CurrentValue = coverFileName;
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
@@ -73,7 +73,7 @@ public class RetrieveMangaChaptersFromMangaconnectorWorker(MangaConnectorId<Mang
|
||||
}
|
||||
}
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
@@ -35,7 +35,7 @@ public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IEnumera
|
||||
// Set new Path
|
||||
manga.Library = toLibrary;
|
||||
|
||||
if (await DbContext.Sync(CancellationToken, GetType()) is { success: false })
|
||||
if (await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false })
|
||||
return [];
|
||||
|
||||
// Create Jobs to move chapters from old to new Path
|
||||
|
@@ -19,7 +19,7 @@ public class RemoveOldNotificationsWorker(TimeSpan? interval = null, IEnumerable
|
||||
Log.Debug($"Removing {toRemove.Count} old notifications...");
|
||||
DbContext.RemoveRange(toRemove);
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
@@ -33,7 +33,7 @@ public class SendNotificationsWorker(TimeSpan? interval = null, IEnumerable<Base
|
||||
|
||||
Log.Debug("Notifications sent.");
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
@@ -28,7 +28,7 @@ public class UpdateChaptersDownloadedWorker(TimeSpan? interval = null, IEnumerab
|
||||
}
|
||||
}
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
@@ -37,7 +37,7 @@ public class UpdateMetadataWorker(TimeSpan? interval = null, IEnumerable<BaseWor
|
||||
}
|
||||
Log.Debug("Updated metadata.");
|
||||
|
||||
if(await DbContext.Sync(CancellationToken, GetType()) is { success: false } e)
|
||||
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
|
||||
Log.Error($"Failed to save database changes: {e.exceptionMessage}");
|
||||
|
||||
return [];
|
||||
|
Reference in New Issue
Block a user