Example #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataBaseType"></param>
        public ServerAdapter(DataBaseTypeEnum dataBaseType)
        {
            var config = new SqliteDataAccess().GetConfigModels();

            if (config == null || !config.Any())
            {
                return;
            }
            if (dataBaseType == DataBaseTypeEnum.NotDesignated)
            {
                return;
            }
            ServerList = new List <BaseServer>();

            if ((dataBaseType & DataBaseTypeEnum.SqlServer) == DataBaseTypeEnum.SqlServer)
            {
                var tempConfigList = config.Where(f => f.DbType == DataBaseTypeEnum.SqlServer && f.IsEnable == IsEnableEnum.Enable).ToList();
                if (tempConfigList != null && tempConfigList.Count > 0)
                {
                    foreach (var tempConfig in tempConfigList)
                    {
                        if (!string.IsNullOrEmpty(tempConfig?.LinkConnectionString))
                        {
                            ServerList.Add(new BaseServer(tempConfig.LinkConnectionString, new SqlServerDataAccess(), DataBaseTypeEnum.SqlServer));
                        }
                    }
                }
            }
            if ((dataBaseType & DataBaseTypeEnum.MySql) == DataBaseTypeEnum.MySql)
            {
                var tempConfigList = config.Where(f => f.DbType == DataBaseTypeEnum.MySql && f.IsEnable == IsEnableEnum.Enable).ToList();
                if (tempConfigList != null && tempConfigList.Count > 0)
                {
                    foreach (var tempConfig in tempConfigList)
                    {
                        if (!string.IsNullOrEmpty(tempConfig?.LinkConnectionString))
                        {
                            ServerList.Add(new BaseServer(tempConfig.LinkConnectionString, new MySqlDataAccess(), DataBaseTypeEnum.MySql));
                        }
                    }
                }
            }
            if ((dataBaseType & DataBaseTypeEnum.Oracle) == DataBaseTypeEnum.Oracle)
            {
                var tempConfigList = config.Where(f => f.DbType == DataBaseTypeEnum.Oracle && f.IsEnable == IsEnableEnum.Enable).ToList();
                if (tempConfigList != null && tempConfigList.Count > 0)
                {
                    foreach (var tempConfig in tempConfigList)
                    {
                        if (!string.IsNullOrEmpty(tempConfig?.LinkConnectionString))
                        {
                            ServerList.Add(new BaseServer(tempConfig.LinkConnectionString, new OracleDataAccess(), DataBaseTypeEnum.Oracle));
                        }
                    }
                }
            }
        }