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.

121 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
namespace CommService
{
/*
*ConfigReader
*
*2010-10-30
*xml
*/
class ConfigReader
{
public string sListenIP;
public int nListenPort;
public int nTerminalTimeOut;
public string sRemotingIP;
public int nRemotingPort;
public int nOffLineHours;
public string sConnectString;
public string sLogLevel;
public bool bConnectTiming;
public int nIntervalHoursForTiming;
/*
*Load
*
*2010-10-30
*string sConfigFile xml
*bool true,false
*
*/
public bool Load(string sConfigFile)
{
if (File.Exists(sConfigFile) == false)
{
return false;
}
XmlElement theConfig = null, theElem = null, root = null;
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(sConfigFile);
root = xmldoc.DocumentElement;
theConfig = (XmlElement)root.SelectSingleNode("/root/config");
//mycontrols.UserControl1 userControl;
if (theConfig != null)
{
theElem = (XmlElement)theConfig.FirstChild;
while (theElem != null)
{
if (theElem.Name == "ListenIP")
{
sListenIP = theElem.InnerXml;
}
else if (theElem.Name == "ListenPort")
{
nListenPort = Convert.ToInt32(theElem.InnerXml);
}
else if (theElem.Name == "RemotingIP")
{
sRemotingIP = theElem.InnerXml;
}
else if (theElem.Name == "RemotingPort")
{
nRemotingPort = Convert.ToInt32(theElem.InnerXml);
}//OffLineHours
else if (theElem.Name == "OffLineHours")
{
nOffLineHours = Convert.ToInt32(theElem.InnerXml);
}
else if (theElem.Name == "TerminalTimeOut")
{
nTerminalTimeOut = Convert.ToInt32(theElem.InnerXml);
}
else if (theElem.Name == "ConnectString")
{
sConnectString = theElem.InnerXml;
}
else if (theElem.Name == "ConnectTiming")
{
bConnectTiming = Convert.ToBoolean(theElem.InnerXml);
}
else if (theElem.Name == "IntervalHoursForTiming")
{
//01-100
nIntervalHoursForTiming = Convert.ToInt32(theElem.InnerXml);
if (nIntervalHoursForTiming < 0 )
{
nIntervalHoursForTiming = 1;
}
else if (nIntervalHoursForTiming > 100)
{
nIntervalHoursForTiming = 100;
}
}
else if (theElem.Name == "LogLevel")
{
sLogLevel = theElem.InnerXml;
}
//else if (theElem.Name == "Width")
//{
// userControl.Width = Convert.ToInt32(theElem.InnerXml);
//}
theElem = (XmlElement)theElem.NextSibling;
}
}
return false;
}
}
}