alielie
2025-11-21 3a471ae651b228231bebb3a2d438baa1d4ac0261
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using HMI.Core.Entity;
using HMI.Core.Util;
using System;
using System.Collections.Generic;
using System.IO;
 
namespace HMI.Core.Manager
{
    /// <summary>
    /// TODO 优化数据源,需要支持sqlite和xml
    /// </summary>
    public class TestItemManager
    {
        /// <summary>
        /// 根据产品获取测试项
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T GetTestItemByProduct<T>(string product) where T : IList<TestItemData>
        {
            string path = Path.Combine(PathHelper.TestItemDataFolder, $"TestItem_{product}.setting");
            if (!File.Exists(path)) return default(T);
            T datas = XmlHelper.DeserializeFromXml<T>(path);
            return datas;
        }
 
        /// <summary>
        /// 根据产品保存测试项
        /// </summary>
        /// <param name="datas"></param>
        /// <exception cref="Exception"></exception>
        public static void SaveTestItemByProduct(string product, IList<TestItemData> datas)
        {
            if (datas == null)
            {
                throw new Exception("不能为null");
            }
            string path = Path.Combine(PathHelper.TestItemDataFolder, $"TestItem_{product}.setting");
            XmlHelper.SerializeToXml(path, datas);
        }
 
    }
}