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

@@ -22,7 +22,7 @@ namespace ModernKeePass.Application.Common.Interfaces
Task Open(byte[] file, Credentials credentials); Task Open(byte[] file, Credentials credentials);
Task ReOpen(byte[] file); Task ReOpen(byte[] file);
Task Create(Credentials credentials, string name, DatabaseVersion version = DatabaseVersion.V2); Task Create(Credentials credentials, string name, DatabaseVersion version = DatabaseVersion.V3);
Task<byte[]> SaveDatabase(); Task<byte[]> SaveDatabase();
Task<byte[]> SaveDatabase(byte[] newFileContents); Task<byte[]> SaveDatabase(byte[] newFileContents);
void UpdateCredentials(Credentials credentials); void UpdateCredentials(Credentials credentials);

View File

@@ -13,6 +13,7 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
public string Password { get; set; } public string Password { get; set; }
public string KeyFilePath { get; set; } public string KeyFilePath { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Version { get; set; }
public bool CreateSampleData { get; set; } public bool CreateSampleData { get; set; }
public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand> public class CreateDatabaseCommandHandler : IAsyncRequestHandler<CreateDatabaseCommand>
@@ -30,12 +31,25 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
{ {
if (_database.IsOpen) throw new DatabaseOpenException(); if (_database.IsOpen) throw new DatabaseOpenException();
var version = DatabaseVersion.V2;
switch (message.Version)
{
case "4":
version = DatabaseVersion.V4;
break;
case "3":
version = DatabaseVersion.V3;
break;
}
await _database.Create(new Credentials await _database.Create(new Credentials
{ {
KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath) : null, KeyFileContents = !string.IsNullOrEmpty(message.KeyFilePath) ? await _file.OpenBinaryFile(message.KeyFilePath) : null,
Password = message.Password Password = message.Password
}, message.Name); }, message.Name, version);
_database.FileAccessToken = message.FilePath; _database.FileAccessToken = message.FilePath;
var contents = await _database.SaveDatabase();
await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);
if (message.CreateSampleData) if (message.CreateSampleData)
{ {

View File

@@ -1,28 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace ModernKeePass.Domain.AOP
{
public class NotifyPropertyChangedBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected bool SetProperty<T>(ref T property, T value, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<T>.Default.Equals(property, value))
{
return false;
}
property = value;
OnPropertyChanged(propertyName);
return true;
}
}
}

View File

@@ -75,7 +75,6 @@
<None Include="project.json" /> <None Include="project.json" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AOP\NotifyPropertyChangedBase.cs" />
<Compile Include="Common\Constants.cs" /> <Compile Include="Common\Constants.cs" />
<Compile Include="Dtos\Credentials.cs" /> <Compile Include="Dtos\Credentials.cs" />
<Compile Include="Dtos\FileInfo.cs" /> <Compile Include="Dtos\FileInfo.cs" />

View File

@@ -3,6 +3,7 @@
public enum DatabaseVersion public enum DatabaseVersion
{ {
V2, V2,
V3,
V4 V4
} }
} }

View File

@@ -11,6 +11,7 @@ using ModernKeePass.Domain.Enums;
using ModernKeePass.Domain.Interfaces; using ModernKeePass.Domain.Interfaces;
using ModernKeePassLib; using ModernKeePassLib;
using ModernKeePassLib.Collections; using ModernKeePassLib.Collections;
using ModernKeePassLib.Cryptography.Cipher;
using ModernKeePassLib.Cryptography.KeyDerivation; using ModernKeePassLib.Cryptography.KeyDerivation;
using ModernKeePassLib.Interfaces; using ModernKeePassLib.Interfaces;
using ModernKeePassLib.Keys; using ModernKeePassLib.Keys;
@@ -112,7 +113,7 @@ namespace ModernKeePass.Infrastructure.KeePass
await Open(file, _credentials); await Open(file, _credentials);
} }
public async Task Create(Credentials credentials, string name, DatabaseVersion version = DatabaseVersion.V2) public async Task Create(Credentials credentials, string name, DatabaseVersion version = DatabaseVersion.V4)
{ {
try try
{ {
@@ -131,6 +132,7 @@ namespace ModernKeePass.Infrastructure.KeePass
{ {
case DatabaseVersion.V4: case DatabaseVersion.V4:
_pwDatabase.KdfParameters = KdfPool.Get("Argon2").GetDefaultParameters(); _pwDatabase.KdfParameters = KdfPool.Get("Argon2").GetDefaultParameters();
_pwDatabase.DataCipherUuid = CipherPool.GlobalPool[1].CipherUuid;
break; break;
} }
}); });

View File

