From 4c2ffb00f9c083d57c55b2ac6d7aab2cb3d5d236 Mon Sep 17 00:00:00 2001 From: hartvig Date: Mon, 12 Sep 2011 11:19:37 -0200 Subject: [PATCH] Work items: 30148 --- umbraco/cms/businesslogic/events/EventArgs.cs | 4 + umbraco/presentation/content.cs | 126 ++++++++++++++++-- umbraco/presentation/macro.cs | 30 +++-- .../dashboard/DesktopMediaUploader.ascx | 2 +- .../dashboard/DeveloperDashboardIntro.ascx | 2 +- .../dashboard/DeveloperDashboardVideos.ascx | 2 +- .../dashboard/MediaDashboardIntro.ascx | 2 +- .../dashboard/MediaDashboardVideos.ascx | 2 +- .../dashboard/MembersDashboardIntro.ascx | 2 +- .../dashboard/MembersDashboardVideos.ascx | 2 +- .../dashboard/SettingsDashboardIntro.ascx | 2 +- .../dashboard/SettingsDashboardVideos.ascx | 2 +- .../dashboard/StartupDashboardIntro.ascx | 2 +- .../dashboard/StartupDashboardKits.ascx | 2 +- .../dashboard/StartupDashboardVideos.ascx | 2 +- .../umbraco/members/MemberSearch.ascx | 2 +- .../umbraco/templateControls/Macro.cs | 7 +- 17 files changed, 157 insertions(+), 36 deletions(-) diff --git a/umbraco/cms/businesslogic/events/EventArgs.cs b/umbraco/cms/businesslogic/events/EventArgs.cs index 578c70efb8..3514065cee 100644 --- a/umbraco/cms/businesslogic/events/EventArgs.cs +++ b/umbraco/cms/businesslogic/events/EventArgs.cs @@ -57,5 +57,9 @@ namespace umbraco.cms.businesslogic { public int ParentId { get; internal set; } } + public class ContentCacheLoadNodeEventArgs : System.ComponentModel.CancelEventArgs + { + public bool CancelChildren { get; set; } + } } diff --git a/umbraco/presentation/content.cs b/umbraco/presentation/content.cs index b7d44030f3..b330a41e29 100644 --- a/umbraco/presentation/content.cs +++ b/umbraco/presentation/content.cs @@ -10,6 +10,7 @@ using System.Xml.XPath; using umbraco.BusinessLogic; using umbraco.BusinessLogic.Actions; +using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.cache; using umbraco.cms.businesslogic.web; using umbraco.DataLayer; @@ -743,6 +744,88 @@ namespace umbraco } + /// + /// Occurs when [after loading the xml string from the database and creating the xml node]. + /// + public delegate void ContentCacheLoadNodeEventHandler(XmlNode xmlNode, cms.businesslogic.ContentCacheLoadNodeEventArgs e); + + /// + /// Occurs when [after loading the xml string from the database]. + /// + public delegate void ContentCacheDatabaseLoadXmlStringEventHandler(ref string xml, cms.businesslogic.ContentCacheLoadNodeEventArgs e); + + /// + /// Occurs when [after loading the xml string from the database]. + /// + public static event ContentCacheDatabaseLoadXmlStringEventHandler AfterContentCacheDatabaseLoadXmlString; + + /// + /// Fires the before when creating the document cache from database + /// + /// The sender. + /// The instance containing the event data. + internal static void FireAfterContentCacheDatabaseLoadXmlString(ref string xml, cms.businesslogic.ContentCacheLoadNodeEventArgs e) + { + if (AfterContentCacheDatabaseLoadXmlString != null) + { + AfterContentCacheDatabaseLoadXmlString(ref xml, e); + } + } + + /// + /// Occurs when [before when creating the document cache from database]. + /// + public static event ContentCacheLoadNodeEventHandler BeforeContentCacheLoadNode; + + /// + /// Fires the before when creating the document cache from database + /// + /// The sender. + /// The instance containing the event data. + internal static void FireBeforeContentCacheLoadNode(XmlNode node, cms.businesslogic.ContentCacheLoadNodeEventArgs e) + { + if (BeforeContentCacheLoadNode != null) + { + BeforeContentCacheLoadNode(node, e); + } + } + + /// + /// Occurs when [after loading document cache xml node from database]. + /// + public static event ContentCacheLoadNodeEventHandler AfterContentCacheLoadNodeFromDatabase; + + /// + /// Fires the after loading document cache xml node from database + /// + /// The sender. + /// The instance containing the event data. + internal static void FireAfterContentCacheLoadNodeFromDatabase(XmlNode node, cms.businesslogic.ContentCacheLoadNodeEventArgs e) + { + if (AfterContentCacheLoadNodeFromDatabase != null) + { + AfterContentCacheLoadNodeFromDatabase(node, e); + } + } + + /// + /// Occurs when [before a publish action updates the content cache]. + /// + public static event ContentCacheLoadNodeEventHandler BeforePublishNodeToContentCache; + + /// + /// Fires the before a publish action updates the content cache + /// + /// The sender. + /// The instance containing the event data. + public static void FireBeforePublishNodeToContentCache(XmlNode node, cms.businesslogic.ContentCacheLoadNodeEventArgs e) + { + if (BeforePublishNodeToContentCache != null) + { + BeforePublishNodeToContentCache(node, e); + } + } + #endregion @@ -904,21 +987,40 @@ order by umbracoNode.level, umbracoNode.sortOrder"; { int currentId = dr.GetInt("id"); int parentId = dr.GetInt("parentId"); + var xml = dr.GetString("xml"); - // Retrieve the xml content from the database - // and parse it into a DOM node - xmlDoc.LoadXml(dr.GetString("xml")); - nodeIndex.Add(currentId, xmlDoc.FirstChild); - - // Build the content hierarchy - List children; - if (!hierarchy.TryGetValue(parentId, out children)) + // Call the eventhandler to allow modification of the string + var e1 = new ContentCacheLoadNodeEventArgs(); + FireAfterContentCacheDatabaseLoadXmlString(ref xml, e1); + // check if a listener has canceled the event + if (!e1.Cancel) { - // No children for this parent, so add one - children = new List(); - hierarchy.Add(parentId, children); + // and parse it into a DOM node + xmlDoc.LoadXml(xml); + var node = xmlDoc.FirstChild; + // same event handler loader form the xml node + var e2 = new ContentCacheLoadNodeEventArgs(); + FireAfterContentCacheLoadNodeFromDatabase(node, e2); + // and checking if it was canceled again + if (!e1.Cancel) + { + nodeIndex.Add(currentId, node); + + // verify if either of the handlers canceled the children to load + if (!e1.CancelChildren && !e2.CancelChildren) + { + // Build the content hierarchy + List children; + if (!hierarchy.TryGetValue(parentId, out children)) + { + // No children for this parent, so add one + children = new List(); + hierarchy.Add(parentId, children); + } + children.Add(currentId); + } + } } - children.Add(currentId); } } } diff --git a/umbraco/presentation/macro.cs b/umbraco/presentation/macro.cs index 6cf0b3afa4..1ddb506386 100644 --- a/umbraco/presentation/macro.cs +++ b/umbraco/presentation/macro.cs @@ -42,6 +42,9 @@ namespace umbraco private static Hashtable _macroAlias = new Hashtable(); + public IList Exceptions = new List(); + private readonly Dictionary macroObjectCache = new Dictionary(); + /// Cache for . private static Dictionary m_PredefinedExtensions; @@ -148,9 +151,9 @@ namespace umbraco { macroID = id; - if (macroCache[macroCacheIdentifier + id] != null) + if (macroObjectCache.ContainsKey(macroCacheIdentifier + id)) { - var tempMacro = (macro)macroCache[macroCacheIdentifier + id]; + var tempMacro = macroObjectCache[macroCacheIdentifier + id]; Name = tempMacro.Name; Alias = tempMacro.Alias; ScriptType = tempMacro.ScriptType; @@ -226,7 +229,8 @@ namespace umbraco } } // add current macro-object to cache - macroCache.Insert(macroCacheIdentifier + id, this); + if (!macroObjectCache.ContainsKey(macroCacheIdentifier + id)) + macroObjectCache.Add(macroCacheIdentifier + id, this); } macroType = (int)Macro.FindMacroType(XsltFile, ScriptFile, ScriptType, ScriptAssembly); @@ -313,16 +317,16 @@ namespace umbraco ClearAliasCache(); if (macroID > 0) { - if (macroCache[macroCacheIdentifier + macroID] != null) + if (macroObjectCache.ContainsKey(macroCacheIdentifier + macroID)) { - macroCache.Remove(macroCacheIdentifier + macroID); + macroObjectCache.Remove(macroCacheIdentifier + macroID); return true; } - else - return false; - } - else return false; + + } + return false; + } private string getCacheGuid(MacroModel model, Hashtable pageElements, int pageId) @@ -416,6 +420,7 @@ namespace umbraco } catch (Exception e) { + Exceptions.Add(e); HttpContext.Current.Trace.Warn("umbracoMacro", "Error loading userControl (" + scriptType + ")", e); macroControl = new LiteralControl("Error loading userControl '" + scriptType + "'"); @@ -431,6 +436,7 @@ namespace umbraco } catch (Exception e) { + Exceptions.Add(e); HttpContext.Current.Trace.Warn("umbracoMacro", "Error loading customControl (Assembly: " + scriptAssembly + ", Type: '" + scriptType + "'", e); @@ -453,6 +459,7 @@ namespace umbraco } catch (Exception e) { + Exceptions.Add(e); HttpContext.Current.Trace.Warn("umbracoMacro", "Error loading MacroEngine script (file: " + ScriptFile + ", Type: '" + scriptType + "'", e); @@ -673,6 +680,8 @@ namespace umbraco } catch (Exception e) { + Exceptions.Add(e); + // inner exception code by Daniel Lindström from SBBS.se Exception ie = e; while (ie != null) @@ -685,6 +694,7 @@ namespace umbraco } catch (Exception e) { + Exceptions.Add(e); HttpContext.Current.Trace.Warn("umbracoMacro", "Error loading XSLT " + xsltFile, e); return new LiteralControl("Error reading XSLT file: \\xslt\\" + XsltFile); } @@ -804,7 +814,7 @@ namespace umbraco return umbraco.cms.businesslogic.cache.Cache.GetCacheItem( _xsltExtensionsCacheKey, _xsltExtensionsSyncLock, - CacheItemPriority.Normal, // normal priority + CacheItemPriority.NotRemovable, // NH 4.7.1, Changing to NotRemovable null, // no refresh action new CacheDependency(_xsltExtensionsConfig), // depends on the .config file TimeSpan.FromDays(1), // expires in 1 day (?) diff --git a/umbraco/presentation/umbraco/dashboard/DesktopMediaUploader.ascx b/umbraco/presentation/umbraco/dashboard/DesktopMediaUploader.ascx index 09f6a270f7..57283b16ee 100644 --- a/umbraco/presentation/umbraco/dashboard/DesktopMediaUploader.ascx +++ b/umbraco/presentation/umbraco/dashboard/DesktopMediaUploader.ascx @@ -2,7 +2,7 @@

