/// <summary> /// 加载分类词典 /// </summary> private void GetCategoryDictionary() { RepositoryDataCache._categories = new Dictionary <int, IList <ICategory> >(); IList <ICategory> categories = new List <ICategory>(); ICategory category; categoryDal.GetAllCategories(rd => { while (rd.Read()) { category = this.CreateCategory( int.Parse(rd["id"].ToString()), _siteRep.GetSiteById(int.Parse(rd["siteId"].ToString())) ); rd.CopyToEntity(category); categories.Add(category); } }); //排序 // IOrderedEnumerable<ICategory> categories2 = categories.OrderBy(a => a.ID); foreach (ICategory _category in categories) { if (!RepositoryDataCache._categories.ContainsKey(_category.Site.Id)) { RepositoryDataCache._categories.Add(_category.Site.Id, new List <ICategory>()); } RepositoryDataCache._categories[_category.Site.Id].Add(_category); //添加Tag映射 Kvdb.Put(String.Format("{0}:cache:t:lft:{1}", _category.Site.Id.ToString(), _category.Tag), _category.Lft.ToString()); if (_category.Site.Id == 1 && _category.Tag.IndexOf("duct") != -1) { var x = "1:cache:t:lft:duct-machine" == String.Format("{0}:cache:t:lft:{1}", _category.Site.Id.ToString(), _category.Tag); } //添加ID映射 Kvdb.Put(String.Format("{0}:cache:id:lft:{1}", _category.Site.Id.ToString(), _category.Id.ToString()), _category.Lft.ToString()); } //categories2 = null; categories = null; }
/// <summary> /// 加载分类词典 /// </summary> private void InitCategoryDictionary() { RepositoryDataCache._categories = new Dictionary <int, IList <ICategory> >(); IList <ICategory> categories = new List <ICategory>(); ICategory ic; categoryDal.GetAllCategories(rd => { while (rd.Read()) { var category = new CmsCategoryEntity(); category.ID = Convert.ToInt32(rd["id"]); category.Title = (rd["page_title"] ?? "").ToString(); category.Description = (rd["page_description"] ?? "").ToString(); category.Icon = Convert.ToString(rd["icon"]); category.Keywords = Convert.ToString(rd["page_keywords"]); category.Location = Convert.ToString(rd["location"]); category.Name = Convert.ToString(rd["name"]); category.Tag = Convert.ToString(rd["tag"]); category.ParentId = Convert.ToInt32(rd["parent_id"]); category.SiteId = Convert.ToInt32(rd["site_id"]); category.Flag = Convert.ToInt32(rd["flag"]); category.Path = Convert.ToString(rd["path"]); category.SortNumber = Convert.ToInt32(rd["sort_number"]); ic = CreateCategory(category); if (ic.Site() != null) { categories.Add(ic); } } }); foreach (var _category in categories) { if (!RepositoryDataCache._categories.ContainsKey(_category.Site().GetAggregateRootId())) { RepositoryDataCache._categories.Add(_category.Site().GetAggregateRootId(), new List <ICategory>()); } RepositoryDataCache._categories[_category.Site().GetAggregateRootId()].Add(_category); //添加Id->Path映射 var key = catIdKey(_category.Site().GetAggregateRootId(), _category.GetDomainId()); Kvdb.Put(key, _category.Get().Path); } categories = null; }