缓存方法二

namespace BLL.Manager
{
    /// <summary>
    /// 武功资源管理
    /// </summary>
    public class GestResourceManager
    {
        private const string CacheKey = "GestResourceManager";
        private static object LockHelper = new object();
        private static Hashtable htCollection = null;
        private static IList<GestResourceEntity> iList_Collection = null;

        private GestResourceManager()
        {
            htCollection = new Hashtable();
        }

        public IList<GestResourceEntity> Gests
        {
            get
            {
                return iList_Collection;
            }
        }

        public GestResourceEntity this[string index]
        {
            get
            {
                if (htCollection[index] == null)
                    return null;
                return htCollection[index] as GestResourceEntity;
            }
        }

        public static GestResourceManager GetResource()
        {
            GestResourceManager manager = LRCache.Get(CacheKey) as GestResourceManager;
            if (manager == null)
            {
                lock (LockHelper)
                {
                    if (manager == null)
                    {
                        manager = new GestResourceManager();
                        manager.LoadGestResource();
                        LRCache.Insert(CacheKey, manager);
                    }
                }
            }
            return manager;
        }

        /// <summary>
        /// 加载武功资源
        /// </summary>
        private void LoadGestResource()
        {
            IList<GestResourceEntity> iList_GestResourceEntity = new GestBLL().GetAllGest();
            if (iList_GestResourceEntity == null)
                return;
            iList_Collection = iList_GestResourceEntity;
            foreach (GestResourceEntity resource in iList_GestResourceEntity)
            {
                htCollection[resource.GestID.ToString()] = resource;
            }
        }

 

    }
}

 

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

namespace BLL.Manager
{
    /// <summary>
    /// 建筑参数
    /// </summary>
    public class BuildingParaManager
    {
        private const string BUILDINGPARAKEY = "BuildingPara";
        private const string XMLPATH = "~/Config/Building.xml";
        private const string ParentNode = "/Buildings";
        private static string XMLMapPath = string.Empty;
        public Hashtable BuildParaCollection = null;
        public List<BuildingPara> BuildingParas = null;
        private XmlDocument document = null;
        private static object obj = new object();

        private BuildingParaManager()
        {
            BuildParaCollection = new Hashtable();
            BuildingParas = new List<BuildingPara>();
            document = new XmlDocument();
        }

        public BuildingPara this[string index]
        {
            get
            {
                if (BuildParaCollection[index] == null)
                    return null;
                return BuildParaCollection[index] as BuildingPara;
            }
        }

        public static BuildingParaManager GetBuildingPara()
        {
            BuildingParaManager dll = LRCache.Get(BUILDINGPARAKEY) as BuildingParaManager;
            XMLMapPath = HttpContext.Current.Server.MapPath(XMLPATH);
            if (dll == null)
            {
                lock (obj)
                {
                    dll = new BuildingParaManager();
                    dll.LoadXML();
                    CacheDependency dependency = new CacheDependency(XMLMapPath);
                    LRCache.Insert(BUILDINGPARAKEY, dll, dependency);
                }
            }
            return dll;
        }

        private void LoadXML()
        {
            document.Load(XMLMapPath);
            XmlNode parentNode = document.SelectSingleNode(ParentNode);
            if (parentNode != null)
            {
                foreach(XmlNode node in parentNode.ChildNodes)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                        continue;
                    BuildingPara para = new BuildingPara();
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        if (childNode.NodeType == XmlNodeType.Comment)
                            continue;
                        if (childNode.Name == "Name")
                            para.Name = childNode.InnerText;
                        else if (childNode.Name == "Area")
                            para.Area = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');
                        else if (childNode.Name == "BuildNeedMan")
                            para.BuildNeedMan = childNode.InnerText;
                        else if (childNode.Name == "RepairNeedMan")
                            para.RepairNeedMan = childNode.InnerText;
                        else if (childNode.Name == "Normal")
                            para.Normal = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');
                        else if (childNode.Name == "BuildStart")
                            para.BuildStart = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');
                        else if (childNode.Name == "Upgrading")
                            para.Upgrading = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');
                        else if (childNode.Name == "Broken")
                            para.Broken = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');
                        else if (childNode.Name == "NormalPath")
                            para.NormalPath = childNode.InnerText;
                        else if (childNode.Name == "BuildPath")
                            para.BuildPath = childNode.InnerText;
                        else if (childNode.Name == "UpgradingPath")
                            para.UpgradingPath = childNode.InnerText;
                        else if (childNode.Name == "BrokenPath")
                            para.BrokenPath = childNode.InnerText;
                        else if (childNode.Name == "RemovingPath")
                            para.RemovingPath = childNode.InnerText;
                        else if (childNode.Name == "RepairingPath")
                            para.RepairingPath = childNode.InnerText;
                        else if (childNode.Name == "Removing")
                            para.Removing = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');
                        else if (childNode.Name == "Repairing")
                            para.Repairing = ArrayUtil.SplitStringToIntArray(childNode.InnerText, ',');

                        else if (childNode.Name == "PhotoPath")
                            para.PhotoPath = childNode.InnerText;
                        else if (childNode.Name == "NormalPhoto")
                            para.NormalPhoto = childNode.InnerText;
                        else if (childNode.Name == "BuildStartPhoto")
                            para.BuildStartPhoto = childNode.InnerText;
                        else if (childNode.Name == "UpgradingPhoto")
                            para.UpgradingPhoto = childNode.InnerText;
                        else if (childNode.Name == "BrokenPhoto")
                            para.BrokenPhoto = childNode.InnerText;
                        else if (childNode.Name == "RemovingPhoto")
                            para.RemovingPhoto = childNode.InnerText;
                        else if (childNode.Name == "RepairingPhoto")
                            para.RepairingPhoto = childNode.InnerText;

                    }
                    BuildParaCollection[node.Attributes["TypeID"].Value] = para;
                    BuildingParas.Add(para);
                }
            }
        }
       

 

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值