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.
99 lines
2.7 KiB
C#
99 lines
2.7 KiB
C#
using HighWayIot.Log4net;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
|
|
namespace HighWayIot.Common
|
|
{
|
|
/// <summary>
|
|
/// XML读写类
|
|
/// </summary>
|
|
public class XmlUtil
|
|
{
|
|
private static readonly Lazy<XmlUtil> lazy = new Lazy<XmlUtil>(() => new XmlUtil());
|
|
|
|
public static XmlUtil Instance
|
|
{
|
|
get
|
|
{
|
|
return lazy.Value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// XML读写实例
|
|
/// </summary>
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
|
|
/// <summary>
|
|
/// 运行时路径
|
|
/// </summary>
|
|
private string Path = System.Environment.CurrentDirectory;
|
|
|
|
/// <summary>
|
|
/// 客户端配置读取
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ClientsConfig> ClientReader()
|
|
{
|
|
List<ClientsConfig> list = new List<ClientsConfig>();
|
|
|
|
xmlDocument.Load($"{Path}\\RFIDConfiguration.xml");
|
|
XmlNode root = xmlDocument.DocumentElement;
|
|
XmlNode node = root.SelectSingleNode("Clients");
|
|
foreach (XmlNode role in node)
|
|
{
|
|
XmlAttribute clientIp = (XmlAttribute)role.Attributes.GetNamedItem("ip");
|
|
XmlAttribute clientPort = (XmlAttribute)role.Attributes.GetNamedItem("port");
|
|
XmlAttribute clientID = (XmlAttribute)role.Attributes.GetNamedItem("ID");
|
|
list.Add(new ClientsConfig()
|
|
{
|
|
IP = clientIp.Value,
|
|
Port = clientPort.Value,
|
|
ID = clientID.Value
|
|
});
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取服务端配置
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string ServerReader()
|
|
{
|
|
xmlDocument.Load($"{Path}\\RFIDConfiguration.xml");
|
|
XmlNode root = xmlDocument.DocumentElement;
|
|
XmlNode node = root.SelectSingleNode("Server");
|
|
XmlAttribute ip = (XmlAttribute)node.Attributes.GetNamedItem("ip");
|
|
XmlAttribute port = (XmlAttribute)node.Attributes.GetNamedItem("port");
|
|
string res = ip.Value + ":" + port.Value;
|
|
return res;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class ClientsConfig
|
|
{
|
|
/// <summary>
|
|
/// IP
|
|
/// </summary>
|
|
public string IP { get; set; }
|
|
|
|
/// <summary>
|
|
/// 端口号
|
|
/// </summary>
|
|
public string Port { get; set; }
|
|
|
|
/// <summary>
|
|
/// ID
|
|
/// </summary>
|
|
public string ID { get; set; }
|
|
}
|
|
}
|