From 1e8bf4ff83972e4f6344d140d7872aa8bc48e54d Mon Sep 17 00:00:00 2001 From: hartvig Date: Thu, 3 Mar 2011 08:41:05 -0100 Subject: [PATCH] Work items: 30110 --- .../config/umbracoSettings.config | 321 +++++++++--------- umbraco/businesslogic/UmbracoSettings.cs | 18 + umbraco/businesslogic/Utils/TypeFinder.cs | 62 ++-- .../config/umbracoSettings.config | 275 +++++++-------- .../presentation/umbraco.presentation.csproj | 2 +- .../presentation/umbraco/nodeFactory/Page.cs | 14 +- umbraco/presentation/web.config | 10 +- 7 files changed, 379 insertions(+), 323 deletions(-) diff --git a/config templates/config/umbracoSettings.config b/config templates/config/umbracoSettings.config index 5c75d74fa7..f7db161a26 100644 --- a/config templates/config/umbracoSettings.config +++ b/config templates/config/umbracoSettings.config @@ -1,180 +1,189 @@  - - - - jpeg,jpg,gif,bmp,png,tiff,tif - - alt,border,class,style,align,id,name,onclick,usemap - - - - /scripts - - js,xml - - - false - + + + + jpeg,jpg,gif,bmp,png,tiff,tif + + alt,border,class,style,align,id,name,onclick,usemap + + + + /scripts + + js,xml + + + false + - - True - - - - - 1 - - - - your@email.here - + True + + + + + 1 + + + + your@email.here + - - True + + True - - gif + + gif - - True + + True - - UTF8 + + UTF8 - - false + + false - - - true + + + true - - True + + True - - True + + True - - False + + False - - text + + text - - In Preview Mode - click to end]]> + + In Preview Mode - click to end]]> - - - 1800 - + + + 1800 + - - - false - - true - - - - - - - - - - - plus - star - - - ae - oe - aa - ae - oe - ue - ss - ae - oe - - - - - true - + + + false + + true + + - + + + + + + + + plus + star + + + ae + oe + aa + ae + oe + ue + ss + ae + oe + + - - - - - p - div - - - - - - + + true + - - true - true - - - - - - - - - - - - - - - - - 0 - - - - - + + + + cs + vb + + - - - - - your-username - your-username - your-username - your-username - your-username - - css,xslt - - - - - - - + + + + + p + div + + + - - - - - UsersMembershipProvider - - + + + + + true + true + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + your-username + your-username + your-username + your-username + your-username + + css,xslt + + + + + + + + + + + + + UsersMembershipProvider + + + + + + + + - - - - - - diff --git a/umbraco/businesslogic/UmbracoSettings.cs b/umbraco/businesslogic/UmbracoSettings.cs index 81a79bc676..895f084d6e 100644 --- a/umbraco/businesslogic/UmbracoSettings.cs +++ b/umbraco/businesslogic/UmbracoSettings.cs @@ -860,6 +860,24 @@ namespace umbraco } } + public static XmlNode AppCodeFileExtensions + { + get + { + XmlNode value = GetKeyAsNode("/settings/developer/appCodeFileExtensions"); + if (value != null) + { + return value; + } + + // default is .cs and .vb + value = _umbracoSettings.CreateElement("appCodeFileExtensions"); + value.AppendChild(xmlHelper.addTextNode(_umbracoSettings, "ext", "cs")); + value.AppendChild(xmlHelper.addTextNode(_umbracoSettings, "ext", "vb")); + return value; + } + } + /// /// Tells us whether the Xml to always update disk cache, when changes are made to content /// Default is enabled diff --git a/umbraco/businesslogic/Utils/TypeFinder.cs b/umbraco/businesslogic/Utils/TypeFinder.cs index 73a6dc808f..a9c4e02825 100644 --- a/umbraco/businesslogic/Utils/TypeFinder.cs +++ b/umbraco/businesslogic/Utils/TypeFinder.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Web; using System.IO; using System.Linq; +using System.Xml; using umbraco.IO; namespace umbraco.BusinessLogic.Utils @@ -36,8 +37,13 @@ namespace umbraco.BusinessLogic.Utils } // also add types from app_code, if any + List allowedExt = new List(); + foreach (XmlNode x in UmbracoSettings.AppCodeFileExtensions) + if (!String.IsNullOrEmpty(x.Value)) + allowedExt.Add(x.Value); + DirectoryInfo appCodeFolder = new DirectoryInfo(IOHelper.MapPath(IOHelper.ResolveUrl("~/App_code"))); - if (appCodeFolder.Exists && appCodeFolder.GetFiles().Length > 0) + if (appCodeFolder.Exists && appCodeFolder.GetFilesByExtensions(allowedExt.ToArray()).Count() > 0) { types.AddRange(FindClassesMarkedWithAttribute(Assembly.Load("App_Code"), attribute)); } @@ -45,29 +51,29 @@ namespace umbraco.BusinessLogic.Utils return types.Distinct(); } - static IEnumerable FindClassesMarkedWithAttribute(Assembly assembly, Type attribute) - { - try - { - return assembly.GetTypes().Where(type => type.GetCustomAttributes(attribute, true).Length > 0); - } - catch (ReflectionTypeLoadException ex) - { - if (GlobalSettings.DebugMode) - { - StringBuilder sb = new StringBuilder(); - sb.AppendFormat("Unable to load one or more of the types in assembly '{0}'. Exceptions were thrown:", assembly.FullName); - foreach (Exception e in ex.LoaderExceptions) - sb.AppendFormat("\n{0}: {1}", e.GetType().FullName, e.Message); - throw new Exception(sb.ToString()); - } - else - { - // return the types that were loaded, ignore those that could not be loaded - return ex.Types; - } - } - } + static IEnumerable FindClassesMarkedWithAttribute(Assembly assembly, Type attribute) + { + try + { + return assembly.GetTypes().Where(type => type.GetCustomAttributes(attribute, true).Length > 0); + } + catch (ReflectionTypeLoadException ex) + { + if (GlobalSettings.DebugMode) + { + StringBuilder sb = new StringBuilder(); + sb.AppendFormat("Unable to load one or more of the types in assembly '{0}'. Exceptions were thrown:", assembly.FullName); + foreach (Exception e in ex.LoaderExceptions) + sb.AppendFormat("\n{0}: {1}", e.GetType().FullName, e.Message); + throw new Exception(sb.ToString()); + } + else + { + // return the types that were loaded, ignore those that could not be loaded + return ex.Types; + } + } + } /// /// Searches all loaded assemblies for classes of the type passed in. @@ -104,7 +110,7 @@ namespace umbraco.BusinessLogic.Utils string binFolder = Path.Combine(IO.IOHelper.MapPath("/", false), "bin"); string[] strTypes = TypeResolver.GetAssignablesFromType(binFolder, "*.dll"); - + List types = new List(); @@ -171,5 +177,11 @@ namespace umbraco.BusinessLogic.Utils { return t => (type.IsAssignableFrom(t) && (onlyConcreteClasses ? (t.IsClass && !t.IsAbstract) : true)); } + + public static IEnumerable GetFilesByExtensions(this DirectoryInfo dir, params string[] extensions) + { + var allowedExtensions = new HashSet(extensions, StringComparer.OrdinalIgnoreCase); + return dir.GetFiles().Where(f => allowedExtensions.Contains(f.Extension)); + } } } diff --git a/umbraco/presentation/config/umbracoSettings.config b/umbraco/presentation/config/umbracoSettings.config index 8d844045f9..bfe3854d83 100644 --- a/umbraco/presentation/config/umbracoSettings.config +++ b/umbraco/presentation/config/umbracoSettings.config @@ -1,160 +1,169 @@  - - - - jpeg,jpg,gif,bmp,png,tiff,tif - - alt,border,class,style,align,id,name,onclick,usemap - - - - /scripts - - js,xml - - - false - + + + + jpeg,jpg,gif,bmp,png,tiff,tif + + alt,border,class,style,align,id,name,onclick,usemap + + + + /scripts + + js,xml + + + false + - - True - - - - - - 1134 - 1135 - 1135 - - - - - robot@umbraco.dk - + True + + + + + + 1134 + 1135 + 1135 + + + + + robot@umbraco.dk + - - True + + True - - gif + + gif - - False + + False - - Raw + + Raw - - True + + True - - True + + True - - False + + False - - text + + text - false + false - true + true - In Preview Mode - click to end]]> + In Preview Mode - click to end]]> - - - 1800 + + + 1800 - + - - - false - - false - - - - - - - - - plus - star - - - ae - oe - aa - - - - true - true - - + + + false + + false + + - + + + + + + plus + star + + + ae + oe + aa + + + + true + true + - - true - true - - - - falses - 86400 - 1440 - + + + + cs + vb + + + + - - - - + + true + true + + + + falses + 86400 + 1440 + - - - - - 0 - - - - - + + + + - - - - - umbraco - umbraco - css,xslt - umbraco - umbraco - umbraco - + + + + + 0 + + + + + - - - - - + + + + + umbraco + umbraco + css,xslt + umbraco + umbraco + umbraco + - - - - - UsersMembershipProvider - - + + + + + - - - - - + + + + + UsersMembershipProvider + + + + + + + + \ No newline at end of file diff --git a/umbraco/presentation/umbraco.presentation.csproj b/umbraco/presentation/umbraco.presentation.csproj index 87c8a171a1..099e28c9d9 100644 --- a/umbraco/presentation/umbraco.presentation.csproj +++ b/umbraco/presentation/umbraco.presentation.csproj @@ -3217,9 +3217,9 @@ + - diff --git a/umbraco/presentation/umbraco/nodeFactory/Page.cs b/umbraco/presentation/umbraco/nodeFactory/Page.cs index a554472f30..32ef70a4b0 100644 --- a/umbraco/presentation/umbraco/nodeFactory/Page.cs +++ b/umbraco/presentation/umbraco/nodeFactory/Page.cs @@ -330,12 +330,16 @@ namespace umbraco.NodeFactory public static Node GetNodeByXpath(string xpath) { - XPathNodeIterator xpathNode = library.GetXmlNodeByXPath(xpath); - XmlNode n = ((IHasXmlNode) xpathNode.Current).GetNode(); - if (n != null) { - return new Node(n); + XPathNodeIterator itNode = library.GetXmlNodeByXPath(xpath); + XmlNode nodeXmlNode = null; + if (itNode.MoveNext()) + { + nodeXmlNode = ((IHasXmlNode)itNode.Current).GetNode(); + } + if (nodeXmlNode != null) + { + return new Node(nodeXmlNode); } - return null; } diff --git a/umbraco/presentation/web.config b/umbraco/presentation/web.config index 1308072404..02e3863a6a 100644 --- a/umbraco/presentation/web.config +++ b/umbraco/presentation/web.config @@ -39,8 +39,8 @@ - - + + @@ -64,7 +64,7 @@ --> - + @@ -178,12 +178,16 @@ + + + +