1st working version in clean arch

WIP Parent group mapping issues
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-30 19:43:04 +02:00
parent d1ba73ee9d
commit e4bd788ed3
54 changed files with 319 additions and 283 deletions

View File

@@ -42,6 +42,7 @@
<Compile Include="ApplicationModule.cs" />
<Compile Include="Common\Interfaces\ICryptographyClient.cs" />
<Compile Include="Common\Interfaces\IDatabaseProxy.cs" />
<Compile Include="Common\Interfaces\IEntityVm.cs" />
<Compile Include="Common\Interfaces\IFileProxy.cs" />
<Compile Include="Common\Interfaces\IImportFormat.cs" />
<Compile Include="Common\Interfaces\IPasswordProxy.cs" />

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
namespace ModernKeePass.Application.Common.Interfaces
{
@@ -18,7 +19,7 @@ namespace ModernKeePass.Application.Common.Interfaces
Task<GroupEntity> Open(FileInfo fileInfo, Credentials credentials);
Task<GroupEntity> ReOpen();
Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials);
Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2);
Task SaveDatabase();
Task SaveDatabase(string filePath);
void SetRecycleBin(string id);

View File

@@ -0,0 +1,11 @@
using ModernKeePass.Domain.Enums;
namespace ModernKeePass.Application.Common.Interfaces
{
public interface IEntityVm
{
string Id { get; set; }
string Title { get; set; }
Icon Icon { get; set; }
}
}

View File

