diff --git a/TextLocator/Index/LuceneIndexCore.cs b/TextLocator/Index/LuceneIndexCore.cs
index b4ba243eeeceda2987daeb033254f03dab467696..91c71e5aa0e5b297572410e4e95a0a5114ccc823 100644
--- a/TextLocator/Index/LuceneIndexCore.cs
+++ b/TextLocator/Index/LuceneIndexCore.cs
@@ -24,8 +24,9 @@ namespace TextLocator.Index
///
/// 状态回调委托
///
- ///
- public delegate void Callback(string status);
+ ///
+ ///
+ public delegate void Callback(string msg, double percent);
///
/// 锁
@@ -57,10 +58,13 @@ namespace TextLocator.Index
// 文件总数
int count = filePaths.Count();
+ // 每次初始化的时候完成数量都是0
+ finishCount = 0;
+
using (var countDown = new MutipleThreadResetEvent(count))
{
// 设置线程最大数量
- ThreadPool.SetMaxThreads(24, 48);
+ ThreadPool.SetMaxThreads(32, 64);
// 遍历读取文件,并创建索引
for (int i = 0; i < count; i++)
{
@@ -77,6 +81,7 @@ namespace TextLocator.Index
// 等待所有线程结束
countDown.WaitAll();
+ // 销毁
countDown.Dispose();
}
@@ -167,14 +172,12 @@ namespace TextLocator.Index
indexWriter.AddDocument(doc);
// 优化索引
indexWriter.Optimize();
-
- finishCount++;
}
- string msg = "索引:[" + finishCount + " / " + taskInfo.TotalCount + "] => 文件:" + filePath + ",耗时:" + (DateTime.Now - beginMark).TotalSeconds + "秒";
+ string msg = "索引:[" + finishCount * 1.0F + "/" + taskInfo.TotalCount + "] => 文件:" + filePath + ",耗时:" + (DateTime.Now - beginMark).TotalSeconds + "秒";
// 执行状态回调
- taskInfo.Callback(msg);
+ taskInfo.Callback(msg, finishCount * 1.00F / taskInfo.TotalCount * 1.00F * 100.00F);
log.Debug(msg);
}
@@ -184,6 +187,12 @@ namespace TextLocator.Index
}
finally
{
+
+ lock (locker)
+ {
+ finishCount++;
+ }
+
// 手动GC
GC.Collect();
GC.WaitForPendingFinalizers();
diff --git a/TextLocator/MainWindow.xaml b/TextLocator/MainWindow.xaml
index 88d078e3db79455b498d74ab4f6387e68b665845..100b16eeb2cebecd0d717564a3b5dfbba5ab7b28 100644
--- a/TextLocator/MainWindow.xaml
+++ b/TextLocator/MainWindow.xaml
@@ -226,11 +226,13 @@
-
-
-
+
+
+
+
+
diff --git a/TextLocator/MainWindow.xaml.cs b/TextLocator/MainWindow.xaml.cs
index e856dde8d4717e9e1480a55387d2ad84fd5c501b..0d2d271d0c1b5175923074b70f24b0741b110365 100644
--- a/TextLocator/MainWindow.xaml.cs
+++ b/TextLocator/MainWindow.xaml.cs
@@ -146,14 +146,18 @@ namespace TextLocator
Task.Factory.StartNew(() =>
{
DateTime beginMark = DateTime.Now;
+ // 定义文件列表
+ List filePaths = new List();
foreach (string s in _IndexFolders)
{
+ log.Debug("目录:" + s);
// 获取文件信息列表
- List filePaths = FileUtil.GetAllFiles(s);
- // 创建索引方法
- LuceneIndexCore.CreateIndex(filePaths, rebuild, ShowStatus);
+ FileUtil.GetAllFiles(s, filePaths);
}
+ // 创建索引方法
+ LuceneIndexCore.CreateIndex(filePaths, rebuild, ShowStatus);
+
string msg = "索引执行结束,共用时:" + (DateTime.Now - beginMark).TotalSeconds + "秒";
// 显示状态
@@ -173,10 +177,15 @@ namespace TextLocator
/// 显示状态
///
///
- private void ShowStatus(string text)
+ ///
+ private void ShowStatus(string text, double percent = 100)
{
this.Dispatcher.BeginInvoke(new Action(() => {
this.WorkStatus.Text = text;
+ if (percent > 0)
+ {
+ this.WorkProgress.Value = percent;
+ }
}));
}
@@ -311,11 +320,11 @@ namespace TextLocator
resultNum++;
}
- string message = "检索完成!共检索到" + resultNum + "个符合条件的结果(只显示前" + num + "条)。耗时:" + (DateTime.Now - beginMark).TotalSeconds + "秒。";
+ string msg = "检索完成!共检索到" + resultNum + "个符合条件的结果(只显示前" + num + "条)。耗时:" + (DateTime.Now - beginMark).TotalSeconds + "秒。";
- Message.ShowSuccess("MessageContainer", message);
+ Message.ShowSuccess("MessageContainer", msg);
- ShowStatus(message);
+ ShowStatus(msg);
}
finally
{
@@ -474,6 +483,8 @@ namespace TextLocator
return;
}
+ ShowStatus("开始更新索引...");
+
BuildIndex(false);
}
@@ -498,7 +509,9 @@ namespace TextLocator
Message.ShowWarning("MessageContainer", "索引构建中,请稍等。");
return;
}
- build = true;
+ build = true;
+
+ ShowStatus("开始重建索引...");
BuildIndex(true);
}
diff --git a/TextLocator/Properties/AssemblyInfo.cs b/TextLocator/Properties/AssemblyInfo.cs
index 61c5dc01a4a674b467e0743105f39ff088092739..f1dfc959ba83edfe1a3135799fefa9bb034a7363 100644
--- a/TextLocator/Properties/AssemblyInfo.cs
+++ b/TextLocator/Properties/AssemblyInfo.cs
@@ -50,7 +50,7 @@ using System.Windows;
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.6")]
+[assembly: AssemblyFileVersion("1.0.0.8")]
// log4net
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
\ No newline at end of file
diff --git a/TextLocator/Util/FileUtil.cs b/TextLocator/Util/FileUtil.cs
index 0c7dfc77cdd4bd57ef7e0ac5e35c5f3f374f4347..58a32c3b5ccc7729bb7397055c39b418b6cfd81f 100644
--- a/TextLocator/Util/FileUtil.cs
+++ b/TextLocator/Util/FileUtil.cs
@@ -72,23 +72,6 @@ namespace TextLocator.Util
return bi;
}
- ///
- /// 获取全部文件
- ///
- /// 根目录路径
- ///
- public static List GetAllFiles(string rootPath)
- {
- log.Debug("根目录:" + rootPath);
- // 声明一个files包,用来存储遍历出的word文档
- List filePaths = new List();
- // 获取全部文件列表
- GetAllFiles(rootPath, filePaths);
-
- // 返回文件列表
- return filePaths;
- }
-
///
/// 获取文件大小友好显示
///
@@ -136,7 +119,7 @@ namespace TextLocator.Util
///
/// 根目录路径
/// 文档列表
- private static void GetAllFiles(string rootPath, List filePaths)
+ public static void GetAllFiles(string rootPath, List filePaths)
{
DirectoryInfo dir = new DirectoryInfo(rootPath);
// 得到所有子目录