using AIProofread.Controls; using AIProofread.Model; using Newtonsoft.Json; using System.Collections.Generic; using System.Runtime.InteropServices; namespace AIProofread.core { /// /// 常识性检测数据 /// [ClassInterface(ClassInterfaceType.AutoDual)] [ComVisible(true)] public class CommonSenseDetection { /// /// 检测历史 /// //public static readonly Dictionary> histories = new Dictionary>(); // 暂时改成全局 private List history = new List(); // 生成单例 public static readonly CommonSenseDetection instance = new CommonSenseDetection(); private FormCommonsenseDetection formCommonsenseDetection; private CommonSenseDetection() { } public static CommonSenseDetection Instance(FormCommonsenseDetection handler) { instance.formCommonsenseDetection = handler; return instance; } public void WebInitializationCompleted() { if (formCommonsenseDetection != null && !formCommonsenseDetection.IsDisposed) { formCommonsenseDetection.InitializationCompleted(); } } // 检测状态 public bool isChecking = false; public string checkingSummary; public string checkingLocation; public string checkingKey; public string GetCheckStatus() { return JSONObject.Create() .Put("isChecking", isChecking) .Put("checkingKey", checkingKey) .Put("checkingLocation", checkingLocation) .Put("checkingSummary", checkingSummary) .ToString(); } public void SetCheckingData(bool isChecking, string checkingKey, string checkingSummary,string checkingLocation) { if (isChecking) { this.isChecking = isChecking; this.checkingKey = checkingKey; this.checkingSummary = checkingSummary; this.checkingLocation = checkingLocation; Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(false,false); } else { this.isChecking = false; this.checkingKey = null; this.checkingSummary = null; this.checkingLocation = null; var enableAll = string.IsNullOrEmpty(checkingSummary); Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(enableAll,!enableAll); } } public string GetHistory() { //int id = Globals.ThisAddIn.ActiveDocument.Id; return JsonConvert.SerializeObject(history);// histories.ContainsKey(id) ? JsonConvert.SerializeObject(histories[id]) : "[]"; } public void SetHistory(string json) { var item = JsonConvert.DeserializeObject(json); history.Add(item); //int id = Globals.ThisAddIn.ActiveDocument.Id; //if (histories.ContainsKey(id)) //{ // histories.Add(id, new List() { item }); //} //else //{ // histories[id].Add(item); //} } public void Close() { if (isChecking) { Globals.ThisAddIn.formCommonsenseDetection.Hide(); return; } Globals.ThisAddIn.HideDetection(); } } }