using NationalInstruments.TestStand.Interop.API;
|
using NationalInstruments.TestStand.Interop.UI.Ax;
|
using System;
|
|
namespace Plugin.TsSupport
|
{
|
public class TsExecutionWrapper : ITestExecutionWrapper
|
{
|
|
#region TestStand事件
|
/// <summary>
|
/// TS 引擎
|
/// </summary>
|
private Engine engine = null;
|
|
/// <summary>
|
/// 测试序列路径
|
/// </summary>
|
private string testSeqFile = string.Empty;
|
|
/// <summary>
|
/// 测试序列
|
/// </summary>
|
private SequenceFile testSeq = null;
|
|
/// <summary>
|
/// 测试模型序列
|
/// </summary>
|
private SequenceFile modeSeq = null;
|
|
/// <summary>
|
/// 运行实例
|
/// </summary>
|
private Execution execution = null;
|
|
public SequenceContext context { get; set; } = null;
|
|
/// <summary>
|
/// 事件管理器
|
/// </summary>
|
public AxApplicationMgr AxApplicationMgr { get; private set; }
|
|
public event _ApplicationMgrEvents_EndExecutionEventHandler OnEndExecution;
|
|
public event EventHandler<UIMessageEvent> UIMessageEvent;
|
public event EventHandler<ExecutionEndEvent> EndExecutionEvent;
|
|
public TsExecutionWrapper()
|
{
|
AxApplicationMgr = TestAppManager.GetAxApplicationMgr();
|
//AxApplicationMgr.EndExecution += AxApplicationMgr_EndExecution;
|
//AxApplicationMgr.ExitApplication += new EventHandler(this.AxApplicationMgr_ExitApplication);
|
//AxApplicationMgr.UIMessageEvent +=
|
// new _ApplicationMgrEvents_UIMessageEventEventHandler(this.AxApplicationMgr_UIMessageEvent);
|
//AxApplicationMgr.ExecutionClosed +=
|
// new _ApplicationMgrEvents_ExecutionClosedEventHandler(this.AxApplicationMgr_ExecutionClosed);
|
}
|
|
#endregion
|
|
public object Init()
|
{
|
this.engine = this.AxApplicationMgr.GetEngine();
|
this.engine.PersistBreakpoints = false;
|
this.AxApplicationMgr.IsEditor = true;
|
this.AxApplicationMgr.LoginOnStart = false;
|
this.AxApplicationMgr.Start();
|
return this.AxApplicationMgr;
|
}
|
|
public object StartSequence(string filePath, string modelPath)
|
{
|
this.testSeqFile = filePath;
|
|
this.modeSeq = this.engine.GetSequenceFileEx(modelPath);
|
this.testSeq = this.engine.GetSequenceFileEx(this.testSeqFile, 2, TypeConflictHandlerTypes.ConflictHandler_UseGlobalType);
|
this.execution = this.engine.NewExecution(this.testSeq, "Test UUTs", this.modeSeq, false, 0, null, null, null);
|
return execution;
|
}
|
|
public T GetFileGlobalValue<T>(string key, int option)
|
{
|
if (typeof(T) == typeof(bool))
|
{
|
return (T)(object)context?.FileGlobals?.GetValBoolean(key, option);
|
}
|
else if (typeof(T) == typeof(string))
|
{
|
return (T)(object)context?.FileGlobals?.GetValString(key, option);
|
}
|
else if (typeof(T) == typeof(int))
|
{
|
return (T)(object)context?.FileGlobals?.GetValNumber(key, option);
|
}
|
else if (typeof(T) == typeof(double))
|
{
|
return (T)(object)context?.FileGlobals?.GetValNumber(key, option);
|
}
|
else if (typeof(T) == typeof(float))
|
{
|
return (T)(object)context?.FileGlobals?.GetValNumber(key, option);
|
}
|
return default(T);
|
}
|
|
public T GetStationGlobalValue<T>(string key, int option)
|
{
|
if (typeof(T) == typeof(bool))
|
{
|
return (T)(object)engine?.Globals?.GetValBoolean(key, option);
|
}
|
else if (typeof(T) == typeof(string))
|
{
|
return (T)(object)engine?.Globals?.GetValString(key, option);
|
}
|
else if (typeof(T) == typeof(int))
|
{
|
return (T)(object)engine?.Globals?.GetValNumber(key, option);
|
}
|
else if (typeof(T) == typeof(double))
|
{
|
return (T)(object)engine?.Globals?.GetValNumber(key, option);
|
}
|
else if (typeof(T) == typeof(float))
|
{
|
return (T)(object)engine?.Globals?.GetValNumber(key, option);
|
}
|
return default(T);
|
}
|
|
public void SetFileGlobalValue<T>(string key, int option, T value)
|
{
|
if (value is bool bVal)
|
{
|
context?.FileGlobals?.SetValBoolean(key, option, bVal);
|
}
|
else if (value is string sVal)
|
{
|
context?.FileGlobals?.SetValString(key, option, sVal);
|
}
|
else if (value is int iVal)
|
{
|
context?.FileGlobals?.SetValNumber(key, option, iVal);
|
}
|
else if (value is double dVal)
|
{
|
context?.FileGlobals?.SetValNumber(key, option, dVal);
|
}
|
else if (value is float fVal)
|
{
|
context?.FileGlobals?.SetValNumber(key, option, fVal);
|
}
|
}
|
|
public void SetStationGlobalValue<T>(string key, int option, T value, bool inContext = false)
|
{
|
PropertyObject obj = null;
|
if (inContext)
|
{
|
obj = context?.StationGlobals;
|
}
|
else
|
{
|
obj = engine?.Globals;
|
}
|
|
if (value is bool bVal)
|
{
|
obj?.SetValBoolean(key, option, bVal);
|
}
|
else if (value is string sVal)
|
{
|
obj?.SetValString(key, option, sVal);
|
}
|
else if (value is int iVal)
|
{
|
obj?.SetValNumber(key, option, iVal);
|
}
|
else if (value is double dVal)
|
{
|
obj?.SetValNumber(key, option, dVal);
|
}
|
else if (value is float fVal)
|
{
|
obj?.SetValNumber(key, option, fVal);
|
}
|
//engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
|
}
|
|
public void CommitToDisk(bool option)
|
{
|
engine?.CommitGlobalsToDisk(option);
|
}
|
|
public bool WaitForExit()
|
{
|
return this.execution?.WaitForEndEx(-1, true, Type.Missing, null) == true;
|
}
|
|
public bool ReleaseSeqFile()
|
{
|
if (testSeq != null)
|
{
|
return engine?.ReleaseSequenceFileEx(testSeq, 4) == true;
|
}
|
return true;
|
}
|
|
public void SetContext(object context)
|
{
|
|
}
|
}
|
}
|