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