using HMI.Core.Util; using HMI.ParameterManage.Entity; using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace HMI.ParameterManage.Util { /// /// TODO 优化数据源,需要支持sqlite和xml /// public class ParameterManager { /// /// 获取保存的产品 /// /// public static T GetProducts() where T : IList { string path = Path.Combine(ParameterManage.FileFolder, "Product.setting"); if (!File.Exists(path)) return default(T); T datas = XmlHelper.DeserializeFromXml(path); return datas; } /// /// 根据产品名称获取产品参数 /// /// /// public static List GetParametersByProductName(string productName) { string path = Path.Combine(ParameterManage.FileFolder, "Parameter", $"Parameter_{productName}.setting"); if (!File.Exists(path)) return new List(); List datas = XmlHelper.DeserializeFromXml>(path); return datas; } /// /// 获取通用参数 /// /// /// public static T GetCommonParameter() where T : IList { string path = Path.Combine(ParameterManage.FileFolder, "CommonParameter.setting"); if (!File.Exists(path)) return default(T); T datas = XmlHelper.DeserializeFromXml(path); return datas; } /// /// 保存通用参数 /// /// /// public static void SaveCommonParameter(IList datas) { if (datas == null) { throw new Exception("不能为null"); } string path = Path.Combine(ParameterManage.FileFolder, "CommonParameter.setting"); XmlHelper.SerializeToXml(path, datas); } } }