70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Umbraco.Core;
|
|
using Umbraco.Core.Services;
|
|
using Umbraco.Web.Trees;
|
|
|
|
namespace Umbraco.Web.BackOffice.Trees
|
|
{
|
|
/// <summary>
|
|
/// The base controller for all tree requests
|
|
/// </summary>
|
|
public abstract class TreeController : TreeControllerBase
|
|
{
|
|
private static readonly ConcurrentDictionary<Type, TreeAttribute> _treeAttributeCache = new ConcurrentDictionary<Type, TreeAttribute>();
|
|
|
|
private readonly TreeAttribute _treeAttribute;
|
|
|
|
private readonly ILocalizedTextService _textService;
|
|
|
|
protected TreeController()
|
|
{
|
|
var serviceProvider = HttpContext.RequestServices;
|
|
_textService = serviceProvider.GetService<ILocalizedTextService>();
|
|
_treeAttribute = GetTreeAttribute();
|
|
}
|
|
|
|
protected TreeController(ILocalizedTextService textService)
|
|
{
|
|
_textService = textService ?? throw new ArgumentNullException(nameof(textService));
|
|
_treeAttribute = GetTreeAttribute();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string RootNodeDisplayName => Tree.GetRootNodeDisplayName(this, _textService);
|
|
|
|
/// <inheritdoc />
|
|
public override string TreeGroup => _treeAttribute.TreeGroup;
|
|
|
|
/// <inheritdoc />
|
|
public override string TreeAlias => _treeAttribute.TreeAlias;
|
|
|
|
/// <inheritdoc />
|
|
public override string TreeTitle => _treeAttribute.TreeTitle;
|
|
|
|
/// <inheritdoc />
|
|
public override TreeUse TreeUse => _treeAttribute.TreeUse;
|
|
|
|
/// <inheritdoc />
|
|
public override string SectionAlias => _treeAttribute.SectionAlias;
|
|
|
|
/// <inheritdoc />
|
|
public override int SortOrder => _treeAttribute.SortOrder;
|
|
|
|
/// <inheritdoc />
|
|
public override bool IsSingleNodeTree => _treeAttribute.IsSingleNodeTree;
|
|
|
|
private TreeAttribute GetTreeAttribute()
|
|
{
|
|
return _treeAttributeCache.GetOrAdd(GetType(), type =>
|
|
{
|
|
var treeAttribute = type.GetCustomAttribute<TreeAttribute>(false);
|
|
if (treeAttribute == null)
|
|
throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute");
|
|
return treeAttribute;
|
|
});
|
|
}
|
|
}
|
|
}
|