2017-10-31 12:14:26 +01:00
|
|
|
|
using System;
|
2020-04-15 19:06:13 +02:00
|
|
|
|
using System.Collections.ObjectModel;
|
2020-04-16 19:43:17 +02:00
|
|
|
|
using System.Linq;
|
2020-03-27 13:27:29 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
2020-04-22 16:21:47 +02:00
|
|
|
|
using GalaSoft.MvvmLight;
|
2020-04-23 19:00:38 +02:00
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
2020-04-21 19:12:26 +02:00
|
|
|
|
using GalaSoft.MvvmLight.Views;
|
2020-03-27 13:27:29 +01:00
|
|
|
|
using MediatR;
|
2020-05-04 12:48:27 +02:00
|
|
|
|
using Messages;
|
2020-04-22 11:58:06 +02:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
2020-03-27 13:27:29 +01:00
|
|
|
|
using ModernKeePass.Application.Database.Commands.SaveDatabase;
|
2020-03-27 18:45:13 +01:00
|
|
|
|
using ModernKeePass.Application.Database.Models;
|
|
|
|
|
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
2020-05-07 12:11:12 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Commands.AddAttachment;
|
2020-04-14 19:59:19 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Commands.AddHistory;
|
2020-05-07 12:11:12 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Commands.DeleteAttachment;
|
2020-04-16 14:08:50 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Commands.DeleteHistory;
|
2020-04-15 19:06:13 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Commands.RestoreHistory;
|
2020-03-27 13:27:29 +01:00
|
|
|
|
using ModernKeePass.Application.Entry.Commands.SetFieldValue;
|
2020-04-02 19:12:16 +02:00
|
|
|
|
using ModernKeePass.Application.Entry.Models;
|
|
|
|
|
using ModernKeePass.Application.Entry.Queries.GetEntry;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using ModernKeePass.Application.Group.Commands.AddEntry;
|
2020-04-02 19:12:16 +02:00
|
|
|
|
using ModernKeePass.Application.Group.Commands.DeleteEntry;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using ModernKeePass.Application.Group.Commands.RemoveEntry;
|
2020-04-02 19:12:16 +02:00
|
|
|
|
using ModernKeePass.Application.Group.Queries.GetGroup;
|
2020-03-27 13:27:29 +01:00
|
|
|
|
using ModernKeePass.Application.Security.Commands.GeneratePassword;
|
|
|
|
|
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
|
2020-03-31 19:19:02 +02:00
|
|
|
|
using ModernKeePass.Domain.Enums;
|
2020-04-02 19:12:16 +02:00
|
|
|
|
using ModernKeePass.Application.Group.Models;
|
2020-04-28 18:54:37 +02:00
|
|
|
|
using ModernKeePass.Common;
|
2020-05-06 18:54:39 +02:00
|
|
|
|
using ModernKeePass.Domain.Dtos;
|
2020-05-04 12:48:27 +02:00
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
using ModernKeePass.Extensions;
|
2020-04-28 18:54:37 +02:00
|
|
|
|
using ModernKeePass.Models;
|
2017-09-12 18:20:32 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2020-05-04 12:48:27 +02:00
|
|
|
|
public class EntryDetailVm : ViewModelBase
|
2017-09-12 18:20:32 +02:00
|
|
|
|
{
|
2017-10-12 18:37:49 +02:00
|
|
|
|
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
2020-03-27 13:27:29 +01:00
|
|
|
|
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
|
|
|
|
|
public double PasswordComplexityIndicator => _mediator.Send(new EstimatePasswordComplexityQuery {Password = Password}).GetAwaiter().GetResult();
|
2017-10-16 18:31:45 +02:00
|
|
|
|
public bool UpperCasePatternSelected { get; set; } = true;
|
|
|
|
|
public bool LowerCasePatternSelected { get; set; } = true;
|
|
|
|
|
public bool DigitsPatternSelected { get; set; } = true;
|
|
|
|
|
public bool MinusPatternSelected { get; set; }
|
|
|
|
|
public bool UnderscorePatternSelected { get; set; }
|
|
|
|
|
public bool SpacePatternSelected { get; set; }
|
|
|
|
|
public bool SpecialPatternSelected { get; set; }
|
|
|
|
|
public bool BracketsPatternSelected { get; set; }
|
|
|
|
|
public string CustomChars { get; set; } = string.Empty;
|
2020-04-28 18:54:37 +02:00
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
public string Id => SelectedItem.Id;
|
|
|
|
|
|
2020-04-28 18:54:37 +02:00
|
|
|
|
public string ParentGroupName => _parent.Title;
|
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
public bool IsRecycleOnDelete
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var database = Database;
|
|
|
|
|
return database.IsRecycleBinEnabled && _parent.Id != database.RecycleBinId;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-06 18:54:39 +02:00
|
|
|
|
|
2020-04-25 22:03:47 +02:00
|
|
|
|
public ObservableCollection<EntryVm> History { get; private set; }
|
2020-05-06 18:54:39 +02:00
|
|
|
|
public ObservableCollection<Field> AdditionalFields { get; private set; }
|
|
|
|
|
public ObservableCollection<Attachment> Attachments { get; private set; }
|
2020-03-30 19:43:04 +02:00
|
|
|
|
|
2018-06-15 18:07:44 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if the Entry is current or from history
|
|
|
|
|
/// </summary>
|
2020-04-16 14:08:50 +02:00
|
|
|
|
public bool IsCurrentEntry => SelectedIndex == 0;
|
|
|
|
|
|
|
|
|
|
public EntryVm SelectedItem
|
2020-04-03 17:33:53 +02:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return _selectedItem; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-05-06 18:54:39 +02:00
|
|
|
|
Set(() => SelectedItem, ref _selectedItem, value, true);
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
AdditionalFields = new ObservableCollection<Field>(SelectedItem.AdditionalFields.Select(f => new Field
|
|
|
|
|
{
|
|
|
|
|
Name = f.Key,
|
|
|
|
|
Value = f.Value
|
|
|
|
|
}));
|
|
|
|
|
Attachments = new ObservableCollection<Attachment>(SelectedItem.Attachments.Select(f => new Attachment
|
|
|
|
|
{
|
|
|
|
|
Name = f.Key,
|
|
|
|
|
Content = f.Value
|
|
|
|
|
}));
|
2020-05-07 12:11:12 +02:00
|
|
|
|
Attachments.CollectionChanged += (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
SaveCommand.RaiseCanExecuteChanged();
|
|
|
|
|
_isDirty = true;
|
|
|
|
|
};
|
2020-05-06 18:54:39 +02:00
|
|
|
|
RaisePropertyChanged(string.Empty);
|
|
|
|
|
}
|
2020-04-16 14:08:50 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-06 18:54:39 +02:00
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
public int SelectedIndex
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedIndex; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-22 16:21:47 +02:00
|
|
|
|
Set(() => SelectedIndex, ref _selectedIndex, value);
|
|
|
|
|
RaisePropertyChanged(nameof(IsCurrentEntry));
|
2020-05-07 12:11:12 +02:00
|
|
|
|
AddAttachmentCommand.RaiseCanExecuteChanged();
|
2020-04-16 14:08:50 +02:00
|
|
|
|
}
|
2020-04-03 17:33:53 +02:00
|
|
|
|
}
|
2017-10-16 18:31:45 +02:00
|
|
|
|
|
2017-11-06 19:01:01 +01:00
|
|
|
|
public double PasswordLength
|
|
|
|
|
{
|
|
|
|
|
get { return _passwordLength; }
|
2020-04-22 16:21:47 +02:00
|
|
|
|
set { Set(() => PasswordLength, ref _passwordLength, value); }
|
2017-11-06 19:01:01 +01:00
|
|
|
|
}
|
2017-11-29 19:13:38 +01:00
|
|
|
|
|
2020-03-27 13:27:29 +01:00
|
|
|
|
public string Title
|
2017-09-26 14:32:15 +02:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.Title; }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.Title = value;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
SetFieldValue(nameof(Title), value).Wait();
|
2020-03-31 19:19:02 +02:00
|
|
|
|
}
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
2017-10-11 11:20:05 +02:00
|
|
|
|
|
2017-09-26 14:32:15 +02:00
|
|
|
|
public string UserName
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.Username; }
|
2020-04-30 19:40:48 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SelectedItem.Username = value;
|
|
|
|
|
SetFieldValue(nameof(UserName), value).Wait();
|
|
|
|
|
RaisePropertyChanged(nameof(UserName));
|
|
|
|
|
}
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
2017-11-06 19:01:01 +01:00
|
|
|
|
|
2017-09-26 14:32:15 +02:00
|
|
|
|
public string Password
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.Password; }
|
2017-10-13 11:48:58 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.Password = value;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
SetFieldValue(nameof(Password), value).Wait();
|
2020-04-22 16:21:47 +02:00
|
|
|
|
RaisePropertyChanged(nameof(Password));
|
|
|
|
|
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
|
2017-10-13 11:48:58 +02:00
|
|
|
|
}
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
2018-02-23 18:09:21 +01:00
|
|
|
|
|
2017-09-26 14:32:15 +02:00
|
|
|
|
public string Url
|
|
|
|
|
{
|
2020-04-20 20:02:43 +02:00
|
|
|
|
get { return SelectedItem.Url; }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-20 20:02:43 +02:00
|
|
|
|
SelectedItem.Url = value;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
SetFieldValue(nameof(Url), value).Wait();
|
2020-04-30 19:40:48 +02:00
|
|
|
|
RaisePropertyChanged(nameof(Url));
|
2020-03-31 19:19:02 +02:00
|
|
|
|
}
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
2018-06-15 18:07:44 +02:00
|
|
|
|
|
2017-09-26 14:32:15 +02:00
|
|
|
|
public string Notes
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.Notes; }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.Notes = value;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
SetFieldValue(nameof(Notes), value).Wait();
|
2020-03-31 19:19:02 +02:00
|
|
|
|
}
|
2017-09-26 14:32:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 19:43:04 +02:00
|
|
|
|
public Symbol Icon
|
2017-09-29 18:08:20 +02:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return (Symbol)Enum.Parse(typeof(Symbol), SelectedItem.Icon.ToString()); }
|
2020-03-31 19:19:02 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.Icon = (Icon)Enum.Parse(typeof(Icon), value.ToString());
|
|
|
|
|
SetFieldValue(nameof(Icon), SelectedItem.Icon).Wait();
|
2020-03-31 19:19:02 +02:00
|
|
|
|
}
|
2017-09-29 18:08:20 +02:00
|
|
|
|
}
|
2017-10-06 14:56:16 +02:00
|
|
|
|
|
2017-10-18 13:57:10 +02:00
|
|
|
|
public DateTimeOffset ExpiryDate
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.ExpirationDate; }
|
2018-07-24 17:52:44 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!HasExpirationDate) return;
|
2020-04-14 13:44:07 +02:00
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.ExpirationDate = value.Date;
|
|
|
|
|
SetFieldValue("ExpirationDate", SelectedItem.ExpirationDate).Wait();
|
2018-07-24 17:52:44 +02:00
|
|
|
|
}
|
2017-10-18 13:57:10 +02:00
|
|
|
|
}
|
2017-11-06 19:01:01 +01:00
|
|
|
|
|
2017-10-18 13:57:10 +02:00
|
|
|
|
public TimeSpan ExpiryTime
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.ExpirationDate.TimeOfDay; }
|
2018-07-24 17:52:44 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!HasExpirationDate) return;
|
2020-04-14 13:44:07 +02:00
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.ExpirationDate = SelectedItem.ExpirationDate.Date.Add(value);
|
|
|
|
|
SetFieldValue("ExpirationDate", SelectedItem.ExpirationDate).Wait();
|
2018-07-24 17:52:44 +02:00
|
|
|
|
}
|
2017-10-18 13:57:10 +02:00
|
|
|
|
}
|
2020-03-31 19:19:02 +02:00
|
|
|
|
|
|
|
|
|
public bool HasExpirationDate
|
2017-10-06 14:56:16 +02:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem.HasExpirationDate; }
|
2017-10-13 11:48:58 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.HasExpirationDate = value;
|
2020-04-14 17:49:29 +02:00
|
|
|
|
SetFieldValue(nameof(HasExpirationDate), value).Wait();
|
2020-04-22 16:21:47 +02:00
|
|
|
|
RaisePropertyChanged(nameof(HasExpirationDate));
|
2017-10-13 11:48:58 +02:00
|
|
|
|
}
|
2017-10-06 14:56:16 +02:00
|
|
|
|
}
|
2020-03-31 19:19:02 +02:00
|
|
|
|
|
2020-04-14 17:49:29 +02:00
|
|
|
|
public SolidColorBrush BackgroundColor
|
2017-12-14 17:15:28 +01:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem?.BackgroundColor.ToSolidColorBrush(); }
|
2017-12-14 17:15:28 +01:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.BackgroundColor = value.ToColor();
|
|
|
|
|
SetFieldValue(nameof(BackgroundColor), SelectedItem.BackgroundColor).Wait();
|
2017-12-14 17:15:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-31 19:19:02 +02:00
|
|
|
|
|
2020-04-14 17:49:29 +02:00
|
|
|
|
public SolidColorBrush ForegroundColor
|
2017-10-06 17:57:36 +02:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return SelectedItem?.ForegroundColor.ToSolidColorBrush(); }
|
2017-10-13 11:48:58 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
SelectedItem.ForegroundColor = value.ToColor();
|
|
|
|
|
SetFieldValue(nameof(ForegroundColor), SelectedItem.ForegroundColor).Wait();
|
2017-10-13 11:48:58 +02:00
|
|
|
|
}
|
2017-10-06 17:57:36 +02:00
|
|
|
|
}
|
2020-04-15 19:06:13 +02:00
|
|
|
|
|
2020-03-31 19:19:02 +02:00
|
|
|
|
|
|
|
|
|
public bool IsEditMode
|
2017-10-18 13:57:10 +02:00
|
|
|
|
{
|
2020-04-16 14:08:50 +02:00
|
|
|
|
get { return IsCurrentEntry && _isEditMode; }
|
2020-04-22 16:21:47 +02:00
|
|
|
|
set { Set(() => IsEditMode, ref _isEditMode, value); }
|
2017-10-18 13:57:10 +02:00
|
|
|
|
}
|
2020-03-31 19:19:02 +02:00
|
|
|
|
|
|
|
|
|
public bool IsRevealPassword
|
2018-06-26 15:01:02 +02:00
|
|
|
|
{
|
2020-03-31 19:19:02 +02:00
|
|
|
|
get { return _isRevealPassword; }
|
2020-04-22 16:21:47 +02:00
|
|
|
|
set { Set(() => IsRevealPassword, ref _isRevealPassword, value); }
|
2018-06-26 15:01:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 20:02:43 +02:00
|
|
|
|
public RelayCommand SaveCommand { get; }
|
|
|
|
|
public RelayCommand GeneratePasswordCommand { get; }
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public RelayCommand<string> MoveCommand { get; }
|
2020-04-20 20:02:43 +02:00
|
|
|
|
public RelayCommand RestoreCommand { get; }
|
2020-04-21 19:12:26 +02:00
|
|
|
|
public RelayCommand DeleteCommand { get; }
|
|
|
|
|
public RelayCommand GoBackCommand { get; }
|
2020-04-28 18:54:37 +02:00
|
|
|
|
public RelayCommand GoToParentCommand { get; set; }
|
2020-05-06 18:54:39 +02:00
|
|
|
|
public RelayCommand<Attachment> OpenAttachmentCommand { get; set; }
|
2020-05-07 12:11:12 +02:00
|
|
|
|
public RelayCommand AddAttachmentCommand { get; set; }
|
|
|
|
|
public RelayCommand<Attachment> DeleteAttachmentCommand { get; set; }
|
2020-04-14 13:44:07 +02:00
|
|
|
|
|
|
|
|
|
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
|
|
|
|
|
2020-03-27 13:27:29 +01:00
|
|
|
|
private readonly IMediator _mediator;
|
2020-04-21 19:12:26 +02:00
|
|
|
|
private readonly INavigationService _navigation;
|
2020-04-22 11:58:06 +02:00
|
|
|
|
private readonly IResourceProxy _resource;
|
|
|
|
|
private readonly IDialogService _dialog;
|
2020-04-23 19:00:38 +02:00
|
|
|
|
private readonly INotificationService _notification;
|
2020-05-06 18:54:39 +02:00
|
|
|
|
private readonly IFileProxy _file;
|
2020-04-25 22:03:47 +02:00
|
|
|
|
private GroupVm _parent;
|
2020-04-16 14:08:50 +02:00
|
|
|
|
private EntryVm _selectedItem;
|
|
|
|
|
private int _selectedIndex;
|
2017-10-06 14:56:16 +02:00
|
|
|
|
private bool _isEditMode;
|
2017-10-06 17:57:36 +02:00
|
|
|
|
private bool _isRevealPassword;
|
2017-11-06 19:01:01 +01:00
|
|
|
|
private double _passwordLength = 25;
|
2020-04-16 14:08:50 +02:00
|
|
|
|
private bool _isDirty;
|
2017-11-22 18:54:03 +01:00
|
|
|
|
|
2020-05-06 18:54:39 +02:00
|
|
|
|
public EntryDetailVm(IMediator mediator, INavigationService navigation, IResourceProxy resource, IDialogService dialog, INotificationService notification, IFileProxy file)
|
2017-09-13 18:37:44 +02:00
|
|
|
|
{
|
2020-03-27 13:27:29 +01:00
|
|
|
|
_mediator = mediator;
|
2020-04-21 19:12:26 +02:00
|
|
|
|
_navigation = navigation;
|
2020-04-22 11:58:06 +02:00
|
|
|
|
_resource = resource;
|
|
|
|
|
_dialog = dialog;
|
2020-04-23 19:00:38 +02:00
|
|
|
|
_notification = notification;
|
2020-05-06 18:54:39 +02:00
|
|
|
|
_file = file;
|
2018-06-20 18:41:56 +02:00
|
|
|
|
|
2020-04-14 13:44:07 +02:00
|
|
|
|
SaveCommand = new RelayCommand(async () => await SaveChanges(), () => Database.IsDirty);
|
2020-03-27 13:27:29 +01:00
|
|
|
|
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
|
2020-04-30 19:40:48 +02:00
|
|
|
|
MoveCommand = new RelayCommand<string>(async destination => await Move(destination), destination => _parent != null && !string.IsNullOrEmpty(destination) && destination != _parent.Id);
|
2020-04-15 19:06:13 +02:00
|
|
|
|
RestoreCommand = new RelayCommand(async () => await RestoreHistory());
|
2020-04-21 19:12:26 +02:00
|
|
|
|
DeleteCommand = new RelayCommand(async () => await AskForDelete());
|
|
|
|
|
GoBackCommand = new RelayCommand(() => _navigation.GoBack());
|
2020-04-28 18:54:37 +02:00
|
|
|
|
GoToParentCommand = new RelayCommand(() => GoToGroup(_parent.Id));
|
2020-05-06 18:54:39 +02:00
|
|
|
|
OpenAttachmentCommand = new RelayCommand<Attachment>(async attachment => await OpenAttachment(attachment));
|
2020-05-07 12:11:12 +02:00
|
|
|
|
AddAttachmentCommand = new RelayCommand(async () => await AddAttachment(), () => IsCurrentEntry);
|
|
|
|
|
DeleteAttachmentCommand = new RelayCommand<Attachment>(async attachment => await DeleteAttachment(attachment));
|
2020-05-04 14:29:52 +02:00
|
|
|
|
|
|
|
|
|
MessengerInstance.Register<DatabaseSavedMessage>(this, _ => SaveCommand.RaiseCanExecuteChanged());
|
2020-04-21 19:12:26 +02:00
|
|
|
|
}
|
2020-05-07 12:11:12 +02:00
|
|
|
|
|
2020-04-25 22:03:47 +02:00
|
|
|
|
public async Task Initialize(string entryId)
|
|
|
|
|
{
|
2020-05-07 12:11:12 +02:00
|
|
|
|
SelectedIndex = 0;
|
2020-04-25 22:03:47 +02:00
|
|
|
|
SelectedItem = await _mediator.Send(new GetEntryQuery { Id = entryId });
|
|
|
|
|
_parent = await _mediator.Send(new GetGroupQuery { Id = SelectedItem.ParentGroupId });
|
|
|
|
|
History = new ObservableCollection<EntryVm> { SelectedItem };
|
|
|
|
|
foreach (var entry in SelectedItem.History.Skip(1))
|
|
|
|
|
{
|
|
|
|
|
History.Add(entry);
|
|
|
|
|
}
|
2020-05-07 12:11:12 +02:00
|
|
|
|
History.CollectionChanged += (sender, args) => SaveCommand.RaiseCanExecuteChanged();
|
2020-04-25 22:03:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 19:12:26 +02:00
|
|
|
|
private async Task AskForDelete()
|
|
|
|
|
{
|
2020-04-22 11:58:06 +02:00
|
|
|
|
if (IsCurrentEntry)
|
|
|
|
|
{
|
2020-04-23 19:00:38 +02:00
|
|
|
|
if (IsRecycleOnDelete)
|
|
|
|
|
{
|
|
|
|
|
await Delete();
|
|
|
|
|
_notification.Show(_resource.GetResourceValue("EntryRecyclingConfirmation"), _resource.GetResourceValue("EntryRecycled"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _dialog.ShowMessage(_resource.GetResourceValue("EntryDeletingConfirmation"),
|
|
|
|
|
_resource.GetResourceValue("EntityDeleteTitle"),
|
|
|
|
|
_resource.GetResourceValue("EntityDeleteActionButton"),
|
|
|
|
|
_resource.GetResourceValue("EntityDeleteCancelButton"),
|
|
|
|
|
async isOk =>
|
2020-04-22 11:58:06 +02:00
|
|
|
|
{
|
2020-04-23 19:00:38 +02:00
|
|
|
|
if (isOk) await Delete();
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-04-22 11:58:06 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _dialog.ShowMessage(_resource.GetResourceValue("HistoryDeleteDescription"), _resource.GetResourceValue("HistoryDeleteTitle"),
|
|
|
|
|
_resource.GetResourceValue("EntityDeleteActionButton"),
|
|
|
|
|
_resource.GetResourceValue("EntityDeleteCancelButton"), async isOk =>
|
|
|
|
|
{
|
2020-04-23 19:00:38 +02:00
|
|
|
|
if (!isOk) return;
|
|
|
|
|
await _mediator.Send(new DeleteHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
|
|
|
|
History.RemoveAt(SelectedIndex);
|
|
|
|
|
SelectedIndex = 0;
|
2020-04-22 11:58:06 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2017-10-02 18:40:54 +02:00
|
|
|
|
}
|
2020-04-15 19:06:13 +02:00
|
|
|
|
|
2020-03-27 13:27:29 +01:00
|
|
|
|
public async Task GeneratePassword()
|
2017-10-16 18:31:45 +02:00
|
|
|
|
{
|
2020-03-27 13:27:29 +01:00
|
|
|
|
Password = await _mediator.Send(new GeneratePasswordCommand
|
2017-10-16 18:31:45 +02:00
|
|
|
|
{
|
2020-03-27 13:27:29 +01:00
|
|
|
|
BracketsPatternSelected = BracketsPatternSelected,
|
|
|
|
|
CustomChars = CustomChars,
|
|
|
|
|
DigitsPatternSelected = DigitsPatternSelected,
|
|
|
|
|
LowerCasePatternSelected = LowerCasePatternSelected,
|
|
|
|
|
MinusPatternSelected = MinusPatternSelected,
|
|
|
|
|
PasswordLength = (int)PasswordLength,
|
|
|
|
|
SpacePatternSelected = SpacePatternSelected,
|
|
|
|
|
SpecialPatternSelected = SpecialPatternSelected,
|
|
|
|
|
UnderscorePatternSelected = UnderscorePatternSelected,
|
|
|
|
|
UpperCasePatternSelected = UpperCasePatternSelected
|
|
|
|
|
});
|
2020-04-22 16:21:47 +02:00
|
|
|
|
RaisePropertyChanged(nameof(IsRevealPasswordEnabled));
|
2017-10-16 18:31:45 +02:00
|
|
|
|
}
|
2018-06-20 18:41:56 +02:00
|
|
|
|
|
2020-04-28 15:20:47 +02:00
|
|
|
|
public async Task Move(string destination)
|
2017-10-18 10:32:51 +02:00
|
|
|
|
{
|
2020-04-28 15:20:47 +02:00
|
|
|
|
await _mediator.Send(new AddEntryCommand { ParentGroupId = destination, EntryId = Id });
|
|
|
|
|
await _mediator.Send(new RemoveEntryCommand { ParentGroupId = _parent.Id, EntryId = Id });
|
2020-04-28 18:54:37 +02:00
|
|
|
|
GoToGroup(destination);
|
2017-10-31 18:49:18 +01:00
|
|
|
|
}
|
2020-04-03 17:33:53 +02:00
|
|
|
|
|
|
|
|
|
public async Task SetFieldValue(string fieldName, object value)
|
2018-06-18 18:40:00 +02:00
|
|
|
|
{
|
2020-04-03 17:33:53 +02:00
|
|
|
|
await _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = fieldName, FieldValue = value });
|
2020-04-20 20:02:43 +02:00
|
|
|
|
SaveCommand.RaiseCanExecuteChanged();
|
2020-04-16 14:08:50 +02:00
|
|
|
|
_isDirty = true;
|
2020-04-14 19:59:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task AddHistory()
|
|
|
|
|
{
|
2020-04-16 17:16:03 +02:00
|
|
|
|
if (_isDirty) await _mediator.Send(new AddHistoryCommand { Entry = History[0] });
|
2018-06-18 18:40:00 +02:00
|
|
|
|
}
|
2020-04-16 14:08:50 +02:00
|
|
|
|
|
2020-05-06 18:54:39 +02:00
|
|
|
|
public void GoToGroup(string groupId)
|
|
|
|
|
{
|
|
|
|
|
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = groupId });
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 14:08:50 +02:00
|
|
|
|
private async Task RestoreHistory()
|
2020-04-01 12:48:36 +02:00
|
|
|
|
{
|
2020-04-22 11:58:06 +02:00
|
|
|
|
await _mediator.Send(new RestoreHistoryCommand { Entry = History[0], HistoryIndex = History.Count - SelectedIndex - 1 });
|
2020-04-16 14:08:50 +02:00
|
|
|
|
History.Insert(0, SelectedItem);
|
|
|
|
|
SelectedIndex = 0;
|
2020-04-01 12:48:36 +02:00
|
|
|
|
}
|
2020-04-22 11:58:06 +02:00
|
|
|
|
|
2020-04-14 13:44:07 +02:00
|
|
|
|
private async Task SaveChanges()
|
|
|
|
|
{
|
2020-04-14 19:59:19 +02:00
|
|
|
|
await AddHistory();
|
2020-05-04 12:48:27 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _mediator.Send(new SaveDatabaseCommand());
|
|
|
|
|
}
|
|
|
|
|
catch (SaveException e)
|
|
|
|
|
{
|
|
|
|
|
MessengerInstance.Send(new SaveErrorMessage { Message = e.Message });
|
|
|
|
|
}
|
2020-04-20 20:02:43 +02:00
|
|
|
|
SaveCommand.RaiseCanExecuteChanged();
|
2020-04-16 14:08:50 +02:00
|
|
|
|
_isDirty = false;
|
2020-04-14 13:44:07 +02:00
|
|
|
|
}
|
2020-04-23 19:00:38 +02:00
|
|
|
|
|
|
|
|
|
private async Task Delete()
|
|
|
|
|
{
|
|
|
|
|
await _mediator.Send(new DeleteEntryCommand
|
|
|
|
|
{
|
|
|
|
|
EntryId = Id,
|
|
|
|
|
ParentGroupId = SelectedItem.ParentGroupId,
|
|
|
|
|
RecycleBinName = _resource.GetResourceValue("RecycleBinTitle")
|
|
|
|
|
});
|
|
|
|
|
_navigation.GoBack();
|
|
|
|
|
}
|
2020-04-28 18:54:37 +02:00
|
|
|
|
|
2020-05-06 18:54:39 +02:00
|
|
|
|
private async Task OpenAttachment(Attachment attachment)
|
2020-04-28 18:54:37 +02:00
|
|
|
|
{
|
2020-05-06 18:54:39 +02:00
|
|
|
|
var extensionIndex = attachment.Name.LastIndexOf('.');
|
|
|
|
|
var fileInfo = await _file.CreateFile(attachment.Name,
|
|
|
|
|
attachment.Name.Substring(extensionIndex, attachment.Name.Length - extensionIndex),
|
|
|
|
|
string.Empty,
|
|
|
|
|
false);
|
|
|
|
|
if (fileInfo == null) return;
|
|
|
|
|
await _file.WriteBinaryContentsToFile(fileInfo.Id, attachment.Content);
|
2020-04-28 18:54:37 +02:00
|
|
|
|
}
|
2020-05-07 12:11:12 +02:00
|
|
|
|
|
|
|
|
|
private async Task AddAttachment()
|
|
|
|
|
{
|
|
|
|
|
var fileInfo = await _file.OpenFile(string.Empty, Domain.Common.Constants.Extensions.Any, false);
|
|
|
|
|
if (fileInfo == null) return;
|
|
|
|
|
var contents = await _file.ReadBinaryFile(fileInfo.Id);
|
|
|
|
|
await _mediator.Send(new AddAttachmentCommand { Entry = SelectedItem, AttachmentName = fileInfo.Name, AttachmentContent = contents });
|
|
|
|
|
Attachments.Add(new Attachment { Name = fileInfo.Name, Content = contents });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task DeleteAttachment(Attachment attachment)
|
|
|
|
|
{
|
|
|
|
|
await _mediator.Send(new DeleteAttachmentCommand { Entry = SelectedItem, AttachmentName = attachment.Name });
|
|
|
|
|
Attachments.Remove(attachment);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-12 18:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|