mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 07:30:15 -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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/Common/Interfaces/IFileProxy.cs
Normal file
13
ModernKeePass.Application/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; }
|
||||
}
|
||||
}
|
10
ModernKeePass.Application/Common/Interfaces/IImportFormat.cs
Normal file
10
ModernKeePass.Application/Common/Interfaces/IImportFormat.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
15
ModernKeePass.Application/Common/Interfaces/IRecentProxy.cs
Normal file
15
ModernKeePass.Application/Common/Interfaces/IRecentProxy.cs
Normal file
@@ -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/Common/Mappings/IMapFrom.cs
Normal file
10
ModernKeePass.Application/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);
|
||||
}
|
||||
}
|
30
ModernKeePass.Application/Common/Mappings/MappingProfile.cs
Normal file
30
ModernKeePass.Application/Common/Mappings/MappingProfile.cs
Normal file
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
ModernKeePass.Application/Common/Mappings/MappingProfiles.cs
Normal file
17
ModernKeePass.Application/Common/Mappings/MappingProfiles.cs
Normal file
@@ -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/Database/Models/DatabaseVm.cs
Normal file
21
ModernKeePass.Application/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/Database/Models/MainVm.cs
Normal file
7
ModernKeePass.Application/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);
|
||||
}
|
||||
}
|
||||
}
|
27
ModernKeePass.Application/Entry/Models/EntryVm.cs
Normal file
27
ModernKeePass.Application/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/Group/Models/GroupVm.cs
Normal file
33
ModernKeePass.Application/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));
|
||||
}
|
||||
}
|
||||
}
|
104
ModernKeePass.Application/ModernKeePass.Application.csproj
Normal file
104
ModernKeePass.Application/ModernKeePass.Application.csproj
Normal file
@@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{42353562-5E43-459C-8E3E-2F21E575261D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ModernKeePass.Application</RootNamespace>
|
||||
<AssemblyName>ModernKeePass.Application</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .NET Framework is automatically included -->
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\Interfaces\ICryptographyClient.cs" />
|
||||
<Compile Include="Common\Interfaces\IDatabaseProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IFileProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IHasSelectableObject.cs" />
|
||||
<Compile Include="Common\Interfaces\IImportFormat.cs" />
|
||||
<Compile Include="Common\Interfaces\IIsEnabled.cs" />
|
||||
<Compile Include="Common\Interfaces\IPasswordProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IProxyInvocationHandler.cs" />
|
||||
<Compile Include="Common\Interfaces\IRecentProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\IResourceProxy.cs" />
|
||||
<Compile Include="Common\Interfaces\ISelectableModel.cs" />
|
||||
<Compile Include="Common\Interfaces\ISettingsProxy.cs" />
|
||||
<Compile Include="Common\Mappings\IMapFrom.cs" />
|
||||
<Content Include="Common\Mappings\MappingProfile.cs" />
|
||||
<Compile Include="Common\Mappings\MappingProfiles.cs" />
|
||||
<Compile Include="Database\Commands\CloseDatabase\CloseDatabaseCommand.cs" />
|
||||
<Compile Include="Database\Commands\CreateDatabase\CreateDatabaseCommand.cs" />
|
||||
<Compile Include="Database\Commands\SaveDatabase\SaveDatabaseCommand.cs" />
|
||||
<Compile Include="Database\Models\DatabaseVm.cs" />
|
||||
<Compile Include="Database\Models\MainVm.cs" />
|
||||
<Compile Include="Database\Queries\IsDatabaseOpen\IsDatabaseOpenQuery.cs" />
|
||||
<Compile Include="Database\Queries\OpenDatabase\OpenDatabaseQuery.cs" />
|
||||
<Compile Include="Database\Queries\OpenDatabase\OpenDatabaseQueryValidator.cs" />
|
||||
<Compile Include="Entry\Models\EntryVm.cs" />
|
||||
<Compile Include="Group\Models\GroupVm.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.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="Resources\Commands\" />
|
||||
<Folder Include="Resources\Queries\" />
|
||||
<Folder Include="Settings\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\ModernKeePass.Domain.csproj">
|
||||
<Project>{9a0759f1-9069-4841-99e3-3bec44e17356}</Project>
|
||||
<Name>ModernKeePass.Domain</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
@@ -1,18 +1,20 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ModernKeePassLib.Test")]
|
||||
[assembly: AssemblyTitle("ModernKeePass.Application")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ModernKeePassLib.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyProduct("ModernKeePass.Application")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
22
ModernKeePass.Application/Services/CryptographyService.cs
Normal file
22
ModernKeePass.Application/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/Services/DatabaseService.cs
Normal file
103
ModernKeePass.Application/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/Services/FileService.cs
Normal file
37
ModernKeePass.Application/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/Services/ImportService.cs
Normal file
35
ModernKeePass.Application/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/Services/RecentService.cs
Normal file
40
ModernKeePass.Application/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/Services/ResourceService.cs
Normal file
20
ModernKeePass.Application/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/Services/SecurityService.cs
Normal file
35
ModernKeePass.Application/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/Services/SettingsService.cs
Normal file
25
ModernKeePass.Application/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);
|
||||
}
|
||||
}
|
||||
}
|
15
ModernKeePass.Application/project.json
Normal file
15
ModernKeePass.Application/project.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"supports": {},
|
||||
"dependencies": {
|
||||
"Autofac": "4.9.4",
|
||||
"AutoMapper": "6.2.2",
|
||||
"FluentValidation": "8.6.2",
|
||||
"MediatR": "4.0.0",
|
||||
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
|
||||
"NETStandard.Library": "1.6.1",
|
||||
"Splat": "3.0.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.2": {}
|
||||
}
|
||||
}
|
28
ModernKeePass.Domain.12/AOP/NotifyPropertyChangedBase.cs
Normal file
28
ModernKeePass.Domain.12/AOP/NotifyPropertyChangedBase.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ModernKeePass.Domain.AOP
|
||||
{
|
||||
public class NotifyPropertyChangedBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged(string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected bool SetProperty<T>(ref T property, T value, [CallerMemberName] string propertyName = "")
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(property, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
property = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
9
ModernKeePass.Domain.12/Dtos/Credentials.cs
Normal file
9
ModernKeePass.Domain.12/Dtos/Credentials.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ModernKeePass.Domain.Dtos
|
||||
{
|
||||
public class Credentials
|
||||
{
|
||||
public string Password { get; set; }
|
||||
public string KeyFilePath { get; set; }
|
||||
// TODO: add Windows Hello
|
||||
}
|
||||
}
|
8
ModernKeePass.Domain.12/Dtos/FileInfo.cs
Normal file
8
ModernKeePass.Domain.12/Dtos/FileInfo.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ModernKeePass.Domain.Dtos
|
||||
{
|
||||
public class FileInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
16
ModernKeePass.Domain.12/Dtos/PasswordGenerationOptions.cs
Normal file
16
ModernKeePass.Domain.12/Dtos/PasswordGenerationOptions.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace ModernKeePass.Domain.Dtos
|
||||
{
|
||||
public class PasswordGenerationOptions
|
||||
{
|
||||
public int PasswordLength { get; set; }
|
||||
public bool UpperCasePatternSelected { get; set; }
|
||||
public bool LowerCasePatternSelected { get; set; }
|
||||
public bool DigitsPatternSelected { get; set; }
|
||||
public bool SpecialPatternSelected { get; set; }
|
||||
public bool MinusPatternSelected { get; set; }
|
||||
public bool UnderscorePatternSelected { get; set; }
|
||||
public bool SpacePatternSelected { get; set; }
|
||||
public bool BracketsPatternSelected { get; set; }
|
||||
public string CustomChars { get; set; }
|
||||
}
|
||||
}
|
14
ModernKeePass.Domain.12/Entities/BaseEntity.cs
Normal file
14
ModernKeePass.Domain.12/Entities/BaseEntity.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class BaseEntity
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Color ForegroundColor { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
public DateTimeOffset LastModificationDate { get; set; }
|
||||
}
|
||||
}
|
9
ModernKeePass.Domain.12/Entities/DatabaseEntity.cs
Normal file
9
ModernKeePass.Domain.12/Entities/DatabaseEntity.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class DatabaseEntity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public GroupEntity RootGroupEntity { get; set; }
|
||||
}
|
||||
}
|
22
ModernKeePass.Domain.12/Entities/EntryEntity.cs
Normal file
22
ModernKeePass.Domain.12/Entities/EntryEntity.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class EntryEntity: BaseEntity
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public Uri Url { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTimeOffset ExpirationDate { get; set; }
|
||||
public Color ForegroundColor { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
public Dictionary<string, string> AdditionalFields { get; set; } = new Dictionary<string, string>();
|
||||
public IEnumerable<EntryEntity> History { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public bool HasExpirationDate { get; set; }
|
||||
}
|
||||
}
|
12
ModernKeePass.Domain.12/Entities/GroupEntity.cs
Normal file
12
ModernKeePass.Domain.12/Entities/GroupEntity.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class GroupEntity : BaseEntity
|
||||
{
|
||||
public List<GroupEntity> SubGroups { get; set; } = new List<GroupEntity>();
|
||||
public List<EntryEntity> Entries { get; set; } = new List<EntryEntity>();
|
||||
public Icon Icon { get; set; }
|
||||
}
|
||||
}
|
10
ModernKeePass.Domain.12/Enums/CredentialStatusTypes.cs
Normal file
10
ModernKeePass.Domain.12/Enums/CredentialStatusTypes.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ModernKeePass.Domain.Enums
|
||||
{
|
||||
public enum CredentialStatusTypes
|
||||
{
|
||||
Normal = 0,
|
||||
Error = 1,
|
||||
Warning = 3,
|
||||
Success = 5
|
||||
}
|
||||
}
|
54
ModernKeePass.Domain.12/Enums/Icon.cs
Normal file
54
ModernKeePass.Domain.12/Enums/Icon.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace ModernKeePass.Domain.Enums
|
||||
{
|
||||
public enum Icon
|
||||
{
|
||||
Delete,
|
||||
Edit,
|
||||
Save,
|
||||
Cancel,
|
||||
Accept,
|
||||
Home,
|
||||
Camera,
|
||||
Setting,
|
||||
Mail,
|
||||
Find,
|
||||
Help,
|
||||
Clock,
|
||||
Crop,
|
||||
World,
|
||||
Flag,
|
||||
PreviewLink,
|
||||
Document,
|
||||
ProtectedDocument,
|
||||
ContactInfo,
|
||||
ViewAll,
|
||||
Rotate,
|
||||
List,
|
||||
Shop,
|
||||
BrowsePhotos,
|
||||
Caption,
|
||||
Repair,
|
||||
Page,
|
||||
Paste,
|
||||
Important,
|
||||
SlideShow,
|
||||
MapDrive,
|
||||
ContactPresence,
|
||||
Contact,
|
||||
Folder,
|
||||
View,
|
||||
Permissions,
|
||||
Map,
|
||||
CellPhone,
|
||||
OutlineStar,
|
||||
Calculator,
|
||||
Library,
|
||||
SyncFolder,
|
||||
GoToStart,
|
||||
ZeroBars,
|
||||
FourBars,
|
||||
Scan,
|
||||
ReportHacked,
|
||||
Stop
|
||||
}
|
||||
}
|
7
ModernKeePass.Domain.12/Enums/ImportFormat.cs
Normal file
7
ModernKeePass.Domain.12/Enums/ImportFormat.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Domain.Enums
|
||||
{
|
||||
public enum ImportFormat
|
||||
{
|
||||
CSV
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class DatabaseClosedException: Exception
|
||||
{ }
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class DatabaseOpenException: Exception
|
||||
{ }
|
||||
}
|
11
ModernKeePass.Domain.12/Exceptions/NavigationException.cs
Normal file
11
ModernKeePass.Domain.12/Exceptions/NavigationException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class NavigationException: Exception
|
||||
{
|
||||
public NavigationException(Type pageType) : base($"Failed to load Page {pageType.FullName}")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
14
ModernKeePass.Domain.12/Exceptions/SaveException.cs
Normal file
14
ModernKeePass.Domain.12/Exceptions/SaveException.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class SaveException : Exception
|
||||
{
|
||||
public new Exception InnerException { get; }
|
||||
|
||||
public SaveException(Exception exception)
|
||||
{
|
||||
InnerException = exception;
|
||||
}
|
||||
}
|
||||
}
|
11
ModernKeePass.Domain.12/ModernKeePass.Domain.csproj
Normal file
11
ModernKeePass.Domain.12/ModernKeePass.Domain.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Splat" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
28
ModernKeePass.Domain/AOP/NotifyPropertyChangedBase.cs
Normal file
28
ModernKeePass.Domain/AOP/NotifyPropertyChangedBase.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ModernKeePass.Domain.AOP
|
||||
{
|
||||
public class NotifyPropertyChangedBase : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void OnPropertyChanged(string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected bool SetProperty<T>(ref T property, T value, [CallerMemberName] string propertyName = "")
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(property, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
property = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
9
ModernKeePass.Domain/Dtos/Credentials.cs
Normal file
9
ModernKeePass.Domain/Dtos/Credentials.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ModernKeePass.Domain.Dtos
|
||||
{
|
||||
public class Credentials
|
||||
{
|
||||
public string Password { get; set; }
|
||||
public string KeyFilePath { get; set; }
|
||||
// TODO: add Windows Hello
|
||||
}
|
||||
}
|
8
ModernKeePass.Domain/Dtos/FileInfo.cs
Normal file
8
ModernKeePass.Domain/Dtos/FileInfo.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ModernKeePass.Domain.Dtos
|
||||
{
|
||||
public class FileInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
16
ModernKeePass.Domain/Dtos/PasswordGenerationOptions.cs
Normal file
16
ModernKeePass.Domain/Dtos/PasswordGenerationOptions.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace ModernKeePass.Domain.Dtos
|
||||
{
|
||||
public class PasswordGenerationOptions
|
||||
{
|
||||
public int PasswordLength { get; set; }
|
||||
public bool UpperCasePatternSelected { get; set; }
|
||||
public bool LowerCasePatternSelected { get; set; }
|
||||
public bool DigitsPatternSelected { get; set; }
|
||||
public bool SpecialPatternSelected { get; set; }
|
||||
public bool MinusPatternSelected { get; set; }
|
||||
public bool UnderscorePatternSelected { get; set; }
|
||||
public bool SpacePatternSelected { get; set; }
|
||||
public bool BracketsPatternSelected { get; set; }
|
||||
public string CustomChars { get; set; }
|
||||
}
|
||||
}
|
14
ModernKeePass.Domain/Entities/BaseEntity.cs
Normal file
14
ModernKeePass.Domain/Entities/BaseEntity.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class BaseEntity
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Color ForegroundColor { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
public DateTimeOffset LastModificationDate { get; set; }
|
||||
}
|
||||
}
|
9
ModernKeePass.Domain/Entities/DatabaseEntity.cs
Normal file
9
ModernKeePass.Domain/Entities/DatabaseEntity.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class DatabaseEntity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public GroupEntity RootGroupEntity { get; set; }
|
||||
}
|
||||
}
|
19
ModernKeePass.Domain/Entities/EntryEntity.cs
Normal file
19
ModernKeePass.Domain/Entities/EntryEntity.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class EntryEntity: BaseEntity
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public Uri Url { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTimeOffset ExpirationDate { get; set; }
|
||||
public Dictionary<string, string> AdditionalFields { get; set; } = new Dictionary<string, string>();
|
||||
public IEnumerable<EntryEntity> History { get; set; }
|
||||
public Icon Icon { get; set; }
|
||||
public bool HasExpirationDate { get; set; }
|
||||
}
|
||||
}
|
12
ModernKeePass.Domain/Entities/GroupEntity.cs
Normal file
12
ModernKeePass.Domain/Entities/GroupEntity.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.Domain.Entities
|
||||
{
|
||||
public class GroupEntity : BaseEntity
|
||||
{
|
||||
public List<GroupEntity> SubGroups { get; set; } = new List<GroupEntity>();
|
||||
public List<EntryEntity> Entries { get; set; } = new List<EntryEntity>();
|
||||
public Icon Icon { get; set; }
|
||||
}
|
||||
}
|
10
ModernKeePass.Domain/Enums/CredentialStatusTypes.cs
Normal file
10
ModernKeePass.Domain/Enums/CredentialStatusTypes.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ModernKeePass.Domain.Enums
|
||||
{
|
||||
public enum CredentialStatusTypes
|
||||
{
|
||||
Normal = 0,
|
||||
Error = 1,
|
||||
Warning = 3,
|
||||
Success = 5
|
||||
}
|
||||
}
|
54
ModernKeePass.Domain/Enums/Icon.cs
Normal file
54
ModernKeePass.Domain/Enums/Icon.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace ModernKeePass.Domain.Enums
|
||||
{
|
||||
public enum Icon
|
||||
{
|
||||
Delete,
|
||||
Edit,
|
||||
Save,
|
||||
Cancel,
|
||||
Accept,
|
||||
Home,
|
||||
Camera,
|
||||
Setting,
|
||||
Mail,
|
||||
Find,
|
||||
Help,
|
||||
Clock,
|
||||
Crop,
|
||||
World,
|
||||
Flag,
|
||||
PreviewLink,
|
||||
Document,
|
||||
ProtectedDocument,
|
||||
ContactInfo,
|
||||
ViewAll,
|
||||
Rotate,
|
||||
List,
|
||||
Shop,
|
||||
BrowsePhotos,
|
||||
Caption,
|
||||
Repair,
|
||||
Page,
|
||||
Paste,
|
||||
Important,
|
||||
SlideShow,
|
||||
MapDrive,
|
||||
ContactPresence,
|
||||
Contact,
|
||||
Folder,
|
||||
View,
|
||||
Permissions,
|
||||
Map,
|
||||
CellPhone,
|
||||
OutlineStar,
|
||||
Calculator,
|
||||
Library,
|
||||
SyncFolder,
|
||||
GoToStart,
|
||||
ZeroBars,
|
||||
FourBars,
|
||||
Scan,
|
||||
ReportHacked,
|
||||
Stop
|
||||
}
|
||||
}
|
7
ModernKeePass.Domain/Enums/ImportFormat.cs
Normal file
7
ModernKeePass.Domain/Enums/ImportFormat.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ModernKeePass.Domain.Enums
|
||||
{
|
||||
public enum ImportFormat
|
||||
{
|
||||
CSV
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class DatabaseClosedException: Exception
|
||||
{ }
|
||||
}
|
7
ModernKeePass.Domain/Exceptions/DatabaseOpenException.cs
Normal file
7
ModernKeePass.Domain/Exceptions/DatabaseOpenException.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Domain.Exceptions
|
||||
{
|
||||
public class DatabaseOpenException: Exception
|
||||
{ }
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user