/// <summary>
        /// The event this handles fires after a document is published in the back office and the cache is updated.
        /// We render out the page and store it's HTML in the database for retrieval by the indexer.
        /// </summary>
        /// <param name="sender">Document being published</param>
        /// <param name="e">Event Arguments</param>
        /// <remarks>
        /// the indexer thread doesn't always access to a fully initialised umbraco core to do the rendering,
        /// whereas this event always should, hence this method rather than doing both rendering and indexing
        /// in the same thread
        /// </remarks>
        private void ContentAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e)
        {
            if (sender == null || sender.Id < 1)
            {
                return;
            }
            var id = sender.Id;

            // get config and check we're enabled and good to go
            if (!CheckConfig())
            {
                return;
            }
            // this can take a while...
            Library.SetTimeout(Config.Instance.GetByKey("ScriptTimeout"));
            var nodeTypeAlias = sender.ContentType.Alias;

            var    renderer = Manager.Instance.DocumentRendererFactory.CreateNew(nodeTypeAlias);
            string fullHtml;

            if (renderer.Render(id, out fullHtml))
            {
                HtmlCache.Store(id, ref fullHtml);
            }
            else
            {
                HtmlCache.Remove(id);
            }
        }
Esempio n. 2
0
 private static void ContentAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e)
 {
     //ensure that only the providers that have DONT unpublishing support enabled
     //that are also flagged to listen
     ExamineManager.Instance.ReIndexNode(ToXDocument(sender, true).Root, IndexTypes.Content,
                                         ExamineManager.Instance.IndexProviderCollection.OfType <BaseUmbracoIndexer>()
                                         .Where(x => !x.SupportUnpublishedContent &&
                                                x.EnableDefaultEventHandler));
 }
Esempio n. 3
0
        private void content_AfterClearDocumentCache(Document sender, DocumentCacheEventArgs e)
        {
            var nodeId = sender.Id.ToString();

            //ensure that only the providers that DONT have unpublishing support enabled
            //that are also flagged to listen
            ExamineManager.Instance.DeleteFromIndex(nodeId,
                                                    ExamineManager.Instance.IndexProviderCollection.OfType <BaseUmbracoIndexer>()
                                                    .Where(x => !x.SupportUnpublishedContent &&
                                                           x.EnableDefaultEventHandler));
        }
        void ContentAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e)
        {

            Logger.Info("Received update cache event");

            var content = UmbracoContext.Current.Application.Services.ContentService.GetById(sender.Id);
            var runtimeContentModel = RuntimeUmbracoContext.Instance.UmbracoContentSerialiser.Serialise(content);

            foreach (var adapter in RuntimeUmbracoContext.Instance.DeploymentAdapters)
            {
                adapter.DeployContent(runtimeContentModel, DeploymentAction.Deploy);
            }
        }
 void content_BeforeClearDocumentCache(Document doc, DocumentCacheEventArgs e)
 {
     #if !DEBUG
     try
     #endif
     {
         UrlTrackerRepository.AddGoneEntryByNodeId(doc.Id);
     }
     #if !DEBUG
     catch (Exception ex)
     {
         ex.LogException(doc.Id);
     }
     #endif
 }
