mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
WIP Clean Architecture
Windows 8.1 App Uses keepasslib v2.44 (temporarily)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface ICryptographyClient
|
||||
{
|
||||
IEnumerable<BaseEntity> Ciphers { get; }
|
||||
IEnumerable<BaseEntity> KeyDerivations { get; }
|
||||
IEnumerable<string> CompressionAlgorithms { get; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IDatabaseProxy
|
||||
{
|
||||
bool IsOpen { get; }
|
||||
GroupEntity RecycleBin { get; set; }
|
||||
BaseEntity Cipher { get; set; }
|
||||
BaseEntity KeyDerivation { get; set; }
|
||||
string Compression { get; set; }
|
||||
|
||||
Task<DatabaseEntity> Open(FileInfo fileInfo, Credentials credentials);
|
||||
Task<DatabaseEntity> Create(FileInfo fileInfo, Credentials credentials);
|
||||
Task SaveDatabase();
|
||||
Task SaveDatabase(FileInfo FileInfo);
|
||||
Task UpdateCredentials(Credentials credentials);
|
||||
void CloseDatabase();
|
||||
Task AddEntry(GroupEntity parentGroup, EntryEntity entity);
|
||||
Task AddGroup(GroupEntity parentGroup, GroupEntity entity);
|
||||
Task UpdateEntry(EntryEntity entity);
|
||||
Task UpdateGroup(GroupEntity entity);
|
||||
Task DeleteEntry(EntryEntity entity);
|
||||
Task DeleteGroup(GroupEntity entity);
|
||||
}
|
||||
}
|
13
ModernKeePass.Application.12/Common/Interfaces/IFileProxy.cs
Normal file
13
ModernKeePass.Application.12/Common/Interfaces/IFileProxy.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IFileProxy
|
||||
{
|
||||
Task<byte[]> OpenBinaryFile(string path);
|
||||
Task<IList<string>> OpenTextFile(string path);
|
||||
Task WriteBinaryContentsToFile(string path, byte[] contents);
|
||||
void ReleaseFile(string path);
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IHasSelectableObject
|
||||
{
|
||||
ISelectableModel SelectedItem { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IImportFormat
|
||||
{
|
||||
Task<List<Dictionary<string, string>>> Import(string path);
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IIsEnabled
|
||||
{
|
||||
bool IsEnabled { get; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IPasswordProxy
|
||||
{
|
||||
string GeneratePassword(PasswordGenerationOptions options);
|
||||
uint EstimatePasswordComplexity(string password);
|
||||
byte[] GenerateKeyFile(byte[] additionalEntropy);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IProxyInvocationHandler
|
||||
{
|
||||
object Invoke(object proxy, MethodInfo method, object[] parameters);
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IRecentProxy
|
||||
{
|
||||
int EntryCount { get; }
|
||||
Task<FileInfo> Get(string token);
|
||||
Task<IEnumerable<FileInfo>> GetAll();
|
||||
Task Add(FileInfo recentItem);
|
||||
void ClearAll();
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface IResourceProxy
|
||||
{
|
||||
string GetResourceValue(string key);
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface ISelectableModel
|
||||
{
|
||||
bool IsSelected { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
namespace ModernKeePass.Application.Common.Interfaces
|
||||
{
|
||||
public interface ISettingsProxy
|
||||
{
|
||||
T GetSetting<T>(string property, T defaultValue = default);
|
||||
void PutSetting<T>(string property, T value);
|
||||
}
|
||||
}
|
10
ModernKeePass.Application.12/Common/Mappings/IMapFrom.cs
Normal file
10
ModernKeePass.Application.12/Common/Mappings/IMapFrom.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Mappings
|
||||
{
|
||||
|
||||
public interface IMapFrom<T>
|
||||
{
|
||||
void Mapping(Profile profile);
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AutoMapper;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Mappings
|
||||
{
|
||||
public class MappingProfile : Profile
|
||||
{
|
||||
public MappingProfile()
|
||||
{
|
||||
ApplyMappingsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
private void ApplyMappingsFromAssembly(Assembly assembly)
|
||||
{
|
||||
var types = assembly.GetExportedTypes()
|
||||
.Where(t => t.GetInterfaces().Any(i =>
|
||||
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>)))
|
||||
.ToList();
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var instance = Activator.CreateInstance(type);
|
||||
var methodInfo = type.GetMethod("Mapping");
|
||||
methodInfo?.Invoke(instance, new object[] { this });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
|
||||
namespace ModernKeePass.Application.Common.Mappings
|
||||
{
|
||||
public class MappingProfiles: Profile
|
||||
{
|
||||
public void ApplyMappings()
|
||||
{
|
||||
new DatabaseVm().Mapping(this);
|
||||
new EntryVm().Mapping(this);
|
||||
new GroupVm().Mapping(this);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Queries.IsDatabaseOpen;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Commands.CloseDatabase
|
||||
{
|
||||
public class CloseDatabaseCommand: IRequest
|
||||
{
|
||||
public class CloseDatabaseCommandHandler : IRequestHandler<CloseDatabaseCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public CloseDatabaseCommandHandler(IDatabaseProxy database, IMediator mediator)
|
||||
{
|
||||
_database = database;
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task Handle(CloseDatabaseCommand message, CancellationToken cancellationToken)
|
||||
{
|
||||
var isDatabaseOpen = await _mediator.Send(new IsDatabaseOpenQuery(), cancellationToken);
|
||||
if (isDatabaseOpen) _database.CloseDatabase();
|
||||
else throw new DatabaseClosedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
using MediatR;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.IsDatabaseOpen;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
{
|
||||
public class CreateDatabaseCommand : IRequest<DatabaseVm>
|
||||
{
|
||||
public FileInfo FileInfo { get; set; }
|
||||
public Credentials Credentials { get; set; }
|
||||
|
||||
public class CreateDatabaseCommandHandler : IRequestHandler<CreateDatabaseCommand, DatabaseVm>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CreateDatabaseCommandHandler(IDatabaseProxy database, IMediator mediator, IMapper mapper)
|
||||
{
|
||||
_database = database;
|
||||
_mediator = mediator;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<DatabaseVm> Handle(CreateDatabaseCommand message, CancellationToken cancellationToken)
|
||||
{
|
||||
var isDatabaseOpen = await _mediator.Send(new IsDatabaseOpenQuery(), cancellationToken);
|
||||
if (isDatabaseOpen) throw new DatabaseOpenException();
|
||||
|
||||
var database = await _database.Create(message.FileInfo, message.Credentials);
|
||||
var databaseVm = new DatabaseVm
|
||||
{
|
||||
IsOpen = true,
|
||||
Name = database.Name,
|
||||
RootGroup = _mapper.Map<GroupVm>(database.RootGroupEntity)
|
||||
};
|
||||
return databaseVm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using MediatR;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Queries.IsDatabaseOpen;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Commands.SaveDatabase
|
||||
{
|
||||
public class SaveDatabaseCommand : IRequest
|
||||
{
|
||||
public class SaveDatabaseCommandHandler : IRequestHandler<SaveDatabaseCommand>
|
||||
{
|
||||
private readonly IDatabaseProxy _database;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public SaveDatabaseCommandHandler(IDatabaseProxy database, IMediator mediator)
|
||||
{
|
||||
_database = database;
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task Handle(SaveDatabaseCommand message, CancellationToken cancellationToken)
|
||||
{
|
||||
var isDatabaseOpen = await _mediator.Send(new IsDatabaseOpenQuery(), cancellationToken);
|
||||
if (isDatabaseOpen) await _database.SaveDatabase();
|
||||
else throw new DatabaseClosedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
ModernKeePass.Application.12/Database/Models/DatabaseVm.cs
Normal file
21
ModernKeePass.Application.12/Database/Models/DatabaseVm.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Models
|
||||
{
|
||||
public class DatabaseVm: IMapFrom<DatabaseEntity>
|
||||
{
|
||||
public bool IsOpen { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupVm RootGroup { get; set; }
|
||||
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<DatabaseEntity, DatabaseVm>()
|
||||
.ForMember(d => d.Name, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.RootGroup, opts => opts.MapFrom(s => s.RootGroupEntity));
|
||||
}
|
||||
}
|
||||
}
|
7
ModernKeePass.Application.12/Database/Models/MainVm.cs
Normal file
7
ModernKeePass.Application.12/Database/Models/MainVm.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Application.Database.Models
|
||||
{
|
||||
public class MainVm
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.IsDatabaseOpen
|
||||
{
|
||||
public class IsDatabaseOpenQuery: IRequest<bool>
|
||||
{
|
||||
public class IsDatabaseOpenQueryHandler: IRequestHandler<IsDatabaseOpenQuery, bool>
|
||||
{
|
||||
private readonly IDatabaseProxy _databaseProxy;
|
||||
|
||||
public IsDatabaseOpenQueryHandler(IDatabaseProxy databaseProxy)
|
||||
{
|
||||
_databaseProxy = databaseProxy;
|
||||
}
|
||||
public Task<bool> Handle(IsDatabaseOpenQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(_databaseProxy.IsOpen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
using ModernKeePass.Application.Database.Queries.IsDatabaseOpen;
|
||||
using ModernKeePass.Application.Group.Models;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Exceptions;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
{
|
||||
public class OpenDatabaseQuery: IRequest<DatabaseVm>
|
||||
{
|
||||
public FileInfo FileInfo { get; set; }
|
||||
public Credentials Credentials { get; set; }
|
||||
|
||||
public class OpenDatabaseQueryHandler : IRequestHandler<OpenDatabaseQuery, DatabaseVm>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IDatabaseProxy _databaseProxy;
|
||||
|
||||
public OpenDatabaseQueryHandler(IMapper mapper, IMediator mediator, IDatabaseProxy databaseProxy)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_mediator = mediator;
|
||||
_databaseProxy = databaseProxy;
|
||||
}
|
||||
|
||||
public async Task<DatabaseVm> Handle(OpenDatabaseQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var isDatabaseOpen = await _mediator.Send(new IsDatabaseOpenQuery(), cancellationToken);
|
||||
if (isDatabaseOpen) throw new DatabaseOpenException();
|
||||
|
||||
var database = await _databaseProxy.Open(request.FileInfo, request.Credentials);
|
||||
var databaseVm = new DatabaseVm
|
||||
{
|
||||
IsOpen = true,
|
||||
Name = database.Name,
|
||||
RootGroup = _mapper.Map<GroupVm>(database.RootGroupEntity)
|
||||
};
|
||||
return databaseVm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
{
|
||||
public class OpenDatabaseQueryValidator : AbstractValidator<OpenDatabaseQuery>
|
||||
{
|
||||
public OpenDatabaseQueryValidator()
|
||||
{
|
||||
RuleFor(v => v.Credentials != null && v.FileInfo != null);
|
||||
}
|
||||
}
|
||||
}
|
13
ModernKeePass.Application.12/DependencyInjection.cs
Normal file
13
ModernKeePass.Application.12/DependencyInjection.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ModernKeePass.Application
|
||||
{
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddApplication(this IServiceCollection services)
|
||||
{
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
27
ModernKeePass.Application.12/Entry/Models/EntryVm.cs
Normal file
27
ModernKeePass.Application.12/Entry/Models/EntryVm.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Drawing;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Application.Entry.Models
|
||||
{
|
||||
public class EntryVm: IMapFrom<EntryEntity>
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public Color ForegroundColor { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<EntryEntity, EntryVm>()
|
||||
.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.ForegroundColor, opts => opts.MapFrom(s => s.ForegroundColor))
|
||||
.ForMember(d => d.BackgroundColor, opts => opts.MapFrom(s => s.BackgroundColor));
|
||||
}
|
||||
}
|
||||
}
|
33
ModernKeePass.Application.12/Group/Models/GroupVm.cs
Normal file
33
ModernKeePass.Application.12/Group/Models/GroupVm.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Mappings;
|
||||
using ModernKeePass.Application.Entry.Models;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Application.Group.Models
|
||||
{
|
||||
public class GroupVm: IMapFrom<GroupEntity>
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public Color ForegroundColor { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
public List<GroupVm> SubGroups { get; set; } = new List<GroupVm>();
|
||||
public List<EntryVm> Entries { get; set; } = new List<EntryVm>();
|
||||
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<GroupEntity, GroupVm>()
|
||||
.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.ForegroundColor, opts => opts.MapFrom(s => s.ForegroundColor))
|
||||
.ForMember(d => d.BackgroundColor, opts => opts.MapFrom(s => s.BackgroundColor))
|
||||
.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries))
|
||||
.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Common\Mappings\MappingProfile.cs" />
|
||||
<Compile Remove="Services\CryptographyService.cs" />
|
||||
<Compile Remove="Services\DatabaseService.cs" />
|
||||
<Compile Remove="Services\FileService.cs" />
|
||||
<Compile Remove="Services\ImportService.cs" />
|
||||
<Compile Remove="Services\RecentService.cs" />
|
||||
<Compile Remove="Services\ResourceService.cs" />
|
||||
<Compile Remove="Services\SecurityService.cs" />
|
||||
<Compile Remove="Services\SettingsService.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Mappings\MappingProfile.cs" />
|
||||
<Content Include="Services\CryptographyService.cs" />
|
||||
<Content Include="Services\DatabaseService.cs" />
|
||||
<Content Include="Services\FileService.cs" />
|
||||
<Content Include="Services\ImportService.cs" />
|
||||
<Content Include="Services\RecentService.cs" />
|
||||
<Content Include="Services\ResourceService.cs" />
|
||||
<Content Include="Services\SecurityService.cs" />
|
||||
<Content Include="Services\SettingsService.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Entry\Commands\UpdateEntry\" />
|
||||
<Folder Include="Entry\Queries\" />
|
||||
<Folder Include="Group\Commands\CreateEntry\" />
|
||||
<Folder Include="Group\Commands\CreateGroup\" />
|
||||
<Folder Include="Group\Commands\DeleteEntry\" />
|
||||
<Folder Include="Group\Commands\DeleteGroup\" />
|
||||
<Folder Include="Group\Commands\UpdateGroup\" />
|
||||
<Folder Include="Group\Queries\" />
|
||||
<Folder Include="Import\" />
|
||||
<Folder Include="Resources\Commands\" />
|
||||
<Folder Include="Resources\Queries\" />
|
||||
<Folder Include="Settings\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="4.9.4" />
|
||||
<PackageReference Include="AutoMapper" Version="6.2.2" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="2.0.1" />
|
||||
<PackageReference Include="FluentValidation" Version="8.6.2" />
|
||||
<PackageReference Include="MediatR" Version="4.0.1" />
|
||||
<PackageReference Include="Splat" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\ModernKeePass.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
22
ModernKeePass.Application.12/Services/CryptographyService.cs
Normal file
22
ModernKeePass.Application.12/Services/CryptographyService.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class CryptographyService : ICryptographyService
|
||||
{
|
||||
private readonly ICryptographyClient _cryptographyClient;
|
||||
public IEnumerable<Entity> Ciphers => _cryptographyClient.Ciphers;
|
||||
|
||||
public IEnumerable<Entity> KeyDerivations => _cryptographyClient.KeyDerivations;
|
||||
|
||||
public IEnumerable<string> CompressionAlgorithms => _cryptographyClient.CompressionAlgorithms;
|
||||
|
||||
public CryptographyService(ICryptographyClient cryptographyClient)
|
||||
{
|
||||
_cryptographyClient = cryptographyClient;
|
||||
}
|
||||
}
|
||||
}
|
103
ModernKeePass.Application.12/Services/DatabaseService.cs
Normal file
103
ModernKeePass.Application.12/Services/DatabaseService.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class DatabaseService: IDatabaseService
|
||||
{
|
||||
private readonly IDatabaseProxy _databaseProxy;
|
||||
|
||||
public string Name { get; private set; }
|
||||
public bool IsOpen { get; private set; }
|
||||
public Domain.Entities.GroupEntity RootGroupEntity { get; private set; }
|
||||
public Domain.Entities.GroupEntity RecycleBin
|
||||
{
|
||||
get => _databaseProxy.RecycleBin;
|
||||
set => _databaseProxy.RecycleBin = value;
|
||||
}
|
||||
public Entity Cipher
|
||||
{
|
||||
get => _databaseProxy.Cipher;
|
||||
set => _databaseProxy.Cipher = value;
|
||||
}
|
||||
public Entity KeyDerivation
|
||||
{
|
||||
get => _databaseProxy.KeyDerivation;
|
||||
set => _databaseProxy.KeyDerivation = value;
|
||||
}
|
||||
public string Compression
|
||||
{
|
||||
get => _databaseProxy.Compression;
|
||||
set => _databaseProxy.Compression = value;
|
||||
}
|
||||
public bool IsRecycleBinEnabled => RecycleBin != null;
|
||||
|
||||
public DatabaseService(IDatabaseProxy databaseProxy)
|
||||
{
|
||||
_databaseProxy = databaseProxy;
|
||||
}
|
||||
|
||||
public async Task Open(FileInfo fileInfo, Credentials credentials)
|
||||
{
|
||||
RootGroupEntity = await _databaseProxy.Open(fileInfo, credentials);
|
||||
Name = RootGroupEntity?.Name;
|
||||
IsOpen = true;
|
||||
}
|
||||
|
||||
public async Task Create(FileInfo fileInfo, Credentials credentials)
|
||||
{
|
||||
RootGroupEntity = await _databaseProxy.Create(fileInfo, credentials);
|
||||
Name = RootGroupEntity?.Name;
|
||||
IsOpen = true;
|
||||
}
|
||||
|
||||
public async Task Save()
|
||||
{
|
||||
await _databaseProxy.SaveDatabase();
|
||||
}
|
||||
|
||||
public async Task SaveAs(FileInfo fileInfo)
|
||||
{
|
||||
await _databaseProxy.SaveDatabase(fileInfo);
|
||||
}
|
||||
|
||||
public Task CreateRecycleBin(Domain.Entities.GroupEntity recycleBinGroupEntity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task UpdateCredentials(Credentials credentials)
|
||||
{
|
||||
await _databaseProxy.UpdateCredentials(credentials);
|
||||
await Save();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_databaseProxy.CloseDatabase();
|
||||
IsOpen = false;
|
||||
}
|
||||
|
||||
public async Task AddEntity(GroupEntity parentEntity, Entity entity)
|
||||
{
|
||||
await _databaseProxy.AddEntity(parentEntity, entity);
|
||||
//await Save();
|
||||
}
|
||||
|
||||
public async Task UpdateEntity(Entity entity)
|
||||
{
|
||||
await _databaseProxy.UpdateEntity(entity);
|
||||
}
|
||||
|
||||
public async Task DeleteEntity(Entity entity)
|
||||
{
|
||||
if (IsRecycleBinEnabled) await AddEntity(RecycleBin, entity);
|
||||
await _databaseProxy.DeleteEntity(entity);
|
||||
//await Save();
|
||||
}
|
||||
}
|
||||
}
|
37
ModernKeePass.Application.12/Services/FileService.cs
Normal file
37
ModernKeePass.Application.12/Services/FileService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class FileService: IFileService
|
||||
{
|
||||
private readonly IFileProxy _fileProxy;
|
||||
|
||||
public FileService(IFileProxy fileProxy)
|
||||
{
|
||||
_fileProxy = fileProxy;
|
||||
}
|
||||
|
||||
public Task<byte[]> OpenBinaryFile(string path)
|
||||
{
|
||||
return _fileProxy.OpenBinaryFile(path);
|
||||
}
|
||||
|
||||
public Task WriteBinaryContentsToFile(string path, byte[] contents)
|
||||
{
|
||||
return _fileProxy.WriteBinaryContentsToFile(path, contents);
|
||||
}
|
||||
|
||||
public Task<IList<string>> OpenTextFile(string path)
|
||||
{
|
||||
return _fileProxy.OpenTextFile(path);
|
||||
}
|
||||
|
||||
public void ReleaseFile(string path)
|
||||
{
|
||||
_fileProxy.ReleaseFile(path);
|
||||
}
|
||||
}
|
||||
}
|
35
ModernKeePass.Application.12/Services/ImportService.cs
Normal file
35
ModernKeePass.Application.12/Services/ImportService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class ImportService: IImportService
|
||||
{
|
||||
private readonly Func<ImportFormat, IImportFormat> _importFormatProviders;
|
||||
|
||||
public ImportService(Func<ImportFormat, IImportFormat> importFormatProviders)
|
||||
{
|
||||
_importFormatProviders = importFormatProviders;
|
||||
}
|
||||
|
||||
public async Task Import(ImportFormat format, string filePath, Group group)
|
||||
{
|
||||
var importProvider = _importFormatProviders(format);
|
||||
var data = await importProvider.Import(filePath);
|
||||
|
||||
/*foreach (var entity in data)
|
||||
{
|
||||
var entry = group.AddNewEntry();
|
||||
entry.Name = entity["0"];
|
||||
entry.UserName = entity["1"];
|
||||
entry.Password = entity["2"];
|
||||
if (entity.Count > 3) entry.Url = entity["3"];
|
||||
if (entity.Count > 4) entry.Notes = entity["4"];
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
40
ModernKeePass.Application.12/Services/RecentService.cs
Normal file
40
ModernKeePass.Application.12/Services/RecentService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class RecentService: IRecentService
|
||||
{
|
||||
private readonly IRecentProxy _recentProxy;
|
||||
|
||||
public RecentService(IRecentProxy recentProxy)
|
||||
{
|
||||
_recentProxy = recentProxy;
|
||||
}
|
||||
|
||||
public bool HasEntries => _recentProxy.EntryCount > 0;
|
||||
|
||||
public async Task<FileInfo> Get(string token)
|
||||
{
|
||||
return await _recentProxy.Get(token);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<FileInfo>> GetAll()
|
||||
{
|
||||
return await _recentProxy.GetAll();
|
||||
}
|
||||
|
||||
public async Task Add(FileInfo recentItem)
|
||||
{
|
||||
await _recentProxy.Add(recentItem);
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
{
|
||||
_recentProxy.ClearAll();
|
||||
}
|
||||
}
|
||||
}
|
20
ModernKeePass.Application.12/Services/ResourceService.cs
Normal file
20
ModernKeePass.Application.12/Services/ResourceService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class ResourceService: IResourceService
|
||||
{
|
||||
private readonly IResourceProxy _resourceProxy;
|
||||
|
||||
public ResourceService(IResourceProxy resourceProxy)
|
||||
{
|
||||
_resourceProxy = resourceProxy;
|
||||
}
|
||||
|
||||
public string GetResourceValue(string key)
|
||||
{
|
||||
return _resourceProxy.GetResourceValue(key);
|
||||
}
|
||||
}
|
||||
}
|
35
ModernKeePass.Application.12/Services/SecurityService.cs
Normal file
35
ModernKeePass.Application.12/Services/SecurityService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class SecurityService: ISecurityService
|
||||
{
|
||||
private readonly IPasswordProxy _passwordProxy;
|
||||
private readonly IFileService _fileService;
|
||||
|
||||
public SecurityService(IPasswordProxy passwordProxy, IFileService fileService)
|
||||
{
|
||||
_passwordProxy = passwordProxy;
|
||||
_fileService = fileService;
|
||||
}
|
||||
|
||||
public string GeneratePassword(PasswordGenerationOptions options)
|
||||
{
|
||||
return _passwordProxy.GeneratePassword(options);
|
||||
}
|
||||
|
||||
public uint EstimatePasswordComplexity(string password)
|
||||
{
|
||||
return _passwordProxy.EstimatePasswordComplexity(password);
|
||||
}
|
||||
|
||||
public async Task GenerateKeyFile(string filePath)
|
||||
{
|
||||
var fileContents = _passwordProxy.GenerateKeyFile(null);
|
||||
await _fileService.WriteBinaryContentsToFile(filePath, fileContents);
|
||||
}
|
||||
}
|
||||
}
|
25
ModernKeePass.Application.12/Services/SettingsService.cs
Normal file
25
ModernKeePass.Application.12/Services/SettingsService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Application.Services
|
||||
{
|
||||
public class SettingsService: ISettingsService
|
||||
{
|
||||
private readonly ISettingsProxy _settingsProxy;
|
||||
|
||||
public SettingsService(ISettingsProxy settingsProxy)
|
||||
{
|
||||
_settingsProxy = settingsProxy;
|
||||
}
|
||||
|
||||
public T GetSetting<T>(string property, T defaultValue = default)
|
||||
{
|
||||
return _settingsProxy.GetSetting<T>(property, defaultValue);
|
||||
}
|
||||
|
||||
public void PutSetting<T>(string property, T value)
|
||||
{
|
||||
_settingsProxy.PutSetting<T>(property, value);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user