public static T GetKeyValueData <T>(string dataCategory, string key) where T : class, new() { List <KeyValueDataAccessSetting> list = KeyValueDataAccessSettingManager.GetAllSettings(); KeyValueDataAccessSetting setting = list.Find(f => f.DataCategory.ToUpper().Trim() == dataCategory.Trim().ToUpper()); if (setting == null) { throw new NullReferenceException("没有找到" + dataCategory + "在KeyValueDataAccessSetting.config中的配置!"); } if (!m_CacheData.ContainsKey(dataCategory.ToUpper().Trim())) { string xmlFileFullPath = Path.Combine(GetBaseFolderPath(), setting.DataCategoryPath, setting.DataCategory + ".xml"); T t = DeserializeToObject <T>(xmlFileFullPath); m_CacheData.Add(dataCategory.ToUpper().Trim(), t); return(t); } else { lock (m_SyncObj) { return((T)m_CacheData[dataCategory.ToUpper().Trim()]); } } }
public List <T> GetKeyValueData <T>(string dataCategory) where T : class, new() { List <KeyValueDataAccessSetting> settingList = KeyValueDataAccessSettingManager.GetAllSettings(); KeyValueDataAccessSetting setting = settingList.Find(f => f.DataCategory.ToUpper().Trim() == dataCategory.Trim().ToUpper()); if (setting == null) { throw new NullReferenceException("没有找到" + dataCategory + "在KeyValueDataAccessSetting.config中的配置!"); } string sql = string.Empty; if (string.IsNullOrEmpty(setting.DataCategoryPath)) { sql = @"SELECT [SysNo] ,[DataCategory] ,[BizKey] ,[BizValue] ,[Status] ,[InDate] ,[LastEditDate] FROM [WebKeyValueData].[dbo].[DefaultKVD] WITH(NOLOCK) WHERE DataCategory='{0}'"; sql = string.Format(sql, dataCategory.Replace("'", "''")); } else { sql = @"SELECT [SysNo] ,[DataCategory] ,[BizKey] ,[BizValue] ,[Status] ,[InDate] ,[LastEditDate] FROM {0} WITH(NOLOCK) WHERE DataCategory='{1}'"; sql = string.Format(sql, setting.DataCategoryPath, dataCategory.Replace("'", "''")); } string dbConnectionName = SQLDBProvider.DBConnectionName; CustomDataCommand cmd = DataCommandManager.CreateCustomDataCommandFromSql(sql, dbConnectionName); DataTable dt = cmd.ExecuteDataTable(); List <T> list = new List <T>(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { string bizValue = row["BizValue"] != null ? row["BizValue"].ToString().Trim() : null; if (!string.IsNullOrEmpty(bizValue) && bizValue.Length >= 4) { T t = SerializationUtility.XmlDeserialize <T>(bizValue); list.Add(t); } } } return(list); }
/// <summary> /// 本方法只适用于XMLMaker制造的XMFileData模式,根据dataCategory(对应xml的文件名)取出xml文件中的数据,转换为类型为T的数据列表 /// </summary> /// <typeparam name="T">返回的数据类型</typeparam> /// <param name="dataCategory">数据类别</param> /// <returns>返回的数据列表</returns> public static List <T> GetKeyValueData <T>(string dataCategory) where T : class, new() { List <KeyValueDataAccessSetting> settingList = KeyValueDataAccessSettingManager.GetAllSettings(); KeyValueDataAccessSetting setting = settingList.Find(f => f.DataCategory.ToUpper().Trim() == dataCategory.ToUpper().Trim()); if (setting == null) { return(null); } IKeyValueDataProvider dataProvider = GetProvider(setting.AccessMode); List <T> list = dataProvider.GetKeyValueData <T>(dataCategory); return(list); }
public static List <T> GetKeyValueData <T>(string dataCategory) where T : class, new() { List <KeyValueDataAccessSetting> list = KeyValueDataAccessSettingManager.GetAllSettings(); KeyValueDataAccessSetting setting = list.Find(f => f.DataCategory.ToUpper().Trim() == dataCategory.Trim().ToUpper()); if (setting == null) { throw new NullReferenceException("没有找到" + dataCategory + "在KeyValueDataAccessSetting.config中的配置!"); } if (!m_CacheData.ContainsKey(dataCategory.ToUpper().Trim())) { string xmlFileFullPath = Path.Combine(GetBaseFolderPath(), setting.DataCategoryPath, setting.DataCategory + ".xml"); if (!File.Exists(xmlFileFullPath)) { return(null); } DataTable dt = null; try { DataSet ds = new DataSet(); XmlReadMode mode = ds.ReadXml(xmlFileFullPath, XmlReadMode.ReadSchema); dt = ds.Tables[0]; } catch (Exception) { return(null); } if (dt != null) { List <T> tlist = BuildEntityListFromDataTable <T>(dt); m_CacheData.Add(dataCategory.ToUpper().Trim(), tlist); return(tlist); } return(null); } else { lock (m_SyncObj) { return((List <T>)m_CacheData[dataCategory.ToUpper().Trim()]); } } }