Create database works with new Vm

Refactoring
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-22 16:21:47 +02:00
parent a88051bc0c
commit a7da427ded
36 changed files with 371 additions and 274 deletions

View File

@@ -1,27 +0,0 @@
using Windows.ApplicationModel;
namespace ModernKeePass.ViewModels
{
public class AboutVm
{
private readonly Package _package;
public string Name => _package.DisplayName;
public string Version
{
get
{
var version = _package.Id.Version;
return $"{version.Major}.{version.Minor}";
}
}
public AboutVm() : this(Package.Current) { }
public AboutVm(Package package)
{
_package = package;
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
@@ -10,12 +11,11 @@ using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Database.Queries.OpenDatabase;
using ModernKeePass.Application.Security.Commands.GenerateKeyFile;
using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels
{
public class CompositeKeyVm: NotifyPropertyChangedBase
public class CompositeKeyVm: ObservableObject
{
public enum StatusTypes
{
@@ -30,8 +30,8 @@ namespace ModernKeePass.ViewModels
get { return _hasPassword; }
set
{
SetProperty(ref _hasPassword, value);
OnPropertyChanged(nameof(IsValid));
Set(() => HasPassword, ref _hasPassword, value);
RaisePropertyChanged(nameof(IsValid));
}
}
@@ -40,8 +40,8 @@ namespace ModernKeePass.ViewModels
get { return _hasKeyFile; }
set
{
SetProperty(ref _hasKeyFile, value);
OnPropertyChanged(nameof(IsValid));
Set(() => HasKeyFile, ref _hasKeyFile, value);
RaisePropertyChanged(nameof(IsValid));
}
}
@@ -50,13 +50,13 @@ namespace ModernKeePass.ViewModels
public string Status
{
get { return _status; }
set { SetProperty(ref _status, value); }
set { Set(() => Status, ref _status, value); }
}
public int StatusType
{
get { return (int)_statusType; }
set { SetProperty(ref _statusType, (StatusTypes)value); }
get { return _statusType; }
set { Set(() => StatusType, ref _statusType, value); }
}
public string Password
@@ -65,7 +65,7 @@ namespace ModernKeePass.ViewModels
set
{
_password = value;
OnPropertyChanged(nameof(PasswordComplexityIndicator));
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
StatusType = (int)StatusTypes.Normal;
Status = string.Empty;
}
@@ -77,14 +77,14 @@ namespace ModernKeePass.ViewModels
set
{
_keyFilePath = value;
OnPropertyChanged(nameof(IsValid));
RaisePropertyChanged(nameof(IsValid));
}
}
public string KeyFileText
{
get { return _keyFileText; }
set { SetProperty(ref _keyFileText, value); }
set { Set(() => KeyFileText, ref _keyFileText, value); }
}
public string RootGroupId { get; set; }
@@ -96,7 +96,7 @@ namespace ModernKeePass.ViewModels
private bool _isOpening;
private string _password = string.Empty;
private string _status;
private StatusTypes _statusType;
private int _statusType;
private string _keyFilePath;
private string _keyFileText;
private readonly IMediator _mediator;
@@ -121,7 +121,7 @@ namespace ModernKeePass.ViewModels
try
{
_isOpening = true;
OnPropertyChanged(nameof(IsValid));
RaisePropertyChanged(nameof(IsValid));
if (createNew)
{
await _mediator.Send(new CreateDatabaseCommand
@@ -159,7 +159,7 @@ namespace ModernKeePass.ViewModels
finally
{
_isOpening = false;
OnPropertyChanged(nameof(IsValid));
RaisePropertyChanged(nameof(IsValid));
}
return false;
}

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
@@ -27,13 +28,12 @@ using ModernKeePass.Application.Security.Queries.EstimatePasswordComplexity;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Interfaces;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Extensions;
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
public class EntryDetailVm : NotifyPropertyChangedBase, IVmEntity
public class EntryDetailVm : ObservableObject, IVmEntity
{
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
@@ -71,8 +71,8 @@ namespace ModernKeePass.ViewModels
get { return _selectedItem; }
set
{
SetProperty(ref _selectedItem, value);
if (value != null) OnPropertyChanged();
Set(() => SelectedItem, ref _selectedItem, value);
if (value != null) RaisePropertyChanged();
}
}
public int SelectedIndex
@@ -80,15 +80,15 @@ namespace ModernKeePass.ViewModels
get { return _selectedIndex; }
set
{
SetProperty(ref _selectedIndex, value);
OnPropertyChanged(nameof(IsCurrentEntry));
Set(() => SelectedIndex, ref _selectedIndex, value);
RaisePropertyChanged(nameof(IsCurrentEntry));
}
}
public double PasswordLength
{
get { return _passwordLength; }
set { SetProperty(ref _passwordLength, value); }
set { Set(() => PasswordLength, ref _passwordLength, value); }
}
public string Title
@@ -114,8 +114,8 @@ namespace ModernKeePass.ViewModels
{
SelectedItem.Password = value;
SetFieldValue(nameof(Password), value).Wait();
OnPropertyChanged(nameof(Password));
OnPropertyChanged(nameof(PasswordComplexityIndicator));
RaisePropertyChanged(nameof(Password));
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
}
}
@@ -180,7 +180,7 @@ namespace ModernKeePass.ViewModels
{
SelectedItem.HasExpirationDate = value;
SetFieldValue(nameof(HasExpirationDate), value).Wait();
OnPropertyChanged(nameof(HasExpirationDate));
RaisePropertyChanged(nameof(HasExpirationDate));
}
}
@@ -208,13 +208,13 @@ namespace ModernKeePass.ViewModels
public bool IsEditMode
{
get { return IsCurrentEntry && _isEditMode; }
set { SetProperty(ref _isEditMode, value); }
set { Set(() => IsEditMode, ref _isEditMode, value); }
}
public bool IsRevealPassword
{
get { return _isRevealPassword; }
set { SetProperty(ref _isRevealPassword, value); }
set { Set(() => IsRevealPassword, ref _isRevealPassword, value); }
}
public RelayCommand SaveCommand { get; }
@@ -332,7 +332,7 @@ namespace ModernKeePass.ViewModels
UnderscorePatternSelected = UnderscorePatternSelected,
UpperCasePatternSelected = UpperCasePatternSelected
});
OnPropertyChanged(nameof(IsRevealPasswordEnabled));
RaisePropertyChanged(nameof(IsRevealPasswordEnabled));
}
public async Task Move(GroupVm destination)

