diff --git a/.vs/AIProofread/v17/.suo b/.vs/AIProofread/v17/.suo
index 7b027b3..835cfbd 100644
Binary files a/.vs/AIProofread/v17/.suo and b/.vs/AIProofread/v17/.suo differ
diff --git a/AIProofread/AIProofread.csproj b/AIProofread/AIProofread.csproj
index bc54380..7b4e79f 100644
--- a/AIProofread/AIProofread.csproj
+++ b/AIProofread/AIProofread.csproj
@@ -302,6 +302,12 @@
FormDialog.cs
+
+ Form
+
+
+ FormLexicon.cs
+
Form
@@ -400,6 +406,9 @@
FormDialog.cs
+
+ FormLexicon.cs
+
FormLoading.cs
diff --git a/AIProofread/Bridge.cs b/AIProofread/Bridge.cs
index 2035f31..9027df1 100644
--- a/AIProofread/Bridge.cs
+++ b/AIProofread/Bridge.cs
@@ -154,6 +154,7 @@ namespace AIProofread
data["version"] = Config.APP_VERSION;
data["platform"] = Config.IS_WPS ? "wps" : "word";
data["environment"] = Config.APP_ENV.ToString();
+ data["deviceId"] = Config.DeviceId;
return JsonConvert.SerializeObject(data);
}
public void SetBtnStatus(string key, bool status)
@@ -280,6 +281,11 @@ namespace AIProofread
{
Globals.ThisAddIn.ShowLoginForm(action);
}
+ public void ShowLexiconForm()
+ {
+ //Globals.ThisAddIn.ShowLoginForm(action);
+ (new FormLexicon()).Show();
+ }
public void Logout(string action)
{
// web同步注销到ribbon
@@ -508,6 +514,10 @@ namespace AIProofread
public void ClearCurrentDocumentMarks() => Globals.ThisAddIn.ActiveDocument?.ClearAllProofreadMark();
public void removeBookmark(string markId) => DocumentUtil.RemoveBookmark(markId);
+ public string GetDeviceId()
+ {
+ return Config.DeviceId;
+ }
public string getAllBookmark()
{
diff --git a/AIProofread/Config.cs b/AIProofread/Config.cs
index 7470762..b65e1af 100644
--- a/AIProofread/Config.cs
+++ b/AIProofread/Config.cs
@@ -21,6 +21,7 @@ namespace AIProofread
/// 文本背景色
///
public static readonly string TextBackgroundColor = "#D6AA69";
+ public static string DeviceId = "";
#if DEBUG
///
/// 网页访问地址
diff --git a/AIProofread/Controls/BaseWinForm.cs b/AIProofread/Controls/BaseWinForm.cs
index 5f0c960..c2da513 100644
--- a/AIProofread/Controls/BaseWinForm.cs
+++ b/AIProofread/Controls/BaseWinForm.cs
@@ -1,8 +1,10 @@
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
+using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -123,6 +125,7 @@ namespace AIProofread.Controls
var eventForwarder = new EventForwarder(this);
webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder);
+ webView.CoreWebView2.AddHostObjectToScript("host", this);
webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge);
if(callaback != null)
{
@@ -135,5 +138,35 @@ namespace AIProofread.Controls
Logger.Log("\ninit webview error:" + ex.Message + "\n" + ex.StackTrace);
}
}
+ public void Download(string url)
+ {
+ Globals.ThisAddIn.ActiveDocument.RunInMainThread(() =>
+ {
+ var sfd = new SaveFileDialog();
+ sfd.Filter = "Excel文件|*.xlsx";
+ sfd.DefaultExt = ".xlsx";
+
+ if (sfd.ShowDialog() == DialogResult.OK)
+ {
+ var fileName = sfd.FileName;
+ Download(url, fileName);
+ }
+ });
+ }
+ public void Download(string url, string fileName)
+ {
+ // 现在url对应文件并保存到fileName
+ try
+ {
+ using (var client = new WebClient())
+ {
+ client.DownloadFile(url, fileName);
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.Log("\nDownload error:" + ex.Message + "\n" + ex.StackTrace);
+ }
+ }
}
}
diff --git a/AIProofread/Controls/FormLexicon.Designer.cs b/AIProofread/Controls/FormLexicon.Designer.cs
new file mode 100644
index 0000000..9142d8d
--- /dev/null
+++ b/AIProofread/Controls/FormLexicon.Designer.cs
@@ -0,0 +1,66 @@
+namespace AIProofread.Controls
+{
+ partial class FormLexicon
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.MainWebView = new Microsoft.Web.WebView2.WinForms.WebView2();
+ ((System.ComponentModel.ISupportInitialize)(this.MainWebView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // MainWebView
+ //
+ this.MainWebView.AllowExternalDrop = true;
+ this.MainWebView.CreationProperties = null;
+ this.MainWebView.DefaultBackgroundColor = System.Drawing.Color.White;
+ this.MainWebView.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.MainWebView.Location = new System.Drawing.Point(0, 0);
+ this.MainWebView.Name = "MainWebView";
+ this.MainWebView.Size = new System.Drawing.Size(1000, 640);
+ this.MainWebView.TabIndex = 0;
+ this.MainWebView.ZoomFactor = 1D;
+ //
+ // FormLexicon
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1000, 640);
+ this.Controls.Add(this.MainWebView);
+ this.Name = "FormLexicon";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "FormLexicon";
+ this.Load += new System.EventHandler(this.FormLexicon_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Microsoft.Web.WebView2.WinForms.WebView2 MainWebView;
+ }
+}
\ No newline at end of file
diff --git a/AIProofread/Controls/FormLexicon.cs b/AIProofread/Controls/FormLexicon.cs
new file mode 100644
index 0000000..94af12a
--- /dev/null
+++ b/AIProofread/Controls/FormLexicon.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace AIProofread.Controls
+{
+ [ClassInterface(ClassInterfaceType.AutoDual)]
+ [ComVisible(true)]
+ public partial class FormLexicon : BaseWinForm
+ {
+ public FormLexicon()
+ {
+ InitializeComponent();
+ }
+
+ private void FormLexicon_Load(object sender, EventArgs e)
+ {
+ // 初始化
+ InitWebView(MainWebView, Config.WebPath("lexicon"), "lexicon");
+ }
+ }
+}
diff --git a/AIProofread/Controls/FormLexicon.resx b/AIProofread/Controls/FormLexicon.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/AIProofread/Controls/FormLexicon.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/AIProofread/Controls/FormLogin.cs b/AIProofread/Controls/FormLogin.cs
index e9ef85e..803d46e 100644
--- a/AIProofread/Controls/FormLogin.cs
+++ b/AIProofread/Controls/FormLogin.cs
@@ -1,8 +1,11 @@
using System;
+using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AIProofread.Controls
{
+ [ClassInterface(ClassInterfaceType.AutoDual)]
+ [ComVisible(true)]
public partial class FormLogin : BaseWinForm
{
diff --git a/AIProofread/Model/DocumentInfo.cs b/AIProofread/Model/DocumentInfo.cs
index 6e48a42..0f314aa 100644
--- a/AIProofread/Model/DocumentInfo.cs
+++ b/AIProofread/Model/DocumentInfo.cs
@@ -107,6 +107,14 @@ namespace AIProofread.Model
}
}
+ public void RunInMainThread(Action action)
+ {
+ if (null != TaskPane)
+ {
+ TaskPane.Control.BeginInvoke(action);
+ }
+ }
+
public void ShowDialog(string message, string confirmText, string confirmAction)
{
TaskPane.Control.BeginInvoke(new Action(() =>
diff --git a/AIProofread/Ribbon1.cs b/AIProofread/Ribbon1.cs
index adf3893..9871436 100644
--- a/AIProofread/Ribbon1.cs
+++ b/AIProofread/Ribbon1.cs
@@ -171,6 +171,7 @@ namespace AIProofread
private void btnOpenLexicon_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.SendMessageToWeb("show-lexicon", null);
+ //(new FormLexicon()).Show();
}
private void btnSetting_Click(object sender, RibbonControlEventArgs e)
diff --git a/AIProofread/ThisAddIn.cs b/AIProofread/ThisAddIn.cs
index 1e68d51..211e1af 100644
--- a/AIProofread/ThisAddIn.cs
+++ b/AIProofread/ThisAddIn.cs
@@ -106,6 +106,7 @@ namespace AIProofread
{
try
{
+ InitDeviceId();
AppInitialize();
//formCommonsenseDetection.ShowInTaskbar = false;
//formCommonsenseDetection.Show();
@@ -141,6 +142,31 @@ namespace AIProofread
Logger.Log("Startup", ex1.ToString());
}
}
+
+ // 异步获取设备唯一标识
+ public void InitDeviceId()
+ {
+ System.Threading.Tasks.Task.Run(() =>
+ {
+ try
+ {
+ var deviceId = Tools.GetDeviceId();
+ if (string.IsNullOrEmpty(deviceId))
+ {
+ deviceId = Tools.GetDeviceId();
+ }
+ if (!string.IsNullOrEmpty(deviceId))
+ {
+ Config.DeviceId = deviceId;
+ Logger.Log("设备唯一标识:" + deviceId);
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.Log("InitDeviceId", ex.ToString());
+ }
+ });
+ }
public void CheckDocumentClosed(object sender, System.Timers.ElapsedEventArgs e)
diff --git a/AIProofread/core/Tools.cs b/AIProofread/core/Tools.cs
index 71cd2f1..4d0a47b 100644
--- a/AIProofread/core/Tools.cs
+++ b/AIProofread/core/Tools.cs
@@ -234,5 +234,23 @@ namespace AIProofread
{
return JsonConvert.SerializeObject(data, Formatting.Indented);
}
+
+ ///
+ /// 生成设备唯一标识
+ ///
+ ///
+ public static string GetDeviceId()
+ {
+ string devicePath = Config.APP_DATA_PATH + "\\deviceId.txt";
+ // 如果存在则直接返回
+ if (File.Exists(devicePath))
+ {
+ return File.ReadAllText(devicePath);
+ }
+ string deviceId = Guid.NewGuid().ToString().ToLower();
+ // 将deviceId保存为纯文本文件到程序目录
+ File.WriteAllText(devicePath, deviceId);
+ return deviceId;
+ }
}
}