Lots of bug corrections

WIP - still lots left
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-31 19:19:02 +02:00
parent e4bd788ed3
commit 90c592d7ee
24 changed files with 191 additions and 215 deletions

View File

@@ -39,7 +39,6 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationModule.cs" />
<Compile Include="Common\Interfaces\ICryptographyClient.cs" />
<Compile Include="Common\Interfaces\IDatabaseProxy.cs" />
<Compile Include="Common\Interfaces\IEntityVm.cs" />

View File

@@ -1,32 +0,0 @@
using System.Reflection;
using Autofac;
using AutoMapper;
using MediatR;
using ModernKeePass.Application.Common.Mappings;
using Module = Autofac.Module;
namespace ModernKeePass.Application
{
public class ApplicationModule: Module
{
protected override void Load(ContainerBuilder builder)
{
// Register Automapper profiles
builder.RegisterType<MappingProfile>().As<Profile>();
// Register Mediatr
builder
.RegisterType<Mediator>()
.As<IMediator>()
.InstancePerLifetimeScope();
// request & notification handlers
builder.Register<SingleInstanceFactory>(context =>
{
var c = context.Resolve<IComponentContext>();
return t => c.Resolve(t);
});
builder.RegisterAssemblyTypes(typeof(ApplicationModule).GetTypeInfo().Assembly).AsImplementedInterfaces();
}
}
}

View File

@@ -1,4 +1,6 @@
using ModernKeePass.Domain.Enums;
using System.Collections.Generic;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.Enums;
namespace ModernKeePass.Application.Common.Interfaces
{
@@ -7,5 +9,7 @@ namespace ModernKeePass.Application.Common.Interfaces
string Id { get; set; }
string Title { get; set; }
Icon Icon { get; set; }
List<GroupVm> Breadcrumb { get; }
GroupVm ParentGroup { get; set; }
}
}

View File

@@ -1,9 +1,12 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Database.Queries.OpenDatabase
@@ -39,7 +42,29 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
KeyFilePath = request.KeyFilePath,
Password = request.Password
});
return _mapper.Map<GroupVm>(rootGroup);
return BuildHierarchy(null, rootGroup);
}
private GroupVm BuildHierarchy(GroupVm parentGroup, GroupEntity groupEntity)
{
var groupVm = _mapper.Map<GroupVm>(groupEntity);
groupVm.ParentGroup = parentGroup;
if (parentGroup != null)
{
groupVm.Breadcrumb.AddRange(parentGroup.Breadcrumb);
groupVm.Breadcrumb.Add(parentGroup);
}
groupVm.Entries = groupEntity.Entries.Select(e =>
{
var entry = _mapper.Map<EntryVm>(e);
entry.ParentGroup = groupVm;
entry.Breadcrumb.AddRange(groupVm.Breadcrumb);
entry.Breadcrumb.Add(groupVm);
return entry;
}).OrderBy(e => e.Title).ToList();
groupVm.SubGroups = groupEntity.SubGroups.Select(g => BuildHierarchy(groupVm, g)).ToList();
return groupVm;
}
}
}

View File

