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-04-22 16:21:47 +02:00
|
|
|
|
using GalaSoft.MvvmLight;
|
2020-03-27 18:45:13 +01:00
|
|
|
|
using MediatR;
|
|
|
|
|
using ModernKeePass.Application.Database.Models;
|
|
|
|
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetCipher;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetCompression;
|
|
|
|
|
using ModernKeePass.Application.Parameters.Commands.SetKeyDerivation;
|
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;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
|
2020-05-13 13:50:33 +02:00
|
|
|
|
namespace ModernKeePass.ViewModels.Settings
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
// TODO: implement Kdf settings
|
2020-05-13 13:50:33 +02:00
|
|
|
|
public class SecurityVm: ObservableObject
|
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
|
|
|
|
|
2020-04-03 18:14:44 +02:00
|
|
|
|
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-05-13 13:50:33 +02:00
|
|
|
|
public SecurityVm(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-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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|