记录错误日志
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);
|
||||
// 登录成功 展示
|
||||
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)
|
||||
{
|
||||
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;
|
||||
var r = document.Range(End, Start);
|
||||
var markName = Config.BuildBookmarkName(item.id);
|
||||
try
|
||||
{
|
||||
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;
|
||||
|
||||
// 判断是否已经存在
|
||||
if (controls.Contains(markName))
|
||||
{
|
||||
controls.Remove(markName);
|
||||
}
|
||||
// 判断选区是否正确
|
||||
if (item.tag == "i" || r.Text == item.origin)
|
||||
{
|
||||
bookmark = controls.AddBookmark(r, markName);
|
||||
bookmark.Tag = "ai_proofread";
|
||||
if (item.color != null)
|
||||
var r = document.Range(End, Start);
|
||||
var markName = Config.BuildBookmarkName(item.id);
|
||||
|
||||
// 判断是否已经存在
|
||||
if (controls.Contains(markName))
|
||||
{
|
||||
// 给选区添加背景颜色
|
||||
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
||||
controls.Remove(markName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int startPos = 0, index,findCount = 0;
|
||||
while ((index = fullText.IndexOf(item.origin, startPos)) != -1)
|
||||
// 判断选区是否正确
|
||||
if (item.tag == "i" || r.Text == item.origin)
|
||||
{
|
||||
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);
|
||||
bookmark.Tag = "ai_proofread";
|
||||
if (item.color != null)
|
||||
{
|
||||
// 给选区添加背景颜色
|
||||
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
||||
}
|
||||
break;
|
||||
// 给选区添加背景颜色
|
||||
r.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(item.color));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int startPos = 0, index, findCount = 0;
|
||||
while ((index = fullText.IndexOf(item.origin, startPos)) != -1)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -10,14 +10,10 @@ namespace AIProofread
|
||||
/// <summary>
|
||||
/// 网页访问地址
|
||||
/// </summary>
|
||||
public static readonly string WEB_PATH = "http://localhost:5173/";
|
||||
public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/";
|
||||
#else
|
||||
public static readonly string WEB_PATH = "dist/index.html";
|
||||
public static readonly string WEB_PATH = "https://gm-plugin.gachafun.com/";
|
||||
#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";
|
||||
|
||||
/// <summary>
|
||||
|
@ -113,16 +113,23 @@ namespace AIProofread.Controls
|
||||
protected async void InitWebView(WebView2 webView,String url,string name)
|
||||
{
|
||||
//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");
|
||||
var env = await CoreWebView2Environment.CreateAsync(null, Config.WEB_DATA_PATH, ops);
|
||||
await webView.EnsureCoreWebView2Async(env);
|
||||
await webView.EnsureCoreWebView2Async(env);
|
||||
|
||||
var eventForwarder = new EventForwarder(this);
|
||||
webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder);
|
||||
webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge);
|
||||
var eventForwarder = new EventForwarder(this);
|
||||
webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder);
|
||||
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)
|
||||
{
|
||||
this.content = content;
|
||||
InitBookMark(bookmark);
|
||||
if (bookmark != null)
|
||||
{
|
||||
this.mark = bookmark;
|
||||
// 记录目前字体
|
||||
originSize = bookmark.Range.Font.Size;
|
||||
}
|
||||
//InitBookMark(bookmark);
|
||||
}
|
||||
|
||||
private void InitBookMark(Bookmark bookmark)
|
||||
@ -59,37 +65,35 @@ namespace UtilLib
|
||||
|
||||
public void Select()
|
||||
{
|
||||
if (mark != null)
|
||||
{
|
||||
mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体
|
||||
//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();
|
||||
}
|
||||
if (mark == null) return;
|
||||
mark.Range.Font.Size = originSize + 2; // 将选中标签文本放大字体
|
||||
mark.Select();
|
||||
|
||||
}
|
||||
public void UnSelect()
|
||||
{
|
||||
if (mark != null)
|
||||
{
|
||||
mark.Range.Font.Size = originSize; // 还原
|
||||
}
|
||||
if (mark == null) return;
|
||||
mark.Range.Font.Size = originSize; // 还原
|
||||
}
|
||||
|
||||
private void SetMarkStyle()
|
||||
{
|
||||
if (mark == null) return;
|
||||
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineThick;
|
||||
mark.Shading.BackgroundPatternColor = (WdColor)ColorTranslator.ToOle(Colors.FromHex(content.color));
|
||||
}
|
||||
|
||||
private void ResetMarkStyle()
|
||||
{
|
||||
if (mark == null) return;
|
||||
mark.Range.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
|
||||
mark.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
|
||||
}
|
||||
|
||||
public void Process(int status)
|
||||
{
|
||||
|
||||
if (mark == null) return;
|
||||
//
|
||||
content.isAccept = status;
|
||||
if (status == AcceptStatus.Accept)
|
||||
|
@ -66,7 +66,7 @@ namespace AIProofread
|
||||
|
||||
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)
|
||||
@ -94,6 +94,7 @@ namespace AIProofread
|
||||
private void btnClear_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
DocumentUtil.ClearProofreadMarks();
|
||||
Globals.ThisAddIn.SendMessageToWeb("clear-tips",null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,10 @@ namespace AIProofread
|
||||
public string Text { get; set; }
|
||||
|
||||
public DocumentText() { }
|
||||
public DocumentText(string text)
|
||||
{
|
||||
this.Text = text;
|
||||
}
|
||||
public DocumentText(byte[] hash, string text)
|
||||
{
|
||||
this.Hash = BitConverter.ToString(hash).ToLower().Replace("-", "");
|
||||
|
@ -1,27 +1,41 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace AIProofread
|
||||
{
|
||||
public class Tools
|
||||
{
|
||||
private static readonly string[] paragSplitor = new string[] { "\r", "\n", "\r\n" };
|
||||
public static Dictionary<string, object> GetAllText()
|
||||
{
|
||||
// 获取当前文档所有文本
|
||||
string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text;
|
||||
List<DocumentText> list = new List<DocumentText>();
|
||||
|
||||
|
||||
if (allText != null && allText.Trim().Length > 0)
|
||||
{
|
||||
// 开始分割
|
||||
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)
|
||||
{
|
||||
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
|
||||
list.Add(new DocumentText(hash, text));
|
||||
if(text.Trim().Length > 0)
|
||||
{
|
||||
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>
|
||||
|
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