Removed ModernKeePassLib dependency

Code cleanup
WIP on service replacement and VM use
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-27 18:45:13 +01:00
parent e3638c2f5c
commit 45fcf7e8ab
31 changed files with 383 additions and 277 deletions

View File

@@ -54,14 +54,16 @@
<Compile Include="Common\Interfaces\ISettingsProxy.cs" />
<Compile Include="Common\Mappings\IMapFrom.cs" />
<Compile Include="Common\Mappings\MappingProfile.cs" />
<Compile Include="Cryptography\Commands\SetCipher\SetCipherCommand.cs" />
<Compile Include="Cryptography\Commands\SetCompression\SetCompressionCommand.cs" />
<Compile Include="Cryptography\Commands\SetKeyDerivation\SetKeyDerivationCommand.cs" />
<Compile Include="Cryptography\Models\CipherVm.cs" />
<Compile Include="Cryptography\Models\KeyDerivationVm.cs" />
<Compile Include="Cryptography\Queries\GetCiphers\GetCiphersQuery.cs" />
<Compile Include="Cryptography\Queries\GetCompressions\GetCompressionsQuery.cs" />
<Compile Include="Cryptography\Queries\GetKeyDerivations\GetKeyDerivationsQuery.cs" />
<Compile Include="Parameters\Commands\SetCipher\SetCipherCommand.cs" />
<Compile Include="Parameters\Commands\SetCompression\SetCompressionCommand.cs" />
<Compile Include="Parameters\Commands\SetHasRecycleBin\SetHasRecycleBinCommand.cs" />
<Compile Include="Parameters\Commands\SetKeyDerivation\SetKeyDerivationCommand.cs" />
<Compile Include="Parameters\Commands\SetRecycleBin\SetRecycleBinCommand.cs" />
<Compile Include="Parameters\Models\CipherVm.cs" />
<Compile Include="Parameters\Models\KeyDerivationVm.cs" />
<Compile Include="Parameters\Queries\GetCiphers\GetCiphersQuery.cs" />
<Compile Include="Parameters\Queries\GetCompressions\GetCompressionsQuery.cs" />
<Compile Include="Parameters\Queries\GetKeyDerivations\GetKeyDerivationsQuery.cs" />
<Compile Include="Database\Commands\CloseDatabase\CloseDatabaseCommand.cs" />
<Compile Include="Database\Commands\CreateDatabase\CreateDatabaseCommand.cs" />
<Compile Include="Database\Commands\CreateDatabase\CreateDatabaseQueryValidator.cs" />

View File

@@ -14,13 +14,13 @@ namespace ModernKeePass.Application.Common.Interfaces
string CipherId { get; set; }
string KeyDerivationId { get; set; }
string Compression { get; set; }
bool IsRecycleBinEnabled { get; }
bool IsRecycleBinEnabled { get; set; }
Task<GroupEntity> Open(FileInfo fileInfo, Credentials credentials);
Task<GroupEntity> ReOpen();
Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials);
Task SaveDatabase();
Task SaveDatabase(FileInfo FileInfo);
Task SaveDatabase(string filePath);
Task UpdateCredentials(Credentials credentials);
void CloseDatabase();

View File

@@ -1,14 +1,13 @@
using MediatR;
using System.Threading.Tasks;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Database.Commands.SaveDatabase
{
public class SaveDatabaseCommand : IRequest
{
public FileInfo FileInfo { get; set; }
public string FilePath { get; set; }
public class SaveDatabaseCommandHandler : IAsyncRequestHandler<SaveDatabaseCommand>
{
@@ -23,8 +22,8 @@ namespace ModernKeePass.Application.Database.Commands.SaveDatabase
{
if (!_database.IsOpen) throw new DatabaseClosedException();
if (message.FileInfo != null) await _database.SaveDatabase(message.FileInfo);
else await _database.SaveDatabase();
if (string.IsNullOrEmpty(message.FilePath)) await _database.SaveDatabase();
else await _database.SaveDatabase(message.FilePath);
}
}
}

View File

@@ -8,7 +8,8 @@ namespace ModernKeePass.Application.Database.Commands.UpdateCredentials
{
public class UpdateCredentialsCommand: IRequest
{
public Credentials Credentials { get; set; }
public string Password { get; set; }
public string KeyFilePath { get; set; }
public class UpdateCredentialsCommandHandler : IAsyncRequestHandler<UpdateCredentialsCommand>
{
@@ -21,7 +22,14 @@ namespace ModernKeePass.Application.Database.Commands.UpdateCredentials
public async Task Handle(UpdateCredentialsCommand message)
{
if (_database.IsOpen) await _database.UpdateCredentials(message.Credentials);
if (_database.IsOpen)
{
await _database.UpdateCredentials(new Credentials
{
KeyFilePath = message.KeyFilePath,
Password = message.Password
});
}
else throw new DatabaseClosedException();
}
}

View File

@@ -2,7 +2,7 @@
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Cryptography.Commands.SetCipher
namespace ModernKeePass.Application.Parameters.Commands.SetCipher
{
public class SetCipherCommand : IRequest
{

View File

@@ -2,7 +2,7 @@
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Cryptography.Commands.SetCompression
namespace ModernKeePass.Application.Parameters.Commands.SetCompression
{
public class SetCompressionCommand : IRequest
{

View File

@@ -0,0 +1,27 @@
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin
{
public class SetHasRecycleBinCommand : IRequest
{
public bool HasRecycleBin { get; set; }
public class SetHasRecycleBinCommandHandler : IRequestHandler<SetHasRecycleBinCommand>
{
private readonly IDatabaseProxy _database;
public SetHasRecycleBinCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public void Handle(SetHasRecycleBinCommand message)
{
if (_database.IsOpen) _database.IsRecycleBinEnabled = message.HasRecycleBin;
else throw new DatabaseClosedException();
}
}
}
}

View File

@@ -2,7 +2,7 @@
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Cryptography.Commands.SetKeyDerivation
namespace ModernKeePass.Application.Parameters.Commands.SetKeyDerivation
{
public class SetKeyDerivationCommand : IRequest
{

View File

@@ -0,0 +1,27 @@
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin
{
public class SetRecycleBinCommand : IRequest
{
public string RecycleBinId { get; set; }
public class SetRecycleBinCommandHandler : IRequestHandler<SetRecycleBinCommand>
{
private readonly IDatabaseProxy _database;
public SetRecycleBinCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public void Handle(SetRecycleBinCommand message)
{
if (_database.IsOpen) _database.RecycleBinId = message.RecycleBinId;
else throw new DatabaseClosedException();
}
}
}
}