public IEnumerable <ResolvedContentType> ResolveContentTypes(
            IEnumerable <ContentReference> contentLinks)
        {
            var contentReferences = contentLinks as ContentReference[] ?? contentLinks.ToArray();

            var result = new List <ResolvedContentType>();

            result.AddRange(contentReferences
                            .Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.Catalog)
                            .Select(l => new ResolvedContentType(l, _catalogContentType)));

            var nodeContentLinks =
                contentReferences.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.CatalogNode);
            var nodeIds = nodeContentLinks.Select(l => _referenceConverter.GetObjectId(l));

            var entryLinks =
                contentReferences.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.CatalogEntry);
            var entryIds = entryLinks.Select(l => _referenceConverter.GetObjectId(l));

            var ds = LoadMetaClassNames(entryIds, nodeIds);

            result.AddRange(ResolveContentTypes(ds.Tables[0], CatalogContentType.CatalogEntry));
            result.AddRange(ResolveContentTypes(ds.Tables[1], CatalogContentType.CatalogNode));

            return(result);
        }
Esempio n. 2
0
        public IDictionary <ContentReference, ContentType> ResolveContentTypes(
            IEnumerable <ContentReference> contentLinks)
        {
            var result = new Dictionary <ContentReference, ContentType>();
            var catalogContentLinks =
                contentLinks.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.Catalog);

            foreach (var catalogContentLink in catalogContentLinks)
            {
                result.Add(catalogContentLink, _catalogContentType);
            }

            var notCachedLinks = new List <ContentReference>();

            foreach (var contentLink in contentLinks)
            {
                var cached = _cache.Get(GetCacheKey(contentLink)) as ContentType;
                if (cached != null)
                {
                    result.Add(contentLink, cached);
                }
                else
                {
                    notCachedLinks.Add(contentLink);
                }
            }

            var nodeContentLinks =
                notCachedLinks.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.CatalogNode);
            var nodeIds = nodeContentLinks.Select(l => _referenceConverter.GetObjectId(l));

            var entryLinks =
                notCachedLinks.Where(l => _referenceConverter.GetContentType(l) == CatalogContentType.CatalogEntry);
            var entryIds = entryLinks.Select(l => _referenceConverter.GetObjectId(l));

            var ds = LoadMetaClassNames(entryIds, nodeIds);

            foreach (var keyPair in ResolveContentTypes(ds.Tables[0], CatalogContentType.CatalogEntry))
            {
                result.Add(keyPair.Key, keyPair.Value);
                _cache.Insert(GetCacheKey(keyPair.Key), keyPair.Value, _cacheEvictionPolicyFunc(keyPair.Key));
            }

            foreach (var keyPair in ResolveContentTypes(ds.Tables[1], CatalogContentType.CatalogNode))
            {
                result.Add(keyPair.Key, keyPair.Value);
                _cache.Insert(GetCacheKey(keyPair.Key), keyPair.Value, _cacheEvictionPolicyFunc(keyPair.Key));
            }

            return(result);
        }
Esempio n. 3
0
        public void CheckReferenceConverter()
        {
            // variationController has demo code for "Loading examples"
            ContentReference theRef = _referenceConverter.GetContentLink("Shirts_1");
            int theInt = _referenceConverter.GetObjectId(theRef);

            CatalogContentType theType = _referenceConverter.GetContentType(theRef);

            ContentReference theSameRef = _referenceConverter.GetContentLink
                                              (theInt, CatalogContentType.CatalogNode, 0);

            string theCode = _referenceConverter.GetCode(theSameRef);

            ContentReference catalogRoot = _referenceConverter.GetRootLink();

            List <string> codes = new List <string>
            {
                "Shirts_1",
                "Men_1"
            };

            IDictionary <string, ContentReference> theDict;

            theDict = _referenceConverter.GetContentLinks(codes);
        }
