Create a shared project with all Win App common files (8.1 and 10)

Finally use the dependency injected Resource Service
This commit is contained in:
Geoffroy BONNEVILLE
2020-04-17 16:56:07 +02:00
parent 2fb5b14085
commit 73670e8689
73 changed files with 131 additions and 1872 deletions

View File

@@ -1,5 +1,7 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Navigation;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Common;
using ModernKeePass.Models;
using ModernKeePass.ViewModels;
@@ -14,6 +16,7 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class EntryDetailPage
{
private readonly IResourceProxy _resource;
public EntryDetailVm Model => (EntryDetailVm) DataContext;
/// <summary>
@@ -22,9 +25,11 @@ namespace ModernKeePass.Views
/// </summary>
public NavigationHelper NavigationHelper { get; }
public EntryDetailPage()
public EntryDetailPage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
public EntryDetailPage(IResourceProxy resource)
{
InitializeComponent();
_resource = resource;
NavigationHelper = new NavigationHelper(this);
}
@@ -66,29 +71,28 @@ namespace ModernKeePass.Views
private async void TopMenu_OnDeleteButtonClick(object sender, RoutedEventArgs e)
{
var resource = new ResourceHelper();
if (Model.IsCurrentEntry)
{
var isRecycleOnDelete = Model.IsRecycleOnDelete;
var message = isRecycleOnDelete
? resource.GetResourceValue("EntryRecyclingConfirmation")
: resource.GetResourceValue("EntryDeletingConfirmation");
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
? _resource.GetResourceValue("EntryRecyclingConfirmation")
: _resource.GetResourceValue("EntryDeletingConfirmation");
await MessageDialogHelper.ShowActionDialog(_resource.GetResourceValue("EntityDeleteTitle"), message,
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
{
var text = isRecycleOnDelete ? resource.GetResourceValue("EntryRecycled") : resource.GetResourceValue("EntryDeleted");
var text = isRecycleOnDelete ? _resource.GetResourceValue("EntryRecycled") : _resource.GetResourceValue("EntryDeleted");
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
await Model.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
await Model.MarkForDelete(_resource.GetResourceValue("RecycleBinTitle"));
NavigationHelper.GoBack();
}, null);
}
else
{
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("HistoryDeleteTitle"), resource.GetResourceValue("HistoryDeleteDescription"),
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
await MessageDialogHelper.ShowActionDialog(_resource.GetResourceValue("HistoryDeleteTitle"), _resource.GetResourceValue("HistoryDeleteDescription"),
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
{
//ToastNotificationHelper.ShowMovedToast(Entity, _resource.GetResourceValue("EntityDeleting"), text);
await Model.DeleteHistory();

View File

@@ -5,11 +5,13 @@ using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Common;
using ModernKeePass.Events;
using ModernKeePass.Models;
using ModernKeePass.ViewModels;
using EntryVm = ModernKeePass.Application.Entry.Models.EntryVm;
// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229
@@ -21,6 +23,8 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class GroupDetailPage
{
private readonly IResourceProxy _resource;
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
@@ -28,9 +32,11 @@ namespace ModernKeePass.Views
public NavigationHelper NavigationHelper { get; }
public GroupDetailVm Model => (GroupDetailVm)DataContext;
public GroupDetailPage()
public GroupDetailPage(): this (App.Services.GetRequiredService<IResourceProxy>()) { }
public GroupDetailPage(IResourceProxy resource)
{
InitializeComponent();
_resource = resource;
NavigationHelper = new NavigationHelper(this);
}
@@ -150,19 +156,18 @@ namespace ModernKeePass.Views
private async void TopMenu_OnDeleteButtonClick(object sender, RoutedEventArgs e)
{
var resource = new ResourceHelper();
var isRecycleOnDelete = Model.IsRecycleOnDelete;
var message = isRecycleOnDelete
? resource.GetResourceValue("GroupRecyclingConfirmation")
: resource.GetResourceValue("GroupDeletingConfirmation");
var text = isRecycleOnDelete ? resource.GetResourceValue("GroupRecycled") : resource.GetResourceValue("GroupDeleted");
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
? _resource.GetResourceValue("GroupRecyclingConfirmation")
: _resource.GetResourceValue("GroupDeletingConfirmation");
var text = isRecycleOnDelete ? _resource.GetResourceValue("GroupRecycled") : _resource.GetResourceValue("GroupDeleted");
await MessageDialogHelper.ShowActionDialog(_resource.GetResourceValue("EntityDeleteTitle"), message,
_resource.GetResourceValue("EntityDeleteActionButton"),
_resource.GetResourceValue("EntityDeleteCancelButton"), async a =>
{
//ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
await Model.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
await Model.MarkForDelete(_resource.GetResourceValue("RecycleBinTitle"));
NavigationHelper.GoBack();
}, null);
}

View File

@@ -4,7 +4,8 @@ using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Common;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Infrastructure.File;
using ModernKeePass.ViewModels;
@@ -18,10 +19,13 @@ namespace ModernKeePass.Views
/// </summary>
public sealed partial class NewDatabasePage
{
private readonly IResourceProxy _resource;
public NewVm Model => (NewVm)DataContext;
public NewDatabasePage()
public NewDatabasePage(): this(App.Services.GetRequiredService<IResourceProxy>()) { }
public NewDatabasePage(IResourceProxy resource)
{
_resource = resource;
InitializeComponent();
}
@@ -49,14 +53,13 @@ namespace ModernKeePass.Views
private void ImportFormatComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var resource = new ResourceHelper();
var comboBox = sender as ComboBox;
switch (comboBox?.SelectedIndex)
{
case 0:
Model.ImportFormat = new CsvImportFormat();
Model.ImportFileExtensionFilter = ".csv";
Model.ImportFormatHelp = resource.GetResourceValue("NewImportFormatHelpCSV");
Model.ImportFormatHelp = _resource.GetResourceValue("NewImportFormatHelpCSV");
break;
}
}

View File

@@ -8,6 +8,7 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Database.Commands.CloseDatabase;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase;
@@ -24,7 +25,7 @@ namespace ModernKeePass.Views.UserControls
public sealed partial class CompositeKeyUserControl
{
private readonly IMediator _mediator;
private readonly ResourceHelper _resource;
private readonly IResourceProxy _resource;
public CompositeKeyVm Model => Grid.DataContext as CompositeKeyVm;
public bool CreateNew
@@ -77,13 +78,12 @@ namespace ModernKeePass.Views.UserControls
public bool ShowComplexityIndicator => CreateNew || UpdateKey;
public CompositeKeyUserControl(): this(App.Services.GetRequiredService<IMediator>())
{ }
public CompositeKeyUserControl(): this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<IResourceProxy>()) { }
public CompositeKeyUserControl(IMediator mediator)
public CompositeKeyUserControl(IMediator mediator, IResourceProxy resource)
{
_mediator = mediator;
_resource = new ResourceHelper();
_resource = resource;
InitializeComponent();
}