diff --git a/src/Umbraco.Tests/ContentStores/PublishMediaStoreTests.cs b/src/Umbraco.Tests/ContentStores/PublishMediaStoreTests.cs index 290714dc00..8a988a7a35 100644 --- a/src/Umbraco.Tests/ContentStores/PublishMediaStoreTests.cs +++ b/src/Umbraco.Tests/ContentStores/PublishMediaStoreTests.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Xml; +using Examine; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Web; @@ -9,34 +12,258 @@ namespace Umbraco.Tests [TestFixture] public class PublishMediaStoreTests { - [Test] - public void Test_DictionaryDocument() + [TestCase("id")] + [TestCase("nodeId")] + [TestCase("__NodeId")] + public void DictionaryDocument_Id_Keys(string key) { - Func> getDictionary = i => new Dictionary() + var dicDoc = GetDictionaryDocument(idKey: key); + DoAssert(dicDoc); + } + + [TestCase("template")] + [TestCase("templateId")] + public void DictionaryDocument_Template_Keys(string key) + { + var dicDoc = GetDictionaryDocument(templateKey: key); + DoAssert(dicDoc); + } + + [TestCase("nodeName")] + [TestCase("__nodeName")] + public void DictionaryDocument_NodeName_Keys(string key) + { + var dicDoc = GetDictionaryDocument(nodeNameKey: key); + DoAssert(dicDoc); + } + + [TestCase("nodeTypeAlias")] + [TestCase("__NodeTypeAlias")] + public void DictionaryDocument_NodeTypeAlias_Keys(string key) + { + var dicDoc = GetDictionaryDocument(nodeTypeAliasKey: key); + DoAssert(dicDoc); + } + + [TestCase("path")] + [TestCase("__Path")] + public void DictionaryDocument_Path_Keys(string key) + { + var dicDoc = GetDictionaryDocument(pathKey: key); + DoAssert(dicDoc); + } + + [Test] + public void DictionaryDocument_Get_Children() + { + var child1 = GetDictionaryDocument(idVal: 222333); + var child2 = GetDictionaryDocument(idVal: 444555); + + var dicDoc = GetDictionaryDocument(children: new List() { - {"id", i.ToString()}, - {"template", "testTemplate"}, + child1, child2 + }); + + Assert.AreEqual(2, dicDoc.Children.Count()); + Assert.AreEqual(222333, dicDoc.Children.ElementAt(0).Id); + Assert.AreEqual(444555, dicDoc.Children.ElementAt(1).Id); + } + + [Test] + public void Convert_From_Search_Result() + { + var result = new SearchResult() + { + Id = 1234, + Score = 1 + }; + result.Fields.Add("__IndexType", "media"); + result.Fields.Add("__NodeId", "1234"); + result.Fields.Add("__NodeTypeAlias", "Image"); + result.Fields.Add("__Path", "-1,1234"); + result.Fields.Add("__nodeName", "Test"); + result.Fields.Add("id", "1234"); + result.Fields.Add("nodeName", "Test"); + result.Fields.Add("nodeTypeAlias", "Image"); + result.Fields.Add("parentID", "-1"); + result.Fields.Add("path", "-1,1234"); + result.Fields.Add("updateDate", "2012-07-16T10:34:09"); + result.Fields.Add("writerName", "Shannon"); + + var store = new DefaultPublishedMediaStore(); + var doc = store.ConvertFromSearchResult(result); + + DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2); + Assert.AreEqual(null, doc.Parent); + } + + [Test] + public void Convert_From_XPath_Navigator() + { + var xmlDoc = GetMediaXml(); + var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator(); + var store = new DefaultPublishedMediaStore(); + var doc = store.ConvertFromXPathNavigator(navigator); + + DoAssert(doc, 2000, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon2", 22, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1); + Assert.AreEqual(null, doc.Parent); + Assert.AreEqual(2, doc.Children.Count()); + Assert.AreEqual(2001, doc.Children.ElementAt(0).Id); + Assert.AreEqual(2002, doc.Children.ElementAt(1).Id); + } + + private XmlDocument GetMediaXml() + { + var xml = @" + + + + +]> + + + + + + + + + + +"; + + var xmlDoc = new XmlDocument(); + xmlDoc.LoadXml(xml); + return xmlDoc; + } + + private Dictionary GetDictionary( + int id, + int parentId, + string idKey, + string templateKey, + string nodeNameKey, + string nodeTypeAliasKey, + string pathKey) + { + return new Dictionary() + { + {idKey, id.ToString()}, + {templateKey, "333"}, {"sortOrder", "44"}, - {"nodeName", "Testing"}, + {nodeNameKey, "Testing"}, {"urlName", "testing"}, - {"nodeTypeAlias", "myType"}, + {nodeTypeAliasKey, "myType"}, {"nodeType", "22"}, {"writerName", "Shannon"}, - {"creatorName", "Shannon"}, + {"creatorName", "Shannon2"}, {"writerID", "33"}, - {"creatorID", "33"}, - {"path", "1,2,3,4,5"}, + {"creatorID", "44"}, + {pathKey, "1,2,3,4,5"}, {"createDate", "2012-01-02"}, - {"level", "3"} + {"updateDate", "2012-01-03"}, + {"level", "3"}, + {"parentID", parentId.ToString()} }; - - var dicDoc = new DefaultPublishedMediaStore.DictionaryDocument( - getDictionary(1234), - d => new DefaultPublishedMediaStore.DictionaryDocument( - getDictionary(321), - a => null, - a => new List()), - d => new List()); } + + private DefaultPublishedMediaStore.DictionaryDocument GetDictionaryDocument( + string idKey = "id", + string templateKey = "template", + string nodeNameKey = "nodeName", + string nodeTypeAliasKey = "nodeTypeAlias", + string pathKey = "path", + int idVal = 1234, + int parentIdVal = 321, + IEnumerable children = null) + { + if (children == null) + children = new List(); + var dicDoc = new DefaultPublishedMediaStore.DictionaryDocument( + //the dictionary + GetDictionary(idVal, parentIdVal, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey), + //callback to get the parent + d => new DefaultPublishedMediaStore.DictionaryDocument( + GetDictionary(parentIdVal, -1, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey), + //there is no parent + a => null, + //we're not going to test this so ignore + a => new List()), + //callback to get the children + d => children); + return dicDoc; + } + + private void DoAssert( + DefaultPublishedMediaStore.DictionaryDocument dicDoc, + int idVal = 1234, + int templateIdVal = 333, + int sortOrderVal = 44, + string urlNameVal = "testing", + string nodeTypeAliasVal = "myType", + int nodeTypeIdVal = 22, + string writerNameVal = "Shannon", + string creatorNameVal = "Shannon2", + int writerIdVal = 33, + int creatorIdVal = 44, + string pathVal = "1,2,3,4,5", + DateTime? createDateVal = null, + DateTime? updateDateVal = null, + int levelVal = 3, + int parentIdVal = 321) + { + if (!createDateVal.HasValue) + createDateVal = DateTime.Parse("2012-01-02"); + if (!updateDateVal.HasValue) + updateDateVal = DateTime.Parse("2012-01-03"); + + DoAssert((IDocument)dicDoc, idVal, templateIdVal, sortOrderVal, urlNameVal, nodeTypeAliasVal, nodeTypeIdVal, writerNameVal, + creatorNameVal, writerIdVal, creatorIdVal, pathVal, createDateVal, updateDateVal, levelVal); + + //now validate the parentId that has been parsed, this doesn't exist on the IDocument + Assert.AreEqual(parentIdVal, dicDoc.ParentId); + } + + private void DoAssert( + IDocument doc, + int idVal = 1234, + int templateIdVal = 333, + int sortOrderVal = 44, + string urlNameVal = "testing", + string nodeTypeAliasVal = "myType", + int nodeTypeIdVal = 22, + string writerNameVal = "Shannon", + string creatorNameVal = "Shannon2", + int writerIdVal = 33, + int creatorIdVal = 44, + string pathVal = "1,2,3,4,5", + DateTime? createDateVal = null, + DateTime? updateDateVal = null, + int levelVal = 3) + { + if (!createDateVal.HasValue) + createDateVal = DateTime.Parse("2012-01-02"); + if (!updateDateVal.HasValue) + updateDateVal = DateTime.Parse("2012-01-03"); + + Assert.AreEqual(idVal, doc.Id); + Assert.AreEqual(templateIdVal, doc.TemplateId); + Assert.AreEqual(sortOrderVal, doc.SortOrder); + Assert.AreEqual(urlNameVal, doc.UrlName); + Assert.AreEqual(nodeTypeAliasVal, doc.DocumentTypeAlias); + Assert.AreEqual(nodeTypeIdVal, doc.DocumentTypeId); + Assert.AreEqual(writerNameVal, doc.WriterName); + Assert.AreEqual(creatorNameVal, doc.CreatorName); + Assert.AreEqual(writerIdVal, doc.WriterId); + Assert.AreEqual(creatorIdVal, doc.CreatorId); + Assert.AreEqual(pathVal, doc.Path); + Assert.AreEqual(createDateVal.Value, doc.CreateDate); + Assert.AreEqual(updateDateVal.Value, doc.UpdateDate); + Assert.AreEqual(levelVal, doc.Level); + + } + + } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index f57aff8cf9..2dcbc0d25f 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -31,6 +31,7 @@ 4 + ..\packages\log4net.2.0.0\lib\net40-full\log4net.dll diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index fc18da3c20..50209bba48 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -266,6 +266,7 @@ ClientDependency.config + Designer log4net.config @@ -1447,7 +1448,9 @@ - + + Designer + diff --git a/src/Umbraco.Web.UI/Web.config b/src/Umbraco.Web.UI/Web.config index 43dea5529d..aa7e19c746 100644 --- a/src/Umbraco.Web.UI/Web.config +++ b/src/Umbraco.Web.UI/Web.config @@ -33,12 +33,12 @@ - + - - + + diff --git a/src/Umbraco.Web/BaseRest/BaseRestHandler.cs b/src/Umbraco.Web/BaseRestHandler.cs similarity index 95% rename from src/Umbraco.Web/BaseRest/BaseRestHandler.cs rename to src/Umbraco.Web/BaseRestHandler.cs index 17e33466d4..9f2b3323cd 100644 --- a/src/Umbraco.Web/BaseRest/BaseRestHandler.cs +++ b/src/Umbraco.Web/BaseRestHandler.cs @@ -1,14 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Web; using System.Web.SessionState; using System.Reflection; using System.Xml; using System.IO; -namespace Umbraco.Web.BaseRest +namespace Umbraco.Web { internal class BaseRestHandler : IHttpHandler, IRequiresSessionState { diff --git a/src/Umbraco.Web/DefaultPublishedMediaStore.cs b/src/Umbraco.Web/DefaultPublishedMediaStore.cs index 9eac930d55..fd4ce31389 100644 --- a/src/Umbraco.Web/DefaultPublishedMediaStore.cs +++ b/src/Umbraco.Web/DefaultPublishedMediaStore.cs @@ -8,6 +8,7 @@ using Examine; using Umbraco.Core; using Umbraco.Core.Dynamics; using Umbraco.Core.Models; +using umbraco; namespace Umbraco.Web { @@ -62,30 +63,68 @@ namespace Umbraco.Web internal IDocument ConvertFromSearchResult(SearchResult searchResult) { - //TODO: Unit test this - //NOTE: we could just use the ExamineExtensions.ConvertFromSearchResult method but it will be faster to just - // use the data store in Examine cache. - throw new NotImplementedException(); + //TODO: Some fields will not be included, that just the way it is unfortunatley until this is fixed: + // http://examine.codeplex.com/workitem/10350 + + var values = new Dictionary(searchResult.Fields); + //we need to ensure some fields exist, because of the above issue + if (!new []{"template", "templateId"}.Any(values.ContainsKey)) + values.Add("template", 0.ToString()); + if (!new[] { "sortOrder" }.Any(values.ContainsKey)) + values.Add("sortOrder", 0.ToString()); + if (!new[] { "urlName" }.Any(values.ContainsKey)) + values.Add("urlName", ""); + if (!new[] { "nodeType" }.Any(values.ContainsKey)) + values.Add("nodeType", 0.ToString()); + if (!new[] { "creatorName" }.Any(values.ContainsKey)) + values.Add("creatorName", ""); + if (!new[] { "writerID" }.Any(values.ContainsKey)) + values.Add("writerID", 0.ToString()); + if (!new[] { "creatorID" }.Any(values.ContainsKey)) + values.Add("creatorID", 0.ToString()); + if (!new[] { "createDate" }.Any(values.ContainsKey)) + values.Add("createDate", default(DateTime).ToString("yyyy-MM-dd HH:mm:ss")); + if (!new[] { "level" }.Any(values.ContainsKey)) + { + values.Add("level", values["__Path"].Split(',').Length.ToString()); + } + + + return new DictionaryDocument(values, + d => d.ParentId != -1 //parent should be null if -1 + ? GetUmbracoMedia(d.ParentId) + : null, + //callback to return the children of the current node + d => GetChildrenMedia(d.ParentId)); } internal IDocument ConvertFromXPathNavigator(XPathNavigator xpath) { - //TODO: Unit test this - if (xpath == null) throw new ArgumentNullException("xpath"); var values = new Dictionary {{"nodeName", xpath.GetAttribute("nodeName", "")}}; - + if (!UmbracoSettings.UseLegacyXmlSchema) + { + values.Add("nodeTypeAlias", xpath.Name); + } + var result = xpath.SelectChildren(XPathNodeType.Element); //add the attributes e.g. id, parentId etc if (result.Current != null && result.Current.HasAttributes) { if (result.Current.MoveToFirstAttribute()) { - values.Add(result.Current.Name, result.Current.Value); + //checking for duplicate keys because of the 'nodeTypeAlias' might already be added above. + if (!values.ContainsKey(result.Current.Name)) + { + values.Add(result.Current.Name, result.Current.Value); + } while (result.Current.MoveToNextAttribute()) { - values.Add(result.Current.Name, result.Current.Value); + if (!values.ContainsKey(result.Current.Name)) + { + values.Add(result.Current.Name, result.Current.Value); + } } result.Current.MoveToParent(); } @@ -108,9 +147,78 @@ namespace Umbraco.Web } return new DictionaryDocument(values, - d => d.ParentId.HasValue ? GetUmbracoMedia(d.ParentId.Value) : null, - //TODO: Fix this! - d => Enumerable.Empty()); + d => d.ParentId != -1 //parent should be null if -1 + ? GetUmbracoMedia(d.ParentId) + : null, + //callback to return the children of the current node based on the xml structure already found + d => GetChildrenMedia(d.ParentId, xpath)); + } + + /// + /// A Helper methods to return the children for media whther it is based on examine or xml + /// + /// + /// + /// + private IEnumerable GetChildrenMedia(int parentId, XPathNavigator xpath = null) + { + + //if there is no navigator, try examine first, then re-look it up + if (xpath == null) + { + try + { + //first check in Examine as this is WAY faster + var criteria = ExamineManager.Instance + .SearchProviderCollection["InternalSearcher"] + .CreateSearchCriteria("media"); + var filter = criteria.ParentId(parentId); + var results = ExamineManager + .Instance.SearchProviderCollection["InternalSearcher"] + .Search(filter.Compile()); + if (results.Any()) + { + return results.Select(ConvertFromSearchResult); + } + } + catch (FileNotFoundException) + { + //Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco + //See this thread: http://examine.cdodeplex.com/discussions/264341 + //Catch the exception here for the time being, and just fallback to GetMedia + } + + var media = library.GetMedia(parentId, true); + if (media != null && media.Current != null) + { + if (!media.MoveNext()) + return null; + xpath = media.Current; + } + } + + var children = xpath.SelectChildren(XPathNodeType.Element); + var mediaList = new List(); + while (children.Current != null) + { + if (!children.MoveNext()) + { + break; + } + + //NOTE: I'm not sure why this is here, it is from legacy code of ExamineBackedMedia, but + // will leave it here as it must have done something! + if (children.Current.Name != "contents") + { + //make sure it's actually a node, not a property + if (!string.IsNullOrEmpty(children.Current.GetAttribute("path", "")) && + !string.IsNullOrEmpty(children.Current.GetAttribute("id", ""))) + { + mediaList.Add(ConvertFromXPathNavigator(children.Current)); + } + } + } + return mediaList; } /// @@ -122,8 +230,6 @@ namespace Umbraco.Web /// internal class DictionaryDocument : IDocument { - - //TODO: Unit test this! public DictionaryDocument( IDictionary valueDictionary, @@ -149,11 +255,12 @@ namespace Umbraco.Web ValidateAndSetProperty(valueDictionary, val => CreatorId = int.Parse(val), "creatorID"); ValidateAndSetProperty(valueDictionary, val => Path = val, "path", "__Path"); ValidateAndSetProperty(valueDictionary, val => CreateDate = DateTime.Parse(val), "createDate"); + ValidateAndSetProperty(valueDictionary, val => UpdateDate = DateTime.Parse(val), "updateDate"); ValidateAndSetProperty(valueDictionary, val => Level = int.Parse(val), "level"); ValidateAndSetProperty(valueDictionary, val => { int pId; - ParentId = null; + ParentId = -1; if (int.TryParse(val, out pId)) { ParentId = pId; @@ -180,7 +287,7 @@ namespace Umbraco.Web get { return _getParent(this); } } - public int? ParentId { get; private set; } + public int ParentId { get; private set; } public int Id { get; private set; } public int TemplateId { get; private set; } public int SortOrder { get; private set; } @@ -206,15 +313,14 @@ namespace Umbraco.Web private readonly List _keysAdded = new List(); private void ValidateAndSetProperty(IDictionary valueDictionary, Action setProperty, params string[] potentialKeys) { - foreach (var s in potentialKeys) + var key = potentialKeys.FirstOrDefault(x => valueDictionary.ContainsKey(x) && valueDictionary[x] != null); + if (key == null) { - if (valueDictionary[s] == null) - throw new FormatException("The valueDictionary is not formatted correctly and is missing the '" + s + "' element"); - setProperty(valueDictionary[s]); - _keysAdded.Add(s); - break; + throw new FormatException("The valueDictionary is not formatted correctly and is missing any of the '" + string.Join(",", potentialKeys) + "' elements"); } + setProperty(valueDictionary[key]); + _keysAdded.Add(key); } } } diff --git a/src/Umbraco.Web/ExamineExtensions.cs b/src/Umbraco.Web/ExamineExtensions.cs index 36976dfe7d..5dc1e2dfd8 100644 --- a/src/Umbraco.Web/ExamineExtensions.cs +++ b/src/Umbraco.Web/ExamineExtensions.cs @@ -16,6 +16,10 @@ namespace Umbraco.Web this IEnumerable results, IPublishedStore store) { + //TODO: The search result has already returned a result which SHOULD include all of the data to create an IDocument, + // however thsi is currently not the case: + // http://examine.codeplex.com/workitem/10350 + var list = new DynamicDocumentList(); var xd = new XmlDocument(); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index b4407d649b..f58e3c1b7e 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -240,7 +240,7 @@ Properties\SolutionInfo.cs - + diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index 7ffe109ceb..4798931c16 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -67,83 +67,83 @@ namespace Umbraco.Web umbracoContext.RoutingContext = routingContext; // remap to handler if it is a base rest request - if (Umbraco.Web.BaseRest.BaseRestHandler.IsBaseRestRequest(umbracoContext.RequestUrl)) + if (BaseRestHandler.IsBaseRestRequest(umbracoContext.RequestUrl)) { - httpContext.RemapHandler(new Umbraco.Web.BaseRest.BaseRestHandler()); + httpContext.RemapHandler(new BaseRestHandler()); } else - //do not continue if this request is not a front-end routable page - if (EnsureUmbracoRoutablePage(umbracoContext, httpContext)) - { - var uri = umbracoContext.RequestUrl; - - // legacy - no idea what this is - LegacyCleanUmbPageFromQueryString(ref uri); - - //Create a document request since we are rendering a document on the front-end - - // create the new document request - var docreq = new DocumentRequest( - umbracoContext.UmbracoUrl, //very important to use this url! it is the path only lowercased version of the current URL. - routingContext); - //assign the document request to the umbraco context now that we know its a front end request - umbracoContext.DocumentRequest = docreq; - - // note - at that point the original legacy module did something do handle IIS custom 404 errors - // ie pages looking like /anything.aspx?404;/path/to/document - I guess the reason was to support - // "directory urls" without having to do wildcard mapping to ASP.NET on old IIS. This is a pain - // to maintain and probably not used anymore - removed as of 06/2012. @zpqrtbnk. - // - // to trigger Umbraco's not-found, one should configure IIS and/or ASP.NET custom 404 errors - // so that they point to a non-existing page eg /redirect-404.aspx - // TODO: SD: We need more information on this for when we release 4.10.0 as I'm not sure what this means. - - //create the searcher - var searcher = new DocumentRequestBuilder(docreq); - //find domain - searcher.LookupDomain(); - //redirect if it has been flagged - if (docreq.IsRedirect) - httpContext.Response.Redirect(docreq.RedirectUrl, true); - //set the culture on the thread - Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = docreq.Culture; - //find the document, found will be true if the doc request has found BOTH a node and a template - // though currently we don't use this value. - var found = searcher.LookupDocument(); - //this could be called in the LookupDocument method, but I've just put it here for clarity. - searcher.DetermineRenderingEngine(); - - //TODO: here we should launch an event so that people can modify the doc request to do whatever they want. - - //redirect if it has been flagged - if (docreq.IsRedirect) - httpContext.Response.Redirect(docreq.RedirectUrl, true); - - //if no doc is found, send to our not found handler - if (docreq.Is404) + //do not continue if this request is not a front-end routable page + if (EnsureUmbracoRoutablePage(umbracoContext, httpContext)) { - httpContext.RemapHandler(new DocumentNotFoundHandler()); + var uri = umbracoContext.RequestUrl; + + // legacy - no idea what this is + LegacyCleanUmbPageFromQueryString(ref uri); + + //Create a document request since we are rendering a document on the front-end + + // create the new document request + var docreq = new DocumentRequest( + umbracoContext.UmbracoUrl, //very important to use this url! it is the path only lowercased version of the current URL. + routingContext); + //assign the document request to the umbraco context now that we know its a front end request + umbracoContext.DocumentRequest = docreq; + + // note - at that point the original legacy module did something do handle IIS custom 404 errors + // ie pages looking like /anything.aspx?404;/path/to/document - I guess the reason was to support + // "directory urls" without having to do wildcard mapping to ASP.NET on old IIS. This is a pain + // to maintain and probably not used anymore - removed as of 06/2012. @zpqrtbnk. + // + // to trigger Umbraco's not-found, one should configure IIS and/or ASP.NET custom 404 errors + // so that they point to a non-existing page eg /redirect-404.aspx + // TODO: SD: We need more information on this for when we release 4.10.0 as I'm not sure what this means. + + //create the searcher + var searcher = new DocumentRequestBuilder(docreq); + //find domain + searcher.LookupDomain(); + //redirect if it has been flagged + if (docreq.IsRedirect) + httpContext.Response.Redirect(docreq.RedirectUrl, true); + //set the culture on the thread + Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = docreq.Culture; + //find the document, found will be true if the doc request has found BOTH a node and a template + // though currently we don't use this value. + var found = searcher.LookupDocument(); + //this could be called in the LookupDocument method, but I've just put it here for clarity. + searcher.DetermineRenderingEngine(); + + //TODO: here we should launch an event so that people can modify the doc request to do whatever they want. + + //redirect if it has been flagged + if (docreq.IsRedirect) + httpContext.Response.Redirect(docreq.RedirectUrl, true); + + //if no doc is found, send to our not found handler + if (docreq.Is404) + { + httpContext.RemapHandler(new DocumentNotFoundHandler()); + } + else + { + + //ok everything is ready to pass off to our handlers (mvc or webforms) but we need to setup a few things + //mostly to do with legacy code,etc... + + //we need to complete the request which assigns the page back to the docrequest to make it available for legacy handlers like default.aspx + docreq.UmbracoPage = new page(docreq); + + //this is required for many legacy things in umbraco to work + httpContext.Items["pageID"] = docreq.DocumentId; + + //this is again required by many legacy objects + httpContext.Items.Add("pageElements", docreq.UmbracoPage.Elements); + + RewriteToUmbracoHandler(HttpContext.Current, uri.Query, docreq.RenderingEngine); + + } } - else - { - - //ok everything is ready to pass off to our handlers (mvc or webforms) but we need to setup a few things - //mostly to do with legacy code,etc... - - //we need to complete the request which assigns the page back to the docrequest to make it available for legacy handlers like default.aspx - docreq.UmbracoPage = new page(docreq); - - //this is required for many legacy things in umbraco to work - httpContext.Items["pageID"] = docreq.DocumentId; - - //this is again required by many legacy objects - httpContext.Items.Add("pageElements", docreq.UmbracoPage.Elements); - - RewriteToUmbracoHandler(HttpContext.Current, uri.Query, docreq.RenderingEngine); - - } - } } ///