From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 Plugin.TsSupport/TapWrapper.cs |  237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 237 insertions(+), 0 deletions(-)

diff --git a/Plugin.TsSupport/TapWrapper.cs b/Plugin.TsSupport/TapWrapper.cs
new file mode 100644
index 0000000..c676291
--- /dev/null
+++ b/Plugin.TsSupport/TapWrapper.cs
@@ -0,0 +1,237 @@
+锘縰sing AddInPlugin;
+using AddInPlugin.Util;
+using Microsoft.Win32;
+using OpenTap;
+using OpenTap.Addin;
+using OpenTap.Addin.Listener;
+using OpenTap.Addin.Reader;
+using OpenTap.Addin.Util;
+using OpenTap.Plugins.BasicSteps;
+using System;
+using System.ComponentModel;
+using System.IO;
+using System.Windows;
+using System.Windows.Threading;
+
+namespace Plugin.TsSupport
+{
+    public class Net47Getter : IRegGetter
+    {
+        public string GetAppPath(string keyPath)
+        {
+            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath))
+            {
+                if (key == null)
+                {
+                    throw new Exception("娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆$紪杈戝櫒");
+                }
+
+                string value = key.GetValue("Location")?.ToString();
+                if (string.IsNullOrEmpty(value))
+                {
+                    throw new Exception("娉ㄥ唽琛ㄤ笉瀛樺湪锛岃鍏堣繍琛屼竴娆$紪杈戝櫒");
+                }
+                return value;
+            }
+        }
+    }
+
+    public class TapWrapper : ITestExecutionWrapper, IResultListener, IUserInputInterface
+    {
+        TapThread testPlanThread;
+        TestPlan Plan;
+        TestPlanRun PlanRun;
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        public event EventHandler<UIMessageEvent> UIMessageEvent;
+        public event EventHandler<ExecutionEndEvent> EndExecutionEvent;
+
+        private PostUIMessageHandler uIMessageHandler;
+
+        public string Name { get; set; }
+
+        public bool IsConnected => true;
+
+        static TapWrapper()
+        {
+            RegUtil.Register(new Net47Getter());
+        }
+
+        public object Init()
+        {
+            StationGlobalsManager.Register(new DefaultStationGlobalsManager());
+            VariableResolverFactory.Register(new DefaultVariableResolverFactory());
+            ResultSettings.Current.Add(this);
+            UserInput.SetInterface(this);
+            LvlibpLoader.PreLoad();
+            PropertyInfoCache.Refresh(typeof(MethodVariable));
+            uIMessageHandler = PostUIMessageHandler.Get();
+            uIMessageHandler.OnPostUIMsg += PostUIMsgHandler_OnPostUIMsg;
+            return null;
+        }
+
+        private void PostUIMsgHandler_OnPostUIMsg(object sender, PostUIMsg e)
+        {
+            UIMessageEvent?.Invoke(this, new UIMessageEvent()
+            {
+                Origin = e,
+                EventCode = e.EventCode,
+                BoolData = e.BoolData,
+                NumberData = e.NumberData,
+                StrData = e.StringData
+            });
+        }
+
+        public object StartSequence(string filePath, string modelPath)
+        {
+            Plan = TestPlanReader.ReadTestPlan(filePath);
+            //Plan = TestPlan.Load(filePath);
+            testPlanThread = TapThread.Start(() =>
+            {
+                var res = ResultSettings.Current;
+                res.Add(uIMessageHandler);
+                Plan.Execute(ResultSettings.Current);
+            });
+            return Plan;
+        }
+
+
+        public T GetFileGlobalValue<T>(string key, int option)
+        {
+            return PlanRun.Resolve<T>(null, $"FileGlobals.{key}");
+        }
+
+        public T GetStationGlobalValue<T>(string key, int option)
+        {
+            if (PlanRun == null)
+            {
+                return StationGlobalsManager.GetValue<T>(key);
+            }
+            return PlanRun.Resolve<T>(null, $"StationGlobals.{key}");
+        }
+
+        public T GetValue<T>(string key, int option)
+        {
+            return default(T);
+        }
+
+        public void SetValue<T>(string key, T value, int option)
+        {
+
+        }
+
+        public void SetFileGlobalValue<T>(string key, int option, T value)
+        {
+            PlanRun.Update(null, $"FileGlobals.{key}", value);
+        }
+
+        public void SetStationGlobalValue<T>(string key, int option, T value, bool inContext = false)
+        {
+            if (PlanRun == null)
+            {
+                StationGlobalsManager.SetValue(key, value);
+            }
+            else
+            {
+                PlanRun.Update(null, $"StationGlobals.{key}", value);
+            }
+        }
+
+        public void CommitToDisk(bool option)
+        {
+            StationGlobalsManager.WriteToLocal(null);
+        }
+
+        public void OnTestPlanRunStart(TestPlanRun planRun)
+        {
+            PlanRun = planRun;
+        }
+
+        public void OnTestPlanRunCompleted(TestPlanRun planRun, Stream logStream)
+        {
+            PlanRun = null;
+        }
+
+        public void OnTestStepRunStart(TestStepRun stepRun)
+        {
+
+        }
+
+        public void OnTestStepRunCompleted(TestStepRun stepRun)
+        {
+
+        }
+
+        public void OnResultPublished(Guid stepRunID, ResultTable result)
+        {
+
+        }
+
+        public void Open()
+        {
+
+        }
+
+        public void Close()
+        {
+            EndExecutionEvent?.Invoke(this, new ExecutionEndEvent());
+            Plan = null;
+            PlanRun = null;
+            testPlanThread = null;
+        }
+
+        public bool WaitForExit()
+        {
+            return true;
+        }
+
+        public bool ReleaseSeqFile()
+        {
+            return true;
+        }
+
+        public void Dispose()
+        {
+        }
+
+        public void SetContext(object context)
+        {
+
+        }
+
+        public DispatcherObject ui { get; private set; }
+
+        public void RegisteUserInput(DispatcherObject ui)
+        {
+            this.ui = ui;
+        }
+
+        public void RequestUserInput(object dataObject, TimeSpan Timeout, bool modal)
+        {
+            if (dataObject is DialogRequest req)
+            {
+                this.ui?.Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    if (req.Buttons == InputButtons.OkCancel)
+                    {
+                        var res = MessageBox.Show(req.Message, req.Name, MessageBoxButton.OKCancel);
+                        req.Input2 = res == MessageBoxResult.OK ? WaitForInputResult2.Ok : WaitForInputResult2.Cancel;
+                    }
+                    else
+                    {
+                        var res = MessageBox.Show(req.Message, req.Name, MessageBoxButton.YesNo);
+                        req.Input1 = res == MessageBoxResult.Yes ? WaitForInputResult1.Yes : WaitForInputResult1.No;
+                    }
+                })).Wait();
+            }
+            else if (dataObject is OpenTap.TestPlan.PlanLoadError err)
+            {
+                this.ui?.Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    var res = MessageBox.Show(err.Message, err.Name, MessageBoxButton.OKCancel);
+                    err.Response = res == MessageBoxResult.OK ? TestPlan.PlanLoadErrorResponse.Ignore : TestPlan.PlanLoadErrorResponse.Abort;
+                })).Wait();
+            }
+        }
+    }
+}

--
Gitblit v1.9.1