using HMI.Core.Entity;
|
using HMI.Core.Util;
|
using System.Collections.Generic;
|
using System.IO;
|
|
namespace HMI.Core.Manager
|
{
|
/// <summary>
|
/// TODO 优化数据源,需要支持sqlite和xml
|
/// </summary>
|
public class ProductManager
|
{
|
/// <summary>
|
/// 获取保存的产品
|
/// </summary>
|
/// <returns></returns>
|
public static T GetProducts<T>() where T : IList<ProductData>
|
{
|
string path = PathHelper.ProductDataFile;
|
if (!File.Exists(path)) return default(T);
|
T datas = XmlHelper.DeserializeFromXml<T>(path);
|
return datas;
|
}
|
|
/// <summary>
|
/// 获取保存的产品
|
/// </summary>
|
/// <returns></returns>
|
public static T GetParametersByProductName<T>(string productName) where T : IList<ParameterData>
|
{
|
string path = Path.Combine(PathHelper.ProductParameterFolder, $"Parameter_{productName}.data");
|
if (!File.Exists(path)) return default(T);
|
T datas = XmlHelper.DeserializeFromXml<T>(path);
|
return datas;
|
}
|
|
|
public static List<ProductData> GetProducts()
|
{
|
List<ProductData> datas = GetProducts<List<ProductData>>();
|
return datas ?? new List<ProductData>();
|
}
|
|
/// <summary>
|
/// 根据产品名称获取产品参数
|
/// </summary>
|
/// <param name="productName"></param>
|
/// <returns></returns>
|
public static List<ParameterData> GetParametersByProductName(string productName)
|
{
|
List<ParameterData> datas = GetParametersByProductName<List<ParameterData>>(productName);
|
return datas ?? new List<ParameterData>();
|
}
|
}
|
}
|