终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.0 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 BeDesignerSCADA.Helper
  9. {
  10. internal class Config
  11. {
  12. private static ScriptRunningMachine srm { get; } = new ScriptRunningMachine();
  13. static Config()
  14. {
  15. srm.WorkMode |=
  16. // Enable DirectAccess
  17. MachineWorkMode.AllowDirectAccess
  18. // Ignore exceptions in CLR calling (by default)
  19. | MachineWorkMode.IgnoreCLRExceptions
  20. // Enable CLR Event Binding
  21. | MachineWorkMode.AllowCLREventBind;
  22. RegisterFunction();
  23. }
  24. /// <summary>
  25. /// 运行脚本
  26. /// </summary>
  27. /// <param name="script"></param>
  28. public static void RunJsScipt(string script)
  29. {
  30. try
  31. {
  32. srm.Run(script);
  33. }
  34. catch (Exception e)
  35. {
  36. MessageBox.Show(e.Message, "脚本错误");
  37. }
  38. }
  39. /// <summary>
  40. /// 注册对象到js
  41. /// </summary>
  42. public static void SetVariable(string name, object obj)
  43. {
  44. srm.SetGlobalVariable(name, obj);
  45. }
  46. /// <summary>
  47. /// 注册方法到Js
  48. /// </summary>
  49. private static void RegisterFunction()
  50. {
  51. srm["ShowMessage"] = new NativeFunctionObject("ShowMessage", (ctx, owner, args) =>
  52. {
  53. StringBuilder sb = new StringBuilder();
  54. foreach (var item in args)
  55. {
  56. sb.Append(item.ToString());
  57. }
  58. MessageBox.Show($"{sb}", "提示");
  59. return null;
  60. });
  61. srm["SetICDValue"] = new NativeFunctionObject("SetICDValue", (ctx, owner, args) =>
  62. {
  63. MessageBox.Show($"发送ICD数据", "提示");
  64. return null;
  65. });
  66. }
  67. }
  68. }