@@ -1,5 +1,4 @@
using MediatR;
using System.Threading.Tasks;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Exceptions;
@@ -7,7 +6,7 @@ namespace ModernKeePass.Application.Database.Commands.CloseDatabase
{
public class CloseDatabaseCommand: IRequest
{
public class CloseDatabaseCommandHandler : IAsyncRequestHandler<CloseDatabaseCommand>
public class CloseDatabaseCommandHandler : IRequestHandler<CloseDatabaseCommand>
{
private readonly IDatabaseProxy _database;
@@ -15,7 +14,7 @@ namespace ModernKeePass.Application.Database.Commands.CloseDatabase
{
_database = database;
}
public async Task Handle(CloseDatabaseCommand message)
public void Handle(CloseDatabaseCommand message)
{
if (_database.IsOpen) _database.CloseDatabase();
else throw new DatabaseClosedException();

View File

@@ -23,15 +23,18 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
{
var database = new DatabaseVm
{
IsOpen = _databaseProxy.IsOpen,
Name = _databaseProxy.Name,
RootGroup = _mapper.Map<GroupVm>(_databaseProxy.RootGroup),
IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled,
RecycleBin = _mapper.Map<GroupVm>(_databaseProxy.RecycleBin),
Compression = _databaseProxy.Compression,
CipherId = _databaseProxy.CipherId,
KeyDerivationId = _databaseProxy.CipherId
IsOpen = _databaseProxy.IsOpen
};
if (database.IsOpen)
{
database.Name = _databaseProxy.Name;
database.RootGroup = _mapper.Map<GroupVm>(_databaseProxy.RootGroup);
database.IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled;
database.RecycleBin = _mapper.Map<GroupVm>(_databaseProxy.RecycleBin);
database.Compression = _databaseProxy.Compression;
database.CipherId = _databaseProxy.CipherId;
database.KeyDerivationId = _databaseProxy.CipherId;
}
return database;
}
}

View File

@@ -1,5 +1,4 @@
using System.Reflection;
using AutoMapper;
using FluentValidation;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
@@ -11,7 +10,6 @@ namespace ModernKeePass.Application
public static IServiceCollection AddApplication(this IServiceCollection services)
{
var assembly = typeof(DependencyInjection).GetTypeInfo().Assembly;
services.AddAutoMapper(assembly);
services.AddMediatR(assembly);
//services.AddValidatorsFromAssembly(assembly);

View File

@@ -2,14 +2,17 @@
using System.Collections.Generic;
using System.Drawing;
using AutoMapper;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Common.Mappings;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
namespace ModernKeePass.Application.Entry.Models
{
public class EntryVm: IMapFrom<EntryEntity>
public class EntryVm: IEntityVm, IMapFrom<EntryEntity>
{
public GroupVm ParentGroup { get; set; }
public string Id { get; set; }
public string Title { get; set; }
public string Username { get; set; }
@@ -28,6 +31,7 @@ namespace ModernKeePass.Application.Entry.Models
public void Mapping(Profile profile)
{
profile.CreateMap<EntryEntity, EntryVm>()
.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
.ForMember(d => d.Username, opts => opts.MapFrom(s => s.UserName))

View File

@@ -1,31 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Common.Mappings;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.Application.Group.Models
{
public class GroupVm: IMapFrom<GroupEntity>
public class GroupVm: IEntityVm, ISelectableModel, IMapFrom<GroupEntity>
{
public GroupVm ParentGroup { get; set; }
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>();
public List<GroupVm> SubGroups { get; set; }
public List<EntryVm> Entries { get; set; }
public bool IsSelected { get; set; }
public override string ToString()
{
return Title;
}
public void Mapping(Profile profile)
{
profile.CreateMap<GroupEntity, GroupVm>()
.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
.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,18 +1,8 @@
using AutoMapper;
using ModernKeePass.Application.Common.Mappings;
using ModernKeePass.Domain.Entities;
namespace ModernKeePass.Application.Cryptography.Models
namespace ModernKeePass.Application.Parameters.Models
{
public class CipherVm: IMapFrom<BaseEntity>
public class CipherVm
{
public string Id { get; set; }
public string Name { get; set; }
public void Mapping(Profile profile)
{
profile.CreateMap<BaseEntity, CipherVm>()
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name));
}
}
}

View File

@@ -1,19 +1,9 @@
using AutoMapper;
using ModernKeePass.Application.Common.Mappings;
using ModernKeePass.Domain.Entities;
namespace ModernKeePass.Application.Cryptography.Models
namespace ModernKeePass.Application.Parameters.Models
{
public class KeyDerivationVm : IMapFrom<BaseEntity>
public class KeyDerivationVm
{
public string Id { get; set; }
public string Name { get; set; }
public void Mapping(Profile profile)
{
profile.CreateMap<BaseEntity, CipherVm>()
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name));
}
}
}

View File

@@ -1,27 +1,29 @@
using System.Collections.Generic;
using AutoMapper;
using System.Linq;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Cryptography.Models;
using ModernKeePass.Application.Parameters.Models;
namespace ModernKeePass.Application.Cryptography.Queries.GetCiphers
namespace ModernKeePass.Application.Parameters.Queries.GetCiphers
{
public class GetCiphersQuery: IRequest<IEnumerable<CipherVm>>
{
public class GetCiphersQueryHandler: IRequestHandler<GetCiphersQuery, IEnumerable<CipherVm>>
{
private readonly ICryptographyClient _cryptography;
private readonly IMapper _mapper;
public GetCiphersQueryHandler(ICryptographyClient cryptography, IMapper mapper)
public GetCiphersQueryHandler(ICryptographyClient cryptography)
{
_cryptography = cryptography;
_mapper = mapper;
}
public IEnumerable<CipherVm> Handle(GetCiphersQuery message)
{
yield return _mapper.Map<CipherVm>(_cryptography.Ciphers);
return _cryptography.Ciphers.Select(c => new CipherVm
{
Id = c.Id,
Name = c.Name
});
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Linq;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
namespace ModernKeePass.Application.Cryptography.Queries.GetCompressions
namespace ModernKeePass.Application.Parameters.Queries.GetCompressions
{
public class GetCompressionsQuery : IRequest<IEnumerable<string>>
{

View File

@@ -1,27 +1,29 @@
using System.Collections.Generic;
using AutoMapper;
using System.Linq;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Cryptography.Models;
using ModernKeePass.Application.Parameters.Models;
namespace ModernKeePass.Application.Cryptography.Queries.GetKeyDerivations
namespace ModernKeePass.Application.Parameters.Queries.GetKeyDerivations
{
public class GetKeyDerivationsQuery : IRequest<IEnumerable<KeyDerivationVm>>
{
public class GetKeyDerivationsQueryHandler : IRequestHandler<GetKeyDerivationsQuery, IEnumerable<KeyDerivationVm>>
{
private readonly ICryptographyClient _cryptography;
private readonly IMapper _mapper;
public GetKeyDerivationsQueryHandler(ICryptographyClient cryptography, IMapper mapper)
public GetKeyDerivationsQueryHandler(ICryptographyClient cryptography)
{
_cryptography = cryptography;
_mapper = mapper;
}
public IEnumerable<KeyDerivationVm> Handle(GetKeyDerivationsQuery message)
{
yield return _mapper.Map<KeyDerivationVm>(_cryptography.KeyDerivations);
return _cryptography.KeyDerivations.Select(c => new KeyDerivationVm
{
Id = c.Id,
Name = c.Name
});
}
}
}

View File

@@ -3,7 +3,7 @@
"dependencies": {
"Autofac": "4.9.4",
"Autofac.Extensions.DependencyInjection": "4.4.0",
"AutoMapper": "6.1.1",
"AutoMapper": "6.0.2",
"AutoMapper.Extensions.Microsoft.DependencyInjection": "2.0.1",
"FluentValidation": "8.6.2",
"MediatR": "3.0.1",

View File

@@ -47,6 +47,7 @@
<Compile Include="Entities\EntryEntity.cs" />
<Compile Include="Entities\GroupEntity.cs" />
<Compile Include="Enums\CredentialStatusTypes.cs" />
<Compile Include="Enums\DatabaseVersion.cs" />
<Compile Include="Enums\EntryFieldName.cs" />
<Compile Include="Enums\Icon.cs" />
<Compile Include="Enums\ImportFormat.cs" />

View File

@@ -0,0 +1,8 @@
namespace ModernKeePass.Domain.Enums
{
public enum DatabaseVersion
{
V2,
V4
}
}

View File

@@ -1,6 +1,4 @@
using System.Reflection;
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Infrastructure.Common;
@@ -13,9 +11,6 @@ namespace ModernKeePass.Infrastructure
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
{
var assembly = typeof(DependencyInjection).GetTypeInfo().Assembly;
services.AddAutoMapper(assembly);
services.AddSingleton(typeof(IDatabaseProxy), typeof(KeePassDatabaseClient));
services.AddTransient(typeof(ICryptographyClient), typeof(KeePassCryptographyClient));
services.AddTransient(typeof(IPasswordProxy), typeof(KeePassPasswordClient));

View File

@@ -19,6 +19,7 @@ namespace ModernKeePass.Infrastructure.KeePass
{
Uri url;
CreateMap<PwEntry, EntryEntity>()
//.ForMember(dest => dest.Parent, opt => opt.MapFrom(src => src.ParentGroup))
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Uuid.ToHexString()))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.TitleField)))
.ForMember(dest => dest.UserName, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.UserNameField)))
@@ -37,6 +38,7 @@ namespace ModernKeePass.Infrastructure.KeePass
.ForMember(dest => dest.AdditionalFields, opt => opt.MapFrom(src =>
src.Strings.Where(s => !PwDefs.GetStandardFields().Contains(s.Key)).ToDictionary(s => s.Key, s => GetEntryValue(src, s.Key))))
.ForMember(dest => dest.LastModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime)));
//.MaxDepth(1);
}
private void FromModelToDto()

View File

@@ -15,17 +15,18 @@ namespace ModernKeePass.Infrastructure.KeePass
private void FromDtoToModel()
{
CreateMap<PwGroup, GroupEntity>()
//.ForMember(d => d.Parent, opts => opts.MapFrom(s => s.ParentGroup))
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Uuid.ToHexString()))
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name))
.ForMember(d => d.Icon, opts => opts.MapFrom(s => IconMapper.MapPwIconToIcon(s.IconId)))
.ForMember(d => d.LastModificationDate, opts => opts.MapFrom(s => s.LastModificationTime))
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.Groups));
//.MaxDepth(1);
}
private void FromModelToDto()
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -20,7 +20,6 @@ namespace ModernKeePass.Infrastructure.KeePass
{
public class KeePassDatabaseClient: IDatabaseProxy
{
private readonly ISettingsProxy _settings;
private readonly IFileProxy _fileService;
private readonly IMapper _mapper;
private readonly IDateTime _dateTime;
@@ -77,9 +76,8 @@ namespace ModernKeePass.Infrastructure.KeePass
set { _pwDatabase.Compression = (PwCompressionAlgorithm) Enum.Parse(typeof(PwCompressionAlgorithm), value); }
}
public KeePassDatabaseClient(ISettingsProxy settings, IFileProxy fileService, IMapper mapper, IDateTime dateTime)
public KeePassDatabaseClient(IFileProxy fileService, IMapper mapper, IDateTime dateTime)
{
_settings = settings;
_fileService = fileService;
_mapper = mapper;
_dateTime = dateTime;
@@ -111,17 +109,16 @@ namespace ModernKeePass.Infrastructure.KeePass
return await Open(new FileInfo {Path = _fileAccessToken}, _credentials);
}
public async Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials)
public async Task<GroupEntity> Create(FileInfo fileInfo, Credentials credentials, DatabaseVersion version = DatabaseVersion.V2)
{
var compositeKey = await CreateCompositeKey(credentials);
var ioConnection = await BuildConnectionInfo(fileInfo);
_pwDatabase.New(ioConnection, compositeKey);
var fileFormat = _settings.GetSetting<string>("DefaultFileFormat");
switch (fileFormat)
switch (version)
{
case "4":
case DatabaseVersion.V4:
_pwDatabase.KdfParameters = KdfPool.Get("Argon2").GetDefaultParameters();
break;
}

View File

@@ -1,10 +1,10 @@
{
"supports": {},
"dependencies": {
"AutoMapper": "6.1.1",
"AutoMapper": "6.0.2",
"AutoMapper.Extensions.Microsoft.DependencyInjection": "2.0.1",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"ModernKeePassLib": "2.44.1",
"ModernKeePassLib": "2.44.2",
"NETStandard.Library": "2.0.3"
},
"frameworks": {

View File

@@ -17,8 +17,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="ModernKeePassLib" Version="2.44.1" />
<PackageReference Include="AutoMapper" Version="6.1.1" />
<PackageReference Include="ModernKeePassLib" Version="2.44.2" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">

View File

@@ -1,6 +1,8 @@
using System.Windows.Input;
using Windows.UI.Xaml;
using MediatR;
using Microsoft.Xaml.Interactivity;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
@@ -10,6 +12,8 @@ namespace ModernKeePass.Actions
{
public class DeleteEntityAction : DependencyObject, IAction
{
private readonly IMediator _mediator;
public IVmEntity Entity
{
get { return (IVmEntity)GetValue(EntityProperty); }
@@ -30,15 +34,23 @@ namespace ModernKeePass.Actions
DependencyProperty.Register("Command", typeof(ICommand), typeof(DeleteEntityAction),
new PropertyMetadata(null));
public DeleteEntityAction() : this(App.Mediator) { }
public DeleteEntityAction(IMediator mediator)
{
_mediator = mediator;
}
public object Execute(object sender, object parameter)
{
var resource = new ResourcesService();
var type = Entity is GroupVm ? "Group" : "Entry";
var isRecycleOnDelete = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult().IsRecycleBinEnabled;
var message = Entity.IsRecycleOnDelete
var message = isRecycleOnDelete
? resource.GetResourceValue($"{type}RecyclingConfirmation")
: resource.GetResourceValue($"{type}DeletingConfirmation");
var text = Entity.IsRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
var text = isRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), a =>

View File

@@ -19,7 +19,6 @@ using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Database.Queries.ReOpenDatabase;
using ModernKeePass.Common;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Exceptions;
using ModernKeePass.Infrastructure;
using ModernKeePass.Services;
@@ -58,6 +57,7 @@ namespace ModernKeePass
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddApplication();
serviceCollection.AddInfrastructure();
serviceCollection.AddAppAutomapper();
Services = serviceCollection.BuildServiceProvider();
Mediator = Services.GetService<IMediator>();
}
@@ -97,12 +97,7 @@ namespace ModernKeePass
if (file != null)
{
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var fileInfo = new FileInfo
{
Name = file.DisplayName,
Path = token
};
await Mediator.Send(new SaveDatabaseCommand { FileInfo = fileInfo });
await Mediator.Send(new SaveDatabaseCommand { FilePath = token });
}
}, null);
}

View File

@@ -1,6 +1,6 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Interfaces;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.Controls
{

View File

@@ -5,7 +5,7 @@ using ModernKeePass.Domain.Enums;
namespace ModernKeePass.Converters
{
public class IntToSymbolConverter : IValueConverter
public class IconToSymbolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{

View File

@@ -0,0 +1,18 @@
using System.Reflection;
using AutoMapper;
using Microsoft.Extensions.DependencyInjection;
namespace ModernKeePass
{
public static class DependencyInjection
{
public static IServiceCollection AddAppAutomapper(this IServiceCollection services)
{
var applicationAssembly = typeof(Application.DependencyInjection).GetTypeInfo().Assembly;
var infrastructureAssembly = typeof(Infrastructure.DependencyInjection).GetTypeInfo().Assembly;
services.AddAutoMapper(applicationAssembly, infrastructureAssembly);
return services;
}
}
}

View File

@@ -1,5 +1,5 @@
using System;
using ModernKeePass.ViewModels;
using ModernKeePass.Application.Group.Models;
namespace ModernKeePass.Events
{

View File

@@ -1,20 +1,18 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Input;
using ModernKeePass.ViewModels;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Application.Group.Models;
namespace ModernKeePass.Interfaces
{
public interface IVmEntity
{
GroupVm ParentGroup { get; }
GroupVm PreviousGroup { get; }
int Icon { get; }
Symbol Icon { get; }
string Id { get; }
string Title { get; set; }
IEnumerable<IVmEntity> BreadCrumb { get; }
IEnumerable<GroupVm> BreadCrumb { get; }
bool IsEditMode { get; }
bool IsRecycleOnDelete { get; }
/// <summary>
/// Save changes to Model

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
<Identity Name="wismna.ModernKeePass" Publisher="CN=0719A91A-C322-4EE0-A257-E60733EECF06" Version="1.15.0.0" />
<Identity Name="wismna.ModernKeePass" Publisher="CN=0719A91A-C322-4EE0-A257-E60733EECF06" Version="1.15.0.2" />
<Properties>
<DisplayName>ModernKeePass</DisplayName>
<PublisherDisplayName>wismna</PublisherDisplayName>

View File

@@ -1,6 +1,6 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Interfaces;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.TemplateSelectors
{

View File

@@ -3,13 +3,16 @@ using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml.Controls;
using MediatR;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
using ModernKeePass.Application.Group.Commands.AddEntry;
using ModernKeePass.Application.Group.Commands.CreateGroup;
using ModernKeePass.Application.Group.Commands.DeleteEntry;
using ModernKeePass.Application.Group.Commands.RemoveEntry;
using ModernKeePass.Application.Security.Commands.GeneratePassword;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Common;
@@ -34,8 +37,23 @@ namespace ModernKeePass.ViewModels
public bool BracketsPatternSelected { get; set; }
public string CustomChars { get; set; } = string.Empty;
public string Id => _entry.Id;
public bool IsRecycleOnDelete => _database.IsRecycleBinEnabled && !ParentGroup.IsSelected;
public IEnumerable<IVmEntity> BreadCrumb => new List<IVmEntity>(ParentGroup.BreadCrumb) {ParentGroup};
public IEnumerable<Application.Group.Models.GroupVm> BreadCrumb
{
get
{
var groups = new Stack<Application.Group.Models.GroupVm>();
var group = _entry.ParentGroup;
while (group.ParentGroup != null)
{
group = group.ParentGroup;
groups.Push(group);
}
return groups;
}
}
/// <summary>
/// Determines if the Entry is current or from history
/// </summary>
@@ -87,12 +105,12 @@ namespace ModernKeePass.ViewModels
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Notes), FieldValue = value }); }
}
public int Icon
public Symbol Icon
{
get
{
if (HasExpired) return (int)Domain.Enums.Icon.ReportHacked;
return (int) _entry.Icon;
if (HasExpired) return Symbol.ReportHacked;
return (Symbol) _entry.Icon;
}
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Icon), FieldValue = value }); }
}
@@ -156,20 +174,7 @@ namespace ModernKeePass.ViewModels
}
}
public IEnumerable<IVmEntity> History
{
get
{
var history = new Stack<EntryVm>();
foreach (var historyEntry in _entry.History)
{
history.Push(new EntryVm(historyEntry, ParentGroup) {IsSelected = false});
}
history.Push(this);
return history;
}
}
public IEnumerable<Application.Entry.Models.EntryVm> History => _entry.History;
public Color? BackgroundColor
@@ -190,6 +195,8 @@ namespace ModernKeePass.ViewModels
}
}
public bool CanRestore => _entry.ParentGroup == _database.RecycleBin;
public ICommand SaveCommand { get; }
public ICommand GeneratePasswordCommand { get; }
public ICommand UndoDeleteCommand { get; }
@@ -197,7 +204,7 @@ namespace ModernKeePass.ViewModels
private readonly Application.Entry.Models.EntryVm _entry;
private readonly IMediator _mediator;
private readonly IResourceService _resource;
private DatabaseVm _database;
private readonly DatabaseVm _database;
private bool _isEditMode;
private bool _isRevealPassword;
private double _passwordLength = 25;
@@ -205,18 +212,20 @@ namespace ModernKeePass.ViewModels
public EntryVm() { }
internal EntryVm(Application.Entry.Models.EntryVm entry, Application.Group.Models.GroupVm parent) : this(entry, parent, App.Mediator, new ResourcesService()) { }
internal EntryVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, new ResourcesService(), isNewEntry) { }
public EntryVm(Application.Entry.Models.EntryVm entry, Application.Group.Models.GroupVm parent, IMediator mediator, IResourceService resource)
public EntryVm(Application.Entry.Models.EntryVm entry, IMediator mediator, IResourceService resource, bool isNewEntry = false)
{
_entry = entry;
_mediator = mediator;
_resource = resource;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
_isEditMode = isNewEntry;
if (isNewEntry) GeneratePassword().GetAwaiter().GetResult();
SaveCommand = new RelayCommand(() => _mediator.Send(new SaveDatabaseCommand()));
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
UndoDeleteCommand = new RelayCommand(async () => await Move(PreviousGroup), () => PreviousGroup != null);
UndoDeleteCommand = new RelayCommand(async () => await Move(entry.ParentGroup), () => _entry.ParentGroup != null);
}
public async Task GeneratePassword()
@@ -242,20 +251,18 @@ namespace ModernKeePass.ViewModels
{
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);
await Move(_database.IsRecycleBinEnabled && _entry.ParentGroup == _database.RecycleBin ? _database.RecycleBin : null);
}
public async Task Move(Application.Group.Models.GroupVm destination)
{
PreviousGroup = ParentGroup;
PreviousGroup.Entries.Remove(this);
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _entry.ParentGroup, Entry = _entry });
if (destination == null)
{
await _mediator.Send(new DeleteEntryCommand { Entry = _entry });
return;
}
ParentGroup = destination;
ParentGroup.Entries.Add(this);
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
}
public async Task CommitDelete()

