Don't use mediator for App services (recent, resource, settings)

WIP in View models
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-28 16:13:17 +01:00
parent 45fcf7e8ab
commit d1ba73ee9d
30 changed files with 68 additions and 349 deletions

View File

@@ -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>

View File

@@ -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();

View File

@@ -1,7 +0,0 @@
namespace ModernKeePass.Application.Common.Interfaces
{
public interface IHasSelectableObject
{
ISelectableModel SelectedItem { get; set; }
}
}

View File

@@ -1,7 +0,0 @@
namespace ModernKeePass.Application.Common.Interfaces
{
public interface IIsEnabled
{
bool IsEnabled { get; }
}
}

View File

@@ -1,7 +0,0 @@
namespace ModernKeePass.Application.Common.Interfaces
{
public interface ISelectableModel
{
bool IsSelected { get; set; }
}
}

View File

@@ -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; }

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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();
}
}

View File

@@ -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
});
}
}
}
}

View File

@@ -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();
}
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -55,6 +55,9 @@
<Compile Include="Exceptions\NavigationException.cs" />
<Compile Include="Exceptions\SaveException.cs" />
<Compile Include="Interfaces\IDateTime.cs" />
<Compile Include="Interfaces\IHasSelectableObject.cs" />
<Compile Include="Interfaces\IIsEnabled.cs" />
<Compile Include="Interfaces\ISelectableModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />

View File

