More work on streamlining package development for views and conventions.

This commit is contained in:
Shannon
2013-10-02 21:03:51 +10:00
parent 92efd6d645
commit dc42c1ebb7
4 changed files with 72 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Web.Trees.Menu
{
private readonly string _packageFolderName;
private readonly List<MenuItem> _menuItems;
public MenuItemCollection()
{
_menuItems = new List<MenuItem>();

View File

@@ -1,11 +1,14 @@
using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.Linq;
using System.Net.Http.Formatting;
using Umbraco.Core;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees.Menu;
using Umbraco.Web.WebApi;
using Umbraco.Web.WebApi.Filters;
using Constants = Umbraco.Core.Constants;
namespace Umbraco.Web.Trees
{
@@ -15,6 +18,7 @@ namespace Umbraco.Web.Trees
public abstract class TreeController : UmbracoAuthorizedApiController
{
private readonly TreeAttribute _attribute;
private readonly MenuItemCollection _menuItemCollection;
/// <summary>
/// Remove the xml formatter... only support JSON!
@@ -41,6 +45,19 @@ namespace Umbraco.Web.Trees
//assign the properties of this object to those of the metadata attribute
_attribute = treeAttributes.First();
//Create the menu item collection with the area nem already specified
_menuItemCollection = Metadata.AreaName.IsNullOrWhiteSpace()
? new MenuItemCollection()
: new MenuItemCollection(Metadata.AreaName);
}
/// <summary>
/// Returns a menu item collection to be used to return the menu items from GetMenuForNode
/// </summary>
public MenuItemCollection MenuItems
{
get { return _menuItemCollection; }
}
/// <summary>
@@ -300,6 +317,7 @@ namespace Umbraco.Web.Trees
#endregion
#region Events
public static event EventHandler<TreeNodesRenderingEventArgs> TreeNodesRendering;
private static void OnTreeNodesRendering(TreeController instance, TreeNodesRenderingEventArgs e)
@@ -314,6 +332,49 @@ namespace Umbraco.Web.Trees
{
var handler = RootNodeRendering;
if (handler != null) handler(instance, e);
}
#endregion
#region Metadata
/// <summary>
/// stores the metadata about plugin controllers
/// </summary>
private static readonly ConcurrentDictionary<Type, PluginControllerMetadata> MetadataStorage = new ConcurrentDictionary<Type, PluginControllerMetadata>();
/// <summary>
/// Returns the metadata for this instance
/// </summary>
internal PluginControllerMetadata Metadata
{
get { return GetMetadata(this.GetType()); }
}
/// <summary>
/// Returns the metadata for a PluginController
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
internal static PluginControllerMetadata GetMetadata(Type type)
{
return MetadataStorage.GetOrAdd(type, type1 =>
{
var attribute = type.GetCustomAttribute<PluginControllerAttribute>(false);
var meta = new PluginControllerMetadata()
{
AreaName = attribute == null ? null : attribute.AreaName,
ControllerName = ControllerExtensions.GetControllerName(type),
ControllerNamespace = type.Namespace,
ControllerType = type
};
MetadataStorage.TryAdd(type, meta);
return meta;
});
}
#endregion
}
}