2020-04-14 13:44:07 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediatR;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Application.Database.Commands.CloseDatabase;
|
|
|
|
|
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Common.Behaviors
|
|
|
|
|
{
|
2020-04-27 11:14:29 +02:00
|
|
|
|
public class DirtyStatusBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
|
2020-04-14 13:44:07 +02:00
|
|
|
|
{
|
|
|
|
|
private readonly List<string> _excludedCommands = new List<string>
|
|
|
|
|
{nameof(SaveDatabaseCommand), nameof(CloseDatabaseCommand)};
|
|
|
|
|
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-04-27 11:14:29 +02:00
|
|
|
|
public DirtyStatusBehavior(IDatabaseProxy database)
|
2020-04-14 13:44:07 +02:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next)
|
|
|
|
|
{
|
|
|
|
|
var response = await next();
|
|
|
|
|
var queryName = typeof(TRequest).Name;
|
2020-04-27 11:14:29 +02:00
|
|
|
|
if (queryName.Contains("Command"))
|
2020-04-14 13:44:07 +02:00
|
|
|
|
{
|
2020-04-27 11:14:29 +02:00
|
|
|
|
_database.IsDirty = !_excludedCommands.Contains(queryName);
|
2020-04-14 13:44:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|