Exemplo n.º 1
0
        public ConfigStream LoadConfigStream(string path)
        {
            var configStream = new ConfigStream
            {
                Path = FileLoader.GetPath(path)
                       //Config = FileLoader.LoadText(path)
            };

            return(configStream);
        }
Exemplo n.º 2
0
        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);
            }
        }