public SmartSqlMapConfig LoadConfig(ConfigStream configStream) { using (configStream.Stream) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartSqlMapConfig)); SqlMapConfig = xmlSerializer.Deserialize(configStream.Stream) as SmartSqlMapConfig; SqlMapConfig.Path = configStream.Path; SqlMapConfig.SmartSqlMaps = new List <SmartSqlMap> { }; return(SqlMapConfig); } }
public SmartSqlMapConfig LoadConfig(ConfigStream configStream) { using (configStream.Stream) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartSqlMapConfig)); SqlMapConfig = xmlSerializer.Deserialize(configStream.Stream) as SmartSqlMapConfig; SqlMapConfig.Path = configStream.Path; SqlMapConfig.SmartSqlMaps = new Dictionary <String, SmartSqlMap> { }; if (SqlMapConfig.TypeHandlers != null) { foreach (var typeHandler in SqlMapConfig.TypeHandlers) { typeHandler.Handler = TypeHandlerFactory.Create(typeHandler.Type); } } return(SqlMapConfig); } }
public SmartSqlMap LoadSmartSqlMap(ConfigStream configStream) { using (configStream.Stream) { var sqlMap = new SmartSqlMap { SmartSqlMapConfig = SqlMapConfig, Path = configStream.Path, Statements = new List <Statement> { }, Caches = new List <SqlMap.Cache> { } }; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configStream.Stream); XmlNamespaceManager xmlNsM = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsM.AddNamespace("ns", "http://SmartSql.net/schemas/SmartSqlMap.xsd"); sqlMap.Scope = xmlDoc.SelectSingleNode("//ns:SmartSqlMap", xmlNsM) .Attributes["Scope"].Value; #region Init Caches var cacheNodes = xmlDoc.SelectNodes("//ns:Cache", xmlNsM); foreach (XmlElement cacheNode in cacheNodes) { var cache = SqlMap.Cache.Load(cacheNode); sqlMap.Caches.Add(cache); } #endregion #region Init Statement var statementNodes = xmlDoc.SelectNodes("//ns:Statement", xmlNsM); foreach (XmlElement statementNode in statementNodes) { var statement = statementFactory.Load(statementNode, sqlMap); sqlMap.Statements.Add(statement); } #endregion return(sqlMap); } }
public SmartSqlMap LoadSmartSqlMap(ConfigStream configStream) { using (configStream.Stream) { var sqlMap = new SmartSqlMap { SqlMapConfig = SqlMapConfig, Path = configStream.Path, Statements = new Dictionary <String, Statement> { }, Caches = new Dictionary <String, Configuration.Cache> { }, ResultMaps = new Dictionary <String, ResultMap> { }, MultipleResultMaps = new Dictionary <String, MultipleResultMap> { }, ParameterMaps = new Dictionary <String, ParameterMap> { } }; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configStream.Stream); XmlNamespaceManager xmlNsM = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsM.AddNamespace("ns", "http://SmartSql.net/schemas/SmartSqlMap.xsd"); sqlMap.Scope = xmlDoc.SelectSingleNode("//ns:SmartSqlMap", xmlNsM) .Attributes["Scope"].Value; #region Init Caches var cacheNodes = xmlDoc.SelectNodes("//ns:Caches/ns:Cache", xmlNsM); foreach (XmlElement cacheNode in cacheNodes) { var cache = CacheFactory.Load(cacheNode, sqlMap); sqlMap.Caches.Add(cache.Id, cache); } #endregion #region Init ResultMaps var resultMapsNodes = xmlDoc.SelectNodes("//ns:ResultMaps/ns:ResultMap", xmlNsM); foreach (XmlElement xmlNode in resultMapsNodes) { var resultMap = MapFactory.LoadResultMap(xmlNode, sqlMap, xmlNsM); sqlMap.ResultMaps.Add(resultMap.Id, resultMap); } #endregion #region Init MultipleResultMaps var multipleResultMapsNode = xmlDoc.SelectNodes("//ns:MultipleResultMaps/ns:MultipleResultMap", xmlNsM); foreach (XmlElement xmlNode in multipleResultMapsNode) { var multipleResultMap = MapFactory.LoadMultipleResultMap(xmlNode, sqlMap); sqlMap.MultipleResultMaps.Add(multipleResultMap.Id, multipleResultMap); } #endregion #region Init ParameterMaps var parameterMaps = xmlDoc.SelectNodes("//ns:ParameterMaps/ns:ParameterMap", xmlNsM); foreach (XmlElement xmlNode in parameterMaps) { var parameterMap = MapFactory.LoadParameterMap(xmlNode, sqlMap); sqlMap.ParameterMaps.Add(parameterMap.Id, parameterMap); } #endregion #region Init Statement var statementNodes = xmlDoc.SelectNodes("//ns:Statements/ns:Statement", xmlNsM); LoadStatementInSqlMap(sqlMap, statementNodes); #endregion return(sqlMap); } }
public SmartSqlMap LoadSmartSqlMap(ConfigStream configStream) { try { using (configStream.Stream) { var sqlMap = new SmartSqlMap { SqlMapConfig = SqlMapConfig, Path = configStream.Path, Statements = new List <Statement> { }, Caches = new List <Configuration.Cache> { }, ResultMaps = new List <ResultMap> { }, ParameterMaps = new List <ParameterMap> { } }; XDocument xmlDoc = XDocument.Load(configStream.Stream, LoadOptions.SetLineInfo); var nametable = xmlDoc.Root.CreateReader().NameTable; XmlNamespaceManager xmlNsM = new XmlNamespaceManager(nametable); xmlNsM.AddNamespace("ns", "http://SmartSql.net/schemas/SmartSqlMap.xsd"); sqlMap.Scope = xmlDoc.Root.XPathSelectElement("//ns:SmartSqlMap", xmlNsM) .Attribute("Scope").Value; #region Init Caches var cacheNodes = xmlDoc.XPathSelectElements("//ns:Cache", xmlNsM); foreach (XElement cacheNode in cacheNodes) { var cache = CacheFactory.Load(cacheNode); sqlMap.Caches.Add(cache); } #endregion #region Init ResultMaps var resultMapsNodes = xmlDoc.XPathSelectElements("//ns:ResultMap", xmlNsM); foreach (XElement xmlNode in resultMapsNodes) { var resultMap = MapFactory.LoadResultMap(xmlNode, SqlMapConfig); sqlMap.ResultMaps.Add(resultMap); } #endregion #region Init ParameterMaps var parameterMaps = xmlDoc.XPathSelectElements("//ns:ParameterMap", xmlNsM); foreach (XElement xmlNode in parameterMaps) { var parameterMap = MapFactory.LoadParameterMap(xmlNode, SqlMapConfig); sqlMap.ParameterMaps.Add(parameterMap); } #endregion #region Init Statement var statementNodes = xmlDoc.XPathSelectElements("//ns:Statement", xmlNsM); LoadStatementInSqlMap(sqlMap, statementNodes); var insertNodes = xmlDoc.XPathSelectElements("//ns:Insert", xmlNsM); LoadStatementInSqlMap(sqlMap, insertNodes); var updateNodes = xmlDoc.XPathSelectElements("//ns:Update", xmlNsM); LoadStatementInSqlMap(sqlMap, updateNodes); var deleteNodes = xmlDoc.XPathSelectElements("//ns:Delete", xmlNsM); LoadStatementInSqlMap(sqlMap, deleteNodes); var selectNodes = xmlDoc.XPathSelectElements("//ns:Select", xmlNsM); LoadStatementInSqlMap(sqlMap, selectNodes); #endregion return(sqlMap); } } catch (Exception ex) { throw new Exception(configStream.Path, ex); } }
public SmartSqlMap LoadSmartSqlMap(ConfigStream configStream) { using (configStream.Stream) { var sqlMap = new SmartSqlMap { SqlMapConfig = SqlMapConfig, Path = configStream.Path, Statements = new List <Statement> { }, Caches = new List <Configuration.Cache> { }, ResultMaps = new List <ResultMap> { }, ParameterMaps = new List <ParameterMap> { } }; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configStream.Stream); XmlNamespaceManager xmlNsM = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsM.AddNamespace("ns", "http://SmartSql.net/schemas/SmartSqlMap.xsd"); sqlMap.Scope = xmlDoc.SelectSingleNode("//ns:SmartSqlMap", xmlNsM) .Attributes["Scope"].Value; #region Init Caches var cacheNodes = xmlDoc.SelectNodes("//ns:Cache", xmlNsM); foreach (XmlElement cacheNode in cacheNodes) { var cache = CacheFactory.Load(cacheNode); sqlMap.Caches.Add(cache); } #endregion #region Init ResultMaps var resultMapsNodes = xmlDoc.SelectNodes("//ns:ResultMap", xmlNsM); foreach (XmlElement xmlNode in resultMapsNodes) { var resultMap = MapFactory.LoadResultMap(xmlNode, SqlMapConfig, xmlNsM); sqlMap.ResultMaps.Add(resultMap); } #endregion #region Init ParameterMaps var parameterMaps = xmlDoc.SelectNodes("//ns:ParameterMap", xmlNsM); foreach (XmlElement xmlNode in parameterMaps) { var parameterMap = MapFactory.LoadParameterMap(xmlNode, SqlMapConfig); sqlMap.ParameterMaps.Add(parameterMap); } #endregion #region Init Statement var statementNodes = xmlDoc.SelectNodes("//ns:Statement", xmlNsM); LoadStatementInSqlMap(sqlMap, statementNodes); var insertNodes = xmlDoc.SelectNodes("//ns:Insert", xmlNsM); LoadStatementInSqlMap(sqlMap, insertNodes); var updateNodes = xmlDoc.SelectNodes("//ns:Update", xmlNsM); LoadStatementInSqlMap(sqlMap, updateNodes); var deleteNodes = xmlDoc.SelectNodes("//ns:Delete", xmlNsM); LoadStatementInSqlMap(sqlMap, deleteNodes); var selectNodes = xmlDoc.SelectNodes("//ns:Select", xmlNsM); LoadStatementInSqlMap(sqlMap, selectNodes); #endregion return(sqlMap); } }