Desktop Media Uploader

- Umbraco + Umbraco

Desktop Media Uploader is a small desktop application that you can install on your computer which allows you to easily upload media items directly to the media section.

The badge below will auto configure itself based upon whether you already have Desktop Media Uploader installed or not.

Just click the Install Now / Upgrade Now / Launch Now link to perform that action.

diff --git a/umbraco/presentation/umbraco/dashboard/DeveloperDashboardIntro.ascx b/umbraco/presentation/umbraco/dashboard/DeveloperDashboardIntro.ascx index 448dade455..cb502bc125 100644 --- a/umbraco/presentation/umbraco/dashboard/DeveloperDashboardIntro.ascx +++ b/umbraco/presentation/umbraco/dashboard/DeveloperDashboardIntro.ascx @@ -4,7 +4,7 @@

Start here

- Umbraco + Umbraco

This section contains the tools to add advanced features to your Umbraco site

diff --git a/umbraco/presentation/umbraco/dashboard/DeveloperDashboardVideos.ascx b/umbraco/presentation/umbraco/dashboard/DeveloperDashboardVideos.ascx index dcd404e7d3..3c301a7bf7 100644 --- a/umbraco/presentation/umbraco/dashboard/DeveloperDashboardVideos.ascx +++ b/umbraco/presentation/umbraco/dashboard/DeveloperDashboardVideos.ascx @@ -107,7 +107,7 @@