@@ -116,6 +116,10 @@ namespace ModernKeePass
} }
}); });
} }
else
{
await _dialog.ShowError(realException, realException.Message, "OK", () => {});
}
} }
/// <summary> /// <summary>

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,29 +7,19 @@
xmlns:converters="using:ModernKeePass.Converters" xmlns:converters="using:ModernKeePass.Converters"
xmlns:viewModels="using:ModernKeePass.ViewModels" xmlns:viewModels="using:ModernKeePass.ViewModels"
xmlns:userControls="using:ModernKeePass.Views.UserControls" xmlns:userControls="using:ModernKeePass.Views.UserControls"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<viewModels:NewVm x:Key="ViewModel"/>
</Page.Resources> </Page.Resources>
<Page.DataContext>
<viewModels:NewVm />
</Page.DataContext>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<HyperlinkButton x:Uid="NewCreateButton" Click="CreateDatabaseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" /> <HyperlinkButton x:Uid="NewCreateButton" Click="CreateDatabaseButton_OnClick" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}" />
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" /> <TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="15,0,0,30" x:Uid="NewCreateDesc" />
<Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}"> <Border HorizontalAlignment="Left" BorderThickness="1" BorderBrush="AliceBlue" Width="550" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel Margin="25,0,25,0"> <StackPanel Margin="25,0,25,0">
<TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Name}" />
<userControls:CompositeKeyUserControl x:Uid="CompositeKeyNewButton" CreateNew="True" DatabaseFilePath="{Binding Token}"> <userControls:SetCredentialsUserControl x:Uid="CompositeKeyNewButton" />
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="ValidationChecked">
<core:NavigateToPageAction TargetPage="ModernKeePass.Views.GroupDetailPage" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</userControls:CompositeKeyUserControl>
</StackPanel> </StackPanel>
</Border> </Border>
<CheckBox x:Name="CheckBox" x:Uid="NewImportCheckbox" Margin="15,10,0,0" IsChecked="{Binding IsImportChecked, Mode=TwoWay}" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}" /> <CheckBox x:Name="CheckBox" x:Uid="NewImportCheckbox" Margin="15,10,0,0" IsChecked="{Binding IsImportChecked, Mode=TwoWay}" Visibility="{Binding IsFileSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />

View File

@@ -20,7 +20,7 @@ namespace ModernKeePass.Views
public sealed partial class NewDatabasePage public sealed partial class NewDatabasePage
{ {
private readonly IResourceProxy _resource; private readonly IResourceProxy _resource;
public NewVm Model => (NewVm)DataContext; private NewVm Model => (NewVm)Resources["ViewModel"];
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { } public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
public NewDatabasePage(IResourceProxy resource) public NewDatabasePage(IResourceProxy resource)

View File

@@ -8,16 +8,18 @@
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems" xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<CollectionViewSource x:Name="RecycleBinGroups" Source="{Binding Groups}" />
<CollectionViewSource x:Name="Ciphers" Source="{Binding Ciphers}" />
<CollectionViewSource x:Name="Compressions" Source="{Binding Compressions}" />
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding KeyDerivations}" />
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/> <converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
<listItems:SettingsDatabaseVm x:Key="ViewModel"/> <listItems:SettingsDatabaseVm x:Key="ViewModel"/>
</Page.Resources> </Page.Resources>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel.Resources>
<CollectionViewSource x:Name="RecycleBinGroups" Source="{Binding Groups}" />
<CollectionViewSource x:Name="Ciphers" Source="{Binding Ciphers}" />
<CollectionViewSource x:Name="Compressions" Source="{Binding Compressions}" />
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding KeyDerivations}" />
</StackPanel.Resources>
<ToggleSwitch x:Uid="SettingsDatabaseRecycleBin" IsOn="{Binding HasRecycleBin, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" /> <ToggleSwitch x:Uid="SettingsDatabaseRecycleBin" IsOn="{Binding HasRecycleBin, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" />
<StackPanel Visibility="{Binding HasRecycleBin, Converter={StaticResource BooleanToVisibilityConverter}}"> <StackPanel Visibility="{Binding HasRecycleBin, Converter={StaticResource BooleanToVisibilityConverter}}">
<RadioButton x:Uid="SettingsDatabaseRecycleBinCreate" GroupName="Recycle" IsChecked="{Binding IsNewRecycleBin, Mode=TwoWay}" /> <RadioButton x:Uid="SettingsDatabaseRecycleBinCreate" GroupName="Recycle" IsChecked="{Binding IsNewRecycleBin, Mode=TwoWay}" />

View File

@@ -7,11 +7,13 @@
xmlns:listItems="using:ModernKeePass.ViewModels.ListItems" xmlns:listItems="using:ModernKeePass.ViewModels.ListItems"
mc:Ignorable="d"> mc:Ignorable="d">
<Page.Resources> <Page.Resources>
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding FileFormats}" />
<listItems:SettingsNewVm x:Key="ViewModel"/> <listItems:SettingsNewVm x:Key="ViewModel"/>
</Page.Resources> </Page.Resources>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" DataContext="{StaticResource ViewModel}">
<StackPanel.Resources>
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding FileFormats}" />
</StackPanel.Resources>
<TextBlock x:Uid="SettingsNewDatabaseDesc" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,10"/> <TextBlock x:Uid="SettingsNewDatabaseDesc" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,0,0,10"/>
<ToggleSwitch x:Uid="SettingsNewDatabaseSample" IsOn="{Binding IsCreateSample, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" /> <ToggleSwitch x:Uid="SettingsNewDatabaseSample" IsOn="{Binding IsCreateSample, Mode=TwoWay}" Style="{StaticResource MainColorToggleSwitch}" />
<TextBlock x:Uid="SettingsNewDatabaseKdf" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,20,0,10" /> <TextBlock x:Uid="SettingsNewDatabaseKdf" Style="{StaticResource TextBlockSettingsHeaderStyle}" Margin="5,20,0,10" />
@@ -21,7 +23,7 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource KeyDerivations}}" SelectedItem="{Binding FileFormatVersion, Mode=TwoWay}" ItemContainerStyle="{StaticResource MainColorComboBoxItem}" Style="{StaticResource MainColorComboBox}" /> <ComboBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource KeyDerivations}}" SelectedItem="{Binding DatabaseFormatVersion, Mode=TwoWay}" DisplayMemberPath="DisplayText" ItemContainerStyle="{StaticResource MainColorComboBoxItem}" Style="{StaticResource MainColorComboBox}" />
<Button Grid.Column="2" Style="{StaticResource TextBlockButtonStyle}"> <Button Grid.Column="2" Style="{StaticResource TextBlockButtonStyle}">
<SymbolIcon Symbol="Help" RenderTransformOrigin="0.5,0.5" > <SymbolIcon Symbol="Help" RenderTransformOrigin="0.5,0.5" >
<SymbolIcon.RenderTransform> <SymbolIcon.RenderTransform>

