Changed most services to singletons

Refactor the Database Service (no more enum, ...)
Restored the Donate page with Paypal web page
Added (but not working) MS App Center integration
Corrected tests accordingly
WIP AOP to detect database changes
This commit is contained in:
BONNEVILLE Geoffroy
2018-02-23 18:09:21 +01:00
parent b46ab8db51
commit 7dbf93fe7b
35 changed files with 199 additions and 194 deletions

View File

@@ -15,10 +15,10 @@ using ModernKeePassLib.Serialization;
namespace ModernKeePass.Services
{
public class DatabaseService: IDatabase
public class DatabaseService: SingletonServiceBase<DatabaseService>, IDatabaseService
{
private readonly PwDatabase _pwDatabase = new PwDatabase();
private readonly ISettings _settings;
private readonly ISettingsService _settings;
private StorageFile _realDatabaseFile;
private StorageFile _databaseFile;
private GroupVm _recycleBin;
@@ -48,7 +48,7 @@ namespace ModernKeePass.Services
get { return _databaseFile; }
set
{
if (IsOpen)
if (IsOpen && HasChanged)
{
throw new DatabaseOpenedException();
}
@@ -77,15 +77,18 @@ namespace ModernKeePass.Services
public bool IsOpen => _pwDatabase.IsOpen;
public bool IsFileOpen => !_pwDatabase.IsOpen && _databaseFile != null;
public bool IsClosed => _databaseFile == null;
public bool HasChanged { get; set; }
public DatabaseService() : this(SettingsService.Instance)
{
}
public DatabaseService() : this(new SettingsService())
{ }
public DatabaseService(ISettings settings)
public DatabaseService(ISettingsService settings)
{
_settings = settings;
}
/// <summary>
/// Open a KeePass database
/// </summary>
@@ -118,7 +121,7 @@ namespace ModernKeePass.Services
}
else _pwDatabase.Open(ioConnection, key, new NullStatusLogger());
if (!_pwDatabase.IsOpen) return;
//if (!_pwDatabase.IsOpen) return;
// Copy database in temp directory and use this file for operations
if (_settings.GetSetting<bool>("AntiCorruption"))

View File

@@ -6,7 +6,7 @@ using ModernKeePass.Interfaces;
namespace ModernKeePass.Services
{
public class LicenseService : ILicenseService
public class LicenseService : SingletonServiceBase<LicenseService>, ILicenseService
{
public enum PurchaseResult
{

View File

@@ -8,10 +8,10 @@ using ModernKeePass.ViewModels;
namespace ModernKeePass.Services
{
public class RecentService : IRecent
public class RecentService : SingletonServiceBase<RecentService>, IRecentService
{
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
public int EntryCount => _mru.Entries.Count;
public ObservableCollection<IRecentItem> GetAllFiles(bool removeIfNonExistant = true)

View File

@@ -3,7 +3,7 @@ using ModernKeePass.Interfaces;
namespace ModernKeePass.Services
{
public class ResourcesService: IResource
public class ResourcesService: IResourceService
{
private const string ResourceFileName = "CodeBehind";
private readonly ResourceLoader _resourceLoader = ResourceLoader.GetForCurrentView();

View File

@@ -5,10 +5,10 @@ using ModernKeePass.Interfaces;
namespace ModernKeePass.Services
{
public class SettingsService : ISettings
public class SettingsService : SingletonServiceBase<SettingsService>, ISettingsService
{
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
public T GetSetting<T>(string property)
{
try

View File

@@ -0,0 +1,12 @@
using System;
namespace ModernKeePass.Services
{
public abstract class SingletonServiceBase<T> where T : new()
{
private static readonly Lazy<T> LazyInstance =
new Lazy<T>(() => new T());
public static T Instance => LazyInstance.Value;
}
}