private void ReadConfig(ref System.Web.HttpServerUtility s)
{
string XMLString = FileUtility.ReadFile(s.MapPath(CONFIG_PATH));
XmlDocument doc = new XmlDocument();
try {
doc.LoadXml(XMLString);
}
catch (Exception ex) {
return;
}
Hardwares = new List();
XmlNodeList nlHardwares = default(XmlNodeList);
nlHardwares = doc.SelectNodes("/Hardwares/Hardware");
foreach (XmlElement eleHardware in nlHardwares) {
Hardwares.Add(ParseHardwareNode(eleHardware));
}
}
private CHardware ParseHardwareNode(XmlElement eleHardware)
{
CHardware oHardware = new CHardware();
oHardware.HardwareType = eleHardware.GetAttribute("HardwareType");
XmlElement eleHtmlMetaInfo = eleHardware.SelectSingleNode("./HtmlMetaInfo");
if (eleHtmlMetaInfo != null) {
oHardware.HtmlMetaInfo = eleHtmlMetaInfo.InnerText;
}
XmlNodeList nlIdentities = eleHardware.SelectNodes("./Serial");
foreach (XmlElement eleSerial in nlIdentities) {
CHardware.CHardwareSerial oHardwareSerial = new CHardware.CHardwareSerial();
XmlNodeList nlHeaders = eleSerial.SelectNodes("./Header");
foreach (XmlElement eleHeader in nlHeaders) {
CHardware.CHardwareSerial.CHardwareSerialArea oHardwareSerialArea = new CHardware.CHardwareSerial.CHardwareSerialArea(eleHeader.GetAttribute("Area"), eleHeader.GetAttribute("Scope"));
oHardwareSerial.Areas.Add(oHardwareSerialArea);
}
oHardware.HardwareIdentities.Add(oHardwareSerial);
}
XmlNodeList nlSubHardwares = eleHardware.SelectNodes("./Hardware");
foreach (XmlElement eleSubHardware in nlSubHardwares) {
CHardware oSubHardware = ParseHardwareNode(eleSubHardware);
oSubHardware.ParentHardware = oHardware;
oHardware.SubHardwares.Add(oSubHardware);
}
return oHardware;
}
private CHardware SearchMatchingHardware(ref System.Web.HttpRequest Request, CHardware oHardware)
{
if (oHardware.IsMatch(Request) == true) {
if (oHardware.SubHardwares.Count > 0) {
foreach (CHardware oSubHardware in oHardware.SubHardwares) {
CHardware oMatchedSubHardware = SearchMatchingHardware(Request, oSubHardware);
if (oMatchedSubHardware != null) {
return oMatchedSubHardware;
}
}
}
return oHardware;
}
else {
return null;
}
}
public string DetectHardwareInfo(ref System.Web.HttpRequest Request, ref string HtmlMetaInfo)
{
HtmlMetaInfo = null;
foreach (CHardware oHardware in this.Hardwares) {
CHardware oMatchedHardware = SearchMatchingHardware(Request, oHardware);
if (oMatchedHardware != null) {
HtmlMetaInfo = oMatchedHardware.HtmlMetaInfo;
return oMatchedHardware.HardwareType;
}
}
return null;
}
|