2020-03-24 13:01:14 +01:00
|
|
|
|
using MediatR;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.Dtos;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
|
|
|
|
{
|
2020-04-01 19:37:30 +02:00
|
|
|
|
public class CreateDatabaseCommand : IRequest
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
public string Password { get; set; }
|
|
|
|
|
public string KeyFilePath { get; set; }
|
2020-03-24 13:01:14 +01:00
|
|
|
|
|
2020-04-01 19:37:30 +02:00
|
|
|
|
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand>
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-04-01 19:37:30 +02:00
|
|
|
|
public CreateDatabaseCommandHandler(IDatabaseProxy database)
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 19:37:30 +02:00
|
|
|
|
public async Task Handle(CreateDatabaseCommand message)
|
2020-03-24 13:01:14 +01:00
|
|
|
|
{
|
2020-03-26 19:04:51 +01:00
|
|
|
|
if (_database.IsOpen) throw new DatabaseOpenException();
|
2020-03-24 13:01:14 +01:00
|
|
|
|
|
2020-04-01 19:37:30 +02:00
|
|
|
|
await _database.Create(
|
2020-03-26 19:04:51 +01:00
|
|
|
|
new FileInfo
|
|
|
|
|
{
|
|
|
|
|
Path = message.FilePath
|
|
|
|
|
},
|
|
|
|
|
new Credentials
|
|
|
|
|
{
|
|
|
|
|
KeyFilePath = message.KeyFilePath,
|
|
|
|
|
Password = message.Password
|
|
|
|
|
});
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
2020-03-24 17:31:34 +01:00
|
|
|
|
|
2020-03-24 13:01:14 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|