41 lines
1.2 KiB
C#

using Newtonsoft.Json;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace AIProofread
{
public class Tools
{
public static string GetAllText()
{
// 获取当前文档所有文本
string allText = Globals.ThisAddIn.Application.ActiveDocument.Range().Text;
List<DocumentText> list = new List<DocumentText>();
if (allText != null && allText.Length > 0)
{
// 开始分割
MD5 md5 = new MD5CryptoServiceProvider();
List<string> lines = StringUtil.CutTextToSentences(allText);
foreach (string text in lines)
{
byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
list.Add(new DocumentText(hash, text));
}
}
var map = new Dictionary<string, object>
{
{ "list", list },
{ "text", allText }
};
return GetJSONString(map);
}
public static string GetJSONString(object data)
{
return JsonConvert.SerializeObject(data, Formatting.Indented);
}
}
}