Пример #1
0
        private FieldList GetFieldListForCatalog(CatalogSitecoreItem item, VersionUri version)
        {
            var fields = Cache.Lookup(item.Id, version);

            if (fields != null)
            {
                if (UseVerboseLogging)
                {
                    _log.Log <ContentNodeDataProvider>("cache hit");
                }
                Stats.Hit();
                return(fields);
            }
            if (UseVerboseLogging)
            {
                _log.Log <ContentNodeDataProvider>("cache miss");
            }
            Stats.Miss();

            PopulateCacheWithFieldListsForAllVersions(item);

            fields = _cache.Lookup(item.Id, version);
            if (fields != null)
            {
                return(fields);
            }

            return(item.GetFieldList(version));
        }
Пример #2
0
        private void PopulateCacheWithChildrensFieldLists(CatalogSitecoreItem catalogItem)
        {
            if (catalogItem == null)
            {
                return;
            }
            if (AreAllChildrenPresent(catalogItem))
            {
                return;
            }

            int catalogId = int.Parse(catalogItem.Node.ItemId);

            var catalog = ProductCatalog.Get(catalogId);

            var repository = ObjectFactory.Instance.Resolve <IRepository <Category> >();
            var categories = repository.Select(new CategoriesInCatalogQuery(catalog)).ToList();

            foreach (var category in categories)
            {
                var id = new ID(category.Guid);
                if (!_sitecoreItems.ContainsKey(id))
                {
                    continue;                                                  // This can happen, if the parent of this category was deleted.
                }
                var childItem = _sitecoreItems[id] as ContentNodeSitecoreItem;
                if (childItem == null)
                {
                    throw new Exception("Could not find category in list of items. " + category.Guid);
                }

                foreach (VersionUri version in GetItemVersions())
                {
                    var list = new FieldList();
                    list.SafeAdd(FieldIDs.Icon, childItem.GetIcon());
                    list.SafeAdd(FieldIDs.Sortorder, childItem.Node.SortOrder.ToString());
                    list.SafeAdd(FieldIDs.DisplayName, childItem.Node.Name);
                    _categoryValueProvider.AddDataFromCategory(list, version, category);

                    //_log.Log<ContentNodeDataProvider>(string.Format("Storing: {0}", category.Guid));
                    Cache.Store(new ID(category.Guid), version, list);
                }
            }
        }
Пример #3
0
        private void PopulateCacheWithFieldListsForAllVersions(CatalogSitecoreItem item)
        {
            var repository = ObjectFactory.Instance.Resolve <IRepository <ProductCatalog> >();
            var catalog    = repository.Get(int.Parse(item.Node.ItemId));

            if (catalog == null)
            {
                throw new Exception("Could not read catalog with id " + item.Node.ItemId);
            }

            foreach (VersionUri version in GetItemVersions())
            {
                var list = new FieldList();
                list.SafeAdd(FieldIDs.Icon, item.GetIcon());
                list.SafeAdd(FieldIDs.Sortorder, item.Node.SortOrder.ToString());
                list.SafeAdd(FieldIDs.DisplayName, item.Node.Name);
                _catalogValueProvider.AddDataFromCatalog(catalog, list, version);

                //_log.Log<ContentNodeDataProvider>(string.Format("Storing: {0}", item.Id));
                Cache.Store(item.Id, version, list);
            }
        }