Resolve "ASCII export and import for Git" #83

Merged
thorsten merged 30 commits from 48-ascii-export-and-import-for-git into main 2023-02-12 12:55:07 +00:00
Showing only changes of commit 52927d4715 - Show all commits

View File

@ -7,8 +7,8 @@ namespace Processor;
public static class ExportProcessor public static class ExportProcessor
{ {
private static readonly Timer EXPORT_TIMER = new(); private static readonly Timer EXPORT_TIMER = new();
private static readonly object EXPORT_LOCK = new(); private static readonly SemaphoreSlim EXPORT_SEMAPHORE_BRICK_WALL = new(2);
private static readonly SemaphoreSlim EXPORT_SEMAPHORE = new(2); private static readonly SemaphoreSlim EXPORT_SEMAPHORE_EXPORTING = new(1);
static ExportProcessor() static ExportProcessor()
{ {
@ -19,19 +19,19 @@ public static class ExportProcessor
private static async Task ExportToJson() private static async Task ExportToJson()
{ {
if(!await EXPORT_SEMAPHORE.WaitAsync(1)) if(!await EXPORT_SEMAPHORE_BRICK_WALL.WaitAsync(1))
return; return;
Monitor.Enter(EXPORT_LOCK);
try try
{ {
await EXPORT_SEMAPHORE_EXPORTING.WaitAsync();
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>(); await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
await db.ExportAsync(Environment.ExpandEnvironmentVariables(Path.Join(await AppSettings.GetAutoExportDestinationPath(), await AppSettings.GetAutoExportFilename()))); await db.ExportAsync(Environment.ExpandEnvironmentVariables(Path.Join(await AppSettings.GetAutoExportDestinationPath(), await AppSettings.GetAutoExportFilename())));
} }
finally finally
{ {
Monitor.Exit(EXPORT_LOCK); EXPORT_SEMAPHORE_EXPORTING.Release();
EXPORT_SEMAPHORE.Release(); EXPORT_SEMAPHORE_BRICK_WALL.Release();
} }
} }