Watch and learn

- Videos + Videos

Hours of Umbraco training videos are only a click away

Want to master Umbraco Macros and more? Spend a couple of minutes learning some best practices diff --git a/umbraco/presentation/umbraco/dashboard/MediaDashboardIntro.ascx b/umbraco/presentation/umbraco/dashboard/MediaDashboardIntro.ascx index b5fbfe8d4c..0ab1cc56cd 100644 --- a/umbraco/presentation/umbraco/dashboard/MediaDashboardIntro.ascx +++ b/umbraco/presentation/umbraco/dashboard/MediaDashboardIntro.ascx @@ -4,7 +4,7 @@

Start here

- Umbraco + Umbraco

Get started with Media right now

diff --git a/umbraco/presentation/umbraco/dashboard/MediaDashboardVideos.ascx b/umbraco/presentation/umbraco/dashboard/MediaDashboardVideos.ascx index dd3e0d26c5..87e3432aab 100644 --- a/umbraco/presentation/umbraco/dashboard/MediaDashboardVideos.ascx +++ b/umbraco/presentation/umbraco/dashboard/MediaDashboardVideos.ascx @@ -106,7 +106,7 @@

Watch and learn

- Videos + Videos

Hours of Umbraco training videos are only a click away

Want to master Umbraco? Spend a couple of minutes learning some best practices diff --git a/umbraco/presentation/umbraco/dashboard/MembersDashboardIntro.ascx b/umbraco/presentation/umbraco/dashboard/MembersDashboardIntro.ascx index 2ca8c7d02c..4969c1ed9d 100644 --- a/umbraco/presentation/umbraco/dashboard/MembersDashboardIntro.ascx +++ b/umbraco/presentation/umbraco/dashboard/MembersDashboardIntro.ascx @@ -4,7 +4,7 @@

