Most services are implemented as command/queries

Code cleanup
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-26 19:04:51 +01:00
parent 903e7649e4
commit 22072bb2fe
46 changed files with 567 additions and 390 deletions

View File

@@ -1,22 +0,0 @@
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

@@ -1,37 +0,0 @@
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

@@ -1,35 +0,0 @@
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

@@ -1,40 +0,0 @@
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

@@ -1,35 +0,0 @@
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

@@ -1,25 +0,0 @@
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);
}
}
}