Correct package version installed

Dependency injection works
Project renaming
WIP replacement of services with CQRS
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-24 17:31:34 +01:00
parent ba8bbe045b
commit f208e2d0b6
34 changed files with 310 additions and 124 deletions

View File

@@ -5,13 +5,22 @@ using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Storage;
using Windows.Storage.AccessCache;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.HockeyApp;
using ModernKeePass.Application;
using ModernKeePass.Application.Database.Commands.CloseDatabase;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
using ModernKeePass.Application.Database.Queries.GetDatabase;
using ModernKeePass.Common;
using ModernKeePass.Exceptions;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Exceptions;
using ModernKeePass.Infrastructure;
using ModernKeePass.Services;
using ModernKeePass.Views;
@@ -24,6 +33,10 @@ namespace ModernKeePass
/// </summary>
sealed partial class App
{
public IServiceProvider Services { get; }
private IMediator _mediator;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -39,6 +52,13 @@ namespace ModernKeePass
Suspending += OnSuspending;
Resuming += OnResuming;
UnhandledException += OnUnhandledException;
// Setup DI
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddApplication();
serviceCollection.AddInfrastructure();
Services = serviceCollection.BuildServiceProvider();
_mediator = Services.GetService<IMediator>();
}
#region Event Handlers
@@ -52,8 +72,7 @@ namespace ModernKeePass
exception.InnerException != null
? exception.InnerException
: exception;
var database = DatabaseService.Instance;
var resource = new ResourcesService();
if (realException is SaveException)
{
@@ -64,6 +83,7 @@ namespace ModernKeePass
resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"),
async command =>
{
var database = await _mediator.Send(new GetDatabaseQuery());
var savePicker = new FileSavePicker
{
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
@@ -73,7 +93,16 @@ namespace ModernKeePass
new List<string> {".kdbx"});
var file = await savePicker.PickSaveFileAsync();
if (file != null) database.Save(file);
if (file != null)
{
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
var fileInfo = new FileInfo
{
Name = file.DisplayName,
Path = token
};
await _mediator.Send(new SaveDatabaseCommand { FileInfo = fileInfo });
}
}, null);
}
}
@@ -136,14 +165,13 @@ namespace ModernKeePass
Window.Current.Activate();
}
private void OnResuming(object sender, object e)
private async void OnResuming(object sender, object e)
{
var currentFrame = Window.Current.Content as Frame;
var database = DatabaseService.Instance;
try
{
database.ReOpen();
var database = await _mediator.Send(new GetDatabaseQuery());
#if DEBUG
ToastNotificationHelper.ShowGenericToast(database.Name, "Database reopened (changes were saved)");
#endif
@@ -177,11 +205,14 @@ namespace ModernKeePass
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
var database = DatabaseService.Instance;
try
{
if (SettingsService.Instance.GetSetting("SaveSuspend", true)) database.Save();
database.Close(false);
var database = await _mediator.Send(new GetDatabaseQuery());
if (SettingsService.Instance.GetSetting("SaveSuspend", true))
{
await _mediator.Send(new SaveDatabaseCommand());
}
await _mediator.Send(new CloseDatabaseCommand());
}
catch (Exception exception)
{

View File

@@ -1,11 +0,0 @@
using System;
namespace ModernKeePass.Exceptions
{
public class NavigationException: Exception
{
public NavigationException(Type pageType) : base($"Failed to load Page {pageType.FullName}")
{
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
namespace ModernKeePass.Exceptions
{
public class SaveException : Exception
{
public new Exception InnerException { get; }
public SaveException(Exception exception)
{
InnerException = exception;
}
}
}

View File

@@ -20,7 +20,7 @@ namespace ModernKeePass.Interfaces
bool HasChanged { get; set; }
Task Open(StorageFile databaseFile, CompositeKey key, bool createNew = false);
void ReOpen();
Task ReOpen();
void Save();
Task Save(StorageFile file);
void CreateRecycleBin(string title);

View File

@@ -3,7 +3,7 @@ using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Microsoft.HockeyApp;
using ModernKeePass.Exceptions;
using ModernKeePass.Domain.Exceptions;
using ModernKeePass.Interfaces;
using ModernKeePass.ViewModels;
using ModernKeePassLib;
@@ -122,9 +122,9 @@ namespace ModernKeePass.Services
}
}
public void ReOpen()
public async Task ReOpen()
{
Open(_databaseFile, _compositeKey);
await Open(_databaseFile, _compositeKey);
}
/// <summary>

View File

@@ -242,7 +242,7 @@ namespace ModernKeePass.ViewModels
if (UpperCasePatternSelected) pwProfile.CharSet.Add(PwCharSet.UpperCase);
if (LowerCasePatternSelected) pwProfile.CharSet.Add(PwCharSet.LowerCase);
if (DigitsPatternSelected) pwProfile.CharSet.Add(PwCharSet.Digits);
if (SpecialPatternSelected) pwProfile.CharSet.Add(PwCharSet.SpecialChars);
if (SpecialPatternSelected) pwProfile.CharSet.Add(PwCharSet.Special);
if (MinusPatternSelected) pwProfile.CharSet.Add('-');
if (UnderscorePatternSelected) pwProfile.CharSet.Add('_');
if (SpacePatternSelected) pwProfile.CharSet.Add(' ');

View File

@@ -85,7 +85,7 @@ namespace ModernKeePass.Views.UserControls
if (UpdateKey)
{
Model.UpdateKey();
await Model.UpdateKey();
ValidationChecked?.Invoke(this, new PasswordEventArgs(Model.RootGroup));
}
else
@@ -157,7 +157,7 @@ namespace ModernKeePass.Views.UserControls
var file = await savePicker.PickSaveFileAsync();
if (file == null) return;
Model.CreateKeyFile(file);
await Model.CreateKeyFile(file);
}
private async Task OpenDatabase(IResourceService resource)

View File

@@ -19,6 +19,8 @@
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxBundlePlatforms>neutral</AppxBundlePlatforms>
<AppxBundle>Always</AppxBundle>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -116,7 +118,6 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\IntToSymbolConverter.cs" />
<Compile Include="Exceptions\NavigationException.cs" />
<Compile Include="ImportFormats\CsvImportFormat.cs" />
<Compile Include="ImportFormats\NullImportFormat.cs" />
<Compile Include="Interfaces\IFormat.cs" />
@@ -147,7 +148,6 @@
<Compile Include="Converters\DiscreteIntToSolidColorBrushConverter.cs" />
<Compile Include="Converters\EmptyStringToVisibilityConverter.cs" />
<Compile Include="Converters\NullToBooleanConverter.cs" />
<Compile Include="Exceptions\SaveException.cs" />
<Compile Include="Extensions\DispatcherTaskExtensions.cs" />
<Compile Include="Interfaces\IDatabaseService.cs" />
<Compile Include="Interfaces\IHasSelectableObject.cs" />
@@ -393,10 +393,41 @@
</Page>
</ItemGroup>
<ItemGroup>
<Reference Include="Autofac">
<HintPath>..\..\..\..\..\.nuget\packages\Autofac\4.9.4\lib\netstandard1.1\Autofac.dll</HintPath>
</Reference>
<Reference Include="AutoMapper, Version=6.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.6.1.1\lib\netstandard1.1\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper.Extensions.Microsoft.DependencyInjection, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.Extensions.Microsoft.DependencyInjection.2.0.1\lib\netstandard1.1\AutoMapper.Extensions.Microsoft.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.8.5\lib\netstandard1.0\BouncyCastle.Crypto.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentValidation, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7de548da2fbae0f0, processorArchitecture=MSIL">
<HintPath>..\packages\FluentValidation.8.6.2\lib\netstandard1.1\FluentValidation.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MediatR, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediatR.3.0.1\lib\netstandard1.1\MediatR.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MediatR.Extensions.Microsoft.DependencyInjection, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediatR.Extensions.Microsoft.DependencyInjection.2.0.0\lib\netstandard1.1\MediatR.Extensions.Microsoft.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.HockeyApp.Core45, Version=4.1.6.1005, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\HockeySDK.Core.4.1.6\lib\portable-net45+win8+wp8+wpa81+win81+uap10.0\Microsoft.HockeyApp.Core45.dll</HintPath>
<Private>True</Private>
@@ -433,6 +464,14 @@
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.ComponentModel.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.Primitives.4.3.0\lib\netstandard1.0\System.ComponentModel.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.ComponentModel.TypeConverter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.TypeConverter.4.3.0\lib\netstandard1.0\System.ComponentModel.TypeConverter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Drawing.Primitives.4.3.0\lib\netstandard1.1\System.Drawing.Primitives.dll</HintPath>
<Private>True</Private>
@@ -538,30 +577,23 @@
<Content Include="Assets\Wide310x150Logo.scale-80.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ModernKeePass.Application\ModernKeePass.Application.csproj">
<ProjectReference Include="..\ModernKeePass.Application\Application.csproj">
<Project>{42353562-5e43-459c-8e3e-2f21e575261d}</Project>
<Name>ModernKeePass.Application</Name>
<Name>Application</Name>
</ProjectReference>
<ProjectReference Include="..\ModernKeePass.Domain\ModernKeePass.Domain.csproj">
<ProjectReference Include="..\ModernKeePass.Domain\Domain.csproj">
<Project>{9a0759f1-9069-4841-99e3-3bec44e17356}</Project>
<Name>ModernKeePass.Domain</Name>
<Name>Domain</Name>
</ProjectReference>
<ProjectReference Include="..\ModernKeePass.Infrastructure\ModernKeePass.Infrastructure.csproj">
<ProjectReference Include="..\ModernKeePass.Infrastructure\Infrastructure.csproj">
<Project>{09577e4c-4899-45b9-bf80-1803d617ccae}</Project>
<Name>ModernKeePass.Infrastructure</Name>
<Name>Infrastructure</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
<VisualStudioVersion>12.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="6.1.1" targetFramework="win81" />
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="2.0.1" targetFramework="win81" />
<package id="FluentValidation" version="8.6.2" targetFramework="win81" />
<package id="HockeySDK.Core" version="4.1.6" targetFramework="win81" />
<package id="HockeySDK.WINRT" version="4.1.6" targetFramework="win81" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="win81" />
<package id="MediatR" version="3.0.1" targetFramework="win81" />
<package id="MediatR.Extensions.Microsoft.DependencyInjection" version="2.0.0" targetFramework="win81" />
<package id="Microsoft.CSharp" version="4.3.0" targetFramework="win81" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.1.1" targetFramework="win81" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.1.1" targetFramework="win81" />
<package id="Microsoft.NETCore.Platforms" version="2.1.1" targetFramework="win81" />
<package id="Microsoft.NETCore.Portable.Compatibility" version="1.0.1" targetFramework="win81" />
<package id="Microsoft.NETCore.UniversalWindowsPlatform" version="6.1.7" targetFramework="win81" />
@@ -15,14 +22,21 @@
<package id="Splat" version="3.0.0" targetFramework="win81" />
<package id="System.Buffers" version="4.5.0" targetFramework="win81" />
<package id="System.Collections" version="4.3.0" targetFramework="win81" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="win81" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="win81" />
<package id="System.ComponentModel" version="4.3.0" targetFramework="win81" />
<package id="System.ComponentModel.Primitives" version="4.3.0" targetFramework="win81" />
<package id="System.ComponentModel.TypeConverter" version="4.3.0" targetFramework="win81" />
<package id="System.Diagnostics.Contracts" version="4.3.0" targetFramework="win81" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="win81" />
<package id="System.Drawing.Primitives" version="4.3.0" targetFramework="win81" />
<package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="win81" />
<package id="System.Globalization" version="4.3.0" targetFramework="win81" />
<package id="System.IO" version="4.3.0" targetFramework="win81" />
<package id="System.IO.Compression" version="4.3.0" targetFramework="win81" />
<package id="System.Linq" version="4.3.0" targetFramework="win81" />
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="win81" />
<package id="System.Linq.Queryable" version="4.3.0" targetFramework="win81" />
<package id="System.Memory" version="4.5.1" targetFramework="win81" />
<package id="System.Net.Requests" version="4.3.0" targetFramework="win81" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="win81" />
@@ -37,6 +51,7 @@
<package id="System.Runtime.Serialization.Primitives" version="4.3.0" targetFramework="win81" />
<package id="System.Runtime.WindowsRuntime" version="4.3.0" targetFramework="win81" />
<package id="System.Text.Encoding" version="4.3.0" targetFramework="win81" />
<package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="win81" />
<package id="System.Threading" version="4.3.0" targetFramework="win81" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="win81" />
<package id="System.Threading.Tasks.Parallel" version="4.3.0" targetFramework="win81" />