2020-03-27 18:45:13 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
2020-03-27 18:45:13 +01:00
|
|
|
|
using MediatR;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-04-03 17:33:53 +02:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
2020-03-27 18:45:13 +01:00
|
|
|
|
using ModernKeePass.Application.Database.Models;
|
|
|
|
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
2020-04-02 19:12:16 +02:00
|
|
|
|
using ModernKeePass.Application.Group.Queries.GetGroup;
|
2020-03-27 18:45:13 +01:00
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetCipher;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetCompression;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetHasRecycleBin;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetKeyDerivation;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetRecycleBin;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using ModernKeePass.Application.Parameters.Models;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Queries.GetCiphers;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Queries.GetCompressions;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using ModernKeePass.Domain.AOP;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
// TODO: implement Kdf settings
|
2020-04-03 17:33:53 +02:00
|
|
|
|
public class SettingsDatabaseVm: NotifyPropertyChangedBase
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
2020-03-27 18:45:13 +01:00
|
|
|
|
private readonly IMediator _mediator;
|
|
|
|
|
private readonly DatabaseVm _database;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
|
|
|
|
|
public bool HasRecycleBin
|
|
|
|
|
{
|
2020-03-27 18:45:13 +01:00
|
|
|
|
get { return _database.IsRecycleBinEnabled; }
|
2017-10-30 18:34:38 +01:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-03-31 19:19:02 +02:00
|
|
|
|
_mediator.Send(new SetHasRecycleBinCommand {HasRecycleBin = value}).Wait();
|
2020-03-27 18:45:13 +01:00
|
|
|
|
OnPropertyChanged(nameof(HasRecycleBin));
|
2017-10-30 18:34:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 17:30:03 +01:00
|
|
|
|
public bool IsNewRecycleBin
|
|
|
|
|
{
|
2020-04-02 19:12:16 +02:00
|
|
|
|
get { return string.IsNullOrEmpty(_database.RecycleBinId); }
|
2018-03-12 17:30:03 +01:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-03 17:33:53 +02:00
|
|
|
|
if (value) _mediator.Send(new SetRecycleBinCommand { RecycleBinId = null }).Wait();
|
2018-03-12 17:30:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-03 18:14:44 +02:00
|
|
|
|
public ObservableCollection<IEntityVm> Groups { get; }
|
|
|
|
|
public ObservableCollection<CipherVm> Ciphers { get; }
|
2020-03-27 18:45:13 +01:00
|
|
|
|
public IEnumerable<string> Compressions => _mediator.Send(new GetCompressionsQuery()).GetAwaiter().GetResult();
|
2020-04-03 18:14:44 +02:00
|
|
|
|
public ObservableCollection<KeyDerivationVm> KeyDerivations { get; }
|
2020-03-27 18:45:13 +01:00
|
|
|
|
|
|
|
|
|
public CipherVm SelectedCipher
|
2017-11-02 11:30:03 +01:00
|
|
|
|
{
|
2020-03-27 18:45:13 +01:00
|
|
|
|
get { return Ciphers.FirstOrDefault(c => c.Id == _database.CipherId); }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set { _mediator.Send(new SetCipherCommand {CipherId = value.Id}).Wait(); }
|
2020-03-27 18:45:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SelectedCompression
|
|
|
|
|
{
|
|
|
|
|
get { return Compressions.FirstOrDefault(c => c == _database.Compression); }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set { _mediator.Send(new SetCompressionCommand {Compression = value}).Wait(); }
|
2020-03-27 18:45:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public KeyDerivationVm SelectedKeyDerivation
|
|
|
|
|
{
|
|
|
|
|
get { return KeyDerivations.FirstOrDefault(c => c.Id == _database.KeyDerivationId); }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set { _mediator.Send(new SetKeyDerivationCommand {KeyDerivationId = value.Id}).Wait(); }
|
2017-11-02 11:30:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-03 17:33:53 +02:00
|
|
|
|
public IEntityVm SelectedRecycleBin
|
|
|
|
|
{
|
|
|
|
|
get { return Groups.FirstOrDefault(g => g.Id == _database.RecycleBinId); }
|
|
|
|
|
set { _mediator.Send(new SetRecycleBinCommand { RecycleBinId = value.Id}).Wait(); }
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public SettingsDatabaseVm() : this(App.Services.GetService<IMediator>()) { }
|
2017-11-23 15:26:57 +01:00
|
|
|
|
|
2020-03-27 18:45:13 +01:00
|
|
|
|
public SettingsDatabaseVm(IMediator mediator)
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
2020-03-27 18:45:13 +01:00
|
|
|
|
_mediator = mediator;
|
|
|
|
|
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
2020-04-02 19:12:16 +02:00
|
|
|
|
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
|
2020-04-03 17:33:53 +02:00
|
|
|
|
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
|
2020-04-03 18:14:44 +02:00
|
|
|
|
var ciphers = _mediator.Send(new GetCiphersQuery()).GetAwaiter().GetResult();
|
|
|
|
|
Ciphers = new ObservableCollection<CipherVm>(ciphers);
|
|
|
|
|
var keyDerivations = _mediator.Send(new GetKeyDerivationsQuery()).GetAwaiter().GetResult();
|
|
|
|
|
KeyDerivations = new ObservableCollection<KeyDerivationVm>(keyDerivations);
|
2017-10-30 18:34:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|