コード例 #1
0
        public static bool DataType(string dbFile = "db.json")
        {
            var list     = new List <ConfigModel>();
            var cacheKey = "FastData.Core.Config";

            if (DbCache.Exists(CacheType.Web, cacheKey))
            {
                list = DbCache.Get <List <ConfigModel> >(CacheType.Web, cacheKey);
            }
            else
            {
                list = BaseConfig.GetListValue <ConfigModel>(AppSettingKey.Config, dbFile);
                DbCache.Set <List <ConfigModel> >(CacheType.Web, cacheKey, list);
            }

            var result = new List <bool>();

            result.Add(list.Count(a => a.DbType.ToLower() == DataDbType.Oracle) > 0);
            result.Add(list.Count(a => a.DbType.ToLower() == DataDbType.DB2) > 0);
            result.Add(list.Count(a => a.DbType.ToLower() == DataDbType.MySql) > 0);
            result.Add(list.Count(a => a.DbType.ToLower() == DataDbType.PostgreSql) > 0);
            result.Add(list.Count(a => a.DbType.ToLower() == DataDbType.SQLite) > 0);
            result.Add(list.Count(a => a.DbType.ToLower() == DataDbType.SqlServer) > 0);

            return(result.Count(a => a == true) > 1);
        }
コード例 #2
0
        /// <summary>
        /// 获取配置实体
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static ConfigModel GetConfig(string key = null)
        {
            var list     = new List <ConfigModel>();
            var cacheKey = key == null ? "FastApi.Config" : string.Format("FastApi.Config.{0}", key);

            if (BaseCache.Exists(cacheKey))
            {
                list = BaseCache.Get <List <ConfigModel> >(cacheKey);
            }
            else
            {
                list = BaseConfig.GetListValue <ConfigModel>("DataConfig", "db.json");
                BaseCache.Set <List <ConfigModel> >(cacheKey, list);
            }

            if (string.IsNullOrEmpty(key))
            {
                return(list[0]);
            }
            else
            {
                return(list.Find(a => a.Key.ToLower() == key.ToLower()));
            }
        }
コード例 #3
0
ファイル: DataConfig.cs プロジェクト: jason10wm/FastData.Core
        /// <summary>
        /// 获取配置实体
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static ConfigModel Get(string key = null, string projectName = null, string dbFile = "db.json")
        {
            var list     = new List <ConfigModel>();
            var item     = new ConfigModel();
            var cacheKey = "FastData.Core.Config";

            if (DbCache.Exists(CacheType.Web, cacheKey))
            {
                list = DbCache.Get <List <ConfigModel> >(CacheType.Web, cacheKey);
            }
            else if (projectName != null)
            {
                var assembly = Assembly.Load(projectName);
                using (var resource = assembly.GetManifestResourceStream(string.Format("{0}.{1}", projectName, dbFile)))
                {
                    if (resource != null)
                    {
                        using (var reader = new StreamReader(resource))
                        {
                            var content = reader.ReadToEnd();
                            list = BaseJson.JsonToList <ConfigModel>(BaseJson.ModelToJson(BaseJson.JsonToDic(content).GetValue("DataConfig")));
                            list.ForEach(a => { a.IsUpdateCache = false; });
                            DbCache.Set <List <ConfigModel> >(CacheType.Web, cacheKey, list);
                        }
                    }
                    else
                    {
                        list = BaseConfig.GetListValue <ConfigModel>(AppSettingKey.Config, dbFile);
                        DbCache.Set <List <ConfigModel> >(CacheType.Web, cacheKey, list);
                    }
                }
            }
            else
            {
                list = BaseConfig.GetListValue <ConfigModel>(AppSettingKey.Config, dbFile);
                DbCache.Set <List <ConfigModel> >(CacheType.Web, cacheKey, list);
            }

            if (string.IsNullOrEmpty(key))
            {
                item = list[0];
            }
            else
            {
                item = list.Find(a => a.Key.ToLower() == key.ToLower());
            }

            if (item.DesignModel == "")
            {
                item.DesignModel = Config.DbFirst;
            }

            if (item.SqlErrorType == "")
            {
                item.SqlErrorType = SqlErrorType.File;
            }

            if (item.CacheType == "")
            {
                item.CacheType = CacheType.Web;
            }

            item.IsPropertyCache = true;
            item.DbType          = item.DbType.ToLower();

            if (projectName != null)
            {
                item.IsUpdateCache = false;
            }
            return(item);
        }