Start here

- Umbraco + Umbraco

Get started with Members right now

diff --git a/umbraco/presentation/umbraco/dashboard/MembersDashboardVideos.ascx b/umbraco/presentation/umbraco/dashboard/MembersDashboardVideos.ascx index 539c3c8822..bf141cfd57 100644 --- a/umbraco/presentation/umbraco/dashboard/MembersDashboardVideos.ascx +++ b/umbraco/presentation/umbraco/dashboard/MembersDashboardVideos.ascx @@ -106,7 +106,7 @@

Watch and learn

- Videos + Videos

Hours of Umbraco training videos are only a click away

Want to master Umbraco Members? Spend a couple of minutes learning some best practices diff --git a/umbraco/presentation/umbraco/dashboard/SettingsDashboardIntro.ascx b/umbraco/presentation/umbraco/dashboard/SettingsDashboardIntro.ascx index 3c78009f3f..1a8844b0c4 100644 --- a/umbraco/presentation/umbraco/dashboard/SettingsDashboardIntro.ascx +++ b/umbraco/presentation/umbraco/dashboard/SettingsDashboardIntro.ascx @@ -4,7 +4,7 @@

Start here

- Umbraco + Umbraco

This section contains the building blocks for your Umbraco site

diff --git a/umbraco/presentation/umbraco/dashboard/SettingsDashboardVideos.ascx b/umbraco/presentation/umbraco/dashboard/SettingsDashboardVideos.ascx index 5b6eaa7255..d0aaf17f49 100644 --- a/umbraco/presentation/umbraco/dashboard/SettingsDashboardVideos.ascx +++ b/umbraco/presentation/umbraco/dashboard/SettingsDashboardVideos.ascx @@ -106,7 +106,7 @@

