//Invalidate cache if editor has changed a matching page... //Remember that a page can have children that is affected as well so need to take care of those as well public void OnContentChange(object sender, EPiServer.ContentEventArgs e) { if (e == null || e.Content == null) { return; } var masterkey = GetMasterKey(e.Content); _cache.RemoveLocal(masterkey); if (e.ContentLink == null) { return; } var descendants = _contentLoader.GetDescendents(e.ContentLink); foreach (var contentLink in descendants) { var page = _contentLoader.Get <IContent>(contentLink); masterkey = GetMasterKey(page); _cache.RemoveLocal(masterkey); } masterkey = GetMasterKeyForAncestor(e.ContentLink); _cache.RemoveLocal(masterkey); var ancestors = _contentLoader.GetAncestors(e.ContentLink); foreach (var ancestor in ancestors) { masterkey = GetMasterKeyForAncestor(ancestor.ContentLink); _cache.RemoveLocal(masterkey); } }
private void ContentEvents_PublishedContent(object sender, EPiServer.ContentEventArgs e) { if (e.Content is StoreLocationPage) { var storeLocation = e.Content as StoreLocationPage; // Update if not set already and warehouse code is added if (!string.IsNullOrEmpty(storeLocation.WarehouseCode) && string.IsNullOrEmpty(storeLocation.Address)) { // Find the warehouse var warehouse = WarehouseHelper.GetWarehouse(storeLocation.WarehouseCode); if (warehouse != null) { StoreLocationPage updatedPage = storeLocation.CreateWritableClone() as StoreLocationPage; // Map properties to page updatedPage.Address = SetupAddress(warehouse.ContactInformation.Line1, warehouse.ContactInformation.Line2); updatedPage.City = warehouse.ContactInformation.City; updatedPage.PostCode = warehouse.ContactInformation.PostalCode; updatedPage.State = warehouse.ContactInformation.State; updatedPage.Country = warehouse.ContactInformation.CountryName; updatedPage.Telephone = warehouse.ContactInformation.DaytimePhoneNumber; updatedPage.Fax = warehouse.ContactInformation.FaxNumber; updatedPage.Email = warehouse.ContactInformation.Email; // Update var repository = ServiceLocator.Current.GetInstance <IContentRepository>(); repository.Save(updatedPage, EPiServer.DataAccess.SaveAction.ForceCurrentVersion); } } } }
private void ContentEvents_CreatedContent(object sender, EPiServer.ContentEventArgs e) { if (e.Content is ProjectExperimentMapping mapping) { if (mapping.ExperimentMapping == null) { var updatedContent = mapping.CreateWritableClone() as ProjectExperimentMapping; if (updatedContent.ExperimentMapping == null) { updatedContent.ExperimentMapping = new List <ExperimentMapItem>(); } var variations = _experimentationClient.Value.GetExperiment(mapping.ExperimentKey).Variations; var appProjects = _projectRepo.Value.List().ToList(); foreach (var variation in variations) { var mappingItem = new ExperimentMapItem() { VariationKey = variation.Key, VariationDescription = variation.Description }; var project = appProjects.Where(x => x.Name == variation.Description); if (project.Count() == 1) { mappingItem.ProjectId = project.First().ID.ToString(); } updatedContent.ExperimentMapping.Add(mappingItem); } _contentRepo.Value.Save(updatedContent as IContent, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess); e.CancelAction = true; } } }
private void ContentEv_PublishedContent(object sender, EPiServer.ContentEventArgs e) { var info = new List <string> { "Published Content Event Fired!", $"The name of the item published: {e.Content.Name}" }; WriteToTextFile(info); }
void Service_MovedContent(object sender, EPiServer.ContentEventArgs e) { if (e.TargetLink.CompareToIgnoreWorkID(SiteDefinition.Current.WasteBasket)) { VulcanHandler.Service.DeleteContentEveryLanguage(e.ContentLink); } else { VulcanHandler.Service.IndexContentEveryLanguage(e.Content); } }
void Service_PublishedContent(object sender, EPiServer.ContentEventArgs e) { // Update the index for the currently published content VulcanHandler.Service.IndexContentByLanguage(e.Content); // See if there are references to the content and if so, update the index for them as well var references = ContentRepository.Service.GetReferencesToContent(e.ContentLink, false); foreach (var r in references.Where(x => !x.OwnerID.CompareToIgnoreWorkID(e.ContentLink))) { VulcanHandler.Service.IndexContentByLanguage(ContentRepository.Service.Get <IContent>(r.OwnerID)); } }
private void DeleteEvent_MovedContent(object sender, EPiServer.ContentEventArgs e) { if (e.Content != null) { ITrashBin siteTrashBin = this.contentRepository.GetChildren <IContent>(SiteDefinition.Current.StartPage) .OfType <ITrashBin>() .FirstOrDefault(); if (e.TargetLink.CompareToIgnoreWorkID(ContentReference.WasteBasket)) { if (siteTrashBin != null && !ContentReference.IsNullOrEmpty(siteTrashBin?.ContentLink)) { var originalParent = ((MoveContentEventArgs)e).OriginalParent; if (!originalParent.CompareToIgnoreWorkID(siteTrashBin.ContentLink)) { this.contentRepository.Move(e.ContentLink, siteTrashBin.ContentLink); } } } } }
void Service_DeletedContentLanguage(object sender, EPiServer.ContentEventArgs e) { VulcanHandler.Service.DeleteContentByLanguage(e.Content); }