View File

@@ -4,6 +4,7 @@ using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml.Controls;
using MediatR;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Models;
@@ -27,38 +28,29 @@ namespace ModernKeePass.ViewModels
{
public class GroupVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
{
public GroupVm ParentGroup { get; private set; }
public GroupVm PreviousGroup { get; private set; }
public ObservableCollection<Application.Entry.Models.EntryVm> Entries => new ObservableCollection<Application.Entry.Models.EntryVm>(_group.Entries);
public ObservableCollection<EntryVm> Entries
{
get { return _entries; }
private set { SetProperty(ref _entries, value); }
}
public ObservableCollection<Application.Group.Models.GroupVm> Groups => new ObservableCollection<Application.Group.Models.GroupVm>(_group.SubGroups);
public IEnumerable<EntryVm> SubEntries
public IEnumerable<Application.Entry.Models.EntryVm> SubEntries
{
get
{
var subEntries = new List<EntryVm>();
var subEntries = new List<Application.Entry.Models.EntryVm>();
subEntries.AddRange(Entries);
foreach (var group in Groups)
{
subEntries.AddRange(group.SubEntries);
subEntries.AddRange(group.Entries);
}
return subEntries;
}
}
public ObservableCollection<GroupVm> Groups { get; set; } = new ObservableCollection<GroupVm>();
public string Id => _group.Id;
public bool IsNotRoot => ParentGroup != null;
public bool IsNotRoot => _database.RootGroup != _group;
public bool ShowRestore => IsNotRoot && ParentGroup.IsSelected;
public bool IsRecycleOnDelete => GetDatabase().IsRecycleBinEnabled && !IsSelected && !ParentGroup.IsSelected;
public bool ShowRestore => IsNotRoot && _database.RecycleBin != _group;
/// <summary>
/// Is the Group the database Recycle Bin?
@@ -67,33 +59,30 @@ namespace ModernKeePass.ViewModels
{
get
{
var database = GetDatabase();
return database.IsRecycleBinEnabled && database.RecycleBinId == Id;
return _database.IsRecycleBinEnabled && _database.RecycleBin == _group;
}
set
{
if (value && _group != null) _database.RecycleBin = this;
if (value && _group != null) _database.RecycleBin = _group;
}
}
public IOrderedEnumerable<IGrouping<char, EntryVm>> EntriesZoomedOut => from e in Entries
public IOrderedEnumerable<IGrouping<char, Application.Entry.Models.EntryVm>> EntriesZoomedOut => from e in Entries
group e by e.Title.ToUpper().FirstOrDefault() into grp
orderby grp.Key
select grp;
public string Id => _group.Id;
public string Title
{
get { return _group == null ? string.Empty : _group.Title; }
get { return _group.Title; }
set { _group.Title = value; }
}
public int Icon
public Symbol Icon
{
get
{
if (_group?.Icon != null) return (int) _group?.Icon;
return -1;
}
get { return (Symbol) _group.Icon; }
set { _group.Icon = (Icon)value; }
}
@@ -114,12 +103,12 @@ namespace ModernKeePass.ViewModels
set { SetProperty(ref _isMenuClosed, value); }
}
public IEnumerable<IVmEntity> BreadCrumb
public IEnumerable<Application.Group.Models.GroupVm> BreadCrumb
{
get
{
var groups = new Stack<GroupVm>();
var group = this;
var groups = new Stack<Application.Group.Models.GroupVm>();
var group = _group;
while (group.ParentGroup != null)
{
group = group.ParentGroup;
@@ -137,33 +126,31 @@ namespace ModernKeePass.ViewModels
private readonly Application.Group.Models.GroupVm _group;
private readonly IMediator _mediator;
private readonly DatabaseVm _database;
private bool _isEditMode;
private Application.Entry.Models.EntryVm _reorderedEntry;
private ObservableCollection<EntryVm> _entries = new ObservableCollection<EntryVm>();
private bool _isMenuClosed = true;
public GroupVm() {}
internal GroupVm(Application.Group.Models.GroupVm group, GroupVm parent, string recycleBinId = null) : this(group, parent, App.Mediator, recycleBinId)
internal GroupVm(Application.Group.Models.GroupVm group) : this(group, App.Mediator)
{ }
public GroupVm(Application.Group.Models.GroupVm group, GroupVm parent, IMediator mediator, string recycleBinId = null)
public GroupVm(Application.Group.Models.GroupVm group, IMediator mediator, bool isEditMode = false)
{
_group = group;
_mediator = mediator;
ParentGroup = parent;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
_isEditMode = isEditMode;
SaveCommand = new RelayCommand(async () => await _mediator.Send(new SaveDatabaseCommand()));
SortEntriesCommand = new RelayCommand(async () =>
await SortEntriesAsync().ConfigureAwait(false), () => IsEditMode);
SortGroupsCommand = new RelayCommand(async () =>
await SortGroupsAsync().ConfigureAwait(false), () => IsEditMode);
UndoDeleteCommand = new RelayCommand(async () => await Move(PreviousGroup), () => PreviousGroup != null);
UndoDeleteCommand = new RelayCommand(async () => await Move(group.ParentGroup), () => _group.ParentGroup != null);
if (recycleBinId != null && _group.Id.Equals(recycleBinId)) _database.RecycleBin = this;
Entries = new ObservableCollection<EntryVm>(group.Entries.Select(e => new EntryVm(e, this)));
Entries.CollectionChanged += Entries_CollectionChanged;
Groups = new ObservableCollection<GroupVm>(group.SubGroups.Select(g => new GroupVm(g, this, recycleBinId)));
}
private async void Entries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
@@ -189,50 +176,33 @@ namespace ModernKeePass.ViewModels
}
}
public async Task<GroupVm> AddNewGroup(string name = "")
public async Task<Application.Group.Models.GroupVm> AddNewGroup(string name = "")
{
var newGroup = await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group});
var newGroupVm = new GroupVm(newGroup, this) {Title = name, IsEditMode = string.IsNullOrEmpty(name)};
Groups.Add(newGroupVm);
return newGroupVm;
return await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group});
}
public async Task<EntryVm> AddNewEntry()
public async Task<Application.Entry.Models.EntryVm> AddNewEntry()
{
var newEntry = await _mediator.Send(new CreateEntryCommand { ParentGroup = _group });
var newEntryVm = new EntryVm(newEntry, this) {IsEditMode = true};
await newEntryVm.GeneratePassword();
Entries.Add(newEntryVm);
return newEntryVm;
return await _mediator.Send(new CreateEntryCommand { ParentGroup = _group });
}
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 && !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 && !IsSelected ? _database.RecycleBin : null);
((RelayCommand)UndoDeleteCommand).RaiseCanExecuteChanged();
}
public async Task UndoDelete()
public async Task Move(Application.Group.Models.GroupVm destination)
{
await Move(PreviousGroup);
}
public async Task Move(GroupVm destination)
{
PreviousGroup = ParentGroup;
PreviousGroup.Groups.Remove(this);
await _mediator.Send(new RemoveGroupCommand {ParentGroup = PreviousGroup._group, Group = _group});
await _mediator.Send(new RemoveGroupCommand {ParentGroup = _group.ParentGroup, Group = _group});
if (destination == null)
{
await _mediator.Send(new DeleteGroupCommand { Group = _group });
return;
}
ParentGroup = destination;
ParentGroup.Groups.Add(this);
await _mediator.Send(new AddGroupCommand {ParentGroup = ParentGroup._group, Group = _group});
await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
}
public async Task CommitDelete()
@@ -248,20 +218,13 @@ namespace ModernKeePass.ViewModels
private async Task SortEntriesAsync()
{
await _mediator.Send(new SortEntriesCommand {Group = _group});
Entries = new ObservableCollection<EntryVm>(Entries.OrderBy(e => e.Title));
OnPropertyChanged(nameof(Entries));
}
private async Task SortGroupsAsync()
{
await _mediator.Send(new SortGroupsCommand {Group = _group});
Groups = new ObservableCollection<GroupVm>(Groups.OrderBy(g => g.Title).ThenBy(g => g._group == null));
// TODO: should not be needed
OnPropertyChanged(nameof(Groups));
}
private DatabaseVm GetDatabase()
{
return _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
namespace ModernKeePass.ViewModels

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Windows.Storage;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;

View File

@@ -2,10 +2,6 @@
using System.Collections.ObjectModel;
using System.Linq;
using MediatR;
using ModernKeePass.Application.Cryptography.Models;
using ModernKeePass.Application.Cryptography.Queries.GetCiphers;
using ModernKeePass.Application.Cryptography.Queries.GetCompressions;
using ModernKeePass.Application.Cryptography.Queries.GetKeyDerivations;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Parameters.Commands.SetCipher;
@@ -13,8 +9,12 @@ using ModernKeePass.Application.Parameters.Commands.SetCompression;
using ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin;
using ModernKeePass.Application.Parameters.Commands.SetKeyDerivation;
using ModernKeePass.Application.Parameters.Commands.SetRecycleBin;
using ModernKeePass.Application.Parameters.Models;
using ModernKeePass.Application.Parameters.Queries.GetCiphers;
using ModernKeePass.Application.Parameters.Queries.GetCompressions;
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels
{
@@ -37,14 +37,14 @@ namespace ModernKeePass.ViewModels
public bool IsNewRecycleBin
{
get { return _database.RecycleBinId == null; }
get { return _database.RecycleBin == null; }
set
{
if (value) _mediator.Send(new SetRecycleBinCommand() { RecycleBinId = null }).GetAwaiter().GetResult();
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBin = null }).GetAwaiter().GetResult();
}
}
public ObservableCollection<GroupVm> Groups { get; set; }
public ObservableCollection<Application.Group.Models.GroupVm> Groups { get; set; }
public IEnumerable<CipherVm> Ciphers => _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
public IEnumerable<string> Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
@@ -119,7 +119,7 @@ namespace ModernKeePass.ViewModels
{
_mediator = mediator;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
//Groups = _database.RootGroup.SubGroups;
Groups = new ObservableCollection<Application.Group.Models.GroupVm>(_database.RootGroup.SubGroups);
}
}
}

