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 作为历史根节点
---
SimpleUtil/HMI.TapApi/ProductUtil.cs | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 164 insertions(+), 0 deletions(-)
diff --git a/SimpleUtil/HMI.TapApi/ProductUtil.cs b/SimpleUtil/HMI.TapApi/ProductUtil.cs
new file mode 100644
index 0000000..54a0877
--- /dev/null
+++ b/SimpleUtil/HMI.TapApi/ProductUtil.cs
@@ -0,0 +1,164 @@
+锘縰sing HMI.Simple.Util;
+using OpenTap;
+using OpenTap.Addin.Util;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace HMI.TapApi
+{
+ public class ProductUtil
+ {
+ private static void WriteParameterData(object instance, ParameterData data)
+ {
+ TestPlanRun context = (TestPlanRun)instance;
+ string name = $"DUTSetting.{data.Name}";
+ if (data.IsArray)
+ {
+ Type type;
+ if (data.Type == "Bool")
+ {
+ type = typeof(bool);
+ }
+ else if (data.Type == "Int")
+ {
+ type = typeof(int);
+ }
+ else if (data.Type == "Double")
+ {
+ type = typeof(double);
+ }
+ else
+ {
+ type = typeof(string);
+ }
+ string[] arr = data.Value?.Split(',') ?? new string[0];
+ if (arr.Length > 0)
+ {
+ //RuntimeVariable rv;
+ //if (data.Type == "Int")
+ //{
+ // int[] values = arr.Select(a => int.Parse(a)).ToArray();
+ // rv = new RuntimeVariable(context, name, values);
+ //}
+ //if (data.Type == "Double")
+ //{
+ // double[] values = arr.Select(a => double.Parse(a)).ToArray();
+ // rv = new RuntimeVariable(context, name, values);
+ //}
+ //if (data.Type == "Bool")
+ //{
+ // bool[] values = arr.Select(a => bool.Parse(a)).ToArray();
+ // rv = new RuntimeVariable(context, name, values);
+ //}
+ //else
+ //{
+ // rv = new RuntimeVariable(context, name, arr);
+ //}
+
+ if (data.Type == "Int")
+ {
+ int[] values = arr.Select(a => int.Parse(a)).ToArray();
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", values);
+ }
+ if (data.Type == "Double")
+ {
+ double[] values = arr.Select(a => double.Parse(a)).ToArray();
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", values);
+ }
+ if (data.Type == "Bool")
+ {
+ bool[] values = arr.Select(a => bool.Parse(a)).ToArray();
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", values);
+ }
+ else
+ {
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", arr);
+ }
+ }
+ }
+ else
+ {
+ if (data.Type == "Bool")
+ {
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", bool.Parse(data.Value));
+ }
+ else if (data.Type == "Int")
+ {
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", int.Parse(data.Value));
+ }
+ else if (data.Type == "Double")
+ {
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", double.Parse(data.Value));
+ }
+ else
+ {
+ context.Update(null, $"{ConstNames.FileGlobalsName}.{name}", data.Value);
+ }
+ }
+ }
+
+ private static string GetDataFilePath()
+ {
+ string path = ParameterUtil.GetCommonParameterValue("ShareConfig", out _);
+ if (string.IsNullOrEmpty(path))
+ {
+ path = Path.Combine(HMI.Simple.Util.RegUtil.GetLocaltion(), "Config");
+ }
+ return path;
+ }
+
+ /// <summary>
+ /// 鏍规嵁浜у搧鍨嬪彿鍐欓厤缃�
+ /// </summary>
+ /// <param name="model">浜у搧鍨嬪彿</param>
+ /// <param name="instance">TestStand涓婁笅鏂�</param>
+ /// <param name="errMsg">寮傚父淇℃伅</param>
+ /// <returns>鏄惁鎴愬姛</returns>
+ public static bool WriteConfigToContextByModel(string model, object instance, out string errMsg)
+ {
+ errMsg = string.Empty;
+ try
+ {
+ string path = Path.Combine(GetDataFilePath(), "Product", "Parameter", $"Parameter_{model}.data");
+ return WriteConfigToContextByPath(path, instance, out errMsg);
+ }
+ catch (Exception ex)
+ {
+ errMsg = ex.Message;
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// 鏍规嵁璺緞鍐欓厤缃�
+ /// </summary>
+ /// <param name="path">缁濆璺緞</param>
+ /// <param name="instance">TestStand涓婁笅鏂�</param>
+ /// <param name="errMsg">寮傚父淇℃伅</param>
+ /// <returns>鏄惁鎴愬姛</returns>
+ public static bool WriteConfigToContextByPath(string path, object instance, out string errMsg)
+ {
+ errMsg = string.Empty;
+ try
+ {
+ if (!File.Exists(path))
+ {
+ throw new Exception($"鏈壘鍒拌閰嶇疆[{path}]锛岃妫�鏌�");
+ }
+ List<ParameterData> datas = XmlHelper.DeserializeFromXml<List<ParameterData>>(path);
+ foreach (var data in datas)
+ {
+ WriteParameterData(instance, data);
+ }
+ return true;
+ }
+ catch (Exception ex)
+ {
+ errMsg = ex.Message;
+ return false;
+ }
+ }
+ }
+}
--
Gitblit v1.9.1