From aa798ca60278c2c651d8e6ba636030a531414ca4 Mon Sep 17 00:00:00 2001 From: yangzhiqin <12345> Date: Fri, 7 Jul 2023 14:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OMDb.Core/Const/Const.cs | 19 ++ OMDb.Core/Const/MediaTypes.cs | 21 ++ .../Helpers/ExcelHelper.cs | 0 OMDb.Core/Helpers/ImageHelper.cs | 103 +++++++-- OMDb.Core/Helpers/LogHelper.cs | 30 --- OMDb.Core/Models/Entry.cs | 2 +- OMDb.Core/Models/EntryCollection.cs | 2 +- OMDb.Core/Models/EntryCollectionItem.cs | 2 +- OMDb.Core/Models/EntryMetadata.cs | 1 + OMDb.Core/Models/EntryName.cs | 2 +- OMDb.Core/Models/ExtractsLine.cs | 2 +- OMDb.Core/Models/WatchHistory.cs | 2 +- OMDb.Core/OMDb.Core.csproj | 1 + OMDb.Core/Services/CommonService.cs | 3 +- ...elService.cs => EntryLabelClassService.cs} | 2 +- .../{LabelService.cs => LabelClassService.cs} | 4 +- OMDb.Core/Services/DbService.cs | 6 +- .../Services/StorageDbService/EntryService.cs | 60 +++--- ...Service.cs => EntryWatchHistoryService.cs} | 2 +- .../{ => Utils}/Extensions/EnumExtension.cs | 2 +- .../Extensions/IEnumerableExtension.cs | 2 +- .../{ => Utils}/Extensions/ObjectExtension.cs | 28 ++- OMDb.Core/Utils/Logger.cs | 46 ++++ OMDb.Core/Utils/ObjectUtil.cs | 5 +- OMDb.Core/Utils/PathUtils/PathUtils.cs | 14 ++ OMDb.Core/Utils/PathUtils/TempPathUtils.cs | 102 +++++++++ OMDb.Douban/EntryInfo.cs | 16 +- OMDb.Douban/Rate.cs | 4 +- OMDb.JavDb/EntryInfo.cs | 6 +- .../Private/LPIdToReadOnlyConverter.cs | 5 +- .../Dialogs/AddEntryBatchDialog.xaml.cs | 30 ++- .../AddLabelPropertyDataLKDialog.xaml.cs | 6 +- .../Dialogs/AddLabelPropertyLKDialog.xaml.cs | 1 - .../OMDb.WinUI3/Dialogs/EditDbSource.xaml.cs | 1 - .../Dialogs/EditEntryDialog.xaml.cs | 113 ++++------ .../Dialogs/EditStorageDialog.xaml.cs | 2 +- .../Dialogs/MyContentDialog.xaml.cs | 3 +- .../Dialogs/PickEntryCollectionDialog.xaml.cs | 1 - .../OMDb.WinUI3/Extensions/EntryExtension.cs | 3 +- .../OMDb.WinUI3/Helpers/FFmpegHelper.cs | 13 -- OMDb.WinUI3/OMDb.WinUI3/Helpers/FileHelper.cs | 5 +- OMDb.WinUI3/OMDb.WinUI3/Helpers/ImgHelper.cs | 47 +--- .../OMDb.WinUI3/Helpers/TempFileHelper.cs | 31 --- .../OMDb.WinUI3/Models/EntryCollection.cs | 4 +- OMDb.WinUI3/OMDb.WinUI3/Models/EntryDetail.cs | 16 +- .../Models/Tools/AVCodecConversionItem.cs | 2 +- .../MyControls/EntryDetailControl.xaml.cs | 1 - .../MyControls/EntryStoragesControl.xaml.cs | 1 - .../MyControls/ExplorerControl.xaml.cs | 2 +- .../MyControls/LabelsControl.xaml.cs | 4 +- .../MyControls/LabelsProPertyControl.xaml.cs | 1 - .../OMDb.WinUI3/Services/CommonService.cs | 134 ++++-------- .../OMDb.WinUI3/Services/ConfigService.cs | 3 +- .../OMDb.WinUI3/Services/EntryService.cs | 203 +++++++++--------- .../OMDb.WinUI3/Services/ExcelService.cs | 42 ++-- .../OMDb.WinUI3/Services/RecentFileService.cs | 2 +- .../ViewModels/ClassificationViewModel.cs | 5 +- .../Dialogs/AddEntryBatchViewModel.cs | 1 - .../ViewModels/Dialogs/EditEntryViewModel.cs | 4 +- .../EntryCollectionDetailViewModel.cs | 2 +- .../ViewModels/EntryDetailViewModel.cs | 12 +- .../OMDb.WinUI3/ViewModels/EntryViewModel.cs | 36 ++-- .../OMDb.WinUI3/ViewModels/HomeViewModel.cs | 1 - .../ViewModels/Homes/ExtractLineViewModel.cs | 2 +- .../ViewModels/Homes/RandomEntryViewModel.cs | 2 +- .../Homes/RecentlyUpdatedEntryViewModel.cs | 2 +- .../Homes/RecentlyWatchedEntryViewModel.cs | 2 +- .../Homes/RecentlyWatchedFilesViewModel.cs | 1 - .../ViewModels/Homes/StatisticsViewModel.cs | 4 +- .../ViewModels/LabelCollectionViewModel.cs | 4 +- .../OMDb.WinUI3/ViewModels/LabelViewModel.cs | 12 +- .../ViewModels/SettingViewModel.cs | 2 +- .../ViewModels/StorageViewModel.cs | 2 +- .../ViewModels/Tools/AVCodecToolViewModel.cs | 2 +- .../Management/LabelPropertyPage.xaml.cs | 10 +- 75 files changed, 688 insertions(+), 583 deletions(-) create mode 100644 OMDb.Core/Const/Const.cs create mode 100644 OMDb.Core/Const/MediaTypes.cs rename {OMDb.WinUI3/OMDb.WinUI3 => OMDb.Core}/Helpers/ExcelHelper.cs (100%) delete mode 100644 OMDb.Core/Helpers/LogHelper.cs rename OMDb.Core/Services/DataCenterDbService/{EntryLabelService.cs => EntryLabelClassService.cs} (96%) rename OMDb.Core/Services/DataCenterDbService/{LabelService.cs => LabelClassService.cs} (98%) rename OMDb.Core/Services/StorageDbService/{WatchHistoryService.cs => EntryWatchHistoryService.cs} (98%) rename OMDb.Core/{ => Utils}/Extensions/EnumExtension.cs (96%) rename OMDb.Core/{ => Utils}/Extensions/IEnumerableExtension.cs (98%) rename OMDb.Core/{ => Utils}/Extensions/ObjectExtension.cs (72%) create mode 100644 OMDb.Core/Utils/Logger.cs create mode 100644 OMDb.Core/Utils/PathUtils/PathUtils.cs create mode 100644 OMDb.Core/Utils/PathUtils/TempPathUtils.cs delete mode 100644 OMDb.WinUI3/OMDb.WinUI3/Helpers/FFmpegHelper.cs delete mode 100644 OMDb.WinUI3/OMDb.WinUI3/Helpers/TempFileHelper.cs diff --git a/OMDb.Core/Const/Const.cs b/OMDb.Core/Const/Const.cs new file mode 100644 index 0000000..195a477 --- /dev/null +++ b/OMDb.Core/Const/Const.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OMDb.Core.Const +{ + public class Const + { + public const string BlankSpace = " "; + + public const string LineBreak = "\n"; + + public const double Scale_Cover = 160.0 / 260.0; + } +} + diff --git a/OMDb.Core/Const/MediaTypes.cs b/OMDb.Core/Const/MediaTypes.cs new file mode 100644 index 0000000..86714c7 --- /dev/null +++ b/OMDb.Core/Const/MediaTypes.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OMDb.Core.Const +{ + public class MediaTypes + { + public static readonly ImmutableList Image = ImmutableList.Create("BMP", "JPG", "PNG", "TIF", "GIF", "PCX", "TGA", "EXIF", "FPX", "SVG", "PSD", "CDR", "PCD", "DXF", "UFO", "EPS", "AI", "RAW", "WMF", "WEBP", "AVIF", "APNG"); + + public static readonly ImmutableList Video = ImmutableList.Create("AVI","WMV","MPEG","MP4","M4V","MOV","ASF","FLV","F4V","RMVB","RM","3GP","VOB"); + + public static readonly ImmutableList VideoSub = ImmutableList.Create("SRT","WEBVTT","STL","SBV","ASS","DFXP","TTML"); + + public static readonly ImmutableList Audio = ImmutableList.Create("MP3","WAV","WMA","MP2","Flac","MIDI","RA","APE","AAC","CDA","MOV"); + + } +} diff --git a/OMDb.WinUI3/OMDb.WinUI3/Helpers/ExcelHelper.cs b/OMDb.Core/Helpers/ExcelHelper.cs similarity index 100% rename from OMDb.WinUI3/OMDb.WinUI3/Helpers/ExcelHelper.cs rename to OMDb.Core/Helpers/ExcelHelper.cs diff --git a/OMDb.Core/Helpers/ImageHelper.cs b/OMDb.Core/Helpers/ImageHelper.cs index fce1ce2..6c04f04 100644 --- a/OMDb.Core/Helpers/ImageHelper.cs +++ b/OMDb.Core/Helpers/ImageHelper.cs @@ -1,9 +1,13 @@ using ImageMagick; +using OMDb.Core.Const; using OMDb.Core.Models; +using OMDb.Core.Services; +using OMDb.Core.Utils.Extensions; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; +using System.Net; namespace OMDb.Core.Helpers { @@ -49,6 +53,9 @@ public static ImageInfo GetImageInfo(string path) } + + + private static async Task ToMemoryStreamAsync(Image image) { MemoryStream stream = new MemoryStream(); @@ -57,7 +64,7 @@ private static async Task ToMemoryStreamAsync(Image image) return stream; } - public static async void DrawBannerCoverAsync(List covers, ImageInfo bg,string savedPath) + public static async void DrawBannerCoverAsync(List covers, ImageInfo bg, string savedPath) { using (Image image = Image.Load(bg.FullPath)) { @@ -67,9 +74,9 @@ public static async void DrawBannerCoverAsync(List covers, ImageInfo images.Add(Image.Load(cover.FullPath)); } int width = (int)(bg.Width * 0.16); - foreach(Image coverImage in images) + foreach (Image coverImage in images) { - coverImage.Mutate(x => x.Resize(width, coverImage.Height * (width/ coverImage.Width))); + coverImage.Mutate(x => x.Resize(width, coverImage.Height * (width / coverImage.Width))); } double span = bg.Width * 0.025; Point[] points = new Point[images.Count]; @@ -157,7 +164,7 @@ public static async Task DrawWaterfallAsync(List covers, s } } } - foreach(var temp in images) + foreach (var temp in images) { temp.Dispose(); } @@ -182,7 +189,7 @@ public static async Task DrawWaterfallAsync(List covers, M foreach (Image coverImage in images) { var cutRect = CalPerfectResizeRectangle(coverImage.Width, coverImage.Height, width, height); - coverImage.Mutate(x => x.Resize(width, height, KnownResamplers.Bicubic, cutRect,new Rectangle(0,0,width,height),true)); + coverImage.Mutate(x => x.Resize(width, height, KnownResamplers.Bicubic, cutRect, new Rectangle(0, 0, width, height), true)); } int columCount = (int)Math.Ceiling(image.Width / (float)width); int rowCount = (int)Math.Ceiling(image.Height / (float)height) + 1; @@ -219,19 +226,19 @@ public static async Task DrawWaterfallAsync(List covers, M /// /// 如果为0则依据height等比例缩放 /// 如果为0则依据width等比例缩放 - public static async void ResetSizeAsync(string path,string savedPath, int width, int height) + public static async void ResetSizeAsync(string path, string savedPath, int width, int height) { using (Image image = Image.Load(path)) { - if(width != 0 && height != 0) + if (width != 0 && height != 0) { image.Mutate(x => x.Resize(width, height)); } - else if(width != 0) + else if (width != 0) { image.Mutate(x => x.Resize(width, image.Height * (width / image.Width))); } - else if(height != 0) + else if (height != 0) { image.Mutate(x => x.Resize(image.Width * (height / image.Height), height)); } @@ -333,7 +340,7 @@ public static async Task ResetSizeAsync(MemoryStream inputStream, /// /// /// - public static async Task BlurAsync(string path,float sigma = 10) + public static async Task BlurAsync(string path, float sigma = 10) { using (Image image = Image.Load(path)) { @@ -350,7 +357,7 @@ public static async Task BlurAsync(string path,float sigma = 10) /// /// /// - private static Rectangle CalPerfectResizeRectangle(int srcWidth,int srcHeight,int targetWidth,int targetHeight) + private static Rectangle CalPerfectResizeRectangle(int srcWidth, int srcHeight, int targetWidth, int targetHeight) { Rectangle resultRect; //宽高比越大,图片越矮胖 @@ -373,9 +380,81 @@ private static Rectangle CalPerfectResizeRectangle(int srcWidth,int srcHeight,in //原图宽高比小于目标宽高比,说明目标图片要变矮胖 //保留X,Y要裁剪 double srcCutHeight = targetHeight * srcWidth / targetWidth; - resultRect = new Rectangle(0,(int)(srcHeight / 2 - srcCutHeight / 2),srcWidth, (int)srcCutHeight); + resultRect = new Rectangle(0, (int)(srcHeight / 2 - srcCutHeight / 2), srcWidth, (int)srcCutHeight); } return resultRect; } + + + /// + /// 获取图片最佳排序 + /// + /// 图片路径 + /// 期望长宽比 + /// + public static List GetBestImg(IEnumerable paths, double scale) + { + List infos = new List(); + var path_imgs = paths.Where(a => MediaTypes.Image.Contains(Path.GetExtension(a).Remove(".").ToUpper())).Where(a => File.Exists(a)); + if (!path_imgs.IsNullOrEmptyOrWhiteSpazeOrCountZero()) + { + foreach (var path in Core.Helpers.RandomHelper.RandomList(path_imgs, 100))//仅对100张照片计算 + infos.Add(Core.Helpers.ImageHelper.GetImageInfo(path)); + + //优先长宽比更适配的图片 + List sortedInfos; + sortedInfos = infos.OrderBy(p => Math.Abs(p.Scale - scale)).OrderByDescending(p => p.Length).ToList(); + + int[] weights = new int[sortedInfos.Count]; + for (int i = 0; i < sortedInfos.Count; i++) + { + weights[i] = i + 1;//权重从1开始递增 + } + var coverItems = Core.Helpers.RandomHelper.RandomList(sortedInfos, weights, 1);//获取最优的 + return coverItems?.Select(p => p.FullPath).ToList(); + } + else + return null; + } + + + /// + /// 用远程地址获取文件字节流 + /// + /// URL + /// + public static byte[] GetUrlMemoryStream(string path) + { + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + Stream responseStream = response.GetResponseStream(); + + List btlst = new List(); + int b = responseStream.ReadByte(); + while (b > -1) + { + btlst.Add((byte)b); + b = responseStream.ReadByte(); + } + byte[] bts = btlst.ToArray(); + return bts; + } + + public static bool IsSupportImg(string file) + { + if (!string.IsNullOrEmpty(file)) + { + var ext = System.IO.Path.GetExtension(file).Replace(".", ""); + return MediaTypes.Image.Contains(ext.ToLower()); + } + else + { + return false; + } + } + + + } } diff --git a/OMDb.Core/Helpers/LogHelper.cs b/OMDb.Core/Helpers/LogHelper.cs deleted file mode 100644 index 4ea68ad..0000000 --- a/OMDb.Core/Helpers/LogHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Google.Protobuf.WellKnownTypes; -using Org.BouncyCastle.Utilities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; -using NLog; - -namespace OMDb.Core.Helpers -{ - public sealed class LogHelper - { - public Logger _logger = LogManager.GetLogger("OMDB"); - - private static readonly LogHelper instance = new LogHelper(); - - static LogHelper() { } - private LogHelper() { } - public static LogHelper Instance - { - get - { - return instance; - } - } - } -} - diff --git a/OMDb.Core/Models/Entry.cs b/OMDb.Core/Models/Entry.cs index b632f77..fd99cab 100644 --- a/OMDb.Core/Models/Entry.cs +++ b/OMDb.Core/Models/Entry.cs @@ -1,4 +1,4 @@ -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.Core/Models/EntryCollection.cs b/OMDb.Core/Models/EntryCollection.cs index ab989df..48078cb 100644 --- a/OMDb.Core/Models/EntryCollection.cs +++ b/OMDb.Core/Models/EntryCollection.cs @@ -1,5 +1,5 @@ using OMDb.Core.DbModels; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.Core/Models/EntryCollectionItem.cs b/OMDb.Core/Models/EntryCollectionItem.cs index 3c2d066..1147f55 100644 --- a/OMDb.Core/Models/EntryCollectionItem.cs +++ b/OMDb.Core/Models/EntryCollectionItem.cs @@ -1,5 +1,5 @@ using OMDb.Core.DbModels; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.Core/Models/EntryMetadata.cs b/OMDb.Core/Models/EntryMetadata.cs index 5c30df3..0cf2974 100644 --- a/OMDb.Core/Models/EntryMetadata.cs +++ b/OMDb.Core/Models/EntryMetadata.cs @@ -33,6 +33,7 @@ public bool Save(string file) { try { + JsonSerializerSettings settings = new JsonSerializerSettings { Formatting = Formatting.Indented }; var json = JsonConvert.SerializeObject(this); System.IO.File.WriteAllText(file, json); return true; diff --git a/OMDb.Core/Models/EntryName.cs b/OMDb.Core/Models/EntryName.cs index 1380576..6b4f4d1 100644 --- a/OMDb.Core/Models/EntryName.cs +++ b/OMDb.Core/Models/EntryName.cs @@ -1,4 +1,4 @@ -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.Core/Models/ExtractsLine.cs b/OMDb.Core/Models/ExtractsLine.cs index dcd5d94..2b7ab0e 100644 --- a/OMDb.Core/Models/ExtractsLine.cs +++ b/OMDb.Core/Models/ExtractsLine.cs @@ -1,4 +1,4 @@ -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.Core/Models/WatchHistory.cs b/OMDb.Core/Models/WatchHistory.cs index e39fd25..41240e9 100644 --- a/OMDb.Core/Models/WatchHistory.cs +++ b/OMDb.Core/Models/WatchHistory.cs @@ -1,4 +1,4 @@ -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.Core/OMDb.Core.csproj b/OMDb.Core/OMDb.Core.csproj index 1f80611..1e62478 100644 --- a/OMDb.Core/OMDb.Core.csproj +++ b/OMDb.Core/OMDb.Core.csproj @@ -7,6 +7,7 @@ + diff --git a/OMDb.Core/Services/CommonService.cs b/OMDb.Core/Services/CommonService.cs index f923fd7..3a36ade 100644 --- a/OMDb.Core/Services/CommonService.cs +++ b/OMDb.Core/Services/CommonService.cs @@ -1,5 +1,4 @@ -using OMDb.Core.Extensions; -using OMDb.Core.Models; +using OMDb.Core.Models; using OMDb.Core.Utils.StringUtil; using System; using System.Collections.Generic; diff --git a/OMDb.Core/Services/DataCenterDbService/EntryLabelService.cs b/OMDb.Core/Services/DataCenterDbService/EntryLabelClassService.cs similarity index 96% rename from OMDb.Core/Services/DataCenterDbService/EntryLabelService.cs rename to OMDb.Core/Services/DataCenterDbService/EntryLabelClassService.cs index d851f6d..626546b 100644 --- a/OMDb.Core/Services/DataCenterDbService/EntryLabelService.cs +++ b/OMDb.Core/Services/DataCenterDbService/EntryLabelClassService.cs @@ -8,7 +8,7 @@ namespace OMDb.Core.Services { - public static class EntryLabelService + public static class EntryLabelClassService { /// /// 查詢所有Entry&Label對應關係 diff --git a/OMDb.Core/Services/DataCenterDbService/LabelService.cs b/OMDb.Core/Services/DataCenterDbService/LabelClassService.cs similarity index 98% rename from OMDb.Core/Services/DataCenterDbService/LabelService.cs rename to OMDb.Core/Services/DataCenterDbService/LabelClassService.cs index 4d684ae..be6cdf7 100644 --- a/OMDb.Core/Services/DataCenterDbService/LabelService.cs +++ b/OMDb.Core/Services/DataCenterDbService/LabelClassService.cs @@ -8,7 +8,7 @@ namespace OMDb.Core.Services { - public static class LabelService + public static class LabelClassService { private static bool IsLocalDbValid() { @@ -42,7 +42,7 @@ public static async Task> GetAllLabelAsync(string currentDb) public static List GetAllLabel(string currentDb) { StringBuilder sb = new StringBuilder(); - sb.AppendFormat(@"select * from Label where DbCenterId='{0}'", currentDb); + sb.AppendFormat(@"select * from LabelClass where DbCenterId='{0}'", currentDb); return DbService.DCDb.Ado.SqlQuery(sb.ToString()); } diff --git a/OMDb.Core/Services/DbService.cs b/OMDb.Core/Services/DbService.cs index a4d7d56..1a5eaf7 100644 --- a/OMDb.Core/Services/DbService.cs +++ b/OMDb.Core/Services/DbService.cs @@ -1,7 +1,7 @@ using OMDb.Core.DbModels; using OMDb.Core.DbModels.ManagerCenterDb; -using OMDb.Core.Helpers; using OMDb.Core.Models; +using OMDb.Core.Utils; using SqlSugar; using System; using System.Collections.Generic; @@ -167,7 +167,7 @@ internal static bool SetMCDb(string connet) } catch (Exception ex) { - LogHelper.Instance._logger.Error(ex); + Logger.Error(ex); return false; } } @@ -215,7 +215,7 @@ internal static bool SetDCDb(string connet) } catch (Exception ex) { - LogHelper.Instance._logger.Error(ex); + Logger.Error(ex); return false; } } diff --git a/OMDb.Core/Services/StorageDbService/EntryService.cs b/OMDb.Core/Services/StorageDbService/EntryService.cs index a617a91..a1e88ec 100644 --- a/OMDb.Core/Services/StorageDbService/EntryService.cs +++ b/OMDb.Core/Services/StorageDbService/EntryService.cs @@ -1,7 +1,7 @@ using OMDb.Core.DbModels; using OMDb.Core.Enums; -using OMDb.Core.Extensions; using OMDb.Core.Models; +using OMDb.Core.Utils.Extensions; using SqlSugar; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ public static List QueryEntry(Enums.SortType sortType, Enums.SortWa { return sortType switch { - Enums.SortType.CreateTime => SortByCreateTime(sortWay, dbIds,labelIds), + Enums.SortType.CreateTime => SortByCreateTime(sortWay, dbIds, labelIds), Enums.SortType.LastWatchTime => SortByLastWatchTime(sortWay, dbIds, labelIds), Enums.SortType.LastUpdateTime => SortByLastUpdateTime(sortWay, dbIds, labelIds), Enums.SortType.WatchTimes => SortByWatchTimes(sortWay, dbIds, labelIds), @@ -41,7 +41,7 @@ public static List QueryEntry(Enums.SortType sortType, Enums.SortWa } public static async Task> QueryEntryAsync(Enums.SortType sortType, Enums.SortWay sortWay, List dbIds = null, List labelIds = null) { - return await Task.Run(()=> QueryEntry(sortType, sortWay, dbIds, labelIds)); + return await Task.Run(() => QueryEntry(sortType, sortWay, dbIds, labelIds)); } private static List SortByCreateTime(Enums.SortWay sortWay, List dbIds, List labelIds = null) { @@ -49,7 +49,7 @@ private static List SortByCreateTime(Enums.SortWay sortWay, List inLabelEntryIds = null; if (labelIds != null && labelIds.Count != 0) { - inLabelEntryIds = LabelService.GetEntrys(labelIds); + inLabelEntryIds = LabelClassService.GetEntrys(labelIds); } foreach (var item in DbService.Dbs) { @@ -79,7 +79,7 @@ private static List SortByCreateTime(Enums.SortWay sortWay, List SortByLastWatchTime(Enums.SortWay sortWay, List List inLabelEntryIds = null; if (labelIds != null && labelIds.Count != 0) { - inLabelEntryIds = LabelService.GetEntrys(labelIds); + inLabelEntryIds = LabelClassService.GetEntrys(labelIds); } foreach (var item in DbService.Dbs) { @@ -142,7 +142,7 @@ private static List SortByLastUpdateTime(Enums.SortWay sortWay, Lis List inLabelEntryIds = null; if (labelIds != null && labelIds.Count != 0) { - inLabelEntryIds = LabelService.GetEntrys(labelIds); + inLabelEntryIds = LabelClassService.GetEntrys(labelIds); } foreach (var item in DbService.Dbs) { @@ -189,7 +189,7 @@ private static List SortByWatchTimes(Enums.SortWay sortWay, List inLabelEntryIds = null; if (labelIds != null && labelIds.Count != 0) { - inLabelEntryIds = LabelService.GetEntrys(labelIds); + inLabelEntryIds = LabelClassService.GetEntrys(labelIds); } foreach (var item in DbService.Dbs) { @@ -238,7 +238,7 @@ private static List SortByMyRating(Enums.SortWay sortWay, List inLabelEntryIds = null; if (labelIds != null && labelIds.Count != 0) { - inLabelEntryIds = LabelService.GetEntrys(labelIds); + inLabelEntryIds = LabelClassService.GetEntrys(labelIds); } foreach (var item in DbService.Dbs) { @@ -298,7 +298,7 @@ public static async Task> QueryEntryAsync(List queryItems { return await Task.Run(() => { - Dictionary dic = new Dictionary(); + Dictionary dic = new Dictionary(); var group = queryItems.GroupBy(p => p.DbId); foreach (var item in group) { @@ -318,9 +318,9 @@ public static async Task> QueryEntryAsync(List queryItems } } List entries = new List(); - foreach(var item in queryItems) + foreach (var item in queryItems) { - if(dic.TryGetValue(item.Id, out Entry entry)) + if (dic.TryGetValue(item.Id, out Entry entry)) { entries.Add(entry); } @@ -369,23 +369,19 @@ public static async Task QueryEntryAsync(QueryItem queryItem, bool withNa } /// - /// 添加前需指定数据库id - /// 若未设词条id将自动赋值 + /// 新增或编辑词条主表 /// /// - public static void AddEntry(Entry entry) + public static void UpdateOrAddEntry(Entry entry) { - if(string.IsNullOrEmpty(entry.EntryId)) - { + if (string.IsNullOrEmpty(entry.EntryId)) entry.EntryId = Guid.NewGuid().ToString(); - } entry.CoverImg = entry.CoverImg.GetDefaultCoverName(); - DbService.GetConnection(entry.DbId).Insertable(entry as EntryDb).ExecuteCommand(); - } - - public static void UpdateEntry(Entry entry) - { - DbService.GetConnection(entry.DbId).Updateable(entry as EntryDb).RemoveDataCache().ExecuteCommand(); + var existingEntry = DbService.GetConnection(entry.DbId).Queryable().Where(s => s.EntryId == entry.EntryId).First(); + if (existingEntry != null) + DbService.GetConnection(entry.DbId).Insertable(entry as EntryDb).ExecuteCommand(); + else + DbService.GetConnection(entry.DbId).Updateable(entry as EntryDb).RemoveDataCache().ExecuteCommand(); } /// @@ -398,8 +394,8 @@ public static void RemoveEntry(Entry entry) var connet = DbService.GetConnection(entry.DbId); connet.BeginTran(); connet.Deleteable().In(entry.EntryId).ExecuteCommand(); - connet.Deleteable().Where(p=>p.EntryId == entry.EntryId).ExecuteCommand(); - connet.Deleteable().Where(p=>p.EntryId == entry.EntryId).ExecuteCommand(); + connet.Deleteable().Where(p => p.EntryId == entry.EntryId).ExecuteCommand(); + connet.Deleteable().Where(p => p.EntryId == entry.EntryId).ExecuteCommand(); DbService.DCDb.Deleteable().Where(p => p.EntryId == entry.EntryId).ExecuteCommand(); DbService.DCDb.Deleteable().Where(p => p.EntryId == entry.EntryId).ExecuteCommand(); connet.CommitTran(); @@ -442,9 +438,9 @@ public static async Task> GetEntryByIdsAsync(IEnumerable ent /// /// 变化量,可用正负来表示增加减少 /// - public static bool UpdateWatchTime(string entryId,string dbId,int increment) + public static bool UpdateWatchTime(string entryId, string dbId, int increment) { - return DbService.GetConnection(dbId).Updateable().SetColumns(p=>p.WatchTimes == p.WatchTimes+increment).Where(p=>p.EntryId == entryId).ExecuteCommand() > 0; + return DbService.GetConnection(dbId).Updateable().SetColumns(p => p.WatchTimes == p.WatchTimes + increment).Where(p => p.EntryId == entryId).ExecuteCommand() > 0; } /// @@ -458,8 +454,8 @@ public static async Task> RandomEntryAsync(int count = 1) { return null; } - List> firstRandoms = new List>(); - foreach(var dbId in DbService.Dbs.Keys) + List> firstRandoms = new List>(); + foreach (var dbId in DbService.Dbs.Keys) { int max = await QueryEntryCountAsync(dbId); var indexes = Helpers.RandomHelper.RandomInt(0, max - 1, count); @@ -486,13 +482,13 @@ public static async Task> RandomEntryAsync(int count = 1) } - public static void AddEntry(EntryDb edb,string dbId) + public static void AddEntry(EntryDb edb, string dbId) { DbService.GetConnection(dbId).Insertable(edb).ExecuteCommand(); } public static void UpdateEntry(EntryDb edb, string dbId) { - DbService.GetConnection(dbId).Updateable(edb).Where(a=>a.EntryId.Equals(edb.EntryId)).ExecuteCommand(); + DbService.GetConnection(dbId).Updateable(edb).Where(a => a.EntryId.Equals(edb.EntryId)).ExecuteCommand(); } } } diff --git a/OMDb.Core/Services/StorageDbService/WatchHistoryService.cs b/OMDb.Core/Services/StorageDbService/EntryWatchHistoryService.cs similarity index 98% rename from OMDb.Core/Services/StorageDbService/WatchHistoryService.cs rename to OMDb.Core/Services/StorageDbService/EntryWatchHistoryService.cs index 5585df0..9258494 100644 --- a/OMDb.Core/Services/StorageDbService/WatchHistoryService.cs +++ b/OMDb.Core/Services/StorageDbService/EntryWatchHistoryService.cs @@ -8,7 +8,7 @@ namespace OMDb.Core.Services { - public static class WatchHistoryService + public static class EntryWatchHistoryService { /// /// 查询词条所有观看记录 diff --git a/OMDb.Core/Extensions/EnumExtension.cs b/OMDb.Core/Utils/Extensions/EnumExtension.cs similarity index 96% rename from OMDb.Core/Extensions/EnumExtension.cs rename to OMDb.Core/Utils/Extensions/EnumExtension.cs index f78485a..7b9330f 100644 --- a/OMDb.Core/Extensions/EnumExtension.cs +++ b/OMDb.Core/Utils/Extensions/EnumExtension.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace OMDb.Core.Extensions +namespace OMDb.Core.Utils.Extensions { public static class EnumExtension { diff --git a/OMDb.Core/Extensions/IEnumerableExtension.cs b/OMDb.Core/Utils/Extensions/IEnumerableExtension.cs similarity index 98% rename from OMDb.Core/Extensions/IEnumerableExtension.cs rename to OMDb.Core/Utils/Extensions/IEnumerableExtension.cs index 818c84f..a03b360 100644 --- a/OMDb.Core/Extensions/IEnumerableExtension.cs +++ b/OMDb.Core/Utils/Extensions/IEnumerableExtension.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace OMDb.Core.Extensions +namespace OMDb.Core.Utils.Extensions { public static class IEnumerableExtension { diff --git a/OMDb.Core/Extensions/ObjectExtension.cs b/OMDb.Core/Utils/Extensions/ObjectExtension.cs similarity index 72% rename from OMDb.Core/Extensions/ObjectExtension.cs rename to OMDb.Core/Utils/Extensions/ObjectExtension.cs index 93dbbe6..0052ec7 100644 --- a/OMDb.Core/Extensions/ObjectExtension.cs +++ b/OMDb.Core/Utils/Extensions/ObjectExtension.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,7 +9,7 @@ using System.Text; using System.Threading.Tasks; -namespace OMDb.Core.Extensions +namespace OMDb.Core.Utils.Extensions { public static class ObjectExtension { @@ -24,7 +25,7 @@ public static T DepthClone(this object obj) { if (ReferenceEquals(obj, null)) { - return default(T); + return default; } try { @@ -33,7 +34,7 @@ public static T DepthClone(this object obj) } catch (JsonException) { - return default(T); + return default; } } @@ -43,12 +44,12 @@ public static T DepthClone(this object obj) /// /// /// - public static void CopyFrom(this object obj,T target) + public static void CopyFrom(this object obj, T target) { var type = typeof(T); foreach (var sourceProperty in type.GetProperties()) { - if(sourceProperty.CanWrite) + if (sourceProperty.CanWrite) { var targetProperty = type.GetProperty(sourceProperty.Name); targetProperty.SetValue(obj, sourceProperty.GetValue(target, null), null); @@ -60,5 +61,22 @@ public static void CopyFrom(this object obj,T target) targetField.SetValue(obj, sourceField.GetValue(target)); } } + + + public static bool IsNullOrEmptyOrWhiteSpazeOrCountZero(this object value) + { + if (value == null || value == DBNull.Value || value.ToString().Length == 0 || string.IsNullOrWhiteSpace(value.ToString())) + { + return true; + } + + if (value is ICollection) + { + ICollection collection = value as ICollection; + return collection.Count == 0; + } + + return false; + } } } diff --git a/OMDb.Core/Utils/Logger.cs b/OMDb.Core/Utils/Logger.cs new file mode 100644 index 0000000..4b7f37c --- /dev/null +++ b/OMDb.Core/Utils/Logger.cs @@ -0,0 +1,46 @@ +using Google.Protobuf.WellKnownTypes; +using Org.BouncyCastle.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using NLog; + +namespace OMDb.Core.Utils +{ + public class Logger + { + public NLog.Logger _logger = LogManager.GetLogger("OMDB"); + + private static readonly Logger instance = new Logger(); + + static Logger() { } + private Logger() { } + private static Logger Instance + { + get + { + return instance; + } + } + + + public static void Info(string msg) + { + Instance._logger.Info(msg); + } + + public static void Error(Exception ex) + { + Instance._logger.Error(ex); + } + + public static void Error(string msg) + { + Instance._logger.Error(msg); + } + } +} + diff --git a/OMDb.Core/Utils/ObjectUtil.cs b/OMDb.Core/Utils/ObjectUtil.cs index c62ef8f..a8f86b8 100644 --- a/OMDb.Core/Utils/ObjectUtil.cs +++ b/OMDb.Core/Utils/ObjectUtil.cs @@ -8,9 +8,6 @@ namespace OMDb.Core.Utils { public static class ObjectUtil { - public static bool IsNullOrEmptyOrWhiteSpace(this Object obj) - { - return obj==null?true:obj.ToString().Trim().Length==0?true:false; - } + } } diff --git a/OMDb.Core/Utils/PathUtils/PathUtils.cs b/OMDb.Core/Utils/PathUtils/PathUtils.cs new file mode 100644 index 0000000..9246b20 --- /dev/null +++ b/OMDb.Core/Utils/PathUtils/PathUtils.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OMDb.Core.Utils.PathUtils +{ + public static class PathUtils + { + private static readonly string[] IllegalPathChar = new string[10] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|", ";" }; + private static readonly string IllegalPathCharStr = "\\ / : * ? \" < > | ;"; + } +} diff --git a/OMDb.Core/Utils/PathUtils/TempPathUtils.cs b/OMDb.Core/Utils/PathUtils/TempPathUtils.cs new file mode 100644 index 0000000..bbeacb1 --- /dev/null +++ b/OMDb.Core/Utils/PathUtils/TempPathUtils.cs @@ -0,0 +1,102 @@ +using NPOI.HPSF; +using OMDb.Core.Utils.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OMDb.Core.Utils.PathUtils +{ + public static class TempPathUtils + { + private const string _defaultImageName = @"temp_img.jpg"; + private const string _defaultFileName = @"temp_file"; + + private static List lstFullTempFilePath = new List(); + + public static void CreateTempImage(string fileName , Stream stream ) + { + CreateTempFile(Path.Combine(Path.GetTempPath(), fileName.IsNullOrEmptyOrWhiteSpazeOrCountZero() ? fileName : _defaultImageName), stream); + } + public static void CreateTempImage(Stream stream) + { + CreateTempFile(Path.Combine(Path.GetTempPath(), _defaultImageName), stream); + } + public static void CreateTempImage(string fileName) + { + CreateTempFile(Path.Combine(Path.GetTempPath(), fileName.IsNullOrEmptyOrWhiteSpazeOrCountZero() ? fileName : _defaultImageName), null); + } + public static void CreateTempImage() + { + CreateTempFile(Path.Combine(Path.GetTempPath(), _defaultImageName), null); + } + + public static void CreateTempFile(string? fileName = null, Stream? stream = null) + { + var newTempFile = Path.Combine(Path.GetTempPath(), fileName ?? _defaultFileName); + //删除原临时文件 + if (lstFullTempFilePath.Contains(newTempFile)) + DeleteTempFile(newTempFile); + using (var fs = File.Create(newTempFile)) + stream?.CopyTo(fs); + } + + + public static List GetTempFileAll() + { + return lstFullTempFilePath; + } + + public static string GetTempFile(string fileName) + { + var fullTempFilePath = Path.Combine(Path.GetTempPath(), fileName ?? _defaultFileName); + if (lstFullTempFilePath.Contains(fullTempFilePath)) + return fullTempFilePath; + else + return string.Empty; + } + + public static string GetDefaultTempImage() + { + var path_DefaultTempImage = Path.Combine(Path.GetTempPath(), _defaultImageName); + if (lstFullTempFilePath.Contains(path_DefaultTempImage)) + return path_DefaultTempImage; + else + return string.Empty; + } + + + public static void DeleteTempFileAll() + { + if (lstFullTempFilePath.IsNullOrEmptyOrWhiteSpazeOrCountZero()) + return; + foreach (var file in lstFullTempFilePath) + { + if (File.Exists(file)) + { + File.Delete(file); + lstFullTempFilePath.Remove(file); + } + } + } + + + public static void DeleteTempFile(string file) + { + if (File.Exists(file)) + File.Delete(file); + } + public static void DeleteTempFile(List files) + { + foreach (var file in files) + { + if (File.Exists(file)) + { + File.Delete(file); + lstFullTempFilePath.Remove(file); + } + } + } + } +} diff --git a/OMDb.Douban/EntryInfo.cs b/OMDb.Douban/EntryInfo.cs index 2e7d878..8c22d31 100644 --- a/OMDb.Douban/EntryInfo.cs +++ b/OMDb.Douban/EntryInfo.cs @@ -1,5 +1,4 @@ using HtmlAgilityPack; -using OMDb.Core.Helpers; using OMDb.Core.Interfaces; using OMDb.Core.Models; using SixLabors.ImageSharp.Processing; @@ -12,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using OMDb.Core.Services; +using OMDb.Core.Utils; namespace OMDb.Douban { @@ -38,7 +38,7 @@ Dictionary IEntryInfo.EntryInfo(string keyword) } catch (Exception ex) { - LogHelper.Instance._logger.Error("获取信息失败" + ex); + Logger.Error("获取信息失败" + ex); } return dic; @@ -61,7 +61,7 @@ private void GetCover(HtmlDocument htmlDoc, ref Dictionary dic) } catch (Exception ex) { - LogHelper.Instance._logger.Error("封面获取失败" + ex); + Logger.Error("封面获取失败" + ex); } } @@ -79,7 +79,7 @@ private void GetRate(HtmlDocument htmlDoc, ref Dictionary dic) } catch (Exception ex) { - LogHelper.Instance._logger.Error("评分获取失败" + ex); + Logger.Error("评分获取失败" + ex); } } @@ -99,7 +99,7 @@ private void GetActor(HtmlDocument htmlDoc, ref Dictionary dic) } catch (Exception ex) { - LogHelper.Instance._logger.Error("主演获取失败" + ex); + Logger.Error("主演获取失败" + ex); } } @@ -115,7 +115,7 @@ private void GetDirector(HtmlDocument htmlDoc, ref Dictionary di } catch (Exception ex) { - LogHelper.Instance._logger.Error("导演获取失败" + ex); + Logger.Error("导演获取失败" + ex); } } @@ -143,7 +143,7 @@ private void GetDate(HtmlDocument htmlDoc, ref Dictionary dic) } catch (Exception ex) { - LogHelper.Instance._logger.Error("上映日期获取失败" + ex); + Logger.Info("上映日期获取失败" + ex); } } @@ -165,7 +165,7 @@ private void GetClass(HtmlDocument htmlDoc, ref Dictionary dic) } catch (Exception ex) { - LogHelper.Instance._logger.Error("分类获取失败" + ex); + Logger.Error("分类获取失败" + ex); } } diff --git a/OMDb.Douban/Rate.cs b/OMDb.Douban/Rate.cs index b83894c..62436c9 100644 --- a/OMDb.Douban/Rate.cs +++ b/OMDb.Douban/Rate.cs @@ -1,7 +1,7 @@ using HtmlAgilityPack; -using OMDb.Core.Helpers; using OMDb.Core.Interfaces; using OMDb.Core.Models; +using OMDb.Core.Utils; using System; using System.Collections.Generic; using System.Composition; @@ -37,7 +37,7 @@ private double GetRate(HtmlDocument htmlDoc) } catch (Exception ex) { - LogHelper.Instance._logger.Error("评分获取失败" + ex); + Logger.Error("评分获取失败" + ex); return 0; } } diff --git a/OMDb.JavDb/EntryInfo.cs b/OMDb.JavDb/EntryInfo.cs index bf3699b..aee7795 100644 --- a/OMDb.JavDb/EntryInfo.cs +++ b/OMDb.JavDb/EntryInfo.cs @@ -1,5 +1,4 @@ using HtmlAgilityPack; -using OMDb.Core.Helpers; using OMDb.Core.Interfaces; using OMDb.Core.Models; using SixLabors.ImageSharp.Processing; @@ -11,6 +10,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; +using OMDb.Core.Utils; namespace OMDb.JavDb { @@ -46,7 +46,7 @@ Dictionary IEntryInfo.EntryInfo(string keyword) } catch (Exception ex) { - LogHelper.Instance._logger.Error("JavDb获取信息失败!"+ex); + Logger.Error("JavDb获取信息失败!"+ex); } return dic; @@ -68,7 +68,7 @@ private void GetCover(HtmlDocument htmlDoc, ref Dictionary dic) } catch (Exception ex) { - LogHelper.Instance._logger.Error("封面获取失败!"+ex); + Logger.Error("封面获取失败!"+ex); } } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Converters/Private/LPIdToReadOnlyConverter.cs b/OMDb.WinUI3/OMDb.WinUI3/Converters/Private/LPIdToReadOnlyConverter.cs index cf9ca61..9410846 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Converters/Private/LPIdToReadOnlyConverter.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Converters/Private/LPIdToReadOnlyConverter.cs @@ -1,6 +1,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Data; using OMDb.Core.Utils; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Services; using System; @@ -12,7 +13,7 @@ public sealed class LPIdToReadOnlyConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, string language) { - if (value.IsNullOrEmptyOrWhiteSpace()) + if (value.IsNullOrEmptyOrWhiteSpazeOrCountZero()) { return false; } @@ -24,7 +25,7 @@ public object Convert(object value, Type targetType, object parameter, string la public object ConvertBack(object value, Type targetType, object parameter, string language) { - if (value.IsNullOrEmptyOrWhiteSpace()) + if (value.IsNullOrEmptyOrWhiteSpazeOrCountZero()) { return false; } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddEntryBatchDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddEntryBatchDialog.xaml.cs index 4ac30ba..8009c81 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddEntryBatchDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddEntryBatchDialog.xaml.cs @@ -10,7 +10,6 @@ using Microsoft.UI.Xaml.Shapes; using NLog; using NPOI.SS.Formula.Functions; -using OMDb.Core.Extensions; using OMDb.Core.Services.PluginsService; using OMDb.Core.Utils; using OMDb.WinUI3.Helpers; @@ -33,6 +32,8 @@ using Windows.Foundation.Collections; using static System.Net.WebRequestMethods; using OMDb.Core.Services; +using OMDb.Core.Utils.Extensions; +using OMDb.Core.Utils.PathUtils; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -69,7 +70,7 @@ public AddEntryBatchDialog() } - public static async Task ShowDialog() + public static async Task> ShowDialog() { MyContentDialog dialog = new MyContentDialog(); dialog.TitleTextBlock.Text = "词条批量新增"; @@ -101,13 +102,13 @@ private void SelectFolders_Click(object sender, RoutedEventArgs e) private void ReturnFolder_Click(object sender, RoutedEventArgs e) { var result = this.ei.BasicGridView.SelectedItems.ToList(); - if (!result.IsNullOrEmptyOrWhiteSpace()) + if (!result.IsNullOrEmptyOrWhiteSpazeOrCountZero()) { foreach (var item in result) { ExplorerItem exp = item as ExplorerItem; EntryDetail ed = new EntryDetail(); - ed.FullCoverImgPath = Services.CommonService.GetCoverByPath(exp.Name); + ed.FullCoverImgPath = Services.CommonService.GetCover(exp.Name); ed.Name = System.IO.Path.GetFileName(exp.Name); ed.FullEntryPath = PathService.GetFullEntryPathByEntryName(exp.Name, VM.SelectedEnrtyStorage.StoragePath); ed.Entry = new Core.Models.Entry(); @@ -145,16 +146,13 @@ private async void GetInfoBatch_Click(object sender, RoutedEventArgs e) try { var coverStream = (MemoryStream)(entryInfo["封面"]); - TempFileHelper.CreateTempImg(item.Name + ".jpg"); - FileStream fs = new FileStream(TempFileHelper.fullTempImgPath, FileMode.Create); - coverStream.WriteTo(fs); - fs.Close(); - item.FullCoverImgPath = TempFileHelper.fullTempImgPath; - //Image_CoverImg.Source = ImgHelper.CreateBitmapImage(coverStream); + var newFileName = item.Name + ".jpg"; + TempPathUtils.CreateTempImage(newFileName, coverStream); + item.FullCoverImgPath = TempPathUtils.GetTempFile(newFileName); } catch (Exception ex) { - Core.Helpers.LogHelper.Instance._logger.Error("封面" + ex.Message); + Core.Utils.Logger.Error("封面" + ex.Message); } try @@ -164,7 +162,7 @@ private async void GetInfoBatch_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - Core.Helpers.LogHelper.Instance._logger.Error("评分" + ex.Message); + Core.Utils.Logger.Error("评分" + ex.Message); } try @@ -174,13 +172,13 @@ private async void GetInfoBatch_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - Core.Helpers.LogHelper.Instance._logger.Error("上映日期" + ex.Message); + Core.Utils.Logger.Error("上映日期" + ex.Message); } sw.Stop(); - Core.Helpers.LogHelper.Instance._logger.Info($"获取“{item.Name}”信息耗时:{sw.Elapsed}"); + Core.Utils.Logger.Info($"获取“{item.Name}”信息耗时:{sw.Elapsed}"); } swTotal.Stop(); - Core.Helpers.LogHelper.Instance._logger.Info($"获取信息总耗时:{swTotal.Elapsed}"); + Core.Utils.Logger.Info($"获取信息总耗时:{swTotal.Elapsed}"); //this.pr.IsActive = false; //this.btn_GetInfo.IsEnabled = true; } @@ -204,7 +202,7 @@ private void Button_CoverImg_Click(object sender, RoutedEventArgs e) private void LoadLabelControl() { var lst_label_lp = Core.Services.LabelPropertyService.GetAllLabel(DbSelectorService.dbCurrentId); - var lst_label_lc = Core.Services.LabelService.GetAllLabel(DbSelectorService.dbCurrentId); + var lst_label_lc = Core.Services.LabelClassService.GetAllLabel(DbSelectorService.dbCurrentId); var lpids = new List();//属性标签 var lcids = new List();//分类标签 diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyDataLKDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyDataLKDialog.xaml.cs index 058c98c..04dbb14 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyDataLKDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyDataLKDialog.xaml.cs @@ -7,8 +7,8 @@ using Microsoft.UI.Xaml.Navigation; using NPOI.POIFS.Properties; using OMDb.Core.DbModels; -using OMDb.Core.Extensions; using OMDb.Core.Utils; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Helpers; using OMDb.WinUI3.Models; using OMDb.WinUI3.Services; @@ -57,7 +57,7 @@ public static async Task> ShowDialog(string pId) foreach (var item in content.VM.DtData) { //手动输入的属性数据 - if (item.LPId.IsNullOrEmptyOrWhiteSpace()) + if (item.LPId.IsNullOrEmptyOrWhiteSpazeOrCountZero()) { var childs = content.VM.LabelPropertyTrees.Where(a => a.LPDb.LPId.Equals(item.ParentId)).FirstOrDefault().Children; var lp_repeat = childs.Where(a => a.LPDb.Name.Equals(item.Name)); @@ -111,7 +111,7 @@ private void AddLink_Click(object sender, RoutedEventArgs e) { var lp = new LabelPropertyDb(); var itemsRoot = (LabelPropertyTree)this.ListView_LabelPropertyTrees.SelectedItem; - if (itemsRoot.IsNullOrEmptyOrWhiteSpace()) return; + if (itemsRoot.IsNullOrEmptyOrWhiteSpazeOrCountZero()) return; lp.ParentId = itemsRoot.LPDb.LPId; VM.DtData.Add(lp); } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyLKDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyLKDialog.xaml.cs index 08e7435..31cfe3e 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyLKDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/AddLabelPropertyLKDialog.xaml.cs @@ -6,7 +6,6 @@ using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using OMDb.Core.DbModels; -using OMDb.Core.Extensions; using OMDb.Core.Utils; using OMDb.WinUI3.Helpers; using OMDb.WinUI3.Models; diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditDbSource.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditDbSource.xaml.cs index 7b68097..69824f6 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditDbSource.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditDbSource.xaml.cs @@ -5,7 +5,6 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; -using OMDb.Core.Extensions; using System; using System.Collections.Generic; using System.IO; diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditEntryDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditEntryDialog.xaml.cs index e8ed9f9..a11a474 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditEntryDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditEntryDialog.xaml.cs @@ -13,10 +13,11 @@ using NPOI.SS.Formula.Functions; using OMDb.Core.DbModels; using OMDb.Core.Enums; -using OMDb.Core.Extensions; using OMDb.Core.Services; using OMDb.Core.Services.PluginsService; using OMDb.Core.Utils; +using OMDb.Core.Utils.Extensions; +using OMDb.Core.Utils.PathUtils; using OMDb.WinUI3.Helpers; using OMDb.WinUI3.Models; using OMDb.WinUI3.MyControls; @@ -64,11 +65,11 @@ public EditEntryDialog(Core.Models.Entry entry) #region 动态加载属性标签 var lst_label_lp = Core.Services.LabelPropertyService.GetAllLabel(DbSelectorService.dbCurrentId); - var lst_label_lc = Core.Services.LabelService.GetAllLabel(DbSelectorService.dbCurrentId); + var lst_label_lc = Core.Services.LabelClassService.GetAllLabel(DbSelectorService.dbCurrentId); var lpids = new List();//属性标签 var lcids = new List();//分类标签 if (entry != null) lpids = Core.Services.LabelPropertyService.GetLabelIdsOfEntry(entry.EntryId); - if (entry != null) lcids = Core.Services.LabelService.GetLabelIdsOfEntry(entry.EntryId); + if (entry != null) lcids = Core.Services.LabelClassService.GetLabelIdsOfEntry(entry.EntryId); if (lst_label_lp.Count > 0) { @@ -182,7 +183,7 @@ public EditEntryDialog(Core.Models.Entry entry) - + } @@ -250,20 +251,18 @@ public EditEntryDialog(Core.Models.Entry entry) { //封面空 -> 尋找指定文件夾中圖片 -> 尋找指定文件夾中視頻縮略圖 -> 設置默認封面 case SaveType.Folder: - lstPath.Add(content.PointFolder.Text); - entryDetail.FullCoverImgPath = Services.CommonService.GetCoverByPath(lstPath, PathType.Folder); + entryDetail.FullCoverImgPath = Services.CommonService.GetCover(content.PointFolder.Text); break; //封面空 -> 尋找指定地址中圖片 -> 尋找指定地址中視頻縮略圖 -> 設置默認封面 case SaveType.Files: - //lstPath.AddRange() - entryDetail.FullCoverImgPath = Services.CommonService.GetCoverByPath(lstPath, PathType.Folder); + entryDetail.FullCoverImgPath = Services.CommonService.GetCover(); break; //設置默認封面 case SaveType.Local: - entryDetail.FullCoverImgPath = Services.CommonService.GetCoverByPath(); + entryDetail.FullCoverImgPath = Services.CommonService.GetCover(); break; default: - entryDetail.FullCoverImgPath = Services.CommonService.GetCoverByPath(); + entryDetail.FullCoverImgPath = Services.CommonService.GetCover(); break; } } @@ -274,8 +273,8 @@ public EditEntryDialog(Core.Models.Entry entry) #endregion #region 词条关联属性标签数据 (1.关联原有的属性标签数据 2.新增属性标签数据并关联) - var lpdb_original = content.VM.Label_Property.Where(a => a.IsChecked == true).Where(a => !a.LPDb.LPId.IsNullOrEmptyOrWhiteSpace()).Select(a => a.LPDb).ToList(); - var lpdb_new = content.VM.Label_Property.Where(a => a.IsChecked == true).Where(a => a.LPDb.LPId.IsNullOrEmptyOrWhiteSpace()).Select(a => a.LPDb).ToList(); + var lpdb_original = content.VM.Label_Property.Where(a => a.IsChecked == true).Where(a => !a.LPDb.LPId.IsNullOrEmptyOrWhiteSpazeOrCountZero()).Select(a => a.LPDb).ToList(); + var lpdb_new = content.VM.Label_Property.Where(a => a.IsChecked == true).Where(a => a.LPDb.LPId.IsNullOrEmptyOrWhiteSpazeOrCountZero()).Select(a => a.LPDb).ToList(); foreach (var item in lpdb_new) Core.Services.LabelPropertyService.AddLabel(item); if (lpdb_original.Count > 0) @@ -333,82 +332,52 @@ private async void Button_CoverImg_Click(object sender, RoutedEventArgs e) private async void GetInfo_Click(object sender, RoutedEventArgs e) { if (Convert.ToString(this.ddb.Content).Equals("无服务")) return; - /*var rate=RatingService.GetRatings(this.VM.EntryName,Convert.ToString(this.ddb.Content)); - this.VM.MyRating = rate.Rate / rate.Max * 5.0;*/ this.pr.IsActive = true; var entryInfo = new Dictionary(); this.btn_GetInfo.IsEnabled = false; - //Dialogs.WatingDialog.Show("移动文件中"); entryInfo = await EntryInfoService.GetEntryInfo(this.VM.EntryName, Convert.ToString(this.ddb.Content)); - //Dialogs.WatingDialog.Hide(); this.pr.IsActive = false; this.btn_GetInfo.IsEnabled = true; - try - { - var coverStream = (MemoryStream)(entryInfo["封面"]); - TempFileHelper.CreateTempImg(); - FileStream fs = new FileStream(TempFileHelper.fullTempImgPath, FileMode.Create); - coverStream.WriteTo(fs); - fs.Close(); - VM.Entry.CoverImg = TempFileHelper.fullTempImgPath; - Image_CoverImg.Source = ImgHelper.CreateBitmapImage(coverStream); - } - catch (Exception ex) - { - throw ex; - } - try - { - this.VM.MyRating = Convert.ToDouble(entryInfo["评分"]); - } - catch (Exception ex) - { - throw ex; - } + #region 基本信息 + entryInfo.TryGetValue("封面", out object stream_cover); + TempPathUtils.CreateTempImage((MemoryStream)stream_cover); + VM.Entry.CoverImg = TempPathUtils.GetDefaultTempImage(); + Image_CoverImg.Source = ImgHelper.CreateBitmapImage((MemoryStream)stream_cover); - try - { - this.VM.ReleaseDate = Convert.ToDateTime(entryInfo["上映日期"]); - } - catch (Exception ex) - { - throw ex; - } + entryInfo.TryGetValue("评分", out object rate); + this.VM.MyRating = Convert.ToDouble(rate); + + entryInfo.TryGetValue("上映日期", out object date); + this.VM.ReleaseDate = Convert.ToDateTime(date); + #endregion - try + #region 属性标签数据 + var lstBaba = this.VM.Label_Property.Where(a => a.LPDb.Level == 1).ToList(); + foreach (var ei in entryInfo) { - var lstBaba = this.VM.Label_Property.Where(a => a.LPDb.Level == 1).ToList(); - foreach (var ei in entryInfo) + if (lstBaba.Select(a => a.LPDb.Name).ToList().Contains(ei.Key)) { - if (lstBaba.Select(a => a.LPDb.Name).ToList().Contains(ei.Key)) + string[] eiv = (string[])ei.Value; + var lbc = (LabelsProPertyControl)this.stp.FindChild(ei.Key); + lbc.StrSelectItem.Text = string.Join("/", eiv); + foreach (var item in eiv) { - string[] eiv = (string[])ei.Value; - var lbc = (LabelsProPertyControl)this.stp.FindChild(ei.Key); - lbc.StrSelectItem.Text = string.Join("/", eiv); - foreach (var item in eiv) + var lpdb = new LabelPropertyDb() { - var lpdb = new LabelPropertyDb() - { - Name = item, - ParentId = lstBaba.Where(a => a.LPDb.Name == ei.Key).FirstOrDefault().LPDb.LPId, - DbCenterId = lstBaba.Where(a => a.LPDb.Name == ei.Key).FirstOrDefault().LPDb.DbCenterId - }; - var lp = new LabelProperty(lpdb); - lp.IsChecked = true; - lbc.LabelPropertyCollection.Add(lp); - this.VM.Label_Property.Add(lp); - //Core.Services.LabelPropertyService.AddLabel(lpdb); - } + Name = item, + ParentId = lstBaba.Where(a => a.LPDb.Name == ei.Key).FirstOrDefault().LPDb.LPId, + DbCenterId = lstBaba.Where(a => a.LPDb.Name == ei.Key).FirstOrDefault().LPDb.DbCenterId + }; + var lp = new LabelProperty(lpdb); + lp.IsChecked = true; + lbc.LabelPropertyCollection.Add(lp); + this.VM.Label_Property.Add(lp); + //Core.Services.LabelPropertyService.AddLabel(lpdb); } - } - - } - catch (Exception ex) - { - throw ex; } + #endregion } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditStorageDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditStorageDialog.xaml.cs index d78b118..5dbd039 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditStorageDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/EditStorageDialog.xaml.cs @@ -6,7 +6,7 @@ using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; using Microsoft.UI.Xaml.Navigation; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.IO; diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/MyContentDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/MyContentDialog.xaml.cs index 4cca74e..8e2234f 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/MyContentDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/MyContentDialog.xaml.cs @@ -5,6 +5,7 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; +using OMDb.Core.Utils; using System; using System.Collections.Generic; using System.IO; @@ -50,7 +51,7 @@ private void Button_Cancel_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - Core.Helpers.LogHelper.Instance._logger.Error(ex); + Logger.Error(ex); throw ex; } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/PickEntryCollectionDialog.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/PickEntryCollectionDialog.xaml.cs index e2067eb..cc7db84 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Dialogs/PickEntryCollectionDialog.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Dialogs/PickEntryCollectionDialog.xaml.cs @@ -5,7 +5,6 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; -using OMDb.Core.Extensions; using System; using System.Collections.Generic; using System.ComponentModel; diff --git a/OMDb.WinUI3/OMDb.WinUI3/Extensions/EntryExtension.cs b/OMDb.WinUI3/OMDb.WinUI3/Extensions/EntryExtension.cs index b53f50f..09687da 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Extensions/EntryExtension.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Extensions/EntryExtension.cs @@ -1,5 +1,4 @@ using OMDb.Core.DbModels; -using OMDb.Core.Extensions; using OMDb.Core.Models; using System; using System.Collections.Generic; @@ -66,7 +65,7 @@ public static List GetBestImg(this Core.Models.Entry entry,bool horizont { foreach (var file in Core.Helpers.RandomHelper.RandomList(items, 100))//仅对100张照片计算 { - if (Helpers.ImgHelper.IsSupportImg(file.FullName)) + if (Core.Helpers.ImageHelper.IsSupportImg(file.FullName)) { infos.Add(Core.Helpers.ImageHelper.GetImageInfo(file.FullName)); } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Helpers/FFmpegHelper.cs b/OMDb.WinUI3/OMDb.WinUI3/Helpers/FFmpegHelper.cs deleted file mode 100644 index 0d0ba48..0000000 --- a/OMDb.WinUI3/OMDb.WinUI3/Helpers/FFmpegHelper.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Xabe.FFmpeg; - -namespace OMDb.WinUI3.Helpers -{ - internal static class FFmpegHelper - { - } -} diff --git a/OMDb.WinUI3/OMDb.WinUI3/Helpers/FileHelper.cs b/OMDb.WinUI3/OMDb.WinUI3/Helpers/FileHelper.cs index 397b0b9..3c2c2ef 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Helpers/FileHelper.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Helpers/FileHelper.cs @@ -1,4 +1,5 @@ -using OMDb.WinUI3.Models; +using OMDb.Core.Utils; +using OMDb.WinUI3.Models; using System; using System.Collections.Generic; using System.IO; @@ -222,7 +223,7 @@ public static int CopyFolder(string sourceFolder, string destFolder, ProgressCal catch (Exception e) { Helpers.InfoHelper.ShowError(e.Message); - Core.Helpers.LogHelper.Instance._logger.Error(e); + Logger.Error(e); return 0; } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Helpers/ImgHelper.cs b/OMDb.WinUI3/OMDb.WinUI3/Helpers/ImgHelper.cs index 0bf292a..08c9308 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Helpers/ImgHelper.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Helpers/ImgHelper.cs @@ -1,6 +1,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; +using OMDb.Core.Const; using System; using System.Collections.Generic; using System.IO; @@ -13,36 +14,13 @@ namespace OMDb.WinUI3.Helpers { public static class ImgHelper { - private static List SupportImgs = new List() - { - "jpeg", - "jpg", - "png", - "bmp", - "gif", - "tiff", - "ico", - "svg" - }; - public static bool IsSupportImg(string file) - { - if(!string.IsNullOrEmpty(file)) - { - var ext = System.IO.Path.GetExtension(file).Replace(".",""); - return SupportImgs.Contains(ext.ToLower()); - } - else - { - return false; - } - } public static async Task CreateBitmapImageAsync(MemoryStream stream) { try { var bitmapImage = new BitmapImage(); - stream.Seek(0,SeekOrigin.Begin); + stream.Seek(0, SeekOrigin.Begin); await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream()); return bitmapImage; } @@ -68,27 +46,6 @@ public static BitmapImage CreateBitmapImage(MemoryStream stream) } - /// - /// 用远程地址获取文件字节流 - /// - /// URL - /// - public static byte[] GetUrlMemoryStream(string path) - { - - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path); - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - Stream responseStream = response.GetResponseStream(); - List btlst = new List(); - int b = responseStream.ReadByte(); - while (b > -1) - { - btlst.Add((byte)b); - b = responseStream.ReadByte(); - } - byte[] bts = btlst.ToArray(); - return bts; - } } } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Helpers/TempFileHelper.cs b/OMDb.WinUI3/OMDb.WinUI3/Helpers/TempFileHelper.cs deleted file mode 100644 index a55ab8f..0000000 --- a/OMDb.WinUI3/OMDb.WinUI3/Helpers/TempFileHelper.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OMDb.WinUI3.Helpers -{ - public static class TempFileHelper - { - private const string _imgName = @"temp.jpg"; - - public static string fullTempImgPath; - - public static void CreateTempImg(string name=null) - { - using(File.Create(Path.Combine(Path.GetTempPath(), name!=null?name:_imgName))); - fullTempImgPath = Path.Combine(Path.GetTempPath(), name != null ? name : _imgName); - } - - - private static void DeleteTempImg() - { - if (fullTempImgPath==null||!File.Exists(fullTempImgPath)) return; - File.Delete(fullTempImgPath); - fullTempImgPath = null; - } - } -} - diff --git a/OMDb.WinUI3/OMDb.WinUI3/Models/EntryCollection.cs b/OMDb.WinUI3/OMDb.WinUI3/Models/EntryCollection.cs index dd68c00..e55428a 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Models/EntryCollection.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Models/EntryCollection.cs @@ -1,8 +1,8 @@ using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.UI.Xaml.Media; -using OMDb.Core.Extensions; using OMDb.Core.Models; using OMDb.Core.Services; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -98,7 +98,7 @@ public static async Task CreateBaseAsync(Core.Models.EntryColle { foreach(var g in result.Items.GroupBy(p => p.DbId).ToList()) { - var histories = await WatchHistoryService.QueryWatchHistoriesAsync(g.Select(p => p.Id).ToList(), g.Key); + var histories = await EntryWatchHistoryService.QueryWatchHistoriesAsync(g.Select(p => p.Id).ToList(), g.Key); if(histories != null && histories.Count != 0) { result.WatchedCount += histories.GroupBy(p => p.EntryId).Count(); diff --git a/OMDb.WinUI3/OMDb.WinUI3/Models/EntryDetail.cs b/OMDb.WinUI3/OMDb.WinUI3/Models/EntryDetail.cs index 79443db..33a9dc8 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Models/EntryDetail.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Models/EntryDetail.cs @@ -2,9 +2,10 @@ using CommunityToolkit.Mvvm.Input; using ICSharpCode.SharpZipLib.Core; using OMDb.Core.Enums; -using OMDb.Core.Extensions; +using OMDb.Core.Helpers; using OMDb.Core.Models; using OMDb.Core.Services; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Extensions; using OMDb.WinUI3.Services; using SqlSugar; @@ -203,12 +204,12 @@ public List Labels SetProperty(ref labels, value); Task.Run(() => { - Core.Services.LabelService.ClearEntryLabel(Entry.EntryId);//清空词条标签 + Core.Services.LabelClassService.ClearEntryLabel(Entry.EntryId);//清空词条标签 if (value != null) { List entryLabelDbs = new List(labels.Count); labels.ForEach(p => entryLabelDbs.Add(new Core.DbModels.EntryLabelClassLinkDb() { EntryId = Entry.EntryId, LCId = p.LCId, DbId = Entry.DbId })); - Core.Services.LabelService.AddEntryLabel(entryLabelDbs);//添加词条标签 + Core.Services.LabelClassService.AddEntryLabel(entryLabelDbs);//添加词条标签 } }); } @@ -223,7 +224,7 @@ public List Lpdbs SetProperty(ref _lpdbs, value); Task.Run(() => { - Core.Services.LabelService.ClearEntryLabel(Entry.EntryId);//清空词条标签 + Core.Services.LabelClassService.ClearEntryLabel(Entry.EntryId);//清空词条标签 if (value != null) { List entryLabelDbs = new List(_lpdbs.Count); @@ -233,6 +234,7 @@ public List Lpdbs }); } } + private ObservableCollection imgs; public ObservableCollection Imgs { @@ -247,7 +249,7 @@ private async Task Init() Names = namesT.Select(p => new EntryName(p)).ToObservableCollection(); } await UpdateWatchHistoryAsync(); - labels = await Core.Services.LabelService.GetLabelOfEntryAsync(Entry.EntryId); + labels = await Core.Services.LabelClassService.GetLabelOfEntryAsync(Entry.EntryId); Labels ??= new List(); WatchHistory ??= new ObservableCollection(); @@ -271,7 +273,7 @@ private async Task Init() } public async Task UpdateWatchHistoryAsync() { - var histories = (await Core.Services.WatchHistoryService.QueryWatchHistoriesAsync(Entry.EntryId, Entry.DbId)).ToObservableCollection(); + var histories = (await Core.Services.EntryWatchHistoryService.QueryWatchHistoriesAsync(Entry.EntryId, Entry.DbId)).ToObservableCollection(); if (histories == null) { WatchHistory = new ObservableCollection(); @@ -294,7 +296,7 @@ public void LoadLocalImgs() { foreach (var file in items) { - if (Helpers.ImgHelper.IsSupportImg(file.FullName)) + if (ImageHelper.IsSupportImg(file.FullName)) { Imgs.Add(file.FullName); } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Models/Tools/AVCodecConversionItem.cs b/OMDb.WinUI3/OMDb.WinUI3/Models/Tools/AVCodecConversionItem.cs index c962112..2abac01 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Models/Tools/AVCodecConversionItem.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Models/Tools/AVCodecConversionItem.cs @@ -1,6 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; -using OMDb.Core.Extensions; using OMDb.Core.Models; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.Linq; diff --git a/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryDetailControl.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryDetailControl.xaml.cs index e794ee8..0351865 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryDetailControl.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryDetailControl.xaml.cs @@ -22,7 +22,6 @@ using OMDb.WinUI3.Models; using Microsoft.UI.Xaml.Shapes; using OMDb.Core.Utils; -using OMDb.Core.Extensions; using System.Collections.ObjectModel; // To learn more about WinUI, the WinUI project structure, diff --git a/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryStoragesControl.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryStoragesControl.xaml.cs index c2b9aa0..427d1d3 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryStoragesControl.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/MyControls/EntryStoragesControl.xaml.cs @@ -5,7 +5,6 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; -using OMDb.Core.Extensions; using System; using System.Collections.Generic; using System.ComponentModel; diff --git a/OMDb.WinUI3/OMDb.WinUI3/MyControls/ExplorerControl.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/MyControls/ExplorerControl.xaml.cs index 4c7ba9f..9e5650e 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/MyControls/ExplorerControl.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/MyControls/ExplorerControl.xaml.cs @@ -22,8 +22,8 @@ using OMDb.WinUI3.Models; using Microsoft.UI.Xaml.Shapes; using OMDb.Core.Utils; -using OMDb.Core.Extensions; using System.Collections.ObjectModel; +using OMDb.Core.Utils.Extensions; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. diff --git a/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsControl.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsControl.xaml.cs index eea39eb..5fd4963 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsControl.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsControl.xaml.cs @@ -5,7 +5,7 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using System; using System.Collections.Generic; using System.ComponentModel; @@ -171,7 +171,7 @@ private async void ShowAddLabelsFlyout(FrameworkElement element) { if(AllLabels == null) { - var labels = await Core.Services.LabelService.GetAllLabelAsync(Services.Settings.DbSelectorService.dbCurrentId); + var labels = await Core.Services.LabelClassService.GetAllLabelAsync(Services.Settings.DbSelectorService.dbCurrentId); if (labels != null) { AllLabels = labels.Select(p => new Models.Label(p)).ToList(); diff --git a/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsProPertyControl.xaml.cs b/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsProPertyControl.xaml.cs index 63d4708..724493b 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsProPertyControl.xaml.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/MyControls/LabelsProPertyControl.xaml.cs @@ -5,7 +5,6 @@ using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; -using OMDb.Core.Extensions; using OMDb.WinUI3.Events; using System; using System.Collections.Generic; diff --git a/OMDb.WinUI3/OMDb.WinUI3/Services/CommonService.cs b/OMDb.WinUI3/OMDb.WinUI3/Services/CommonService.cs index 450853f..75056c1 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Services/CommonService.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Services/CommonService.cs @@ -1,6 +1,5 @@ using OMDb.Core.Utils; using NPOI.OpenXmlFormats.Vml; -using OMDb.Core.Extensions; using OMDb.WinUI3.Models; using System; using System.Collections.Generic; @@ -11,6 +10,11 @@ using OMDb.Core.Utils.StringUtil; using OMDb.Core.Services; using OMDb.Core.Enums; +using OMDb.Core.Utils.Extensions; +using OMDb.Core.Const; +using OMDb.Core.Models; +using OMDb.WinUI3.Extensions; +using OMDb.Core.Helpers; namespace OMDb.WinUI3.Services { @@ -20,67 +24,43 @@ public static class CommonService /// 根据地址自动获取封面 /// /// - public static string GetCoverByPath(List lstPath = null, Core.Enums.PathType fileType = Core.Enums.PathType.TotalAll) + public static string GetCover(string path = null) { var result = string.Empty; - if (lstPath == null || !(lstPath.Count > 0)) - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - switch (fileType) - { - case Core.Enums.PathType.Folder: - List filesPath = new List(); - foreach (var path in lstPath) - { - //封面空 -> 尋找指定文件夾中圖片 -> 尋找指定文件夾中視頻縮略圖 -> 設置默認封面 - var files = Helpers.FileHelper.FindExplorerItems(path); - var sourceFiles = Helpers.FileHelper.GetAllFiles(files); - filesPath.AddRange(sourceFiles.Select(a => a.FullName)); - } - - result = filesPath.Where(a => GetPathType(a).Equals('2')).FirstOrDefault(); - if (string.IsNullOrWhiteSpace(result)) - { - result = filesPath.Where(a => GetPathType(a).Equals('3')).FirstOrDefault(); - if (string.IsNullOrWhiteSpace(result)) - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - else - { - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - } - } - return result; - case Core.Enums.PathType.Image: - return result; - case Core.Enums.PathType.Video: - return result; - case Core.Enums.PathType.Audio: - return result; - case Core.Enums.PathType.VideoSub: - return result; - case Core.Enums.PathType.More: - return result; - case Core.Enums.PathType.All: - result = lstPath.Where(a => GetPathType(a).Equals('2')).FirstOrDefault(); - if (string.IsNullOrWhiteSpace(result)) - { - result = lstPath.Where(a => GetPathType(a).Equals('3')).FirstOrDefault(); - if (string.IsNullOrWhiteSpace(result)) - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - else - { - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - } - } - return result; - case Core.Enums.PathType.TotalAll: - return result; - default: - return result; + result = ConfigService.DefaultCover; + if (Directory.Exists(path)) + { + var files = Helpers.FileHelper.FindExplorerItems(path); + var sourceFiles = Helpers.FileHelper.GetAllFiles(files); + var filesPath = sourceFiles.Select(a => a.FullName); + var imgs = filesPath.Where(x => GetPathType(x) == PathType.Image); + if (!imgs.IsNullOrEmptyOrWhiteSpazeOrCountZero()) + result = ImageHelper.GetBestImg(imgs, Const.Scale_Cover).FirstOrDefault(); } + return result; + } + /// + /// 根据地址自动获取封面 + /// + /// + public static string GetCover(List paths) + { + var result = string.Empty; + + result = ConfigService.DefaultCover; + + if (paths.IsNullOrEmptyOrWhiteSpazeOrCountZero()) + result = ImageHelper.GetBestImg(paths, Const.Scale_Cover).FirstOrDefault(); + + return result; } + + + + /// /// 根据文件名获取文件类型(数据库版本) 图片->2 / 视频->3 / 音频->4 / 字幕->5 / 其他->6 /// @@ -91,44 +71,22 @@ public static PathType GetPathType(string path) var isExist = File.Exists(path); if (!isExist) return PathType.More; - var typeAllImg = @"BMP,JPG,PNG,TIF,GIF,PCX,TGA,EXIF,FPX,SVG,PSD,CDR,PCD,DXF,UFO,EPS,AI,RAW,WMF,WEBP,AVIF,APNG"; - var typeAllVideo = @"AVI、WMV、MPEG、MP4、M4V、MOV、ASF、FLV、F4V、RMVB、RM、3GP、VOB"; - var typeAllVideoSub = @"SRT、WEBVTT、STL、SBV、ASS、DFXP、TTML"; - var typeAllAudio = @"MP3、WAV、WMA、MP2、Flac、MIDI、RA、APE、AAC、CDA、MOV"; - var file_extension = Path.GetExtension(path).Delete1stChar().ToUpper(); - if (typeAllImg.Contains(file_extension)) + + var file_extension = Path.GetExtension(path).Remove(".").ToUpper(); + + if (MediaTypes.Image.Contains(file_extension)) return PathType.Image; - else if (typeAllVideo.Contains(file_extension)) + + if (MediaTypes.Video.Contains(file_extension)) return PathType.Video; - else if (typeAllVideoSub.Contains(file_extension)) + + if (MediaTypes.VideoSub.Contains(file_extension)) return PathType.VideoSub; - else if (typeAllAudio.Contains(file_extension)) - return PathType.Audio; - else - return PathType.More; - } + if (MediaTypes.Audio.Contains(file_extension)) + return PathType.Audio; - /// - /// 根据地址自动获取封面 - /// - /// - public static string GetCoverByPath(string path) - { - var result = string.Empty; - if (!path.NotNullAndEmpty()) - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - List filesPath = new List(); - - //封面空 -> 尋找指定文件夾中圖片 -> 設置默認封面 - var files = Helpers.FileHelper.FindExplorerItems(path); - var sourceFiles = Helpers.FileHelper.GetAllFiles(files); - filesPath.AddRange(sourceFiles.Select(a => a.FullName)); - - result = filesPath.Where(a => GetPathType(a).Equals("Image")).FirstOrDefault(); - if (string.IsNullOrWhiteSpace(result)) - result = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); - return result; + return PathType.More; } } } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Services/ConfigService.cs b/OMDb.WinUI3/OMDb.WinUI3/Services/ConfigService.cs index b29ca27..dc6280c 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Services/ConfigService.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Services/ConfigService.cs @@ -48,6 +48,7 @@ public static class ConfigService public static string InfoFolder { get; } = "Info"; public static string OMDbFolder { get; } = ".omdb"; public static string StorageDbName { get; } = "omdb.db"; + public static string DefaultCover { get; private set; } = System.IO.Path.Combine(AppContext.BaseDirectory, "Assets\\Img", "DefaultCover.jpg"); /// /// 元文件文件名 /// @@ -59,7 +60,7 @@ public static void Load() { Core.Config.InitMCDb(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "MCDb.db")); SettingService.Load(); - + Core.Config.SetFFmpegExecutablesPath(System.IO.Path.Combine(AppContext.BaseDirectory, "Assets", "FFmpeg")); LoadStorages(); } diff --git a/OMDb.WinUI3/OMDb.WinUI3/Services/EntryService.cs b/OMDb.WinUI3/OMDb.WinUI3/Services/EntryService.cs index 613e953..2d429d4 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Services/EntryService.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Services/EntryService.cs @@ -14,112 +14,86 @@ using static System.Net.WebRequestMethods; using OMDb.Core.Services; using OMDb.Core.Enums; +using System.Transactions; namespace OMDb.WinUI3.Services { public static class EntryService { /// - /// 新建词条 + /// 新增 /// /// 词条唯一id - public static async Task AddEntryAsync() + public static async Task AddEntryAsync() { var entryDetail = await Dialogs.EditEntryDialog.ShowDialog(); if (entryDetail != null) { - if (Directory.Exists(entryDetail.FullEntryPath)) - { - int i = 1; - while (true) - { - string newPath = $"{entryDetail.FullEntryPath}({i++})"; - if (!Directory.Exists(newPath)) - { - entryDetail.FullEntryPath = newPath; - entryDetail.Entry.Path = newPath; - break; - } - } - } - - //创建词条文件夹 - InitFolder(entryDetail); + await NewEntryAsync(entryDetail); - - - - - //创建元数据(MataData) - InitFile(entryDetail); - - //保存至数据库 - await SaveToDbAsync(entryDetail); - - //这时已经是相对路径 Helpers.InfoHelper.ShowSuccess("创建成功"); - GlobalEvent.NotifyAddEntry(null, new EntryEventArgs(entryDetail.Entry)); - return entryDetail.Entry.EntryId; - } - else - { - return null; + } } + /// - /// 创建元数据(MataData) + /// 批量新增 /// - /// - private static void InitFile(Models.EntryDetail entry) + /// + public static async Task AddEntryBatchAsync() { - string metaDateFile = Path.Combine(entry.FullEntryPath, Services.ConfigService.MetadataFileNmae); - Core.Models.EntryMetadata metadata; - if (System.IO.File.Exists(metaDateFile)) - { - metadata = Core.Models.EntryMetadata.Read(metaDateFile); - metadata.Name = entry.Entry.Name; - } - else + var eds = await Dialogs.AddEntryBatchDialog.ShowDialog(); + foreach (var ed in eds) + await NewEntryAsync(ed); + } + + /// + /// 编辑 + /// + /// 词条唯一id + public static async Task EditEntryAsync(Core.Models.Entry entry) + { + var entryDetail = await Dialogs.EditEntryDialog.ShowDialog(entry); + if (entryDetail != null) { - metadata = new Core.Models.EntryMetadata() - { - Id = entry.Entry.EntryId, - Name = entry.Entry.Name, - }; + InitFile(entryDetail); + await UpdateDbAsync(entryDetail); + Helpers.InfoHelper.ShowSuccess("已保存"); + GlobalEvent.NotifyUpdateEntry(null, new EntryEventArgs(entryDetail.Entry)); } - metadata.Save(metaDateFile); } - //创建词条(Entry)路径 (仓库 -> .omdb -> Db源 -> 词条) - private static void InitFolder(Models.EntryDetail entry) + + /// + /// 删除 + /// + /// + /// + public static async Task RemoveEntryAsync(Core.Models.Entry entry) { - Directory.CreateDirectory(entry.FullEntryPath); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.AudioFolder)); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.ImgFolder)); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.VideoFolder)); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.ResourceFolder)); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.SubFolder)); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.InfoFolder)); - Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.MoreFolder)); + if (await Dialogs.QueryDialog.ShowDialog("删除", $"是否删除 {entry.Name} 词条?不会删除本地文件")) + { + Core.Services.EntryService.RemoveEntry(entry); + Helpers.InfoHelper.ShowSuccess("已删除"); + GlobalEvent.NotifyRemoveEntry(null, new EntryEventArgs(entry)); + } } /// /// 保存至数据库 /// - /// + /// /// /// - private static async Task SaveToDbAsync(Models.EntryDetail ed) + private static async Task UpdateDbAsync(Models.EntryDetail ed) { await Task.Run(() => { - Core.Services.EntryService.AddEntry(ed.Entry);//词条 + Core.Services.EntryService.UpdateOrAddEntry(ed.Entry);//更新词条主表 Core.Services.EntryNameSerivce.UpdateOrAddDefaultNames(ed.Entry.EntryId, ed.Entry.DbId, ed.Entry.Name);//更新或插入词条默认名称 - - TreatEntry(ed);//处理词条主表Entry TreatEntrySource(ed);//资源路径表EntrySource更新 TreatLabelLink(ed);//词条标签关联表 @@ -131,15 +105,14 @@ await Task.Run(() => /// /// 保存至数据库 /// - /// + /// /// /// - private static async Task UpdateDbAsync(Models.EntryDetail ed) + private static async Task SaveToDbAsync(Models.EntryDetail ed) { await Task.Run(() => { - //数据库主表and多语言表 更新 - Core.Services.EntryService.UpdateEntry(ed.Entry);//词条 + Core.Services.EntryService.UpdateOrAddEntry(ed.Entry);//词条 Core.Services.EntryNameSerivce.UpdateOrAddDefaultNames(ed.Entry.EntryId, ed.Entry.DbId, ed.Entry.Name);//更新或插入词条默认名称 TreatEntry(ed);//处理词条主表Entry @@ -149,40 +122,38 @@ await Task.Run(() => }); } - /// - /// 编辑词条 - /// - /// 词条唯一id - public static async Task EditEntryAsync(Core.Models.Entry entry) + public static async Task NewEntryAsync(EntryDetail ed, bool isNew = true) { - var entryDetail = await Dialogs.EditEntryDialog.ShowDialog(entry); - if (entryDetail != null) + if (isNew) { - InitFile(entryDetail); - await UpdateDbAsync(entryDetail); - Helpers.InfoHelper.ShowSuccess("已保存"); - GlobalEvent.NotifyUpdateEntry(null, new EntryEventArgs(entryDetail.Entry)); + //创建词条根目录 + if (Directory.Exists(ed.FullEntryPath)) + { + var my_format = "yyyyMMddHHmmss"; + string newPath = $"{ed.FullEntryPath}_{DateTime.Now.ToString(my_format)}"; + ed.FullEntryPath = newPath; + ed.Entry.Path = newPath; + } + InitFolder(ed);//创建词条文件夹 + InitFile(ed);//创建元数据(MataData) + await SaveToDbAsync(ed);//保存至数据库 } - } - - public static async Task RemoveEntryAsync(Core.Models.Entry entry) - { - if (await Dialogs.QueryDialog.ShowDialog("删除", $"是否删除 {entry.Name} 词条?不会删除本地文件")) + else { - Core.Services.EntryService.RemoveEntry(entry); - Helpers.InfoHelper.ShowSuccess("已删除"); - GlobalEvent.NotifyRemoveEntry(null, new EntryEventArgs(entry)); + } + GlobalEvent.NotifyAddEntry(null, new EntryEventArgs(ed.Entry)); } + private static void TreatLabelLink(EntryDetail ed) { if (ed.Labels?.Count != 0) { List entryLabelDbs = new List(ed.Labels.Count); ed.Labels.ForEach(p => entryLabelDbs.Add(new Core.DbModels.EntryLabelClassLinkDb() { EntryId = ed.Entry.EntryId, LCId = p.LCId, DbId = ed.Entry.DbId })); - Core.Services.LabelService.ClearEntryLabel(ed.Entry.EntryId);//清空词条分类标签 - Core.Services.LabelService.AddEntryLabel(entryLabelDbs);//添加词条分类标签 + Core.Services.LabelClassService.ClearEntryLabel(ed.Entry.EntryId);//清空词条分类标签 + Core.Services.LabelClassService.AddEntryLabel(entryLabelDbs);//添加词条分类标签 } if (ed.Lpdbs?.Count != 0) { @@ -229,14 +200,50 @@ private static void TreatEntry(EntryDetail ed) + + + + + + + /// - /// 批量新增 + /// 创建元数据(MataData) /// - /// - public static async Task AddEntryBatchAsync() + /// + private static void InitFile(Models.EntryDetail entry) + { + string metaDateFile = Path.Combine(entry.FullEntryPath, Services.ConfigService.MetadataFileNmae); + Core.Models.EntryMetadata metadata; + if (System.IO.File.Exists(metaDateFile)) + { + metadata = Core.Models.EntryMetadata.Read(metaDateFile); + metadata.Name = entry.Entry.Name; + } + else + { + metadata = new Core.Models.EntryMetadata() + { + Id = entry.Entry.EntryId, + Name = entry.Entry.Name, + }; + } + metadata.Save(metaDateFile); + } + + + //创建词条(Entry)路径 (仓库 -> .omdb -> Db源 -> 词条) + private static void InitFolder(Models.EntryDetail entry) { - var entryDetail = await Dialogs.AddEntryBatchDialog.ShowDialog(); - return null; + Directory.CreateDirectory(entry.FullEntryPath); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.AudioFolder)); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.ImgFolder)); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.VideoFolder)); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.ResourceFolder)); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.SubFolder)); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.InfoFolder)); + Directory.CreateDirectory(Path.Combine(entry.FullEntryPath, Services.ConfigService.MoreFolder)); } } } + diff --git a/OMDb.WinUI3/OMDb.WinUI3/Services/ExcelService.cs b/OMDb.WinUI3/OMDb.WinUI3/Services/ExcelService.cs index 3980cd5..becbf2c 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Services/ExcelService.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Services/ExcelService.cs @@ -38,29 +38,30 @@ public static void ExportExcel(string filePath, EnrtyStorage enrtyStorage) //用于支持gb2312 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - //創建數據表 - DataTable dataTable = new DataTable(); - //基本信息列 - dataTable.Columns.Add("Name", typeof(string)); - dataTable.Columns.Add("ReleaseDate", typeof(string)); - dataTable.Columns.Add("MyRating", typeof(double)); + //数据库查询 属性标签&分类标签 - var label_lc = Core.Services.LabelService.GetAllLabel(DbSelectorService.dbCurrentId); + var label_lc = Core.Services.LabelClassService.GetAllLabel(DbSelectorService.dbCurrentId); var label_lp = Core.Services.LabelPropertyService.GetAllLabel(DbSelectorService.dbCurrentId); //标签&词条 关联关系 - var result_EntryLabel = Core.Services.EntryLabelService.SelectAllEntryLabel(enrtyStorage.StorageName); + var result_EntryLabelClass = Core.Services.EntryLabelClassService.SelectAllEntryLabel(enrtyStorage.StorageName); var result_EntryLabelProperty = Core.Services.EntryLabelPropertyService.SelectAllEntryLabel(enrtyStorage.StorageName); - label_lp.Where(a => a.Level == 1).ToList().ForEach(s => dataTable.Columns.Add(s.Name, typeof(string))); - //分類列 - dataTable.Columns.Add("Classification", typeof(string)); + + DataTable dataTable = new DataTable();//創建數據表 - dataTable.Columns.Add("SaveType", typeof(string)); - dataTable.Columns.Add("path_source", typeof(string)); - dataTable.Columns.Add("path_entry", typeof(string)); - dataTable.Columns.Add("path_cover", typeof(string)); + dataTable.Columns.Add("Name", typeof(string));//词条名称 + dataTable.Columns.Add("Alias", typeof(string));//词条名称(别名) + dataTable.Columns.Add("ReleaseDate", typeof(string)); + dataTable.Columns.Add("MyRating", typeof(double)); + label_lp.Where(a => a.Level == 1).ToList().ForEach(s => dataTable.Columns.Add(s.Name, typeof(string)));//属性标签列 + + dataTable.Columns.Add("Classification", typeof(string));//分類列 + dataTable.Columns.Add("SaveType", typeof(string));//存储模式 + dataTable.Columns.Add("path_source", typeof(string));//存储路径 + dataTable.Columns.Add("path_entry", typeof(string));//词条路径 + dataTable.Columns.Add("path_cover", typeof(string));//封面路径(全路径) @@ -90,7 +91,7 @@ public static void ExportExcel(string filePath, EnrtyStorage enrtyStorage) row["MyRating"] = myRating; //屬性 - var elc = result_EntryLabel.Where(a => a.EntryId == Convert.ToString(eid)); + var elc = result_EntryLabelClass.Where(a => a.EntryId == Convert.ToString(eid)); var elp = result_EntryLabelProperty.Where(a => a.EntryId == Convert.ToString(eid)); foreach (var lp in label_lp) { @@ -434,17 +435,16 @@ public static async void ImportExcel(string filePath, EnrtyStorage enrtyStorage) switch (saveMode) { case SaveType.Folder: - lstPath.Add(esdbs[0].Path); - edb.CoverImg = CommonService.GetCoverByPath(lstPath, PathType.Folder); + edb.CoverImg = CommonService.GetCover(esdbs[0].Path); break; case SaveType.Files: if (esdbs.Count > 0) - edb.CoverImg = CommonService.GetCoverByPath(lstPath, PathType.Folder); + edb.CoverImg = CommonService.GetCover(lstPath); else - edb.CoverImg = CommonService.GetCoverByPath(); + edb.CoverImg = CommonService.GetCover(); break; case SaveType.Local: - edb.CoverImg = CommonService.GetCoverByPath(); + edb.CoverImg = CommonService.GetCover(); break; default: break; diff --git a/OMDb.WinUI3/OMDb.WinUI3/Services/RecentFileService.cs b/OMDb.WinUI3/OMDb.WinUI3/Services/RecentFileService.cs index 47f30b4..71a36ef 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/Services/RecentFileService.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/Services/RecentFileService.cs @@ -1,7 +1,7 @@ using Microsoft.UI.Xaml.CustomAttributes; using Newtonsoft.Json; -using OMDb.Core.Extensions; using OMDb.Core.Models; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Events; using OMDb.WinUI3.Services.Settings; using System; diff --git a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/ClassificationViewModel.cs b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/ClassificationViewModel.cs index 6c507f9..6542514 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/ClassificationViewModel.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/ClassificationViewModel.cs @@ -4,6 +4,7 @@ using Microsoft.UI.Xaml.Media.Imaging; using MySqlX.XDevAPI.Common; using OMDb.Core.Enums; +using OMDb.Core.Helpers; using OMDb.Core.Models; using OMDb.WinUI3.Models; using OMDb.WinUI3.Services; @@ -89,7 +90,7 @@ private async Task InitLabels() { LabelsDic.Clear(); } - var labels = await Core.Services.LabelService.GetAllLabelAsync(Services.Settings.DbSelectorService.dbCurrentId); + var labels = await Core.Services.LabelClassService.GetAllLabelAsync(Services.Settings.DbSelectorService.dbCurrentId); if (labels != null) { foreach (var label in labels) @@ -252,7 +253,7 @@ private string FindBannerCover(List entries) { foreach (var file in Core.Helpers.RandomHelper.RandomList(items,100))//仅对100张照片计算 { - if (Helpers.ImgHelper.IsSupportImg(file.FullName)) + if (ImageHelper.IsSupportImg(file.FullName)) { infos.Add(Core.Helpers.ImageHelper.GetImageInfo(file.FullName)); } diff --git a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/AddEntryBatchViewModel.cs b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/AddEntryBatchViewModel.cs index 3108362..32754b4 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/AddEntryBatchViewModel.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/AddEntryBatchViewModel.cs @@ -1,6 +1,5 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using OMDb.Core.Extensions; using OMDb.WinUI3.Services; using System; using System.Collections.Generic; diff --git a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/EditEntryViewModel.cs b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/EditEntryViewModel.cs index 4f019f3..06defb2 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/EditEntryViewModel.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/Dialogs/EditEntryViewModel.cs @@ -1,6 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Models; using OMDb.WinUI3.MyControls; using OMDb.WinUI3.Services; @@ -208,7 +208,7 @@ private async void Init(Core.Models.Entry entry) } else { - var labels = await Core.Services.LabelService.GetLabelOfEntryAsync(entry.EntryId); + var labels = await Core.Services.LabelClassService.GetLabelOfEntryAsync(entry.EntryId); if (labels != null) { Helpers.WindowHelper.MainWindow.DispatcherQueue.TryEnqueue(() => diff --git a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryCollectionDetailViewModel.cs b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryCollectionDetailViewModel.cs index 47f7468..256826c 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryCollectionDetailViewModel.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryCollectionDetailViewModel.cs @@ -1,7 +1,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.UI.Xaml.Controls.Primitives; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Models; using OMDb.WinUI3.Services; using System; diff --git a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryDetailViewModel.cs b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryDetailViewModel.cs index 329d8f8..dd0afdf 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryDetailViewModel.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryDetailViewModel.cs @@ -3,7 +3,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Shapes; using OMDb.Core.DbModels; -using OMDb.Core.Extensions; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Dialogs; using OMDb.WinUI3.Models; using System; @@ -141,7 +141,7 @@ public bool IsEditWatchHistory Time = new DateTime(NewHistorDate.Year, NewHistorDate.Month, NewHistorDate.Day, NewHistorTime.Hours, NewHistorTime.Minutes, 0), Mark = NewHistorMark }; - Core.Services.WatchHistoryService.AddWatchHistory(watchHistory); + Core.Services.EntryWatchHistoryService.AddWatchHistory(watchHistory); Entry.WatchHistory.Add(watchHistory); } else//编辑 @@ -149,7 +149,7 @@ public bool IsEditWatchHistory EditingWatchHistory.Time = new DateTime(NewHistorDate.Year, NewHistorDate.Month, NewHistorDate.Day, NewHistorTime.Hours, NewHistorTime.Minutes, 0); EditingWatchHistory.Mark = NewHistorMark; EditingWatchHistory.Done = NewHistorDone; - Core.Services.WatchHistoryService.UpdateWatchHistory(EditingWatchHistory); + Core.Services.EntryWatchHistoryService.UpdateWatchHistory(EditingWatchHistory); } CancelEditHistoryCommand.Execute(null); await Entry.UpdateWatchHistoryAsync();//确保按时间倒序 @@ -172,7 +172,7 @@ public bool IsEditWatchHistory { if (await Dialogs.QueryDialog.ShowDialog("是否确认删除记录?", $"{item.Time} - {item.Mark}")) { - Core.Services.WatchHistoryService.DeleteWatchHistory(item); + Core.Services.EntryWatchHistoryService.DeleteWatchHistory(item); Entry.WatchHistory.Remove(item); if(item.Done) { @@ -209,7 +209,7 @@ public bool IsEditWatchHistory { Rating = value; Entry.Entry.MyRating = Rating; - Core.Services.EntryService.UpdateEntry(Entry.Entry); + Core.Services.EntryService.UpdateOrAddEntry(Entry.Entry); Helpers.InfoHelper.ShowSuccess("已更新评分"); }); public ICommand RefreshCommand => new RelayCommand(async() => @@ -249,7 +249,7 @@ await Task.Run(() => }); string newRelPath = System.IO.Path.Combine(Entry.Entry.Path.Substring(0, Entry.Entry.Path.LastIndexOf(oldEntryName)), Entry.Name); Entry.Entry.Path = newRelPath; - Core.Services.EntryService.UpdateEntry(Entry.Entry); + Core.Services.EntryService.UpdateOrAddEntry(Entry.Entry); Dialogs.WatingDialog.Hide(); RefreshCommand.Execute(null); } diff --git a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryViewModel.cs b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryViewModel.cs index 442394b..65e4c60 100644 --- a/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryViewModel.cs +++ b/OMDb.WinUI3/OMDb.WinUI3/ViewModels/EntryViewModel.cs @@ -1,8 +1,8 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Newtonsoft.Json; -using OMDb.Core.Extensions; using OMDb.Core.Models; +using OMDb.Core.Utils.Extensions; using OMDb.WinUI3.Models; using OMDb.WinUI3.Services; using System; @@ -17,7 +17,7 @@ namespace OMDb.WinUI3.ViewModels { public class EntryViewModel : ObservableObject { - public static EntryViewModel Current { get;private set; } + public static EntryViewModel Current { get; private set; } public ObservableCollection EnrtyStorages { get; set; } = Services.ConfigService.EnrtyStorages; private ObservableCollection entries; public ObservableCollection Entries @@ -41,7 +41,7 @@ public Core.Enums.SortType SortType set { SetProperty(ref sortType, value); - _=UpdateEntryListAsync(); + _ = UpdateEntryListAsync(); } } private Core.Enums.SortWay sortWay = Core.Enums.SortWay.Positive; @@ -87,7 +87,7 @@ public ObservableCollection EntryStorages private string autoSuggestText; public string AutoSuggestText { - get=> autoSuggestText; + get => autoSuggestText; set { SetProperty(ref autoSuggestText, value); @@ -146,7 +146,7 @@ public EntryViewModel() private async void Init() { Helpers.InfoHelper.ShowWaiting(); - var labelDbs = await Core.Services.LabelService.GetAllLabelAsync(Services.Settings.DbSelectorService.dbCurrentId); + var labelDbs = await Core.Services.LabelClassService.GetAllLabelAsync(Services.Settings.DbSelectorService.dbCurrentId); List