Ejemplo n.º 1
0
        public static DbAccessor CreateDbAccessor()
        {
            var result = CreateDbAccessor(DefaultDbName);

            if (EvnValService.GetDefaultDbAccessorHashCode() == null)
            {
                EvnValService.SetDefaultDbAccessorHashCode(result);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static bool IsValidConfigFileName(string fileName)
        {
            bool result = true;

            if (!fileName.EndsWith(CONFIG_FILE_EXTENSION))
            {
                result = false;
            }

            #region 如果配置文件的名字是以XXX.DbProviderName.config(如:XXX.sqlserver.config)形式出现的,则进行筛选处理,筛选出只能当前使用的Provider相同的配置文件
            var fileNamePieces = fileName.Split('.');
            if (fileNamePieces.Length > 2)
            {
                string configDbProviderName = fileNamePieces[fileNamePieces.Length - 2];

                var lsDbProviderNames = new List <string>();
                foreach (var field in typeof(DbProviderName).GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    lsDbProviderNames.Add(field.Name);
                }

                if (lsDbProviderNames.Exists(c => c.ToLower() == configDbProviderName.ToLower()))
                {
                    string strDbAccessorHashCode = EvnValService.GetDefaultDbAccessorHashCode();
                    if (strDbAccessorHashCode != null)
                    {
                        string strDbProviderName = EvnValRepository.Instance.GetEvnVal(strDbAccessorHashCode).ToString();
                        if (configDbProviderName.ToLower() != strDbProviderName.ToString().ToLower())
                        {
                            result = false;
                        }
                    }
                }
            }
            #endregion

            return(result);
        }