diff --git a/src/Umbraco.Web/Trees/ApplicationTreeController.cs b/src/Umbraco.Web/Trees/ApplicationTreeController.cs index 9e8ab975d8..bd3d08b963 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeController.cs @@ -77,7 +77,7 @@ namespace Umbraco.Web.Trees private TreeNode GetRootForMultipleAppTree(ApplicationTree configTree, FormDataCollection queryStrings) { if (configTree == null) throw new ArgumentNullException("configTree"); - var byControllerAttempt = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext, Request); + var byControllerAttempt = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext); if (byControllerAttempt.Success) { return byControllerAttempt.Result; @@ -103,10 +103,10 @@ namespace Umbraco.Web.Trees { var rootId = Constants.System.Root.ToString(CultureInfo.InvariantCulture); if (configTree == null) throw new ArgumentNullException("configTree"); - var byControllerAttempt = configTree.TryLoadFromControllerTree(id, queryStrings, ControllerContext, Request); + var byControllerAttempt = configTree.TryLoadFromControllerTree(id, queryStrings, ControllerContext); if (byControllerAttempt.Success) { - var rootNode = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext, Request); + var rootNode = configTree.TryGetRootNodeFromControllerTree(queryStrings, ControllerContext); if (rootNode.Success == false) { //This should really never happen if we've successfully got the children above. diff --git a/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs b/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs index ab060d8c08..86667486ac 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs @@ -22,7 +22,7 @@ namespace Umbraco.Web.Trees internal static class ApplicationTreeExtensions { - private static Attempt TryGetControllerTree(this ApplicationTree appTree) + internal static Attempt TryGetControllerTree(this ApplicationTree appTree) { //get reference to all TreeApiControllers var controllerTrees = UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers @@ -38,7 +38,7 @@ namespace Umbraco.Web.Trees return new Attempt(true, foundControllerTree); } - internal static Attempt TryGetRootNodeFromControllerTree(this ApplicationTree appTree, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request) + internal static Attempt TryGetRootNodeFromControllerTree(this ApplicationTree appTree, FormDataCollection formCollection, HttpControllerContext controllerContext) { var foundControllerTreeAttempt = appTree.TryGetControllerTree(); if (foundControllerTreeAttempt.Success == false) @@ -49,7 +49,7 @@ namespace Umbraco.Web.Trees //instantiate it, since we are proxying, we need to setup the instance with our current context var instance = (TreeApiController)DependencyResolver.Current.GetService(foundControllerTree); instance.ControllerContext = controllerContext; - instance.Request = request; + instance.Request = controllerContext.Request; //return the root var node = instance.GetRootNode(formCollection); return node == null @@ -57,7 +57,7 @@ namespace Umbraco.Web.Trees : new Attempt(true, node); } - internal static Attempt TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext, HttpRequestMessage request) + internal static Attempt TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext) { var foundControllerTreeAttempt = appTree.TryGetControllerTree(); if (foundControllerTreeAttempt.Success == false) @@ -69,7 +69,7 @@ namespace Umbraco.Web.Trees //instantiate it, since we are proxying, we need to setup the instance with our current context var instance = (TreeApiController)DependencyResolver.Current.GetService(foundControllerTree); instance.ControllerContext = controllerContext; - instance.Request = request; + instance.Request = controllerContext.Request; //return it's data return new Attempt(true, instance.GetNodes(id, formCollection)); } @@ -99,7 +99,7 @@ namespace Umbraco.Web.Trees return new Attempt(true, bTree.RootNode); } - private static Attempt TryGetLegacyTreeDef(this ApplicationTree appTree) + internal static Attempt TryGetLegacyTreeDef(this ApplicationTree appTree) { //This is how the legacy trees worked.... var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias); diff --git a/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs b/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs index 3ebe1cf497..5ebd57026d 100644 --- a/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs +++ b/src/Umbraco.Web/Trees/LegacyTreeDataConverter.cs @@ -20,6 +20,7 @@ namespace Umbraco.Web.Trees /// internal class LegacyTreeDataConverter { + /// /// Gets the menu item collection from a legacy tree node based on it's parent node's child collection /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 47b513f916..b8e2969da4 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -798,6 +798,7 @@ + diff --git a/src/Umbraco.Web/WebApi/ControllerContextExtensions.cs b/src/Umbraco.Web/WebApi/ControllerContextExtensions.cs index 1ab1b0bc42..1858048ba6 100644 --- a/src/Umbraco.Web/WebApi/ControllerContextExtensions.cs +++ b/src/Umbraco.Web/WebApi/ControllerContextExtensions.cs @@ -1,4 +1,5 @@ -using System.Web.Http.Controllers; +using System.Runtime.Remoting.Contexts; +using System.Web.Http.Controllers; namespace Umbraco.Web.WebApi { diff --git a/src/Umbraco.Web/WebApi/WebApiHelper.cs b/src/Umbraco.Web/WebApi/WebApiHelper.cs new file mode 100644 index 0000000000..ca0fd08932 --- /dev/null +++ b/src/Umbraco.Web/WebApi/WebApiHelper.cs @@ -0,0 +1,31 @@ +using System; +using System.Net.Http; +using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Hosting; +using System.Web.Http.Routing; + +namespace Umbraco.Web.WebApi +{ + internal static class WebApiHelper + { + /// + /// A helper method to create a WebAPI HttpControllerContext which can be used to execute a controller manually + /// + /// + /// + /// + /// + internal static HttpControllerContext CreateContext(HttpMethod method, Uri uri, HttpContextBase httpContext) + { + var config = new HttpConfiguration(GlobalConfiguration.Configuration.Routes); + IHttpRouteData route = new HttpRouteData(new HttpRoute()); + var req = new HttpRequestMessage(method, uri); + req.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; + req.Properties[HttpPropertyKeys.HttpRouteDataKey] = route; + req.Properties["MS_HttpContext"] = httpContext; + return new HttpControllerContext(config, route, req); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs index 7b17c2303e..64a424ebb4 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TreeClientService.asmx.cs @@ -1,7 +1,16 @@ using System; using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Formatting; using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Hosting; +using System.Web.Http.Routing; +using System.Web.Mvc; +using System.Web.Routing; using System.Web.Services; +using Umbraco.Web.WebApi; using Umbraco.Web.WebServices; using umbraco.presentation.umbraco.controls; using umbraco.cms.presentation.Trees; @@ -11,29 +20,30 @@ using System.EnterpriseServices; using System.IO; using System.Web.UI; using umbraco.controls.Tree; +using Umbraco.Web.Trees; namespace umbraco.presentation.webservices { - /// - /// Client side ajax utlities for the tree - /// - [ScriptService] - [WebService] + /// + /// Client side ajax utlities for the tree + /// + [ScriptService] + [WebService] public class TreeClientService : UmbracoAuthorizedWebService - { + { - /// - /// Returns a key/value object with: json, app, js as the keys - /// - /// - [WebMethod] + /// + /// Returns a key/value object with: json, app, js as the keys + /// + /// + [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] - public Dictionary GetInitAppTreeData(string app, string treeType, bool showContextMenu, bool isDialog, TreeDialogModes dialogMode, string functionToCall, string nodeKey) - { - AuthorizeRequest(app, true); + public Dictionary GetInitAppTreeData(string app, string treeType, bool showContextMenu, bool isDialog, TreeDialogModes dialogMode, string functionToCall, string nodeKey) + { + AuthorizeRequest(app, true); - var treeCtl = new TreeControl() - { + var treeCtl = new TreeControl() + { ShowContextMenu = showContextMenu, IsDialog = isDialog, DialogMode = dialogMode, @@ -42,9 +52,9 @@ namespace umbraco.presentation.webservices NodeKey = string.IsNullOrEmpty(nodeKey) ? "" : nodeKey, StartNodeID = -1, //TODO: set this based on parameters! FunctionToCall = string.IsNullOrEmpty(functionToCall) ? "" : functionToCall - }; + }; - var returnVal = new Dictionary(); + var returnVal = new Dictionary(); if (string.IsNullOrEmpty(treeType)) { @@ -54,7 +64,30 @@ namespace umbraco.presentation.webservices } else { - + //first get the app tree definition so we can then figure out if we need to load by legacy or new + //now we'll look up that tree + var appTree = Services.ApplicationTreeService.GetByAlias(treeType); + if (appTree == null) + throw new InvalidOperationException("No tree found with alias " + treeType); + + var controllerAttempt = appTree.TryGetControllerTree(); + if (controllerAttempt.Success) + { + var context = WebApiHelper.CreateContext(new HttpMethod("GET"), Context.Request.Url, new HttpContextWrapper(Context)); + + var rootAttempt = appTree.TryGetRootNodeFromControllerTree( + new FormDataCollection(new Dictionary {{"app", app}}), + context); + + if (rootAttempt.Success) + { + + } + } + + var legacyAttempt = appTree.TryGetLegacyTreeDef(); + + //get the tree that we need to render var tree = TreeDefinitionCollection.Instance.FindTree(treeType).CreateInstance(); tree.ShowContextMenu = showContextMenu; @@ -68,21 +101,21 @@ namespace umbraco.presentation.webservices //now render it's start node var xTree = new XmlTree(); xTree.Add(tree.RootNode); - returnVal.Add("json", xTree.ToString()); + returnVal.Add("json", xTree.ToString()); } returnVal.Add("app", app); - returnVal.Add("js", treeCtl.JSCurrApp); + returnVal.Add("js", treeCtl.JSCurrApp); - return returnVal; - } + return returnVal; + } [Obsolete("Use the AuthorizeRequest methods on the base class UmbracoAuthorizedWebService instead")] - public static void Authorize() - { - if (!BasePages.BasePage.ValidateUserContextID(BasePages.BasePage.umbracoUserContextID)) - throw new Exception("Client authorization failed. User is not logged in"); - } + public static void Authorize() + { + if (!BasePages.BasePage.ValidateUserContextID(BasePages.BasePage.umbracoUserContextID)) + throw new Exception("Client authorization failed. User is not logged in"); + } - } + } }