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,38 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.AccessCache;
using ModernKeePass.Application.Common.Interfaces;
namespace ModernKeePass.Infrastructure.UWP
{
public class StorageFileClient: IFileProxy
{
public async Task<byte[]> OpenBinaryFile(string path)
{
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path);
var result = await FileIO.ReadBufferAsync(file);
return result.ToArray();
}
public async Task<IList<string>> OpenTextFile(string path)
{
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path);
var result = await FileIO.ReadLinesAsync(file);
return result;
}
public void ReleaseFile(string path)
{
StorageApplicationPermissions.FutureAccessList.Remove(path);
}
public async Task WriteBinaryContentsToFile(string path, byte[] contents)
{
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(path);
await FileIO.WriteBytesAsync(file, contents);
}
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage.AccessCache;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.Infrastructure.UWP
{
public class UwpRecentFilesClient: IRecentProxy
{
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
public int EntryCount => _mru.Entries.Count;
public async Task<FileInfo> Get(string token)
{
var recentEntry = _mru.Entries.FirstOrDefault(e => e.Token == token);
var file = await _mru.GetFileAsync(token);
StorageApplicationPermissions.FutureAccessList.AddOrReplace(recentEntry.Metadata, file);
return new FileInfo
{
Name = file.DisplayName,
Path = recentEntry.Metadata
};
}
public async Task<IEnumerable<FileInfo>> GetAll()
{
var result = new List<FileInfo>();
foreach (var entry in _mru.Entries)
{
try
{
var recentItem = await Get(entry.Token);
result.Add(recentItem);
}
catch (Exception)
{
_mru.Remove(entry.Token);
}
}
return result;
}
public async Task Add(FileInfo recentItem)
{
var file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(recentItem.Path);
_mru.Add(file, recentItem.Path);
}
public void ClearAll()
{
for (var i = _mru.Entries.Count; i > 0; i--)
{
var entry = _mru.Entries[i];
StorageApplicationPermissions.FutureAccessList.Remove(entry.Metadata);
_mru.Remove(entry.Token);
}
}
}
}

View File

@@ -0,0 +1,17 @@
using Windows.ApplicationModel.Resources;
using ModernKeePass.Application.Common.Interfaces;
namespace ModernKeePass.Infrastructure.UWP
{
public class UwpResourceClient: IResourceProxy
{
private const string ResourceFileName = "CodeBehind";
private readonly ResourceLoader _resourceLoader = ResourceLoader.GetForCurrentView();
public string GetResourceValue(string key)
{
var resource = _resourceLoader.GetString($"/{ResourceFileName}/{key}");
return resource;
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using Windows.Foundation.Collections;
using Windows.Storage;
using ModernKeePass.Application.Common.Interfaces;
namespace ModernKeePass.Infrastructure.UWP
{
public class UwpSettingsClient : ISettingsProxy
{
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
public T GetSetting<T>(string property, T defaultValue = default)
{
try
{
return (T)Convert.ChangeType(_values[property], typeof(T));
}
catch (InvalidCastException)
{
return defaultValue;
}
}
public void PutSetting<T>(string property, T value)
{
if (_values.ContainsKey(property))
_values[property] = value;
else _values.Add(property, value);
}
}
}