@@ -13,6 +13,7 @@ namespace ModernKeePass.Application.Entry.Models
public class EntryVm: IEntityVm, IMapFrom<EntryEntity>
{
public GroupVm ParentGroup { get; set; }
public List<GroupVm> Breadcrumb { get; } = new List<GroupVm>();
public string Id { get; set; }
public string Title { get; set; }
public string Username { get; set; }
@@ -24,14 +25,19 @@ namespace ModernKeePass.Application.Entry.Models
public Icon Icon { get; set; }
public Color ForegroundColor { get; set; }
public Color BackgroundColor { get; set; }
public bool HasExpirationDate { get; internal set; }
public DateTimeOffset ExpirationDate { get; internal set; }
public DateTimeOffset ModificationDate { get; internal set; }
public bool HasExpirationDate { get; set; }
public DateTimeOffset ExpirationDate { get; set; }
public DateTimeOffset ModificationDate { get; set; }
public override string ToString()
{
return ModificationDate.ToString("g");
}
public void Mapping(Profile profile)
{
profile.CreateMap<EntryEntity, EntryVm>()
.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
//.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

@@ -16,6 +16,7 @@ namespace ModernKeePass.Application.Group.Models
public string Id { get; set; }
public string Title { get; set; }
public Icon Icon { get; set; }
public List<GroupVm> Breadcrumb { get; } = new List<GroupVm>();
public List<GroupVm> SubGroups { get; set; }
public List<EntryVm> Entries { get; set; }
public bool IsSelected { get; set; }
@@ -28,12 +29,12 @@ namespace ModernKeePass.Application.Group.Models
public void Mapping(Profile profile)
{
profile.CreateMap<GroupEntity, GroupVm>()
.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
//.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.Entries, opts => opts.MapFrom(s => s.Entries.OrderBy(e => e.Name)))
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups));
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon));
//.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,10 +1,7 @@
{
"supports": {},
"dependencies": {
"Autofac": "4.9.4",
"Autofac.Extensions.DependencyInjection": "4.4.0",
"AutoMapper": "6.0.2",
"AutoMapper.Extensions.Microsoft.DependencyInjection": "2.0.1",
"AutoMapper": "5.2.0",
"FluentValidation": "8.6.2",
"MediatR": "3.0.1",
"MediatR.Extensions.Microsoft.DependencyInjection": "2.0.0",

View File

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

View File

@@ -42,7 +42,6 @@
<ItemGroup>
<Compile Include="Common\MachineDateTime.cs" />
<Compile Include="DependencyInjection.cs" />
<Compile Include="InfrastructureModule.cs" />
<Compile Include="File\CsvImportFormat.cs" />
<Compile Include="KeePass\EntryFieldMapper.cs" />
<Compile Include="KeePass\EntryMappingProfile.cs" />

View File

@@ -1,25 +0,0 @@
using Autofac;
using AutoMapper;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Infrastructure.KeePass;
using ModernKeePass.Infrastructure.UWP;
namespace ModernKeePass.Infrastructure
{
public class InfrastructureModule: Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<KeePassDatabaseClient>().As<IDatabaseProxy>().SingleInstance();
builder.RegisterType<KeePassPasswordClient>().As<IPasswordProxy>().SingleInstance();
builder.RegisterType<KeePassCryptographyClient>().As<ICryptographyClient>();
builder.RegisterType<UwpSettingsClient>().As<ISettingsProxy>();
builder.RegisterType<UwpResourceClient>().As<IResourceProxy>();
builder.RegisterType<UwpRecentFilesClient>().As<IRecentProxy>();
builder.RegisterType<StorageFileClient>().As<IFileProxy>();
// Register Automapper profiles
builder.RegisterType<EntryMappingProfile>().As<Profile>();
}
}
}

View File

@@ -19,7 +19,7 @@ namespace ModernKeePass.Infrastructure.KeePass
{
Uri url;
CreateMap<PwEntry, EntryEntity>()
//.ForMember(dest => dest.Parent, opt => opt.MapFrom(src => src.ParentGroup))
.ForMember(dest => dest.ParentId, opt => opt.MapFrom(src => src.ParentGroup.Uuid.ToHexString()))
.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)))
@@ -38,7 +38,6 @@ 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,14 +15,13 @@ namespace ModernKeePass.Infrastructure.KeePass
private void FromDtoToModel()
{
CreateMap<PwGroup, GroupEntity>()
//.ForMember(d => d.Parent, opts => opts.MapFrom(s => s.ParentGroup))
.ForMember(d => d.ParentId, opts => opts.MapFrom(s => s.ParentGroup.Uuid.ToHexString()))
.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);
.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));
}
private void FromModelToDto()

View File

