mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Don't use mediator for App services (recent, resource, settings)
WIP in View models
This commit is contained in:
@@ -43,14 +43,11 @@
|
||||
<Compile Include="Common\Interfaces\ICryptographyClient.cs" />
|
||||
<Compile Include="Common\Interfaces\IDatabaseProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IFileProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IHasSelectableObject.cs" />
|
||||
<Compile Include="Common\Interfaces\IImportFormat.cs" />
|
||||
<Compile Include="Common\Interfaces\IIsEnabled.cs" />
|
||||
<Compile Include="Common\Interfaces\IPasswordProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IProxyInvocationHandler.cs" />
|
||||
<Compile Include="Common\Interfaces\IRecentProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IResourceProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\ISelectableModel.cs" />
|
||||
<Compile Include="Common\Interfaces\ISettingsProxy.cs" />
|
||||
<Compile Include="Common\Mappings\IMapFrom.cs" />
|
||||
<Compile Include="Common\Mappings\MappingProfile.cs" />
|
||||
@@ -91,18 +88,9 @@
|
||||
<Compile Include="Group\Commands\SortGroups\SortGroupsCommand.cs" />
|
||||
<Compile Include="Group\Models\GroupVm.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Recent\Commands\AddRecent\AddRecentCommand.cs" />
|
||||
<Compile Include="Recent\Commands\ClearAllRecent\ClearAllRecentCommand.cs" />
|
||||
<Compile Include="Recent\Models\RecentVm.cs" />
|
||||
<Compile Include="Recent\Queries\GetAllRecent\GetAllRecentQuery.cs" />
|
||||
<Compile Include="Recent\Queries\GetRecent\GetRecentQuery.cs" />
|
||||
<Compile Include="Recent\Queries\HasRecent\HasRecentQuery.cs" />
|
||||
<Compile Include="Resources\Queries\GetResourceQuery.cs" />
|
||||
<Compile Include="Security\Commands\GenerateKeyFile\GenerateKeyFileCommand.cs" />
|
||||
<Compile Include="Security\Commands\GeneratePassword\GeneratePasswordCommand.cs" />
|
||||
<Compile Include="Security\Queries\EstimatePasswordComplexity\EstimatePasswordComplexityQuery.cs" />
|
||||
<Compile Include="Settings\Commands\PutSettingCommand.cs" />
|
||||
<Compile Include="Settings\Queries\GetSettingQuery.cs" />
|
||||
<Content Include="Services\DatabaseService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@@ -10,7 +10,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
string Name { get; }
|
||||
GroupEntity RootGroup { get; }
|
||||
|
||||
string RecycleBinId { get; set; }
|
||||
GroupEntity RecycleBin { get; set; }
|
||||
string CipherId { get; set; }
|
||||
string KeyDerivationId { get; set; }
|
||||
string Compression { get; set; }
|
||||
@@ -21,6 +21,7 @@ namespace ModernKeePass.Application.Common.Interfaces
|
||||
Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials);
|
||||
Task SaveDatabase();
|
||||
Task SaveDatabase(string filePath);
|
||||
void SetRecycleBin(string id);
|
||||
Task UpdateCredentials(Credentials credentials);
|
||||
void CloseDatabase();
|
||||
|
||||
|
@@ -1,7 +0,0 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IHasSelectableObject
|
||||
{
|
||||
ISelectableModel SelectedItem { get; set; }
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IIsEnabled
|
||||
{
|
||||
bool IsEnabled { get; }
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface ISelectableModel
|
||||
{
|
||||
bool IsSelected { get; set; }
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@ namespace ModernKeePass.Application.Database.Models
|
||||
public bool IsOpen { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupVm RootGroup { get; set; }
|
||||
public string RecycleBinId { get; set; }
|
||||
public GroupVm RecycleBin { get; set; }
|
||||
public bool IsRecycleBinEnabled { get; set; }
|
||||
public string Compression { get; set; }
|
||||
public string CipherId { get; set; }
|
||||
|
@@ -27,7 +27,7 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
|
||||
Name = _databaseProxy.Name,
|
||||
RootGroup = _mapper.Map<GroupVm>(_databaseProxy.RootGroup),
|
||||
IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled,
|
||||
RecycleBinId = _databaseProxy.RecycleBinId,
|
||||
RecycleBin = _mapper.Map<GroupVm>(_databaseProxy.RecycleBin),
|
||||
Compression = _databaseProxy.Compression,
|
||||
CipherId = _databaseProxy.CipherId,
|
||||
KeyDerivationId = _databaseProxy.CipherId
|
||||
|
@@ -13,6 +13,7 @@ namespace ModernKeePass.Application.Group.Models
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public GroupVm ParentGroup { get; set; }
|
||||
public List<GroupVm> SubGroups { get; set; } = new List<GroupVm>();
|
||||
public List<EntryVm> Entries { get; set; } = new List<EntryVm>();
|
||||
|
||||
@@ -22,6 +23,7 @@ namespace ModernKeePass.Application.Group.Models
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon))
|
||||
.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
|
||||
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries.OrderBy(e => e.Name)))
|
||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups));
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin
|
||||
{
|
||||
public class SetRecycleBinCommand : IRequest
|
||||
{
|
||||
public string RecycleBinId { get; set; }
|
||||
public GroupVm RecycleBin { get; set; }
|
||||
|
||||
public class SetRecycleBinCommandHandler : IRequestHandler<SetRecycleBinCommand>
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace ModernKeePass.Application.Parameters.Commands.SetRecycleBin
|
||||
|
||||
public void Handle(SetRecycleBinCommand message)
|
||||
{
|
||||
if (_database.IsOpen) _database.RecycleBinId = message.RecycleBinId;
|
||||
if (_database.IsOpen) _database.SetRecycleBin(message.RecycleBin.Id);
|
||||
else throw new DatabaseClosedException();
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +0,0 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Commands.AddRecent
|
||||
{
|
||||
public class AddRecentCommand: IRequest
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
|
||||
public class AddRecentCommandHandler: IRequestHandler<AddRecentCommand>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public AddRecentCommandHandler(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public void Handle(AddRecentCommand message)
|
||||
{
|
||||
_recent.Add(new FileInfo
|
||||
{
|
||||
Name = message.Name,
|
||||
Path = message.Path
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Commands.ClearAllRecent
|
||||
{
|
||||
public class ClearAllRecentCommand : IRequest
|
||||
{
|
||||
public class ClearAllRecentCommandHandler : IRequestHandler<ClearAllRecentCommand>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public ClearAllRecentCommandHandler(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public void Handle(ClearAllRecentCommand message)
|
||||
{
|
||||
_recent.ClearAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Models
|
||||
{
|
||||
public class RecentVm: IMapFrom<FileInfo>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<FileInfo, RecentVm>()
|
||||
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Path, opts => opts.MapFrom(s => s.Path));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Recent.Models;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Queries.GetAllRecent
|
||||
{
|
||||
public class GetAllRecentQuery : IRequest<IEnumerable<RecentVm>>
|
||||
{
|
||||
public class GetAllRecentQueryHandler : IAsyncRequestHandler<GetAllRecentQuery, IEnumerable<RecentVm>>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetAllRecentQueryHandler(IRecentProxy recent, IMapper mapper)
|
||||
{
|
||||
_recent = recent;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RecentVm>> Handle(GetAllRecentQuery message)
|
||||
{
|
||||
var fileInfo = await _recent.GetAll();
|
||||
return _mapper.Map<IEnumerable<RecentVm>>(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Recent.Models;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Queries.GetRecent
|
||||
{
|
||||
public class GetRecentQuery : IRequest<RecentVm>
|
||||
{
|
||||
public string Token { get; set; }
|
||||
|
||||
public class GetRecentQueryHandler : IAsyncRequestHandler<GetRecentQuery, RecentVm>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GetRecentQueryHandler(IRecentProxy recent, IMapper mapper)
|
||||
{
|
||||
_recent = recent;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<RecentVm> Handle(GetRecentQuery message)
|
||||
{
|
||||
var fileInfo = await _recent.Get(message.Token);
|
||||
return _mapper.Map<RecentVm>(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Recent.Queries.HasRecent
|
||||
{
|
||||
public class HasRecentQuery : IRequest<bool>
|
||||
{
|
||||
public class HasRecentQueryHandler : IRequestHandler<HasRecentQuery, bool>
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
|
||||
public HasRecentQueryHandler(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
}
|
||||
|
||||
public bool Handle(HasRecentQuery message)
|
||||
{
|
||||
return _recent.EntryCount > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Resources.Queries
|
||||
{
|
||||
public class GetResourceQuery: IRequest<string>
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public class GetResourceQueryHandler: IRequestHandler<GetResourceQuery, string>
|
||||
{
|
||||
private readonly IResourceProxy _resourceProxy;
|
||||
|
||||
public GetResourceQueryHandler(IResourceProxy resourceProxy)
|
||||
{
|
||||
_resourceProxy = resourceProxy;
|
||||
}
|
||||
public string Handle(GetResourceQuery message)
|
||||
{
|
||||
return _resourceProxy.GetResourceValue(message.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Settings.Commands
|
||||
{
|
||||
public class PutSettingCommand<T> : IRequest
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public T value { get; set; }
|
||||
|
||||
public class PutSettingCommandHandler : IRequestHandler<PutSettingCommand<T>>
|
||||
{
|
||||
private readonly ISettingsProxy _settingsProxy;
|
||||
|
||||
public PutSettingCommandHandler(ISettingsProxy settingsProxy)
|
||||
{
|
||||
_settingsProxy = settingsProxy;
|
||||
}
|
||||
public void Handle(PutSettingCommand<T> message)
|
||||
{
|
||||
_settingsProxy.PutSetting(message.Key, message.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Settings.Queries
|
||||
{
|
||||
public class GetSettingQuery<T> : IRequest<T>
|
||||
{
|
||||
public string Key { get; set; }
|
||||
|
||||
public class GetSettingQueryHandler : IRequestHandler<GetSettingQuery<T>, T>
|
||||
{
|
||||
private readonly ISettingsProxy _settingsProxy;
|
||||
|
||||
public GetSettingQueryHandler(ISettingsProxy settingsProxy)
|
||||
{
|
||||
_settingsProxy = settingsProxy;
|
||||
}
|
||||
public T Handle(GetSettingQuery<T> message)
|
||||
{
|
||||
return _settingsProxy.GetSetting<T>(message.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user