From d95b688a7f8548327180d4c257419fc89d018ccf Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Tue, 14 Aug 2012 12:03:34 +0600 Subject: [PATCH] Adds new IUmbracoEvents: #U4-164 --- src/Umbraco.Core/CacheRefreshersResolver.cs | 2 + src/Umbraco.Core/CoreBootManager.cs | 4 +- .../ManyObjectsResolverBase.cs | 20 +++++-- src/Umbraco.Web/ApplicationEventsResolver.cs | 54 +++++++++++++++++ src/Umbraco.Web/ContentStoreResolver.cs | 48 +++++++-------- src/Umbraco.Web/IApplicationEvents.cs | 15 +++++ .../ThumbnailProvidersResolver.cs | 3 + .../Routing/LastChanceLookupResolver.cs | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 4 ++ src/Umbraco.Web/UmbracoApplication.cs | 7 ++- src/Umbraco.Web/WebBootManager.cs | 57 +++++++++++++++++- ...ureSystemPathsApplicationStartupHandler.cs | 3 +- .../LibraryCacheRefresher.cs | 59 +++++++++++++++++++ .../umbraco.presentation/library.cs | 52 ---------------- .../umbraco/Search/ExamineEvents.cs | 3 +- .../nodeFactory/UmbracoSiteMapProvider.cs | 33 ----------- .../UmbracoSiteMapProviderAccessUpdate.cs | 37 ++++++++++++ src/umbraco.businesslogic/ApplicationBase.cs | 2 +- .../ApplicationRegistrar.cs | 2 +- .../ApplicationStartupHandler.cs | 2 + .../ApplicationTreeRegistrar.cs | 2 +- .../Properties/AssemblyInfo.cs | 1 + .../IApplicationStartupHandler.cs | 2 +- .../umbraco.interfaces.csproj | 2 +- 24 files changed, 289 insertions(+), 127 deletions(-) create mode 100644 src/Umbraco.Web/ApplicationEventsResolver.cs create mode 100644 src/Umbraco.Web/IApplicationEvents.cs create mode 100644 src/Umbraco.Web/umbraco.presentation/LibraryCacheRefresher.cs create mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProviderAccessUpdate.cs diff --git a/src/Umbraco.Core/CacheRefreshersResolver.cs b/src/Umbraco.Core/CacheRefreshersResolver.cs index dab9555069..e6973c3d8f 100644 --- a/src/Umbraco.Core/CacheRefreshersResolver.cs +++ b/src/Umbraco.Core/CacheRefreshersResolver.cs @@ -5,6 +5,8 @@ using umbraco.interfaces; namespace Umbraco.Core { + + /// /// A resolver to return all ICacheRefresher objects /// diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 1d14c8c5dd..f1bb6e45e7 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -21,6 +21,8 @@ namespace Umbraco.Core private bool _isStarted = false; private bool _isComplete = false; + protected ApplicationContext ApplicationContext { get; private set; } + public virtual IBootManager Initialize() { if (_isInitialized) @@ -30,7 +32,7 @@ namespace Umbraco.Core _timer = DisposableTimer.Start(x => LogHelper.Info("Umbraco application startup complete" + " (took " + x + "ms)")); //create the ApplicationContext - ApplicationContext.Current = new ApplicationContext() + ApplicationContext = ApplicationContext.Current = new ApplicationContext() { IsReady = true // fixme }; diff --git a/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs b/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs index 8c6dba8fd2..bab284c7f4 100644 --- a/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs +++ b/src/Umbraco.Core/ObjectResolution/ManyObjectsResolverBase.cs @@ -13,12 +13,15 @@ namespace Umbraco.Core.ObjectResolution private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(); #region Constructors + + /// /// Initializes a new instance of the class with an empty list of objects. /// /// The lifetime scope of instantiated objects, default is per Application protected ManyObjectsResolverBase(ObjectLifetimeScope scope = ObjectLifetimeScope.Application) { + CanResolveBeforeFrozen = false; if (scope == ObjectLifetimeScope.HttpRequest) { if (HttpContext.Current == null) @@ -39,6 +42,8 @@ namespace Umbraco.Core.ObjectResolution /// protected ManyObjectsResolverBase(HttpContextBase httpContext) { + CanResolveBeforeFrozen = false; + if (httpContext == null) throw new ArgumentNullException("httpContext"); LifetimeScope = ObjectLifetimeScope.HttpRequest; CurrentHttpContext = httpContext; InstanceTypes = new List(); @@ -68,6 +73,11 @@ namespace Umbraco.Core.ObjectResolution } #endregion + /// + /// used internally for special resolvers to be able to resolve objects before resolution is frozen. + /// + internal bool CanResolveBeforeFrozen { get; set; } + /// /// Returns the list of Types registered that instances will be created from /// @@ -92,7 +102,7 @@ namespace Umbraco.Core.ObjectResolution get { //We cannot return values unless resolution is locked - if (!Resolution.IsFrozen) + if (!CanResolveBeforeFrozen && !Resolution.IsFrozen) throw new InvalidOperationException("Values cannot be returned until Resolution is frozen"); switch (LifetimeScope) @@ -139,7 +149,7 @@ namespace Umbraco.Core.ObjectResolution /// Removes a type. /// /// The type to remove. - public void RemoveType(Type value) + public virtual void RemoveType(Type value) { EnsureCorrectType(value); using (new WriteLock(_lock)) @@ -161,7 +171,7 @@ namespace Umbraco.Core.ObjectResolution /// Adds a Type to the end of the list. /// /// The object to be added. - public void AddType(Type value) + public virtual void AddType(Type value) { EnsureCorrectType(value); using (var l = new UpgradeableReadLock(_lock)) @@ -188,7 +198,7 @@ namespace Umbraco.Core.ObjectResolution /// /// Clears the list. /// - public void Clear() + public virtual void Clear() { using (new WriteLock(_lock)) { @@ -201,7 +211,7 @@ namespace Umbraco.Core.ObjectResolution /// /// The zero-based index at which the object should be inserted. /// The object to insert. - public void InsertType(int index, Type value) + public virtual void InsertType(int index, Type value) { EnsureCorrectType(value); using (var l = new UpgradeableReadLock(_lock)) diff --git a/src/Umbraco.Web/ApplicationEventsResolver.cs b/src/Umbraco.Web/ApplicationEventsResolver.cs new file mode 100644 index 0000000000..dfba44eb42 --- /dev/null +++ b/src/Umbraco.Web/ApplicationEventsResolver.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.ObjectResolution; +using umbraco.interfaces; + +namespace Umbraco.Web +{ + /// + /// A resolver to return all IApplicationEvents objects + /// + internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase + { + + /// + /// Constructor + /// + /// + internal ApplicationEventsResolver(IEnumerable applicationEventHandlers) + : base(applicationEventHandlers) + { + + } + + /// + /// Gets the implementations. + /// + public IEnumerable ApplicationEventHandlers + { + get { return Values.OfType(); } + } + + public override void Clear() + { + throw new NotSupportedException("This class does not support this method"); + } + + public override void AddType(Type value) + { + throw new NotSupportedException("This class does not support this method"); + } + + public override void InsertType(int index, Type value) + { + throw new NotSupportedException("This class does not support this method"); + } + + public override void RemoveType(Type value) + { + throw new NotSupportedException("This class does not support this method"); + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/ContentStoreResolver.cs b/src/Umbraco.Web/ContentStoreResolver.cs index 25ca1d5e13..762af03d02 100644 --- a/src/Umbraco.Web/ContentStoreResolver.cs +++ b/src/Umbraco.Web/ContentStoreResolver.cs @@ -2,31 +2,31 @@ using Umbraco.Core.ObjectResolution; namespace Umbraco.Web { - /// - /// An object resolver to return the IContentStore - /// - internal class ContentStoreResolver : SingleObjectResolverBase +/// +/// An object resolver to return the IContentStore +/// +internal class ContentStoreResolver : SingleObjectResolverBase +{ + internal ContentStoreResolver(IContentStore contentStore) + : base(contentStore) { - internal ContentStoreResolver(IContentStore contentStore) - { - Value = contentStore; - } + } - /// - /// Can be used by developers at runtime to set their IContentStore at app startup - /// - /// - public void SetContentStore(IContentStore contentStore) - { - Value = contentStore; - } - - /// - /// Returns the IContentStore - /// - public IContentStore ContentStore - { - get { return Value; } - } + /// + /// Can be used by developers at runtime to set their IContentStore at app startup + /// + /// + public void SetContentStore(IContentStore contentStore) + { + Value = contentStore; } + + /// + /// Returns the IContentStore + /// + public IContentStore ContentStore + { + get { return Value; } + } +} } \ No newline at end of file diff --git a/src/Umbraco.Web/IApplicationEvents.cs b/src/Umbraco.Web/IApplicationEvents.cs new file mode 100644 index 0000000000..e6cdb6b8b6 --- /dev/null +++ b/src/Umbraco.Web/IApplicationEvents.cs @@ -0,0 +1,15 @@ +using Umbraco.Core; +using umbraco.interfaces; + +namespace Umbraco.Web +{ + /// + /// Custom IApplicationStartupHandler that auto subscribes to the applications events + /// + public interface IApplicationEvents : IApplicationStartupHandler + { + void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext); + void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext); + void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext); + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Media/ThumbnailProviders/ThumbnailProvidersResolver.cs b/src/Umbraco.Web/Media/ThumbnailProviders/ThumbnailProvidersResolver.cs index 11533a686c..b6e15324d1 100644 --- a/src/Umbraco.Web/Media/ThumbnailProviders/ThumbnailProvidersResolver.cs +++ b/src/Umbraco.Web/Media/ThumbnailProviders/ThumbnailProvidersResolver.cs @@ -24,6 +24,9 @@ namespace Umbraco.Web.Media.ThumbnailProviders } + /// + /// Return the providers + /// public IEnumerable Providers { get diff --git a/src/Umbraco.Web/Routing/LastChanceLookupResolver.cs b/src/Umbraco.Web/Routing/LastChanceLookupResolver.cs index 6a4703ac8c..0feadc8a4b 100644 --- a/src/Umbraco.Web/Routing/LastChanceLookupResolver.cs +++ b/src/Umbraco.Web/Routing/LastChanceLookupResolver.cs @@ -10,8 +10,8 @@ namespace Umbraco.Web.Routing { internal LastChanceLookupResolver(IDocumentLastChanceLookup lastChanceLookup) + : base(lastChanceLookup) { - Value = lastChanceLookup; } /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 40043c92ec..6f7d117e9a 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -238,6 +238,10 @@ Properties\SolutionInfo.cs + + + + diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 0c74bc516c..81f3e019d8 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -14,7 +14,12 @@ namespace Umbraco.Web /// public class UmbracoApplication : System.Web.HttpApplication { - private readonly IBootManager _bootManager = new WebBootManager(); + public UmbracoApplication() + { + _bootManager = new WebBootManager(this); + } + + private readonly IBootManager _bootManager; public static event EventHandler ApplicationStarting; public static event EventHandler ApplicationStarted; diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 4c223d62b8..57a9308f5d 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -15,8 +15,16 @@ namespace Umbraco.Web /// internal class WebBootManager : CoreBootManager { - public void Boot() + private readonly UmbracoApplication _umbracoApplication; + + public WebBootManager(UmbracoApplication umbracoApplication) { + _umbracoApplication = umbracoApplication; + if (umbracoApplication == null) throw new ArgumentNullException("umbracoApplication"); + } + + public void Boot() + { InitializeResolvers(); } @@ -50,8 +58,51 @@ namespace Umbraco.Web ); route.RouteHandler = new RenderRouteHandler(ControllerBuilder.Current.GetControllerFactory()); - //find and initialize the application startup handlers - ApplicationStartupHandler.RegisterHandlers(); + //find and initialize the application startup handlers, we need to initialize this resolver here because + //it is a special resolver where they need to be instantiated first before any other resolvers in order to bind to + //events and to call their events during bootup. + //ApplicationStartupHandler.RegisterHandlers(); + ApplicationEventsResolver.Current = new ApplicationEventsResolver( + PluginManager.Current.ResolveApplicationStartupHandlers()); + + //set the special flag to let us resolve before frozen resolution + ApplicationEventsResolver.Current.CanResolveBeforeFrozen = true; + + //now we need to call the initialize methods + ApplicationEventsResolver.Current.ApplicationEventHandlers + .ForEach(x => x.OnApplicationInitialized(_umbracoApplication, ApplicationContext)); + + return this; + } + + /// + /// Ensure that the OnApplicationStarting methods of the IApplicationEvents are called + /// + /// + /// + public override IBootManager Startup(Action afterStartup) + { + base.Startup(afterStartup); + + //call OnApplicationStarting of each application events handler + ApplicationEventsResolver.Current.ApplicationEventHandlers + .ForEach(x => x.OnApplicationStarting(_umbracoApplication, ApplicationContext)); + + return this; + } + + /// + /// Ensure that the OnApplicationStarted methods of the IApplicationEvents are called + /// + /// + /// + public override IBootManager Complete(Action afterComplete) + { + base.Complete(afterComplete); + + //call OnApplicationStarting of each application events handler + ApplicationEventsResolver.Current.ApplicationEventHandlers + .ForEach(x => x.OnApplicationStarted(_umbracoApplication, ApplicationContext)); return this; } diff --git a/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs b/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs index f5444173d8..a6071c4432 100644 --- a/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs +++ b/src/Umbraco.Web/umbraco.presentation/EnsureSystemPathsApplicationStartupHandler.cs @@ -5,10 +5,11 @@ using System.Linq; using System.Web; using umbraco.IO; using umbraco.businesslogic; +using umbraco.interfaces; namespace umbraco.presentation { - public class EnsureSystemPathsApplicationStartupHandler : ApplicationStartupHandler + public class EnsureSystemPathsApplicationStartupHandler : IApplicationStartupHandler { public EnsureSystemPathsApplicationStartupHandler() { diff --git a/src/Umbraco.Web/umbraco.presentation/LibraryCacheRefresher.cs b/src/Umbraco.Web/umbraco.presentation/LibraryCacheRefresher.cs new file mode 100644 index 0000000000..3e991fafc4 --- /dev/null +++ b/src/Umbraco.Web/umbraco.presentation/LibraryCacheRefresher.cs @@ -0,0 +1,59 @@ +using umbraco.businesslogic; +using umbraco.cms.businesslogic; +using umbraco.cms.businesslogic.media; +using umbraco.cms.businesslogic.member; +using umbraco.interfaces; + +namespace umbraco +{ + /// + /// Special class made to listen to save events on objects where umbraco.library caches some of their objects + /// + public class LibraryCacheRefresher : IApplicationStartupHandler + { + public LibraryCacheRefresher() + { + if (UmbracoSettings.UmbracoLibraryCacheDuration > 0) + { + Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave); + Member.BeforeDelete += new Member.DeleteEventHandler(Member_BeforeDelete); + Media.AfterSave += new Media.SaveEventHandler(Media_AfterSave); + Media.BeforeDelete += new Media.DeleteEventHandler(Media_BeforeDelete); + } + + // now handled directly by the IRoutesCache implementation + //content.AfterUpdateDocumentCache += new content.DocumentCacheEventHandler(content_AfterUpdateDocumentCache); + //content.AfterRefreshContent += new content.RefreshContentEventHandler(content_AfterRefreshContent); + } + + //void content_AfterRefreshContent(Document sender, RefreshContentEventArgs e) + //{ + // library.ClearNiceUrlCache(); + //} + + //void content_AfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e) + //{ + // library.ClearNiceUrlCache(); + //} + + void Member_BeforeDelete(Member sender, DeleteEventArgs e) + { + library.ClearLibraryCacheForMember(sender.Id); + } + + void Media_BeforeDelete(Media sender, DeleteEventArgs e) + { + library.ClearLibraryCacheForMedia(sender.Id); + } + + void Media_AfterSave(Media sender, SaveEventArgs e) + { + library.ClearLibraryCacheForMedia(sender.Id); + } + + void Member_AfterSave(Member sender, SaveEventArgs e) + { + library.ClearLibraryCacheForMember(sender.Id); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 006920a46f..59ef823758 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -12,7 +12,6 @@ using System.Xml.XPath; using umbraco.BusinessLogic; -using umbraco.businesslogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.media; using umbraco.cms.businesslogic.member; @@ -2162,55 +2161,4 @@ namespace umbraco #endregion } - - /// - /// Special class made to listen to save events on objects where umbraco.library caches some of their objects - /// - public class LibraryCacheRefresher : ApplicationStartupHandler - { - public LibraryCacheRefresher() - { - if (UmbracoSettings.UmbracoLibraryCacheDuration > 0) - { - Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave); - Member.BeforeDelete += new Member.DeleteEventHandler(Member_BeforeDelete); - Media.AfterSave += new Media.SaveEventHandler(Media_AfterSave); - Media.BeforeDelete += new Media.DeleteEventHandler(Media_BeforeDelete); - } - - // now handled directly by the IRoutesCache implementation - //content.AfterUpdateDocumentCache += new content.DocumentCacheEventHandler(content_AfterUpdateDocumentCache); - //content.AfterRefreshContent += new content.RefreshContentEventHandler(content_AfterRefreshContent); - } - - //void content_AfterRefreshContent(Document sender, RefreshContentEventArgs e) - //{ - // library.ClearNiceUrlCache(); - //} - - //void content_AfterUpdateDocumentCache(Document sender, DocumentCacheEventArgs e) - //{ - // library.ClearNiceUrlCache(); - //} - - void Member_BeforeDelete(Member sender, DeleteEventArgs e) - { - library.ClearLibraryCacheForMember(sender.Id); - } - - void Media_BeforeDelete(Media sender, DeleteEventArgs e) - { - library.ClearLibraryCacheForMedia(sender.Id); - } - - void Media_AfterSave(Media sender, SaveEventArgs e) - { - library.ClearLibraryCacheForMedia(sender.Id); - } - - void Member_AfterSave(Member sender, SaveEventArgs e) - { - library.ClearLibraryCacheForMember(sender.Id); - } - } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs index 294af15e71..1d30d3eb88 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Search/ExamineEvents.cs @@ -7,13 +7,14 @@ using Examine; using UmbracoExamine; using Lucene.Net.Documents; using umbraco.businesslogic; +using umbraco.interfaces; namespace umbraco.presentation.umbraco.Search { /// /// Used to wire up events for Examine /// - public class ExamineEvents : ApplicationStartupHandler + public class ExamineEvents : IApplicationStartupHandler { public ExamineEvents() diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProvider.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProvider.cs index f639525ea4..221ee75c27 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProvider.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProvider.cs @@ -10,8 +10,6 @@ using System.Security.Cryptography; using System.Web.Util; using System.Collections.Specialized; using System.Configuration.Provider; -using umbraco.businesslogic; -using umbraco.cms.businesslogic; using System.Collections; #endregion @@ -205,35 +203,4 @@ namespace umbraco.presentation.nodeFactory { return m_nodes[id]; } } - - public class UmbracoSiteMapProviderAccessUpdate : ApplicationStartupHandler - { - public UmbracoSiteMapProviderAccessUpdate() - { - // Add events to security - if (System.Web.SiteMap.Provider is UmbracoSiteMapProvider) - { - cms.businesslogic.web.Access.AfterAddMemberShipRoleToDocument += new global::umbraco.cms.businesslogic.web.Access.AddMemberShipRoleToDocumentEventHandler(Access_AfterAddMemberShipRoleToDocument); - cms.businesslogic.web.Access.AfterRemoveMemberShipRoleToDocument += new global::umbraco.cms.businesslogic.web.Access.RemoveMemberShipRoleFromDocumentEventHandler(Access_AfterRemoveMemberShipRoleToDocument); - cms.businesslogic.web.Access.AfterRemoveProtection += new global::umbraco.cms.businesslogic.web.Access.RemoveProtectionEventHandler(Access_AfterRemoveProtection); - } - - } - - void Access_AfterRemoveProtection(global::umbraco.cms.businesslogic.web.Document sender, RemoveProtectionEventArgs e) - { - ((UmbracoSiteMapProvider)System.Web.SiteMap.Provider).UpdateNode(new NodeFactory.Node(sender.Id)); - } - - - void Access_AfterRemoveMemberShipRoleToDocument(global::umbraco.cms.businesslogic.web.Document sender, string role, RemoveMemberShipRoleFromDocumentEventArgs e) - { - ((UmbracoSiteMapProvider)System.Web.SiteMap.Provider).UpdateNode(new NodeFactory.Node(sender.Id)); - } - - void Access_AfterAddMemberShipRoleToDocument(global::umbraco.cms.businesslogic.web.Document sender, string role, AddMemberShipRoleToDocumentEventArgs e) - { - ((UmbracoSiteMapProvider)System.Web.SiteMap.Provider).UpdateNode(new NodeFactory.Node(sender.Id)); - } - } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProviderAccessUpdate.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProviderAccessUpdate.cs new file mode 100644 index 0000000000..338ed6b74c --- /dev/null +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/nodeFactory/UmbracoSiteMapProviderAccessUpdate.cs @@ -0,0 +1,37 @@ +using umbraco.businesslogic; +using umbraco.cms.businesslogic; +using umbraco.interfaces; + +namespace umbraco.presentation.nodeFactory +{ + public class UmbracoSiteMapProviderAccessUpdate : IApplicationStartupHandler + { + public UmbracoSiteMapProviderAccessUpdate() + { + // Add events to security + if (System.Web.SiteMap.Provider is UmbracoSiteMapProvider) + { + cms.businesslogic.web.Access.AfterAddMemberShipRoleToDocument += new global::umbraco.cms.businesslogic.web.Access.AddMemberShipRoleToDocumentEventHandler(Access_AfterAddMemberShipRoleToDocument); + cms.businesslogic.web.Access.AfterRemoveMemberShipRoleToDocument += new global::umbraco.cms.businesslogic.web.Access.RemoveMemberShipRoleFromDocumentEventHandler(Access_AfterRemoveMemberShipRoleToDocument); + cms.businesslogic.web.Access.AfterRemoveProtection += new global::umbraco.cms.businesslogic.web.Access.RemoveProtectionEventHandler(Access_AfterRemoveProtection); + } + + } + + void Access_AfterRemoveProtection(global::umbraco.cms.businesslogic.web.Document sender, RemoveProtectionEventArgs e) + { + ((UmbracoSiteMapProvider)System.Web.SiteMap.Provider).UpdateNode(new NodeFactory.Node(sender.Id)); + } + + + void Access_AfterRemoveMemberShipRoleToDocument(global::umbraco.cms.businesslogic.web.Document sender, string role, RemoveMemberShipRoleFromDocumentEventArgs e) + { + ((UmbracoSiteMapProvider)System.Web.SiteMap.Provider).UpdateNode(new NodeFactory.Node(sender.Id)); + } + + void Access_AfterAddMemberShipRoleToDocument(global::umbraco.cms.businesslogic.web.Document sender, string role, AddMemberShipRoleToDocumentEventArgs e) + { + ((UmbracoSiteMapProvider)System.Web.SiteMap.Provider).UpdateNode(new NodeFactory.Node(sender.Id)); + } + } +} \ No newline at end of file diff --git a/src/umbraco.businesslogic/ApplicationBase.cs b/src/umbraco.businesslogic/ApplicationBase.cs index 12628ebb15..9678db5fc2 100644 --- a/src/umbraco.businesslogic/ApplicationBase.cs +++ b/src/umbraco.businesslogic/ApplicationBase.cs @@ -14,7 +14,7 @@ namespace umbraco.BusinessLogic /// To use, inhirite the ApplicationBase Class and add an empty constructor. /// [Obsolete("ApplicationBase has been depricated. Please use ApplicationStartupHandler instead.")] - public abstract class ApplicationBase : ApplicationStartupHandler + public abstract class ApplicationBase : IApplicationStartupHandler { } } diff --git a/src/umbraco.businesslogic/ApplicationRegistrar.cs b/src/umbraco.businesslogic/ApplicationRegistrar.cs index db1921ec0c..d29d50d90f 100644 --- a/src/umbraco.businesslogic/ApplicationRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationRegistrar.cs @@ -8,7 +8,7 @@ using umbraco.interfaces; namespace umbraco.BusinessLogic { - public class ApplicationRegistrar : ApplicationStartupHandler + public class ApplicationRegistrar : IApplicationStartupHandler { private ISqlHelper _sqlHelper; protected ISqlHelper SqlHelper diff --git a/src/umbraco.businesslogic/ApplicationStartupHandler.cs b/src/umbraco.businesslogic/ApplicationStartupHandler.cs index 62590219c3..0e805a45fd 100644 --- a/src/umbraco.businesslogic/ApplicationStartupHandler.cs +++ b/src/umbraco.businesslogic/ApplicationStartupHandler.cs @@ -17,9 +17,11 @@ namespace umbraco.businesslogic /// Class inhiriting from ApplicationStartupHandler are automaticly registered and instantiated by umbraco on application start. /// To use, inhirite the ApplicationStartupHandler Class and add an empty constructor. /// + [Obsolete("This class is no longer used, implement IApplicationEvents instead")] public abstract class ApplicationStartupHandler : IApplicationStartupHandler { + [Obsolete("This method is no longer used, use the Umbraco.Web.ApplicationEventsResolver to create the handlers")] public static void RegisterHandlers() { if (ApplicationContext.Current == null || !ApplicationContext.Current.IsConfigured) diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs index 6eb4c2244b..70f709c84f 100644 --- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs @@ -9,7 +9,7 @@ using umbraco.interfaces; namespace umbraco.BusinessLogic { - public class ApplicationTreeRegistrar : ApplicationStartupHandler + public class ApplicationTreeRegistrar : IApplicationStartupHandler { private ISqlHelper _sqlHelper; protected ISqlHelper SqlHelper diff --git a/src/umbraco.businesslogic/Properties/AssemblyInfo.cs b/src/umbraco.businesslogic/Properties/AssemblyInfo.cs index f34d599fba..b55e9ce622 100644 --- a/src/umbraco.businesslogic/Properties/AssemblyInfo.cs +++ b/src/umbraco.businesslogic/Properties/AssemblyInfo.cs @@ -17,4 +17,5 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("umbraco")] [assembly: InternalsVisibleTo("Umbraco.LegacyTests")] \ No newline at end of file diff --git a/src/umbraco.interfaces/IApplicationStartupHandler.cs b/src/umbraco.interfaces/IApplicationStartupHandler.cs index b526499a7d..a442f9b100 100644 --- a/src/umbraco.interfaces/IApplicationStartupHandler.cs +++ b/src/umbraco.interfaces/IApplicationStartupHandler.cs @@ -5,6 +5,6 @@ using System.Text; namespace umbraco.interfaces { - public interface IApplicationStartupHandler + public interface IApplicationStartupHandler { } } diff --git a/src/umbraco.interfaces/umbraco.interfaces.csproj b/src/umbraco.interfaces/umbraco.interfaces.csproj index 9a1b91c301..8548c44273 100644 --- a/src/umbraco.interfaces/umbraco.interfaces.csproj +++ b/src/umbraco.interfaces/umbraco.interfaces.csproj @@ -122,6 +122,7 @@ Properties\SolutionInfo.cs + @@ -132,7 +133,6 @@ Code - Code