From e837e425c5dc712728c75c80bd7151f1fd178f5a Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Tue, 2 Jul 2024 22:20:02 +0800 Subject: [PATCH] fix minor issue --- .../Core/Database/AdvancedDbCollectionView.cs | 4 +-- .../Database/IAdvancedDbCollectionView.cs | 12 ++++++++ .../Core/ExceptionService/HutaoException.cs | 7 ----- .../Achievement/AchievementDbService.cs | 4 +-- .../Service/Achievement/AchievementService.cs | 28 +++++++++++++------ .../Achievement/IAchievementService.cs | 4 +-- .../Service/Cultivation/CultivationService.cs | 26 +++++++---------- .../UI/Xaml/Control/StandardView.xaml | 13 +++++---- .../UI/Xaml/Data/AdvancedCollectionView.cs | 12 ++++++-- .../UI/Xaml/View/Page/AchievementPage.xaml | 2 +- .../UI/Xaml/View/Page/LaunchGamePage.xaml | 2 +- .../Achievement/AchievementImporter.cs | 4 +-- .../Achievement/AchievementViewModel.cs | 18 ++++++------ .../Cultivation/CultivationViewModel.cs | 2 +- 14 files changed, 76 insertions(+), 62 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Core/Database/IAdvancedDbCollectionView.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Database/AdvancedDbCollectionView.cs b/src/Snap.Hutao/Snap.Hutao/Core/Database/AdvancedDbCollectionView.cs index 7b03141f..7af5c052 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Database/AdvancedDbCollectionView.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Database/AdvancedDbCollectionView.cs @@ -10,7 +10,7 @@ using Snap.Hutao.UI.Xaml.Data; namespace Snap.Hutao.Core.Database; // The scope of the view follows the scope of the service provider. -internal sealed class AdvancedDbCollectionView : AdvancedCollectionView +internal sealed class AdvancedDbCollectionView : AdvancedCollectionView, IAdvancedDbCollectionView where TEntity : class, IAdvancedCollectionViewItem, ISelectable { private readonly IServiceProvider serviceProvider; @@ -57,7 +57,7 @@ internal sealed class AdvancedDbCollectionView : AdvancedCollectionView // The scope of the view follows the scope of the service provider. [SuppressMessage("", "SA1402")] -internal sealed class AdvancedDbCollectionView : AdvancedCollectionView +internal sealed class AdvancedDbCollectionView : AdvancedCollectionView, IAdvancedDbCollectionView where TEntityAccess : class, IEntityAccess, IAdvancedCollectionViewItem where TEntity : class, ISelectable { diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Database/IAdvancedDbCollectionView.cs b/src/Snap.Hutao/Snap.Hutao/Core/Database/IAdvancedDbCollectionView.cs new file mode 100644 index 00000000..ca13cf68 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Core/Database/IAdvancedDbCollectionView.cs @@ -0,0 +1,12 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.UI.Xaml.Data; + +namespace Snap.Hutao.Core.Database; + +internal interface IAdvancedDbCollectionView : IAdvancedCollectionView + where TEntity : class +{ + void Detach(); +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs index e90e4b22..cec74ad6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/ExceptionService/HutaoException.cs @@ -51,13 +51,6 @@ internal sealed class HutaoException : Exception throw new HutaoException(SH.FormatServiceGachaStatisticsFactoryItemIdInvalid(id), innerException); } - [DoesNotReturn] - [MethodImpl(MethodImplOptions.NoInlining)] - public static HutaoException UserdataCorrupted(string message, Exception? innerException = default) - { - throw new HutaoException(message, innerException); - } - [DoesNotReturn] [MethodImpl(MethodImplOptions.NoInlining)] public static InvalidCastException InvalidCast(string name, Exception? innerException = default) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbService.cs index 22f8ffd6..19b2f2be 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementDbService.cs @@ -28,7 +28,7 @@ internal sealed partial class AchievementDbService : IAchievementDbService } catch (ArgumentException ex) { - throw HutaoException.UserdataCorrupted(SH.ServiceAchievementUserdataCorruptedAchievementIdNotUnique, ex); + throw HutaoException.Throw(SH.ServiceAchievementUserdataCorruptedAchievementIdNotUnique, ex); } } @@ -65,7 +65,7 @@ internal sealed partial class AchievementDbService : IAchievementDbService public void RemoveAchievementArchive(AchievementArchive archive) { - // It will cascade delete the achievements. + // Cascade delete the achievements. this.Delete(archive); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs index 4c9934ac..6e92e93a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/AchievementService.cs @@ -7,7 +7,9 @@ using Snap.Hutao.Core.ExceptionService; using Snap.Hutao.Model.Entity; using Snap.Hutao.Model.InterChange.Achievement; using Snap.Hutao.Model.Primitive; +using Snap.Hutao.UI.Xaml.Data; using Snap.Hutao.ViewModel.Achievement; +using System.Collections.ObjectModel; using EntityAchievement = Snap.Hutao.Model.Entity.Achievement; namespace Snap.Hutao.Service.Achievement; @@ -23,11 +25,19 @@ internal sealed partial class AchievementService : IAchievementService private readonly RuntimeOptions runtimeOptions; private readonly ITaskContext taskContext; - private AdvancedDbCollectionView? archivesView; + private AdvancedDbCollectionView? archives; - public AdvancedDbCollectionView Archives + public async ValueTask> GetArchivesAsync(CancellationToken token = default) { - get => archivesView ??= new(achievementDbService.GetAchievementArchiveCollection(), serviceProvider); + if (archives is null) + { + await taskContext.SwitchToBackgroundAsync(); + ObservableCollection source = achievementDbService.GetAchievementArchiveCollection(); + await taskContext.SwitchToMainThreadAsync(); + archives = new(source, serviceProvider); + } + + return archives; } public List GetAchievementViewList(AchievementArchive archive, AchievementServiceMetadataContext context) @@ -53,27 +63,27 @@ internal sealed partial class AchievementService : IAchievementService return ArchiveAddResultKind.InvalidName; } - ArgumentNullException.ThrowIfNull(archivesView); + ArgumentNullException.ThrowIfNull(archives); - if (archivesView.SourceCollection.Any(a => a.Name == newArchive.Name)) + if (archives.SourceCollection.Any(a => a.Name == newArchive.Name)) { return ArchiveAddResultKind.AlreadyExists; } await taskContext.SwitchToMainThreadAsync(); - archivesView.Add(newArchive); - archivesView.MoveCurrentTo(newArchive); + archives.Add(newArchive); + archives.MoveCurrentTo(newArchive); return ArchiveAddResultKind.Added; } public async ValueTask RemoveArchiveAsync(AchievementArchive archive) { - ArgumentNullException.ThrowIfNull(archivesView); + ArgumentNullException.ThrowIfNull(archives); // Sync cache await taskContext.SwitchToMainThreadAsync(); - archivesView.Remove(archive); + archives.Remove(archive); // Sync database await taskContext.SwitchToBackgroundAsync(); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/IAchievementService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/IAchievementService.cs index 8625e8df..6ccbc5c8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Achievement/IAchievementService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Achievement/IAchievementService.cs @@ -10,9 +10,9 @@ namespace Snap.Hutao.Service.Achievement; internal interface IAchievementService { - AdvancedDbCollectionView Archives { get; } + ValueTask> GetArchivesAsync(CancellationToken token = default); - ValueTask ExportToUIAFAsync(EntityArchive selectedArchive); + ValueTask ExportToUIAFAsync(EntityArchive archive); List GetAchievementViewList(EntityArchive archive, AchievementServiceMetadataContext context); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs index 8f5eab0c..6f49ac41 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs @@ -13,10 +13,6 @@ using ModelItem = Snap.Hutao.Model.Item; namespace Snap.Hutao.Service.Cultivation; -/// -/// 养成计算服务 -/// -[HighQuality] [ConstructorGenerated] [Injection(InjectAs.Singleton, typeof(ICultivationService))] internal sealed partial class CultivationService : ICultivationService @@ -126,19 +122,17 @@ internal sealed partial class CultivationService : ICultivationService return true; } + await taskContext.SwitchToMainThreadAsync(); + if (Projects.CurrentItem is null) + { + Projects.MoveCurrentTo(Projects.SourceCollection.SelectedOrDefault()); + if (Projects.CurrentItem is null) + { + return false; + } + } + await taskContext.SwitchToBackgroundAsync(); - - if (Projects?.CurrentItem is null) - { - // Initialize - _ = Projects; - } - - if (Projects?.CurrentItem is null) - { - return false; - } - CultivateEntry? entry = cultivationDbService.GetCultivateEntryByProjectIdAndItemId(Projects.CurrentItem.InnerId, itemId); if (entry is null) diff --git a/src/Snap.Hutao/Snap.Hutao/UI/Xaml/Control/StandardView.xaml b/src/Snap.Hutao/Snap.Hutao/UI/Xaml/Control/StandardView.xaml index 1d6ca20e..0979ffad 100644 --- a/src/Snap.Hutao/Snap.Hutao/UI/Xaml/Control/StandardView.xaml +++ b/src/Snap.Hutao/Snap.Hutao/UI/Xaml/Control/StandardView.xaml @@ -5,6 +5,7 @@ Visible Collapsed + 0:0:0.5