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,10 +16,11 @@ 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; }
public override string ToString()
{
return Title;
@@ -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",