WIP Clean Architecture

Windows 8.1 App Uses keepasslib v2.44 (temporarily)
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-24 13:01:14 +01:00
parent 34cd4ca3d8
commit 7e44d47065
290 changed files with 4084 additions and 36416 deletions

View 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;
}
}
}

View 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();
}
}
}

View 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);
}
}
}

View 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"];
}*/
}
}
}

View 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();
}
}
}

View 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);
}
}
}

View 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);
}
}
}

View 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);
}
}
}