优化日志记录、资源管理及功能支持
- 引入 log4net 库,统一日志记录方式,提升可维护性。 - 优化异常处理,增加详细日志记录,增强代码健壮性。 - 调整资源文件引用,新增图标资源,删除无用资源。 - 优化文档事件处理逻辑,改进面板显示与隐藏逻辑。 - 增加对 WPS 环境的支持,动态调整功能行为。 - 禁用部分功能(如常识性检测、客服、升级和帮助)。 - 删除冗余代码,清理注释,统一代码风格。 - 更新程序集版本至 2.2.5,改进调试与生产环境配置。
This commit is contained in:
parent
5b519f48e1
commit
32e85c62c0
Binary file not shown.
@ -582,6 +582,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="favicon.ico" />
|
||||
<None Include="Resources\icon-update-new-wps.jpg" />
|
||||
<None Include="Resources\icon-update-new.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
|
@ -7,8 +7,8 @@
|
||||
<SupportUrlHistory />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<StartAction>Project</StartAction>
|
||||
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.18608\office6\wps.exe</StartProgram>
|
||||
<StartAction>Program</StartAction>
|
||||
<StartProgram>C:\Soft\Kingsoft\WPS Office\12.1.0.20784\office6\wps.exe</StartProgram>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<StartAction>Project</StartAction>
|
||||
|
@ -109,6 +109,10 @@ namespace AIProofread
|
||||
Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("show-history", null);
|
||||
}
|
||||
|
||||
public void HasNewVersion()
|
||||
{
|
||||
Globals.ThisAddIn.ribbon.ShowNewVersionIcon();
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查插件更新信息
|
||||
/// </summary>
|
||||
@ -315,6 +319,19 @@ namespace AIProofread
|
||||
{
|
||||
return Tools.GetAllText(Globals.ThisAddIn.Application.ActiveDocument);
|
||||
}
|
||||
public bool SaveDocument(int documentId)
|
||||
{
|
||||
var document = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument;
|
||||
try
|
||||
{
|
||||
document.Save();
|
||||
return true;
|
||||
}catch (Exception ex)
|
||||
{
|
||||
Logger.Error("保存文档失败", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Saved(int documentId)
|
||||
{
|
||||
@ -576,18 +593,15 @@ namespace AIProofread
|
||||
webViewDict.Add(name, webView);
|
||||
}
|
||||
|
||||
Logger.Error("初始化Main Pane Web环境 开始");
|
||||
Logger.Debug("初始化Main Pane Web环境 开始");
|
||||
// 禁用web安全,允许跨域 否则需要web编译为umd加载模式
|
||||
var ops = new CoreWebView2EnvironmentOptions("--disable-web-security");
|
||||
var env = await CoreWebView2Environment.CreateAsync(null, Config.WEB_DATA_PATH, ops);
|
||||
await webView.EnsureCoreWebView2Async(env);
|
||||
//webView.CoreWebView2.Settings.AreDevToolsEnabled = false;
|
||||
//webView.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = false;
|
||||
//webView.CoreWebView2.Settings.AreHostObjectsAllowed = true;
|
||||
// 添加 js与客户端代理
|
||||
|
||||
webView.CoreWebView2.AddHostObjectToScript("bridge", bridge);
|
||||
Logger.Error("初始化Main Pane Web环境 结束");
|
||||
Logger.Debug("初始化Main Pane Web环境 结束");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -864,6 +878,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("读取文件失败:" + ex.Message, ex);
|
||||
return BridgeResult.Error(-1, ex.Message);
|
||||
}
|
||||
}
|
||||
@ -901,7 +916,7 @@ namespace AIProofread
|
||||
}
|
||||
try
|
||||
{
|
||||
Logger.Info("SaveCache " + document.fileName + " used " + document.ProofreadCachePath);
|
||||
Logger.Debug("SaveCache " + document.fileName + " used " + document.ProofreadCachePath);
|
||||
|
||||
if (File.Exists(document.ProofreadCachePath))
|
||||
{
|
||||
@ -914,6 +929,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("保存缓存失败:" + ex.Message, ex);
|
||||
return BridgeResult.Error(-1, ex.Message);
|
||||
}
|
||||
}
|
||||
@ -938,6 +954,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("加载缓存失败:" + ex.Message, ex);
|
||||
return BridgeResult.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
@ -951,8 +968,9 @@ namespace AIProofread
|
||||
File.Delete(Globals.ThisAddIn.ActiveDocument.ProofreadCachePath);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("删除缓存失败:" + ex.Message, ex);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -976,6 +994,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("初始化缓存失败:" + ex.Message, ex);
|
||||
return BridgeResult.Error(ex);
|
||||
}
|
||||
}
|
||||
|
@ -19,19 +19,8 @@ namespace AIProofread
|
||||
/// <summary>
|
||||
/// 测试环境
|
||||
/// </summary>
|
||||
public const string TEST = "http://gm2-plugin.zverse.group/";
|
||||
/// <summary>
|
||||
/// 果麦预发布-灰度
|
||||
/// </summary>
|
||||
public const string PRE = "https://pre-gm-plugin.gachafun.com/";
|
||||
/// <summary>
|
||||
/// 果麦生产
|
||||
/// </summary>
|
||||
public const string PROD = "https://gm-plugin.gachafun.com/";
|
||||
/// <summary>
|
||||
/// 果麦金融
|
||||
/// </summary>
|
||||
public const string GM_FN = "https://gm-plugin-fn.gachafun.com/";
|
||||
public const string PROD = "http://aijdw1.goldmye.com/";
|
||||
public const string TEST = "http://tt-plugin.zverse.group/";
|
||||
}
|
||||
public class Config
|
||||
{
|
||||
@ -48,18 +37,19 @@ namespace AIProofread
|
||||
public static readonly string TextBackgroundColor = "#E9DABB"; // e9dabb D6AA69
|
||||
public static string DeviceId = "";
|
||||
|
||||
#if DEBUG
|
||||
|
||||
#if DEBUG
|
||||
/// <summary>
|
||||
/// 网页访问地址
|
||||
/// </summary>
|
||||
public static string WEB_PATH = AppServer.DEV; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group
|
||||
public static string WEB_PATH = AppServer.PROD; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group
|
||||
public static bool RUN_IN_DEBUG = true;
|
||||
public static AppEnvironment APP_ENV = AppEnvironment.Dev;
|
||||
#else
|
||||
public static string WEB_PATH = AppServer.DEV; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com
|
||||
public static bool RUN_IN_DEBUG = true;
|
||||
public static AppEnvironment APP_ENV = AppEnvironment.Dev;
|
||||
#endif
|
||||
public static AppEnvironment APP_ENV = AppEnvironment.Prod;
|
||||
#else
|
||||
public static string WEB_PATH = AppServer.PROD; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com
|
||||
public static bool RUN_IN_DEBUG = false;
|
||||
public static AppEnvironment APP_ENV = AppEnvironment.Prod;
|
||||
#endif
|
||||
|
||||
public static readonly string APP_DATA_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ai_proofread";
|
||||
public static readonly string APP_LOG_PATH = APP_DATA_PATH + "\\logs\\";
|
||||
|
@ -39,9 +39,9 @@ namespace AIProofread.Controls
|
||||
</style>
|
||||
</head>
|
||||
<body oncontextmenu='return false;'>
|
||||
<h1>页面加载失败</h1>
|
||||
<p>请检查您的网络连接或稍后再试。</p>
|
||||
<a href="+ "\"javascript:window.chrome.webview.postMessage('reload');\"" + @">重新加载</a>
|
||||
<h1>加载组件失败</h1>
|
||||
<p>请检查您的网络连接并重启软件。</p>
|
||||
<a href=" + "\"javascript:window.chrome.webview.postMessage('reload');\"" + @">重新加载</a>
|
||||
</body>
|
||||
</html>";
|
||||
(sender as WebView2).CoreWebView2.NavigateToString(errorPageHtml);
|
||||
@ -57,7 +57,7 @@ namespace AIProofread.Controls
|
||||
if (ex.TryGetWebMessageAsString() == "reload")
|
||||
{
|
||||
isShowingErrorPage = false;
|
||||
//web.Source = new Uri(Config.WebPath("correct"));
|
||||
web.Source = new Uri(Config.WebPath("correct"));
|
||||
}
|
||||
};
|
||||
this.web.Source = new Uri(Config.WebPath("correct" ));
|
||||
|
@ -37,7 +37,7 @@ namespace AIProofread
|
||||
roller.Layout = layout;
|
||||
roller.ActivateOptions();
|
||||
hierarchy.Root.AddAppender(roller);
|
||||
hierarchy.Root.Level = log4net.Core.Level.Debug;
|
||||
hierarchy.Root.Level = log4net.Core.Level.Info;
|
||||
hierarchy.Configured = true;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ using System.Windows.Forms;
|
||||
using AIProofread.Controls;
|
||||
using AIProofread.core;
|
||||
using AIProofread.Util;
|
||||
using DocumentFormat.OpenXml.Office2013.WebExtentionPane;
|
||||
using log4net;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using Newtonsoft.Json;
|
||||
@ -104,11 +105,11 @@ namespace AIProofread.Model
|
||||
/// </summary>
|
||||
public void ShowPane()
|
||||
{
|
||||
if(null == TaskPane)
|
||||
if (null == TaskPane)
|
||||
{
|
||||
CreateTaskPane();
|
||||
}
|
||||
Logger.Debug("TaskPane.Visible {"+TaskPane==null?"null":(TaskPane.Visible?"true":"false")+" => true");
|
||||
Logger.Debug("TaskPane.Visible {" + TaskPane == null ? "null" : (TaskPane.Visible ? "true" : "false") + " => true");
|
||||
TaskPane.Visible = PaneVisible = true;
|
||||
}
|
||||
|
||||
@ -117,12 +118,13 @@ namespace AIProofread.Model
|
||||
/// </summary>
|
||||
public void HidePane()
|
||||
{
|
||||
if (!PaneVisible) return;
|
||||
//if (!PaneVisible) return;
|
||||
ShowDocumentStatus("HidePane");
|
||||
Logger.Debug($"TaskPane.Visible {TaskPane.Visible} => false");
|
||||
TaskPane.Visible = PaneVisible = false;
|
||||
}
|
||||
|
||||
|
||||
public void RunInMainThread(Action action)
|
||||
{
|
||||
Logger.Debug($"RunInMainThread {action}");
|
||||
@ -184,54 +186,59 @@ namespace AIProofread.Model
|
||||
/// </summary>
|
||||
public void Active()
|
||||
{
|
||||
ShowDocumentStatus("Active");
|
||||
IsActive = true;
|
||||
if (Config.IS_WPS && null != TaskPane && PaneVisible)
|
||||
try
|
||||
{
|
||||
TaskPane.Visible = true;
|
||||
Logger.Debug("激活 for " + CurrentDocument.FullName + " 没有 visible is " + PaneVisible);
|
||||
ShowDocumentStatus("Active");
|
||||
IsActive = true;
|
||||
if (Config.IS_WPS && null != TaskPane)
|
||||
{
|
||||
TaskPane.Visible = PaneVisible;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error("Active Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Deactive()
|
||||
{
|
||||
ShowDocumentStatus("Deactive");
|
||||
IsActive = false;
|
||||
if (Config.IS_WPS)
|
||||
try
|
||||
{
|
||||
if (PaneVisible)
|
||||
{
|
||||
// 异步等待一段时间 重新设置为true,防止面板关闭时,触发事件
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
PaneVisible = true;
|
||||
});
|
||||
}
|
||||
if (null != TaskPane && PaneVisible)
|
||||
ShowDocumentStatus("Deactive");
|
||||
IsActive = false;
|
||||
if (Config.IS_WPS && null != TaskPane)
|
||||
{
|
||||
PaneVisible = TaskPane.Visible;
|
||||
TaskPane.Visible = false;
|
||||
Logger.Debug("取消 for " + CurrentDocument.FullName + " current visible " + PaneVisible);
|
||||
}
|
||||
}catch (Exception e)
|
||||
{
|
||||
Logger.Error("Deactive Error", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 判断TaskPane是否已经释放
|
||||
if (null == TaskPane) return;
|
||||
if (TaskPane.Control.IsDisposed) return;
|
||||
|
||||
ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control;
|
||||
control.ResetWeb();
|
||||
|
||||
HidePane();
|
||||
TaskPane?.Dispose();
|
||||
// 释放com
|
||||
try
|
||||
{
|
||||
Marshal.ReleaseComObject(CurrentDocument);
|
||||
}
|
||||
catch (Exception) { }
|
||||
if(TaskPane.Control.IsDisposed) return;
|
||||
ProofreadMainControl control = (ProofreadMainControl)TaskPane.Control;
|
||||
control.ResetWeb();
|
||||
|
||||
HidePane();
|
||||
TaskPane?.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -277,7 +284,7 @@ namespace AIProofread.Model
|
||||
MinWidth = MIN_WIDTH * control.LabelWidth() / 42;
|
||||
}
|
||||
// 创建pane
|
||||
TaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(control, " ");
|
||||
TaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(control, Config.RUN_IN_DEBUG ? CurrentDocument.Name : " ");
|
||||
// 默认隐藏
|
||||
TaskPane.Visible = false;
|
||||
// 设置宽度
|
||||
@ -289,7 +296,9 @@ namespace AIProofread.Model
|
||||
TaskPane.VisibleChanged += TaskPane_VisibleChanged;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查按钮状态
|
||||
/// </summary>
|
||||
public void CheckBtnStatus()
|
||||
{
|
||||
//
|
||||
@ -302,8 +311,15 @@ namespace AIProofread.Model
|
||||
|
||||
private void TaskPane_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
// 如果已经隐藏 则记录隐藏用于(WPS)多面板的切换的处理
|
||||
PaneVisible = TaskPane.Visible;
|
||||
if (Config.IS_WPS)
|
||||
{
|
||||
if(CurrentDocument == Globals.ThisAddIn.ActiveDocument)
|
||||
{
|
||||
Logger.Debug($"VisibleChanged ${CurrentDocument.Name} is {TaskPane.Visible}");
|
||||
// 如果已经隐藏 则记录隐藏用于(WPS)多面板的切换的处理
|
||||
PaneVisible = TaskPane.Visible;
|
||||
}
|
||||
}
|
||||
CheckBtnStatus();
|
||||
//Globals.ThisAddIn.ribbon.BtnShowPanel.Enabled = !TaskPane.Visible && Proofread;
|
||||
}
|
||||
@ -672,7 +688,7 @@ namespace AIProofread.Model
|
||||
List<InsertMarkData> insertMarks = new List<InsertMarkData>();
|
||||
foreach (var correct in list)
|
||||
{
|
||||
if(LogHelper.LoggerForm != null)
|
||||
if (LogHelper.LoggerForm != null)
|
||||
{
|
||||
LogHelper.Log(string.Format("correct content:{0}", correct.Insert));
|
||||
}
|
||||
@ -688,7 +704,7 @@ namespace AIProofread.Model
|
||||
int _prev = prevOffset;
|
||||
bool isDisabled = false;
|
||||
// 判断查找内容是否在原始数据中,否则直跳过
|
||||
if(item.Tag != "i" && item.Origin.Trim().Length > 0)
|
||||
if (item.Tag != "i" && item.Origin.Trim().Length > 0)
|
||||
{
|
||||
isDisabled = correct.Insert.IndexOf(item.Origin) == -1;
|
||||
}
|
||||
@ -787,7 +803,7 @@ namespace AIProofread.Model
|
||||
}
|
||||
|
||||
|
||||
public void InitProofreadCache(List<CorrectContext> list,Dictionary<int, ProofreadRangeInfo> itemInfoDic)
|
||||
public void InitProofreadCache(List<CorrectContext> list, Dictionary<int, ProofreadRangeInfo> itemInfoDic)
|
||||
{
|
||||
marks.Clear();
|
||||
|
||||
@ -800,7 +816,7 @@ namespace AIProofread.Model
|
||||
{
|
||||
var pi = new ProofreadItem(item, correct.Insert, mark, Id);
|
||||
// 是否存在样式信息
|
||||
if (itemInfoDic!= null && itemInfoDic.ContainsKey(item.Id))
|
||||
if (itemInfoDic != null && itemInfoDic.ContainsKey(item.Id))
|
||||
{
|
||||
// 获取样式信息并还原
|
||||
var info = itemInfoDic[item.Id];
|
||||
@ -890,6 +906,10 @@ namespace AIProofread.Model
|
||||
// 采纳
|
||||
marks[proofreadId].Process(status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Debug("不存在此校对项");
|
||||
}
|
||||
}
|
||||
|
||||
internal bool Saved()
|
||||
@ -914,7 +934,8 @@ namespace AIProofread.Model
|
||||
try
|
||||
{
|
||||
CurrentDocument.Save();
|
||||
}catch (Exception ex)
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Log(ex);
|
||||
}
|
||||
@ -1031,7 +1052,7 @@ namespace AIProofread.Model
|
||||
|
||||
public Dictionary<int, ProofreadRangeInfo> GetProofreadOriginData()
|
||||
{
|
||||
Dictionary<int,ProofreadRangeInfo> dic = new Dictionary<int, ProofreadRangeInfo>();
|
||||
Dictionary<int, ProofreadRangeInfo> dic = new Dictionary<int, ProofreadRangeInfo>();
|
||||
// 变量文档所有marks 记录mark对应range的背景、大小、颜色
|
||||
foreach (var item in marks)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ namespace AIProofread.Model
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
documentList.ForEach(doc =>{ doc.Dispose(); });
|
||||
documentList.ForEach(doc => { doc.Dispose(); });
|
||||
|
||||
documentList.Clear();
|
||||
}
|
||||
@ -118,9 +118,8 @@ namespace AIProofread.Model
|
||||
Logger.Error("Document not exists SetActiveDocument");
|
||||
return null;
|
||||
}
|
||||
if (ActiveDocument == document) return document;
|
||||
|
||||
if (Globals.ThisAddIn.IsWPS)
|
||||
if (ActiveDocument != null && ActiveDocument.CurrentDocument != originDocument)
|
||||
{
|
||||
// WPS 只有一个窗口 所以需要先关闭之前文档的面板
|
||||
ActiveDocument?.Deactive();
|
||||
@ -129,6 +128,7 @@ namespace AIProofread.Model
|
||||
ActiveDocument = document;
|
||||
//document.IsActive = true;
|
||||
document.Active();
|
||||
document.CheckBtnStatus();
|
||||
return document;
|
||||
}
|
||||
|
||||
@ -141,12 +141,18 @@ namespace AIProofread.Model
|
||||
{
|
||||
var document = Get(originDocument);
|
||||
|
||||
// 如果不存在,则添加
|
||||
if (document == null)
|
||||
try
|
||||
{
|
||||
Logger.Debug("Document not exists,InitDocument: " + originDocument.Name);
|
||||
document = new DocumentInfo(originDocument);
|
||||
Add(document);
|
||||
// 如果不存在,则添加
|
||||
if (document == null)
|
||||
{
|
||||
Logger.Debug("Document not exists,InitDocument: " + originDocument.Name);
|
||||
document = new DocumentInfo(originDocument);
|
||||
Add(document);
|
||||
}
|
||||
}catch(Exception ex)
|
||||
{
|
||||
Logger.Error("InitDocument error: " + ex.Message,ex);
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ using System.Security;
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("AI校对王")]
|
||||
[assembly: AssemblyDescription("AI校对王 2.2.4")]
|
||||
[assembly: AssemblyDescription("AI校对王 2.2.5")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("果麦文化传媒股份有限公司")]
|
||||
[assembly: AssemblyProduct("AI校对王 2.2.4")]
|
||||
[assembly: AssemblyProduct("AI校对王 2.2.5")]
|
||||
[assembly: AssemblyCopyright("Copyright © 果麦文化传媒股份有限公司 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
20
AIProofread/Properties/Resources.Designer.cs
generated
20
AIProofread/Properties/Resources.Designer.cs
generated
@ -380,6 +380,26 @@ namespace AIProofread.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap icon_update_new {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("icon-update-new", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap icon_update_new_wps {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("icon-update-new-wps", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||
/// </summary>
|
||||
|
@ -136,9 +136,6 @@
|
||||
<data name="icon-history" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-proofread" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-phone" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-phone.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
@ -160,6 +157,9 @@
|
||||
<data name="icon-update-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-update-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-manual" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-manual.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-setting" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-setting.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
@ -187,8 +187,11 @@
|
||||
<data name="icon-refresh-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-refresh-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-export" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="icon-clear" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-manual-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-manual-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="button_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\button_default.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
@ -202,14 +205,14 @@
|
||||
<data name="logo_no_text" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-ai-robot" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="logo_no_text_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="logo_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\logo_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-clear" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="icon-export" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-phone-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-phone-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
@ -217,8 +220,11 @@
|
||||
<data name="icon-history-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-history-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="logo_no_text_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="icon-panel" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-ai-robot" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-logout" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-logout.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
@ -226,13 +232,13 @@
|
||||
<data name="icon_close" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon_close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-panel" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="icon-proofread" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-manual" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-manual.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="icon-update-new" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-update-new.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="icon-manual-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-manual-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
<data name="icon-update-new-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\icon-update-new-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
AIProofread/Resources/icon-update-new-wps.jpg
Normal file
BIN
AIProofread/Resources/icon-update-new-wps.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
AIProofread/Resources/icon-update-new.png
Normal file
BIN
AIProofread/Resources/icon-update-new.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 843 B |
2
AIProofread/Ribbon1.Designer.cs
generated
2
AIProofread/Ribbon1.Designer.cs
generated
@ -255,7 +255,9 @@ namespace AIProofread
|
||||
this.btnLogin.Image = global::AIProofread.Properties.Resources.icon_user;
|
||||
this.btnLogin.Label = "用户登录\r\n";
|
||||
this.btnLogin.Name = "btnLogin";
|
||||
this.btnLogin.ScreenTip = "用户登录\r\n";
|
||||
this.btnLogin.ShowImage = true;
|
||||
this.btnLogin.SuperTip = "通过手机验证码或者密码登录账号";
|
||||
this.btnLogin.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnLogin_Click);
|
||||
//
|
||||
// btnLogout
|
||||
|
@ -178,6 +178,11 @@ namespace AIProofread
|
||||
//Globals.ThisAddIn.SendMessageToWeb("confirm-logout", null);
|
||||
}
|
||||
|
||||
public void ShowNewVersionIcon()
|
||||
{
|
||||
BtnUpdate.Image = Globals.ThisAddIn.IsWPS? Resources.icon_update_new_wps : Resources.icon_update_new;
|
||||
}
|
||||
|
||||
|
||||
private void btnOpenLexicon_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
|
@ -62,6 +62,9 @@ namespace AIProofread
|
||||
/// 智能常识检测对话框 = new FormCommonsenseDetection()
|
||||
/// </summary>
|
||||
public FormCommonsenseDetection formCommonsenseDetection;
|
||||
/// <summary>
|
||||
/// 是否为wps
|
||||
/// </summary>
|
||||
public bool IsWPS { get; set; }
|
||||
|
||||
public List<FormLogin> LoginFormList = new List<FormLogin>();
|
||||
@ -161,6 +164,11 @@ namespace AIProofread
|
||||
}
|
||||
}
|
||||
|
||||
private void Application_DocumentBeforePrint(Document Doc, ref bool Cancel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// 异步获取设备唯一标识
|
||||
public void InitDeviceId()
|
||||
{
|
||||
@ -176,7 +184,7 @@ namespace AIProofread
|
||||
if (!string.IsNullOrEmpty(deviceId))
|
||||
{
|
||||
Config.DeviceId = deviceId;
|
||||
Logger.Debug("设备唯一标识:" + deviceId);
|
||||
Logger.Info("设备唯一标识:" + deviceId);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -227,25 +235,25 @@ namespace AIProofread
|
||||
item.Dispose();
|
||||
});
|
||||
}
|
||||
catch (Exception ext)
|
||||
catch (Exception ex1)
|
||||
{
|
||||
Logger.Debug(ext);
|
||||
Logger.Error("移除已关闭文档->释放面板", ex1);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
documentList.Remove(item);
|
||||
}
|
||||
catch (Exception ext)
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Logger.Debug(ext);
|
||||
Logger.Error("移除已关闭文档",ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Debug(ex.Message, ex);
|
||||
Logger.Error("检测已关闭文档", ex);
|
||||
}
|
||||
//await System.Threading.Tasks.Task.Run(() =>
|
||||
// {
|
||||
@ -306,7 +314,6 @@ namespace AIProofread
|
||||
{
|
||||
Config.IS_WPS = true;
|
||||
IsWPS = true;
|
||||
|
||||
try
|
||||
{
|
||||
Globals.Ribbons.Ribbon1.InitWPS();
|
||||
@ -316,15 +323,16 @@ namespace AIProofread
|
||||
Logger.Error("Init WPS Error ", ex);
|
||||
}
|
||||
}
|
||||
string verTextFile = Config.APP_BASE_DIR + Path.GetFileName("app_version.txt");
|
||||
try
|
||||
{
|
||||
File.WriteAllText(verTextFile, Config.APP_VERSION);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("Write App Version Error ", ex);
|
||||
}
|
||||
//string verTextFile = Config.APP_BASE_DIR + Path.GetFileName("app_version.txt");
|
||||
//try
|
||||
//{
|
||||
// File.WriteAllText(verTextFile, Config.APP_VERSION);
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// Logger.Error("Write App Version Error ", ex);
|
||||
//}
|
||||
Logger.Info("init " + (Config.IS_WPS ? "WPS" : "WORD") + " end");
|
||||
}
|
||||
|
||||
private void InitAppByConfig()
|
||||
@ -368,21 +376,14 @@ namespace AIProofread
|
||||
{
|
||||
return;
|
||||
}
|
||||
var document = CurrentWordApplication.ActiveDocument;
|
||||
Logger.Debug("Application_DocumentChange -- " + document.Name + " 修订模式: is " + document.TrackRevisions);
|
||||
// 设置当前文档
|
||||
ActiveDocument = documentList.SetActiveDocument(document);
|
||||
if (ActiveDocument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ActiveDocument.CheckBtnStatus();
|
||||
var document = documentList.InitDocument(CurrentWordApplication.ActiveDocument);
|
||||
if(document == null) return;
|
||||
|
||||
CheckDocumentClosed(null, null);
|
||||
if (formCommonsenseDetection != null)
|
||||
{
|
||||
formCommonsenseDetection.SendMessageToWeb("document-change", null);
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
public void SetActiveDocument(Document doc)
|
||||
@ -408,9 +409,15 @@ namespace AIProofread
|
||||
private void Application_WindowActivate(Document activeDoc, Window Wn)
|
||||
{
|
||||
Logger.Debug("Application_WindowActivate -- " + activeDoc.Name);
|
||||
if (activeDoc != null && (ActiveDocument == null || activeDoc != ActiveDocument.CurrentDocument))
|
||||
if (activeDoc != null)
|
||||
{
|
||||
documentList.SetActiveDocument(activeDoc);
|
||||
Logger.Debug("DocumentChange -- " + activeDoc.Name
|
||||
+ " 修订模式: is " + activeDoc.TrackRevisions
|
||||
+ ActiveDocument?.CurrentDocument?.Name + "==》" + activeDoc.Name);
|
||||
|
||||
var document = documentList.SetActiveDocument(activeDoc);
|
||||
// 设置当前文档
|
||||
ActiveDocument = document;
|
||||
}
|
||||
//// 当前文档添加书签集合
|
||||
//if (!allMarks.ContainsKey(activeDoc))
|
||||
@ -443,18 +450,12 @@ namespace AIProofread
|
||||
/// <param name="Cancel"></param>
|
||||
private void Application_DocumentBeforeClose(Document currentDoc, ref bool Cancel)
|
||||
{
|
||||
Logger.Debug("will close " + currentDoc.Name);
|
||||
var doc = documentList.Get(currentDoc);
|
||||
if (doc != null)
|
||||
if (Config.IS_WPS && doc != null)
|
||||
{
|
||||
doc.HidePane();
|
||||
}
|
||||
//LogHelper.Log("DocumentBeforeClose", currentDoc.FullName);
|
||||
//if (allMarks.ContainsKey(currentDoc))
|
||||
//{
|
||||
// allMarks.Remove(currentDoc);
|
||||
//}
|
||||
|
||||
//DisposePanel(currentDoc);
|
||||
}
|
||||
|
||||
//public void ActiveCurrentDocumentMarks(Document document)
|
||||
@ -476,7 +477,7 @@ namespace AIProofread
|
||||
private void Application_DocumentOpen(Document doc)
|
||||
{
|
||||
//LogHelper.Log("DocumentOpen " + doc.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int GetMinWidth()
|
||||
@ -491,34 +492,69 @@ namespace AIProofread
|
||||
|
||||
private void Application_WindowSelectionChange(Selection s)
|
||||
{
|
||||
// 处理当前文档选区,用于判断是否显示常识性检测
|
||||
ribbon.ParseSelectionChange(s);
|
||||
if (ActiveDocument == null || !s.Active) return;
|
||||
// 当前选区是否存在书签
|
||||
if (s.Range.Start != s.Range.End || s.Bookmarks.Count == 0) return;
|
||||
var bookmarks = s.Bookmarks;
|
||||
// 获取当前选区书签的起始位置
|
||||
var currentPosition = s.Range.Start;
|
||||
|
||||
if (s.Bookmarks != null)
|
||||
// Logger.Info("当前选区书签数量: " + s.Bookmarks.Count);
|
||||
// 遍历书签 找到所需的书签
|
||||
foreach (Bookmark item in s.Bookmarks)
|
||||
{
|
||||
if (s.Range.Start == s.Range.End) // 说明是点击呀
|
||||
// 判断书签的选区不包含当前选中区域
|
||||
if (currentPosition < item.Range.Start || currentPosition > item.Range.End)
|
||||
{
|
||||
//var count = s.Bookmarks.Count;
|
||||
if (s.Bookmarks.Count >= 1) // 只有这一个
|
||||
{
|
||||
foreach (Bookmark item in s.Bookmarks)
|
||||
{
|
||||
int proofreadId = Config.GetBookmarkIdByName(item.Name);
|
||||
if (proofreadId > 0)
|
||||
{
|
||||
// 只选择第一个书签
|
||||
// TODO: 优化
|
||||
//Bridge.bridge.SelectMarkById(proofreadId, 0);
|
||||
ActiveDocument?.SelectMarkById(proofreadId, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
ReleaseComObject(item);
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.Debug("当前选区书签名称: " + item.Name + "范围:" + item.Range.Start + "," + item.Range.End);
|
||||
//Logger.Debug("当前选区书签内容: " + item.Range.Text);
|
||||
// 获取书签id
|
||||
int proofreadId = Config.GetBookmarkIdByName(item.Name);
|
||||
// 释放com对象
|
||||
ReleaseComObject(item);
|
||||
Logger.Debug("当前选区proofreadId: " + proofreadId);
|
||||
if (proofreadId > 0)
|
||||
{
|
||||
//var targetRange = item.Range;
|
||||
//// 选中
|
||||
//targetRange.Select();
|
||||
//Globals.ThisAddIn.Application.ActiveWindow.ScrollIntoView(targetRange);
|
||||
// 只选择第一个书签
|
||||
ActiveDocument?.SelectMarkById(proofreadId, true);
|
||||
ReleaseComObject(bookmarks);
|
||||
return;
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
ReleaseComObject(bookmarks);
|
||||
//Bridge.bridge.SelectMarkById(-1, 0);
|
||||
}
|
||||
|
||||
public int MyProperty { get; set; }
|
||||
// 释放COM对象
|
||||
private void ReleaseComObject(object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("ReleaseComObject Error", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
obj = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMessageToWeb(string msg, object data)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
/// <summary>
|
||||
/// 是否启用常识性检测
|
||||
/// </summary>
|
||||
public const bool ENABLE_COMMONSENSE_CHECK = true;
|
||||
public const bool ENABLE_COMMONSENSE_CHECK = false;
|
||||
/// <summary>
|
||||
/// 设置功能
|
||||
/// </summary>
|
||||
@ -34,9 +34,9 @@
|
||||
|
||||
public const bool ENABLE_SAVE_CACHE = true;
|
||||
public const bool ENABLE_LOAD_CACHE = true;
|
||||
public const bool ENABLE_CUSTOMER_SERVICE = true;
|
||||
public const bool ENABLE_UPGRADE = true;
|
||||
public const bool ENABLE_HELP = true;
|
||||
public const bool ENABLE_CUSTOMER_SERVICE = false;
|
||||
public const bool ENABLE_UPGRADE = false;
|
||||
public const bool ENABLE_HELP = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -343,7 +343,7 @@ namespace AIProofread.core
|
||||
};
|
||||
|
||||
var beforeText = it.Start == 0 ? null : originSentence.Substring(0, it.Start);
|
||||
var richTextLength = it.Origin.Length; // it.Tag == "i" ? 1 : it.Text.Length
|
||||
var richTextLength = it.Tag == "i" ? it.Text.Length:it.Origin.Length; // it.Tag == "i" ? 1 : it.Text.Length
|
||||
var richText = originSentence.Substring(it.Start, richTextLength);
|
||||
var afterText = it.Start >= originSentence.Length ? null : originSentence.Substring(it.Start + richTextLength);
|
||||
|
||||
|
@ -17,12 +17,14 @@ using AIProofread.Model;
|
||||
using NPOI.SS.Util;
|
||||
using NPOI.HSSF.Util;
|
||||
using AIProofread.core;
|
||||
using log4net;
|
||||
|
||||
namespace AIProofread
|
||||
{
|
||||
public class DocumentUtil
|
||||
{
|
||||
static int markId = 0;
|
||||
public static readonly ILog Logger = LogHelper.GetLogger(typeof(DocumentUtil));
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个书签
|
||||
@ -117,7 +119,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Log("remove mark", e);
|
||||
Logger.Error("remove mark" + e.Message, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,23 +144,6 @@ namespace AIProofread
|
||||
mark.Delete();
|
||||
}
|
||||
}
|
||||
//foreach (var mark in document.Bookmarks)
|
||||
//{
|
||||
// if (markId != null)
|
||||
// {
|
||||
// if (mark.Name == markId)
|
||||
// {
|
||||
// // 删除
|
||||
// mark.Delete();
|
||||
// mark.Range.Shading.BackgroundPatternColor = (WdColor)WdColorIndex.wdAuto;
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mark.Delete();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public static System.Collections.Generic.List<string> GetSectionText()
|
||||
@ -254,52 +239,11 @@ namespace AIProofread
|
||||
{ "search_end",range.End },
|
||||
{ "search_text",range.Text }
|
||||
};
|
||||
LogHelper.Log(JsonConvert.SerializeObject(msg1));
|
||||
//while (range.Find.Found)
|
||||
//{
|
||||
// var obj4 = range.Document;
|
||||
// MatchControl = range.Start;
|
||||
// MatchAlefHamza = range.End;
|
||||
// var range2 = obj4.Range(ref MatchControl, ref MatchAlefHamza);
|
||||
// num3 = range2.End;
|
||||
// if (range2.Text == findText)
|
||||
// {
|
||||
// return range2;
|
||||
// }
|
||||
// break;
|
||||
// //if (findIndex == num)
|
||||
// //{
|
||||
|
||||
// //}
|
||||
// //num++;
|
||||
// //range.Find.MatchByte = true;
|
||||
// //Find find2 = range.Find;
|
||||
// //MatchAlefHamza = missword;
|
||||
// //MatchControl = true;
|
||||
// //MatchDiacritics = Type.Missing;
|
||||
// //MatchKashida = Type.Missing;
|
||||
// //Replace = Type.Missing;
|
||||
// //ReplaceWith = Type.Missing;
|
||||
// //Format = Type.Missing;
|
||||
// //Wrap = Type.Missing;
|
||||
// //Forward = Type.Missing;
|
||||
// //MatchAllWordForms = Type.Missing;
|
||||
// //MatchSoundsLike = Type.Missing;
|
||||
// //MatchWildcards = Type.Missing;
|
||||
// //MatchWholeWord = Type.Missing;
|
||||
// //Start = Type.Missing;
|
||||
// //End = Type.Missing;
|
||||
// //// 再次重复查找
|
||||
// //find2.Execute(ref MatchAlefHamza, ref MatchControl, ref MatchDiacritics, ref MatchKashida, ref Replace, ref ReplaceWith, ref Format, ref Wrap, ref Forward, ref MatchAllWordForms, ref MatchSoundsLike, ref MatchWildcards, ref MatchWholeWord, ref Start, ref End);
|
||||
//}
|
||||
//if (num3 == 0)
|
||||
//{
|
||||
// return null;
|
||||
//}
|
||||
Logger.Debug(JsonConvert.SerializeObject(msg1));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Log(ex);
|
||||
Logger.Error(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -327,24 +271,9 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Log(ex);
|
||||
Logger.Error(ex);
|
||||
}
|
||||
return null;
|
||||
|
||||
//if(bookmark == null)
|
||||
//{
|
||||
// foreach (var m in marks)
|
||||
// {
|
||||
// var mark = m as Bookmark;
|
||||
// var name = mark.Name;
|
||||
// var tag = mark.Tag?.ToString();
|
||||
// if(tag == markName || name == markName)
|
||||
// {
|
||||
// return mark;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//return bookmark as Bookmark;
|
||||
}
|
||||
|
||||
public static Bookmark FindRangeAndCreateBookmark(CorrectItem correct, CorrectContext sentense, Microsoft.Office.Interop.Word.Document document, ref int prevOffset)
|
||||
@ -381,7 +310,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Log("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n");
|
||||
Logger.Error("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n");
|
||||
}
|
||||
return bookmark;
|
||||
}
|
||||
@ -404,6 +333,7 @@ namespace AIProofread
|
||||
}
|
||||
//int count = 0;
|
||||
var range = document.Range(offset + item.Start, offset + item.End + 1);
|
||||
#region 删除批注
|
||||
//while (true && count++ < 10)
|
||||
//{
|
||||
// //
|
||||
@ -428,6 +358,7 @@ namespace AIProofread
|
||||
// Logger.Log(dce);
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
// 比对原始内容与校对原文是否一致
|
||||
if (range.Text == item.Origin)
|
||||
{
|
||||
@ -446,11 +377,13 @@ namespace AIProofread
|
||||
{
|
||||
return range1;
|
||||
}
|
||||
return null;
|
||||
// 执行查找
|
||||
return FindTextInRange(sentence, item.Origin);
|
||||
//return FindTextInRange(sentence, item.Origin);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error("find by sentence error",e);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -521,7 +454,7 @@ namespace AIProofread
|
||||
if (prevOffset >= paraText.Length)
|
||||
{
|
||||
// 查找位置已经超过了整段长度了
|
||||
LogHelper.Log("prevOffset:" + prevOffset + " paraText.Length:" + paraText.Length);
|
||||
Logger.Debug("prevOffset:" + prevOffset + " paraText.Length:" + paraText.Length);
|
||||
return null;
|
||||
}
|
||||
// 执行查找
|
||||
@ -608,7 +541,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Log(e);
|
||||
Logger.Error("导出勘误表失败",e);
|
||||
Globals.ThisAddIn.ShowDialog("导出勘误表失败,请重试", null, null);
|
||||
}
|
||||
}
|
||||
@ -751,7 +684,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Log(e);
|
||||
Logger.Error(e);
|
||||
}
|
||||
|
||||
var oriCell = row.CreateCell(3);
|
||||
@ -862,7 +795,7 @@ namespace AIProofread
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Log(ex);
|
||||
Logger.Error(ex);
|
||||
}
|
||||
id++;
|
||||
}
|
||||
|
@ -153,6 +153,9 @@ namespace AIProofread
|
||||
|
||||
public static string GetReadDocumentFilePath(Microsoft.Office.Interop.Word.Document doc)
|
||||
{
|
||||
|
||||
// 保存文档确保内容是最新的
|
||||
doc.Save();
|
||||
//
|
||||
string docPath = doc.FullName;
|
||||
string ext = Path.GetExtension(docPath);
|
||||
|
Loading…
x
Reference in New Issue
Block a user