Files
modernkeepass/ModernKeePass.Application/Database/Commands/CloseDatabase/CloseDatabaseCommand.cs
Geoffroy BONNEVILLE 2e01fa2212 Changed tooltip styles
Removed useless isdirty field in entry
When an app can't be saved on suspend, don't reopen it to avoid possible de-sync
2020-05-13 18:59:26 +02:00

26 lines
930 B
C#

using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Database.Commands.CloseDatabase
{
public class CloseDatabaseCommand: IRequest
{
public class CloseDatabaseCommandHandler : IRequestHandler<CloseDatabaseCommand>
{
private readonly IDatabaseProxy _database;
public CloseDatabaseCommandHandler(IDatabaseProxy database)
{
_database = database;
}
public void Handle(CloseDatabaseCommand message)
{
if (!_database.IsOpen) throw new DatabaseClosedException();
// Prevent reopening the database due to possible de-synchronization between app and data
if (_database.IsDirty) _database.FileAccessToken = null;
_database.CloseDatabase();
}
}
}
}