View File

@@ -6,6 +6,7 @@ using Windows.UI.Xaml.Controls;
using MediatR;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePass.Views;

View File

@@ -1,21 +1,20 @@
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml.Controls;
using MediatR;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
using ModernKeePass.Application.Group.Commands.CreateEntry;
using ModernKeePass.Application.Group.Commands.CreateGroup;
using ModernKeePass.Converters;
using ModernKeePass.Domain.Enums;
using ModernKeePass.ImportFormats;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
namespace ModernKeePass.ViewModels
{
public class NewVm : OpenVm
{
private readonly IMediator _mediator;
private readonly ISettingsService _settings;
private string _importFormatHelp;
public string Password { get; set; }
@@ -37,18 +36,19 @@ namespace ModernKeePass.ViewModels
}
}
public NewVm(): this(App.Mediator) { }
public NewVm(): this(App.Mediator, new SettingsService()) { }
public NewVm(IMediator mediator)
public NewVm(IMediator mediator, ISettingsService settings)
{
_mediator = mediator;
_settings = settings;
}
public async Task PopulateInitialData(ISettingsService settings, IImportService<IFormat> importService)
public async Task<Application.Group.Models.GroupVm> PopulateInitialData()
{
var database = await _mediator.Send(new GetDatabaseQuery());
if (settings.GetSetting<bool>("Sample") && !IsImportChecked) await CreateSampleData(database.RootGroup);
else if (IsImportChecked && ImportFile != null && ! (ImportFormat is NullImportFormat)) importService.Import(ImportFormat, ImportFile, database.RootGroup);
if (_settings.GetSetting<bool>("Sample") && !IsImportChecked) await CreateSampleData(database.RootGroup);
return database.RootGroup;
}
private async Task CreateSampleData(Application.Group.Models.GroupVm group)

