This commit is contained in:
Jöran Malek 2024-04-05 12:31:34 +02:00
parent 4c2b5cca93
commit 43b4d50e43
28 changed files with 674 additions and 249 deletions

View file

@ -62,26 +62,25 @@ public class WorkspaceManager(IServiceProvider serviceProvider) : ReactiveObject
};
var dbFactory = serviceProvider.GetRequiredService<IDbContextFactory<NoteDbContext>>();
await using (var dbContext = dbFactory.CreateDbContext())
await using var dbContext = await dbFactory.CreateDbContextAsync().ConfigureAwait(false);
var db = dbContext.Database;
if ((await db.GetPendingMigrationsAsync().ConfigureAwait(false)).Any())
{
var db = dbContext.Database;
await using var transaction = await db.BeginTransactionAsync().ConfigureAwait(false);
try
if (file.Exists)
{
await db.MigrateAsync().ConfigureAwait(false);
}
catch
{
// Show Error through TopLevels.ActiveTopLevel
await transaction.RollbackAsync().ConfigureAwait(false);
return null;
file.CopyTo(Path.ChangeExtension(file.FullName, $"{DateTime.Now:s}{file.Extension}"));
}
await transaction.CommitAsync().ConfigureAwait(false);
await db.MigrateAsync().ConfigureAwait(false);
}
scope = null;
}
catch (Exception)
{
// Show Error through TopLevels.ActiveTopLevel
return null;
}
finally
{
scope?.Dispose();