diff --git a/TextLocator/App.xaml.cs b/TextLocator/App.xaml.cs index 664a990e355e052c466ca69c6131e54b4dd75b2a..7cbd5778a27cb7e237f4f42eb9dc6c4feb8a13f1 100644 --- a/TextLocator/App.xaml.cs +++ b/TextLocator/App.xaml.cs @@ -110,7 +110,7 @@ namespace TextLocator AppUtil.WriteValue("AppConfig", "ResultListPageSize", AppConst.MRESULT_LIST_PAGE_SIZE + ""); // 文件读取超时时间 - AppUtil.WriteValue("AppConfig", "FileReadTimeout", AppConst.FILE_READ_TIMEOUT + ""); + AppUtil.WriteValue("AppConfig", "FileContentReadTimeout", AppConst.FILE_CONTENT_READ_TIMEOUT + ""); // 文件内容摘要切割长度 AppUtil.WriteValue("AppConfig", "FileContentBreviaryCutLength", AppConst.FILE_CONTENT_BREVIARY_CUT_LENGTH + ""); diff --git a/TextLocator/Core/AppConst.cs b/TextLocator/Core/AppConst.cs index ee402f43df06f65b3e085cc7af8d850e6bf23fb4..ec5136be34f85733555fcc0614186dcdf5ece18e 100644 --- a/TextLocator/Core/AppConst.cs +++ b/TextLocator/Core/AppConst.cs @@ -15,9 +15,13 @@ namespace TextLocator.Core public class AppConst { /// - /// 文件读取超时时间,单位:秒 + /// 索引更新任务间隔时间,单位:分 + /// + public static int INDEX_UPDATE_TASK_INTERVAL = int.Parse(AppUtil.ReadValue("AppConfig", "IndexUpdateTaskInterval", "10")); + /// + /// 文件读取超时时间,单位:分钟 /// - public static int FILE_READ_TIMEOUT = int.Parse(AppUtil.ReadValue("AppConfig", "FileReadTimeout", "600")); + public static int FILE_CONTENT_READ_TIMEOUT = int.Parse(AppUtil.ReadValue("AppConfig", "FileContentReadTimeout", "10")); /// /// 文件大小限制 /// @@ -34,10 +38,7 @@ namespace TextLocator.Core /// 缓存池容量 /// public static int CACHE_POOL_CAPACITY = int.Parse(AppUtil.ReadValue("AppConfig", "CachePoolCapacity", "100000")); - /// - /// 索引更新任务间隔时间,单位:分 - /// - public static int INDEX_UPDATE_TASK_INTERVAL = int.Parse(AppUtil.ReadValue("AppConfig", "IndexUpdateTaskInterval", "10")); + /// /// 启用索引更新任务,默认启用 diff --git a/TextLocator/Factory/FileInfoServiceFactory.cs b/TextLocator/Factory/FileInfoServiceFactory.cs index 48a4be80b2249786ed899c9cdeae195970c1bc75..b851e2415df241e44460cc846efedcd893208fb8 100644 --- a/TextLocator/Factory/FileInfoServiceFactory.cs +++ b/TextLocator/Factory/FileInfoServiceFactory.cs @@ -143,7 +143,7 @@ namespace TextLocator.Factory private static void Wait(Thread t, WaitHandle are) { WaitHandle[] ares = new WaitHandle[] { are }; - int index = WaitHandle.WaitAny(ares, TimeSpan.FromSeconds(AppConst.FILE_READ_TIMEOUT)); + int index = WaitHandle.WaitAny(ares, TimeSpan.FromMinutes(AppConst.FILE_CONTENT_READ_TIMEOUT)); if ((index != 0) && t.IsAlive) // 如果不是执行完成的信号,并且,线程还在执行,那么,结束这个线程 { t.Abort(); diff --git a/TextLocator/HotkeyWindow.xaml b/TextLocator/HotkeyWindow.xaml index 9e462da476ea0fb5a15ab01d596a7a36ee6a3460..a8595af2ce42be23cb1b78c4e9a84700a1d097bc 100644 --- a/TextLocator/HotkeyWindow.xaml +++ b/TextLocator/HotkeyWindow.xaml @@ -9,7 +9,7 @@ Title="热键设置" Height="380" Width="520" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" ResizeMode="CanMinimize" Icon="/Resource/App.ico" Loaded="Window_Loaded" Closed="Window_Closed" > - + diff --git a/TextLocator/SettingWindow.xaml b/TextLocator/SettingWindow.xaml index 079e29c44052a637073c43650b915875ef02743e..c662a360e4b8b3bcc7b3959a3c54e2c0e1227d50 100644 --- a/TextLocator/SettingWindow.xaml +++ b/TextLocator/SettingWindow.xaml @@ -7,65 +7,89 @@ xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore" mc:Ignorable="d" x:Name="hotkey" - Title="设置" Height="380" Width="520" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" ResizeMode="CanMinimize" Icon="/Resource/App.ico" Loaded="Window_Loaded" Closed="Window_Closed" > + Title="设置" Height="596.25" Width="1060" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow" ResizeMode="CanMinimize" Icon="/Resource/App.ico" Loaded="Window_Loaded" Closed="Window_Closed"> + + + - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/TextLocator/SettingWindow.xaml.cs b/TextLocator/SettingWindow.xaml.cs index 0a530c827ba5bcc44b58d69bec973523c5d767b5..9bab60f0ad528a7fa6385c5e44a836d41d71cba4 100644 --- a/TextLocator/SettingWindow.xaml.cs +++ b/TextLocator/SettingWindow.xaml.cs @@ -1,16 +1,9 @@ using log4net; -using Newtonsoft.Json; -using Rubyer; using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; -using System.Windows.Media; using TextLocator.Core; -using TextLocator.HotKey; using TextLocator.Message; using TextLocator.Util; @@ -57,22 +50,27 @@ namespace TextLocator /// private void LoadConfig() { - // 每页显示条数 - this.ResultListPageSize.Text = AppConst.MRESULT_LIST_PAGE_SIZE + ""; + // -------- 索引和文件 + // 启用索引更新任务 + this.EnableIndexUpdateTask.IsChecked = AppConst.ENABLE_INDEX_UPDATE_TASK; + // 索引更新时间间隔 + this.IndexUpdateTaskInterval.Text = AppConst.INDEX_UPDATE_TASK_INTERVAL + ""; // 文件读取超时时间 - this.FileReadTimeout.Text = AppConst.FILE_READ_TIMEOUT + ""; + this.FileContentReadTimeout.Text = AppConst.FILE_CONTENT_READ_TIMEOUT + ""; + + // -------- 列表和缓存 + // 每页显示条数 + this.ResultListPageSize.Text = AppConst.MRESULT_LIST_PAGE_SIZE + ""; // 缓存池容量 this.CachePoolCapacity.Text = AppConst.CACHE_POOL_CAPACITY + ""; - // 启用索引更新任务 - this.EnableIndexUpdateTask.IsChecked = AppConst.ENABLE_INDEX_UPDATE_TASK; - // 索引更新时间间隔 - this.IndexUpdateTaskInterval.Text = AppConst.INDEX_UPDATE_TASK_INTERVAL + ""; - + // -------- 内容预览 // 启用预览内容摘要 this.EnablePreviewSummary.IsChecked = AppConst.ENABLE_PREVIEW_SUMMARY; + // 文件内容摘要切割长度 + this.FileContentBreviaryCutLength.Text = AppConst.FILE_CONTENT_BREVIARY_CUT_LENGTH + ""; } #region 保存并关闭 @@ -83,112 +81,145 @@ namespace TextLocator /// private async void SaveClose_Click(object sender, RoutedEventArgs e) { - // 缓存池容量 - string cachePoolCapacityText = this.CachePoolCapacity.Text; - int cachePoolCapacity = 0; + // -------- 索引和文件 + // 启用索引更新任务 + bool enableIndexUpdateTask = (bool)this.EnableIndexUpdateTask.IsChecked; + if (enableIndexUpdateTask) + { + // 索引更新时间间隔 + string indexUpdateTaskIntervalText = this.IndexUpdateTaskInterval.Text; + int indexUpdateTaskInterval = 0; + try + { + indexUpdateTaskInterval = int.Parse(indexUpdateTaskIntervalText); + } + catch + { + MessageCore.ShowWarning("索引更新任务间隔时间错误"); + return; + } + if (indexUpdateTaskInterval < 5 || indexUpdateTaskInterval > 60) + { + MessageCore.ShowWarning("索引更新任务间隔时间:建议设置在5 - 60分钟范围内"); + return; + } + + AppConst.INDEX_UPDATE_TASK_INTERVAL = indexUpdateTaskInterval; + } + // 文件读取超时时间 + string fileContentReadTimeoutText = this.FileContentReadTimeout.Text; + int fileContentReadTimeout = 0; try { - cachePoolCapacity = int.Parse(cachePoolCapacityText); + fileContentReadTimeout = int.Parse(fileContentReadTimeoutText); } catch { - MessageCore.ShowWarning("缓存池容量设置错误"); + MessageCore.ShowWarning("文件读取超时时间错误"); return; } - if (cachePoolCapacity < 50000 || cachePoolCapacity > 500000) + if (fileContentReadTimeout < 5 || fileContentReadTimeout > 15) { - MessageCore.ShowWarning("建议设置在5-50W范围内"); + MessageCore.ShowWarning("文件内容读取超时时间:建议设置在5 - 15分钟范围内"); return; } + // -------- 列表和缓存 // 每页显示条数 - string ResultListPageSizeText = this.ResultListPageSize.Text; - int ResultListPageSize = 0; + string resultListPageSizeText = this.ResultListPageSize.Text; + int resultListPageSize = 0; try { - ResultListPageSize = int.Parse(ResultListPageSizeText); + resultListPageSize = int.Parse(resultListPageSizeText); } catch { MessageCore.ShowWarning("分页条数错误"); return; } - if (ResultListPageSize < 50 || ResultListPageSize > 300) + if (resultListPageSize < 50 || resultListPageSize > 300) { - MessageCore.ShowWarning("建议设置在50 - 300范围内"); + MessageCore.ShowWarning("列表枫叶条数:建议设置在50 - 300范围内"); return; } - - // 文件读取超时时间 - string fileReadTimeoutText = this.FileReadTimeout.Text; - int fileReadTimeout = 0; + // 缓存池容量 + string cachePoolCapacityText = this.CachePoolCapacity.Text; + int cachePoolCapacity = 0; try { - fileReadTimeout = int.Parse(fileReadTimeoutText); + cachePoolCapacity = int.Parse(cachePoolCapacityText); } catch { - MessageCore.ShowWarning("文件读取超时时间错误"); + MessageCore.ShowWarning("缓存池容量设置错误"); return; } - if (fileReadTimeout < 5 * 60 || fileReadTimeout > 15 * 60) + if (cachePoolCapacity < 50000 || cachePoolCapacity > 500000) { - MessageCore.ShowWarning("建议设置在5 - 15分钟范围内"); + MessageCore.ShowWarning("缓存池容量:建议设置在5 - 50W范围内"); return; } - // 启用索引更新任务 - bool enableIndexUpdateTask = (bool)this.EnableIndexUpdateTask.IsChecked; - if (enableIndexUpdateTask) + // -------- 内容预览 + // 启用预览内容摘要 + bool enablePreviewSummary = (bool)this.EnablePreviewSummary.IsChecked; + if (enablePreviewSummary) { - // 索引更新时间间隔 - string indexUpdateTaskIntervalText = this.IndexUpdateTaskInterval.Text; - int indexUpdateTaskInterval = 0; + // 文件内容摘要切割长度 + string fileContentBreviaryCutLengthText = this.FileContentBreviaryCutLength.Text; + int fileContentBreviaryCutLength = 0; try { - indexUpdateTaskInterval = int.Parse(indexUpdateTaskIntervalText); + fileContentBreviaryCutLength = int.Parse(fileContentBreviaryCutLengthText); } catch { - MessageCore.ShowWarning("索引更新任务间隔时间错误"); + MessageCore.ShowWarning("文件内容摘要切割长度错误"); return; } - if (indexUpdateTaskInterval < 5 || indexUpdateTaskInterval > 30) + if (fileContentBreviaryCutLength < 30 || fileContentBreviaryCutLength > 120) { - MessageCore.ShowWarning("建议设置在5 - 30分钟范围内"); + MessageCore.ShowWarning("文件内容摘要切割长度:建议设置在30 - 120范围内"); return; } - AppConst.INDEX_UPDATE_TASK_INTERVAL = indexUpdateTaskInterval; + AppConst.FILE_CONTENT_BREVIARY_CUT_LENGTH = fileContentBreviaryCutLength; } - // 启用预览内容摘要 - bool enablePreviewSummary = (bool)this.EnablePreviewSummary.IsChecked; - - AppConst.CACHE_POOL_CAPACITY = cachePoolCapacity; - AppUtil.WriteValue("AppConfig", "CachePoolCapacity", AppConst.CACHE_POOL_CAPACITY + ""); - log.Debug("修改缓存池容量:" + AppConst.CACHE_POOL_CAPACITY); - - AppConst.MRESULT_LIST_PAGE_SIZE = ResultListPageSize; - AppUtil.WriteValue("AppConfig", "ResultListPageSize", AppConst.MRESULT_LIST_PAGE_SIZE + ""); - log.Debug("修改结果列表分页条数:" + AppConst.MRESULT_LIST_PAGE_SIZE); - - AppConst.FILE_READ_TIMEOUT = fileReadTimeout; - AppUtil.WriteValue("AppConfig", "FileReadTimeout", AppConst.FILE_READ_TIMEOUT + ""); - log.Debug("修改文件读取超时时间:" + AppConst.FILE_READ_TIMEOUT); + // -------- 刷新、保存 + // ---- 索引和文件 AppConst.ENABLE_INDEX_UPDATE_TASK = enableIndexUpdateTask; AppUtil.WriteValue("AppConfig", "EnableIndexUpdateTask", AppConst.ENABLE_INDEX_UPDATE_TASK + ""); log.Debug("修改使用索引更新任务:" + AppConst.ENABLE_INDEX_UPDATE_TASK); - - if (enableIndexUpdateTask) - { + if (AppConst.ENABLE_INDEX_UPDATE_TASK) + { AppUtil.WriteValue("AppConfig", "IndexUpdateTaskInterval", AppConst.INDEX_UPDATE_TASK_INTERVAL + ""); log.Debug("修改索引更新任务间隔时间:" + AppConst.INDEX_UPDATE_TASK_INTERVAL); } + AppConst.FILE_CONTENT_READ_TIMEOUT = fileContentReadTimeout; + AppUtil.WriteValue("AppConfig", "FileContentReadTimeout", AppConst.FILE_CONTENT_READ_TIMEOUT + ""); + log.Debug("修改文件读取超时时间:" + AppConst.FILE_CONTENT_READ_TIMEOUT); + + // ---- 列表和缓存 + AppConst.MRESULT_LIST_PAGE_SIZE = resultListPageSize; + AppUtil.WriteValue("AppConfig", "ResultListPageSize", AppConst.MRESULT_LIST_PAGE_SIZE + ""); + log.Debug("修改结果列表分页条数:" + AppConst.MRESULT_LIST_PAGE_SIZE); + AppConst.CACHE_POOL_CAPACITY = cachePoolCapacity; + AppUtil.WriteValue("AppConfig", "CachePoolCapacity", AppConst.CACHE_POOL_CAPACITY + ""); + log.Debug("修改缓存池容量:" + AppConst.CACHE_POOL_CAPACITY); + // ---- 内容预览 AppConst.ENABLE_PREVIEW_SUMMARY = enablePreviewSummary; AppUtil.WriteValue("AppConfig", "EnablePreviewSummary", AppConst.ENABLE_PREVIEW_SUMMARY + ""); + log.Debug("修改启用预览上下文摘要:" + AppConst.ENABLE_PREVIEW_SUMMARY); + if (AppConst.ENABLE_PREVIEW_SUMMARY) + { + AppUtil.WriteValue("AppConfig", "FileContentBreviaryCutLength", AppConst.FILE_CONTENT_BREVIARY_CUT_LENGTH + ""); + log.Debug("修改文件内容摘要切割长度:" + AppConst.FILE_CONTENT_BREVIARY_CUT_LENGTH); + } + + MessageCore.ShowSuccess("参数保存成功,部分参数需要重启软件才能生效。"); this.Close(); }