View File

@@ -7,29 +7,32 @@ namespace ModernKeePass.ViewModels
{
public class OpenVm: NotifyPropertyChangedBase
{
private readonly IRecentService _recent;
public bool IsFileSelected => DatabaseFile != null;
public string Name => DatabaseFile?.DisplayName;
public StorageFile DatabaseFile { get; private set; }
internal void OpenFile(StorageFile file)
public OpenVm(): this(new RecentService()) { }
public OpenVm(IRecentService recent)
{
OpenFile(file, RecentService.Instance);
_recent = recent;
}
public void OpenFile(StorageFile file, IRecentService recent)
public void OpenFile(StorageFile file)
{
DatabaseFile = file;
OnPropertyChanged("Name");
OnPropertyChanged("IsFileSelected");
OnPropertyChanged("DatabaseFile");
AddToRecentList(file, recent);
AddToRecentList(file);
}
private void AddToRecentList(StorageFile file, IRecentService recent)
private void AddToRecentList(StorageFile file)
{
recent.Add(file, file.DisplayName);
_recent.Add(file, file.DisplayName);
}
}
}

View File

@@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using System.Windows.Input;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;

View File

@@ -4,6 +4,7 @@ using Windows.UI.Xaml.Controls;
using MediatR;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
using ModernKeePass.Views;
using ModernKeePass.Services;