View File

@@ -12,12 +12,9 @@
<UserControl.Resources> <UserControl.Resources>
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/> <converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/> <converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
<viewModels:OpenDatabaseControlVm x:Key="ViewModel"/>
</UserControl.Resources> </UserControl.Resources>
<Grid x:Name="Grid"> <Grid DataContext="{StaticResource ViewModel}">
<!-- DataContext is not set at the root of the control because of issues happening when displaying it -->
<Grid.DataContext>
<viewModels:OpenDatabaseControlVm />
</Grid.DataContext>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="50" /> <ColumnDefinition Width="50" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />

View File

@@ -12,7 +12,7 @@ namespace ModernKeePass.Views.UserControls
{ {
public sealed partial class OpenDatabaseUserControl public sealed partial class OpenDatabaseUserControl
{ {
public OpenDatabaseControlVm Model => Grid.DataContext as OpenDatabaseControlVm; private OpenDatabaseControlVm Model => (OpenDatabaseControlVm)Resources["ViewModel"];
public string DatabaseFilePath public string DatabaseFilePath
{ {

View File

@@ -1,5 +1,5 @@
<UserControl x:Name="UserControl" <UserControl x:Name="UserControl"
x:Class="ModernKeePass.Views.UserControls.UpdateCredentialsUserControl" x:Class="ModernKeePass.Views.UserControls.SetCredentialsUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -14,17 +14,15 @@
<converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/> <converters:DoubleToSolidColorBrushConverter x:Key="DoubleToSolidColorBrushConverter"/>
<converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/> <converters:DiscreteIntToSolidColorBrushConverter x:Key="DiscreteIntToSolidColorBrushConverter"/>
<converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/> <converters:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter"/>
<viewModels:SetCredentialsViewModel x:Key="ViewModel"/>
</UserControl.Resources> </UserControl.Resources>
<Grid x:Name="Grid"> <Grid DataContext="{StaticResource ViewModel}">
<!-- DataContext is not set at the root of the control because of issues happening when displaying it -->
<Grid.DataContext>
<viewModels:SetCredentialsViewModel />
</Grid.DataContext>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="50" /> <ColumnDefinition Width="50" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="45" />
<RowDefinition Height="45" /> <RowDefinition Height="45" />
<RowDefinition Height="40" /> <RowDefinition Height="40" />
<RowDefinition Height="40" /> <RowDefinition Height="40" />
@@ -38,19 +36,19 @@
</core:EventTriggerBehavior> </core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors> </interactivity:Interaction.Behaviors>
</PasswordBox> </PasswordBox>
<PasswordBox Grid.Row="0" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding Password, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" BorderBrush="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" SelectionHighlightColor="{StaticResource MainColor}" /> <PasswordBox Grid.Row="1" Grid.Column="1" x:Uid="CompositeKeyPassword" Password="{Binding ConfirmPassword, Mode=TwoWay}" Height="30" IsPasswordRevealButtonEnabled="True" BorderBrush="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}" SelectionHighlightColor="{StaticResource MainColor}" />
<ProgressBar Grid.Row="0" Grid.Column="1" <ProgressBar Grid.Row="1" Grid.Column="1"
Maximum="128" VerticalAlignment="Bottom" Maximum="128" VerticalAlignment="Bottom"
Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}, Mode=OneWay}" Value="{Binding PasswordComplexityIndicator, ConverterParameter=0\,128, Converter={StaticResource ProgressBarLegalValuesConverter}}"
Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToSolidColorBrushConverter}, Mode=OneWay}"/> Foreground="{Binding PasswordComplexityIndicator, ConverterParameter=128, Converter={StaticResource DoubleToSolidColorBrushConverter}}"/>
<CheckBox Grid.Row="1" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" /> <CheckBox Grid.Row="2" Grid.Column="0" IsChecked="{Binding HasKeyFile, Mode=TwoWay}" />
<HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0" <HyperlinkButton Grid.Row="1" Grid.Column="1" Margin="-15,0,0,0"
Content="{Binding KeyFileText, Mode=OneWay}" Content="{Binding KeyFileText}"
IsEnabled="{Binding HasKeyFile, Mode=OneWay}" IsEnabled="{Binding HasKeyFile}"
Click="KeyFileButton_Click" Click="KeyFileButton_Click"
Style="{StaticResource MainColorHyperlinkButton}" /> Style="{StaticResource MainColorHyperlinkButton}" />
<HyperlinkButton Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" <HyperlinkButton Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right"
IsEnabled="{Binding HasKeyFile, Mode=OneWay}" IsEnabled="{Binding HasKeyFile}"
Style="{StaticResource MainColorHyperlinkButton}" Style="{StaticResource MainColorHyperlinkButton}"
Click="CreateKeyFileButton_Click"> Click="CreateKeyFileButton_Click">
<SymbolIcon Symbol="Add"> <SymbolIcon Symbol="Add">
@@ -59,14 +57,13 @@
</ToolTipService.ToolTip> </ToolTipService.ToolTip>
</SymbolIcon> </SymbolIcon>
</HyperlinkButton> </HyperlinkButton>
<Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" <Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3"
Command="{Binding GenerateCredentialsCommand}"
Content="{Binding ButtonLabel, ElementName=UserControl}" Content="{Binding ButtonLabel, ElementName=UserControl}"
Click="UpdateButton_OnClick" Style="{StaticResource MainColorButton}" />
Style="{StaticResource MainColorButton}" <TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4" Height="Auto" FontSize="14" FontWeight="Light"
IsEnabled="{Binding IsValid, Mode=OneWay}" /> Text="{Binding Status}"
<TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Height="Auto" FontSize="14" FontWeight="Light" Foreground="{Binding StatusType, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}"
Text="{Binding Status, Mode=OneWay}" Visibility="{Binding Status, Converter={StaticResource EmptyStringToVisibilityConverter}}" />
Foreground="{Binding StatusType, Mode=OneWay, Converter={StaticResource DiscreteIntToSolidColorBrushConverter}}"
Visibility="{Binding Status, Mode=OneWay, Converter={StaticResource EmptyStringToVisibilityConverter}}" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -3,17 +3,15 @@ using System.Collections.Generic;
using Windows.Storage.AccessCache; using Windows.Storage.AccessCache;
using Windows.Storage.Pickers; using Windows.Storage.Pickers;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.ViewModels; using ModernKeePass.ViewModels;
using ModernKeePass.Extensions;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace ModernKeePass.Views.UserControls namespace ModernKeePass.Views.UserControls
{ {
public sealed partial class UpdateCredentialsUserControl public sealed partial class SetCredentialsUserControl
{ {
public SetCredentialsViewModel ViewModel => Grid.DataContext as SetCredentialsViewModel; private SetCredentialsViewModel Model => (SetCredentialsViewModel)Resources["ViewModel"];
public string ButtonLabel public string ButtonLabel
{ {
@@ -24,24 +22,10 @@ namespace ModernKeePass.Views.UserControls
DependencyProperty.Register( DependencyProperty.Register(
nameof(ButtonLabel), nameof(ButtonLabel),
typeof(string), typeof(string),
typeof(UpdateCredentialsUserControl), typeof(SetCredentialsUserControl),
new PropertyMetadata("OK", (o, args) => { })); new PropertyMetadata("OK", (o, args) => { }));
public string DatabaseFilePath public SetCredentialsUserControl()
{
get { return (string) GetValue(DatabaseFilePathProperty); }
set { SetValue(DatabaseFilePathProperty, value); }
}
public static readonly DependencyProperty DatabaseFilePathProperty =
DependencyProperty.Register(
"DatabaseFilePath",
typeof(string),
typeof(UpdateCredentialsUserControl),
new PropertyMetadata(null, (o, args) => { }));
public event EventHandler CredentialsUpdated;
public UpdateCredentialsUserControl()
{ {
InitializeComponent(); InitializeComponent();
} }
@@ -61,7 +45,7 @@ namespace ModernKeePass.Views.UserControls
if (file == null) return; if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file); var token = StorageApplicationPermissions.FutureAccessList.Add(file);
ViewModel.KeyFilePath = token; Model.KeyFilePath = token;
} }
private async void CreateKeyFileButton_Click(object sender, RoutedEventArgs e) private async void CreateKeyFileButton_Click(object sender, RoutedEventArgs e)
@@ -77,25 +61,7 @@ namespace ModernKeePass.Views.UserControls
if (file == null) return; if (file == null) return;
var token = StorageApplicationPermissions.FutureAccessList.Add(file); var token = StorageApplicationPermissions.FutureAccessList.Add(file);
ViewModel.KeyFilePath = token; Model.KeyFilePath = token;
}
private async void UpdateButton_OnClick(object sender, RoutedEventArgs e)
{
//throw new NotImplementedException();
if (await Dispatcher.RunTaskAsync(async () =>
{
var fileInfo = new FileInfo
{
Path = DatabaseFilePath
};
await ViewModel.CreateDatabase(fileInfo);
return true;
}))
{
CredentialsUpdated?.Invoke(this, new EventArgs());
}
} }
} }
} }

