bunch of fixes
This commit is contained in:
@@ -1,17 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultStorage(IHostEnvironment environment,
|
||||
IDbContextFactory<VaultDbContext> dbContextFactory) :
|
||||
public class VaultStorage(IContainer<VaultStorageConnection> connection,
|
||||
IHostEnvironment environment,
|
||||
IServiceProvider provider) :
|
||||
IVaultStorage
|
||||
{
|
||||
public bool Create(string name, VaultKey key)
|
||||
public async Task<bool> CreateAsync(string name,
|
||||
VaultKey key)
|
||||
{
|
||||
using VaultDbContext context = dbContextFactory.CreateDbContext();
|
||||
context.Database.SetConnectionString($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
||||
$".vault;Mode=ReadWriteCreate;Password={Convert.ToBase64String(key.Private)}");
|
||||
connection.Set(new VaultStorageConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
||||
$".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.Private)}"));
|
||||
|
||||
IDbContextFactory<VaultDbContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<VaultDbContext>>();
|
||||
using VaultDbContext context = await dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await context.Database.EnsureCreatedAsync().ConfigureAwait(false);
|
||||
await context.Database.CloseConnectionAsync().ConfigureAwait(false);
|
||||
|
||||
context.Database.SetConnectionString(null);
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user