View File

@@ -5,6 +5,7 @@ using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
@@ -27,7 +28,6 @@ using ModernKeePass.Application.Group.Models;
using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Group.Queries.SearchEntries;
using ModernKeePass.Common;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Interfaces;
using ModernKeePass.Models;
@@ -35,7 +35,7 @@ using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
public class GroupDetailVm : NotifyPropertyChangedBase, IVmEntity
public class GroupDetailVm : ObservableObject, IVmEntity
{
public ObservableCollection<EntryVm> Entries { get; }
@@ -75,7 +75,7 @@ namespace ModernKeePass.ViewModels
get { return _isEditMode; }
set
{
SetProperty(ref _isEditMode, value);
Set(() => IsEditMode, ref _isEditMode, value);
SortEntriesCommand.RaiseCanExecuteChanged();
SortGroupsCommand.RaiseCanExecuteChanged();
}
@@ -234,14 +234,14 @@ namespace ModernKeePass.ViewModels
private async Task SortEntriesAsync()
{
await _mediator.Send(new SortEntriesCommand {Group = _group});
OnPropertyChanged(nameof(Entries));
RaisePropertyChanged(nameof(Entries));
SaveCommand.RaiseCanExecuteChanged();
}
private async Task SortGroupsAsync()
{
await _mediator.Send(new SortGroupsCommand {Group = _group});
OnPropertyChanged(nameof(Groups));
RaisePropertyChanged(nameof(Groups));
SaveCommand.RaiseCanExecuteChanged();
}
}

View File