@@ -6,6 +6,7 @@ namespace ModernKeePass.Domain.Entities
{
public string Id { get; set; }
public string Name { get; set; }
public GroupEntity Parent { get; set; }
public DateTimeOffset LastModificationDate { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
namespace ModernKeePass.Interfaces
namespace ModernKeePass.Domain.Interfaces
{
public interface IHasSelectableObject
{

View File

@@ -1,4 +1,4 @@
namespace ModernKeePass.Interfaces
namespace ModernKeePass.Domain.Interfaces
{
public interface IIsEnabled
{

View File

@@ -1,4 +1,4 @@
namespace ModernKeePass.Interfaces
namespace ModernKeePass.Domain.Interfaces
{
public interface ISelectableModel
{

View File

@@ -2,6 +2,8 @@
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Infrastructure.Common;
using ModernKeePass.Infrastructure.KeePass;
using ModernKeePass.Infrastructure.UWP;
@@ -17,10 +19,11 @@ namespace ModernKeePass.Infrastructure
services.AddSingleton(typeof(IDatabaseProxy), typeof(KeePassDatabaseClient));
services.AddTransient(typeof(ICryptographyClient), typeof(KeePassCryptographyClient));
services.AddTransient(typeof(IPasswordProxy), typeof(KeePassPasswordClient));
services.AddTransient(typeof(IResourceProxy), typeof(UwpResourceClient));
/*services.AddTransient(typeof(IResourceProxy), typeof(UwpResourceClient));
services.AddTransient(typeof(ISettingsProxy), typeof(UwpSettingsClient));
services.AddTransient(typeof(IRecentProxy), typeof(UwpRecentFilesClient));
services.AddTransient(typeof(IFileProxy), typeof(StorageFileClient));
services.AddTransient(typeof(IRecentProxy), typeof(UwpRecentFilesClient));*/
services.AddScoped(typeof(IFileProxy), typeof(StorageFileClient));
services.AddTransient(typeof(IDateTime), typeof(MachineDateTime));
return services;
}
}

View File

@@ -7,6 +7,7 @@ using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Exceptions;
using ModernKeePass.Domain.Interfaces;
using ModernKeePassLib;
using ModernKeePassLib.Cryptography.KeyDerivation;
using ModernKeePassLib.Interfaces;
@@ -22,6 +23,7 @@ namespace ModernKeePass.Infrastructure.KeePass
private readonly ISettingsProxy _settings;
private readonly IFileProxy _fileService;
private readonly IMapper _mapper;
private readonly IDateTime _dateTime;
private readonly PwDatabase _pwDatabase = new PwDatabase();
private string _fileAccessToken;
private Credentials _credentials;
@@ -38,19 +40,19 @@ namespace ModernKeePass.Infrastructure.KeePass
set { _pwDatabase.RecycleBinEnabled = value; }
}
public string RecycleBinId
public GroupEntity RecycleBin
{
get
{
if (_pwDatabase.RecycleBinEnabled)
{
var pwGroup = _pwDatabase.RootGroup.FindGroup(_pwDatabase.RecycleBinUuid, true);
return pwGroup.Uuid.ToHexString();
return _mapper.Map<GroupEntity>(pwGroup);
}
return null;
}
set { _pwDatabase.RecycleBinUuid = BuildIdFromString(value); }
set { _pwDatabase.RecycleBinUuid = BuildIdFromString(value.Id); }
}
public string CipherId
@@ -75,11 +77,12 @@ namespace ModernKeePass.Infrastructure.KeePass
set { _pwDatabase.Compression = (PwCompressionAlgorithm) Enum.Parse(typeof(PwCompressionAlgorithm), value); }
}
public KeePassDatabaseClient(ISettingsProxy settings, IFileProxy fileService, IMapper mapper)
public KeePassDatabaseClient(ISettingsProxy settings, IFileProxy fileService, IMapper mapper, IDateTime dateTime)
{
_settings = settings;
_fileService = fileService;
_mapper = mapper;
_dateTime = dateTime;
}
public async Task<GroupEntity> Open(FileInfo fileInfo, Credentials credentials)
@@ -94,7 +97,8 @@ namespace ModernKeePass.Infrastructure.KeePass
_credentials = credentials;
_fileAccessToken = fileInfo.Path;
return _mapper.Map<GroupEntity>(_pwDatabase.RootGroup);
RootGroup = _mapper.Map<GroupEntity>(_pwDatabase.RootGroup);
return RootGroup;
}
catch (InvalidCompositeKeyException ex)
{
@@ -124,7 +128,8 @@ namespace ModernKeePass.Infrastructure.KeePass
_fileAccessToken = fileInfo.Path;
return _mapper.Map<GroupEntity>(_pwDatabase.RootGroup);
RootGroup = _mapper.Map<GroupEntity>(_pwDatabase.RootGroup);
return RootGroup;
}
public async Task SaveDatabase()
@@ -158,6 +163,12 @@ namespace ModernKeePass.Infrastructure.KeePass
}
}
public void SetRecycleBin(string id)
{
_pwDatabase.RecycleBinUuid = BuildIdFromString(id);
_pwDatabase.RecycleBinChanged = _dateTime.Now;
}
public void CloseDatabase()
{
_pwDatabase?.Close();

View File

@@ -1,9 +1,9 @@
using System.Windows.Input;
using Windows.UI.Xaml;
using Microsoft.Xaml.Interactivity;
using ModernKeePass.Application.Resources.Queries;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Actions
@@ -32,23 +32,19 @@ namespace ModernKeePass.Actions
public object Execute(object sender, object parameter)
{
var mediator = App.Mediator;
var resource = new ResourcesService();
var type = Entity is GroupVm ? "Group" : "Entry";
var message = Entity.IsRecycleOnDelete
? mediator.Send(new GetResourceQuery { Key = $"{type}RecyclingConfirmation" })
: mediator.Send(new GetResourceQuery { Key = $"{type}DeletingConfirmation" });
var text = Entity.IsRecycleOnDelete ?
mediator.Send(new GetResourceQuery { Key = $"{type}Recycled" }) :
mediator.Send(new GetResourceQuery { Key = $"{type}Deleted" });
MessageDialogHelper.ShowActionDialog(
mediator.Send(new GetResourceQuery { Key = "EntityDeleteTitle" }).GetAwaiter().GetResult(),
message.GetAwaiter().GetResult(),
mediator.Send(new GetResourceQuery { Key = "EntityDeleteActionButton" }).GetAwaiter().GetResult(),
mediator.Send(new GetResourceQuery { Key = "EntityDeleteCancelButton" }).GetAwaiter().GetResult(), async a =>
? resource.GetResourceValue($"{type}RecyclingConfirmation")
: resource.GetResourceValue($"{type}DeletingConfirmation");
var text = Entity.IsRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
{
ToastNotificationHelper.ShowMovedToast(Entity, await mediator.Send(new GetResourceQuery { Key = "EntityDeleting" }), await text);
await Entity.MarkForDelete(await mediator.Send(new GetResourceQuery { Key = "RecycleBinTitle"}));
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
Command.Execute(null);
}, null).GetAwaiter();

View File

@@ -1,31 +0,0 @@
using System.Threading.Tasks;
using Windows.Storage;
using ModernKeePass.ViewModels;
using ModernKeePassLib;
using ModernKeePassLib.Cryptography.KeyDerivation;
using ModernKeePassLib.Keys;
namespace ModernKeePass.Interfaces
{
public interface IDatabaseService
{
string Name { get; }
bool RecycleBinEnabled { get; set; }
GroupVm RootGroup { get; set; }
GroupVm RecycleBin { get; set; }
PwUuid DataCipher { get; set; }
PwCompressionAlgorithm CompressionAlgorithm { get; set; }
KdfParameters KeyDerivation { get; set; }
bool IsOpen { get; }
bool HasChanged { get; set; }
Task Open(StorageFile databaseFile, CompositeKey key, bool createNew = false);
Task ReOpen();
void Save();
Task Save(StorageFile file);
void CreateRecycleBin(string title);
void AddDeletedItem(PwUuid id);
void Close(bool releaseFile = true);
void UpdateCompositeKey(CompositeKey newCompositeKey);
}
}

View File

@@ -10,18 +10,17 @@ using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
using ModernKeePass.Application.Group.Commands.CreateGroup;
using ModernKeePass.Application.Group.Commands.DeleteEntry;
using ModernKeePass.Application.Resources.Queries;
using ModernKeePass.Application.Security.Commands.GeneratePassword;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
namespace ModernKeePass.ViewModels
{
public class EntryVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
{
public GroupVm ParentGroup { get; private set; }
public GroupVm PreviousGroup { get; private set; }
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery {Password = Password}).GetAwaiter().GetResult();
@@ -35,7 +34,7 @@ namespace ModernKeePass.ViewModels
public bool BracketsPatternSelected { get; set; }
public string CustomChars { get; set; } = string.Empty;
public string Id => _entry.Id;
public bool IsRecycleOnDelete => GetDatabase().IsRecycleBinEnabled && !ParentGroup.IsSelected;
public bool IsRecycleOnDelete => _database.IsRecycleBinEnabled && !ParentGroup.IsSelected;
public IEnumerable<IVmEntity> BreadCrumb => new List<IVmEntity>(ParentGroup.BreadCrumb) {ParentGroup};
/// <summary>
/// Determines if the Entry is current or from history
@@ -197,6 +196,8 @@ namespace ModernKeePass.ViewModels
private readonly Application.Entry.Models.EntryVm _entry;
private readonly IMediator _mediator;
private readonly IResourceService _resource;
private DatabaseVm _database;
private bool _isEditMode;
private bool _isRevealPassword;
private double _passwordLength = 25;
@@ -204,13 +205,14 @@ namespace ModernKeePass.ViewModels
public EntryVm() { }
internal EntryVm(Application.Entry.Models.EntryVm entry, GroupVm parent) : this(entry, parent, App.Mediator) { }
internal EntryVm(Application.Entry.Models.EntryVm entry, Application.Group.Models.GroupVm parent) : this(entry, parent, App.Mediator, new ResourcesService()) { }
public EntryVm(Application.Entry.Models.EntryVm entry, GroupVm parent, IMediator mediator)
public EntryVm(Application.Entry.Models.EntryVm entry, Application.Group.Models.GroupVm parent, IMediator mediator, IResourceService resource)
{
_entry = entry;
_mediator = mediator;
ParentGroup = parent;
_resource = resource;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
SaveCommand = new RelayCommand(() => _mediator.Send(new SaveDatabaseCommand()));
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
@@ -238,13 +240,12 @@ namespace ModernKeePass.ViewModels
public async Task MarkForDelete(string recycleBinTitle)
{
var database = GetDatabase();
if (database.IsRecycleBinEnabled && database.RecycleBinId == null)
await _mediator.Send(new CreateGroupCommand { ParentGroup = database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
await Move(database.IsRecycleBinEnabled && !ParentGroup.IsSelected ? _database.RecycleBin : null);
if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
await _mediator.Send(new CreateGroupCommand { ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
await Move(_database.IsRecycleBinEnabled && !ParentGroup.IsSelected ? _database.RecycleBin : null);
}
public async Task Move(GroupVm destination)
public async Task Move(Application.Group.Models.GroupVm destination)
{
PreviousGroup = ParentGroup;
PreviousGroup.Entries.Remove(this);
@@ -270,13 +271,8 @@ namespace ModernKeePass.ViewModels
public override string ToString()
{
return IsSelected ?
_mediator.Send(new GetResourceQuery{Key = "EntryCurrent"}).GetAwaiter().GetResult() :
_resource.GetResourceValue("EntryCurrent") :
_entry.ModificationDate.ToString("g");
}
private DatabaseVm GetDatabase()
{
return _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
}
}
}

View File

@@ -20,6 +20,7 @@ using ModernKeePass.Application.Group.Commands.SortEntries;
using ModernKeePass.Application.Group.Commands.SortGroups;
using ModernKeePass.Common;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
namespace ModernKeePass.ViewModels

View File

@@ -149,9 +149,6 @@
<Compile Include="Converters\EmptyStringToVisibilityConverter.cs" />
<Compile Include="Converters\NullToBooleanConverter.cs" />
<Compile Include="Extensions\DispatcherTaskExtensions.cs" />
<Content Include="Interfaces\IDatabaseService.cs" />
<Compile Include="Interfaces\IHasSelectableObject.cs" />
<Compile Include="Interfaces\ISelectableModel.cs" />
<Compile Include="Views\BasePages\LayoutAwarePageBase.cs" />
<Compile Include="Views\MainPageFrames\ImportExportPage.xaml.cs">
<DependentUpon>ImportExportPage.xaml</DependentUpon>
@@ -191,7 +188,6 @@
<Compile Include="Converters\ProgressBarLegalValuesConverter.cs" />
<Compile Include="Converters\TextToWidthConverter.cs" />
<Compile Include="Events\PasswordEventArgs.cs" />
<Compile Include="Interfaces\IIsEnabled.cs" />
<Compile Include="Interfaces\IVmEntity.cs" />
<Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>