Esempio n. 1
0
        public static List <ConnConfigInfo> AnalyzeSection(XmlDocument doc, Type baseType)
        {
            var list        = new List <ConnConfigInfo>();
            var cfgSections = doc.SelectNodes("configuration/configSections/section");

            foreach (XmlNode node in cfgSections)
            {
                try
                {
                    if (node.Attributes["type"] != null)
                    {
                        var str  = node.Attributes["type"].Value;
                        var name = node.Attributes["name"].Value;
                        var type = Type.GetType(str);
                        if (baseType.IsAssignableFrom(type))
                        {
                            var ele = doc.SelectSingleNode("configuration/" + name);
                            if (ele != null)
                            {
                                var isEncrypt = false;
                                if (ele.Attributes["UseEncryption"] != null)
                                {
                                    isEncrypt = bool.Parse(ele.Attributes["UseEncryption"].Value);
                                }
                                var info = new ConnConfigInfo
                                {
                                    IsSuccess      = true,
                                    ErrMessage     = "配置正确",
                                    ConnConfigName = name,
                                    ConnType       = "common.database",
                                    HandleType     = type,
                                    IsEncrypt      = isEncrypt,
                                    ItsNode        = node,
                                };
                                list.Add(info);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    var info = new ConnConfigInfo
                    {
                        IsSuccess  = false,
                        ErrMessage = ex.Message,
                    };
                    list.Add(info);
                }
            }
            return(list);
        }
Esempio n. 2
0
        public static List <ConnConfigInfo> AnalyzeFactory(XmlDocument doc, Type baseType)
        {
            var list   = new List <ConnConfigInfo>();
            var xmlnsm = new XmlNamespaceManager(doc.NameTable);

            xmlnsm.AddNamespace("urn", "urn:nhibernate-configuration-2.2");
            var factories = doc.SelectNodes("urn:hibernate-configuration/urn:session-factory", xmlnsm);

            foreach (XmlNode node in factories)
            {
                try
                {
                    var  name      = node.Attributes["name"].Value;
                    var  isEncrypt = false;
                    Type type      = null;
                    foreach (XmlNode prop in node.SelectNodes("urn:property", xmlnsm))
                    {
                        if (prop.Attributes["name"].Value.Equals("connection.provider", StringComparison.OrdinalIgnoreCase))
                        {
                            type = Type.GetType(prop.InnerText);
                            if (baseType.IsAssignableFrom(type))
                            {
                                isEncrypt = true;
                            }
                            break;
                        }
                    }
                    var info = new ConnConfigInfo
                    {
                        IsSuccess      = true,
                        ErrMessage     = "配置正确",
                        ConnConfigName = name,
                        ConnType       = "nhibernate",
                        HandleType     = type,
                        IsEncrypt      = isEncrypt,
                        ItsNode        = node,
                    };
                    list.Add(info);
                }
                catch (Exception ex)
                {
                    var info = new ConnConfigInfo
                    {
                        IsSuccess  = false,
                        ErrMessage = ex.Message,
                    };
                    list.Add(info);
                }
            }
            return(list);
        }