private void ReadXMLFiles(string path) { files.Clear(); sqlDct.Clear(); string[] fls = Directory.GetFiles(path); foreach (string it in fls) { if (!it.ToLower().EndsWith(".xml")) { continue; } files.Add(it); } if (files.Count < 1) { HiLog.Write("folder ({0}) not include xml files", path); throw new Exception(string.Format("folder ({0}) not include xml files", path)); } foreach (string it in files) { ReadXMLFile(it, sqlDct); } }
/// <summary> /// 从配置文件中读取SQL信息 /// </summary> private void ReadXMLFile(string file, IDictionary <string, CachData <T> > dic) { XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode node = doc.DocumentElement; if (node == null) { return; } foreach (XmlNode child in node.ChildNodes) { // 如果是注释 if (XmlNodeType.Comment == child.NodeType) { continue; } foreach (XmlNode child2 in child.ChildNodes) { // 如果是注释 if (XmlNodeType.Comment == child2.NodeType) { continue; } XmlAttributeCollection ndAtt = child2.Attributes; if (ndAtt["id"] == null || ndAtt["id"].Value == null || ndAtt["id"].Value.Trim().Length < 1) { continue; } string id = ndAtt["id"].Value; CachData <T> item = null; bool isFind = dic.TryGetValue(id, out item); if (isFind) { HiLog.Write("key:{0} is alread in file({1}), so in file({2}) sencond time is error", id, item.File, file); throw new Exception(string.Format("key:{0} is alread in file({1}), so in file({2}) sencond time is error", id, item.File, file)); } if (ParseEvt == null) { break; } T data = ParseEvt(child2); if (data == null) { continue; } item = new CachData <T>(); item.File = file; item.Data = data; dic.Add(id, item); } } }
public void LoadXMLsByFolder(string path) { if (ParseEvt == null) { HiLog.Write("not set parse callback, so can't load xml"); throw new Exception("not set parse callback, so can't load xml"); } this.folder = path; if (!Directory.Exists(path)) { HiLog.Write("\"{0}\" folder is not exist,please check you xml folder.", path); throw new Exception(string.Format("\"{0}\" folder is not exist,please check you xml folder.", path)); } ReadXMLFiles(path); lastUpdateTime = GetLastTime(); }