public static SqlMapCache Load(XmlElement cacheNode) { var cache = new SqlMapCache { Id = cacheNode.Attributes["Id"].Value, Type = cacheNode.Attributes["Type"].Value, Parameters = new Dictionary <String, String>(), FlushOnExecutes = new List <FlushOnExecute>() }; foreach (XmlNode childNode in cacheNode.ChildNodes) { switch (childNode.Name) { case "Parameter": { string key = childNode.Attributes["Key"] != null ? childNode.Attributes["Key"].Value :""; string val = childNode.Attributes["Value"] != null ? childNode.Attributes["Value"].Value :""; if (!String.IsNullOrEmpty(key)) { cache.Parameters.Add(key, val); } break; } case "FlushInterval": { string hours = childNode.Attributes["Hours"] != null ? childNode.Attributes["Hours"].Value :""; string minutes = childNode.Attributes["Minutes"] != null ? childNode.Attributes["Minutes"].Value :""; string seconds = childNode.Attributes["Seconds"] != null ? childNode.Attributes["Seconds"].Value :""; cache.FlushInterval = new FlushInterval { Hours = XmlConvert.ToInt32(hours), Minutes = XmlConvert.ToInt32(minutes), Seconds = XmlConvert.ToInt32(seconds) }; break; } case "FlushOnExecute": { string statementId = childNode.Attributes["Statement"] != null ? childNode.Attributes["Statement"].Value : ""; if (!String.IsNullOrEmpty(statementId)) { cache.FlushOnExecutes.Add(new FlushOnExecute { Statement = statementId }); } break; } } } return(cache); }
public SqlMapInfo LoadSqlMap(IDatabase db, ConfigStream configStream) { using (configStream) { var sqlMap = new SqlMapInfo { Path = configStream.Path, Statements = new List <Statement> { }, Caches = new List <SqlMapCache> { } }; XmlDocument xmlDoc = new XmlDocument(); try { //xmlDoc.LoadXml(configStream.Config); var text = FileLoader.LoadText(configStream.Path, db); xmlDoc.LoadXml(text); // xmlDoc.Load(configStream.Path); XmlNamespaceManager xmlNsM = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsM.AddNamespace("ns", "http://PureData.net/schemas/SqlMap.xsd"); sqlMap.Scope = xmlDoc.SelectSingleNode("//ns:SqlMap", xmlNsM) .Attributes["Scope"].Value; //避免大小写 统一 20191115 sqlMap.Scope = SqlMapManager.Instance.FormatSqlMapNameCase(sqlMap.Scope); #region Init Caches var cacheNodes = xmlDoc.SelectNodes("//ns:Cache", xmlNsM); foreach (XmlElement cacheNode in cacheNodes) { var cache = SqlMapCache.Load(cacheNode); sqlMap.Caches.Add(cache); } #endregion #region Init Statement var statementNodes = xmlDoc.SelectNodes("//ns:Statement", xmlNsM); foreach (XmlElement statementNode in statementNodes) { var statement = Statement.Load(statementNode, sqlMap); sqlMap.Statements.Add(statement); } #endregion } catch (Exception ex) { throw new PureDataException("SqlMapLoader", ex); } finally { xmlDoc.RemoveAll(); xmlDoc = null; GC.Collect(); } return(sqlMap); } }