@@ -95,7 +95,7 @@ namespace ModernKeePass.Infrastructure.KeePass
_credentials = credentials;
_fileAccessToken = fileInfo.Path;
RootGroup = _mapper.Map<GroupEntity>(_pwDatabase.RootGroup);
RootGroup = BuildHierarchy(null, _pwDatabase.RootGroup);
return RootGroup;
}
catch (InvalidCompositeKeyException ex)
@@ -125,7 +125,7 @@ namespace ModernKeePass.Infrastructure.KeePass
_fileAccessToken = fileInfo.Path;
RootGroup = _mapper.Map<GroupEntity>(_pwDatabase.RootGroup);
RootGroup = BuildHierarchy(null, _pwDatabase.RootGroup);
return RootGroup;
}
@@ -337,6 +337,28 @@ namespace ModernKeePass.Infrastructure.KeePass
var fileContents = await _fileService.OpenBinaryFile(fileInfo.Path);
return IOConnectionInfo.FromByteArray(fileContents);
}
private GroupEntity BuildHierarchy(GroupEntity parentGroup, PwGroup pwGroup)
{
var group = _mapper.Map<GroupEntity>(pwGroup);
group.Parent = parentGroup;
group.Entries = pwGroup.Entries.Select(e =>
{
var entry = _mapper.Map<EntryEntity>(e);
entry.Parent = group;
return entry;
}).ToList();
group.SubGroups = pwGroup.Groups.Select(g => BuildHierarchy(group, g)).ToList();
/*var group = new GroupEntity
{
Id = pwGroup.Uuid.ToHexString(),
Name = pwGroup.Name,
Icon = IconMapper.MapPwIconToIcon(pwGroup.IconId),
Entries = pwGroup.Entries.Select(e => _mapper.Map<EntryEntity>(e)).ToList(),
SubGroups = pwGroup.Groups.Select(BuildHierarchy).ToList()
};*/
return group;
}
private PwUuid BuildIdFromString(string id)
{

View File

@@ -1,8 +1,7 @@
{
"supports": {},
"dependencies": {
"AutoMapper": "6.0.2",
"AutoMapper.Extensions.Microsoft.DependencyInjection": "2.0.1",
"AutoMapper": "5.2.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"ModernKeePassLib": "2.44.2",
"NETStandard.Library": "2.0.3"

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Services;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Interfaces;
@@ -27,7 +26,7 @@ namespace ModernKeePass.KeePassDatabaseTests
[SetUp]
public void SetUp()
{
var settingsService = Substitute.For<ISettingsService>();
var dateTime = Substitute.For<IDateTime>();
var fileProxy = Substitute.For<IFileProxy>();
fileProxy.OpenBinaryFile(Arg.Any<string>()).Returns(async parameters =>
{
@@ -42,9 +41,8 @@ namespace ModernKeePass.KeePassDatabaseTests
var contents = (byte[]) parameters[1];
await stream.WriteAsync(contents, 0, contents.Length);
});
var fileService = new FileService(fileProxy);
var mapper = new Mapper(new MapperConfiguration(cfg => { cfg.AddProfile(typeof(EntryMappingProfile)); }));
_database = new KeePassDatabaseClient(settingsService, fileService, mapper);
_database = new KeePassDatabaseClient(fileProxy, mapper, dateTime);
}
[TearDown]
@@ -57,12 +55,12 @@ namespace ModernKeePass.KeePassDatabaseTests
[Test]
public async Task TestOpen()
{
var FileInfo = new FileInfo
var fileInfo = new FileInfo
{
Path = Path.Combine(Directory.GetCurrentDirectory(), "Data", "TestDatabase.kdbx")
};
var rootGroup = await _database.Open(FileInfo, _credentials);
var rootGroup = await _database.Open(fileInfo, _credentials);
Assert.That(rootGroup.Name, Is.EqualTo("TestDatabase"));
Assert.That(rootGroup.Entries.Count(), Is.EqualTo(2));
}
@@ -95,7 +93,7 @@ namespace ModernKeePass.KeePassDatabaseTests
};
await _database.Open(originalFileInfo, _credentials);
await _database.SaveDatabase(_fileInfo);
await _database.SaveDatabase(_fileInfo.Path);
_database.CloseDatabase();
Assert.DoesNotThrowAsync(async () => { await _database.Open(_fileInfo, _credentials); });
@@ -115,8 +113,8 @@ namespace ModernKeePass.KeePassDatabaseTests
var newGroup = new GroupEntity {Name = "New Group Test"};
var rootGroup = await _database.Open(originalFileInfo, _credentials);
await _database.AddEntity(rootGroup, newGroup);
await _database.SaveDatabase(_fileInfo);
await _database.AddGroup(rootGroup.Id, newGroup.Id);
await _database.SaveDatabase(_fileInfo.Path);
_database.CloseDatabase();
rootGroup = await _database.Open(_fileInfo, _credentials);
@@ -142,8 +140,8 @@ namespace ModernKeePass.KeePassDatabaseTests
};
var rootGroup = await _database.Open(originalFileInfo, _credentials);
await _database.AddEntity(rootGroup, newEntry);
await _database.SaveDatabase(_fileInfo);
await _database.AddEntry(rootGroup.Id, newEntry.Id);
await _database.SaveDatabase(_fileInfo.Path);
_database.CloseDatabase();
rootGroup = await _database.Open(_fileInfo, _credentials);

View File

@@ -16,9 +16,9 @@ using ModernKeePass.Application.Group.Commands.RemoveEntry;
using ModernKeePass.Application.Security.Commands.GeneratePassword;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Common;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
namespace ModernKeePass.ViewModels
{
@@ -38,21 +38,7 @@ namespace ModernKeePass.ViewModels
public string CustomChars { get; set; } = string.Empty;
public string Id => _entry.Id;
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;
}
}
public IEnumerable<Application.Group.Models.GroupVm> BreadCrumb => _entry.Breadcrumb;
/// <summary>
/// Determines if the Entry is current or from history
@@ -72,14 +58,21 @@ namespace ModernKeePass.ViewModels
public string Title
{
get { return _entry.Title; }
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Title), FieldValue = value}); }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Title), FieldValue = value}).Wait();
_entry.Title = value;
}
}
public string UserName
{
get { return _entry.Username; }
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(UserName), FieldValue = value }); }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(UserName), FieldValue = value }).Wait();
_entry.Username = value;
}
}
public string Password
@@ -87,7 +80,8 @@ namespace ModernKeePass.ViewModels
get { return _entry.Password; }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Password), FieldValue = value });
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Password), FieldValue = value }).Wait();
_entry.Password = value;
OnPropertyChanged();
OnPropertyChanged(nameof(PasswordComplexityIndicator));
}
@@ -95,14 +89,22 @@ namespace ModernKeePass.ViewModels
public string Url
{
get { return _entry.Url.ToString();}
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Url), FieldValue = value }); }
get { return _entry.Url?.ToString(); }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Url), FieldValue = value }).Wait();
_entry.Url = new Uri(value);
}
}
public string Notes
{
get { return _entry.Notes; }
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Notes), FieldValue = value }); }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Notes), FieldValue = value }).Wait();
_entry.Notes = value;
}
}
public Symbol Icon
@@ -112,7 +114,11 @@ namespace ModernKeePass.ViewModels
if (HasExpired) return Symbol.ReportHacked;
return (Symbol) _entry.Icon;
}
set { _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Icon), FieldValue = value }); }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(Icon), FieldValue = value }).Wait();
_entry.Icon = (Icon)value;
}
}
public DateTimeOffset ExpiryDate
@@ -121,7 +127,8 @@ namespace ModernKeePass.ViewModels
set
{
if (!HasExpirationDate) return;
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = "ExpirationDate", FieldValue = value.Date });
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = "ExpirationDate", FieldValue = value.Date }).Wait();
_entry.ExpirationDate = value.Date;
}
}
@@ -131,10 +138,49 @@ namespace ModernKeePass.ViewModels
set
{
if (!HasExpirationDate) return;
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = "ExpirationDate", FieldValue = ExpiryDate.Date.Add(value) });
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = "ExpirationDate", FieldValue = ExpiryDate.Date.Add(value) }).Wait();
_entry.ExpirationDate = _entry.ExpirationDate.Date.Add(value);
}
}
public bool HasExpirationDate
{
get { return _entry.HasExpirationDate; }
set
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(HasExpirationDate), FieldValue = value }).Wait();
_entry.HasExpirationDate = value;
OnPropertyChanged();
}
}
public Color? BackgroundColor
{
get { return _entry?.BackgroundColor; }
set
{
if (value != null)
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(BackgroundColor), FieldValue = value }).Wait();
_entry.BackgroundColor = (Color)value;
}
}
}
public Color? ForegroundColor
{
get { return _entry?.ForegroundColor; }
set
{
if (value != null)
{
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(ForegroundColor), FieldValue = value }).Wait();
_entry.ForegroundColor = (Color)value;
}
}
}
public IEnumerable<Application.Entry.Models.EntryVm> History => _entry.History;
public bool IsEditMode
{
get { return IsSelected && _isEditMode; }
@@ -164,36 +210,6 @@ namespace ModernKeePass.ViewModels
OnPropertyChanged();
}
}
public bool HasExpirationDate
{
get { return _entry.HasExpirationDate; }
set
{
_mediator.Send(new SetFieldValueCommand {EntryId = Id, FieldName = nameof(HasExpirationDate), FieldValue = value});
OnPropertyChanged();
}
}
public IEnumerable<Application.Entry.Models.EntryVm> History => _entry.History;
public Color? BackgroundColor
{
get { return _entry?.BackgroundColor; }
set
{
if (value != null) _entry.BackgroundColor = (Color) value;
}
}
public Color? ForegroundColor
{
get { return _entry?.ForegroundColor; }
set
{
if (value != null) _entry.ForegroundColor = (Color)value;
}
}
public bool CanRestore => _entry.ParentGroup == _database.RecycleBin;
@@ -203,7 +219,6 @@ namespace ModernKeePass.ViewModels
private readonly Application.Entry.Models.EntryVm _entry;
private readonly IMediator _mediator;
private readonly IResourceService _resource;
private readonly DatabaseVm _database;
private bool _isEditMode;
private bool _isRevealPassword;
@@ -212,13 +227,12 @@ namespace ModernKeePass.ViewModels
public EntryVm() { }
internal EntryVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, new ResourcesService(), isNewEntry) { }
internal EntryVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, isNewEntry) { }
public EntryVm(Application.Entry.Models.EntryVm entry, IMediator mediator, IResourceService resource, bool isNewEntry = false)
public EntryVm(Application.Entry.Models.EntryVm entry, IMediator mediator, bool isNewEntry = false)
{
_entry = entry;
_mediator = mediator;
_resource = resource;
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
_isEditMode = isNewEntry;
if (isNewEntry) GeneratePassword().GetAwaiter().GetResult();
@@ -246,7 +260,6 @@ namespace ModernKeePass.ViewModels
OnPropertyChanged(nameof(IsRevealPasswordEnabled));
}
public async Task MarkForDelete(string recycleBinTitle)
{
if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
@@ -274,12 +287,5 @@ namespace ModernKeePass.ViewModels
{
return _entry;
}
public override string ToString()
{
return IsSelected ?
_resource.GetResourceValue("EntryCurrent") :
_entry.ModificationDate.ToString("g");
}
}
}