Watch and learn

- Videos + Videos

Hours of Umbraco training videos are only a click away

Want to master Umbraco? Spend a couple of minutes learning some best practices diff --git a/umbraco/presentation/umbraco/dashboard/StartupDashboardIntro.ascx b/umbraco/presentation/umbraco/dashboard/StartupDashboardIntro.ascx index 486eb0d00f..0de0c753a1 100644 --- a/umbraco/presentation/umbraco/dashboard/StartupDashboardIntro.ascx +++ b/umbraco/presentation/umbraco/dashboard/StartupDashboardIntro.ascx @@ -3,7 +3,7 @@

Start Here

- Umbraco + Umbraco

Thank you for choosing Umbraco!

We think this could be the beginning of something beautiful. You have made a great diff --git a/umbraco/presentation/umbraco/dashboard/StartupDashboardKits.ascx b/umbraco/presentation/umbraco/dashboard/StartupDashboardKits.ascx index daccd74497..b6f1d8b7ef 100644 --- a/umbraco/presentation/umbraco/dashboard/StartupDashboardKits.ascx +++ b/umbraco/presentation/umbraco/dashboard/StartupDashboardKits.ascx @@ -3,7 +3,7 @@

Make it look great

- Umbraco Starter Kits Rock! + Umbraco Starter Kits Rock!

Install a Starter Site and Skin

If you haven't already installed one of our Starter Kits, we think you should do that now. This is one of the best ways to start working with Umbraco. diff --git a/umbraco/presentation/umbraco/dashboard/StartupDashboardVideos.ascx b/umbraco/presentation/umbraco/dashboard/StartupDashboardVideos.ascx index dd3e0d26c5..87e3432aab 100644 --- a/umbraco/presentation/umbraco/dashboard/StartupDashboardVideos.ascx +++ b/umbraco/presentation/umbraco/dashboard/StartupDashboardVideos.ascx @@ -106,7 +106,7 @@

Watch and learn

- Videos + Videos

Hours of Umbraco training videos are only a click away

Want to master Umbraco? Spend a couple of minutes learning some best practices diff --git a/umbraco/presentation/umbraco/members/MemberSearch.ascx b/umbraco/presentation/umbraco/members/MemberSearch.ascx index 9bb9863be2..f30a7b7a4e 100644 --- a/umbraco/presentation/umbraco/members/MemberSearch.ascx +++ b/umbraco/presentation/umbraco/members/MemberSearch.ascx @@ -2,7 +2,7 @@ <%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>

Member Search

- Videos + Videos

diff --git a/umbraco/presentation/umbraco/templateControls/Macro.cs b/umbraco/presentation/umbraco/templateControls/Macro.cs index ea44f42c58..584a91dc93 100644 --- a/umbraco/presentation/umbraco/templateControls/Macro.cs +++ b/umbraco/presentation/umbraco/templateControls/Macro.cs @@ -78,7 +78,6 @@ namespace umbraco.presentation.templateControls ViewState["FileLocation"] = value.ToLower(); } } - [Bindable(true)] [Category("Umbraco")] [DefaultValue(RenderEvents.Init)] @@ -106,6 +105,8 @@ namespace umbraco.presentation.templateControls Render } + public IList Exceptions = new List(); + /// /// Raises the event. /// @@ -162,7 +163,11 @@ namespace umbraco.presentation.templateControls } var c = tempMacro.renderMacro(model, (Hashtable)Context.Items["pageElements"], pageId); if (c != null) + { + Exceptions = tempMacro.Exceptions; + Controls.Add(c); + } else System.Web.HttpContext.Current.Trace.Warn("Template", "Result of inline macro scripting is null");