mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Cleanup code
This commit is contained in:
@@ -26,6 +26,16 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
|
@@ -27,7 +27,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
void CloseDatabase();
|
||||
|
||||
Task AddEntry(string parentGroupId, string entryId);
|
||||
Task InsertEntry(string parentGroupId, string entryId, int messageIndex);
|
||||
Task InsertEntry(string parentGroupId, string entryId, int index);
|
||||
Task AddGroup(string parentGroupId, string groupId);
|
||||
void UpdateEntry(string entryId, string fieldName, object fieldValue);
|
||||
void UpdateGroup(string groupId);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -24,23 +24,6 @@ namespace ModernKeePass.Application.Group.Commands.AddEntry
|
||||
public async Task Handle(AddEntryCommand message)
|
||||
{
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
/*var entryEntity = new EntryEntity
|
||||
{
|
||||
Id = message.Entry.Id,
|
||||
Name = message.Entry.Title,
|
||||
UserName = message.Entry.Username,
|
||||
Password = message.Entry.Password,
|
||||
Url = message.Entry.Url,
|
||||
Notes = message.Entry.Notes,
|
||||
HasExpirationDate = message.Entry.HasExpirationDate,
|
||||
ExpirationDate = message.Entry.ExpirationDate,
|
||||
LastModificationDate = message.Entry.ModificationDate,
|
||||
BackgroundColor = message.Entry.BackgroundColor,
|
||||
ForegroundColor = message.Entry.ForegroundColor,
|
||||
Icon = message.Entry.Icon,
|
||||
AdditionalFields = message.Entry.AdditionalFields,
|
||||
History = message.Entry.History
|
||||
};*/
|
||||
|
||||
await _database.AddEntry(message.ParentGroup.Id, message.Entry.Id);
|
||||
message.ParentGroup.Entries.Add(message.Entry);
|
||||
|
@@ -1,7 +1,5 @@
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
|
Reference in New Issue
Block a user