|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using Unvell.ReoScript;
-
- namespace BPASmartClient.Compiler
- {
- /// <summary>
- /// 编译器
- /// 创建人:奉友福
- /// 创建时间:20220824
- /// </summary>
- public class Config
- {
- #region 单例模式
- public static Config Instance = null;
-
- public static Config GetInstance()
- {
- if (Instance == null)
- {
- Instance = new Config();
- }
- return Instance;
- }
- #endregion
-
- public static ScriptRunningMachine srm { get; } = new ScriptRunningMachine();
-
- public Config()
- {
- srm.WorkMode |=
- // Enable DirectAccess
- MachineWorkMode.AllowDirectAccess
- // Ignore exceptions in CLR calling (by default)
- | MachineWorkMode.IgnoreCLRExceptions
- // Enable CLR Event Binding
- | MachineWorkMode.AllowCLREventBind;
-
- RegisterFunction();
- }
-
- /// <summary>
- /// 运行脚本
- /// </summary>
- /// <param name="script"></param>
- public void RunJsScipt(string script)
- {
- try
- {
- srm.Run(script);
- }
- catch (Exception e)
- {
- //MessageBox.Show(e.Message, "脚本错误");
- }
- }
-
- /// <summary>
- /// 注册对象到js
- /// </summary>
- public void SetVariable(string name, object obj)
- {
- srm.SetGlobalVariable(name, obj);
- }
-
- /// <summary>
- /// 注册方法到Js
- /// </summary>
- 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;
- });
- }
- }
- }
|