View File

@@ -103,21 +103,7 @@ namespace ModernKeePass.ViewModels
set { SetProperty(ref _isMenuClosed, value); }
}
public IEnumerable<Application.Group.Models.GroupVm> BreadCrumb
{
get
{
var groups = new Stack<Application.Group.Models.GroupVm>();
var group = _group;
while (group.ParentGroup != null)
{
group = group.ParentGroup;
groups.Push(group);
}
return groups;
}
}
public IEnumerable<Application.Group.Models.GroupVm> BreadCrumb => _group.Breadcrumb;
public ICommand SaveCommand { get; }
public ICommand SortEntriesCommand { get; }
@@ -210,11 +196,6 @@ namespace ModernKeePass.ViewModels
await _mediator.Send(new DeleteGroupCommand { Group = _group });
}
public override string ToString()
{
return Title;
}
private async Task SortEntriesAsync()
{
await _mediator.Send(new SortEntriesCommand {Group = _group});

View File

@@ -30,7 +30,7 @@ namespace ModernKeePass.ViewModels
get { return _database.IsRecycleBinEnabled; }
set
{
_mediator.Send(new SetHasRecycleBinCommand {HasRecycleBin = value}).GetAwaiter().GetResult();
_mediator.Send(new SetHasRecycleBinCommand {HasRecycleBin = value}).Wait();
OnPropertyChanged(nameof(HasRecycleBin));
}
}
@@ -40,7 +40,7 @@ namespace ModernKeePass.ViewModels
get { return _database.RecycleBin == null; }
set
{
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBin = null }).GetAwaiter().GetResult();
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBin = null }).Wait();
}
}
@@ -53,19 +53,19 @@ namespace ModernKeePass.ViewModels
public CipherVm SelectedCipher
{
get { return Ciphers.FirstOrDefault(c => c.Id == _database.CipherId); }
set { _mediator.Send(new SetCipherCommand {CipherId = value.Id}).GetAwaiter().GetResult(); }
set { _mediator.Send(new SetCipherCommand {CipherId = value.Id}).Wait(); }
}
public string SelectedCompression
{
get { return Compressions.FirstOrDefault(c => c == _database.Compression); }
set { _mediator.Send(new SetCompressionCommand {Compression = value}).GetAwaiter().GetResult(); }
set { _mediator.Send(new SetCompressionCommand {Compression = value}).Wait(); }
}
public KeyDerivationVm SelectedKeyDerivation
{
get { return KeyDerivations.FirstOrDefault(c => c.Id == _database.KeyDerivationId); }
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).GetAwaiter().GetResult(); }
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).Wait(); }
}
/*public int CipherIndex

View File

@@ -55,7 +55,7 @@ namespace ModernKeePass.Views
{
var vm = e.Parameter as Application.Group.Models.GroupVm;
if (vm != null)
DataContext = vm;
DataContext = new GroupVm(vm);
}
}
@@ -103,13 +103,13 @@ namespace ModernKeePass.Views
e.DestinationItem.Item = e.SourceItem.Item;
}
}
private void CreateEntry_ButtonClick(object sender, RoutedEventArgs e)
private async void CreateEntry_ButtonClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(EntryDetailPage), Model.AddNewEntry());
Frame.Navigate(typeof(EntryDetailPage), await Model.AddNewEntry());
}
private void CreateGroup_ButtonClick(object sender, RoutedEventArgs e)
private async void CreateGroup_ButtonClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(GroupDetailPage), Model.AddNewGroup());
Frame.Navigate(typeof(GroupDetailPage), await Model.AddNewGroup());
}
private void GridView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)

View File

@@ -28,9 +28,9 @@ namespace ModernKeePass.Views
_mainFrame = e.Parameter as Frame;
}
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
private async void SaveButton_OnClick(object sender, RoutedEventArgs e)
{
Model.Save();
await Model.Save();
_mainFrame.Navigate(typeof(MainPage));
}
@@ -45,7 +45,7 @@ namespace ModernKeePass.Views
var file = await savePicker.PickSaveFileAsync();
if (file == null) return;
Model.Save(file);
await Model.Save(file);
_mainFrame.Navigate(typeof(MainPage));
}

View File

@@ -16,7 +16,7 @@
</ItemsControl.ItemsPanel>
<ItemsControl.Resources>
<DataTemplate x:Name="FirstItemTemplate">
<HyperlinkButton Foreground="{StaticResource MainColor}" Content="{Binding Name}" Style="{StaticResource MainColorHyperlinkButton}" FontWeight="Light" FontSize="12" Padding="0">
<HyperlinkButton Foreground="{StaticResource MainColor}" Content="{Binding Title}" Style="{StaticResource MainColorHyperlinkButton}" FontWeight="Light" FontSize="12" Padding="0">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:NavigateToPageAction Parameter="{Binding}" TargetPage="ModernKeePass.Views.GroupDetailPage" />
@@ -29,7 +29,7 @@
<Viewbox MaxHeight="10" Margin="0,2,0,0">
<SymbolIcon Symbol="Forward" />
</Viewbox>
<HyperlinkButton Foreground="{StaticResource MainColor}" Content="{Binding Name}" Style="{StaticResource MainColorHyperlinkButton}" FontWeight="Light" FontSize="12" Padding="0">
<HyperlinkButton Foreground="{StaticResource MainColor}" Content="{Binding Title}" Style="{StaticResource MainColorHyperlinkButton}" FontWeight="Light" FontSize="12" Padding="0">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:NavigateToPageAction Parameter="{Binding}" TargetPage="ModernKeePass.Views.GroupDetailPage" />

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
using Windows.UI.Xaml;
using ModernKeePass.Interfaces;
using ModernKeePass.Application.Common.Interfaces;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -13,17 +13,17 @@ namespace ModernKeePass.Views.UserControls
InitializeComponent();
}
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(BreadCrumbUserControl),
new PropertyMetadata(new Stack<IVmEntity>(), (o, args) => { }));
new PropertyMetadata(new Stack<IEntityVm>(), (o, args) => { }));
}
}

View File

@@ -388,15 +388,12 @@
</Page>
</ItemGroup>
<ItemGroup>
<Reference Include="Autofac">
<HintPath>..\..\..\..\..\.nuget\packages\Autofac\4.9.4\lib\netstandard1.1\Autofac.dll</HintPath>
</Reference>
<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>
<Reference Include="AutoMapper, Version=5.2.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.5.2.0\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>
<Reference Include="AutoMapper.Extensions.Microsoft.DependencyInjection, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.Extensions.Microsoft.DependencyInjection.1.2.0\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">

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="6.0.2" targetFramework="win81" />
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="2.0.1" targetFramework="win81" />
<package id="AutoMapper" version="5.2.0" targetFramework="win81" />
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="1.2.0" targetFramework="win81" />
<package id="FluentValidation" version="8.6.2" targetFramework="win81" />
<package id="HockeySDK.Core" version="4.1.6" targetFramework="win81" />
<package id="HockeySDK.WINRT" version="4.1.6" targetFramework="win81" />