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

@@ -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": {