View File

@@ -143,7 +143,6 @@
<Compile Include="Views\MainPageFrames\WelcomePage.xaml.cs"> <Compile Include="Views\MainPageFrames\WelcomePage.xaml.cs">
<DependentUpon>WelcomePage.xaml</DependentUpon> <DependentUpon>WelcomePage.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="ViewModels\AboutVm.cs" />
<Compile Include="ViewModels\CompositeKeyVm.cs" /> <Compile Include="ViewModels\CompositeKeyVm.cs" />
<Compile Include="Views\EntryDetailPage.xaml.cs"> <Compile Include="Views\EntryDetailPage.xaml.cs">
<DependentUpon>EntryDetailPage.xaml</DependentUpon> <DependentUpon>EntryDetailPage.xaml</DependentUpon>
@@ -165,10 +164,6 @@
<Compile Include="ViewModels\GroupDetailVm.cs" /> <Compile Include="ViewModels\GroupDetailVm.cs" />
<Compile Include="ViewModels\SettingsVm.cs" /> <Compile Include="ViewModels\SettingsVm.cs" />
<Compile Include="ViewModels\MainVm.cs" /> <Compile Include="ViewModels\MainVm.cs" />
<Compile Include="ViewModels\NewVm.cs" />
<Compile Include="ViewModels\OpenVm.cs" />
<Compile Include="ViewModels\RecentVm.cs" />
<Compile Include="ViewModels\SaveVm.cs" />
<Compile Include="Views\UserControls\OpenDatabaseUserControl.xaml.cs"> <Compile Include="Views\UserControls\OpenDatabaseUserControl.xaml.cs">
<DependentUpon>OpenDatabaseUserControl.xaml</DependentUpon> <DependentUpon>OpenDatabaseUserControl.xaml</DependentUpon>
</Compile> </Compile>
@@ -181,8 +176,8 @@
<Compile Include="Views\UserControls\TopMenuUserControl.xaml.cs"> <Compile Include="Views\UserControls\TopMenuUserControl.xaml.cs">
<DependentUpon>TopMenuUserControl.xaml</DependentUpon> <DependentUpon>TopMenuUserControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\UserControls\UpdateCredentialsUserControl.xaml.cs"> <Compile Include="Views\UserControls\SetCredentialsUserControl.xaml.cs">
<DependentUpon>UpdateCredentialsUserControl.xaml</DependentUpon> <DependentUpon>SetCredentialsUserControl.xaml</DependentUpon>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -332,7 +327,7 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\UserControls\UpdateCredentialsUserControl.xaml"> <Page Include="Views\UserControls\SetCredentialsUserControl.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>

