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 GetAllText() { // 获取当前文档所有文本 string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text; List list = new List(); if (allText != null && allText.Trim().Length > 0) { // 开始分割 MD5 md5 = new MD5CryptoServiceProvider(); List lines = allText.Split(paragSplitor, StringSplitOptions.None).ToList();//StringUtil.CutTextToSentences(allText); foreach (string text in lines) { 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 { { "list", list }, { "text", allText } }; return map; } public static string GetJSONString(object data) { return JsonConvert.SerializeObject(data, Formatting.Indented); } } }