|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.IO;
|
|
|
using System.Reflection;
|
|
|
using Mesnac.Equips.BaseInfo;
|
|
|
using System.Xml;
|
|
|
|
|
|
namespace Mesnac.Equips.SetConfig
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 设备配置类,在平台设计环境中保存设备配置
|
|
|
/// </summary>
|
|
|
public class ConfigEquip : BaseEquip
|
|
|
{
|
|
|
#region 扩展字段
|
|
|
|
|
|
private bool _isEnableGroup = false;
|
|
|
private string _groupRange = String.Empty;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 扩展属性
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否启用设备群组
|
|
|
/// </summary>
|
|
|
public bool IsEnableGroup
|
|
|
{
|
|
|
get { return _isEnableGroup; }
|
|
|
set { _isEnableGroup = value; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 设备群组范围
|
|
|
/// </summary>
|
|
|
public string GroupRange
|
|
|
{
|
|
|
get { return _groupRange; }
|
|
|
set { _groupRange = value; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 方法重载
|
|
|
public override bool Open()
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
public override bool Read(string block, int start, int len, out object[] buff)
|
|
|
{
|
|
|
buff = null;
|
|
|
return false;
|
|
|
}
|
|
|
public override bool Write(int block, int start, object[] buff)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
public override void Close()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
public class ConfigEquipFactory
|
|
|
{
|
|
|
private string _configFile = string.Empty;
|
|
|
private string _projectWizardName = string.Empty;
|
|
|
public ConfigEquipFactory(string _configFile, string _projectWizardName)
|
|
|
{
|
|
|
this._configFile = _configFile;
|
|
|
this._projectWizardName = _projectWizardName;
|
|
|
this.AllEquips = new Dictionary<string, ConfigEquip>();
|
|
|
this.AllEquips.Clear();
|
|
|
}
|
|
|
public string ProjectWizardName { get { return _projectWizardName; } }
|
|
|
public Dictionary<string, ConfigEquip> AllEquips { get; set; }
|
|
|
|
|
|
public event EventHandler OnCurrentEquipChange;
|
|
|
public event EventHandler OnCurrentGroupChange;
|
|
|
public event EventHandler OnCurrentDataChange;
|
|
|
private ConfigEquip _currentEquip = null;
|
|
|
public ConfigEquip CurrentEquip
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _currentEquip;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
if (_currentEquip != value)
|
|
|
{
|
|
|
_currentEquip = value;
|
|
|
this.CurrentGroup = null;
|
|
|
this.CurrentData = null;
|
|
|
if (OnCurrentEquipChange != null)
|
|
|
{
|
|
|
OnCurrentEquipChange(value, EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
private Mesnac.Equips.BaseInfo.Group _currentGroup = null;
|
|
|
public Mesnac.Equips.BaseInfo.Group CurrentGroup
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _currentGroup;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
if (_currentGroup != value)
|
|
|
{
|
|
|
_currentGroup = value;
|
|
|
this.CurrentData = null;
|
|
|
if (OnCurrentGroupChange != null)
|
|
|
{
|
|
|
OnCurrentEquipChange(value, EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
private Mesnac.Equips.BaseInfo.Data _currentData = null;
|
|
|
public Mesnac.Equips.BaseInfo.Data CurrentData
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _currentData;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
if (_currentData != value)
|
|
|
{
|
|
|
_currentData = value;
|
|
|
}
|
|
|
if (OnCurrentDataChange != null)
|
|
|
{
|
|
|
OnCurrentDataChange(value, EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void SaveConfig()
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(_configFile))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(_configFile)))
|
|
|
{
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(_configFile));
|
|
|
}
|
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
|
XmlTextWriter xtw = new XmlTextWriter(_configFile, Encoding.UTF8);
|
|
|
xtw.WriteStartDocument();
|
|
|
xtw.WriteStartElement("EquipFactory");
|
|
|
xtw.WriteEndElement();
|
|
|
xtw.WriteEndDocument();
|
|
|
xtw.Close();
|
|
|
xmlDocument.Load(_configFile);
|
|
|
XmlNode xn = xmlDocument.DocumentElement;
|
|
|
foreach (ConfigEquip equip in this.AllEquips.Values)
|
|
|
{
|
|
|
XmlElement xe_equip = xmlDocument.CreateElement("Equip");
|
|
|
xe_equip.SetAttribute("name", equip.Name.Trim());
|
|
|
if (equip.Project == null)
|
|
|
{
|
|
|
xe_equip.SetAttribute("project", string.Empty);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
xe_equip.SetAttribute("project", equip.Project.Trim());
|
|
|
}
|
|
|
|
|
|
#region 郑立兵于2015-01-19增加,用于保存群组设备的配置至配置文件中
|
|
|
if (equip.IsEnableGroup)
|
|
|
{
|
|
|
xe_equip.SetAttribute("isEnableGroup", "True");
|
|
|
if (String.IsNullOrEmpty(equip.GroupRange))
|
|
|
{
|
|
|
xe_equip.SetAttribute("groupRange", "1");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
xe_equip.SetAttribute("groupRange", equip.GroupRange.Trim());
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
xn.AppendChild(xe_equip);
|
|
|
#region Main
|
|
|
XmlElement xe_main = xmlDocument.CreateElement("Main");
|
|
|
xe_equip.AppendChild(xe_main);
|
|
|
XmlElement xe_main_child = xmlDocument.CreateElement("Brand");
|
|
|
xe_main_child.SetAttribute("value", equip.Main.Brand);
|
|
|
xe_main.AppendChild(xe_main_child);
|
|
|
xe_main_child = xmlDocument.CreateElement("Model");
|
|
|
xe_main_child.SetAttribute("value", equip.Main.Model);
|
|
|
xe_main.AppendChild(xe_main_child);
|
|
|
xe_main_child = xmlDocument.CreateElement("ReadHz");
|
|
|
xe_main_child.SetAttribute("value", equip.Main.ReadHz.ToString());
|
|
|
xe_main.AppendChild(xe_main_child);
|
|
|
xe_main_child = xmlDocument.CreateElement("UnitLen");
|
|
|
xe_main_child.SetAttribute("value", equip.Main.UnitLen.ToString());
|
|
|
xe_main.AppendChild(xe_main_child);
|
|
|
xe_main_child = xmlDocument.CreateElement("Connection");
|
|
|
xe_main_child.SetAttribute("mode", equip.Main.ConnType.Name.ToString());
|
|
|
xe_main.AppendChild(xe_main_child);
|
|
|
#region 连接属性
|
|
|
PropertyInfo[] piList = (equip.Main.ConnType.GetType()).GetProperties();
|
|
|
foreach (PropertyInfo pi in piList)
|
|
|
{
|
|
|
if (pi.Name.Equals("Name", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("Connection", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
XmlElement xe_info = xmlDocument.CreateElement(pi.Name);
|
|
|
string ssValue = string.Empty;
|
|
|
if (pi.GetValue(equip.Main.ConnType, null) != null)
|
|
|
{
|
|
|
ssValue = pi.GetValue(equip.Main.ConnType, null).ToString();
|
|
|
}
|
|
|
xe_info.SetAttribute("value", ssValue.Trim());
|
|
|
xe_main_child.AppendChild(xe_info);
|
|
|
}
|
|
|
#endregion
|
|
|
#endregion
|
|
|
#region Group
|
|
|
XmlElement xe_groups = xmlDocument.CreateElement("Group");
|
|
|
xe_equip.AppendChild(xe_groups);
|
|
|
foreach (Group group in equip.Group.Values)
|
|
|
{
|
|
|
XmlElement xe_group = xmlDocument.CreateElement("Group");
|
|
|
xe_groups.AppendChild(xe_group);
|
|
|
PropertyInfo[] group_pilst = (group.GetType()).GetProperties();
|
|
|
foreach (PropertyInfo pi in group_pilst)
|
|
|
{
|
|
|
if (pi.Name.Equals("value", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("Data", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("equip", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
xe_group.SetAttribute(pi.Name.ToLower(), pi.GetValue(group, null).ToString().Trim());
|
|
|
}
|
|
|
XmlElement xe_datas = xmlDocument.CreateElement("Data");
|
|
|
xe_group.AppendChild(xe_datas);
|
|
|
foreach (Data data in group.Data.Values)
|
|
|
{
|
|
|
XmlElement xe_data = xmlDocument.CreateElement("Data");
|
|
|
xe_datas.AppendChild(xe_data);
|
|
|
PropertyInfo[] data_pilst = (data.GetType()).GetProperties();
|
|
|
foreach (PropertyInfo pi in data_pilst)
|
|
|
{
|
|
|
if (pi.Name.Equals("value", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("group", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("ReadTime", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("LastBeforeMathValue", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (pi.Name.Equals("keyname", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
string ssValue = string.Empty;
|
|
|
if (pi.GetValue(data, null) != null)
|
|
|
{
|
|
|
ssValue = pi.GetValue(data, null).ToString();
|
|
|
}
|
|
|
xe_data.SetAttribute(pi.Name.ToLower(), ssValue.Trim());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
xmlDocument.Save(_configFile);
|
|
|
}
|
|
|
|
|
|
|
|
|
private bool GetNodeAttributeValue(XmlNode node, string attribute, bool throwException, out string value)
|
|
|
{
|
|
|
value = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
XmlAttribute a = node.Attributes[attribute.ToLower()];
|
|
|
if (a != null && a.Value != null)
|
|
|
{
|
|
|
value = a.Value.ToString().Trim();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
if (throwException)
|
|
|
{
|
|
|
throw (ex);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
private bool GetFirstNodeValue(XmlNode node, string path, string attribute, bool throwException, out string value)
|
|
|
{
|
|
|
value = string.Empty;
|
|
|
try
|
|
|
{
|
|
|
XmlNode a = node.SelectSingleNode(path);
|
|
|
if (a != null)
|
|
|
{
|
|
|
GetNodeAttributeValue(a, attribute, throwException, out value);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
if (throwException)
|
|
|
{
|
|
|
throw (ex);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private readonly string _deviceBasePath = "\\Data\\DeviceConfig"; //设备接口基本目录
|
|
|
private BaseEquip ToEquip(BaseEquip baseEquip)
|
|
|
{
|
|
|
string thisPath = this.GetType().Assembly.Location;
|
|
|
string assPath = (new FileInfo(thisPath)).Directory + this._deviceBasePath + "\\Mesnac.Equips\\";
|
|
|
string dllName = "Mesnac.Equip." + baseEquip.Main.Brand.Trim();
|
|
|
string path = assPath + dllName + "\\" + dllName + ".dll";
|
|
|
string className = "Mesnac.Equip." + baseEquip.Main.Brand.Trim() + "."
|
|
|
+ baseEquip.Main.Model.Trim() + "."
|
|
|
+ baseEquip.Main.ConnType.Name.Trim() + ".Equip";
|
|
|
if (!File.Exists(path))
|
|
|
{
|
|
|
return baseEquip;
|
|
|
}
|
|
|
Assembly ass = Assembly.LoadFile(path);
|
|
|
if (ass == null)
|
|
|
{
|
|
|
return baseEquip;
|
|
|
}
|
|
|
Type type = ass.GetType(className);
|
|
|
if (type == null)
|
|
|
{
|
|
|
return baseEquip;
|
|
|
}
|
|
|
|
|
|
var obj = ass.CreateInstance(className, true);
|
|
|
BaseEquip to = (BaseEquip)Activator.CreateInstance(type);
|
|
|
if (to == null)
|
|
|
{
|
|
|
return baseEquip;
|
|
|
}
|
|
|
to.Name = baseEquip.Name;
|
|
|
to.Project = baseEquip.Project;
|
|
|
to.Main = baseEquip.Main;
|
|
|
to.Group = baseEquip.Group;
|
|
|
foreach (Group group in to.Group.Values)
|
|
|
{
|
|
|
group.Equip = to;
|
|
|
}
|
|
|
return to;
|
|
|
}
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="isConfigEquip"></param>
|
|
|
/// <returns></returns>
|
|
|
private Dictionary<string, BaseEquip> ReadBaseEquip(bool isConfigEquip)
|
|
|
{
|
|
|
Dictionary<string, BaseEquip> Result = new Dictionary<string, BaseEquip>();
|
|
|
if (!File.Exists(this._configFile))
|
|
|
{
|
|
|
return Result;
|
|
|
}
|
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
|
xmlDocument.Load(this._configFile);
|
|
|
foreach (XmlNode factoryNode in xmlDocument)
|
|
|
{
|
|
|
if (factoryNode.Name == "EquipFactory")
|
|
|
{
|
|
|
foreach (XmlNode EquipNode in factoryNode.ChildNodes)
|
|
|
{
|
|
|
string equipNameStr = EquipNode.Attributes["name"].Value.ToString();
|
|
|
ParseEquip(equipNameStr, isConfigEquip, Result, EquipNode);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return Result;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 从Xml配置文件中解析设备
|
|
|
/// </summary>
|
|
|
/// <param name="equipName"></param>
|
|
|
/// <param name="isConfigEquip"></param>
|
|
|
/// <param name="Result"></param>
|
|
|
/// <param name="EquipNode"></param>
|
|
|
private void ParseEquip(string equipName, bool isConfigEquip, Dictionary<string, BaseEquip> Result, XmlNode EquipNode)
|
|
|
{
|
|
|
ConfigEquip equip = new ConfigEquip();
|
|
|
equip.Name = equipName;
|
|
|
equip.Project = EquipNode.Attributes["project"].Value.ToString();
|
|
|
|
|
|
#region 郑立兵于2014-01-19扩展,用于解析设备的群组配置
|
|
|
|
|
|
if (null == EquipNode.Attributes["isEnableGroup"] || String.IsNullOrEmpty(EquipNode.Attributes["isEnableGroup"].Value))
|
|
|
{
|
|
|
equip.IsEnableGroup = false;
|
|
|
equip.GroupRange = String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string strIsEnableGroup = EquipNode.Attributes["isEnableGroup"].Value.Trim();
|
|
|
bool isEnableGroup = false;
|
|
|
bool.TryParse(strIsEnableGroup, out isEnableGroup);
|
|
|
equip.IsEnableGroup = isEnableGroup;
|
|
|
if (null == EquipNode.Attributes["groupRange"])
|
|
|
{
|
|
|
equip.GroupRange = String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string strGroupRange = EquipNode.Attributes["groupRange"].Value.Trim();
|
|
|
if (!String.IsNullOrEmpty(strGroupRange))
|
|
|
{
|
|
|
equip.GroupRange = strGroupRange;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Main
|
|
|
string ss = string.Empty;
|
|
|
equip.Main.Equip = equip;
|
|
|
GetFirstNodeValue(EquipNode, ".//Main//Brand[@value]", "value", true, out ss);
|
|
|
equip.Main.Brand = ss;
|
|
|
GetFirstNodeValue(EquipNode, ".//Main//Model[@value]", "value", true, out ss);
|
|
|
equip.Main.Model = ss;
|
|
|
GetFirstNodeValue(EquipNode, ".//Main//ReadHz[@value]", "value", true, out ss);
|
|
|
int strToInt = 0;
|
|
|
if (int.TryParse(ss, out strToInt))
|
|
|
{
|
|
|
equip.Main.ReadHz = strToInt;
|
|
|
}
|
|
|
GetFirstNodeValue(EquipNode, ".//Main//UnitLen[@value]", "value", true, out ss);
|
|
|
strToInt = 0;
|
|
|
if (int.TryParse(ss, out strToInt))
|
|
|
{
|
|
|
equip.Main.UnitLen = strToInt;
|
|
|
}
|
|
|
GetFirstNodeValue(EquipNode, ".//Main//Connection[@mode]", "mode", true, out ss);
|
|
|
equip.Main.ConnType = Mesnac.Equips.Connection.Factory.Instance.GetConfig(EquipNode.SelectNodes(".//Main//Connection[@mode]")[0]);
|
|
|
|
|
|
//add by yinzf 2017-07-03 如果是default格式,填写ip地址信息
|
|
|
//var Conntype=equip.Main.ConnType as Mesnac.Equips.Connection.Default.ConnType;
|
|
|
//if(Conntype!=null)
|
|
|
//{
|
|
|
// GetFirstNodeValue(EquipNode, ".//Main//Connection//IP[@value]", "value", true, out ss);
|
|
|
// Conntype.IP=ss;
|
|
|
// equip.Main.ConnType=Conntype;
|
|
|
//}
|
|
|
//end add
|
|
|
#endregion
|
|
|
#region Group
|
|
|
XmlNodeList groupNodes = EquipNode.SelectNodes(".//Group")[0].ChildNodes;
|
|
|
foreach (XmlNode groupNode in groupNodes)
|
|
|
{
|
|
|
Group group = new Group();
|
|
|
group.Equip = equip;
|
|
|
GetNodeAttributeValue(groupNode, "name", true, out ss);
|
|
|
group.Name = ss;
|
|
|
GetNodeAttributeValue(groupNode, "remark", false, out ss);
|
|
|
group.Remark = ss;
|
|
|
GetNodeAttributeValue(groupNode, "start", true, out ss);
|
|
|
group.Start = Convert.ToInt32(ss);
|
|
|
GetNodeAttributeValue(groupNode, "block", true, out ss);
|
|
|
group.Block = ss;
|
|
|
GetNodeAttributeValue(groupNode, "len", true, out ss);
|
|
|
group.Len = Convert.ToInt32(ss);
|
|
|
GetNodeAttributeValue(groupNode, "isautoread", false, out ss);
|
|
|
group.IsAutoRead = true;
|
|
|
if (ss.ToLower() == "false" ||
|
|
|
ss == "0")
|
|
|
{
|
|
|
group.IsAutoRead = false;
|
|
|
}
|
|
|
GetNodeAttributeValue(groupNode, "access", false, out ss);
|
|
|
group.Access = System.IO.FileAccess.ReadWrite;
|
|
|
if (string.IsNullOrEmpty(ss))
|
|
|
{
|
|
|
ss = "ReadWrite";
|
|
|
}
|
|
|
if (ss.Equals("Read", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
group.Access = System.IO.FileAccess.Read;
|
|
|
}
|
|
|
if (ss.Equals("Write", StringComparison.CurrentCultureIgnoreCase))
|
|
|
{
|
|
|
group.Access = System.IO.FileAccess.Write;
|
|
|
}
|
|
|
equip.Group.Add(group.Name, group);
|
|
|
|
|
|
#region Data
|
|
|
XmlNodeList dataNodes = groupNode.SelectNodes(".//Data")[0].ChildNodes;
|
|
|
foreach (XmlNode node in dataNodes)
|
|
|
{
|
|
|
Data data = new Data();
|
|
|
data.Group = group;
|
|
|
GetNodeAttributeValue(node, "name", true, out ss);
|
|
|
data.Name = ss;
|
|
|
data.KeyName = equip.Name + "." + group.Name + "." + data.Name;
|
|
|
GetNodeAttributeValue(node, "remark", false, out ss);
|
|
|
data.Remark = ss;
|
|
|
GetNodeAttributeValue(node, "runname", false, out ss);
|
|
|
data.RunName = ss;
|
|
|
if (GetNodeAttributeValue(node, "max", false, out ss))
|
|
|
{
|
|
|
double d = 0;
|
|
|
if (double.TryParse(ss, out d))
|
|
|
{
|
|
|
data.Max = d.ToString();
|
|
|
}
|
|
|
}
|
|
|
if (GetNodeAttributeValue(node, "subtractor", false, out ss))
|
|
|
{
|
|
|
double d = 0;
|
|
|
if (double.TryParse(ss, out d))
|
|
|
{
|
|
|
data.Subtractor = d.ToString();
|
|
|
}
|
|
|
}
|
|
|
GetNodeAttributeValue(node, "start", true, out ss);
|
|
|
data.Start = Convert.ToInt32(ss);
|
|
|
GetNodeAttributeValue(node, "len", true, out ss);
|
|
|
data.Len = Convert.ToInt32(ss);
|
|
|
GetNodeAttributeValue(node, "method", false, out ss);
|
|
|
data.Method = ss;
|
|
|
GetNodeAttributeValue(node, "issave", false, out ss);
|
|
|
if (!string.IsNullOrWhiteSpace(ss))
|
|
|
{
|
|
|
data.IsSave = ss.ToLower().Trim() == "true";
|
|
|
}
|
|
|
group.Data.Add(data.Name, data);
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 郑立兵于2014-01-19修改,用于解析设备群组,通过一个设备组配置,生成多个设备
|
|
|
|
|
|
if (!isConfigEquip)
|
|
|
{
|
|
|
BaseEquip baseEquip = ToEquip(equip as BaseEquip);
|
|
|
|
|
|
if (equip.IsEnableGroup)
|
|
|
{
|
|
|
string[] nameIndexes = EquipTools.GetNameIndexFromRange(equip.GroupRange);
|
|
|
if (nameIndexes != null && nameIndexes.Length > 0)
|
|
|
{
|
|
|
foreach (string nameIndex in nameIndexes)
|
|
|
{
|
|
|
string keyName = equip.Name + nameIndex;
|
|
|
BaseEquip newEquip = new ConfigEquip();
|
|
|
newEquip.Name = keyName;
|
|
|
newEquip.Project = equip.Project;
|
|
|
newEquip.Main.Brand = equip.Main.Brand;
|
|
|
newEquip.Main.ConnType = equip.Main.ConnType;
|
|
|
newEquip.Main.Model = equip.Main.Model;
|
|
|
newEquip.Main.ReadHz = equip.Main.ReadHz;
|
|
|
newEquip.Main.UnitLen = equip.Main.UnitLen;
|
|
|
newEquip.Main.Equip = newEquip;
|
|
|
|
|
|
newEquip = ToEquip(newEquip);
|
|
|
|
|
|
foreach (string groupkey in equip.Group.Keys)
|
|
|
{
|
|
|
Group g = new Group();
|
|
|
g.Access = equip.Group[groupkey].Access;
|
|
|
g.Block = equip.Group[groupkey].Block;
|
|
|
g.Equip = newEquip;
|
|
|
g.IsAutoRead = equip.Group[groupkey].IsAutoRead;
|
|
|
g.Len = equip.Group[groupkey].Len;
|
|
|
g.Name = equip.Group[groupkey].Name;
|
|
|
g.Remark = equip.Group[groupkey].Remark;
|
|
|
g.Start = equip.Group[groupkey].Start;
|
|
|
//g.Value = equip.Group[groupkey].Value;
|
|
|
|
|
|
foreach (string datakey in equip.Group[groupkey].Data.Keys)
|
|
|
{
|
|
|
Data d = new Data();
|
|
|
d.Group = g;
|
|
|
d.IsSave = equip.Group[groupkey].Data[datakey].IsSave;
|
|
|
d.KeyName = newEquip.Name + equip.Group[groupkey].Data[datakey].KeyName.Substring(equip.Group[groupkey].Data[datakey].KeyName.IndexOf("."));
|
|
|
d.LastBeforeMathValue = equip.Group[groupkey].Data[datakey].LastBeforeMathValue;
|
|
|
d.Len = equip.Group[groupkey].Data[datakey].Len;
|
|
|
d.Max = equip.Group[groupkey].Data[datakey].Max;
|
|
|
d.Method = equip.Group[groupkey].Data[datakey].Method;
|
|
|
d.Name = equip.Group[groupkey].Data[datakey].Name;
|
|
|
d.ReadTime = equip.Group[groupkey].Data[datakey].ReadTime;
|
|
|
d.Remark = equip.Group[groupkey].Data[datakey].Remark;
|
|
|
d.RunName = equip.Group[groupkey].Data[datakey].RunName;
|
|
|
d.Start = equip.Group[groupkey].Data[datakey].Start;
|
|
|
d.Subtractor = equip.Group[groupkey].Data[datakey].Subtractor;
|
|
|
//d.Value = equip.Group[groupkey].Data[datakey].Value;
|
|
|
g.Data.Add(datakey, d);
|
|
|
}
|
|
|
|
|
|
newEquip.Group.Add(groupkey, g);
|
|
|
}
|
|
|
|
|
|
|
|
|
Result.Add(keyName, newEquip);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Result.Add(equip.Name, equip);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Result.Add(baseEquip.Name, baseEquip);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Result.Add(equip.Name, equip);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
public void ReadConfig()
|
|
|
{
|
|
|
if (!File.Exists(_configFile))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
this.AllEquips.Clear();
|
|
|
this.CurrentEquip = null;
|
|
|
this.CurrentGroup = null;
|
|
|
this.CurrentData = null;
|
|
|
Dictionary<string, BaseEquip> Result = new Dictionary<string, BaseEquip>();
|
|
|
Result = ReadBaseEquip(true);
|
|
|
foreach (BaseEquip baseEquip in Result.Values)
|
|
|
{
|
|
|
this.AllEquips.Add(baseEquip.Name, (ConfigEquip)baseEquip);
|
|
|
}
|
|
|
}
|
|
|
public Dictionary<string, BaseEquip> GetBaseEquip()
|
|
|
{
|
|
|
Dictionary<string, BaseEquip> Result = new Dictionary<string, BaseEquip>();
|
|
|
if (!File.Exists(_configFile))
|
|
|
{
|
|
|
return Result;
|
|
|
}
|
|
|
Result = ReadBaseEquip(false);
|
|
|
return Result;
|
|
|
}
|
|
|
|
|
|
public Dictionary<string, ConfigEquip> GetAllConfigEquip()
|
|
|
{
|
|
|
if (File.Exists(_configFile))
|
|
|
{
|
|
|
this.AllEquips.Clear();
|
|
|
this.CurrentEquip = null;
|
|
|
this.CurrentGroup = null;
|
|
|
this.CurrentData = null;
|
|
|
Dictionary<string, BaseEquip> Result = new Dictionary<string, BaseEquip>();
|
|
|
Result = ReadBaseEquip(true);
|
|
|
foreach (BaseEquip baseEquip in Result.Values)
|
|
|
{
|
|
|
this.AllEquips.Add(baseEquip.Name, (ConfigEquip)baseEquip);
|
|
|
}
|
|
|
}
|
|
|
return this.AllEquips;
|
|
|
}
|
|
|
}
|
|
|
}
|