Added the option to close DB without saving

Changed the way recent files are retrieved
Stopped showing the DB Closed exception on suspend
Reordering entries works
Moved code from infra to application
Cleanup
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-09 19:43:06 +02:00
parent 14fd4634db
commit d972b6cb5a
35 changed files with 141 additions and 100 deletions

View File

@@ -119,7 +119,7 @@
<Compile Include="Group\Commands\AddGroup\AddGroupCommand.cs" />
<Compile Include="Group\Commands\CreateEntry\CreateEntryCommand.cs" />
<Compile Include="Group\Commands\CreateGroup\CreateGroupCommand.cs" />
<Compile Include="Group\Commands\InsertEntry\InsertEntryCommand.cs" />
<Compile Include="Group\Commands\MoveEntry\MoveEntryCommand.cs" />
<Compile Include="Group\Commands\RemoveEntry\RemoveEntryCommand.cs" />
<Compile Include="Group\Commands\RemoveGroup\RemoveGroupCommand.cs" />
<Compile Include="Group\Commands\SortEntries\SortEntriesCommand.cs" />

View File

@@ -27,7 +27,7 @@ namespace ModernKeePass.Application.Common.Interfaces
void CloseDatabase();
Task AddEntry(string parentGroupId, string entryId);
Task InsertEntry(string parentGroupId, string entryId, int index);
Task MoveEntry(string parentGroupId, string entryId, int index);
Task AddGroup(string parentGroupId, string groupId);
void UpdateEntry(string entryId, string fieldName, object fieldValue);
void UpdateGroup(string groupId);

View File

@@ -8,7 +8,7 @@ namespace ModernKeePass.Application.Common.Interfaces
{
int EntryCount { get; }
Task<FileInfo> Get(string token, bool updateAccessTime = false);
Task<IEnumerable<FileInfo>> GetAll();
IEnumerable<FileInfo> GetAll();
Task Add(FileInfo recentItem);
void ClearAll();
}

View File

@@ -1,6 +1,7 @@
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Domain.Common;
namespace ModernKeePass.Application.Database.Queries.GetDatabase
{
@@ -26,7 +27,7 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
database.Name = _databaseProxy.Name;
database.RootGroupId = _databaseProxy.RootGroupId;
database.IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled;
database.RecycleBinId = _databaseProxy.RecycleBinId;
database.RecycleBinId = _databaseProxy.RecycleBinId == Constants.EmptyId ? null : _databaseProxy.RecycleBinId;
database.Compression = _databaseProxy.Compression;
database.CipherId = _databaseProxy.CipherId;
database.KeyDerivationId = _databaseProxy.KeyDerivationId;

View File

@@ -5,28 +5,28 @@ using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Group.Commands.InsertEntry
namespace ModernKeePass.Application.Group.Commands.MoveEntry
{
public class InsertEntryCommand : IRequest
public class MoveEntryCommand : IRequest
{
public GroupVm ParentGroup { get; set; }
public EntryVm Entry { get; set; }
public int Index { get; set; }
public class InsertEntryCommandHandler : IAsyncRequestHandler<InsertEntryCommand>
public class MoveEntryCommandHandler : IAsyncRequestHandler<MoveEntryCommand>
{
private readonly IDatabaseProxy _database;
public InsertEntryCommandHandler(IDatabaseProxy database)
public MoveEntryCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public async Task Handle(InsertEntryCommand message)
public async Task Handle(MoveEntryCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
await _database.InsertEntry(message.ParentGroup.Id, message.Entry.Id, message.Index);
await _database.MoveEntry(message.ParentGroup.Id, message.Entry.Id, message.Index);
message.ParentGroup.Entries.Insert(message.Index, message.Entry);
}
}

View File

@@ -1,5 +1,6 @@
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Common;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin
@@ -19,8 +20,8 @@ namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin
public void Handle(SetRecycleBinCommand message)
{
if (_database.IsOpen) _database.RecycleBinId = message.RecycleBinId;
else throw new DatabaseClosedException();
if (!_database.IsOpen) throw new DatabaseClosedException();
_database.RecycleBinId = message.RecycleBinId ?? Constants.EmptyId;
}
}
}