Esempio n. 4
0
        protected void WalkCategoryTree(NodeContent node,
                                        IContentRepository repository,
                                        CatalogContentLoader contentLoader,
                                        ICatalogSystem catalog,
                                        ReferenceConverter referenceConverter)
        {
            // ReSharper disable PossibleMultipleEnumeration
            // Get all products
            Stopwatch tmr = Stopwatch.StartNew();
            IEnumerable <EntryContentBase> entries = repository.GetChildren <EPiServer.Commerce.Catalog.ContentTypes.EntryContentBase>(node.ContentLink);

            _log.Debug("Loaded {0} entries in category {1} using IContentRepository in {2}ms",
                       entries.Count(),
                       node.Name,
                       tmr.ElapsedMilliseconds);

            // Load and cache Entry objects. Still a lot of code that uses this
            tmr = Stopwatch.StartNew();
            foreach (EntryContentBase entryAsContent in entries)
            {
                // Load full entry
                int entryId = referenceConverter.GetObjectId(entryAsContent.ContentLink);
                // Catalog Gadget uses info
                //catalog.GetCatalogEntry(entryId,
                //	new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                catalog.GetCatalogEntry(entryId,
                                        new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            }

            // Prime the catalog gadget
            // IEnumerable<IContent> children = repository.GetChildren<IContent>(node.ContentLink, new LanguageSelector("en"), 0, int.MaxValue);
            // _log.Debug("Loaded {0} children", children.Count());

            // .GetDescendents(node.ContentLink);

            tmr.Stop();
            _log.Debug("Loaded {0} entries in category {1} using ICatalogSystem in {2}ms",
                       entries.Count(),
                       node.Name,
                       tmr.ElapsedMilliseconds);

            // Get all products the way it is done in edit mode, but this does not seem to
            // use the cache.
            //int loadedEntries;
            //contentLoader.GetCatalogEntries(node.ContentLink, 0, int.MaxValue, out loadedEntries);
            //_log.Debug("Loaded {0} entries in category {1} using CatalogContentLoader", loadedEntries, node.Name);

            // Get child nodes the same way done by the UI
            IList <CatalogGetChildrenReferenceResult> catalogNodes = contentLoader.GetCatalogNodes(node.ContentLink);

            _log.Debug("Loaded {0} categories in category {1} using CatalogContentLoader", catalogNodes.Count, node.Name);
            foreach (GetChildrenReferenceResult catalogNode in catalogNodes)
            {
                NodeContent childNode = repository.Get <NodeContent>(catalogNode.ContentLink);
                WalkCategoryTree(childNode, repository, contentLoader, catalog, referenceConverter);
            }
            // ReSharper restore PossibleMultipleEnumeration
        }
        public void CheckReferenceConverter(ContentReference contentReference, AdminViewModel model)
        {
            RefInfo refInfo = new RefInfo();

            refInfo.Ref         = contentReference;
            refInfo.Code        = _referenceConverter.GetCode(contentReference);
            refInfo.DbId        = _referenceConverter.GetObjectId(contentReference);
            refInfo.CatalogType = _referenceConverter.GetContentType(contentReference).ToString();
            refInfo.RootRef     = _referenceConverter.GetRootLink();

            model.Refs.Add(refInfo);
        }
        protected void WalkCategoryTree(NodeContent node, 
            IContentRepository repository, 
            CatalogContentLoader contentLoader, 
            ICatalogSystem catalog,
            ReferenceConverter referenceConverter)
        {
            // ReSharper disable PossibleMultipleEnumeration
            // Get all products
            Stopwatch tmr = Stopwatch.StartNew();
            IEnumerable<EntryContentBase> entries = repository.GetChildren<EPiServer.Commerce.Catalog.ContentTypes.EntryContentBase>(node.ContentLink);
            _log.Debug("Loaded {0} entries in category {1} using IContentRepository in {2}ms",
                            entries.Count(),
                            node.Name,
                            tmr.ElapsedMilliseconds);

            // Load and cache Entry objects. Still a lot of code that uses this
            tmr = Stopwatch.StartNew();
            foreach (EntryContentBase entryAsContent in entries)
            {
                // Load full entry
                int entryId = referenceConverter.GetObjectId(entryAsContent.ContentLink);
                // Catalog Gadget uses info
                //catalog.GetCatalogEntry(entryId,
                //	new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                catalog.GetCatalogEntry(entryId,
                    new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            }

            // Prime the catalog gadget
            // IEnumerable<IContent> children = repository.GetChildren<IContent>(node.ContentLink, new LanguageSelector("en"), 0, int.MaxValue);
            // _log.Debug("Loaded {0} children", children.Count());

            // .GetDescendents(node.ContentLink);

            tmr.Stop();
            _log.Debug("Loaded {0} entries in category {1} using ICatalogSystem in {2}ms",
                            entries.Count(),
                            node.Name,
                            tmr.ElapsedMilliseconds);

            // Get all products the way it is done in edit mode, but this does not seem to
            // use the cache.
            //int loadedEntries;
            //contentLoader.GetCatalogEntries(node.ContentLink, 0, int.MaxValue, out loadedEntries);
            //_log.Debug("Loaded {0} entries in category {1} using CatalogContentLoader", loadedEntries, node.Name);

            // Get child nodes the same way done by the UI
            IList<GetChildrenReferenceResult> catalogNodes = contentLoader.GetCatalogNodes(node.ContentLink);
            _log.Debug("Loaded {0} categories in category {1} using CatalogContentLoader", catalogNodes.Count, node.Name);
            foreach (GetChildrenReferenceResult catalogNode in catalogNodes)
            {
                NodeContent childNode = repository.Get<NodeContent>(catalogNode.ContentLink);
                WalkCategoryTree(childNode, repository, contentLoader, catalog, referenceConverter);
            }
            // ReSharper restore PossibleMultipleEnumeration
        }