View File

@@ -4,6 +4,7 @@ using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Navigation;
using ModernKeePass.Common;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
namespace ModernKeePass.Views.BasePages

View File

@@ -18,9 +18,8 @@
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />
<converters:ProgressBarLegalValuesConverter x:Key="ProgressBarLegalValuesConverter" />
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToForegroungBrushComplexityConverter" />
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToForegroundBrushComplexityConverter" />
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter" />
<converters:IntToSymbolConverter x:Key="IntToSymbolConverter" />
<Style TargetType="PasswordBox" x:Name="PasswordBoxWithButtonStyle">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
@@ -429,7 +428,7 @@
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</local:TextBoxWithButton>
<ProgressBar Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}}" Maximum="128" Width="350" HorizontalAlignment="Left" Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToForegroungBrushComplexityConverter}}" />
<ProgressBar Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}}" Maximum="128" Width="350" HorizontalAlignment="Left" Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToForegroundBrushComplexityConverter}}" />
<CheckBox x:Uid="EntryShowPassword" HorizontalAlignment="Left" Margin="-3,0,0,0" IsChecked="{Binding IsRevealPassword, Mode=TwoWay}" IsEnabled="{Binding IsRevealPasswordEnabled}" />
<TextBlock TextWrapping="Wrap" Text="URL" FontSize="18"/>
<local:TextBoxWithButton x:Uid="UrlTextBox" Text="{Binding Url, Mode=TwoWay}" MaxLength="256" Style="{StaticResource EntryTextBoxWithButtonStyle}" ButtonSymbol="&#xE111;" IsEnabled="{Binding IsSelected}">
@@ -498,10 +497,10 @@
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Viewbox MaxHeight="30" Width="50" Grid.Column="0" Grid.Row="0" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}">
<userControls:SymbolPickerUserControl Width="80" Height="40" SelectedSymbol="{Binding Icon, Converter={StaticResource IntToSymbolConverter}, ConverterParameter=0, Mode=TwoWay}" />
<userControls:SymbolPickerUserControl Width="80" Height="40" SelectedSymbol="{Binding Icon, Mode=TwoWay}" />
</Viewbox>
<Viewbox MaxHeight="30" Width="50" Grid.Column="0" Grid.Row="0" Visibility="{Binding IsEditMode, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
<SymbolIcon Symbol="{Binding Icon, Converter={StaticResource IntToSymbolConverter}}" Width="80" Height="40" />
<SymbolIcon Symbol="{Binding Icon}" Width="80" Height="40" />
</Viewbox>
<TextBox Grid.Column="1" Grid.Row="0"
Text="{Binding Title, Mode=TwoWay}"
@@ -525,7 +524,7 @@
</Grid>
<userControls:TopMenuUserControl
x:Name="TopMenu" Grid.Column="2"
RestoreButtonVisibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
RestoreButtonVisibility="{Binding CanRestore, Converter={StaticResource BooleanToVisibilityConverter}}"
DeleteButtonVisibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
IsEditButtonChecked="{Binding IsEditMode, Mode=TwoWay}"
SaveCommand="{Binding SaveCommand}"

View File