@@ -2,11 +2,11 @@
using System.Linq;
using Windows.ApplicationModel;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.Models;
@@ -15,17 +15,17 @@ using ModernKeePass.Views;
namespace ModernKeePass.ViewModels
{
public class MainVm : NotifyPropertyChangedBase, IHasSelectableObject
public class MainVm : ObservableObject, IHasSelectableObject
{
private IOrderedEnumerable<IGrouping<string, MainMenuItemVm>> _mainMenuItems;
private MainMenuItemVm _selectedItem;
private ISelectableModel _selectedItem;
public string Name { get; } = Package.Current.DisplayName;
public IOrderedEnumerable<IGrouping<string, MainMenuItemVm>> MainMenuItems
{
get { return _mainMenuItems; }
set { SetProperty(ref _mainMenuItems, value); }
set { Set(() => MainMenuItems, ref _mainMenuItems, value); }
}
public ISelectableModel SelectedItem
@@ -39,7 +39,7 @@ namespace ModernKeePass.ViewModels
_selectedItem.IsSelected = false;
}
SetProperty(ref _selectedItem, (MainMenuItemVm)value);
Set(() => SelectedItem, ref _selectedItem, value);
if (_selectedItem != null)
{

View File

@@ -1,28 +0,0 @@
using Windows.Storage;
using ModernKeePass.Application.Common.Interfaces;
namespace ModernKeePass.ViewModels
{
public class NewVm : OpenVm
{
private string _importFormatHelp;
public bool IsImportChecked { get; set; }
public IStorageFile ImportFile { get; set; }
public string ImportFileExtensionFilter { get; set; } = "*";
public IImportFormat ImportFormat { get; set; }
public string ImportFormatHelp
{
get { return _importFormatHelp; }
set
{
_importFormatHelp = value;
OnPropertyChanged(nameof(ImportFormatHelp));
}
}
}
}

View File

@@ -1,56 +0,0 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels
{
public class OpenVm: NotifyPropertyChangedBase
{
private readonly IRecentProxy _recent;
private string _name;
private string _path;
private string _token;
public bool IsFileSelected => !string.IsNullOrEmpty(Path);
public string Token
{
get { return _token; }
set { SetProperty(ref _token, value); }
}
public string Name
{
get { return _name; }
private set { SetProperty(ref _name, value); }
}
public string Path
{
get { return _path; }
private set { SetProperty(ref _path, value); }
}
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
public OpenVm(IRecentProxy recent)
{
_recent = recent;
}
public async Task OpenFile(FileInfo file)
{
Token = file.Id;
Name = file.Name;
Path = file.Path;
OnPropertyChanged(nameof(IsFileSelected));
await AddToRecentList(file);
}
private async Task AddToRecentList(FileInfo file)
{
await _recent.Add(file);
}
}
}

View File

@@ -1,69 +0,0 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.ViewModels.ListItems;
namespace ModernKeePass.ViewModels
{
public class RecentVm : NotifyPropertyChangedBase, IHasSelectableObject
{
private readonly IRecentProxy _recent;
private ISelectableModel _selectedItem;
private ObservableCollection<RecentItemVm> _recentItems;
public ObservableCollection<RecentItemVm> RecentItems
{
get { return _recentItems; }
set { SetProperty(ref _recentItems, value); }
}
public ISelectableModel SelectedItem
{
get { return _selectedItem; }
set
{
if (_selectedItem == value) return;
if (_selectedItem != null)
{
_selectedItem.IsSelected = false;
}
SetProperty(ref _selectedItem, value);
if (_selectedItem == null) return;
_selectedItem.IsSelected = true;
}
}
public ICommand ClearAllCommand { get; }
public RecentVm() : this (App.Services.GetRequiredService<IRecentProxy>()) { }
public RecentVm(IRecentProxy recent)
{
_recent = recent;
ClearAllCommand = new RelayCommand(ClearAll);
var recentItems = _recent.GetAll().Select(r => new RecentItemVm(r));
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
if (RecentItems.Count > 0)
SelectedItem = RecentItems[0];
}
public void UpdateAccessTime(string token)
{
_recent.Get(token, true).Wait();
}
private void ClearAll()
{
_recent.ClearAll();
RecentItems.Clear();
}
}
}

View File

@@ -1,55 +0,0 @@
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.AccessCache;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Database.Commands.CloseDatabase;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Common;
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
public class SaveVm
{
public bool IsSaveEnabled => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult().IsDirty;
public RelayCommand SaveCommand { get; }
public RelayCommand CloseCommand { get; }
private readonly IMediator _mediator;
private readonly INavigationService _navigation;
public SaveVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<INavigationService>()) { }
public SaveVm(IMediator mediator, INavigationService navigation)
{
_mediator = mediator;
_navigation = navigation;
SaveCommand = new RelayCommand(async () => await Save(), () => IsSaveEnabled);
CloseCommand = new RelayCommand(async () => await Close());
}
public async Task Save(bool close = true)
{
await _mediator.Send(new SaveDatabaseCommand());
if (close) await _mediator.Send(new CloseDatabaseCommand());
_navigation.NavigateTo(Constants.Navigation.MainPage);
}
public async Task Save(StorageFile file)
{
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
await _mediator.Send(new SaveDatabaseCommand { FilePath = token });
_navigation.NavigateTo(Constants.Navigation.MainPage);
}
public async Task Close()
{
await _mediator.Send(new CloseDatabaseCommand());
_navigation.NavigateTo(Constants.Navigation.MainPage);
}
}
}

View File

@@ -1,27 +1,27 @@
using System.Collections.ObjectModel;
using System.Linq;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Interfaces;
using ModernKeePass.ViewModels.ListItems;
using ModernKeePass.Views;
namespace ModernKeePass.ViewModels
{
public class SettingsVm : NotifyPropertyChangedBase, IHasSelectableObject
public class SettingsVm : ObservableObject, IHasSelectableObject
{
private ListMenuItemVm _selectedItem;
private ISelectableModel _selectedItem;
private IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> _menuItems;
public IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> MenuItems
{
get { return _menuItems; }
set { SetProperty(ref _menuItems, value); }
set { Set(() => MenuItems, ref _menuItems, value); }
}
public ISelectableModel SelectedItem
@@ -35,7 +35,7 @@ namespace ModernKeePass.ViewModels
_selectedItem.IsSelected = false;
}
SetProperty(ref _selectedItem, (ListMenuItemVm)value);
Set(() => SelectedItem, ref _selectedItem, value);
if (_selectedItem != null)
{