Fixes: 28501 ... again.

now re-registers all trees, IActions and IAction handlers when a package is installed or uninstalled.

[TFS Changeset #76355]
This commit is contained in:
Shandem
2010-08-24 12:39:29 +00:00
parent 605b6efc57
commit 6830cdd526
3 changed files with 58 additions and 30 deletions

View File

@@ -27,15 +27,33 @@ namespace umbraco.BusinessLogic.Actions
/// </summary>
public class Action
{
private static readonly List<IAction> _actions = new List<IAction>();
private static readonly Dictionary<string, string> _actionJs = new Dictionary<string, string>();
private static readonly List<IActionHandler> _actionHandlers = new List<IActionHandler>();
private static List<IAction> _actions = new List<IAction>();
private static List<IActionHandler> _actionHandlers = new List<IActionHandler>();
private static readonly List<string> _actionJSReference = new List<string>();
private static readonly Dictionary<string, string> _actionJs = new Dictionary<string, string>();
private static readonly object m_Lock = new object();
private static readonly object m_LockerReRegister = new object();
static Action()
{
RegisterIActions();
RegisterIActionHandlers();
ReRegisterActionsAndHandlers();
}
/// <summary>
/// This is used when an IAction or IActionHandler is installed into the system
/// and needs to be loaded into memory.
/// </summary>
public static void ReRegisterActionsAndHandlers()
{
lock (m_Lock)
{
_actions.Clear();
_actionHandlers.Clear();
RegisterIActions();
RegisterIActionHandlers();
}
}
/// <summary>
@@ -43,17 +61,20 @@ namespace umbraco.BusinessLogic.Actions
/// </summary>
private static void RegisterIActionHandlers()
{
if (_actionHandlers.Count > 0)
return;
List<Type> foundIActionHandlers = TypeFinder.FindClassesOfType<IActionHandler>(true);
foreach (Type type in foundIActionHandlers)
if (_actionHandlers.Count == 0)
{
IActionHandler typeInstance;
typeInstance = Activator.CreateInstance(type) as IActionHandler;
if (typeInstance != null)
_actionHandlers.Add(typeInstance);
List<Type> foundIActionHandlers = TypeFinder.FindClassesOfType<IActionHandler>(true);
foreach (Type type in foundIActionHandlers)
{
IActionHandler typeInstance;
typeInstance = Activator.CreateInstance(type) as IActionHandler;
if (typeInstance != null)
_actionHandlers.Add(typeInstance);
}
}
}
/// <summary>
@@ -61,28 +82,29 @@ namespace umbraco.BusinessLogic.Actions
/// </summary>
private static void RegisterIActions()
{
if (_actions.Count > 0)
return;
List<Type> foundIActions = TypeFinder.FindClassesOfType<IAction>(true);
foreach (Type type in foundIActions)
if (_actions.Count == 0)
{
IAction typeInstance;
PropertyInfo instance = type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);
//if the singletone initializer is not found, try simply creating an instance of the IAction if it supports public constructors
if (instance == null)
typeInstance = Activator.CreateInstance(type) as IAction;
else
typeInstance = instance.GetValue(null, null) as IAction;
if (typeInstance != null)
List<Type> foundIActions = TypeFinder.FindClassesOfType<IAction>(true);
foreach (Type type in foundIActions)
{
if (!string.IsNullOrEmpty(typeInstance.JsSource))
_actionJSReference.Add(typeInstance.JsSource);
_actions.Add(typeInstance);
}
IAction typeInstance;
PropertyInfo instance = type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);
//if the singletone initializer is not found, try simply creating an instance of the IAction if it supports public constructors
if (instance == null)
typeInstance = Activator.CreateInstance(type) as IAction;
else
typeInstance = instance.GetValue(null, null) as IAction;
if (typeInstance != null)
{
if (!string.IsNullOrEmpty(typeInstance.JsSource))
_actionJSReference.Add(typeInstance.JsSource);
_actions.Add(typeInstance);
}
}
}
}
/// <summary>

View File

@@ -18,6 +18,7 @@ using runtimeMacro = umbraco.macro;
using System.Xml;
using umbraco.IO;
using umbraco.cms.presentation.Trees;
using BizLogicAction = umbraco.BusinessLogic.Actions.Action;
namespace umbraco.presentation.developer.packages
{
@@ -567,6 +568,8 @@ namespace umbraco.presentation.developer.packages
TreeDefinitionCollection.Instance.ReRegisterTrees();
BizLogicAction.ReRegisterActionsAndHandlers();
}
private bool isManifestEmpty()

View File

@@ -13,6 +13,7 @@ using System.Xml.XPath;
using umbraco.BasePages;
using umbraco.IO;
using umbraco.cms.presentation.Trees;
using BizLogicAction = umbraco.BusinessLogic.Actions.Action;
namespace umbraco.presentation.developer.packages
{
@@ -254,6 +255,8 @@ namespace umbraco.presentation.developer.packages
TreeDefinitionCollection.Instance.ReRegisterTrees();
BizLogicAction.ReRegisterActionsAndHandlers();
break;
default:
break;