You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Mesnac.Compressor.Entity;
namespace SocketProcess
{
public class TrayFactory
{
#region 单例模式
private static TrayFactory _trayFactory;
private static readonly object sysany = new object();
public static TrayFactory Instance
{
get
{
if (_trayFactory == null)
{
lock(sysany)
{
_trayFactory = new TrayFactory();
}
}
return _trayFactory;
}
}
#endregion
public List<SocketEqiup> SocketEquipList = new List<SocketEqiup>();
private TrayFactory()
{
XmlRead();
}
public void Init()
{
//XmlRead();
//InitSerial();
}
private void XmlRead()
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Config.xml"); //加载xml文件
XmlNode xn = xmlDoc.SelectSingleNode("Setting/Socket");
if (xn == null)
{
return;
}
XmlNodeList xnl = xn.ChildNodes;
foreach (XmlNode xnf in xnl)
{
XmlElement xe = (XmlElement)xnf;
XmlNodeList xnf1 = xe.ChildNodes;
SocketEqiup Socket = new SocketEqiup();
foreach (XmlNode xn2 in xnf1)
{
//Console.WriteLine(xn2.InnerText);//显示子节点点文本
XmlElement xmm = (XmlElement)xn2;
if (xmm.Name == "IP")
{
Socket.IP = xmm.InnerText;
continue;
}
else if (xmm.Name == "Port")
{
Socket.Port = xmm.InnerText;
continue;
}
else if (xmm.Name == "Type")
{
Socket.EquipType = (EquipType)Convert.ToInt32(xmm.InnerText);
continue;
}
}
SocketEquipList.Add(Socket);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}