diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo index 0a8a246..30950c5 100644 Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ diff --git a/AIProofread/AIProofread.csproj b/AIProofread/AIProofread.csproj index d844da6..e1a1fbe 100644 --- a/AIProofread/AIProofread.csproj +++ b/AIProofread/AIProofread.csproj @@ -143,6 +143,9 @@ ..\packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll + + ..\packages\log4net.3.0.4\lib\net462\log4net.dll + ..\packages\MathNet.Numerics.Signed.5.0.0\lib\net461\MathNet.Numerics.dll @@ -198,6 +201,7 @@ + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll @@ -238,6 +242,7 @@ True True + @@ -396,7 +401,7 @@ - + diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs index 35f81c5..decccef 100644 --- a/AIProofread/Bridge.cs +++ b/AIProofread/Bridge.cs @@ -2,6 +2,7 @@ using AIProofread.core; using AIProofread.Model; using AIProofread.Util; +using log4net; using Microsoft.Office.Interop.Word; using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.WinForms; @@ -45,6 +46,7 @@ namespace AIProofread private static object missing = System.Reflection.Missing.Value; private static UpgradeData CurrentUpgrade = null; + public static readonly ILog Logger = LogHelper.GetLogger(typeof(Bridge)); public void ShowUpgradeView() { @@ -138,7 +140,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log(ex); + Logger.Error(ex); } } @@ -247,7 +249,7 @@ namespace AIProofread } catch (Exception e) { - Logger.Log(e); + Logger.Error("启动升级程序失败", e); if (showFail) { MessageBox.Show("启动升级程序失败,请重试"); @@ -271,7 +273,7 @@ namespace AIProofread public void ShowLog(string message) { - Logger.Log((Config.IS_WPS ? "WPS" : "WORD") + "-WEB", message); + Logger.Info((Config.IS_WPS ? "WPS" : "WORD") + "-WEB " + message); } public void ShowLoginForm(string action) @@ -425,13 +427,13 @@ namespace AIProofread } catch (POIXMLException ex) { - Logger.Log(ex); + Logger.Error("校对文档格式有误或内容异常", ex); data["code"] = 5; data["message"] = "文档格式有误或内容异常,请另存文档后再进行校对"; } catch (Exception ex) { - Logger.Log(ex); + Logger.Error("校对文档格式有误或内容异常", ex); throw ex; } //if (loadingDialog != null && !loadingDialog.IsDisposed) @@ -586,7 +588,9 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log(ex); + + Logger.Error("初始化web环境失败", ex); + LogHelper.Log(ex); } } @@ -752,7 +756,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log("Initial Content error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); + Logger.Error("Initial Content error:",ex); return "false"; } return "true"; @@ -843,7 +847,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log("导出勘误表失败:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); + Logger.Error("导出勘误表失败:" + ex.Message,ex); return BridgeResult.Error(-1, ex.Message); } } @@ -894,7 +898,7 @@ namespace AIProofread } try { - Logger.Log("SaveCache " + document.fileName + " used " + document.ProofreadCachePath); + Logger.Info("SaveCache " + document.fileName + " used " + document.ProofreadCachePath); if (File.Exists(document.ProofreadCachePath)) { @@ -924,7 +928,7 @@ namespace AIProofread { return BridgeResult.Error(1, "cache-not-exists"); } - Logger.Log("Load cache " + document.fileName + " used " + document.ProofreadCachePath); + Logger.Info("Load cache " + document.fileName + " used " + document.ProofreadCachePath); try { return BridgeResult.Success(File.ReadAllText(document.ProofreadCachePath)); diff --git a/AIProofread/Controls/BaseWinForm.cs b/AIProofread/Controls/BaseWinForm.cs index b85f357..e891c1e 100644 --- a/AIProofread/Controls/BaseWinForm.cs +++ b/AIProofread/Controls/BaseWinForm.cs @@ -1,4 +1,5 @@ -using Microsoft.Web.WebView2.Core; +using log4net; +using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.WinForms; using NPOI.SS.Util; using System; @@ -16,6 +17,7 @@ namespace AIProofread.Controls [ComVisible(true)] public class BaseWinForm : Form { + #region WIN32 API [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")] private static extern IntPtr CreateRoundRectRgn( int nLeftRect, // x-coordinate of upper-left corner @@ -51,6 +53,9 @@ namespace AIProofread.Controls private const int WM_NCHITTEST = 0x84; // variables for dragging the form private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; + #endregion + + private readonly ILog logger = LogHelper.GetLogger(typeof(BaseWinForm)); protected override CreateParams CreateParams { @@ -117,7 +122,7 @@ namespace AIProofread.Controls this.Height = height; } - protected async void InitWebView(WebView2 webView,String url,string name,Action callaback = null) + protected async void InitWebView(WebView2 webView, String url, string name, Action callaback = null) { //Bridge.InitWebEnvAsync(name, webView); try @@ -132,15 +137,16 @@ namespace AIProofread.Controls webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder); webView.CoreWebView2.AddHostObjectToScript("host", this); webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge); - if(callaback != null) + if (callaback != null) { callaback(); } webView.Source = new Uri(url); - }catch (Exception ex) + } + catch (Exception ex) { - Logger.Log("\ninit webview error:" + ex.Message + "\n" + ex.StackTrace); + logger.Error("\ninit webview error:" + ex.Message, ex); } } public void Download(string url) @@ -170,7 +176,7 @@ namespace AIProofread.Controls } catch (Exception ex) { - Logger.Log("\nDownload error:" + ex.Message + "\n" + ex.StackTrace); + logger.Error("\nDownload error:" + ex.Message, ex); } } } diff --git a/AIProofread/Controls/FormLogger.cs b/AIProofread/Controls/FormLogger.cs index 094fba8..f9f6611 100644 --- a/AIProofread/Controls/FormLogger.cs +++ b/AIProofread/Controls/FormLogger.cs @@ -96,7 +96,7 @@ namespace AIProofread.Controls private void FormLogger_FormClosed(object sender, FormClosedEventArgs e) { - Logger.LoggerForm = null; + LogHelper.LoggerForm = null; } private void TsmiClear_Click(object sender, EventArgs e) diff --git a/AIProofread/LogHelper.cs b/AIProofread/LogHelper.cs new file mode 100644 index 0000000..22be393 --- /dev/null +++ b/AIProofread/LogHelper.cs @@ -0,0 +1,103 @@ +using AIProofread.Controls; +using log4net.Config; +using log4net; +using System; +using System.IO; +using log4net.Appender; +using log4net.Layout; +using log4net.Repository.Hierarchy; + +namespace AIProofread +{ + public class LogHelper + { + public static FormLogger LoggerForm; + + //private static readonly string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + public static ILog Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + static LogHelper() + { + //log4net.GlobalContext.Properties["APP_DATA"] = Config.APP_LOG_PATH; + //XmlConfigurator.Configure(); + //Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); + PatternLayout layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline"); + layout.ActivateOptions(); + //string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + //string logFilePath = Path.Combine(appDataPath, "YourAppName", "logs"); + + RollingFileAppender roller = new RollingFileAppender(); + roller.File = Config.APP_LOG_PATH; + roller.AppendToFile = true; + roller.RollingStyle = RollingFileAppender.RollingMode.Date; + roller.DatePattern = "yyyy-MM-dd'.txt'"; + roller.StaticLogFileName = false; + roller.Layout = layout; + roller.ActivateOptions(); + hierarchy.Root.AddAppender(roller); + hierarchy.Root.Level = log4net.Core.Level.Debug; + hierarchy.Configured = true; + } + + /// + /// + /// + /// + public static void Log(string tag, string message) + { + string time = DateTime.Now.ToString("HH:mm:ss"); + + // 如果日志窗口已经打开,则显示日志 + if (LoggerForm != null && !LoggerForm.IsDisposed && LoggerForm.Visible) + { + LoggerForm.Log(time, tag, message); + } + if (!Directory.Exists(Config.APP_LOG_PATH)) + { + Directory.CreateDirectory(Config.APP_LOG_PATH); + } + Logger.Debug($"[{tag}] {message}"); + //try + //{ + // string path = Config.APP_LOG_PATH + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; + // StreamWriter streamWriter = File.AppendText(path); + // streamWriter.WriteLine("***************************[" + tag + "]***************************"); + // streamWriter.WriteLine("消息:" + message); + // streamWriter.WriteLine("时间:" + time); + // streamWriter.WriteLine(); + // streamWriter.Flush(); + // streamWriter.Close(); + // streamWriter.Dispose(); + //} + //catch (Exception) { } + } + public static void Log(string msg) + { + Log((Config.IS_WPS ? "WPS" : "WORD"), msg); + } + public static void Log(Exception e) + { + Logger.Error(Config.IS_WPS ? "WPS" : "WORD" + e.ToString(), e); + //Log(e.Message + "\n" + e.StackTrace); + } + public static void Log(string tag, Exception e) + { + Logger.Error(tag, e); + } + + public static void LogToWeb(string msg) + { + if (Config.RUN_IN_DEBUG) + { + Globals.ThisAddIn.SendMessageToWeb("DEBUG-LOG", msg); + } + } + + internal static ILog GetLogger(Type type) + { + return LogManager.GetLogger(type); + } + } +} diff --git a/AIProofread/Logger.cs b/AIProofread/Logger.cs deleted file mode 100644 index 3ee9048..0000000 --- a/AIProofread/Logger.cs +++ /dev/null @@ -1,66 +0,0 @@ -using AIProofread.Controls; -using System; -using System.Collections.Generic; -using System.IO; -using System.Windows.Interop; - -namespace AIProofread -{ - public class Logger - { - public static FormLogger LoggerForm; - //private static readonly string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - - /// - /// - /// - /// - public static void Log(string tag,string message) - { - string time = DateTime.Now.ToString("HH:mm:ss"); - - // 如果日志窗口已经打开,则显示日志 - if (LoggerForm != null && !LoggerForm.IsDisposed && LoggerForm.Visible) - { - LoggerForm.Log(time, tag, message); - } - string path = Config.APP_LOG_PATH + DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; - if (!Directory.Exists(Config.APP_LOG_PATH)) - { - Directory.CreateDirectory(Config.APP_LOG_PATH); - } - try - { - StreamWriter streamWriter = File.AppendText(path); - streamWriter.WriteLine("***************************[" + tag + "]***************************"); - streamWriter.WriteLine("消息:" + message); - streamWriter.WriteLine("时间:" + time); - streamWriter.WriteLine(); - streamWriter.Flush(); - streamWriter.Close(); - streamWriter.Dispose(); - } - catch (Exception) { } - } - public static void Log(string msg) - { - Log((Config.IS_WPS ? "WPS" : "WORD"), msg); - } - public static void Log(Exception e) - { - Log(e.Message + "\n" + e.StackTrace); - } - public static void Log(string tag, Exception e) - { - Log(tag,e.Message + "\n" + e.StackTrace); - } - - public static void LogToWeb(string msg) - { - if (Config.RUN_IN_DEBUG) - { - Globals.ThisAddIn.SendMessageToWeb("DEBUG-LOG", msg); - } - } - } -} diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs index 71fa364..23a59cd 100644 --- a/AIProofread/Model/DocumentInfo.cs +++ b/AIProofread/Model/DocumentInfo.cs @@ -227,7 +227,7 @@ namespace AIProofread.Model } catch (Exception e) { - Logger.Log("Error", e); + LogHelper.Log("Error", e); } } @@ -539,7 +539,7 @@ namespace AIProofread.Model } catch (Exception ex) { - Logger.Log("GlobalCallback", "call web global function error \n" + ex.Message + "\n" + callbackId + result); + LogHelper.Log("GlobalCallback", "call web global function error \n" + ex.Message + "\n" + callbackId + result); } } public void SendMessageToWeb(string msg, object data) @@ -556,7 +556,7 @@ namespace AIProofread.Model } catch (Exception ex) { - Logger.Log("SendMessage", "send message to web error \n" + ex.Message + "\n" + msg + data.ToString()); + LogHelper.Log("SendMessage", "send message to web error \n" + ex.Message + "\n" + msg + data.ToString()); } } @@ -580,7 +580,7 @@ namespace AIProofread.Model } catch (Exception ex) { - Logger.Log("ClearAllProofreadMark", ex); + LogHelper.Log("ClearAllProofreadMark", ex); } // 清空marks marks.Clear(); @@ -658,9 +658,9 @@ namespace AIProofread.Model List insertMarks = new List(); foreach (var correct in list) { - if(Logger.LoggerForm != null) + if(LogHelper.LoggerForm != null) { - Logger.Log(string.Format("correct content:{0}", correct.Insert)); + LogHelper.Log(string.Format("correct content:{0}", correct.Insert)); } int currentOffset = correct.SentenceOffset; if (correct.CorrectItems != null && correct.CorrectItems.Count > 0) @@ -707,7 +707,7 @@ namespace AIProofread.Model } catch (Exception e) { - Logger.Log(string.Format("mark color error {0}", e.Message)); + LogHelper.Log(string.Format("mark color error {0}", e.Message)); } } else @@ -720,7 +720,7 @@ namespace AIProofread.Model { "new_text",correct.NewText }, { "paragraph_num",correct.ParagraphNumber }, }; - Logger.Log(JsonConvert.SerializeObject(msg)); + LogHelper.Log(JsonConvert.SerializeObject(msg)); } } } @@ -796,7 +796,7 @@ namespace AIProofread.Model pi.originBackgroundColor = info.Background; pi.originSize = info.Size; } - catch (Exception ex) { Logger.Log(ex); } + catch (Exception ex) { LogHelper.Log(ex); } } marks.Add(item.Id, pi); } @@ -902,7 +902,7 @@ namespace AIProofread.Model CurrentDocument.Save(); }catch (Exception ex) { - Logger.Log(ex); + LogHelper.Log(ex); } } public void FocusToPanel() @@ -924,7 +924,7 @@ namespace AIProofread.Model } catch (Exception ex) { - Logger.Log(ex); + LogHelper.Log(ex); } } @@ -1037,7 +1037,7 @@ namespace AIProofread.Model internal void CheckPanel() { - Logger.Log(CurrentDocument.FullName + $" TaskPane visible {PaneVisible} has " + (TaskPane == null ? "null" : "exists")); + LogHelper.Log(CurrentDocument.FullName + $" TaskPane visible {PaneVisible} has " + (TaskPane == null ? "null" : "exists")); if (TaskPane == null) CreateTaskPane(); } } diff --git a/AIProofread/Model/ExportDataItem.cs b/AIProofread/Model/ExportDataItem.cs index 3ebbcac..e380af3 100644 --- a/AIProofread/Model/ExportDataItem.cs +++ b/AIProofread/Model/ExportDataItem.cs @@ -28,7 +28,8 @@ namespace AIProofread.Model { var sentence = item.OriginSentence; var isInsert = item.content.Tag == "i"; - if (sentence.Length <= MAX_WORD_LENGTH && !isInsert) + var limitLength = Math.Max(item.content.Origin.Length, MAX_WORD_LENGTH); + if (sentence.Length <= limitLength && !isInsert) { return sentence; } @@ -37,18 +38,18 @@ namespace AIProofread.Model Debug.WriteLine("GetReadDocumentFilePath Start ==>", DateTime.Now.ToLongTimeString()); } // 截取中间位置 - if(sentence.Length > MAX_WORD_LENGTH) + if(sentence.Length > limitLength) { try { - var middlePosition = MAX_WORD_LENGTH / 2; + var middlePosition = limitLength / 2; var cutStart = item.content.Start - middlePosition; // 越界了 if (cutStart < 0) { cutStart = 0; } - var originText = sentence.Substring(cutStart, Math.Min(sentence.Length - cutStart, MAX_WORD_LENGTH)); + var originText = sentence.Substring(cutStart, Math.Min(sentence.Length - cutStart, limitLength)); if (!isInsert) { item.content.Start = item.content.Start - cutStart; @@ -58,11 +59,11 @@ namespace AIProofread.Model } catch (Exception ex) { - Logger.Log(ex); + LogHelper.Log(ex); } } var sb = new StringBuilder(); - if (sentence.Length <= MAX_WORD_LENGTH && isInsert) + if (sentence.Length <= limitLength && isInsert) { var before = item.content.Start == 0 ? string.Empty: sentence.Substring(0, item.content.Start); var after = item.content.Start >= sentence.Length ? string.Empty : sentence.Substring(item.content.Start); diff --git a/AIProofread/ProofreadItem.cs b/AIProofread/ProofreadItem.cs index 2d8f52e..e742c11 100644 --- a/AIProofread/ProofreadItem.cs +++ b/AIProofread/ProofreadItem.cs @@ -96,7 +96,7 @@ namespace UtilLib } catch (Exception e) { - Logger.Log(e); + LogHelper.Log(e); } } @@ -113,7 +113,7 @@ namespace UtilLib } catch (Exception e) { - Logger.Log(e); + LogHelper.Log(e); } } @@ -131,7 +131,7 @@ namespace UtilLib } catch (Exception e) { - Logger.Log(e); + LogHelper.Log(e); } } private void PrepareCommentProcess(Bookmark mark) @@ -148,13 +148,13 @@ namespace UtilLib // 判断当前书签选区内容是否有评论 if (comments != null && comments.Count > 0) { - Logger.Log("有批注"); + LogHelper.Log("有批注"); foreach (Microsoft.Office.Interop.Word.Comment item in comments) { // 判断当前评论和书签选区是否一致 if (item.Scope.Start == range.Start && item.Scope.End == range.End) { - Logger.Log("删除批注:" + item.Range.Text); + LogHelper.Log("删除批注:" + item.Range.Text); // 删除评论 item.Delete(); } @@ -224,7 +224,7 @@ namespace UtilLib if (rng.Text?.IndexOf("%") != -1) { - Logger.Log($"处理百分号问题:有批注"); + LogHelper.Log($"处理百分号问题:有批注"); if (rng.Comments != null && rng.Comments.Count > 0) { for (var i = 1; i < rng.Comments.Count; i++) diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs index e27ed56..8043682 100644 --- a/AIProofread/Ribbon1.cs +++ b/AIProofread/Ribbon1.cs @@ -124,7 +124,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log(this.Name, ex); + LogHelper.Log(this.Name, ex); } } Globals.ThisAddIn.LoginFormList.Clear(); @@ -459,7 +459,7 @@ namespace AIProofread } catch (Exception exception) { - Logger.Log(exception); + LogHelper.Log(exception); } return result; } @@ -483,12 +483,12 @@ namespace AIProofread private void BtnOpenLogger_Click(object sender, RibbonControlEventArgs e) { // 判断日志窗口是否已经存在或者打开 - if (Logger.LoggerForm == null || Logger.LoggerForm.IsDisposed) + if (LogHelper.LoggerForm == null || LogHelper.LoggerForm.IsDisposed) { // 创建日志窗口 - Logger.LoggerForm = new FormLogger(); + LogHelper.LoggerForm = new FormLogger(); } - Logger.LoggerForm.Show(); + LogHelper.LoggerForm.Show(); } private int GetRangeParagraphNumber(Range range) diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs index f5ba264..0a6b9dc 100644 --- a/AIProofread/ThisAddIn.cs +++ b/AIProofread/ThisAddIn.cs @@ -8,8 +8,7 @@ using AIProofread.Controls; using UtilLib; using AIProofread.Model; using System.Collections.Generic; -using Excel = Microsoft.Office.Interop.Excel; -using System.Runtime.InteropServices; +using log4net; namespace AIProofread @@ -17,7 +16,8 @@ namespace AIProofread public partial class ThisAddIn { - + // LogManager.GetLogger(typeof(ThisAddIn)) + public ILog Logger = LogHelper.GetLogger(typeof(ThisAddIn)); public static SynchronizationContext FmainThreadContext; public string AddinName = " "; @@ -92,12 +92,12 @@ namespace AIProofread private void ProcessApplicationException(object sender, UnhandledExceptionEventArgs e) { - Logger.Log("UnhandledException", e.ExceptionObject as Exception); + Logger.Error("UnhandledException", e.ExceptionObject as Exception); } private void ProcessApplicationFormException(object sender, System.Threading.ThreadExceptionEventArgs e) { - Logger.Log("ProcessApplicationFormException", e.Exception); + Logger.Error("ProcessApplicationFormException", e.Exception); } private void ThisAddIn_Startup(object sender, System.EventArgs e) @@ -109,7 +109,7 @@ namespace AIProofread //formCommonsenseDetection.ShowInTaskbar = false; //formCommonsenseDetection.Show(); - Logger.Log("ThisAddIn_Startup IS_WPS --> " + IsWPS); + Logger.Debug("ThisAddIn_Startup Platform --> " + (IsWPS?"WPS":"WORD")); // 捕获全局异常 AppDomain.CurrentDomain.UnhandledException += ProcessApplicationException; System.Windows.Forms.Application.ThreadException += ProcessApplicationFormException; @@ -137,7 +137,7 @@ namespace AIProofread } catch (Exception ex1) { - Logger.Log("Startup Error" + ex1.ToString()); + Logger.Error("Startup Error",ex1); } } @@ -156,12 +156,12 @@ namespace AIProofread if (!string.IsNullOrEmpty(deviceId)) { Config.DeviceId = deviceId; - Logger.Log("设备唯一标识:" + deviceId); + Logger.Debug("设备唯一标识:" + deviceId); } } catch (Exception ex) { - Logger.Log("InitDeviceId Error:" + ex.ToString()); + Logger.Error("InitDeviceId Error:",ex); } }); } @@ -193,7 +193,7 @@ namespace AIProofread } if (!existsList.Contains(currentName)) { - Logger.Log("检测到文档关闭,已移除:" + currentName); + Logger.Debug("检测到文档关闭,已移除:" + currentName); try { item.RunInMainThread(() => @@ -203,7 +203,7 @@ namespace AIProofread } catch (Exception ext) { - Logger.Log(ext); + Logger.Debug(ext); } try @@ -212,14 +212,14 @@ namespace AIProofread } catch (Exception ext) { - Logger.Log(ext); + Logger.Debug(ext); } } } } catch (Exception ex) { - Logger.Log(ex); + Logger.Debug(ex.Message,ex); } //await System.Threading.Tasks.Task.Run(() => // { @@ -244,14 +244,14 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log("检测升级信息异常: " + ex.ToString()); + Logger.Error("检测升级信息异常: ",ex); } }); } private void Application_DocumentBeforeSave(Document originDocument, ref bool SaveAsUI, ref bool Cancel) { - Logger.Log("DocumentSave", originDocument.Name + "\r\n"); + //LogHelper.Log("DocumentSave", originDocument.Name + "\r\n"); if (CurrentWordApplication.Documents.Count == 0) { return; @@ -286,7 +286,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log("Init WPS Error " + ex.Message); + Logger.Error("Init WPS Error ",ex); } } string verTextFile = Config.APP_BASE_DIR + Path.GetFileName("app_version.txt"); @@ -296,7 +296,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log("Write App Version Error " + ex.Message); + Logger.Error("Write App Version Error ", ex); } } @@ -307,7 +307,7 @@ namespace AIProofread if (File.Exists(Config.CONFIG_FILE)) { string content = File.ReadAllText(Config.CONFIG_FILE); - Logger.Log("INIT", "Found app.json " + content); + //LogHelper.Log("INIT", "Found app.json " + content); if (content == null || content.Length == 0) return; AppConfig config = JsonConvert.DeserializeObject(content); @@ -348,7 +348,7 @@ namespace AIProofread if (formCommonsenseDetection != null) { formCommonsenseDetection.SendMessageToWeb("document-change", null); } - Logger.Log("Application_DocumentChange -- " + ActiveDocument.fileName + " track is " + ActiveDocument.CurrentDocument.TrackRevisions); + //LogHelper.Log("Application_DocumentChange -- " + ActiveDocument.fileName + " track is " + ActiveDocument.CurrentDocument.TrackRevisions); } public void SetActiveDocument(Document doc) @@ -373,8 +373,11 @@ namespace AIProofread /// private void Application_WindowActivate(Document activeDoc, Window Wn) { - ActiveDocument = documentList.SetActiveDocument(activeDoc); - Logger.Log("Application_WindowActivate -- " + ActiveDocument.fileName); + if(activeDoc != null && (ActiveDocument == null || activeDoc != ActiveDocument.CurrentDocument)) + { + ActiveDocument = documentList.SetActiveDocument(activeDoc); + Logger.Info("Application_WindowActivate -- " + ActiveDocument.fileName); + } //// 当前文档添加书签集合 //if (!allMarks.ContainsKey(activeDoc)) //{ @@ -411,7 +414,7 @@ namespace AIProofread { doc.HidePane(); } - Logger.Log("DocumentBeforeClose", currentDoc.FullName); + //LogHelper.Log("DocumentBeforeClose", currentDoc.FullName); //if (allMarks.ContainsKey(currentDoc)) //{ // allMarks.Remove(currentDoc); @@ -433,12 +436,12 @@ namespace AIProofread private void Application_NewDocument(Document doc) { - Logger.Log("NewDocument" + doc.Name); + //LogHelper.Log("NewDocument" + doc.Name); } private void Application_DocumentOpen(Document doc) { - Logger.Log("DocumentOpen " + doc.Name); + //LogHelper.Log("DocumentOpen " + doc.Name); } @@ -565,7 +568,7 @@ namespace AIProofread // 取消捕获全局异常事件 AppDomain.CurrentDomain.UnhandledException -= ProcessApplicationException; System.Windows.Forms.Application.ThreadException -= ProcessApplicationFormException; - Logger.Log("shutdown"); + Logger.Debug("shutdown"); documentList.Clear(); if (_timer != null) { diff --git a/AIProofread/app.config b/AIProofread/app.config index ef33675..34f343c 100644 --- a/AIProofread/app.config +++ b/AIProofread/app.config @@ -1,5 +1,8 @@  + +
+ @@ -28,4 +31,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AIProofread/core/CorrectResultExportor.cs b/AIProofread/core/CorrectResultExportor.cs index 831b568..ab5caf7 100644 --- a/AIProofread/core/CorrectResultExportor.cs +++ b/AIProofread/core/CorrectResultExportor.cs @@ -6,11 +6,14 @@ using System.Windows.Forms; using UtilLib; using System.Diagnostics; using System; +using log4net; namespace AIProofread.core { public class CorrectResultExportor { + + public ILog Logger = LogHelper.GetLogger(typeof(CorrectResultExportor)); // 设置表头 private static readonly string[] HeaderCols = { @@ -213,54 +216,8 @@ namespace AIProofread.core //sheet.Append(new AutoFilter() { Reference = "A1:G1"}); } - #region 样式设置 - //var headerRange = worksheet.Range["A1:G1"]; - //var allRange = worksheet.Range["A1:G" + rowIndex]; - //// 对齐方式 - //// 所有都是垂直居中 - //allRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; - - //// 水平居中 - //headerRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; - //worksheet.Columns["A:C"].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; - //worksheet.Columns["G"].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; - - //// 全局样式 - //allRange.Font.Size = 11; - - //worksheet.Rows[1].RowHeight = 40; - //// 设置自动换行 - //worksheet.Rows.WrapText = true; - //var themeColor = new XSSFColor(new byte[] { 214, 170, 105 }); // 首行背景色黑色,字体用主题金色 - //// 设置背景/颜色 - //headerRange.Font.Color = ColorTranslator.ToOle(Color.FromArgb(255, 214, 170, 105)); - //headerRange.Interior.Pattern = Excel.XlPattern.xlPatternSolid; - //headerRange.Interior.Color = ColorTranslator.ToOle(Color.Black); - //// 设置字体 - //worksheet.Rows[1].Font.Name = "黑体"; - //worksheet.Columns["G"].Font.Name = "黑体"; - - // 设置列宽 - //worksheet.Columns["A:C"].ColumnWidth = 10; - //worksheet.Columns["D"].ColumnWidth = 80; - //worksheet.Columns["E:F"].ColumnWidth = 20; - //worksheet.Columns["G"].ColumnWidth = 10; - - // 设置冻结、筛选 - //worksheet.Activate(); - //worksheet.Range["B1"].Select(); // 必须选择冻结点 - // // 冻结第一行 - //excel.ActiveWindow.SplitRow = 1; - //excel.ActiveWindow.FreezePanes = true; - //worksheet.EnableAutoFilter = true; - //// 设置第一行筛选 - ////int lastRow = worksheet.UsedRange.Rows.Count; - //Excel.Range range = worksheet.get_Range("A1", "D1"); - //range.AutoFilter("1", "<>", Excel.XlAutoFilterOperator.xlOr, "", true); - #endregion - stopwatch.Stop(); - MessageBox.Show("导出完成,运行时间:" + stopwatch.Elapsed.TotalMilliseconds + "毫秒"); + Logger.Info("导出勘误表"+fileName+"完成,运行时间:" + stopwatch.Elapsed.TotalMilliseconds + "毫秒"); } @@ -268,7 +225,8 @@ namespace AIProofread.core { // 设置列宽 Columns columns = new Columns(); - SetColumnWidth(1, 3, 6, columns); + SetColumnWidth(1, 0, columns); // 隐藏第一列 + SetColumnWidth(2, 3, 6, columns); SetColumnWidth(4, 80, columns); SetColumnWidth(5, 6, 20, columns); SetColumnWidth(7, 10, columns); @@ -287,9 +245,10 @@ namespace AIProofread.core Min = startColIndex, // 从第1列开始 Max = endColIndex, // 到第3列结束 Width = width, // 宽度值(一般 8.43 为默认) - CustomWidth = true + CustomWidth = true, + Hidden = width <= 0, } - ); + ); } private void CreateHeader(SheetData sheetData) diff --git a/AIProofread/core/DocumentUtil.cs b/AIProofread/core/DocumentUtil.cs index 8035e5b..6daa028 100644 --- a/AIProofread/core/DocumentUtil.cs +++ b/AIProofread/core/DocumentUtil.cs @@ -117,7 +117,7 @@ namespace AIProofread } catch (Exception e) { - Logger.Log("remove mark", e); + LogHelper.Log("remove mark", e); } } } @@ -254,7 +254,7 @@ namespace AIProofread { "search_end",range.End }, { "search_text",range.Text } }; - Logger.Log(JsonConvert.SerializeObject(msg1)); + LogHelper.Log(JsonConvert.SerializeObject(msg1)); //while (range.Find.Found) //{ // var obj4 = range.Document; @@ -299,7 +299,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log(ex); + LogHelper.Log(ex); } return null; } @@ -327,7 +327,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log(ex); + LogHelper.Log(ex); } return null; @@ -381,7 +381,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); + LogHelper.Log("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n"); } return bookmark; } @@ -521,7 +521,7 @@ namespace AIProofread if (prevOffset >= paraText.Length) { // 查找位置已经超过了整段长度了 - Logger.Log("prevOffset:" + prevOffset + " paraText.Length:" + paraText.Length); + LogHelper.Log("prevOffset:" + prevOffset + " paraText.Length:" + paraText.Length); return null; } // 执行查找 @@ -604,10 +604,11 @@ namespace AIProofread } //ProcessExport(sfd.FileName); CorrectResultExportor.GetInstance().ExportResult(sfd.FileName); + Globals.ThisAddIn.ActiveDocument?.ShowMessage("导出勘误表成功", 2000, false); } catch (Exception e) { - Logger.Log(e); + LogHelper.Log(e); Globals.ThisAddIn.ShowDialog("导出勘误表失败,请重试", null, null); } } @@ -750,7 +751,7 @@ namespace AIProofread } catch (Exception e) { - Logger.Log(e); + LogHelper.Log(e); } var oriCell = row.CreateCell(3); @@ -861,7 +862,7 @@ namespace AIProofread } catch (Exception ex) { - Logger.Log(ex); + LogHelper.Log(ex); } id++; } @@ -869,7 +870,6 @@ namespace AIProofread // 保存到文件 book.Write(fs); //Globals.ThisAddIn.ShowMessage("导出成功", 3000); - Globals.ThisAddIn.ActiveDocument?.ShowMessage("导出勘误表成功", 2000, false); } } diff --git a/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources b/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources index 159e779..fc4c4a4 100644 Binary files a/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources and b/AIProofread/obj/Debug/AIProofread.Properties.Resources.resources differ diff --git a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache index 9fbbb70..3abc651 100644 Binary files a/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache and b/AIProofread/obj/Debug/AIProofread.csproj.AssemblyReference.cache differ diff --git a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache index f084c56..ef7b877 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache +++ b/AIProofread/obj/Debug/AIProofread.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -80a1b62e50022f6927ea33d64c401a80d068064724a07da1ca8562102f036978 +6ff77d6c12210febf10f5ae1faf45dfc8ef42d08e43da0240ffa9d92fbefb595 diff --git a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt index 702498b..6b8e004 100644 --- a/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt +++ b/AIProofread/obj/Debug/AIProofread.csproj.FileListAbsolute.txt @@ -216,3 +216,12 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread. C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AntdUI.dll C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AntdUI.xml C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormCommonsenseDetection.resources +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormLexicon.resources +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\System.ComponentModel.Annotations.dll +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\DocumentFormat.OpenXml.dll +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\DocumentFormat.OpenXml.Framework.dll +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\DocumentFormat.OpenXml.xml +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\DocumentFormat.OpenXml.Framework.xml +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\log4net.dll +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\log4net.pdb +C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\log4net.xml diff --git a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache index 4795da8..7037f46 100644 Binary files a/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache and b/AIProofread/obj/Debug/AIProofread.csproj.GenerateResource.cache differ diff --git a/AIProofread/obj/Debug/AIProofread.dll b/AIProofread/obj/Debug/AIProofread.dll index 54ff345..8ae85a8 100644 Binary files a/AIProofread/obj/Debug/AIProofread.dll and b/AIProofread/obj/Debug/AIProofread.dll differ diff --git a/AIProofread/obj/Debug/AIProofread.pdb b/AIProofread/obj/Debug/AIProofread.pdb index 5e16cfa..6d2d7e6 100644 Binary files a/AIProofread/obj/Debug/AIProofread.pdb and b/AIProofread/obj/Debug/AIProofread.pdb differ diff --git a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 7203ff6..b6a2912 100644 Binary files a/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/AIProofread/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll b/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll index b3ec8ce..4ea8016 100644 Binary files a/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll and b/AIProofread/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll differ diff --git a/AIProofread/packages.config b/AIProofread/packages.config index db72e38..a477dcd 100644 --- a/AIProofread/packages.config +++ b/AIProofread/packages.config @@ -5,6 +5,7 @@ + diff --git a/updater/Form1.Designer.cs b/updater/Form1.Designer.cs index 80a9a76..2865831 100644 --- a/updater/Form1.Designer.cs +++ b/updater/Form1.Designer.cs @@ -35,7 +35,7 @@ this.panel1 = new System.Windows.Forms.Panel(); this.IconClose = new System.Windows.Forms.PictureBox(); this.label1 = new System.Windows.Forms.Label(); - this.panelLog = new System.Windows.Forms.Panel(); + this.panelLog = new AntdUI.Panel(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.IconClose)).BeginInit(); this.panelLog.SuspendLayout(); @@ -44,12 +44,12 @@ // LabelLog // this.LabelLog.AutoEllipsis = true; + this.LabelLog.BackColor = System.Drawing.Color.Transparent; + this.LabelLog.Dock = System.Windows.Forms.DockStyle.Fill; this.LabelLog.Font = new System.Drawing.Font("微软雅黑", 10F); - this.LabelLog.Location = new System.Drawing.Point(2, 2); - this.LabelLog.MaximumSize = new System.Drawing.Size(296, 114); - this.LabelLog.MinimumSize = new System.Drawing.Size(296, 114); + this.LabelLog.Location = new System.Drawing.Point(5, 5); this.LabelLog.Name = "LabelLog"; - this.LabelLog.Size = new System.Drawing.Size(296, 114); + this.LabelLog.Size = new System.Drawing.Size(290, 100); this.LabelLog.TabIndex = 0; this.LabelLog.Text = "版本检测中 ..."; this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -114,10 +114,13 @@ // // panelLog // + this.panelLog.Back = System.Drawing.Color.FromArgb(((int)(((byte)(247)))), ((int)(((byte)(248)))), ((int)(((byte)(249))))); this.panelLog.Controls.Add(this.LabelLog); - this.panelLog.Location = new System.Drawing.Point(40, 58); + this.panelLog.Location = new System.Drawing.Point(40, 60); this.panelLog.Name = "panelLog"; - this.panelLog.Size = new System.Drawing.Size(300, 114); + this.panelLog.Padding = new System.Windows.Forms.Padding(5); + this.panelLog.Radius = 4; + this.panelLog.Size = new System.Drawing.Size(300, 110); this.panelLog.TabIndex = 8; // // Form1 @@ -155,7 +158,7 @@ private System.Windows.Forms.PictureBox IconClose; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label1; - private System.Windows.Forms.Panel panelLog; + private AntdUI.Panel panelLog; } }