mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Cleanup code
This commit is contained in:
@@ -39,9 +39,9 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
|
||||
if (message.CreateSampleData)
|
||||
{
|
||||
var bankingGroup = _database.CreateGroup(_database.RootGroupId, "Banking");
|
||||
var emailGroup = _database.CreateGroup(_database.RootGroupId, "Email");
|
||||
var internetGroup = _database.CreateGroup(_database.RootGroupId, "Internet");
|
||||
_database.CreateGroup(_database.RootGroupId, "Banking");
|
||||
_database.CreateGroup(_database.RootGroupId, "Email");
|
||||
_database.CreateGroup(_database.RootGroupId, "Internet");
|
||||
|
||||
var sample1 = _database.CreateEntry(_database.RootGroupId);
|
||||
_database.UpdateEntry(sample1.Id, EntryFieldName.Title, "Sample Entry" );
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using System;
|
||||
using MediatR;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
@@ -24,22 +25,34 @@ namespace ModernKeePass.Application.Database.Commands.SaveDatabase
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
byte[] contents;
|
||||
if (string.IsNullOrEmpty(message.FilePath))
|
||||
try
|
||||
{
|
||||
contents = await _database.SaveDatabase();
|
||||
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
||||
byte[] contents;
|
||||
if (string.IsNullOrEmpty(message.FilePath))
|
||||
{
|
||||
contents = await _database.SaveDatabase();
|
||||
|
||||
// Test DB integrity before writing changes to file
|
||||
_database.CloseDatabase();
|
||||
var file = await _file.OpenBinaryFile(_database.FileAccessToken);
|
||||
await _database.ReOpen(file);
|
||||
|
||||
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newFileContents = await _file.OpenBinaryFile(message.FilePath);
|
||||
contents = await _database.SaveDatabase(newFileContents);
|
||||
await _file.WriteBinaryContentsToFile(message.FilePath, contents);
|
||||
|
||||
_file.ReleaseFile(_database.FileAccessToken);
|
||||
_database.FileAccessToken = message.FilePath;
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception exception)
|
||||
{
|
||||
var newFileContents = await _file.OpenBinaryFile(message.FilePath);
|
||||
contents = await _database.SaveDatabase(newFileContents);
|
||||
await _file.WriteBinaryContentsToFile(message.FilePath, contents);
|
||||
|
||||
_file.ReleaseFile(_database.FileAccessToken);
|
||||
_database.FileAccessToken = message.FilePath;
|
||||
throw new SaveException(exception);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Models
|
||||
namespace ModernKeePass.Application.Database.Models
|
||||
{
|
||||
public class DatabaseVm
|
||||
{
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
|
||||
@@ -10,15 +9,13 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
|
||||
public class GetDatabaseQueryHandler : IRequestHandler<GetDatabaseQuery, DatabaseVm>
|
||||
{
|
||||
private readonly IDatabaseProxy _databaseProxy;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetDatabaseQueryHandler(IDatabaseProxy databaseProxy, IMapper mapper)
|
||||
public GetDatabaseQueryHandler(IDatabaseProxy databaseProxy)
|
||||
{
|
||||
_databaseProxy = databaseProxy;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public DatabaseVm Handle(GetDatabaseQuery request)
|
||||
public DatabaseVm Handle(GetDatabaseQuery message)
|
||||
{
|
||||
var database = new DatabaseVm
|
||||
{
|
||||
|
@@ -23,17 +23,17 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
_file = file;
|
||||
}
|
||||
|
||||
public async Task Handle(OpenDatabaseQuery request)
|
||||
public async Task Handle(OpenDatabaseQuery message)
|
||||
{
|
||||
if (_database.IsOpen) throw new DatabaseOpenException();
|
||||
|
||||
var file = await _file.OpenBinaryFile(request.FilePath);
|
||||
var file = await _file.OpenBinaryFile(message.FilePath);
|
||||
await _database.Open(file, new Credentials
|
||||
{
|
||||
KeyFileContents = !string.IsNullOrEmpty(request.KeyFilePath) ? await _file.OpenBinaryFile(request.KeyFilePath): null,
|
||||
Password = request.Password
|
||||
KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath): null,
|
||||
Password = message.Password
|
||||
});
|
||||
_database.FileAccessToken = request.FilePath;
|
||||
_database.FileAccessToken = message.FilePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ namespace ModernKeePass.Application.Database.Queries.ReOpenDatabase
|
||||
_file = file;
|
||||
}
|
||||
|
||||
public async Task Handle(ReOpenDatabaseQuery request)
|
||||
public async Task Handle(ReOpenDatabaseQuery message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
|
Reference in New Issue
Block a user