@@ -42,8 +42,10 @@ namespace ModernKeePass.Views
protected override void OnNavigatedTo(NavigationEventArgs e)
{
NavigationHelper.OnNavigatedTo(e);
if (!(e.Parameter is EntryVm)) return;
DataContext = (EntryVm)e.Parameter;
/*if (!(e.Parameter is EntryVm)) return;
DataContext = (EntryVm)e.Parameter;*/
var args = e.Parameter as Application.Entry.Models.EntryVm;
if (args != null) DataContext = new EntryVm(args);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
@@ -67,7 +69,7 @@ namespace ModernKeePass.Views
case -1:
return;
default:
var entry = listView?.SelectedItem as EntryVm;
var entry = listView?.SelectedItem as Application.Entry.Models.EntryVm;
StackPanel.DataContext = entry;
TopGrid.DataContext = entry;
break;

View File

@@ -17,8 +17,6 @@
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
<converters:IntToSymbolConverter x:Key="IntToSymbolConverter"/>
</Page.Resources>
<Page.DataContext>
<viewModels:GroupVm />
@@ -105,13 +103,13 @@
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="{Binding BackgroundColor, ConverterParameter={StaticResource MainColor}, Converter={StaticResource ColorToBrushConverter}}">
<Viewbox MaxHeight="50" Width="100">
<SymbolIcon Symbol="{Binding Icon, Converter={StaticResource IntToSymbolConverter}, ConverterParameter=0}" Foreground="{StaticResource TextColor}" />
<SymbolIcon Symbol="{Binding Icon}" Foreground="{StaticResource TextColor}" />
</Viewbox>
</Border>
<StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,10,0,0" >
<TextBlock x:Name="NameTextBlock" Text="{Binding Title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" Foreground="{Binding ForegroundColor, ConverterParameter={StaticResource TextBoxForegroundThemeBrush}, Converter={StaticResource ColorToBrushConverter}}"/>
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="NoWrap" />
<TextBlock Text="{Binding UserName}" Style="{StaticResource BodyTextBlockStyle}" Foreground="{Binding ForegroundColor, ConverterParameter={StaticResource TextBoxForegroundThemeBrush}, Converter={StaticResource ColorToBrushConverter}}" MaxHeight="60" />
<TextBlock Text="{Binding Username}" Style="{StaticResource BodyTextBlockStyle}" Foreground="{Binding ForegroundColor, ConverterParameter={StaticResource TextBoxForegroundThemeBrush}, Converter={StaticResource ColorToBrushConverter}}" MaxHeight="60" />
<TextBlock Text="{Binding Url}" Style="{StaticResource BodyTextBlockStyle}" Foreground="{Binding ForegroundColor, ConverterParameter={StaticResource TextBoxForegroundThemeBrush}, Converter={StaticResource ColorToBrushConverter}}" MaxHeight="60" />
</StackPanel>
<Button Grid.Column="2" Style="{StaticResource NoBorderButtonStyle}" Background="{StaticResource AppBarBackgroundThemeBrush}" VerticalAlignment="Bottom">
@@ -121,7 +119,7 @@
<MenuFlyoutItem x:Uid="EntryItemCopyLogin">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<actions:ClipboardAction Text="{Binding UserName}" />
<actions:ClipboardAction Text="{Binding Username}" />
<actions:ToastAction x:Uid="ToastCopyLogin" Title="{Binding Title}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
@@ -207,10 +205,10 @@
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<Viewbox MaxHeight="30" Width="50" Grid.Column="0" Grid.Row="0" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}">
<userControls:SymbolPickerUserControl Width="80" Height="40" SelectedSymbol="{Binding Icon, Converter={StaticResource IntToSymbolConverter}, ConverterParameter=48, Mode=TwoWay}" />
<userControls:SymbolPickerUserControl Width="80" Height="40" SelectedSymbol="{Binding Icon, Mode=TwoWay}" />
</Viewbox>
<Viewbox MaxHeight="30" Width="50" Grid.Column="0" Grid.Row="0" Visibility="{Binding IsEditMode, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
<SymbolIcon Symbol="{Binding Icon, Converter={StaticResource IntToSymbolConverter}}" Width="80" Height="40" />
<SymbolIcon Symbol="{Binding Icon}" Width="80" Height="40" />
</Viewbox>
<TextBox Grid.Column="1" Grid.Row="0"
x:Name="TitleTextBox"

View File

@@ -8,6 +8,7 @@ using Windows.UI.Xaml.Navigation;
using ModernKeePass.Common;
using ModernKeePass.Events;
using ModernKeePass.ViewModels;
using EntryVm = ModernKeePass.Application.Entry.Models.EntryVm;
// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229
@@ -49,10 +50,10 @@ namespace ModernKeePass.Views
var args = e.Parameter as PasswordEventArgs;
if (args != null)
DataContext = args.RootGroup;
DataContext = new GroupVm(args.RootGroup);
else
{
var vm = e.Parameter as GroupVm;
var vm = e.Parameter as Application.Group.Models.GroupVm;
if (vm != null)
DataContext = vm;
}
@@ -75,7 +76,7 @@ namespace ModernKeePass.Views
case -1:
return;
default:
var group = listView?.SelectedItem as GroupVm;
var group = listView?.SelectedItem as Application.Group.Models.GroupVm;
Frame.Navigate(typeof(GroupDetailPage), group);
break;
}

View File

@@ -66,8 +66,7 @@ namespace ModernKeePass.Views
private async void ImportFileButton_OnClick(object sender, RoutedEventArgs e)
{
var picker =
new FileOpenPicker
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
@@ -80,10 +79,10 @@ namespace ModernKeePass.Views
if (Model.ImportFile != null) ImportFileLink.Content = Model.ImportFile.Name;
}
private void CompositeKeyUserControl_OnValidationChecked(object sender, PasswordEventArgs e)
private async void CompositeKeyUserControl_OnValidationChecked(object sender, PasswordEventArgs e)
{
Model.PopulateInitialData(DatabaseService.Instance, new SettingsService(), new ImportService());
_mainFrame.Navigate(typeof(GroupDetailPage), DatabaseService.Instance.RootGroup);
var rootGroup = await Model.PopulateInitialData();
_mainFrame.Navigate(typeof(GroupDetailPage), rootGroup);
}
}
}

View File

@@ -33,8 +33,7 @@ namespace ModernKeePass.Views
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var picker =
new FileOpenPicker
var picker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary

View File

