Example #1
0
        public void NodeUpdated(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("NodeUpdated raised.");

            var configuration = KachingConfiguration.Instance;

            IEnumerable <ContentReference> contentLinks = GetContentLinks(e);

            NodeContent[] nodes = _contentLoader.GetItems(contentLinks, CultureInfo.InvariantCulture)
                                  .OfType <NodeContent>()
                                  .ToArray();

            // If this event was triggered by a move, re-export the complete category structure.
            if (e.HasChangedParent)
            {
                _categoryExportService.StartFullCategoryExport(
                    configuration.TagsImportUrl,
                    configuration.FoldersImportUrl);
            }

            foreach (NodeContent node in nodes)
            {
                _productExportService.ExportChildProducts(node);
            }
        }
Example #2
0
        private IEnumerable <ContentReference> GetContentLinks(
            CatalogContentUpdateEventArgs eventArgs)
        {
            var uniqueLinks = new HashSet <ContentReference>();

            foreach (int entryId in eventArgs.CatalogEntryIds.Where(i => i > 0))
            {
                uniqueLinks.Add(
                    _referenceConverter.GetContentLink(
                        entryId,
                        CatalogContentType.CatalogEntry,
                        0));
            }

            foreach (int nodeId in eventArgs.CatalogNodeIds.Where(i => i > 0))
            {
                uniqueLinks.Add(
                    _referenceConverter.GetContentLink(
                        nodeId,
                        CatalogContentType.CatalogNode,
                        0));
            }

            return(uniqueLinks);
        }
Example #3
0
        public void EntryDeleted(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("EntryDeleted raised.");

            IEnumerable <ContentReference> contentLinks = GetContentLinks(e);


            // Variants
            IEnumerable <ContentReference> variantLinks = GetVariantReferences(contentLinks);

            VariationContent[] variants = _contentLoader.GetItems(variantLinks, CultureInfo.InvariantCulture)
                                          .OfType <VariationContent>()
                                          .ToArray();

            foreach (VariationContent variant in variants)
            {
                foreach (var parent in variant.GetParentProducts())
                {
                    var product = _contentLoader.Get <ProductContent>(parent);

                    IEnumerable <ContentReference> variantRefs = _relationRepository
                                                                 .GetChildren <ProductVariation>(product.ContentLink)
                                                                 .Select(r => r.Child);
                    ICollection <VariationContent> productVariants = _contentLoader
                                                                     .GetItems(variantRefs, LanguageSelector.MasterLanguage())
                                                                     .OfType <VariationContent>()
                                                                     .ToArray();

                    var configuration = KachingConfiguration.Instance;
                    if (productVariants.Count == 1 && configuration.ExportSingleVariantAsProduct)
                    {
                        _productExportService.DeleteSingleVariantProduct(variant);
                    }
                    else
                    {
                        // Since variants are not independent datatypes in Ka-ching
                        // a variant change is always a product update and not a delete
                        _productExportService.ExportProduct(product, variant.Code);
                    }
                }
            }

            // Products
            IEnumerable <ContentReference> productLinks = GetProductReferences(contentLinks);

            ProductContent[] products = _contentLoader.GetItems(productLinks, CultureInfo.InvariantCulture)
                                        .OfType <ProductContent>()
                                        .ToArray();

            _productExportService.DeleteProducts(products);
            _productExportService.DeleteProductAssets(products);
            _productExportService.DeleteProductRecommendations(products);
        }
Example #4
0
        public void NodeDeleted(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("NodeDeleted raised.");

            IEnumerable <ContentReference> contentLinks = GetContentLinks(e);

            NodeContent[] nodes = _contentLoader.GetItems(contentLinks, CultureInfo.InvariantCulture)
                                  .OfType <NodeContent>()
                                  .ToArray();

            foreach (NodeContent node in nodes)
            {
                _productExportService.DeleteChildProducts(node);
            }
        }
Example #5
0
        private void AssociationUpdated(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("AssociationUpdated raised.");

            IEnumerable <ContentReference> contentLinks         = GetContentLinks(e);
            ICollection <ContentReference> affectedProductLinks = GetAffectedProductReferences(contentLinks).ToArray();

            // HACK: Episerver does not clear the deleted associations from cache until after this event has completed.
            // In order to load the list of associations after deletions/updates, force delete the association list from cache.
            foreach (ContentReference entryRef in affectedProductLinks)
            {
                _cache.Remove("EP:ECF:Ass:" + entryRef.ID);
            }

            _productExportService.ExportProductRecommendations(affectedProductLinks, null);
        }
