mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Opening Databases now use a Messenger service
This commit is contained in:
9
WinAppCommon/Messages/DatabaseAlreadyOpenedMessage.cs
Normal file
9
WinAppCommon/Messages/DatabaseAlreadyOpenedMessage.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using ModernKeePass.Application.Database.Models;
|
||||
|
||||
namespace Messages
|
||||
{
|
||||
public class DatabaseAlreadyOpenedMessage
|
||||
{
|
||||
public DatabaseVm OpenedDatabase { get; set; }
|
||||
}
|
||||
}
|
7
WinAppCommon/Messages/DatabaseClosedMessage.cs
Normal file
7
WinAppCommon/Messages/DatabaseClosedMessage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Messages
|
||||
{
|
||||
public class DatabaseClosedMessage
|
||||
{
|
||||
|
||||
}
|
||||
}
|
7
WinAppCommon/Messages/DatabaseOpenedMessage.cs
Normal file
7
WinAppCommon/Messages/DatabaseOpenedMessage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Messages
|
||||
{
|
||||
public class DatabaseOpenedMessage
|
||||
{
|
||||
public string RootGroupId { get; set; }
|
||||
}
|
||||
}
|
7
WinAppCommon/Messages/DatabaseOpeningMessage.cs
Normal file
7
WinAppCommon/Messages/DatabaseOpeningMessage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Messages
|
||||
{
|
||||
public class DatabaseOpeningMessage
|
||||
{
|
||||
public string Token { get; set; }
|
||||
}
|
||||
}
|
8
WinAppCommon/Messages/NavigateToPageMessage.cs
Normal file
8
WinAppCommon/Messages/NavigateToPageMessage.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Messages
|
||||
{
|
||||
public class NavigateToPageMessage
|
||||
{
|
||||
public string Destination { get; set; }
|
||||
public object Parameter { get; set; }
|
||||
}
|
||||
}
|
7
WinAppCommon/Messages/SaveErrorMessage.cs
Normal file
7
WinAppCommon/Messages/SaveErrorMessage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Messages
|
||||
{
|
||||
public class SaveErrorMessage
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -1,6 +1,4 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
@@ -8,7 +6,6 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
{
|
||||
public class RecentItemVm: NotifyPropertyChangedBase, ISelectableModel
|
||||
{
|
||||
private readonly IRecentProxy _recent;
|
||||
private bool _isSelected;
|
||||
private string _name;
|
||||
private string _token;
|
||||
@@ -37,20 +34,12 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
get { return _isSelected; }
|
||||
set { SetProperty(ref _isSelected, value); }
|
||||
}
|
||||
|
||||
public RecentItemVm(FileInfo file): this(App.Services.GetRequiredService<IRecentProxy>(), file) {}
|
||||
public RecentItemVm(IRecentProxy recent, FileInfo file)
|
||||
|
||||
public RecentItemVm(FileInfo file)
|
||||
{
|
||||
_recent = recent;
|
||||
Token = file.Id;
|
||||
Name = file.Name;
|
||||
Path = file.Path;
|
||||
}
|
||||
|
||||
// Called from XAML
|
||||
public void UpdateAccessTime()
|
||||
{
|
||||
_recent.Get(Token, true).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using MediatR;
|
||||
using Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Application.Database.Queries.GetDatabase;
|
||||
using ModernKeePass.Application.Database.Queries.OpenDatabase;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.AOP;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
@@ -28,6 +30,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
SetProperty(ref _hasPassword, value);
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
OpenDatabaseCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +41,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
SetProperty(ref _hasKeyFile, value);
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
OpenDatabaseCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +77,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
_keyFilePath = value;
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
OpenDatabaseCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +87,17 @@ namespace ModernKeePass.ViewModels
|
||||
set { SetProperty(ref _keyFileText, value); }
|
||||
}
|
||||
|
||||
public string RootGroupId { get; set; }
|
||||
public string OpenButtonLabel
|
||||
{
|
||||
get { return _openButtonLabel; }
|
||||
set { SetProperty(ref _openButtonLabel, value); }
|
||||
}
|
||||
|
||||
public RelayCommand<string> OpenDatabaseCommand { get; }
|
||||
|
||||
protected readonly IMediator Mediator;
|
||||
private readonly IResourceProxy _resource;
|
||||
private readonly IMessenger _messenger;
|
||||
private bool _hasPassword;
|
||||
private bool _hasKeyFile;
|
||||
private bool _isOpening;
|
||||
@@ -94,35 +106,55 @@ namespace ModernKeePass.ViewModels
|
||||
private StatusTypes _statusType;
|
||||
private string _keyFilePath;
|
||||
private string _keyFileText;
|
||||
|
||||
private string _openButtonLabel;
|
||||
|
||||
|
||||
public OpenDatabaseControlVm() : this(
|
||||
App.Services.GetRequiredService<IMediator>(),
|
||||
App.Services.GetRequiredService<IResourceProxy>())
|
||||
App.Services.GetRequiredService<IResourceProxy>(),
|
||||
App.Services.GetRequiredService<IMessenger>())
|
||||
{ }
|
||||
|
||||
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource)
|
||||
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, IMessenger messenger)
|
||||
{
|
||||
Mediator = mediator;
|
||||
_resource = resource;
|
||||
_messenger = messenger;
|
||||
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
|
||||
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
|
||||
_openButtonLabel = _resource.GetResourceValue("CompositeKeyOpenButtonLabel");
|
||||
}
|
||||
|
||||
public async Task<bool> OpenDatabase(string databaseFilePath)
|
||||
public async Task TryOpenDatabase(string databaseFilePath)
|
||||
{
|
||||
_messenger.Send(new DatabaseOpeningMessage {Token = databaseFilePath});
|
||||
|
||||
var database = await Mediator.Send(new GetDatabaseQuery());
|
||||
if (database.IsOpen)
|
||||
{
|
||||
_messenger.Send(new DatabaseAlreadyOpenedMessage { OpenedDatabase = database });
|
||||
}
|
||||
else await OpenDatabase(databaseFilePath);
|
||||
}
|
||||
|
||||
public async Task OpenDatabase(string databaseFilePath)
|
||||
{
|
||||
var oldLabel = _openButtonLabel;
|
||||
OpenButtonLabel = _resource.GetResourceValue("CompositeKeyOpening");
|
||||
_isOpening = true;
|
||||
try
|
||||
{
|
||||
_isOpening = true;
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
OpenDatabaseCommand.RaiseCanExecuteChanged();
|
||||
await Mediator.Send(new OpenDatabaseQuery
|
||||
{
|
||||
FilePath = databaseFilePath,
|
||||
KeyFilePath = HasKeyFile ? KeyFilePath : null,
|
||||
Password = HasPassword ? Password : null,
|
||||
});
|
||||
RootGroupId = (await Mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
||||
return true;
|
||||
var rootGroupId = (await Mediator.Send(new GetDatabaseQuery())).RootGroupId;
|
||||
|
||||
_messenger.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
@@ -140,8 +172,9 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
_isOpening = false;
|
||||
OnPropertyChanged(nameof(IsValid));
|
||||
OpenDatabaseCommand.RaiseCanExecuteChanged();
|
||||
OpenButtonLabel = oldLabel;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateStatus(string text, StatusTypes type)
|
||||
|
@@ -36,6 +36,12 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Events\PasswordEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ColorExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions\DispatcherTaskExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseAlreadyOpenedMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseClosedMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseOpenedMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\DatabaseOpeningMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\NavigateToPageMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Messages\SaveErrorMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\FirstItemDataTemplateSelector.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)TemplateSelectors\SelectableDataTemplateSelector.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\ListMenuItemVm.cs" />
|
||||
|
Reference in New Issue
Block a user