@@ -95,7 +95,7 @@ namespace ModernKeePass.Views.UserControls
if (UpdateKey)
{
await Model.UpdateKey();
ValidationChecked?.Invoke(this, new PasswordEventArgs(new GroupVm(Model.RootGroup, null)));
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
}
else
{
@@ -175,7 +175,7 @@ namespace ModernKeePass.Views.UserControls
ButtonLabel = resource.GetResourceValue("CompositeKeyOpening");
if (await Dispatcher.RunTaskAsync(async () => await Model.OpenDatabase(DatabaseFile, CreateNew)))
{
ValidationChecked?.Invoke(this, new PasswordEventArgs(new GroupVm(Model.RootGroup, null)));
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
}
ButtonLabel = oldLabel;

View File

@@ -10,7 +10,7 @@
xmlns:converters="using:ModernKeePass.Converters"
mc:Ignorable="d">
<UserControl.Resources>
<converters:IntToSymbolConverter x:Key="IntToSymbolConverter"/>
<converters:IconToSymbolConverter x:Key="IconToSymbolConverter"/>
</UserControl.Resources>
<ListView
ItemsSource="{Binding ItemsSource, ElementName=UserControl}"
@@ -26,7 +26,7 @@
<x:Double x:Key="HamburgerMenuSize">300</x:Double>
<DataTemplate x:Name="IsSpecial">
<StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding IconId, Converter={StaticResource IntToSymbolConverter}, ConverterParameter=48}" Margin="7,15,0,15">
<SymbolIcon Symbol="{Binding Icon, Converter={StaticResource IconToSymbolConverter}, ConverterParameter=48}" Margin="7,15,0,15">
<ToolTipService.ToolTip>
<ToolTip Content="{Binding Path={Binding DisplayMemberPath, ElementName=UserControl}}" />
</ToolTipService.ToolTip>
@@ -36,7 +36,7 @@
</DataTemplate>
<DataTemplate x:Name="IsNormal">
<StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding IconId, Converter={StaticResource IntToSymbolConverter}, ConverterParameter=48}" Margin="7,15,0,15">
<SymbolIcon Symbol="{Binding Icon, Converter={StaticResource IconToSymbolConverter}, ConverterParameter=48}" Margin="7,15,0,15">
<ToolTipService.ToolTip>
<ToolTip Content="{Binding Path={Binding DisplayMemberPath, ElementName=UserControl}}" />
</ToolTipService.ToolTip>

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Interfaces;
using ModernKeePass.Application.Common.Interfaces;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -75,18 +75,18 @@ namespace ModernKeePass.Views.UserControls
typeof(HamburgerMenuUserControl),
new PropertyMetadata(Visibility.Collapsed, (o, args) => { }));
public IEnumerable<IVmEntity> ItemsSource
public IEnumerable<IEntityVm> ItemsSource
{
get { return (IEnumerable<IVmEntity>)GetValue(ItemsSourceProperty); }
get { return (IEnumerable<IEntityVm>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register(
"ItemsSource",
typeof(IEnumerable<IVmEntity>),
typeof(IEnumerable<IEntityVm>),
typeof(HamburgerMenuUserControl),
new PropertyMetadata(new List<IVmEntity>(), (o, args) => { }));
new PropertyMetadata(new List<IEntityVm>(), (o, args) => { }));
public object SelectedItem
{

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Converters;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -28,8 +27,7 @@ namespace ModernKeePass.Views.UserControls
public SymbolPickerUserControl()
{
InitializeComponent();
var converter = new IntToSymbolConverter();
Symbols = Enum.GetValues(typeof(Symbol)).Cast<Symbol>().Where(s => (int)converter.ConvertBack(s, null, null, string.Empty) != -1);
Symbols = Enum.GetValues(typeof(Symbol)).Cast<Symbol>();
}
private void ComboBox_OnLoaded(object sender, RoutedEventArgs e)

View File

@@ -17,7 +17,7 @@
<PackageCertificateKeyFile>ModernKeePass_StoreKey.pfx</PackageCertificateKeyFile>
<PackageCertificateThumbprint>ED3AA34F46D03498F989901C5DB2742B65D72F60</PackageCertificateThumbprint>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxBundlePlatforms>neutral</AppxBundlePlatforms>
<AppxBundlePlatforms>x64</AppxBundlePlatforms>
<AppxBundle>Always</AppxBundle>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
@@ -117,16 +117,15 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\IntToSymbolConverter.cs" />
<Compile Include="Converters\IconToSymbolConverter.cs" />
<Compile Include="DependencyInjection.cs" />
<Compile Include="ImportFormats\CsvImportFormat.cs" />
<Compile Include="ImportFormats\NullImportFormat.cs" />
<Compile Include="Interfaces\IFormat.cs" />
<Compile Include="Interfaces\IImportService.cs" />
<Compile Include="Interfaces\IProxyInvocationHandler.cs" />
<Compile Include="Interfaces\IRecentService.cs" />
<Compile Include="Interfaces\IRecentItem.cs" />
<Compile Include="Interfaces\IResourceService.cs" />
<Compile Include="Services\ImportService.cs" />
<Compile Include="Services\SingletonServiceBase.cs" />
<Compile Include="TemplateSelectors\SelectableDataTemplateSelector.cs" />
<Compile Include="ViewModels\Items\SettingsSaveVm.cs" />
@@ -392,14 +391,18 @@
<Reference Include="Autofac">
<HintPath>..\..\..\..\..\.nuget\packages\Autofac\4.9.4\lib\netstandard1.1\Autofac.dll</HintPath>
</Reference>
<Reference Include="AutoMapper, Version=6.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.1.1\lib\netstandard1.1\AutoMapper.dll</HintPath>
<Reference Include="AutoMapper, Version=6.0.2.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.0.2\lib\netstandard1.1\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper.Extensions.Microsoft.DependencyInjection, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.Extensions.Microsoft.DependencyInjection.2.0.1\lib\netstandard1.1\AutoMapper.Extensions.Microsoft.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.8.5\lib\netstandard1.0\BouncyCastle.Crypto.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentValidation, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0, processorArchitecture=MSIL">
<HintPath>..\packages\FluentValidation.8.6.2\lib\netstandard1.1\FluentValidation.dll</HintPath>
<Private>True</Private>
@@ -436,6 +439,22 @@
<HintPath>..\packages\Microsoft.Toolkit.Uwp.Notifications.2.0.0\lib\dotnet\Microsoft.Toolkit.Uwp.Notifications.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ModernKeePassLib, Version=2.44.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernKeePassLib.2.44.2\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SixLabors.Core, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SixLabors.Core.1.0.0-beta0006\lib\netstandard1.1\SixLabors.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SixLabors.ImageSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SixLabors.ImageSharp.1.0.0-beta0005\lib\netstandard1.1\SixLabors.ImageSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Splat, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Splat.3.0.0\lib\netstandard1.1\Splat.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard1.1\System.Buffers.dll</HintPath>
<Private>True</Private>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="6.1.1" targetFramework="win81" />
<package id="AutoMapper" version="6.0.2" targetFramework="win81" />
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="2.0.1" targetFramework="win81" />
<package id="FluentValidation" version="8.6.2" targetFramework="win81" />
<package id="HockeySDK.Core" version="4.1.6" targetFramework="win81" />
@@ -14,7 +14,12 @@
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.1" targetFramework="win81" />
<package id="Microsoft.NETCore.UniversalWindowsPlatform" version="6.1.7" targetFramework="win81" />
<package id="Microsoft.Toolkit.Uwp.Notifications" version="2.0.0" targetFramework="win81" />
<package id="ModernKeePassLib" version="2.44.2" targetFramework="win81" />
<package id="NETStandard.Library" version="2.0.3" targetFramework="win81" />
<package id="Portable.BouncyCastle" version="1.8.5" targetFramework="win81" />
<package id="SixLabors.Core" version="1.0.0-beta0006" targetFramework="win81" />
<package id="SixLabors.ImageSharp" version="1.0.0-beta0005" targetFramework="win81" />
<package id="Splat" version="3.0.0" targetFramework="win81" />
<package id="System.Buffers" version="4.5.0" targetFramework="win81" />
<package id="System.Collections" version="4.3.0" targetFramework="win81" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="win81" />