mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
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:
@@ -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"))
|
||||
|
@@ -6,7 +6,7 @@ using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Services
|
||||
{
|
||||
public class LicenseService : ILicenseService
|
||||
public class LicenseService : SingletonServiceBase<LicenseService>, ILicenseService
|
||||
{
|
||||
public enum PurchaseResult
|
||||
{
|
||||
|
@@ -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)
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
|
12
ModernKeePass/Services/SingletonServiceBase.cs
Normal file
12
ModernKeePass/Services/SingletonServiceBase.cs
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user