View File

@@ -1,7 +1,8 @@
using System; using System;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using GalaSoft.MvvmLight.Views;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Xaml.Interactivity; using Microsoft.Xaml.Interactivity;
using ModernKeePass.Common;
namespace ModernKeePass.Actions namespace ModernKeePass.Actions
{ {
@@ -25,7 +26,8 @@ namespace ModernKeePass.Actions
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageDialogHelper.ShowErrorDialog(ex).GetAwaiter(); var dialogService = App.Services.GetRequiredService<IDialogService>();
dialogService.ShowError(ex, ex.Message, null, () => {}).Wait();
return false; return false;
} }
} }

View File

@@ -0,0 +1,8 @@
namespace Messages
{
public class CredentialsSetMessage
{
public string KeyFilePath { get; set; }
public string Password { get; set; }
}
}

View File

@@ -1,11 +1,11 @@
using System; using System;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
using ModernKeePass.Domain.AOP; using GalaSoft.MvvmLight;
using ModernKeePass.Domain.Interfaces; using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems namespace ModernKeePass.ViewModels.ListItems
{ {
public class ListMenuItemVm : NotifyPropertyChangedBase, IIsEnabled, ISelectableModel public class ListMenuItemVm : ObservableObject, IIsEnabled, ISelectableModel
{ {
private bool _isSelected; private bool _isSelected;
@@ -19,7 +19,7 @@ namespace ModernKeePass.ViewModels.ListItems
public bool IsSelected public bool IsSelected
{ {
get { return _isSelected; } get { return _isSelected; }
set { SetProperty(ref _isSelected, value); } set { Set(() => IsSelected, ref _isSelected, value); }
} }
public override string ToString() public override string ToString()

View File

@@ -1,10 +1,10 @@
using ModernKeePass.Domain.AOP; using GalaSoft.MvvmLight;
using ModernKeePass.Domain.Dtos; using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Interfaces; using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels.ListItems namespace ModernKeePass.ViewModels.ListItems
{ {
public class RecentItemVm: NotifyPropertyChangedBase, ISelectableModel public class RecentItemVm: ObservableObject, ISelectableModel
{ {
private bool _isSelected; private bool _isSelected;
private string _name; private string _name;
@@ -14,25 +14,25 @@ namespace ModernKeePass.ViewModels.ListItems
public string Token public string Token
{ {
get { return _token; } get { return _token; }
set { SetProperty(ref _token, value); } set { Set(() => Token, ref _token, value); }
} }
public string Name public string Name
{ {
get { return _name; } get { return _name; }
set { SetProperty(ref _name, value); } set { Set(() => Name, ref _name, value); }
} }
public string Path public string Path
{ {
get { return _path; } get { return _path; }
set { SetProperty(ref _path, value); } set { Set(() => Path, ref _path, value); }
} }
public bool IsSelected public bool IsSelected
{ {
get { return _isSelected; } get { return _isSelected; }
set { SetProperty(ref _isSelected, value); } set { Set(() => IsSelected, ref _isSelected, value); }
} }
public RecentItemVm(FileInfo file) public RecentItemVm(FileInfo file)

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using GalaSoft.MvvmLight;
using MediatR; using MediatR;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces; using ModernKeePass.Application.Common.Interfaces;
@@ -16,12 +17,11 @@ using ModernKeePass.Application.Parameters.Models;
using ModernKeePass.Application.Parameters.Queries.GetCiphers; using ModernKeePass.Application.Parameters.Queries.GetCiphers;
using ModernKeePass.Application.Parameters.Queries.GetCompressions; using ModernKeePass.Application.Parameters.Queries.GetCompressions;
using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations; using ModernKeePass.Application.Parameters.Queries.GetKeyDerivations;
using ModernKeePass.Domain.AOP;
namespace ModernKeePass.ViewModels.ListItems namespace ModernKeePass.ViewModels.ListItems
{ {
// TODO: implement Kdf settings // TODO: implement Kdf settings
public class SettingsDatabaseVm: NotifyPropertyChangedBase public class SettingsDatabaseVm: ObservableObject
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly DatabaseVm _database; private readonly DatabaseVm _database;
@@ -32,7 +32,7 @@ namespace ModernKeePass.ViewModels.ListItems
set set
{ {
_mediator.Send(new SetHasRecycleBinCommand {HasRecycleBin = value}).Wait(); _mediator.Send(new SetHasRecycleBinCommand {HasRecycleBin = value}).Wait();
OnPropertyChanged(nameof(HasRecycleBin)); RaisePropertyChanged(nameof(HasRecycleBin));
} }
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces; using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Common; using ModernKeePass.Common;
@@ -23,12 +24,34 @@ namespace ModernKeePass.ViewModels.ListItems
set { _settings.PutSetting(Constants.Settings.Sample, value); } set { _settings.PutSetting(Constants.Settings.Sample, value); }
} }
public IEnumerable<string> FileFormats => new []{"2", "4"}; public IEnumerable<DatabaseFormat> FileFormats => new []
public string FileFormatVersion
{ {
get { return _settings.GetSetting<string>(Constants.Settings.DefaultFileFormat); } new DatabaseFormat
set { _settings.PutSetting(Constants.Settings.DefaultFileFormat, value); } {
Version = "4",
DisplayText = "4 (Argon2, ChaCha20)"
},
new DatabaseFormat
{
Version = "3",
DisplayText = "3 (AES-KDF, AES/Rijndael)"
} }
};
public DatabaseFormat DatabaseFormatVersion
{
get
{
var version = _settings.GetSetting<string>(Constants.Settings.DefaultFileFormat);
return FileFormats.FirstOrDefault(f => f.Version == version);
}
set { _settings.PutSetting(Constants.Settings.DefaultFileFormat, value.Version); }
}
}
public class DatabaseFormat
{
public string Version { get; set; }
public string DisplayText { get; set; }
} }
} }

View File

@@ -0,0 +1,71 @@
using System.Threading.Tasks;
using Windows.Storage;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Messages;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Commands.CreateDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Common;
using ModernKeePass.Models;
namespace ModernKeePass.ViewModels
{
public class NewVm : OpenVm
{
private readonly IMediator _mediator;
private readonly ISettingsProxy _settings;
private readonly INavigationService _navigation;
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;
RaisePropertyChanged(nameof(ImportFormatHelp));
}
}
public NewVm(): this(
App.Services.GetRequiredService<IMediator>(),
App.Services.GetRequiredService<ISettingsProxy>(),
App.Services.GetRequiredService<IMessenger>(),
App.Services.GetRequiredService<INavigationService>()) { }
public NewVm(IMediator mediator, ISettingsProxy settings, IMessenger messenger, INavigationService navigation)
{
_mediator = mediator;
_settings = settings;
_navigation = navigation;
messenger.Register<CredentialsSetMessage>(this, async message => await CreateDatabase(message));
}
public async Task CreateDatabase(CredentialsSetMessage message)
{
await _mediator.Send(new CreateDatabaseCommand
{
FilePath = Token,
KeyFilePath = message.KeyFilePath,
Password = message.Password,
Name = "ModernKeePass",
Version = _settings.GetSetting(Constants.Settings.DefaultFileFormat, "4"),
CreateSampleData = _settings.GetSetting<bool>(Constants.Settings.Sample)
});
var database = await _mediator.Send(new GetDatabaseQuery());
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = database.RootGroupId });
}
}
}

