Parcourir la source

1111

样式分支
fyf il y a 2 ans
Parent
révision
ba473a93ec
4 fichiers modifiés avec 85 ajouts et 0 suppressions
  1. +9
    -0
      BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj
  2. BIN
     
  3. BIN
     
  4. +76
    -0
      BPASmartClient.SCADAControl/Hepler/Config.cs

+ 9
- 0
BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj Voir le fichier

@@ -10,6 +10,15 @@
<None Remove="Images\光柱.png" />
</ItemGroup>

<ItemGroup>
<Reference Include="Antlr3.Runtime">
<HintPath>DLL\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unvell.ReoScript">
<HintPath>DLL\Unvell.ReoScript.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Resource Include="Images\光柱.png" />
</ItemGroup>




+ 76
- 0
BPASmartClient.SCADAControl/Hepler/Config.cs Voir le fichier

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Unvell.ReoScript;

namespace BPASmartClient.SCADAControl.Hepler
{
public 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();
}

/// <summary>
/// 运行脚本
/// </summary>
/// <param name="script"></param>
public static void RunJsScipt(string script)
{
try
{
srm.Run(script);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "脚本错误");
}
}

/// <summary>
/// 注册对象到js
/// </summary>
public static 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;
});
}
}
}

Chargement…
Annuler
Enregistrer