コード例 #1
0
        /// <summary>
        /// 从配置文件中读取SQL信息
        /// </summary>
        private void ReadXMLFile(string file, IDictionary <string, CachData <T> > dic)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(file);

            XmlNode node = doc.DocumentElement;

            if (node == null)
            {
                return;
            }

            foreach (XmlNode child in node.ChildNodes)
            {
                // 如果是注释
                if (XmlNodeType.Comment == child.NodeType)
                {
                    continue;
                }
                foreach (XmlNode child2 in child.ChildNodes)
                {
                    // 如果是注释
                    if (XmlNodeType.Comment == child2.NodeType)
                    {
                        continue;
                    }

                    XmlAttributeCollection ndAtt = child2.Attributes;

                    if (ndAtt["id"] == null || ndAtt["id"].Value == null || ndAtt["id"].Value.Trim().Length < 1)
                    {
                        continue;
                    }

                    string       id     = ndAtt["id"].Value;
                    CachData <T> item   = null;
                    bool         isFind = dic.TryGetValue(id, out item);
                    if (isFind)
                    {
                        HiLog.Write("key:{0} is alread in file({1}), so  in file({2}) sencond time is error", id, item.File, file);
                        throw new Exception(string.Format("key:{0} is alread in file({1}), so  in file({2}) sencond time is error", id, item.File, file));
                    }

                    if (ParseEvt == null)
                    {
                        break;
                    }
                    T data = ParseEvt(child2);
                    if (data == null)
                    {
                        continue;
                    }
                    item      = new CachData <T>();
                    item.File = file;
                    item.Data = data;
                    dic.Add(id, item);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 取得存储的值
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T  GetValue(string id)
        {
            CachData <T> data = null;

            if (!SQLDct.TryGetValue(id, out data))
            {
                return(default(T));
            }

            return(data.Data);
        }