From 89324370b4e5a25d7e255187c525ed7cfd9a0629 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 29 Aug 2013 15:50:48 +1000 Subject: [PATCH] Completes U4-2415 Remove legacy RestExtensions and restExtensions.config --- src/Umbraco.Core/IO/SystemFiles.cs | 9 - src/Umbraco.Tests/PluginManagerTests.cs | 12 - src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 6 - .../config/restExtensions.Release.config | 13 - .../config/restExtensions.config | 20 -- .../BaseRest/RestExtensionMethodInfo.cs | 122 +------- src/Umbraco.Web/Cache/PageCacheRefresher.cs | 2 - src/Umbraco.Web/CacheHelperExtensions.cs | 4 - src/Umbraco.Web/PluginManagerExtensions.cs | 10 - src/Umbraco.Web/Umbraco.Web.csproj | 10 - src/Umbraco.Web/WebBootManager.cs | 8 - .../umbraco.presentation/LegacyClasses.cs | 20 -- .../umbraco.presentation/library.cs | 9 - .../umbraco/cache/LegacyClasses.cs | 10 - .../developer/Macros/editMacro.aspx.cs | 4 - .../webservices/codeEditorSave.asmx.cs | 5 - .../umbracobase/attributes/RestExtension.cs | 25 -- .../attributes/RestExtensionMethod.cs | 44 --- .../umbracobase/baseHttpModule.cs | 277 ----------------- .../umbracobase/baseLibrary.cs | 150 --------- .../umbracobase/readme.txt | 17 - .../umbracobase/restExtension.cs | 291 ------------------ src/umbraco.businesslogic/IO/SystemFiles.cs | 8 +- .../PackageActions/addRestExtension.cs | 117 ------- src/umbraco.cms/umbraco.cms.csproj | 1 - 25 files changed, 2 insertions(+), 1192 deletions(-) delete mode 100644 src/Umbraco.Web.UI/config/restExtensions.Release.config delete mode 100644 src/Umbraco.Web.UI/config/restExtensions.config delete mode 100644 src/Umbraco.Web/umbraco.presentation/LegacyClasses.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/cache/LegacyClasses.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtension.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtensionMethod.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbracobase/baseHttpModule.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbracobase/readme.txt delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs delete mode 100644 src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs diff --git a/src/Umbraco.Core/IO/SystemFiles.cs b/src/Umbraco.Core/IO/SystemFiles.cs index 1436986ed6..3f459918a8 100644 --- a/src/Umbraco.Core/IO/SystemFiles.cs +++ b/src/Umbraco.Core/IO/SystemFiles.cs @@ -60,15 +60,6 @@ namespace Umbraco.Core.IO } } - public static string RestextensionsConfig - { - get - { - return SystemDirectories.Config + "/restextensions.config"; - } - } - - public static string SkinningXml { get diff --git a/src/Umbraco.Tests/PluginManagerTests.cs b/src/Umbraco.Tests/PluginManagerTests.cs index 0e3abc4710..1703c4be75 100644 --- a/src/Umbraco.Tests/PluginManagerTests.cs +++ b/src/Umbraco.Tests/PluginManagerTests.cs @@ -334,13 +334,6 @@ namespace Umbraco.Tests Assert.AreEqual(3, types.Count()); } - [Test] - public void Resolves_LegacyRestExtensions() - { - var types = PluginManager.Current.ResolveLegacyRestExtensions(); - Assert.AreEqual(1, types.Count()); - } - [Test] public void Resolves_XsltExtensions() { @@ -354,11 +347,6 @@ namespace Umbraco.Tests } - [umbraco.presentation.umbracobase.RestExtension("Blah")] - public class MyLegacyRestExtension - { - - } [Umbraco.Web.BaseRest.RestExtension("Blah")] public class MyRestExtesion diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 7765380db3..ae3485df0e 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -645,9 +645,6 @@ scripting.config - - restExtensions.config - metablogConfig.config @@ -2598,9 +2595,6 @@ Designer - - Designer - Designer diff --git a/src/Umbraco.Web.UI/config/restExtensions.Release.config b/src/Umbraco.Web.UI/config/restExtensions.Release.config deleted file mode 100644 index 7a6afac72b..0000000000 --- a/src/Umbraco.Web.UI/config/restExtensions.Release.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Umbraco.Web.UI/config/restExtensions.config b/src/Umbraco.Web.UI/config/restExtensions.config deleted file mode 100644 index 42a64b14b1..0000000000 --- a/src/Umbraco.Web.UI/config/restExtensions.config +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Umbraco.Web/BaseRest/RestExtensionMethodInfo.cs b/src/Umbraco.Web/BaseRest/RestExtensionMethodInfo.cs index 762a7ae867..176f804319 100644 --- a/src/Umbraco.Web/BaseRest/RestExtensionMethodInfo.cs +++ b/src/Umbraco.Web/BaseRest/RestExtensionMethodInfo.cs @@ -78,71 +78,9 @@ namespace Umbraco.Web.BaseRest return GetFromConfiguration(extensionAlias, methodName, paramsCount) ?? GetFromAttribute(extensionAlias, methodName, paramsCount) - ?? GetFromLegacyConfiguration(extensionAlias, methodName) // that one should be obsoleted at some point - ?? GetFromLegacyAttribute(extensionAlias, methodName) // that one should be obsoleted at some point ?? MissingMethod; } - - // gets a RestExtensionMethodInfo matching extensionAlias and methodName - // by looking at the legacy configuration file - // returns null if not found - // - static RestExtensionMethodInfo GetFromLegacyConfiguration(string extensionAlias, string methodName) - { - const string extensionXPath = "/RestExtensions/ext [@alias='{0}']"; - const string methodXPath = "./permission [@method='{0}']"; - - var config = (Configuration.BaseRestSection)System.Configuration.ConfigurationManager.GetSection("BaseRestExtensions"); - - if (config == null) - return null; // does not exist - - // note - at the moment we reload the config file each time - // we have to support live edits of the config file for backward compatibility reason - // so if we want to cache, we'd also need to implement a watcher on the config file... - - var doc = new XmlDocument(); - doc.Load(IOHelper.MapPath(SystemFiles.RestextensionsConfig)); - - var eNode = doc.SelectSingleNode(string.Format(extensionXPath, extensionAlias)); - - if (eNode == null) - return null; // does not exist - - var mNode = eNode.SelectSingleNode(string.Format(methodXPath, methodName)); - - if (mNode == null) - return null; // does not exist - - var attributes = eNode.Attributes; - if (attributes == null) - return null; // has no attributes - - var assemblyName = attributes["assembly"].Value; - var assembly = Assembly.Load(assemblyName); - - var typeName = attributes["type"].Value; - var type = assembly.GetType(typeName); - - if (type == null) - return null; // does not exist - - var method = type.GetMethod(methodName); - - if (method == null) - return null; // does not exist - - var allowAll = GetAttribute(mNode, "allowAll"); - var returnXml = GetAttribute(mNode, "returnXml"); - - var info = new RestExtensionMethodInfo(allowAll != null && allowAll.ToLower() == "true", - GetAttribute(mNode, "allowGroup"), GetAttribute(mNode, "allowType"), GetAttribute(mNode, "allowMember"), - returnXml == null || returnXml.ToLower() != "false", - method); - - return info; - } - + // gets a RestExtensionMethodInfo matching extensionAlias and methodName // by looking at the configuration file // returns null if not found @@ -203,64 +141,6 @@ namespace Umbraco.Web.BaseRest return info; } - // gets a RestExtensionMethodInfo matching extensionAlias and methodName - // by looking for the legacy attributes - // returns null if not found - // - static RestExtensionMethodInfo GetFromLegacyAttribute(string extensionAlias, string methodName) - { - // here we can cache because any change would trigger an app restart anyway - - var cacheKey = extensionAlias + "." + methodName; - lock (Cache) - { - // if it's in the cache, return - if (Cache.ContainsKey(cacheKey)) - return Cache[cacheKey]; - } - - // find an extension with that alias, then find a method with that name, - // which has been properly marked with the attribute, and use the attribute - // properties to setup a RestExtensionMethodInfo - - // note: add #pragma - yes it's obsolete but we still want to support it for the time being - - var extensions = PluginManager.Current.ResolveLegacyRestExtensions() -#pragma warning disable 612,618 - .Where(type => type.GetCustomAttribute(false).GetAlias() == extensionAlias); -#pragma warning restore 612,618 - - RestExtensionMethodInfo info = null; - - foreach (var extension in extensions) // foreach classes with extension alias - { - var method = extension.GetMethod(methodName); - if (method == null) continue; // not implementing the method = ignore - -#pragma warning disable 612,618 - var attribute = method.GetCustomAttributes(typeof(global::umbraco.presentation.umbracobase.RestExtensionMethod), false).Cast().SingleOrDefault(); -#pragma warning restore 612,618 - if (attribute == null) continue; // method has not attribute = ignore - - // got it! - info = new RestExtensionMethodInfo(attribute.GetAllowAll(), - attribute.GetAllowGroup(), attribute.GetAllowType(), attribute.GetAllowMember(), - attribute.returnXml, - method); - - // cache - lock (Cache) - { - Cache[cacheKey] = info; - } - - // got it, no need to look any further - break; - } - - return info; - } - // gets a RestExtensionMethodInfo matching extensionAlias and methodName // by looking for the attributes // returns null if not found diff --git a/src/Umbraco.Web/Cache/PageCacheRefresher.cs b/src/Umbraco.Web/Cache/PageCacheRefresher.cs index 366607afd2..3c9e496dec 100644 --- a/src/Umbraco.Web/Cache/PageCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/PageCacheRefresher.cs @@ -4,8 +4,6 @@ using Umbraco.Core.Models; using Umbraco.Core.Sync; using umbraco; using umbraco.cms.businesslogic.web; -using umbraco.interfaces; -using umbraco.presentation.cache; namespace Umbraco.Web.Cache { diff --git a/src/Umbraco.Web/CacheHelperExtensions.cs b/src/Umbraco.Web/CacheHelperExtensions.cs index 780f841190..3a5aaaaf6c 100644 --- a/src/Umbraco.Web/CacheHelperExtensions.cs +++ b/src/Umbraco.Web/CacheHelperExtensions.cs @@ -4,11 +4,7 @@ using System.Web.Caching; using System.Web.Mvc; using System.Web.Mvc.Html; using Umbraco.Core; -using Umbraco.Core.Configuration; -using Umbraco.Web.Cache; -using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.web; -using umbraco.presentation.cache; namespace Umbraco.Web { diff --git a/src/Umbraco.Web/PluginManagerExtensions.cs b/src/Umbraco.Web/PluginManagerExtensions.cs index 6196e00fd3..aca533bedb 100644 --- a/src/Umbraco.Web/PluginManagerExtensions.cs +++ b/src/Umbraco.Web/PluginManagerExtensions.cs @@ -49,16 +49,6 @@ namespace Umbraco.Web return resolver.ResolveTypes(); } - /// - /// Returns all classes attributed with legacy RestExtension attribute - /// - /// - /// - internal static IEnumerable ResolveLegacyRestExtensions(this PluginManager resolver) - { - return resolver.ResolveAttributedTypes(); - } - /// /// Returns all classes attributed with RestExtensionAttribute attribute /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 32760eaf2f..0ff6784154 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -514,7 +514,6 @@ - ASPXCodeBehind @@ -861,11 +860,6 @@ Code - - - - - ASPXCodeBehind @@ -911,9 +905,6 @@ publish.aspx - - code - @@ -1928,7 +1919,6 @@ - diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index ce507ec2df..32c9c5571c 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -7,31 +7,23 @@ using System.Web.Mvc; using System.Web.Routing; using StackExchange.Profiling.MVCHelpers; using Umbraco.Core; -using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Dictionary; -using Umbraco.Core.Dynamics; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Profiling; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Sync; using Umbraco.Web.Dictionary; -using Umbraco.Web.Editors; using Umbraco.Web.Media; using Umbraco.Web.Media.ThumbnailProviders; using Umbraco.Web.Models; -using Umbraco.Web.Models.Mapping; using Umbraco.Web.Mvc; -using Umbraco.Web.PropertyEditors; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.WebApi; using umbraco.BusinessLogic; -using umbraco.businesslogic; -using umbraco.cms.businesslogic; -using umbraco.presentation.cache; namespace Umbraco.Web diff --git a/src/Umbraco.Web/umbraco.presentation/LegacyClasses.cs b/src/Umbraco.Web/umbraco.presentation/LegacyClasses.cs deleted file mode 100644 index c5e9014a78..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/LegacyClasses.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Web; -using System.Web.UI; -using System.Xml; -using Umbraco.Core; -using umbraco.IO; -using umbraco.NodeFactory; -using umbraco.cms.businesslogic.web; -using umbraco.interfaces; - -namespace umbraco -{ - -} diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 466731bb92..10e24956f5 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -14,8 +14,6 @@ using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Web; using Umbraco.Web.Cache; -using Umbraco.Web.PublishedCache; -using Umbraco.Web.Routing; using Umbraco.Web.Templates; using umbraco.BusinessLogic; using umbraco.cms.businesslogic; @@ -25,18 +23,11 @@ using umbraco.cms.businesslogic.propertytype; using umbraco.cms.businesslogic.relation; using umbraco.cms.businesslogic.web; using umbraco.cms.helpers; -using umbraco.presentation.cache; using umbraco.scripting; using umbraco.DataLayer; -using System.Web.Security; using umbraco.cms.businesslogic.language; using umbraco.IO; -using System.Collections; -using System.Collections.Generic; -using umbraco.cms.businesslogic.cache; -using umbraco.NodeFactory; using UmbracoContext = umbraco.presentation.UmbracoContext; -using System.Linq; namespace umbraco { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/cache/LegacyClasses.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/cache/LegacyClasses.cs deleted file mode 100644 index 63e9739fb9..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/cache/LegacyClasses.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Linq; -using Umbraco.Core; -using Umbraco.Core.IO; -using Umbraco.Web.Cache; -using umbraco.interfaces; - -namespace umbraco.presentation.cache -{ -} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs index c215002270..6630e510b7 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs @@ -1,15 +1,11 @@ using System; using System.Collections; -using System.Data; -using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using Umbraco.Core.IO; -using Umbraco.Web.Cache; using umbraco.BasePages; -using umbraco.presentation.cache; using umbraco.uicontrols; using umbraco.DataLayer; using umbraco.cms.presentation.Trees; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs index 7005a40c23..df6f5de171 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs @@ -11,17 +11,12 @@ using System.Web.Services; using System.Web.UI; using System.Xml; using System.Xml.Xsl; -using Umbraco.Core; using Umbraco.Core.IO; using Umbraco.Web.WebServices; -using Umbraco.Web; -using Umbraco.Web.Cache; -using umbraco.BasePages; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.macro; using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic.web; -using umbraco.presentation.cache; using System.Net; using System.Collections; using umbraco.NodeFactory; diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtension.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtension.cs deleted file mode 100644 index 202fa76a40..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtension.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace umbraco.presentation.umbracobase -{ - [Obsolete("Use Umbraco.Web.BaseRest.RestExtensionAttribute")] - [System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false)] - public class RestExtension : System.Attribute - { - string alias; - - public RestExtension(string alias) - { - - this.alias = alias; - } - - public string GetAlias() - { - return alias; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtensionMethod.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtensionMethod.cs deleted file mode 100644 index f11c5d644b..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/attributes/RestExtensionMethod.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace umbraco.presentation.umbracobase -{ - [Obsolete("Use Umbraco.Web.BaseRest.RestExtensionMethodAttribute")] - [System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] - public class RestExtensionMethod : System.Attribute - { - public bool allowAll; - public string allowGroup; - public string allowType; - public string allowMember; - public bool returnXml; - - public RestExtensionMethod() - { - returnXml = true; - allowAll = true; - } - - public bool GetAllowAll() - { - return allowAll; - } - - public string GetAllowGroup() - { - return allowGroup; - } - - public string GetAllowType() - { - return allowType; - } - - public string GetAllowMember() - { - return allowMember; - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/baseHttpModule.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/baseHttpModule.cs deleted file mode 100644 index 3e8138f872..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/baseHttpModule.cs +++ /dev/null @@ -1,277 +0,0 @@ -using System; -using System.Data; -using System.IO; -using System.Text; -using System.Text.RegularExpressions; -using System.Configuration; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Reflection; -using System.Collections.Specialized; -using System.Xml; -using umbraco; -using umbraco.cms.businesslogic.member; -using System.Web.SessionState; - -namespace umbraco.presentation.umbracobase -{ - // as of 4.10 the module has been replaced by Umbraco.Web.BaseRest.BaseRestHandler - stephan @zpqrtbnk - [Obsolete("Has been replaced by BaseRestHandler.")] - public class requestModule : IHttpModule - { - - #region IHttpModule Members - - public void Dispose() - { - } - - public void Init(HttpApplication httpApp) - { - //httpApp.PostAuthorizeRequest += new EventHandler(httpApp_PreRequestHandlerExecute); - httpApp.PostAcquireRequestState += new EventHandler(httpApp_PostAcquireRequestState); - httpApp.PostMapRequestHandler += new EventHandler(httpApp_PostMapRequestHandler); - } - - void httpApp_PostMapRequestHandler(object sender, EventArgs e) - { - //remove extension and split the url - HttpApplication httpApp = (HttpApplication)sender; - string url = httpApp.Context.Request.RawUrl; - - string urlStart = IO.IOHelper.ResolveUrl( IO.SystemDirectories.Base ).TrimEnd('/').ToLower() + "/"; - - if (url.ToLower().StartsWith(urlStart)) - { - if (httpApp.Context.Handler is IReadOnlySessionState || httpApp.Context.Handler is IRequiresSessionState) - { - // no need to replace the current handler - return; - } - - // swap the current handler - httpApp.Context.Handler = new MyHttpHandler(httpApp.Context.Handler); - } - } - - void httpApp_PostAcquireRequestState(object sender, EventArgs e) - { - HttpApplication httpApp = (HttpApplication)sender; - - //remove extension and split the url - string url = httpApp.Context.Request.RawUrl; - string urlStart = IO.IOHelper.ResolveUrl(IO.SystemDirectories.Base).TrimEnd('/').ToLower() + "/"; - - if (url.ToLower().StartsWith(urlStart)) - { - MyHttpHandler resourceHttpHandler = HttpContext.Current.Handler as MyHttpHandler; - - if (resourceHttpHandler != null) - { - // set the original handler back - HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler; - } - - string basedir = "/" + IO.SystemDirectories.Base.TrimStart('~').Trim('/') + "/"; - int indexOfBase = url.ToLower().IndexOf(basedir); - url = url.Substring(indexOfBase); - - if (url.ToLower().Contains(".aspx")) - url = url.Substring(0, url.IndexOf(".aspx")); - - if (url.ToLower().Contains("?")) - url = url.Substring(0, url.IndexOf("?")); - - object[] urlArray = url.Split('/'); - - //There has to be minimum 4 parts in the url for this to work... /base/library/method/[parameter].aspx - if (urlArray.Length >= 4) - { - string extensionAlias = urlArray[2].ToString(); - string methodName = urlArray[3].ToString(); - - httpApp.Response.ContentType = "text/xml"; - restExtension myExtension = new restExtension(extensionAlias, methodName); - - if (myExtension.isAllowed) - { - TrySetCulture(); - - string response = invokeMethod(myExtension, urlArray); - // since return value is arbitrary (set by implementor), check length before checking for error - if (response.Length >= 7) - { - if (response.Substring(0, 7) == "") - { - httpApp.Response.StatusCode = 500; - httpApp.Response.StatusDescription = "Internal Server Error"; - } - } - - httpApp.Response.Output.Write(response); - } - else - { - httpApp.Response.StatusCode = 500; - httpApp.Response.StatusDescription = "Internal Server Error"; - //Very static error msg... - httpApp.Response.Output.Write("Extension not found or permission denied"); - } - //end the resposne - httpApp.Response.End(); - } - } - } - - - - - private string invokeMethod(restExtension myExtension, object[] paras) - { - try - { - //So method is either not found or not valid... this should probably be moved... - if (!myExtension.method.IsPublic || !myExtension.method.IsStatic) - return "Method has to be public and static"; - else //And if it is lets continue trying to invoke it... - { - //lets check if we have parameters enough in the url.. - if (myExtension.method.GetParameters().Length > (paras.Length - 4)) //Too few - return "Not Enough parameters in url"; - else - { - - //We have enough parameters... lets invoke.. - //Create an instance of the type we need to invoke the method from. - Object obj = Activator.CreateInstance(myExtension.type); - Object response; - - //umbracoBase.baseBinder bBinder = new baseBinder(); - - if (myExtension.method.GetParameters().Length == 0) - { - //response = myMethod.method.Invoke(obj, BindingFlags.Public | BindingFlags.Instance, bBinder, null, System.Globalization.CultureInfo.CurrentCulture); - response = myExtension.method.Invoke(obj, null); //Invoke with null as parameters as there are none - } - - else - { - //We only need the parts of the url above the number 4 so we'll - //recast those to objects and add them to the object[] - - //Getting the right lenght.. 4 is the magic number dum di dum.. - object[] methodParams = new object[(paras.Length - 4)]; - - int i = 0; - - foreach (ParameterInfo pInfo in myExtension.method.GetParameters()) - { - Type myType = Type.GetType(pInfo.ParameterType.ToString()); - methodParams[(i)] = Convert.ChangeType(paras[i + 4], myType); - i++; - } - - //Invoke with methodParams - //response = myMethod.method.Invoke(obj, BindingFlags.Public | BindingFlags.Instance, bBinder, methodParams, System.Globalization.CultureInfo.CurrentCulture); - response = myExtension.method.Invoke(obj, methodParams); - } - - /*TODO - SOMETHING ALITTLE BETTER THEN ONLY CHECK FOR XPATHNODEITERATOR OR ELSE do ToString() */ - if (response != null) - { - switch (myExtension.method.ReturnType.ToString()) - { - case "System.Xml.XPath.XPathNodeIterator": - return ((System.Xml.XPath.XPathNodeIterator)response).Current.OuterXml; - case "System.Xml.Linq.XDocument": - return response.ToString(); - case "System.Xml.XmlDocument": - XmlDocument xmlDoc = (XmlDocument)response; - StringWriter sw = new StringWriter(); - XmlTextWriter xw = new XmlTextWriter(sw); - xmlDoc.WriteTo(xw); - return sw.ToString(); - default: - string strResponse = ((string)response.ToString()); - - if (myExtension.returnXML) - { - //do a quick "is this html?" check... if it is add CDATA... - if (strResponse.Contains("<") || strResponse.Contains(">")) - strResponse = ""; - return "" + strResponse + ""; - } - else - { - HttpContext.Current.Response.ContentType = "text/html"; - return strResponse; - } - } - } - else - { - if (myExtension.returnXML) - return "Null value returned"; - else - return string.Empty; - } - - - - } - } - } - - catch (Exception ex) - { - //Overall exception handling... - return ""; - } - - } - - private static void TrySetCulture() - { - string domain = HttpContext.Current.Request.Url.Host; //Host only - if (TrySetCulture(domain)) return; - - domain = HttpContext.Current.Request.Url.Authority; //Host with port - if (TrySetCulture(domain)) return; - } - - private static bool TrySetCulture(string domain) - { - var uDomain = cms.businesslogic.web.Domain.GetDomain(domain); - if (uDomain == null) return false; - System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(uDomain.Language.CultureAlias); - return true; - } - - - } - - // a temp handler used to force the SessionStateModule to load session state - public class MyHttpHandler : IHttpHandler, IRequiresSessionState - { - internal readonly IHttpHandler OriginalHandler; - - public MyHttpHandler(IHttpHandler originalHandler) - { - OriginalHandler = originalHandler; - } - - public void ProcessRequest(HttpContext context) - { - // do not worry, ProcessRequest() will not be called, but let's be safe - throw new InvalidOperationException("MyHttpHandler cannot process requests."); - } - - public bool IsReusable - { - // IsReusable must be set to false since class has a member! - get { return false; } - } - } -} - #endregion \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs deleted file mode 100644 index 888280df77..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/baseLibrary.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Xml; -using System.Xml.Xsl; -using System.Xml.XPath; -using System.Data; -using System.Configuration; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Web.UI.WebControls.WebParts; -using System.Web.UI.HtmlControls; -using System.Text.RegularExpressions; -using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.member; -using umbraco.cms.businesslogic.property; - -namespace umbraco.presentation.umbracobase.library -{ - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.")] - public class library - { - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.GetCurrentMember().", false)] - public static Member GetCurrentMember() - { - return Member.GetCurrentMember(); - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.GetCurrentMemberId().", false)] - public static int CurrentMemberId() - { - return Member.CurrentMemberId(); - } - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.")] - public class member - { - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.Login(login, password).", false)] - public static int login(string loginname, string password) - { - Member m = Member.GetMemberFromLoginNameAndPassword(loginname, password); - - if (library.CurrentMemberId() == 0) - { - // If null, login not correct... - if (m != null) - { - Member.AddMemberToCache(m); - return m.Id; - } - else - return 0; - } - else - return library.CurrentMemberId(); - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.Logout().", false)] - public static int logout() - { - Member m = library.GetCurrentMember(); - if (m != null) - { - Member.RemoveMemberFromCache(m.Id); - Member.ClearMemberFromClient(m.Id); - return m.Id; - } - else - return 0; - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.Logout().", false)] - public static int logout(int NodeId) - { - int _currentMemberId = library.CurrentMemberId(); - if (_currentMemberId > 0) - { - Member.RemoveMemberFromCache(library.CurrentMemberId()); - Member.ClearMemberFromClient(library.CurrentMemberId()); - return _currentMemberId; - } - else - return 0; - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.GetCurrentMemberAsXml().", false)] - public static XPathNodeIterator data() - { - if (library.GetCurrentMember() != null) - { - XmlDocument mXml = new XmlDocument(); - mXml.LoadXml(library.GetCurrentMember().ToXml(mXml, false).OuterXml); - XPathNavigator xp = mXml.CreateNavigator(); - return xp.Select("/node"); - } - else - return null; - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.GetCurrentMemberId().", false)] - public static int id() - { - return library.CurrentMemberId(); - } - - [Obsolete("Obsolete, use Umbraco.Web.BaseRest.MemberRest.SetProperty(alias, value).", false)] - public static string setProperty(string alias, object value) - { - string retVal = "False"; - try - { - Member myMember = library.GetCurrentMember(); - - if (myMember != null) - { - Property myProperty = myMember.getProperty(alias); - - if (myMember.ContentType != null && MemberType.GetByAlias(myMember.ContentType.Alias).MemberCanEdit(myProperty.PropertyType)) - { - - if (myProperty.PropertyType.ValidationRegExp.Trim() != "") - { - Regex regexPattern = new Regex(myMember.getProperty(alias).PropertyType.ValidationRegExp); - - if (regexPattern.IsMatch(value.ToString())) - { - myProperty.Value = value; - retVal = "True"; - myMember.XmlGenerate(new XmlDocument()); - } - } - else - { - myProperty.Value = value; - retVal = "True"; - myMember.XmlGenerate(new XmlDocument()); - } - - } - } - } - catch (Exception x) - { retVal = x.Message; } - - return retVal; - } - } - -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/readme.txt b/src/Umbraco.Web/umbraco.presentation/umbracobase/readme.txt deleted file mode 100644 index 45df03c734..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -Umbraco Base Rest Handler -------------------------- - -The Umbraco Base Rest Handler has moved to Umbraco.Web.BaseRest. - -At the moment, both the legacy way and the new way of doing things are supported. -The baseHttpModule does _not_ run anymore, everything is handled by -Umbraco.Web.BaseRest, but the legacy attributes and config files are supported, -so legacy extensions are discovered and will run properly. - -However, you should start using the attributes in Umbraco.Web.BaseRest, and the -new BaseRestExtensions.config config file. - -The legacy system will be obsoleted at some point in the future and all references -to the code legacy will be removed. - --- \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs b/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs deleted file mode 100644 index dbeab6cf53..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbracobase/restExtension.cs +++ /dev/null @@ -1,291 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Xml; -using Umbraco.Core; -using Umbraco.Web; -using umbraco.BusinessLogic.Utils; -using umbraco.cms.businesslogic.member; -using umbraco.IO; - -namespace umbraco.presentation.umbracobase -{ - [Obsolete] - public class restExtension - { - private Type _type; - private MethodInfo _method; - private Assembly _assembly; - private string _alias; - private bool _isAllowed; - private bool _returnXml = true; - - public Type type - { - get { return _type; } - set { _type = value; } - } - - public MethodInfo method - { - get { return _method; } - set { _method = value; } - } - - public Assembly assembly - { - get { return _assembly; } - set { _assembly = value; } - } - - public string alias - { - get { return _alias; } - set { _alias = value; } - } - - public bool isAllowed - { - get { return _isAllowed; } - set { _isAllowed = value; } - } - - public bool returnXML - { - get { return _returnXml; } - set { _returnXml = value; } - } - - - public restExtension() - { } - - public restExtension(string extensionAlias, string methodName) - { - bool allowed = false; - bool fromFile = true; - - XmlDocument baseDoc = new XmlDocument(); //RESTExtension document... - baseDoc.Load(IOHelper.MapPath(SystemFiles.RestextensionsConfig)); - - XmlNode baseExt = baseDoc.SelectSingleNode("/RestExtensions/ext [@alias='" + extensionAlias + "']/permission [@method='" + methodName + "']"); - - //if not there.. it's not allowed... - if (baseExt != null) - { - //Access for all ? - if (baseExt.Attributes["allowAll"] != null) - { - if (baseExt.Attributes["allowAll"].Value.ToString().ToLower() == "true") - allowed = true; - } - - if (!allowed) - { - //Member Based permissions.. check for group, type and ID... - Member currentMem = Member.GetCurrentMember(); - - //not basic.. and not logged in? - out.. - if (currentMem == null) - { - allowed = false; - } - else //do member authentication stuff... - allowed = memberAuthentication(baseExt, currentMem); - } - } - else - { - //check for RestExtensionAttribute - - var restExtensions = PluginManager.Current.ResolveRestExtensions(); - - foreach (var t in restExtensions) - { - - var temp = t.GetCustomAttributes(typeof(RestExtension), false).OfType(); - - if (temp.Any(x => x.GetAlias() == extensionAlias)) - { - - MethodInfo mi = t.GetMethod(methodName); - - if (mi != null) - { - //check allowed - var attributes = mi.GetCustomAttributes(typeof (RestExtensionMethod), false) - .OfType() - .ToArray(); - - //check to make sure the method was decorated properly - if (attributes.Any()) - { - fromFile = false; - - var attribute = attributes.First(); - allowed = attribute.allowAll; - - if (!allowed) - { - //Member Based permissions.. check for group, type and ID... - Member currentMem = Member.GetCurrentMember(); - - //not basic.. and not logged in? - out.. - if (currentMem == null) - { - allowed = false; - } - else - { - //do member authentication stuff... - allowed = memberAuthentication(attribute, currentMem); - } - } - - if (allowed) - { - this.method = t.GetMethod(methodName); - this.isAllowed = this.method != null; - this.alias = extensionAlias; - this.assembly = t.Assembly; - this.type = t; - this.returnXML = attribute.returnXml; - } - } - } - } - } - } - - if (allowed) - { - if (fromFile) - { - XmlNode extNode = baseDoc.SelectSingleNode("/RestExtensions/ext [@alias='" + extensionAlias + "']"); - string asml = extNode.Attributes["assembly"].Value; - string assemblyPath = IOHelper.MapPath(string.Format("{0}/{1}.dll", SystemDirectories.Bin, asml.TrimStart('/'))); - Assembly returnAssembly = System.Reflection.Assembly.LoadFrom(assemblyPath); - - string returnTypeName = extNode.Attributes["type"].Value; - Type returnType = returnAssembly.GetType(returnTypeName); - - - if (baseExt.Attributes["returnXml"] != null && baseExt.Attributes["returnXml"].Value.ToLower() == "false") - this.returnXML = false; - - this.method = returnType.GetMethod(methodName); - this.isAllowed = this.method != null; - this.alias = extensionAlias; - this.assembly = returnAssembly; - this.type = returnType; - } - } - else - { - this.isAllowed = false; - } - } - - private static bool memberAuthentication(RestExtensionMethod baseExt, Member currentMem) - { - //Check group, type and ID - bool memberAccess = false; - - if (!string.IsNullOrEmpty(baseExt.GetAllowGroup())) - { - - //Groups array - string[] groupArray = baseExt.GetAllowGroup().Split(','); - - foreach (MemberGroup mg in currentMem.Groups.Values) - { - foreach (string group in groupArray) - { - if (group == mg.Text) - memberAccess = true; - } - } - - } - - //Membertype allowed? - if (!string.IsNullOrEmpty(baseExt.GetAllowType()) && !memberAccess) - { - - //Types array - string[] typeArray = baseExt.GetAllowType().Split(','); - - foreach (string type in typeArray) - { - if (type == currentMem.ContentType.Alias) - memberAccess = true; - } - - } - - - //Member ID allowed? should this work with loginName instead? - if (!string.IsNullOrEmpty(baseExt.GetAllowMember()) && !memberAccess) - { - - if (int.Parse((string)baseExt.GetAllowMember().Trim()) == currentMem.Id) - memberAccess = true; - - } - return memberAccess; - } - - private static bool memberAuthentication(XmlNode baseExt, Member currentMem) - { - //Check group, type and ID - bool memberAccess = false; - - if (baseExt.Attributes["allowGroup"] != null) - { - if (baseExt.Attributes["allowGroup"].Value != "") - { - //Groups array - string[] groupArray = baseExt.Attributes["allowGroup"].Value.Split(','); - - foreach (MemberGroup mg in currentMem.Groups.Values) - { - foreach (string group in groupArray) - { - if (group == mg.Text) - memberAccess = true; - } - } - } - } - - //Membertype allowed? - if (baseExt.Attributes["allowType"] != null && !memberAccess) - { - if (baseExt.Attributes["allowType"].Value != "") - { - //Types array - string[] typeArray = baseExt.Attributes["allowType"].Value.Split(','); - - foreach (string type in typeArray) - { - if (type == currentMem.ContentType.Alias) - memberAccess = true; - } - } - } - - - //Member ID allowed? should this work with loginName instead? - if (baseExt.Attributes["allowMember"] != null && !memberAccess) - { - if (baseExt.Attributes["allowMember"].Value != "") - { - if (int.Parse((string)baseExt.Attributes["allowMember"].Value.Trim()) == currentMem.Id) - memberAccess = true; - } - } - return memberAccess; - } - - } -} diff --git a/src/umbraco.businesslogic/IO/SystemFiles.cs b/src/umbraco.businesslogic/IO/SystemFiles.cs index 5609abd638..02af967650 100644 --- a/src/umbraco.businesslogic/IO/SystemFiles.cs +++ b/src/umbraco.businesslogic/IO/SystemFiles.cs @@ -42,13 +42,7 @@ namespace umbraco.IO { get { return Umbraco.Core.IO.SystemFiles.XsltextensionsConfig; } } - - public static string RestextensionsConfig - { - get { return Umbraco.Core.IO.SystemFiles.RestextensionsConfig; } - } - - + public static string SkinningXml { get { return Umbraco.Core.IO.SystemFiles.SkinningXml; } diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs deleted file mode 100644 index f77fdad206..0000000000 --- a/src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Xml; -using umbraco.IO; - -namespace umbraco.cms.businesslogic.packager.standardPackageActions -{ - public class addRestExtension : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - public bool Execute(string packageName, XmlNode xmlData) - { - - XmlNodeList _newExts = xmlData.SelectNodes("//ext"); - - if (_newExts.Count > 0) - { - - string reConfig = SystemFiles.RestextensionsConfig; - - XmlDocument xdoc = new XmlDocument(); - xdoc.PreserveWhitespace = true; - xdoc = xmlHelper.OpenAsXmlDocument(reConfig); - - - XmlNode xn = xdoc.SelectSingleNode("//RestExtensions"); - - if (xn != null) - { - for (int i = 0; i < _newExts.Count; i++) - { - XmlNode newExt = _newExts[i]; - string _alias = newExt.Attributes["alias"].Value; - - bool insertExt = true; - if (xn.HasChildNodes) - { - foreach (XmlNode ext in xn.SelectNodes("//ext")) - { - if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) - insertExt = false; - } - } - - if (insertExt) - { - xn.AppendChild(xdoc.ImportNode(newExt, true)); - } - } - - xdoc.Save(IOHelper.MapPath(reConfig)); - return true; - } - } - return false; - } - - public string Alias() - { - return "addRestExtension"; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - - XmlNodeList _newExts = xmlData.SelectNodes("//ext"); - - if (_newExts.Count > 0) - { - string reConfig = SystemFiles.RestextensionsConfig; - - XmlDocument xdoc = new XmlDocument(); - xdoc.PreserveWhitespace = true; - xdoc.Load(reConfig); - - XmlNode xn = xdoc.SelectSingleNode("//RestExtensions"); - - if (xn != null) - { - bool inserted = false; - - for (int i = 0; i < _newExts.Count; i++) - { - XmlNode newExt = _newExts[i]; - string _alias = newExt.Attributes["alias"].Value; - if (xn.HasChildNodes) - { - foreach (XmlNode ext in xn.SelectNodes("//ext")) - { - if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) - { - xn.RemoveChild(ext); - inserted = true; - } - } - } - } - - if (inserted) - { - xdoc.Save(IOHelper.MapPath(reConfig)); - return true; - } - } - } - return false; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } -} \ No newline at end of file diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index 4edc5998b8..612429d986 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -250,7 +250,6 @@ -