/// <summary>
        /// 初始化配置
        /// </summary>
        internal static bool InitConfig()
        {
            if (HasInit)
            {
                return(true);
            }
            _dicLoaderConfig       = new Dictionary <string, Type>();
            _dicEntityLoaderConfig = new Dictionary <string, Type>();
            _dicBoLoader           = new Dictionary <string, Type>();
            Dictionary <string, XmlDocument> dicEntityConfig = new Dictionary <string, XmlDocument>();

            List <ConfigInfo> docs = ConfigXmlLoader.LoadXml("Buffalo.Config");

            if (docs.Count <= 0)
            {
                docs = ConfigXmlLoader.LoadXml("DataAccessConfig");
            }
            if (docs.Count > 0)
            {
                DBInfo existsInfo = null;
                foreach (ConfigInfo doc in docs)
                {
                    XmlDocument docInfo = doc.Document;
                    DBInfo      dbinfo  = GetDBInfo(docInfo);
                    if (!_dicDBInfo.TryGetValue(dbinfo.Name, out existsInfo))
                    {
                        _dicDBInfo[dbinfo.Name] = dbinfo;
                    }
                    else
                    {
                        if (!existsInfo.ConnectionString.Equals(dbinfo.ConnectionString))
                        {
                            throw new Exception("同名数据库:" + dbinfo.Name + ",的连接字符串不同");
                        }
                        if (!existsInfo.DbType.Equals(existsInfo.DbType))
                        {
                            throw new Exception("同名数据库:" + dbinfo.Name + ",的数据库类型不同");
                        }
                    }
                }
            }
            if (_dicDBInfo.Count == 0)
            {
                StringBuilder exMess = new StringBuilder();
                exMess.Append("没有配置数据库信息,请检查");
                if (CommonMethods.IsWebContext)
                {
                    exMess.Append("web.config");
                }
                else
                {
                    exMess.Append("app.config");
                }
                exMess.Append("的appSettings中是否有 Buffalo.Config 或 DataAccessConfig 节点");
                throw new Exception(exMess.ToString());
            }

            LoadModel();
            return(true);
        }
        /// <summary>
        /// 添加到数据层
        /// </summary>
        /// <param name="doc"></param>
        private static void AppendDalLoader(Assembly ass, XmlDocument doc)
        {
            XmlNodeList nodes = doc.GetElementsByTagName("dataaccess");

            if (nodes.Count <= 0)
            {
                return;
            }
            XmlAttribute att = nodes[0].Attributes["name"];

            if (att == null)
            {
                return;
            }
            string name = att.InnerText;
            DBInfo db   = null;

            if (!_dicDBInfo.TryGetValue(name, out db))
            {
                return;
            }
            string[]    namespaces = db.DataaccessNamespace;
            XmlNodeList dalNodes   = nodes[0].ChildNodes;

            foreach (XmlNode dalNode in dalNodes)
            {
                att = dalNode.Attributes["type"];
                if (att == null)
                {
                    continue;
                }
                string typeName = att.InnerText;
                foreach (string allNameSpace in namespaces)
                {
                    if (typeName.StartsWith(allNameSpace))
                    {
                        Type dalType = ass.GetType(typeName);
                        if (dalType != null)
                        {
                            att = dalNode.Attributes["interface"];
                            if (att == null)
                            {
                                break;
                            }
                            _dicLoaderConfig[att.InnerText] = dalType;

                            Type[] gTypes = DefaultType.GetGenericType(dalType, true);
                            if (gTypes != null && gTypes.Length > 0)
                            {
                                Type gType = gTypes[0];
                                _dicEntityLoaderConfig[gType.FullName] = dalType;
                            }
                        }

                        break;
                    }
                }
            }
        }
        /// <summary>
        /// 获取数据库信息
        /// </summary>
        /// <param name="dbName">数据库名</param>
        /// <returns></returns>
        public static DBInfo GetDBInfo(string dbName)
        {
            if (_dicDBInfo == null)
            {
                return(null);
            }
            DBInfo ret = null;

            _dicDBInfo.TryGetValue(dbName, out ret);
            return(ret);
        }
 /// <summary>
 /// 添加数据库信息
 /// </summary>
 /// <param name="dbinfo"></param>
 public static void AppendDBInfo(DBInfo dbinfo)
 {
     _dicDBInfo[dbinfo.Name] = dbinfo;
 }
        /// <summary>
        /// 获取当前配置文件的数据库信息
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static DBInfo GetDBInfo(XmlDocument doc)
        {
            string dbType           = null;
            string connectionString = null;
            string name             = null;

            //string output = null;
            string[]     attNames  = null;
            ICacheAdaper ica       = null;
            string       cacheType = null;
            string       cacheConn = null;

            //Dictionary<string, string> extendDatabaseConnection = new Dictionary<string,string>();
            if (doc == null)
            {
                throw new Exception("找不到配置文件");
            }
            bool        isAlltable = false;
            XmlNodeList lstConfig  = doc.GetElementsByTagName("config");

            if (lstConfig.Count > 0)
            {
                XmlNode node = lstConfig[0];
                foreach (XmlAttribute att in node.Attributes)
                {
                    if (att.Name.Equals("dbType", StringComparison.CurrentCultureIgnoreCase))
                    {
                        dbType = att.InnerText;
                    }
                    //else if (att.Name.Equals("output", StringComparison.CurrentCultureIgnoreCase))
                    //{
                    //    output = att.InnerText;
                    //}
                    else if (att.Name.Equals("name", StringComparison.CurrentCultureIgnoreCase))
                    {
                        name = att.InnerText;
                    }
                    else if (att.Name.Equals("connectionString", StringComparison.CurrentCultureIgnoreCase))
                    {
                        connectionString = att.InnerText;
                    }
                    else if (att.Name.Equals("appnamespace", StringComparison.CurrentCultureIgnoreCase))
                    {
                        string names = att.InnerText;

                        if (!string.IsNullOrEmpty(names))
                        {
                            attNames = names.Split(new char[] { '|' });
                        }
                        for (int i = 0; i < attNames.Length; i++)
                        {
                            string attName = attNames[i];
                            if (!attName.EndsWith("."))
                            {
                                attNames[i] = attName + ".";
                            }
                        }
                    }
                    else if (att.Name.Equals("cache", StringComparison.CurrentCultureIgnoreCase))
                    {
                        cacheType = att.InnerText;
                    }
                    else if (att.Name.Equals("cacheConnString", StringComparison.CurrentCultureIgnoreCase))
                    {
                        cacheConn = att.InnerText;
                    }
                    else if (att.Name.Equals("allCache", StringComparison.CurrentCultureIgnoreCase))
                    {
                        isAlltable = att.InnerText == "1";
                    }
                }
            }
            else
            {
                throw new Exception("配置文件没有config节点");
            }

            DBInfo info = new DBInfo(name, connectionString, dbType);

            ica = QueryCache.GetCache(info, cacheType, cacheConn);

            info.SetQueryCache(ica, isAlltable);

            info.DataaccessNamespace = attNames;
            return(info);
        }