记录错误日志
This commit is contained in:
parent
aba0247d14
commit
79d9e215b6
Binary file not shown.
@ -111,7 +111,7 @@ namespace AIProofread
|
|||||||
Userinfo info = JsonConvert.DeserializeObject<Userinfo>(userinfo);
|
Userinfo info = JsonConvert.DeserializeObject<Userinfo>(userinfo);
|
||||||
// 登录成功 展示
|
// 登录成功 展示
|
||||||
Globals.ThisAddIn.ribbon.ProcessLoginInfo(info);
|
Globals.ThisAddIn.ribbon.ProcessLoginInfo(info);
|
||||||
Globals.ThisAddIn.SendMessageToWeb("async-login-success", null);
|
//Globals.ThisAddIn.SendMessageToWeb("async-login-success", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取文档所有文本数据
|
// 获取文档所有文本数据
|
||||||
@ -362,58 +362,65 @@ namespace AIProofread
|
|||||||
|
|
||||||
public Microsoft.Office.Tools.Word.Bookmark AddBookmark(CorrectedContent item, int findIndex, int offset, int length)
|
public Microsoft.Office.Tools.Word.Bookmark AddBookmark(CorrectedContent item, int findIndex, int offset, int length)
|
||||||
{
|
{
|
||||||
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
|
||||||
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
|
|
||||||
var Start = offset;
|
|
||||||
var End = offset + length - 1;
|
|
||||||
// 整体选区的内容
|
|
||||||
var fullRange = document.Range(Start, End);
|
|
||||||
string fullText = fullRange.Text;
|
|
||||||
End = offset + item.start;
|
|
||||||
Start = offset + item.end;
|
|
||||||
|
|
||||||
Microsoft.Office.Tools.Word.Bookmark bookmark = null;
|
Microsoft.Office.Tools.Word.Bookmark bookmark = null;
|
||||||
var r = document.Range(End, Start);
|
try
|
||||||
var markName = Config.BuildBookmarkName(item.id);
|
{
|
||||||
|
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
||||||
|
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
|
||||||
|
var Start = offset;
|
||||||
|
var End = offset + length - 1;
|
||||||
|
// 整体选区的内容
|
||||||
|
var fullRange = document.Range(Start, End);
|
||||||
|
string fullText = fullRange.Text;
|
||||||
|
End = offset + item.start;
|
||||||
|
Start = offset + item.end;
|
||||||
|
|
||||||
// 判断是否已经存在
|
var r = document.Range(End, Start);
|
||||||
if (controls.Contains(markName))
|
var markName = Config.BuildBookmarkName(item.id);
|
||||||
{
|
|
||||||
controls.Remove(markName);
|
// 判断是否已经存在
|
||||||
}
|
if (controls.Contains(markName))
|
||||||
// 判断选区是否正确
|
|
||||||
if (item.tag == "i" || r.Text == item.origin)
|
|
||||||
{
|
|
||||||
bookmark = controls.AddBookmark(r, markName);
|
|
||||||
bookmark.Tag = "ai_proofread";
|
|
||||||
if (item.color != null)
|
|
||||||
{
|
{
|
||||||
// 给选区添加背景颜色
|
controls.Remove(markName);
|
||||||
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
|
||||||
}
|
}
|
||||||
}
|
// 判断选区是否正确
|
||||||
else
|
if (item.tag == "i" || r.Text == item.origin)
|
||||||
{
|
|
||||||
int startPos = 0, index,findCount = 0;
|
|
||||||
while ((index = fullText.IndexOf(item.origin, startPos)) != -1)
|
|
||||||
{
|
{
|
||||||
if (findCount == findIndex)
|
bookmark = controls.AddBookmark(r, markName);
|
||||||
|
bookmark.Tag = "ai_proofread";
|
||||||
|
if (item.color != null)
|
||||||
{
|
{
|
||||||
r = document.Range(offset + index, offset + index + item.origin.Length);
|
// 给选区添加背景颜色
|
||||||
bookmark = controls.AddBookmark(r, markName);
|
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
||||||
bookmark.Tag = "ai_proofread";
|
}
|
||||||
if (item.color != null)
|
}
|
||||||
{
|
else
|
||||||
// 给选区添加背景颜色
|
{
|
||||||
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
int startPos = 0, index, findCount = 0;
|
||||||
}
|
while ((index = fullText.IndexOf(item.origin, startPos)) != -1)
|
||||||
break;
|
{
|
||||||
|
if (findCount == findIndex)
|
||||||
|
{
|
||||||
|
r = document.Range(offset + index, offset + index + item.origin.Length);
|
||||||
|
bookmark = controls.AddBookmark(r, markName);
|
||||||
|
bookmark.Tag = "ai_proofread";
|
||||||
|
if (item.color != null)
|
||||||
|
{
|
||||||
|
// 给选区添加背景颜色
|
||||||
|
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
startPos = index;
|
||||||
|
findCount++;
|
||||||
}
|
}
|
||||||
startPos = index;
|
|
||||||
findCount++;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Log("create mark error:" + ex.Message + "\n" + ex.StackTrace + "\n\n");
|
||||||
|
}
|
||||||
return bookmark;
|
return bookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,14 +10,10 @@ namespace AIProofread
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 网页访问地址
|
/// 网页访问地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string WEB_PATH = "http://localhost:5173/";
|
public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/";
|
||||||
#else
|
#else
|
||||||
public static readonly string WEB_PATH = "dist/index.html";
|
public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/";
|
||||||
#endif
|
#endif
|
||||||
/// <summary>
|
|
||||||
/// 词库地址
|
|
||||||
/// </summary>
|
|
||||||
public static readonly string LEXICON_PATH = "https://gm.gachafun.com/lexicon";
|
|
||||||
public static readonly string WEB_DATA_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ai_proofread\\userdata";
|
public static readonly string WEB_DATA_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ai_proofread\\userdata";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -113,16 +113,23 @@ namespace AIProofread.Controls
|
|||||||
protected async void InitWebView(WebView2 webView,String url,string name)
|
protected async void InitWebView(WebView2 webView,String url,string name)
|
||||||
{
|
{
|
||||||
//Bridge.InitWebEnvAsync(name, webView);
|
//Bridge.InitWebEnvAsync(name, webView);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (webView.IsDisposed) return;
|
||||||
|
var ops = new CoreWebView2EnvironmentOptions("--disable-web-security");
|
||||||
|
var env = await CoreWebView2Environment.CreateAsync(null, Config.WEB_DATA_PATH, ops);
|
||||||
|
|
||||||
var ops = new CoreWebView2EnvironmentOptions("--disable-web-security");
|
await webView.EnsureCoreWebView2Async(env);
|
||||||
var env = await CoreWebView2Environment.CreateAsync(null, Config.WEB_DATA_PATH, ops);
|
|
||||||
await webView.EnsureCoreWebView2Async(env);
|
|
||||||
|
|
||||||
var eventForwarder = new EventForwarder(this);
|
var eventForwarder = new EventForwarder(this);
|
||||||
webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder);
|
webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder);
|
||||||
webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge);
|
webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge);
|
||||||
|
|
||||||
webView.Source = new Uri(url);
|
webView.Source = new Uri(url);
|
||||||
|
}catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Log("\ninit webview error:" + ex.Message + "\n" + ex.StackTrace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,13 @@ namespace UtilLib
|
|||||||
public ProofreadItem(CorrectedContent content, Bookmark bookmark)
|
public ProofreadItem(CorrectedContent content, Bookmark bookmark)
|
||||||
{
|
{
|
||||||
this.content = content;
|
this.content = content;
|
||||||
InitBookMark(bookmark);
|
if (bookmark != null)
|
||||||
|
{
|
||||||
|
this.mark = bookmark;
|
||||||
|
// 记录目前字体
|
||||||
|
originSize = bookmark.Range.Font.Size;
|
||||||
|
}
|
||||||
|
//InitBookMark(bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitBookMark(Bookmark bookmark)
|
private void InitBookMark(Bookmark bookmark)
|
||||||
@ -59,37 +65,35 @@ namespace UtilLib
|
|||||||
|
|
||||||
public void Select()
|
public void Select()
|
||||||
{
|
{
|
||||||
if (mark != null)
|
if (mark == null) return;
|
||||||
{
|
mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体
|
||||||
mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体
|
mark.Select();
|
||||||
//Globals.ThisAddIn.Application.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;
|
|
||||||
//Globals.ThisAddIn.Application.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
|
|
||||||
//Globals.ThisAddIn.Application.ActiveWindow.Activate();
|
|
||||||
mark.Select();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public void UnSelect()
|
public void UnSelect()
|
||||||
{
|
{
|
||||||
if (mark != null)
|
if (mark == null) return;
|
||||||
{
|
mark.Range.Font.Size = originSize; // 还原
|
||||||
mark.Range.Font.Size = originSize; // 还原
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetMarkStyle()
|
private void SetMarkStyle()
|
||||||
{
|
{
|
||||||
|
if (mark == null) return;
|
||||||
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
|
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
|
||||||
mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(content.color));
|
mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(content.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetMarkStyle()
|
private void ResetMarkStyle()
|
||||||
{
|
{
|
||||||
|
if (mark == null) return;
|
||||||
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
|
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
|
||||||
mark.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
|
mark.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(int status)
|
public void Process(int status)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (mark == null) return;
|
||||||
//
|
//
|
||||||
content.isAccept = status;
|
content.isAccept = status;
|
||||||
if (status == AcceptStatus.Accept)
|
if (status == AcceptStatus.Accept)
|
||||||
|
@ -66,7 +66,7 @@ namespace AIProofread
|
|||||||
|
|
||||||
private void btnOpenLexicon_Click(object sender, RibbonControlEventArgs e)
|
private void btnOpenLexicon_Click(object sender, RibbonControlEventArgs e)
|
||||||
{
|
{
|
||||||
Process.Start(Config.LEXICON_PATH);
|
Globals.ThisAddIn.SendMessageToWeb("show-lexicon", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnSetting_Click(object sender, RibbonControlEventArgs e)
|
private void btnSetting_Click(object sender, RibbonControlEventArgs e)
|
||||||
@ -94,6 +94,7 @@ namespace AIProofread
|
|||||||
private void btnClear_Click(object sender, RibbonControlEventArgs e)
|
private void btnClear_Click(object sender, RibbonControlEventArgs e)
|
||||||
{
|
{
|
||||||
DocumentUtil.ClearProofreadMarks();
|
DocumentUtil.ClearProofreadMarks();
|
||||||
|
Globals.ThisAddIn.SendMessageToWeb("clear-tips",null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ namespace AIProofread
|
|||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
|
||||||
public DocumentText() { }
|
public DocumentText() { }
|
||||||
|
public DocumentText(string text)
|
||||||
|
{
|
||||||
|
this.Text = text;
|
||||||
|
}
|
||||||
public DocumentText(byte[] hash, string text)
|
public DocumentText(byte[] hash, string text)
|
||||||
{
|
{
|
||||||
this.Hash = BitConverter.ToString(hash).ToLower().Replace("-", "");
|
this.Hash = BitConverter.ToString(hash).ToLower().Replace("-", "");
|
||||||
|
@ -1,27 +1,41 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
using System.Security.Policy;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace AIProofread
|
namespace AIProofread
|
||||||
{
|
{
|
||||||
public class Tools
|
public class Tools
|
||||||
{
|
{
|
||||||
|
private static readonly string[] paragSplitor = new string[] { "\r", "\n", "\r\n" };
|
||||||
public static Dictionary<string, object> GetAllText()
|
public static Dictionary<string, object> GetAllText()
|
||||||
{
|
{
|
||||||
// 获取当前文档所有文本
|
// 获取当前文档所有文本
|
||||||
string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text;
|
string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text;
|
||||||
List<DocumentText> list = new List<DocumentText>();
|
List<DocumentText> list = new List<DocumentText>();
|
||||||
|
|
||||||
if (allText != null && allText.Trim().Length > 0)
|
if (allText != null && allText.Trim().Length > 0)
|
||||||
{
|
{
|
||||||
// 开始分割
|
// 开始分割
|
||||||
MD5 md5 = new MD5CryptoServiceProvider();
|
MD5 md5 = new MD5CryptoServiceProvider();
|
||||||
List<string> lines = StringUtil.CutTextToSentences(allText);
|
|
||||||
|
List<string> lines = allText.Split(paragSplitor, StringSplitOptions.None).ToList();//StringUtil.CutTextToSentences(allText);
|
||||||
foreach (string text in lines)
|
foreach (string text in lines)
|
||||||
{
|
{
|
||||||
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
|
if(text.Trim().Length > 0)
|
||||||
list.Add(new DocumentText(hash, text));
|
{
|
||||||
|
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
|
||||||
|
list.Add(new DocumentText(hash, text + "\n"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
list.Add(new DocumentText(text + "\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var map = new Dictionary<string, object>
|
var map = new Dictionary<string, object>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user