View File

@@ -1,12 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces; using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Dtos; using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels namespace ModernKeePass.ViewModels
{ {
public class OpenVm: NotifyPropertyChangedBase public class OpenVm: ObservableObject
{ {
private readonly IRecentProxy _recent; private readonly IRecentProxy _recent;
private string _name; private string _name;
@@ -17,19 +17,19 @@ namespace ModernKeePass.ViewModels
public string Token public string Token
{ {
get { return _token; } get { return _token; }
set { SetProperty(ref _token, value); } set { Set(() => Token, ref _token, value); }
} }
public string Name public string Name
{ {
get { return _name; } get { return _name; }
private set { SetProperty(ref _name, value); } private set { Set(() => Name, ref _name, value); }
} }
public string Path public string Path
{ {
get { return _path; } get { return _path; }
private set { SetProperty(ref _path, value); } private set { Set(() => Path, ref _path, value); }
} }
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { } public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
@@ -44,7 +44,7 @@ namespace ModernKeePass.ViewModels
Token = file.Id; Token = file.Id;
Name = file.Name; Name = file.Name;
Path = file.Path; Path = file.Path;
OnPropertyChanged(nameof(IsFileSelected)); RaisePropertyChanged(nameof(IsFileSelected));
await AddToRecentList(file); await AddToRecentList(file);
} }

View File

@@ -1,16 +1,16 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Windows.Input; using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces; using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Interfaces; using ModernKeePass.Domain.Interfaces;
using ModernKeePass.ViewModels.ListItems; using ModernKeePass.ViewModels.ListItems;
namespace ModernKeePass.ViewModels namespace ModernKeePass.ViewModels
{ {
public class RecentVm : NotifyPropertyChangedBase, IHasSelectableObject public class RecentVm : ObservableObject, IHasSelectableObject
{ {
private readonly IRecentProxy _recent; private readonly IRecentProxy _recent;
private ISelectableModel _selectedItem; private ISelectableModel _selectedItem;
@@ -19,7 +19,7 @@ namespace ModernKeePass.ViewModels
public ObservableCollection<RecentItemVm> RecentItems public ObservableCollection<RecentItemVm> RecentItems
{ {
get { return _recentItems; } get { return _recentItems; }
set { SetProperty(ref _recentItems, value); } set { Set(() => RecentItems, ref _recentItems, value); }
} }
public ISelectableModel SelectedItem public ISelectableModel SelectedItem
@@ -33,7 +33,7 @@ namespace ModernKeePass.ViewModels
_selectedItem.IsSelected = false; _selectedItem.IsSelected = false;
} }
SetProperty(ref _selectedItem, value); Set(() => SelectedItem, ref _selectedItem, value);
if (_selectedItem == null) return; if (_selectedItem == null) return;
_selectedItem.IsSelected = true; _selectedItem.IsSelected = true;

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging; using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Views; using GalaSoft.MvvmLight.Views;
@@ -13,11 +14,10 @@ using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase; using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Application.Database.Queries.OpenDatabase; using ModernKeePass.Application.Database.Queries.OpenDatabase;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Domain.AOP;
namespace ModernKeePass.ViewModels namespace ModernKeePass.ViewModels
{ {
public class OpenDatabaseControlVm : NotifyPropertyChangedBase public class OpenDatabaseControlVm : ObservableObject
{ {
public enum StatusTypes public enum StatusTypes
{ {
@@ -32,8 +32,8 @@ namespace ModernKeePass.ViewModels
get { return _hasPassword; } get { return _hasPassword; }
set set
{ {
SetProperty(ref _hasPassword, value); Set(() => HasPassword, ref _hasPassword, value);
OnPropertyChanged(nameof(IsValid)); RaisePropertyChanged(nameof(IsValid));
OpenDatabaseCommand.RaiseCanExecuteChanged(); OpenDatabaseCommand.RaiseCanExecuteChanged();
} }
} }
@@ -43,8 +43,8 @@ namespace ModernKeePass.ViewModels
get { return _hasKeyFile; } get { return _hasKeyFile; }
set set
{ {
SetProperty(ref _hasKeyFile, value); Set(() => HasKeyFile, ref _hasKeyFile, value);
OnPropertyChanged(nameof(IsValid)); RaisePropertyChanged(nameof(IsValid));
OpenDatabaseCommand.RaiseCanExecuteChanged(); OpenDatabaseCommand.RaiseCanExecuteChanged();
} }
} }
@@ -54,13 +54,13 @@ namespace ModernKeePass.ViewModels
public string Status public string Status
{ {
get { return _status; } get { return _status; }
set { SetProperty(ref _status, value); } set { Set(() => Status, ref _status, value); }
} }
public int StatusType public int StatusType
{ {
get { return (int)_statusType; } get { return _statusType; }
set { SetProperty(ref _statusType, (StatusTypes)value); } set { Set(() => StatusType, ref _statusType, value); }
} }
public string Password public string Password
@@ -80,7 +80,7 @@ namespace ModernKeePass.ViewModels
set set
{ {
_keyFilePath = value; _keyFilePath = value;
OnPropertyChanged(nameof(IsValid)); RaisePropertyChanged(nameof(IsValid));
OpenDatabaseCommand.RaiseCanExecuteChanged(); OpenDatabaseCommand.RaiseCanExecuteChanged();
} }
} }
@@ -88,18 +88,18 @@ namespace ModernKeePass.ViewModels
public string KeyFileText public string KeyFileText
{ {
get { return _keyFileText; } get { return _keyFileText; }
set { SetProperty(ref _keyFileText, value); } set { Set(() => KeyFileText, ref _keyFileText, value); }
} }
public string OpenButtonLabel public string OpenButtonLabel
{ {
get { return _openButtonLabel; } get { return _openButtonLabel; }
set { SetProperty(ref _openButtonLabel, value); } set { Set(() => OpenButtonLabel, ref _openButtonLabel, value); }
} }
public RelayCommand<string> OpenDatabaseCommand { get; } public RelayCommand<string> OpenDatabaseCommand { get; }
protected readonly IMediator Mediator; private readonly IMediator _mediator;
private readonly IResourceProxy _resource; private readonly IResourceProxy _resource;
private readonly IMessenger _messenger; private readonly IMessenger _messenger;
private readonly IDialogService _dialog; private readonly IDialogService _dialog;
@@ -108,7 +108,7 @@ namespace ModernKeePass.ViewModels
private bool _isOpening; private bool _isOpening;
private string _password = string.Empty; private string _password = string.Empty;
private string _status; private string _status;
private StatusTypes _statusType; private int _statusType;
private string _keyFilePath; private string _keyFilePath;
private string _keyFileText; private string _keyFileText;
private string _openButtonLabel; private string _openButtonLabel;
@@ -123,7 +123,7 @@ namespace ModernKeePass.ViewModels
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, IMessenger messenger, IDialogService dialog) public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, IMessenger messenger, IDialogService dialog)
{ {
Mediator = mediator; _mediator = mediator;
_resource = resource; _resource = resource;
_messenger = messenger; _messenger = messenger;
_dialog = dialog; _dialog = dialog;
@@ -136,7 +136,7 @@ namespace ModernKeePass.ViewModels
{ {
_messenger.Send(new DatabaseOpeningMessage {Token = databaseFilePath}); _messenger.Send(new DatabaseOpeningMessage {Token = databaseFilePath});
var database = await Mediator.Send(new GetDatabaseQuery()); var database = await _mediator.Send(new GetDatabaseQuery());
if (database.IsOpen) if (database.IsOpen)
{ {
await _dialog.ShowMessage(_resource.GetResourceValue("MessageDialogDBOpenTitle"), await _dialog.ShowMessage(_resource.GetResourceValue("MessageDialogDBOpenTitle"),
@@ -147,16 +147,16 @@ namespace ModernKeePass.ViewModels
{ {
if (isOk) if (isOk)
{ {
await Mediator.Send(new SaveDatabaseCommand()); await _mediator.Send(new SaveDatabaseCommand());
ToastNotificationHelper.ShowGenericToast( ToastNotificationHelper.ShowGenericToast(
database.Name, database.Name,
_resource.GetResourceValue("ToastSavedMessage")); _resource.GetResourceValue("ToastSavedMessage"));
await Mediator.Send(new CloseDatabaseCommand()); await _mediator.Send(new CloseDatabaseCommand());
await OpenDatabase(databaseFilePath); await OpenDatabase(databaseFilePath);
} }
else else
{ {
await Mediator.Send(new CloseDatabaseCommand()); await _mediator.Send(new CloseDatabaseCommand());
await OpenDatabase(databaseFilePath); await OpenDatabase(databaseFilePath);
} }
}); });
@@ -171,15 +171,15 @@ namespace ModernKeePass.ViewModels
_isOpening = true; _isOpening = true;
try try
{ {
OnPropertyChanged(nameof(IsValid)); RaisePropertyChanged(nameof(IsValid));
OpenDatabaseCommand.RaiseCanExecuteChanged(); OpenDatabaseCommand.RaiseCanExecuteChanged();
await Mediator.Send(new OpenDatabaseQuery await _mediator.Send(new OpenDatabaseQuery
{ {
FilePath = databaseFilePath, FilePath = databaseFilePath,
KeyFilePath = HasKeyFile ? KeyFilePath : null, KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null, Password = HasPassword ? Password : null,
}); });
var rootGroupId = (await Mediator.Send(new GetDatabaseQuery())).RootGroupId; var rootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
_messenger.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId }); _messenger.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
} }
@@ -198,7 +198,7 @@ namespace ModernKeePass.ViewModels
finally finally
{ {
_isOpening = false; _isOpening = false;
OnPropertyChanged(nameof(IsValid)); RaisePropertyChanged(nameof(IsValid));
OpenDatabaseCommand.RaiseCanExecuteChanged(); OpenDatabaseCommand.RaiseCanExecuteChanged();
OpenButtonLabel = oldLabel; OpenButtonLabel = oldLabel;
} }

View File

@@ -1,46 +1,120 @@
using System.Threading.Tasks; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Messages;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces; using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Commands.CreateDatabase;
using ModernKeePass.Common;
using ModernKeePass.Domain.Dtos;
namespace ModernKeePass.ViewModels namespace ModernKeePass.ViewModels
{ {
public class SetCredentialsViewModel : OpenDatabaseControlVm public class SetCredentialsViewModel : ObservableObject
{ {
private readonly ICredentialsProxy _credentials; private readonly ICredentialsProxy _credentials;
private readonly ISettingsProxy _settings; private readonly IMessenger _messenger;
private string _confirmPassword;
public bool HasPassword
{
get { return _hasPassword; }
set
{
Set(() => HasPassword, ref _hasPassword, value);
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public bool HasKeyFile
{
get { return _hasKeyFile; }
set
{
Set(() => HasKeyFile, ref _hasKeyFile, value);
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string Status
{
get { return _status; }
set { Set(() => Status, ref _status, value); }
}
public string Password
{
get { return _password; }
set
{
_password = value;
RaisePropertyChanged(nameof(IsValid));
RaisePropertyChanged(nameof(PasswordComplexityIndicator));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string ConfirmPassword public string ConfirmPassword
{ {
get { return _confirmPassword; } get { return _confirmPassword; }
set { SetProperty(ref _confirmPassword, value); } set
{
_confirmPassword = value;
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string KeyFilePath
{
get { return _keyFilePath; }
set
{
_keyFilePath = value;
RaisePropertyChanged(nameof(IsValid));
GenerateCredentialsCommand.RaiseCanExecuteChanged();
}
}
public string KeyFileText
{
get { return _keyFileText; }
set { Set(() => KeyFileText, ref _keyFileText, value); }
}
public string OpenButtonLabel
{
get { return _openButtonLabel; }
set { Set(() => OpenButtonLabel, ref _openButtonLabel, value); }
} }
public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password); public double PasswordComplexityIndicator => _credentials.EstimatePasswordComplexity(Password);
public new bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && KeyFilePath != string.Empty; public bool IsValid => HasPassword && Password == ConfirmPassword || HasKeyFile && KeyFilePath != string.Empty;
public SetCredentialsViewModel(): this(App.Services.GetRequiredService<ICredentialsProxy>(), App.Services.GetRequiredService<ISettingsProxy>()) { } public RelayCommand GenerateCredentialsCommand{ get; }
public SetCredentialsViewModel(ICredentialsProxy credentials, ISettingsProxy settings) private bool _hasPassword;
private bool _hasKeyFile;
private string _password = string.Empty;
private string _confirmPassword;
private string _status;
private string _keyFilePath;
private string _keyFileText;
private string _openButtonLabel;
public SetCredentialsViewModel(): this(App.Services.GetRequiredService<ICredentialsProxy>(), App.Services.GetRequiredService<IMessenger>()) { }
public SetCredentialsViewModel(ICredentialsProxy credentials, IMessenger messenger)
{ {
_credentials = credentials; _credentials = credentials;
_settings = settings; _messenger = messenger;
GenerateCredentialsCommand = new RelayCommand(GenerateCredentials, () => IsValid);
} }
public async Task CreateDatabase(FileInfo fileInfo) private void GenerateCredentials()
{ {
await Mediator.Send(new CreateDatabaseCommand _messenger.Send(new CredentialsSetMessage
{ {
FilePath = fileInfo.Path,
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null, Password = HasPassword ? Password : null,
Name = "New Database", KeyFilePath = HasKeyFile ? KeyFilePath : null
CreateSampleData = _settings.GetSetting<bool>(Constants.Settings.Sample)
}); });
} }
} }

View File

@@ -36,6 +36,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Events\PasswordEventArgs.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Events\PasswordEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ColorExtensions.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Extensions\ColorExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DispatcherTaskExtensions.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Extensions\DispatcherTaskExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\CredentialsMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseAlreadyOpenedMessage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseAlreadyOpenedMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseClosedMessage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseClosedMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseOpenedMessage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseOpenedMessage.cs" />
@@ -44,12 +45,17 @@
<Compile Include="$(MSBuildThisFileDirectory)Messages\SaveErrorMessage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Messages\SaveErrorMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\FirstItemDataTemplateSelector.cs" /> <Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\FirstItemDataTemplateSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\SelectableDataTemplateSelector.cs" /> <Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\SelectableDataTemplateSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\AboutVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\ListMenuItemVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\ListMenuItemVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\MainMenuItemVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\MainMenuItemVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\RecentItemVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\RecentItemVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsDatabaseVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsDatabaseVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsNewVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsNewVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsSaveVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\SettingsSaveVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\NewVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\OpenVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\RecentVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\SaveVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\OpenDatabaseControlVm.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\OpenDatabaseControlVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\SetCredentialsViewModel.cs" /> <Compile Include="$(MSBuildThisFileDirectory)ViewModels\UserControls\SetCredentialsViewModel.cs" />
</ItemGroup> </ItemGroup>