Esempio n. 6
0
        void content_BeforeClearDocumentCache(Document doc, DocumentCacheEventArgs e)
        {
#if !DEBUG
            try
#endif
            {
                UrlTrackerRepository.AddGoneEntryByNodeId(doc.Id);
            }
#if !DEBUG
            catch (Exception ex)
            {
                ex.LogException();
            }
#endif
        }
        private void ContentOnAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs documentCacheEventArgs)
        {
            //if (sender.ContentType.Alias.StartsWith("uwbs") && sender.ContentType.Alias != Order.NodeAlias)
            //todo: work with aliasses from config
            var alias = sender.ContentType.Alias;

            // todo: make a nice way for this block
            if (Product.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (ProductVariant.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (Category.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (PaymentProvider.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (PaymentProviderMethod.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (DiscountProduct.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (DiscountOrder.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (ShippingProvider.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (ShippingProviderMethod.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (Store.IsAlias(alias))
            {
                ResetAll(sender.Id, alias);
            }
            else if (alias.StartsWith("uwbs") && alias != Order.NodeAlias)
            {
                ResetAll(sender.Id, alias);
            }

            var storePickerProperty = sender.getProperty(Constants.StorePickerAlias);

            if (storePickerProperty != null)
            {
                int storeId;
                if (storePickerProperty.Value != null && int.TryParse(storePickerProperty.Value.ToString(), out storeId))
                {
                    var storeService = StoreHelper.StoreService;
                    var storeById    = storeService.GetById(storeId, null);
                    if (storeById != null)
                    {
                        storeService.TriggerStoreChangedEvent(storeById);
                    }
                }
            }

            if (alias.StartsWith(Settings.NodeAlias))
            {
                IO.Container.Resolve <ISettingsService>().TriggerSettingsChangedEvent(SettingsLoader.GetSettings());
            }

            if (alias.StartsWith(Store.NodeAlias))
            {
                //todo: naar nieuwe v6+ API omzetten
                var storeService = StoreHelper.StoreService;
                storeService.TriggerStoreChangedEvent(storeService.GetById(sender.Id, null));
                var node = new Node(sender.Id);
                if (!sender.Text.Equals(node.Name))
                {
                    StoreHelper.RenameStore(node.Name, sender.Text);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Fires the after document cache unpublish.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="umbraco.cms.businesslogic.DocumentCacheEventArgs"/> instance containing the event data.</param>
 protected virtual void FireAfterClearDocumentCache(Document sender, DocumentCacheEventArgs e)
 {
     if (AfterClearDocumentCache != null)
     {
         AfterClearDocumentCache(sender, e);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Fires the before document cache unpublish.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="umbraco.cms.businesslogic.DocumentCacheEventArgs"/> instance containing the event data.</param>
 protected virtual void FireBeforeClearDocumentCache(Document sender, DocumentCacheEventArgs e)
 {
     if (BeforeClearDocumentCache != null)
     {
         BeforeClearDocumentCache(sender, e);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Clears the document cache and removes the document from the xml db cache.
        /// This means the node gets unpublished from the website.
        /// </summary>
        /// <param name="documentId">The document id.</param>
        public virtual void ClearDocumentCache(int documentId)
        {
            // Get the document
            var d = new Document(documentId);

            var e = new DocumentCacheEventArgs();
            FireBeforeClearDocumentCache(d, e);

            if (!e.Cancel)
            {
                XmlNode x;

                // remove from xml db cache 
                d.XmlRemoveFromDB();

                // Check if node present, before cloning
                x = XmlContentInternal.GetElementById(d.Id.ToString());
                if (x == null)
                    return;

                // We need to lock content cache here, because we cannot allow other threads
                // making changes at the same time, they need to be queued
                lock (_xmlContentInternalSyncLock)
                {
                    // Make copy of memory content, we cannot make changes to the same document
                    // the is read from elsewhere
                    XmlDocument xmlContentCopy = CloneXmlDoc(XmlContentInternal);

                    // Find the document in the xml cache
                    x = xmlContentCopy.GetElementById(d.Id.ToString());
                    if (x != null)
                    {
                        // The document already exists in cache, so repopulate it
                        x.ParentNode.RemoveChild(x);
                        XmlContentInternal = xmlContentCopy;
                        ClearContextCache();
                    }
                }

                if (x != null)
                {
                    // Run Handler				
                    Action.RunActionHandlers(d, ActionUnPublish.Instance);
                }

                // update sitemapprovider
                if (SiteMap.Provider is UmbracoSiteMapProvider)
                {
                    var prov = (UmbracoSiteMapProvider)SiteMap.Provider;
                    prov.RemoveNode(d.Id);
                }

                FireAfterClearDocumentCache(d, e);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Updates the document cache.
        /// </summary>
        /// <param name="d">The d.</param>
        public virtual void UpdateDocumentCache(Document d)
        {
            var e = new DocumentCacheEventArgs();
            FireBeforeUpdateDocumentCache(d, e);

            if (!e.Cancel)
            {
				// lock the xml cache so no other thread can write to it at the same time
				// note that some threads could read from it while we hold the lock, though
                lock (_xmlContentInternalSyncLock)
                {
					// modify a clone of the cache because even though we're into the write-lock
					// we may have threads reading at the same time. why is this an option?
					XmlDocument wip = UmbracoSettings.CloneXmlCacheOnPublish
						? CloneXmlDoc(XmlContentInternal)
						: XmlContentInternal;

					wip = PublishNodeDo(d, wip, true);
					XmlContentInternal = wip;

                    ClearContextCache();
                }

                // clear cached field values
                if (HttpContext.Current != null)
                {
                    System.Web.Caching.Cache httpCache = HttpContext.Current.Cache;
                    string cachedFieldKeyStart = String.Format("contentItem{0}_", d.Id);
                    var foundKeys = new List<string>();
                    foreach (DictionaryEntry cacheItem in httpCache)
                    {
                        string key = cacheItem.Key.ToString();
                        if (key.StartsWith(cachedFieldKeyStart))
                            foundKeys.Add(key);
                    }
                    foreach (string foundKey in foundKeys)
                    {
                        httpCache.Remove(foundKey);
                    }
                }
                Action.RunActionHandlers(d, ActionPublish.Instance);

                FireAfterUpdateDocumentCache(d, e);
            }
        }
Esempio n. 12
0
		private static void ContentAfterClearDocumentCache(Document sender, DocumentCacheEventArgs e)
		{
			var nodeId = sender.Id.ToString();
			//ensure that only the providers that DONT have unpublishing support enabled           
			//that are also flagged to listen
			ExamineManager.Instance.DeleteFromIndex(nodeId,
				ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
					.Where(x => !x.SupportUnpublishedContent
						&& x.EnableDefaultEventHandler));
		}
Esempio n. 13
0
		private static void ContentAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e)
		{
			//ensure that only the providers that have DONT unpublishing support enabled       
			//that are also flagged to listen
			ExamineManager.Instance.ReIndexNode(ToXDocument(sender, true).Root, IndexTypes.Content,
				ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
					.Where(x => !x.SupportUnpublishedContent
						&& x.EnableDefaultEventHandler));
		}
Esempio n. 14
0
        /// <summary>
        /// Updates the document cache.
        /// </summary>
        /// <param name="d">The d.</param>
        public virtual void UpdateDocumentCache(Document d)
        {
            var e = new DocumentCacheEventArgs();
            FireBeforeUpdateDocumentCache(d, e);

            if (!e.Cancel)
            {
				// lock the xml cache so no other thread can write to it at the same time
				// note that some threads could read from it while we hold the lock, though
                lock (XmlContentInternalSyncLock)
                {
					// modify a clone of the cache because even though we're into the write-lock
					// we may have threads reading at the same time. why is this an option?
                    XmlDocument wip = UmbracoConfig.For.UmbracoSettings().Content.CloneXmlContent
						? CloneXmlDoc(XmlContentInternal)
						: XmlContentInternal;

					wip = PublishNodeDo(d, wip, true);
					XmlContentInternal = wip;

                    ClearContextCache();
                }

                var cachedFieldKeyStart = string.Format("{0}{1}_", CacheKeys.ContentItemCacheKey, d.Id);
                ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(cachedFieldKeyStart);                    

                FireAfterUpdateDocumentCache(d, e);
            }
        }
		private void ContentOnAfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs documentCacheEventArgs)
		{
			//if (sender.ContentType.Alias.StartsWith("uwbs") && sender.ContentType.Alias != Order.NodeAlias)
			//todo: work with aliasses from config
			var alias = sender.ContentType.Alias;
			// todo: make a nice way for this block
			if (Product.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (ProductVariant.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (Category.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (PaymentProvider.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (PaymentProviderMethod.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (DiscountProduct.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (DiscountOrder.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (ShippingProvider.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (ShippingProviderMethod.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (Store.IsAlias(alias))
			{
				ResetAll(sender.Id, alias);
			}
			else if (alias.StartsWith("uwbs") && alias != Order.NodeAlias)
			{
				ResetAll(sender.Id, alias);
			}
			
			var storePickerProperty = sender.getProperty(Constants.StorePickerAlias);
			if (storePickerProperty != null)
			{
				int storeId;
				if (storePickerProperty.Value != null && int.TryParse(storePickerProperty.Value.ToString(), out storeId))
				{
					var storeService = StoreHelper.StoreService;
					var storeById = storeService.GetById(storeId, null);
					if (storeById != null)
					{
						storeService.TriggerStoreChangedEvent(storeById);
					}
				}
			}

			if (alias.StartsWith(Settings.NodeAlias))
			{
				IO.Container.Resolve<ISettingsService>().TriggerSettingsChangedEvent(SettingsLoader.GetSettings());
			}

			if (alias.StartsWith(Store.NodeAlias))
			{
				//todo: naar nieuwe v6+ API omzetten
				var storeService = StoreHelper.StoreService;
				storeService.TriggerStoreChangedEvent(storeService.GetById(sender.Id, null));
				var node = new Node(sender.Id);
				if (!sender.Text.Equals(node.Name))
				{
					StoreHelper.RenameStore(node.Name, sender.Text);
				}
			}
		}