终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

94 wiersze
2.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using Unvell.ReoScript;
  8. namespace BPASmartClient.Compiler
  9. {
  10. /// <summary>
  11. /// 编译器
  12. /// 创建人:奉友福
  13. /// 创建时间:20220824
  14. /// </summary>
  15. public class Config
  16. {
  17. #region 单例模式
  18. public static Config Instance = null;
  19. public static Config GetInstance()
  20. {
  21. if (Instance == null)
  22. {
  23. Instance = new Config();
  24. }
  25. return Instance;
  26. }
  27. #endregion
  28. public static ScriptRunningMachine srm { get; } = new ScriptRunningMachine();
  29. public Config()
  30. {
  31. srm.WorkMode |=
  32. // Enable DirectAccess
  33. MachineWorkMode.AllowDirectAccess
  34. // Ignore exceptions in CLR calling (by default)
  35. | MachineWorkMode.IgnoreCLRExceptions
  36. // Enable CLR Event Binding
  37. | MachineWorkMode.AllowCLREventBind;
  38. RegisterFunction();
  39. }
  40. /// <summary>
  41. /// 运行脚本
  42. /// </summary>
  43. /// <param name="script"></param>
  44. public void RunJsScipt(string script)
  45. {
  46. try
  47. {
  48. srm.Run(script);
  49. }
  50. catch (Exception e)
  51. {
  52. //MessageBox.Show(e.Message, "脚本错误");
  53. }
  54. }
  55. /// <summary>
  56. /// 注册对象到js
  57. /// </summary>
  58. public void SetVariable(string name, object obj)
  59. {
  60. srm.SetGlobalVariable(name, obj);
  61. }
  62. /// <summary>
  63. /// 注册方法到Js
  64. /// </summary>
  65. private static void RegisterFunction()
  66. {
  67. srm["ShowMessage"] = new NativeFunctionObject("ShowMessage", (ctx, owner, args) =>
  68. {
  69. StringBuilder sb = new StringBuilder();
  70. foreach (var item in args)
  71. {
  72. sb.Append(item.ToString());
  73. }
  74. //MessageBox.Show($"{sb}", "提示");
  75. return null;
  76. });
  77. srm["SetICDValue"] = new NativeFunctionObject("SetICDValue", (ctx, owner, args) =>
  78. {
  79. //MessageBox.Show($"发送ICD数据", "提示");
  80. return null;
  81. });
  82. }
  83. }
  84. }