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",