From 2a96b993e4b7d74dc9dfdc8fdc636ee997e279cc Mon Sep 17 00:00:00 2001 From: slace Date: Mon, 29 Nov 2010 12:23:55 +0000 Subject: [PATCH] Prelim support for LINQ to Umbraco being able to run a preview NodeDataProvider [TFS Changeset #80842] --- umbraco/presentation/UmbracoServerUtility.cs | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/umbraco/presentation/UmbracoServerUtility.cs b/umbraco/presentation/UmbracoServerUtility.cs index 4392caa3c0..992d923d0b 100644 --- a/umbraco/presentation/UmbracoServerUtility.cs +++ b/umbraco/presentation/UmbracoServerUtility.cs @@ -5,6 +5,9 @@ using umbraco.BasePages; using umbraco.cms.businesslogic.web; using System.Xml.Linq; using umbraco.IO; +using umbraco.presentation.preview; +using umbraco.BusinessLogic; +using System.Xml; namespace umbraco.presentation { @@ -49,6 +52,7 @@ namespace umbraco.presentation } } + private readonly string XDocumentCacheKey = "XDocumentCache"; /// /// Gets the Umbraco XML cache /// @@ -57,10 +61,35 @@ namespace umbraco.presentation { get { - return XDocument.Load(this.MapPath(this.ContentXmlPath)); + if (UmbracoContext.Current.InPreviewMode) + { + PreviewContent pc = new PreviewContent(new Guid(StateHelper.GetCookieValue("PreviewSet"))); + pc.LoadPreviewset(); + return XmlDocumentToXDocument(pc.XmlContent); + } + else + { + if (HttpContext.Current == null) + return XDocument.Load(ContentXmlPath); + XDocument xml = HttpContext.Current.Items[XDocumentCacheKey] as XDocument; + if (xml == null) + { + xml = XmlDocumentToXDocument(content.Instance.XmlContent); + HttpContext.Current.Items[XDocumentCacheKey] = xml; + } + return xml; + } } } + private XDocument XmlDocumentToXDocument(XmlDocument xml) + { + using (var nodeReader = new XmlNodeReader(xml)) + { + nodeReader.MoveToContent(); + return XDocument.Load(nodeReader); + } + } public string DataFolder { get