using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Unvell.ReoScript; namespace BeDesignerSCADA.Helper { internal class Config { private static ScriptRunningMachine srm { get; } = new ScriptRunningMachine(); static Config() { srm.WorkMode |= // Enable DirectAccess MachineWorkMode.AllowDirectAccess // Ignore exceptions in CLR calling (by default) | MachineWorkMode.IgnoreCLRExceptions // Enable CLR Event Binding | MachineWorkMode.AllowCLREventBind; RegisterFunction(); } /// /// 运行脚本 /// /// public static void RunJsScipt(string script) { try { srm.Run(script); } catch (Exception e) { MessageBox.Show(e.Message, "脚本错误"); } } /// /// 注册对象到js /// public static void SetVariable(string name, object obj) { srm.SetGlobalVariable(name, obj); } /// /// 注册方法到Js /// private static void RegisterFunction() { srm["ShowMessage"] = new NativeFunctionObject("ShowMessage", (ctx, owner, args) => { StringBuilder sb = new StringBuilder(); foreach (var item in args) { sb.Append(item.ToString()); } MessageBox.Show($"{sb}", "提示"); return null; }); srm["SetICDValue"] = new NativeFunctionObject("SetICDValue", (ctx, owner, args) => { MessageBox.Show($"发送ICD数据", "提示"); return null; }); } } }