Example #6
0
        public void RelationUpdated(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("RelationUpdated raised.");

            // If an entry is moved to another node, export the entry.
            IEnumerable <ContentReference> contentLinks         = GetContentLinks(e);
            IEnumerable <ContentReference> affectedProductLinks = GetAffectedProductReferences(contentLinks).ToArray();

            ProductContent[] products = _contentLoader.GetItems(affectedProductLinks, CultureInfo.InvariantCulture)
                                        .OfType <ProductContent>()
                                        .ToArray();

            foreach (ProductContent product in products)
            {
                _productExportService.ExportProduct(product, null);
            }
        }
Example #7
0
        public void EntryUpdated(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("EntryUpdated raised.");

            IEnumerable <ContentReference> contentLinks         = GetContentLinks(e);
            IEnumerable <ContentReference> affectedProductLinks = GetAffectedProductReferences(contentLinks);

            ProductContent[] products = _contentLoader.GetItems(affectedProductLinks, CultureInfo.InvariantCulture)
                                        .OfType <ProductContent>()
                                        .ToArray();

            foreach (ProductContent product in products)
            {
                // TODO: Refactor to batched export.
                _productExportService.ExportProduct(product, null);
            }

            _productExportService.ExportProductAssets(products);
        }
        private void EvListner_Raised(object sender, EPiServer.Events.EventNotificationEventArgs e)
        {
            CatalogContentUpdateEventArgs eventArgs = DeSerialize((byte[])e.Param);

            if (eventArgs.EventType == CatalogEventBroadcaster.CatalogEntryUpdatedEventType)
            {
                int entryId = eventArgs.CatalogEntryIds.First();
                ReferenceConverter refConvert = ServiceLocator.Current.GetInstance <ReferenceConverter>();
                ContentReference   catRef     = refConvert.GetEntryContentLink(entryId);
                IContentLoader     loader     = ServiceLocator.Current.GetInstance <IContentLoader>();
                var catEntry = loader.Get <IContent>(catRef);

                var info = new List <string>
                {
                    "Remote Catalog Event Fired!",
                    $"The name of the item updated: {catEntry.Name}"
                };
                WriteToTextFile(info);
            }
        }
 private void ProductEventManagerOnRelationDataUpdating(object sender, CatalogContentUpdateEventArgs catalogContentUpdateEventArgs)
 {
     _log.Debug("Relation Updating ({0}): {1}", catalogContentUpdateEventArgs.EventType,
                string.Join(" | ", catalogContentUpdateEventArgs.CatalogIds));
 }
        protected void LogEventDetails(EventNotificationEventArgs eventNotificationEventArgs, string eventType)
        {
            if (_log.IsDebugEnabled())
            {
                string eventName = eventNotificationEventArgs.EventId.ToString();
                string subType   = "";
                string ids       = null;

                // Deserialize event, we need more data from it
                bool   isRemoteEvent = !IsSelfRaised(eventNotificationEventArgs);
                byte[] param         = eventNotificationEventArgs.Param as byte[];
                if (param == null)
                {
                    _log.Debug("{0} '{1}' raised. Cannot deserialize event since Param is null.", eventType, eventName);
                }
                EventArgs args = DeSerialize(param);
                if (args != null)
                {
                    CatalogKeyEventArgs keyArgs = args as CatalogKeyEventArgs;
                    if (keyArgs != null)
                    {
                        subType   = "CatalogKey";
                        eventName = keyArgs.Name;
                        if (keyArgs.CatalogKeys != null && keyArgs.CatalogKeys.Any())
                        {
                            ids = string.Join(", ", keyArgs.CatalogKeys.Select(k => k.CatalogEntryCode));
                        }
                    }

                    CatalogContentUpdateEventArgs updateArgs = args as CatalogContentUpdateEventArgs;
                    if (updateArgs != null)
                    {
                        subType   = "CatalogContentUpdate";
                        eventName = updateArgs.EventType;
                        if (updateArgs.CatalogEntryIds != null && updateArgs.CatalogEntryIds.Any())
                        {
                            ids = "Entries: " + string.Join(", ", updateArgs.CatalogEntryIds.Select(k => k));
                        }
                        if (updateArgs.CatalogNodeIds != null && updateArgs.CatalogNodeIds.Any())
                        {
                            if (string.IsNullOrEmpty(ids) == false)
                            {
                                ids += " ";
                            }
                            ids += "Nodes: " + string.Join(", ", updateArgs.CatalogNodeIds.Select(k => k));
                        }
                        if (updateArgs.CatalogAssociationIds != null && updateArgs.CatalogAssociationIds.Any())
                        {
                            if (string.IsNullOrEmpty(ids) == false)
                            {
                                ids += " ";
                            }
                            ids += "Associations: " + string.Join(", ", updateArgs.CatalogAssociationIds.Select(k => k));
                        }
                    }
                }

                if (string.IsNullOrEmpty(ids))
                {
                    ids += "none";
                }

                _log.Debug("{0} '{1}' raised with data: {2} (remote: {3}, subtype: {4})", eventType, eventName, ids, isRemoteEvent, subType);
            }
        }