示例#1
0
        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()]);
                }
            }
        }
示例#2
0
        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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
        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()]);
                }
            }
        }
示例#5
0
        public static List <KeyValueDataAccessSetting> GetAllSettings()
        {
            if (m_KeyValueDataAccessSettingList == null)
            {
                lock (m_SyncObj)
                {
                    string filePath = Path.Combine(m_SettingFolderPath, CONFIG_FILE);
                    if (!File.Exists(filePath))
                    {
                        throw new FileNotFoundException("没有找到文件: " + filePath + "!");
                    }

                    m_KeyValueDataAccessSettingList = new List <KeyValueDataAccessSetting>();

                    XElement doc = XElement.Load(filePath);
                    if (doc == null ||
                        doc.Descendants("KVDataAccessItem") == null ||
                        doc.Descendants("KVDataAccessItem").Count() == 0)
                    {
                        return(m_KeyValueDataAccessSettingList);
                    }

                    foreach (var x in doc.Descendants("KVDataAccessItem"))
                    {
                        if (x.Attribute("DataCategory") == null || x.Attribute("DataCategory").Value.Trim() == string.Empty ||
                            x.Attribute("AccessMode") == null || x.Attribute("AccessMode").Value.Trim() == string.Empty)
                        {
                            throw new ApplicationException("DataCategory和AccessMode两个属性必须存在并且有值!");
                        }

                        KeyValueDataAccessSetting setting = new KeyValueDataAccessSetting();
                        setting.DataCategory = x.Attribute("DataCategory").Value.Trim();
                        string mode = x.Attribute("AccessMode").Value.Trim();
                        setting.AccessMode       = (KeyValueDataAccessMode)Enum.Parse(typeof(KeyValueDataAccessMode), mode, true);
                        setting.DataCategoryPath = x.Attribute("DataCategoryPath") == null ? null : x.Attribute("DataCategoryPath").Value.Trim();
                        m_KeyValueDataAccessSettingList.Add(setting);
                    }
                }
            }

            return(m_KeyValueDataAccessSettingList);
        }