From 63d6769d4716e66a77dfdb1a6f6d1ff3e0a8a139 Mon Sep 17 00:00:00 2001 From: nayaku Date: Wed, 13 Sep 2023 16:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E7=89=87Hash?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E5=AD=98=E5=82=A8=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=9B=20=E4=BF=AE=E6=94=B9=E6=84=9F=E7=9F=A5Hash?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E7=AE=97=E5=92=8C=E5=88=A4=E6=96=AD=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=9B=20=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E5=AF=BC=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=20#1=EF=BC=9B=20=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E7=9A=84=E5=AF=BC=E5=85=A5=EF=BC=9B=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=99=A8?= =?UTF-8?q?=EF=BC=9B=20=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E7=BB=93=E6=9E=84=EF=BC=9B=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E8=BD=AC=E6=8D=A2=E5=99=A8=EF=BC=9B=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8C=85=EF=BC=9B=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E4=BA=86=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B7=B2=E6=9C=89=E6=A0=87=E7=AD=BE=E5=90=8E?= =?UTF-8?q?=E5=87=BA=E9=94=99=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageManager/App.xaml | 5 +- ImageManager/App.xaml.cs | 12 +- ImageManager/Bootstrapper.cs | 15 +- ImageManager/Data/Model/Label.cs | 5 + ImageManager/Data/Model/Picture.cs | 38 +- ImageManager/Data/PictureDataArchive.cs | 386 ++++++++++++++++++ ImageManager/Data/PictureFactory.cs | 188 +++++++++ ImageManager/Data/UserSettingData.cs | 4 + ImageManager/ImageManager.csproj | 13 +- ImageManager/Logging/Logger.cs | 115 ++++++ ImageManager/Logging/LoggerFactory.cs | 7 + ...230911081455_UpdatePictureHash.Designer.cs | 124 ++++++ .../20230911081455_UpdatePictureHash.cs | 88 ++++ .../Migrations/ImageContextModelSnapshot.cs | 11 +- ImageManager/Migrations/MigrationCustom.cs | 13 + ImageManager/Migrations/MigratorEx.cs | 25 ++ ImageManager/Tools/BindingProxy.cs | 26 -- .../IsNullOrEmptyToVisibilityConverter.cs | 23 ++ .../Converter}/StyleConverter.cs | 2 +- ImageManager/Tools/Extension/ContainerEx.cs | 21 + .../Tools/{ => Helper}/ClipboardHelper.cs | 8 +- .../{ => Helper}/ControlsSearchHelper.cs | 6 +- ImageManager/Tools/ImageComparer.cs | 68 --- ImageManager/Tools/Log.cs | 86 ---- .../ViewModels/AddImageProgressViewModel.cs | 249 ----------- .../AddImageProgressViewModelWrap.cs | 160 ++++++++ ImageManager/ViewModels/AddImageViewModel.cs | 27 +- ImageManager/ViewModels/DialogViewModel.cs | 28 +- .../ExportImageProgressViewModelWrap.cs | 99 +++++ ImageManager/ViewModels/MainPageViewModel.cs | 33 +- .../ViewModels/PictureAddLabelViewModel.cs | 13 +- .../PictureSelectableItemWrapper.cs | 5 +- ImageManager/ViewModels/ProgressViewModel.cs | 71 ++++ .../ViewModels/ProgressViewModelWrapBase.cs | 49 +++ ImageManager/ViewModels/RootViewModel.cs | 107 ++++- ImageManager/Views/DialogView.xaml | 23 +- ImageManager/Views/MainPageView.xaml | 10 +- ImageManager/Views/MainPageView.xaml.cs | 2 +- ...ageProgressView.xaml => ProgressView.xaml} | 8 +- ...gressView.xaml.cs => ProgressView.xaml.cs} | 7 +- ImageManager/Views/RootView.xaml | 14 +- readme.md | 8 +- 42 files changed, 1638 insertions(+), 564 deletions(-) create mode 100644 ImageManager/Data/PictureDataArchive.cs create mode 100644 ImageManager/Data/PictureFactory.cs create mode 100644 ImageManager/Logging/Logger.cs create mode 100644 ImageManager/Logging/LoggerFactory.cs create mode 100644 ImageManager/Migrations/20230911081455_UpdatePictureHash.Designer.cs create mode 100644 ImageManager/Migrations/20230911081455_UpdatePictureHash.cs create mode 100644 ImageManager/Migrations/MigrationCustom.cs create mode 100644 ImageManager/Migrations/MigratorEx.cs delete mode 100644 ImageManager/Tools/BindingProxy.cs create mode 100644 ImageManager/Tools/Converter/IsNullOrEmptyToVisibilityConverter.cs rename ImageManager/{Views => Tools/Converter}/StyleConverter.cs (94%) create mode 100644 ImageManager/Tools/Extension/ContainerEx.cs rename ImageManager/Tools/{ => Helper}/ClipboardHelper.cs (98%) rename ImageManager/Tools/{ => Helper}/ControlsSearchHelper.cs (93%) delete mode 100644 ImageManager/Tools/ImageComparer.cs delete mode 100644 ImageManager/Tools/Log.cs delete mode 100644 ImageManager/ViewModels/AddImageProgressViewModel.cs create mode 100644 ImageManager/ViewModels/AddImageProgressViewModelWrap.cs create mode 100644 ImageManager/ViewModels/ExportImageProgressViewModelWrap.cs create mode 100644 ImageManager/ViewModels/ProgressViewModel.cs create mode 100644 ImageManager/ViewModels/ProgressViewModelWrapBase.cs rename ImageManager/Views/{AddImageProgressView.xaml => ProgressView.xaml} (86%) rename ImageManager/Views/{AddImageProgressView.xaml.cs => ProgressView.xaml.cs} (94%) diff --git a/ImageManager/App.xaml b/ImageManager/App.xaml index 50351d4..a93089c 100644 --- a/ImageManager/App.xaml +++ b/ImageManager/App.xaml @@ -2,9 +2,9 @@ x:Class="ImageManager.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:conv="clr-namespace:ImageManager.Tools.Converter" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:local="clr-namespace:ImageManager" - xmlns:local2="clr-namespace:ImageManager.Views" xmlns:s="https://github.com/canton7/Stylet"> @@ -23,7 +23,8 @@ - + + diff --git a/ImageManager/App.xaml.cs b/ImageManager/App.xaml.cs index 8830c84..c86306f 100644 --- a/ImageManager/App.xaml.cs +++ b/ImageManager/App.xaml.cs @@ -1,9 +1,10 @@ using HandyControl.Themes; -using ImageManager.Tools; using System.Diagnostics; using System.Reflection; using System.Windows; using System.Windows.Threading; +using LoggerFactory = ImageManager.Logging.LoggerFactory; +using LogLevel = ImageManager.Logging.LogLevel; namespace ImageManager { @@ -59,15 +60,13 @@ protected override void OnStartup(StartupEventArgs e) void ThrowException(Exception e) { - Log.Error(e.ToString()); - Log.ReportError(e.ToString()); + LoggerFactory.GetLogger(nameof(App)).Log(LogLevel.Fatal, exception: e); MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); } void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - Log.Error(e.Exception.ToString()); - Log.ReportError(e.Exception.ToString()); + LoggerFactory.GetLogger(nameof(App)).Log(LogLevel.Fatal, exception: e.Exception); MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + e.Exception.Message.ToString(), "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); e.Handled = true; } @@ -75,8 +74,7 @@ void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExce void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var ex = (Exception)e.ExceptionObject; - Log.Error(ex.ToString()); - Log.ReportError(ex.ToString()); + LoggerFactory.GetLogger(nameof(App)).Log(LogLevel.Fatal, exception: ex); MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止。我们将会上传错误日志以便开发人员解决问题。\n错误信息:" + ex.Message, "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); } diff --git a/ImageManager/Bootstrapper.cs b/ImageManager/Bootstrapper.cs index 93f2264..c3e6edd 100644 --- a/ImageManager/Bootstrapper.cs +++ b/ImageManager/Bootstrapper.cs @@ -1,23 +1,34 @@ using ImageManager.Data; +using ImageManager.Logging; +using ImageManager.Migrations; using ImageManager.ViewModels; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; using StyletIoC; namespace ImageManager { public class Bootstrapper : Bootstrapper { + private Logging.Logger _logger = LoggerFactory.GetLogger(nameof(Bootstrapper)); protected override void ConfigureIoC(IStyletIoCBuilder builder) { var userSettingData = UserSettingData.Default; builder.Bind().ToInstance(userSettingData); - // create Database context + + // 准备数据库 var context = new ImageContext(); - context.Database.Migrate(); + var migrator = context.GetService(); + foreach (var migration in context.Database.GetPendingMigrations()) + { + migrator.MigrateEx(migration, context); + } // 为每个窗体都配置一个DB上下文 builder.Bind() .ToFactory(container => new ImageContext()); + // 清理 Task.Run(() => { diff --git a/ImageManager/Data/Model/Label.cs b/ImageManager/Data/Model/Label.cs index 3962e35..acb56c2 100644 --- a/ImageManager/Data/Model/Label.cs +++ b/ImageManager/Data/Model/Label.cs @@ -24,5 +24,10 @@ public override bool Equals(object? obj) } return false; } + + public override int GetHashCode() + { + return Name.GetHashCode(); + } } } diff --git a/ImageManager/Data/Model/Picture.cs b/ImageManager/Data/Model/Picture.cs index 057ca73..5b2e0ee 100644 --- a/ImageManager/Data/Model/Picture.cs +++ b/ImageManager/Data/Model/Picture.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using ImageManager.Logging; +using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Windows.Media.Imaging; @@ -36,9 +37,10 @@ public class Picture public int Width { get; set; } public int Height { get; set; } public DateTime AddTime { get; set; } - public string Hash { get; set; } - public ulong? WeakHash { get; set; } - public virtual List