From 7c62a61dfaa54ecf4c47811761e11d2d4749b46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A3=8A?= Date: Wed, 24 Nov 2021 23:43:04 +0800 Subject: [PATCH 1/5] =?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 --- TextLocator/Core/AppConst.cs | 4 +-- TextLocator/Index/IndexCore.cs | 30 +++++++++++++++++------ TextLocator/MainWindow.xaml | 2 +- TextLocator/Service/DevelopFileService.cs | 9 +------ TextLocator/Service/TxtFileService.cs | 10 ++------ TextLocator/Service/WordFileService.cs | 6 ++--- TextLocator/Service/XmlFileService.cs | 9 +------ 7 files changed, 33 insertions(+), 37 deletions(-) diff --git a/TextLocator/Core/AppConst.cs b/TextLocator/Core/AppConst.cs index 03ed748..a600210 100644 --- a/TextLocator/Core/AppConst.cs +++ b/TextLocator/Core/AppConst.cs @@ -15,11 +15,11 @@ namespace TextLocator.Core /// /// 线程池最小数量 /// - public static readonly int THREAD_POOL_MIN_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MinSize", "4")); + public static readonly int THREAD_POOL_MIN_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MinSize", "16")); /// /// 线程池最大数量 /// - public static readonly int THREAD_POOL_MAX_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MaxSize", "8")); + public static readonly int THREAD_POOL_MAX_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MaxSize", "32")); /// /// 应用目录 /// diff --git a/TextLocator/Index/IndexCore.cs b/TextLocator/Index/IndexCore.cs index 89c3062..a6ca579 100644 --- a/TextLocator/Index/IndexCore.cs +++ b/TextLocator/Index/IndexCore.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using System.Text.RegularExpressions; using System.Threading; using TextLocator.Core; @@ -158,17 +159,19 @@ namespace TextLocator.Index { TaskInfo taskInfo = obj as TaskInfo; try - { + { + // 开始时间1 + var taskMark = TaskTime.StartNew(); + + // 索引写入 Lucene.Net.Index.IndexWriter indexWriter = taskInfo.IndexWriter; + // 文件路径 string filePath = taskInfo.FilePath; // 写入 AppUtil.WriteValue("FileIndex", filePath, "1"); - // 开始时间 - var taskMark = TaskTime.StartNew(); - // 文件信息 FileInfo fileInfo = new FileInfo(filePath); // 文件名 @@ -181,9 +184,20 @@ namespace TextLocator.Index // 根据文件路径获取文件类型(自定义文件类型分类) FileType fileType = FileTypeUtil.GetFileType(filePath); + string filePathPadding = filePath; + try + { + filePathPadding = filePath.Substring(0, 35) + "......" + filePath.Substring(filePath.Length - 35); + } + catch { } + + StringBuilder msg = new StringBuilder("[" + finishCount * 1.0F + "/" + taskInfo.TotalCount + "] => 引擎:" + (int)fileType + ",文件:" + filePathPadding); + // 文件内容 string content = FileInfoServiceFactory.GetFileInfoService(fileType).GetFileContent(filePath); + msg.Append(",解析:" + taskMark.ConsumeTime + "秒"); + // 缩略信息 string breviary = AppConst.REGIX_LINE_BREAKS_AND_WHITESPACE.Replace(content, ""); if (breviary.Length > 150) @@ -194,6 +208,9 @@ namespace TextLocator.Index // 文件标记 string fileMark = MD5Util.GetMD5Hash(filePath); //fileInfo.DirectoryName + fileInfo.CreationTime.ToString(); + // 开始时间2 + taskMark = TaskTime.StartNew(); + lock (locker) { // 当索引文件中含有与filemark相等的field值时,会先删除再添加,以防出现重复 @@ -216,11 +233,10 @@ namespace TextLocator.Index // 优化索引 indexWriter.Optimize(); } - - string msg = "解析文件:[" + finishCount * 1.0F + "/" + taskInfo.TotalCount + "] => 引擎:" + (int)fileType + ",文件:" + filePath + ",耗时:" + taskMark.ConsumeTime + "秒"; + msg.Append(",索引:" + taskMark.ConsumeTime + "秒"); // 执行状态回调 - taskInfo.Callback(msg, CalcCompletionRatio(finishCount, taskInfo.TotalCount)); + taskInfo.Callback(msg.ToString(), CalcCompletionRatio(finishCount, taskInfo.TotalCount)); ; log.Debug(msg); } diff --git a/TextLocator/MainWindow.xaml b/TextLocator/MainWindow.xaml index 57b0bb2..ae7652e 100644 --- a/TextLocator/MainWindow.xaml +++ b/TextLocator/MainWindow.xaml @@ -12,7 +12,7 @@ - + diff --git a/TextLocator/Service/DevelopFileService.cs b/TextLocator/Service/DevelopFileService.cs index 9a3dc35..98f3b25 100644 --- a/TextLocator/Service/DevelopFileService.cs +++ b/TextLocator/Service/DevelopFileService.cs @@ -26,14 +26,7 @@ namespace TextLocator.Service { using (StreamReader reader = new StreamReader(new FileStream(filePath, FileMode.Open), Encoding.UTF8)) { - StringBuilder builder = new StringBuilder(); - string line; - while ((line = reader.ReadLine()) != null) - { - builder.Append(line); - } - - content = AppConst.REGIX_TAG.Replace(builder.ToString(), ""); + content = AppConst.REGIX_TAG.Replace(reader.ReadToEnd(), ""); reader.Close(); reader.Dispose(); diff --git a/TextLocator/Service/TxtFileService.cs b/TextLocator/Service/TxtFileService.cs index 06cb67d..c543d33 100644 --- a/TextLocator/Service/TxtFileService.cs +++ b/TextLocator/Service/TxtFileService.cs @@ -22,16 +22,10 @@ namespace TextLocator.Service { using (StreamReader reader = new StreamReader(filePath, Encoding.UTF8)) { - StringBuilder builder = new StringBuilder(); - string line; - while ((line = reader.ReadLine()) != null) - { - builder.Append(line); - } + content = reader.ReadToEnd(); + reader.Close(); reader.Dispose(); - - content = builder.ToString(); } } catch (Exception ex) diff --git a/TextLocator/Service/WordFileService.cs b/TextLocator/Service/WordFileService.cs index 5e16d87..4a4c86b 100644 --- a/TextLocator/Service/WordFileService.cs +++ b/TextLocator/Service/WordFileService.cs @@ -34,10 +34,10 @@ namespace TextLocator.Service builder.AppendLine(paragraph.Text); } } - document.Close(); - document.Dispose(); - content = builder.ToString(); + + document.Close(); + document.Dispose(); } } catch (Exception ex) diff --git a/TextLocator/Service/XmlFileService.cs b/TextLocator/Service/XmlFileService.cs index fad755c..ded75f0 100644 --- a/TextLocator/Service/XmlFileService.cs +++ b/TextLocator/Service/XmlFileService.cs @@ -24,14 +24,7 @@ namespace TextLocator.Service { using (StreamReader reader = new StreamReader(new FileStream(filePath, FileMode.Open), Encoding.UTF8)) { - StringBuilder builder = new StringBuilder(); - string line; - while ((line = reader.ReadLine()) != null) - { - builder.Append(line); - } - - content = AppConst.REGIX_TAG.Replace(builder.ToString(), ""); + content = AppConst.REGIX_TAG.Replace(reader.ReadToEnd(), ""); reader.Close(); reader.Dispose(); -- Gitee From b02169bbb5af195fa938e7064bd1c8421a3501ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A3=8A?= Date: Sat, 15 Jan 2022 19:09:00 +0800 Subject: [PATCH 2/5] =?UTF-8?q?UI=E4=BA=A4=E4=BA=92=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E6=96=87=E4=BB=B6=E5=86=85=E5=AE=B9=E7=9A=84?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E4=BF=A1=E6=81=AF=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TextLocator/App.xaml.cs | 2 +- TextLocator/Enums/EnumExtension.cs | 9 +-- TextLocator/Enums/FileType.cs | 2 +- TextLocator/MainWindow.xaml | 44 +++++++------- TextLocator/MainWindow.xaml.cs | 64 +++++++++++++++------ TextLocator/Properties/AssemblyInfo.cs | 2 +- TextLocator/Resource/GenericDictionary.xaml | 25 ++++++++ TextLocator/Service/NoTextFileService.cs | 39 ++++++++++++- TextLocator/TextLocator.csproj | 1 + TextLocator/Util/FileUtil.cs | 2 +- 10 files changed, 137 insertions(+), 53 deletions(-) diff --git a/TextLocator/App.xaml.cs b/TextLocator/App.xaml.cs index 7fc2692..b30583a 100644 --- a/TextLocator/App.xaml.cs +++ b/TextLocator/App.xaml.cs @@ -57,7 +57,7 @@ namespace TextLocator // Excel服务 FileInfoServiceFactory.Register(FileType.Excel表格, new ExcelFileService()); // PowerPoint服务 - FileInfoServiceFactory.Register(FileType.PPT演示文稿, new PowerPointFileService()); + FileInfoServiceFactory.Register(FileType.PPT文稿, new PowerPointFileService()); // PDF服务 FileInfoServiceFactory.Register(FileType.PDF文档, new PdfFileService()); // HTML或XML服务 diff --git a/TextLocator/Enums/EnumExtension.cs b/TextLocator/Enums/EnumExtension.cs index 9b8ea38..181f002 100644 --- a/TextLocator/Enums/EnumExtension.cs +++ b/TextLocator/Enums/EnumExtension.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Data; +using System.ComponentModel; namespace TextLocator.Enums { diff --git a/TextLocator/Enums/FileType.cs b/TextLocator/Enums/FileType.cs index fa7bf2d..93dd77c 100644 --- a/TextLocator/Enums/FileType.cs +++ b/TextLocator/Enums/FileType.cs @@ -21,7 +21,7 @@ namespace TextLocator.Enums /// PowerPoint /// [Description("ppt,pptx")] - PPT演示文稿, + PPT文稿, /// /// PDF /// diff --git a/TextLocator/MainWindow.xaml b/TextLocator/MainWindow.xaml index ae7652e..abf7dbf 100644 --- a/TextLocator/MainWindow.xaml +++ b/TextLocator/MainWindow.xaml @@ -20,7 +20,7 @@ - + @@ -48,10 +48,11 @@ + +