diff --git a/src/Umbraco.Core/Events/EventDefinitionBase.cs b/src/Umbraco.Core/Events/EventDefinitionBase.cs
index 46e57306a5..bb107ea09c 100644
--- a/src/Umbraco.Core/Events/EventDefinitionBase.cs
+++ b/src/Umbraco.Core/Events/EventDefinitionBase.cs
@@ -15,7 +15,10 @@ namespace Umbraco.Core.Events
if (EventName.IsNullOrWhiteSpace())
{
- var findResult = EventNameExtractor.FindEvent(sender, args, EventNameExtractor.MatchIngNames);
+ var findResult = EventNameExtractor.FindEvent(sender, args,
+ //don't match "Ing" suffixed names
+ exclude:EventNameExtractor.MatchIngNames);
+
if (findResult.Success == false)
throw new AmbiguousMatchException("Could not automatically find the event name, the event name will need to be explicitly registered for this event definition. Error: " + findResult.Result.Error);
EventName = findResult.Result.Name;
diff --git a/src/Umbraco.Core/Events/EventNameExtractor.cs b/src/Umbraco.Core/Events/EventNameExtractor.cs
index 3630763405..33137770d4 100644
--- a/src/Umbraco.Core/Events/EventNameExtractor.cs
+++ b/src/Umbraco.Core/Events/EventNameExtractor.cs
@@ -22,23 +22,20 @@ namespace Umbraco.Core.Events
///
internal class EventNameExtractor
{
+
///
/// Finds the event name on the sender that matches the args type
///
- ///
- ///
+ ///
+ ///
///
/// A filter to exclude matched event names, this filter should return true to exclude the event name from being matched
///
///
/// null if not found or an ambiguous match
///
- public static Attempt FindEvent(object sender, object args, Func exclude)
- {
- var argsType = args.GetType();
-
- var senderType = sender.GetType();
-
+ public static Attempt FindEvent(Type senderType, Type argsType, Func exclude)
+ {
var found = MatchedEventNames.GetOrAdd(new Tuple(senderType, argsType), tuple =>
{
var events = CandidateEvents.GetOrAdd(senderType, t =>
@@ -70,14 +67,14 @@ namespace Umbraco.Core.Events
return true;
//special case for our own TypedEventHandler
- if (x.EventInfo.EventHandlerType.GetGenericTypeDefinition() == typeof(TypedEventHandler<,>)
+ if (x.EventInfo.EventHandlerType.GetGenericTypeDefinition() == typeof(TypedEventHandler<,>)
&& x.GenericArgs.Length == 2
&& x.GenericArgs[1] == tuple.Item2)
{
return true;
}
- return false;
+ return false;
}).Select(x => x.EventInfo.Name).ToArray();
});
@@ -93,6 +90,22 @@ namespace Umbraco.Core.Events
return Attempt.Fail(new EventNameExtractorResult(EventNameExtractorError.Ambiguous));
}
+ ///
+ /// Finds the event name on the sender that matches the args type
+ ///
+ ///
+ ///
+ ///
+ /// A filter to exclude matched event names, this filter should return true to exclude the event name from being matched
+ ///
+ ///
+ /// null if not found or an ambiguous match
+ ///
+ public static Attempt FindEvent(object sender, object args, Func exclude)
+ {
+ return FindEvent(sender.GetType(), args.GetType(), exclude);
+ }
+
///
/// Return true if the event is named with an ING name such as "Saving" or "RollingBack"
///
diff --git a/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs b/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs
new file mode 100644
index 0000000000..3aa1db675f
--- /dev/null
+++ b/src/Umbraco.Tests/Cache/CacheRefresherEventHandlerTests.cs
@@ -0,0 +1,108 @@
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using Umbraco.Core.Events;
+using Umbraco.Core.Models;
+using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Services;
+using Umbraco.Tests.TestHelpers;
+using Umbraco.Web.Cache;
+
+namespace Umbraco.Tests.Cache
+{
+ [TestFixture]
+ public class CacheRefresherEventHandlerTests : BaseUmbracoApplicationTest
+ {
+ [Test]
+ public void Can_Find_All_Event_Handlers()
+ {
+ var definitions = new IEventDefinition[]
+ {
+ //I would test these but they are legacy events and we don't need them for deploy, when we migrate to new/better events we can wire up the check
+ //Permission.New += PermissionNew;
+ //Permission.Updated += PermissionUpdated;
+ //Permission.Deleted += PermissionDeleted;
+ //PermissionRepository.AssignedPermissions += CacheRefresherEventHandler_AssignedPermissions;
+
+ new EventDefinition(null, ServiceContext.ApplicationTreeService, new EventArgs(), "Deleted"),
+ new EventDefinition(null, ServiceContext.ApplicationTreeService, new EventArgs(), "Updated"),
+ new EventDefinition(null, ServiceContext.ApplicationTreeService, new EventArgs(), "New"),
+
+ new EventDefinition(null, ServiceContext.SectionService, new EventArgs(), "Deleted"),
+ new EventDefinition(null, ServiceContext.SectionService, new EventArgs(), "New"),
+
+ new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs((IUserType) null)),
+ new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs((IUserType) null)),
+
+ new EventDefinition>(null, ServiceContext.UserService, new SaveEventArgs((IUser) null)),
+ new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs((IUser) null)),
+ new EventDefinition>(null, ServiceContext.UserService, new DeleteEventArgs((IUser) null)),
+
+ new EventDefinition>(null, ServiceContext.LocalizationService, new SaveEventArgs((IDictionaryItem) null)),
+ new EventDefinition>(null, ServiceContext.LocalizationService, new DeleteEventArgs((IDictionaryItem) null)),
+
+ new EventDefinition>(null, ServiceContext.DataTypeService, new SaveEventArgs((IDataTypeDefinition) null)),
+ new EventDefinition>(null, ServiceContext.DataTypeService, new DeleteEventArgs((IDataTypeDefinition) null)),
+
+ new EventDefinition>(null, ServiceContext.FileService, new SaveEventArgs((Stylesheet) null)),
+ new EventDefinition>(null, ServiceContext.FileService, new DeleteEventArgs((Stylesheet) null)),
+
+ new EventDefinition>(null, ServiceContext.DomainService, new SaveEventArgs((IDomain) null)),
+ new EventDefinition>(null, ServiceContext.DomainService, new DeleteEventArgs((IDomain) null)),
+
+ new EventDefinition>(null, ServiceContext.LocalizationService, new SaveEventArgs((ILanguage) null)),
+ new EventDefinition>(null, ServiceContext.LocalizationService, new DeleteEventArgs((ILanguage) null)),
+
+ new EventDefinition>(null, ServiceContext.ContentTypeService, new SaveEventArgs((IContentType) null)),
+ new EventDefinition>(null, ServiceContext.ContentTypeService, new DeleteEventArgs((IContentType) null)),
+ new EventDefinition>(null, ServiceContext.ContentTypeService, new SaveEventArgs((IMediaType) null)),
+ new EventDefinition>(null, ServiceContext.ContentTypeService, new DeleteEventArgs((IMediaType) null)),
+
+ new EventDefinition>(null, ServiceContext.MemberTypeService, new SaveEventArgs((IMemberType) null)),
+ new EventDefinition>(null, ServiceContext.MemberTypeService, new DeleteEventArgs((IMemberType) null)),
+
+ new EventDefinition>(null, ServiceContext.FileService, new SaveEventArgs((ITemplate) null)),
+ new EventDefinition>(null, ServiceContext.FileService, new DeleteEventArgs((ITemplate) null)),
+
+ new EventDefinition>(null, ServiceContext.MacroService, new SaveEventArgs((IMacro) null)),
+ new EventDefinition>(null, ServiceContext.MacroService, new DeleteEventArgs((IMacro) null)),
+
+ new EventDefinition>(null, ServiceContext.MemberService, new SaveEventArgs((IMember) null)),
+ new EventDefinition>(null, ServiceContext.MemberService, new DeleteEventArgs((IMember) null)),
+
+ new EventDefinition>(null, ServiceContext.MemberGroupService, new SaveEventArgs((IMemberGroup) null)),
+ new EventDefinition>(null, ServiceContext.MemberGroupService, new DeleteEventArgs((IMemberGroup) null)),
+
+ new EventDefinition>(null, ServiceContext.MediaService, new SaveEventArgs((IMedia) null)),
+ new EventDefinition>(null, ServiceContext.MediaService, new DeleteEventArgs((IMedia) null)),
+ new EventDefinition>(null, ServiceContext.MediaService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Moved"),
+ new EventDefinition>(null, ServiceContext.MediaService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Trashed"),
+ new EventDefinition(null, ServiceContext.MediaService, new RecycleBinEventArgs(Guid.NewGuid(), new Dictionary>(), true)),
+
+ new EventDefinition>(null, ServiceContext.ContentService, new SaveEventArgs((IContent) null)),
+ new EventDefinition>(null, ServiceContext.ContentService, new DeleteEventArgs((IContent) null)),
+ new EventDefinition>(null, ServiceContext.ContentService, new CopyEventArgs(null, null, -1)),
+ new EventDefinition>(null, ServiceContext.ContentService, new MoveEventArgs(new MoveEventInfo(null, "", -1)), "Trashed"),
+ new EventDefinition(null, ServiceContext.ContentService, new RecycleBinEventArgs(Guid.NewGuid(), new Dictionary>(), true)),
+ new EventDefinition>(null, ServiceContext.ContentService, new PublishEventArgs((IContent) null), "Published"),
+ new EventDefinition>(null, ServiceContext.ContentService, new PublishEventArgs((IContent) null), "UnPublished"),
+
+ new EventDefinition>(null, ServiceContext.PublicAccessService, new SaveEventArgs((PublicAccessEntry) null)),
+ new EventDefinition>(null, ServiceContext.PublicAccessService, new DeleteEventArgs((PublicAccessEntry) null)),
+
+ new EventDefinition>(null, ServiceContext.RelationService, new SaveEventArgs((IRelationType) null)),
+ new EventDefinition>(null, ServiceContext.RelationService, new DeleteEventArgs((IRelationType) null)),
+
+ new EventDefinition>(null, ServiceContext.RelationService, new SaveEventArgs((IRelationType) null)),
+ new EventDefinition>(null, ServiceContext.RelationService, new DeleteEventArgs((IRelationType) null)),
+ };
+
+ foreach (var definition in definitions)
+ {
+ var found = CacheRefresherEventHandler.FindHandler(definition);
+ Assert.IsNotNull(found, "Couldn't find method for " + definition.EventName + " on " + definition.Sender.GetType());
+ }
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs
index 55a7f2a893..2ec175933e 100644
--- a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs
+++ b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Web.Caching;
using Moq;
using NUnit.Framework;
+using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs
index 57595578da..70f48b12fb 100644
--- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs
+++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs
@@ -352,12 +352,7 @@ namespace Umbraco.Tests.TestHelpers
onFail(ex);
}
}
-
- protected ServiceContext ServiceContext
- {
- get { return ApplicationContext.Services; }
- }
-
+
protected DatabaseContext DatabaseContext
{
get { return ApplicationContext.DatabaseContext; }
diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs
index 98f7b36e81..43b6171b94 100644
--- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs
+++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs
@@ -208,6 +208,11 @@ namespace Umbraco.Tests.TestHelpers
Resolution.Freeze();
}
+ protected ServiceContext ServiceContext
+ {
+ get { return ApplicationContext.Services; }
+ }
+
protected ApplicationContext ApplicationContext
{
get { return ApplicationContext.Current; }
diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj
index 10810b0a1f..46c8387de8 100644
--- a/src/Umbraco.Tests/Umbraco.Tests.csproj
+++ b/src/Umbraco.Tests/Umbraco.Tests.csproj
@@ -156,6 +156,7 @@
+
diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs
index 23e064ed9c..59084f13c4 100644
--- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs
+++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Events;
@@ -9,6 +10,7 @@ using Umbraco.Core.Services;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using System.Linq;
+using System.Reflection;
using Umbraco.Core.Logging;
using Umbraco.Core.ObjectResolution;
using Umbraco.Core.Publishing;
@@ -29,35 +31,35 @@ namespace Umbraco.Web.Cache
LogHelper.Info("Initializing Umbraco internal event handlers for cache refreshing");
//bind to application tree events
- ApplicationTreeService.Deleted += ApplicationTreeDeleted;
- ApplicationTreeService.Updated += ApplicationTreeUpdated;
- ApplicationTreeService.New += ApplicationTreeNew;
+ ApplicationTreeService.Deleted += ApplicationTreeService_Deleted;
+ ApplicationTreeService.Updated += ApplicationTreeService_Updated;
+ ApplicationTreeService.New += ApplicationTreeService_New;
//bind to application events
- SectionService.Deleted += ApplicationDeleted;
- SectionService.New += ApplicationNew;
+ SectionService.Deleted += SectionService_Deleted;
+ SectionService.New += SectionService_New;
//bind to user / user type events
- UserService.SavedUserType += UserServiceSavedUserType;
- UserService.DeletedUserType += UserServiceDeletedUserType;
- UserService.SavedUser += UserServiceSavedUser;
- UserService.DeletedUser += UserServiceDeletedUser;
+ UserService.SavedUserType += UserService_SavedUserType;
+ UserService.DeletedUserType += UserService_DeletedUserType;
+ UserService.SavedUser += UserService_SavedUser;
+ UserService.DeletedUser += UserService_DeletedUser;
//Bind to dictionary events
- LocalizationService.DeletedDictionaryItem += LocalizationServiceDeletedDictionaryItem;
- LocalizationService.SavedDictionaryItem += LocalizationServiceSavedDictionaryItem;
+ LocalizationService.DeletedDictionaryItem += LocalizationService_DeletedDictionaryItem;
+ LocalizationService.SavedDictionaryItem += LocalizationService_SavedDictionaryItem;
//Bind to data type events
//NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979
- DataTypeService.Deleted += DataTypeServiceDeleted;
- DataTypeService.Saved += DataTypeServiceSaved;
+ DataTypeService.Deleted += DataTypeService_Deleted;
+ DataTypeService.Saved += DataTypeService_Saved;
//Bind to stylesheet events
- FileService.SavedStylesheet += FileServiceSavedStylesheet;
- FileService.DeletedStylesheet += FileServiceDeletedStylesheet;
+ FileService.SavedStylesheet += FileService_SavedStylesheet;
+ FileService.DeletedStylesheet += FileService_DeletedStylesheet;
//Bind to domain events
@@ -66,17 +68,17 @@ namespace Umbraco.Web.Cache
//Bind to language events
- LocalizationService.SavedLanguage += LocalizationServiceSavedLanguage;
- LocalizationService.DeletedLanguage += LocalizationServiceDeletedLanguage;
+ LocalizationService.SavedLanguage += LocalizationService_SavedLanguage;
+ LocalizationService.DeletedLanguage += LocalizationService_DeletedLanguage;
//Bind to content type events
- ContentTypeService.SavedContentType += ContentTypeServiceSavedContentType;
- ContentTypeService.SavedMediaType += ContentTypeServiceSavedMediaType;
- ContentTypeService.DeletedContentType += ContentTypeServiceDeletedContentType;
- ContentTypeService.DeletedMediaType += ContentTypeServiceDeletedMediaType;
- MemberTypeService.Saved += MemberTypeServiceSaved;
- MemberTypeService.Deleted += MemberTypeServiceDeleted;
+ ContentTypeService.SavedContentType += ContentTypeService_SavedContentType;
+ ContentTypeService.SavedMediaType += ContentTypeService_SavedMediaType;
+ ContentTypeService.DeletedContentType += ContentTypeService_DeletedContentType;
+ ContentTypeService.DeletedMediaType += ContentTypeService_DeletedMediaType;
+ MemberTypeService.Saved += MemberTypeService_Saved;
+ MemberTypeService.Deleted += MemberTypeService_Deleted;
//Bind to permission events
@@ -88,83 +90,83 @@ namespace Umbraco.Web.Cache
//Bind to template events
- FileService.SavedTemplate += FileServiceSavedTemplate;
- FileService.DeletedTemplate += FileServiceDeletedTemplate;
+ FileService.SavedTemplate += FileService_SavedTemplate;
+ FileService.DeletedTemplate += FileService_DeletedTemplate;
//Bind to macro events
- MacroService.Saved += MacroServiceSaved;
- MacroService.Deleted += MacroServiceDeleted;
+ MacroService.Saved += MacroService_Saved;
+ MacroService.Deleted += MacroService_Deleted;
//Bind to member events
- MemberService.Saved += MemberServiceSaved;
- MemberService.Deleted += MemberServiceDeleted;
+ MemberService.Saved += MemberService_Saved;
+ MemberService.Deleted += MemberService_Deleted;
MemberGroupService.Saved += MemberGroupService_Saved;
MemberGroupService.Deleted += MemberGroupService_Deleted;
//Bind to media events
- MediaService.Saved += MediaServiceSaved;
- MediaService.Deleted += MediaServiceDeleted;
- MediaService.Moved += MediaServiceMoved;
- MediaService.Trashed += MediaServiceTrashed;
- MediaService.EmptiedRecycleBin += MediaServiceEmptiedRecycleBin;
+ MediaService.Saved += MediaService_Saved;
+ MediaService.Deleted += MediaService_Deleted;
+ MediaService.Moved += MediaService_Moved;
+ MediaService.Trashed += MediaService_Trashed;
+ MediaService.EmptiedRecycleBin += MediaService_EmptiedRecycleBin;
//Bind to content events - this is for unpublished content syncing across servers (primarily for examine)
- ContentService.Saved += ContentServiceSaved;
- ContentService.Deleted += ContentServiceDeleted;
- ContentService.Copied += ContentServiceCopied;
+ ContentService.Saved += ContentService_Saved;
+ ContentService.Deleted += ContentService_Deleted;
+ ContentService.Copied += ContentService_Copied;
//TODO: The Move method of the content service fires Saved/Published events during its execution so we don't need to listen to moved
//ContentService.Moved += ContentServiceMoved;
- ContentService.Trashed += ContentServiceTrashed;
- ContentService.EmptiedRecycleBin += ContentServiceEmptiedRecycleBin;
+ ContentService.Trashed += ContentService_Trashed;
+ ContentService.EmptiedRecycleBin += ContentService_EmptiedRecycleBin;
- PublishingStrategy.Published += PublishingStrategy_Published;
- PublishingStrategy.UnPublished += PublishingStrategy_UnPublished;
+ ContentService.Published += ContentService_Published;
+ ContentService.UnPublished += ContentService_UnPublished;
//public access events
PublicAccessService.Saved += PublicAccessService_Saved;
PublicAccessService.Deleted += PublicAccessService_Deleted;
- RelationService.SavedRelationType += RelationType_Saved;
- RelationService.DeletedRelationType += RelationType_Deleted;
+ RelationService.SavedRelationType += RelationService_SavedRelationType;
+ RelationService.DeletedRelationType += RelationService_DeletedRelationType;
}
// for tests
internal void Destroy()
{
//bind to application tree events
- ApplicationTreeService.Deleted -= ApplicationTreeDeleted;
- ApplicationTreeService.Updated -= ApplicationTreeUpdated;
- ApplicationTreeService.New -= ApplicationTreeNew;
+ ApplicationTreeService.Deleted -= ApplicationTreeService_Deleted;
+ ApplicationTreeService.Updated -= ApplicationTreeService_Updated;
+ ApplicationTreeService.New -= ApplicationTreeService_New;
//bind to application events
- SectionService.Deleted -= ApplicationDeleted;
- SectionService.New -= ApplicationNew;
+ SectionService.Deleted -= SectionService_Deleted;
+ SectionService.New -= SectionService_New;
//bind to user / user type events
- UserService.SavedUserType -= UserServiceSavedUserType;
- UserService.DeletedUserType -= UserServiceDeletedUserType;
- UserService.SavedUser -= UserServiceSavedUser;
- UserService.DeletedUser -= UserServiceDeletedUser;
+ UserService.SavedUserType -= UserService_SavedUserType;
+ UserService.DeletedUserType -= UserService_DeletedUserType;
+ UserService.SavedUser -= UserService_SavedUser;
+ UserService.DeletedUser -= UserService_DeletedUser;
//Bind to dictionary events
- LocalizationService.DeletedDictionaryItem -= LocalizationServiceDeletedDictionaryItem;
- LocalizationService.SavedDictionaryItem -= LocalizationServiceSavedDictionaryItem;
+ LocalizationService.DeletedDictionaryItem -= LocalizationService_DeletedDictionaryItem;
+ LocalizationService.SavedDictionaryItem -= LocalizationService_SavedDictionaryItem;
//Bind to data type events
//NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979
- DataTypeService.Deleted -= DataTypeServiceDeleted;
- DataTypeService.Saved -= DataTypeServiceSaved;
+ DataTypeService.Deleted -= DataTypeService_Deleted;
+ DataTypeService.Saved -= DataTypeService_Saved;
//Bind to stylesheet events
- FileService.SavedStylesheet -= FileServiceSavedStylesheet;
- FileService.DeletedStylesheet -= FileServiceDeletedStylesheet;
+ FileService.SavedStylesheet -= FileService_SavedStylesheet;
+ FileService.DeletedStylesheet -= FileService_DeletedStylesheet;
//Bind to domain events
@@ -173,17 +175,17 @@ namespace Umbraco.Web.Cache
//Bind to language events
- LocalizationService.SavedLanguage -= LocalizationServiceSavedLanguage;
- LocalizationService.DeletedLanguage -= LocalizationServiceDeletedLanguage;
+ LocalizationService.SavedLanguage -= LocalizationService_SavedLanguage;
+ LocalizationService.DeletedLanguage -= LocalizationService_DeletedLanguage;
//Bind to content type events
- ContentTypeService.SavedContentType -= ContentTypeServiceSavedContentType;
- ContentTypeService.SavedMediaType -= ContentTypeServiceSavedMediaType;
- ContentTypeService.DeletedContentType -= ContentTypeServiceDeletedContentType;
- ContentTypeService.DeletedMediaType -= ContentTypeServiceDeletedMediaType;
- MemberTypeService.Saved -= MemberTypeServiceSaved;
- MemberTypeService.Deleted -= MemberTypeServiceDeleted;
+ ContentTypeService.SavedContentType -= ContentTypeService_SavedContentType;
+ ContentTypeService.SavedMediaType -= ContentTypeService_SavedMediaType;
+ ContentTypeService.DeletedContentType -= ContentTypeService_DeletedContentType;
+ ContentTypeService.DeletedMediaType -= ContentTypeService_DeletedMediaType;
+ MemberTypeService.Saved -= MemberTypeService_Saved;
+ MemberTypeService.Deleted -= MemberTypeService_Deleted;
//Bind to permission events
@@ -195,53 +197,53 @@ namespace Umbraco.Web.Cache
//Bind to template events
- FileService.SavedTemplate -= FileServiceSavedTemplate;
- FileService.DeletedTemplate -= FileServiceDeletedTemplate;
+ FileService.SavedTemplate -= FileService_SavedTemplate;
+ FileService.DeletedTemplate -= FileService_DeletedTemplate;
//Bind to macro events
- MacroService.Saved -= MacroServiceSaved;
- MacroService.Deleted -= MacroServiceDeleted;
+ MacroService.Saved -= MacroService_Saved;
+ MacroService.Deleted -= MacroService_Deleted;
//Bind to member events
- MemberService.Saved -= MemberServiceSaved;
- MemberService.Deleted -= MemberServiceDeleted;
+ MemberService.Saved -= MemberService_Saved;
+ MemberService.Deleted -= MemberService_Deleted;
MemberGroupService.Saved -= MemberGroupService_Saved;
MemberGroupService.Deleted -= MemberGroupService_Deleted;
//Bind to media events
- MediaService.Saved -= MediaServiceSaved;
- MediaService.Deleted -= MediaServiceDeleted;
- MediaService.Moved -= MediaServiceMoved;
- MediaService.Trashed -= MediaServiceTrashed;
- MediaService.EmptiedRecycleBin -= MediaServiceEmptiedRecycleBin;
+ MediaService.Saved -= MediaService_Saved;
+ MediaService.Deleted -= MediaService_Deleted;
+ MediaService.Moved -= MediaService_Moved;
+ MediaService.Trashed -= MediaService_Trashed;
+ MediaService.EmptiedRecycleBin -= MediaService_EmptiedRecycleBin;
//Bind to content events - this is for unpublished content syncing across servers (primarily for examine)
- ContentService.Saved -= ContentServiceSaved;
- ContentService.Deleted -= ContentServiceDeleted;
- ContentService.Copied -= ContentServiceCopied;
+ ContentService.Saved -= ContentService_Saved;
+ ContentService.Deleted -= ContentService_Deleted;
+ ContentService.Copied -= ContentService_Copied;
//TODO: The Move method of the content service fires Saved/Published events during its execution so we don't need to listen to moved
//ContentService.Moved -= ContentServiceMoved;
- ContentService.Trashed -= ContentServiceTrashed;
- ContentService.EmptiedRecycleBin -= ContentServiceEmptiedRecycleBin;
+ ContentService.Trashed -= ContentService_Trashed;
+ ContentService.EmptiedRecycleBin -= ContentService_EmptiedRecycleBin;
- PublishingStrategy.Published -= PublishingStrategy_Published;
- PublishingStrategy.UnPublished -= PublishingStrategy_UnPublished;
+ ContentService.Published -= ContentService_Published;
+ ContentService.UnPublished -= ContentService_UnPublished;
//public access events
PublicAccessService.Saved -= PublicAccessService_Saved;
PublicAccessService.Deleted -= PublicAccessService_Deleted;
- RelationService.SavedRelationType -= RelationType_Saved;
- RelationService.DeletedRelationType -= RelationType_Deleted;
+ RelationService.SavedRelationType -= RelationService_SavedRelationType;
+ RelationService.DeletedRelationType -= RelationService_DeletedRelationType;
}
#region Publishing
- void PublishingStrategy_UnPublished(IPublishingStrategy sender, PublishEventArgs e)
+ static void ContentService_UnPublished(IPublishingStrategy sender, PublishEventArgs e)
{
if (e.PublishedEntities.Any())
{
@@ -263,12 +265,12 @@ namespace Umbraco.Web.Cache
///
/// Refreshes the xml cache for a single node by removing it
///
- private void UnPublishSingle(IContent content)
+ private static void UnPublishSingle(IContent content)
{
DistributedCache.Instance.RemovePageCache(content);
}
- void PublishingStrategy_Published(IPublishingStrategy sender, PublishEventArgs e)
+ static void ContentService_Published(IPublishingStrategy sender, PublishEventArgs e)
{
if (e.PublishedEntities.Any())
{
@@ -293,7 +295,7 @@ namespace Umbraco.Web.Cache
///
/// Refreshes the xml cache for all nodes
///
- private void UpdateEntireCache()
+ private static void UpdateEntireCache()
{
DistributedCache.Instance.RefreshAllPageCache();
}
@@ -301,7 +303,7 @@ namespace Umbraco.Web.Cache
///
/// Refreshes the xml cache for nodes in list
///
- private void UpdateMultipleContentCache(IEnumerable content)
+ private static void UpdateMultipleContentCache(IEnumerable content)
{
DistributedCache.Instance.RefreshPageCache(content.ToArray());
}
@@ -309,7 +311,7 @@ namespace Umbraco.Web.Cache
///
/// Refreshes the xml cache for a single node
///
- private void UpdateSingleContentCache(IContent content)
+ private static void UpdateSingleContentCache(IContent content)
{
DistributedCache.Instance.RefreshPageCache(content);
}
@@ -323,7 +325,7 @@ namespace Umbraco.Web.Cache
DistributedCache.Instance.RefreshPublicAccess();
}
- private void PublicAccessService_Deleted(IPublicAccessService sender, DeleteEventArgs e)
+ static void PublicAccessService_Deleted(IPublicAccessService sender, DeleteEventArgs e)
{
DistributedCache.Instance.RefreshPublicAccess();
}
@@ -332,7 +334,7 @@ namespace Umbraco.Web.Cache
#region Content service event handlers
- static void ContentServiceEmptiedRecycleBin(IContentService sender, RecycleBinEventArgs e)
+ static void ContentService_EmptiedRecycleBin(IContentService sender, RecycleBinEventArgs e)
{
if (e.RecycleBinEmptiedSuccessfully && e.IsContentRecycleBin)
{
@@ -349,7 +351,7 @@ namespace Umbraco.Web.Cache
/// This is for the unpublished page refresher - the entity will be unpublished before being moved to the trash
/// and the unpublished event will take care of remove it from any published caches
///
- static void ContentServiceTrashed(IContentService sender, MoveEventArgs e)
+ static void ContentService_Trashed(IContentService sender, MoveEventArgs e)
{
DistributedCache.Instance.RefreshUnpublishedPageCache(
e.MoveInfoCollection.Select(x => x.Entity).ToArray());
@@ -364,7 +366,7 @@ namespace Umbraco.Web.Cache
/// When an entity is copied new permissions may be assigned to it based on it's parent, if that is the
/// case then we need to clear all user permissions cache.
///
- static void ContentServiceCopied(IContentService sender, CopyEventArgs e)
+ static void ContentService_Copied(IContentService sender, CopyEventArgs e)
{
//check if permissions have changed
var permissionsChanged = ((Content)e.Copy).WasPropertyDirty("PermissionsChanged");
@@ -382,7 +384,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void ContentServiceDeleted(IContentService sender, DeleteEventArgs e)
+ static void ContentService_Deleted(IContentService sender, DeleteEventArgs e)
{
DistributedCache.Instance.RemoveUnpublishedPageCache(e.DeletedEntities.ToArray());
}
@@ -399,7 +401,7 @@ namespace Umbraco.Web.Cache
/// When an entity is created new permissions may be assigned to it based on it's parent, if that is the
/// case then we need to clear all user permissions cache.
///
- static void ContentServiceSaved(IContentService sender, SaveEventArgs e)
+ static void ContentService_Saved(IContentService sender, SaveEventArgs e)
{
var clearUserPermissions = false;
e.SavedEntities.ForEach(x =>
@@ -432,41 +434,41 @@ namespace Umbraco.Web.Cache
#endregion
#region ApplicationTree event handlers
- static void ApplicationTreeNew(ApplicationTree sender, EventArgs e)
+ static void ApplicationTreeService_New(ApplicationTree sender, EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationTreeCache();
}
- static void ApplicationTreeUpdated(ApplicationTree sender, EventArgs e)
+ static void ApplicationTreeService_Updated(ApplicationTree sender, EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationTreeCache();
}
- static void ApplicationTreeDeleted(ApplicationTree sender, EventArgs e)
+ static void ApplicationTreeService_Deleted(ApplicationTree sender, EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationTreeCache();
}
#endregion
#region Application event handlers
- static void ApplicationNew(Section sender, EventArgs e)
+ static void SectionService_New(Section sender, EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationCache();
}
- static void ApplicationDeleted(Section sender, EventArgs e)
+ static void SectionService_Deleted(Section sender, EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationCache();
}
#endregion
#region UserType event handlers
- static void UserServiceDeletedUserType(IUserService sender, DeleteEventArgs e)
+ static void UserService_DeletedUserType(IUserService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserTypeCache(x.Id));
}
- static void UserServiceSavedUserType(IUserService sender, SaveEventArgs e)
+ static void UserService_SavedUserType(IUserService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserTypeCache(x.Id));
}
@@ -475,12 +477,12 @@ namespace Umbraco.Web.Cache
#region Dictionary event handlers
- static void LocalizationServiceSavedDictionaryItem(ILocalizationService sender, SaveEventArgs e)
+ static void LocalizationService_SavedDictionaryItem(ILocalizationService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshDictionaryCache(x.Id));
}
- static void LocalizationServiceDeletedDictionaryItem(ILocalizationService sender, DeleteEventArgs e)
+ static void LocalizationService_DeletedDictionaryItem(ILocalizationService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveDictionaryCache(x.Id));
}
@@ -488,12 +490,12 @@ namespace Umbraco.Web.Cache
#endregion
#region DataType event handlers
- static void DataTypeServiceSaved(IDataTypeService sender, SaveEventArgs e)
+ static void DataTypeService_Saved(IDataTypeService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshDataTypeCache(x));
}
- static void DataTypeServiceDeleted(IDataTypeService sender, DeleteEventArgs e)
+ static void DataTypeService_Deleted(IDataTypeService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveDataTypeCache(x));
}
@@ -503,12 +505,12 @@ namespace Umbraco.Web.Cache
#region Stylesheet and stylesheet property event handlers
- static void FileServiceDeletedStylesheet(IFileService sender, DeleteEventArgs e)
+ static void FileService_DeletedStylesheet(IFileService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveStylesheetCache(x));
}
- static void FileServiceSavedStylesheet(IFileService sender, SaveEventArgs e)
+ static void FileService_SavedStylesheet(IFileService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshStylesheetCache(x));
}
@@ -535,7 +537,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void LocalizationServiceDeletedLanguage(ILocalizationService sender, DeleteEventArgs e)
+ static void LocalizationService_DeletedLanguage(ILocalizationService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveLanguageCache(x));
}
@@ -545,7 +547,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void LocalizationServiceSavedLanguage(ILocalizationService sender, SaveEventArgs e)
+ static void LocalizationService_SavedLanguage(ILocalizationService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshLanguageCache(x));
}
@@ -558,7 +560,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void ContentTypeServiceDeletedMediaType(IContentTypeService sender, DeleteEventArgs e)
+ static void ContentTypeService_DeletedMediaType(IContentTypeService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveMediaTypeCache(x));
}
@@ -568,7 +570,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void ContentTypeServiceDeletedContentType(IContentTypeService sender, DeleteEventArgs e)
+ static void ContentTypeService_DeletedContentType(IContentTypeService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(contentType => DistributedCache.Instance.RemoveContentTypeCache(contentType));
}
@@ -578,7 +580,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void MemberTypeServiceDeleted(IMemberTypeService sender, DeleteEventArgs e)
+ static void MemberTypeService_Deleted(IMemberTypeService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(contentType => DistributedCache.Instance.RemoveMemberTypeCache(contentType));
}
@@ -588,7 +590,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void ContentTypeServiceSavedMediaType(IContentTypeService sender, SaveEventArgs e)
+ static void ContentTypeService_SavedMediaType(IContentTypeService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshMediaTypeCache(x));
}
@@ -598,7 +600,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void ContentTypeServiceSavedContentType(IContentTypeService sender, SaveEventArgs e)
+ static void ContentTypeService_SavedContentType(IContentTypeService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(contentType => DistributedCache.Instance.RefreshContentTypeCache(contentType));
}
@@ -608,7 +610,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void MemberTypeServiceSaved(IMemberTypeService sender, SaveEventArgs e)
+ static void MemberTypeService_Saved(IMemberTypeService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshMemberTypeCache(x));
}
@@ -617,7 +619,8 @@ namespace Umbraco.Web.Cache
#endregion
#region User/permissions event handlers
-
+
+ //fixme: this isn't named correct
static void CacheRefresherEventHandler_AssignedPermissions(PermissionRepository sender, SaveEventArgs e)
{
var userIds = e.SavedEntities.Select(x => x.UserId).Distinct();
@@ -639,12 +642,12 @@ namespace Umbraco.Web.Cache
InvalidateCacheForPermissionsChange(sender);
}
- static void UserServiceSavedUser(IUserService sender, SaveEventArgs e)
+ static void UserService_SavedUser(IUserService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserCache(x.Id));
}
- static void UserServiceDeletedUser(IUserService sender, DeleteEventArgs e)
+ static void UserService_DeletedUser(IUserService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserCache(x.Id));
}
@@ -674,7 +677,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void FileServiceDeletedTemplate(IFileService sender, DeleteEventArgs e)
+ static void FileService_DeletedTemplate(IFileService sender, DeleteEventArgs e)
{
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveTemplateCache(x.Id));
}
@@ -684,7 +687,7 @@ namespace Umbraco.Web.Cache
///
///
///
- static void FileServiceSavedTemplate(IFileService sender, SaveEventArgs e)
+ static void FileService_SavedTemplate(IFileService sender, SaveEventArgs e)
{
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshTemplateCache(x.Id));
}
@@ -693,7 +696,7 @@ namespace Umbraco.Web.Cache
#region Macro event handlers
- void MacroServiceDeleted(IMacroService sender, DeleteEventArgs e)
+ static void MacroService_Deleted(IMacroService sender, DeleteEventArgs e)
{
foreach (var entity in e.DeletedEntities)
{
@@ -701,7 +704,7 @@ namespace Umbraco.Web.Cache
}
}
- void MacroServiceSaved(IMacroService sender, SaveEventArgs e)
+ static void MacroService_Saved(IMacroService sender, SaveEventArgs e)
{
foreach (var entity in e.SavedEntities)
{
@@ -713,7 +716,7 @@ namespace Umbraco.Web.Cache
#region Media event handlers
- static void MediaServiceEmptiedRecycleBin(IMediaService sender, RecycleBinEventArgs e)
+ static void MediaService_EmptiedRecycleBin(IMediaService sender, RecycleBinEventArgs e)
{
if (e.RecycleBinEmptiedSuccessfully && e.IsMediaRecycleBin)
{
@@ -721,22 +724,22 @@ namespace Umbraco.Web.Cache
}
}
- static void MediaServiceTrashed(IMediaService sender, MoveEventArgs e)
+ static void MediaService_Trashed(IMediaService sender, MoveEventArgs e)
{
DistributedCache.Instance.RemoveMediaCacheAfterRecycling(e.MoveInfoCollection.ToArray());
}
- static void MediaServiceMoved(IMediaService sender, MoveEventArgs e)
+ static void MediaService_Moved(IMediaService sender, MoveEventArgs e)
{
DistributedCache.Instance.RefreshMediaCacheAfterMoving(e.MoveInfoCollection.ToArray());
}
- static void MediaServiceDeleted(IMediaService sender, DeleteEventArgs e)
+ static void MediaService_Deleted(IMediaService sender, DeleteEventArgs e)
{
DistributedCache.Instance.RemoveMediaCachePermanently(e.DeletedEntities.Select(x => x.Id).ToArray());
}
- static void MediaServiceSaved(IMediaService sender, SaveEventArgs e)
+ static void MediaService_Saved(IMediaService sender, SaveEventArgs e)
{
DistributedCache.Instance.RefreshMediaCache(e.SavedEntities.ToArray());
}
@@ -744,12 +747,12 @@ namespace Umbraco.Web.Cache
#region Member event handlers
- static void MemberServiceDeleted(IMemberService sender, DeleteEventArgs e)
+ static void MemberService_Deleted(IMemberService sender, DeleteEventArgs e)
{
DistributedCache.Instance.RemoveMemberCache(e.DeletedEntities.ToArray());
}
- static void MemberServiceSaved(IMemberService sender, SaveEventArgs e)
+ static void MemberService_Saved(IMemberService sender, SaveEventArgs e)
{
DistributedCache.Instance.RefreshMemberCache(e.SavedEntities.ToArray());
}
@@ -777,14 +780,14 @@ namespace Umbraco.Web.Cache
#region Relation type event handlers
- private static void RelationType_Saved(IRelationService sender, SaveEventArgs args)
+ static void RelationService_SavedRelationType(IRelationService sender, SaveEventArgs args)
{
var dc = DistributedCache.Instance;
foreach (var e in args.SavedEntities)
dc.RefreshRelationTypeCache(e.Id);
}
- private static void RelationType_Deleted(IRelationService sender, DeleteEventArgs args)
+ static void RelationService_DeletedRelationType(IRelationService sender, DeleteEventArgs args)
{
var dc = DistributedCache.Instance;
foreach (var e in args.DeletedEntities)
@@ -792,5 +795,60 @@ namespace Umbraco.Web.Cache
}
#endregion
+
+
+ ///
+ /// This will inspect the event metadata and execute it's affiliated handler if one is found
+ ///
+ ///
+ internal static void HandleEvents(IEnumerable events)
+ {
+ foreach (var e in events)
+ {
+ var handler = FindHandler(e);
+ if (handler == null) continue;
+
+ handler.Invoke(null, new object[] { e.Sender, e.Args });
+ }
+ }
+
+ ///
+ /// Used to cache all candidate handlers
+ ///
+ private static readonly Lazy CandidateHandlers = new Lazy(() =>
+ {
+ var candidates =
+
+ typeof(CacheRefresherEventHandler).GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
+ .Where(x => x.Name.Contains("_"))
+ .Select(x => new
+ {
+ method = x,
+ nameParts = x.Name.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries),
+ methodParams = x.GetParameters()
+ })
+ .Where(x => x.nameParts.Length == 2 && x.methodParams.Length == 2 && typeof(EventArgs).IsAssignableFrom(x.methodParams[1].ParameterType))
+ .Select(x => x.method)
+ .ToArray();
+
+ return candidates;
+ });
+
+ ///
+ /// Used to cache all found event handlers
+ ///
+ private static readonly ConcurrentDictionary FoundHandlers = new ConcurrentDictionary();
+
+ internal static MethodInfo FindHandler(IEventDefinition eventDefinition)
+ {
+ return FoundHandlers.GetOrAdd(eventDefinition, definition =>
+ {
+ var candidates = CandidateHandlers.Value;
+
+ var found = candidates.FirstOrDefault(x => x.Name == string.Format("{0}_{1}", eventDefinition.Sender.GetType().Name, eventDefinition.EventName));
+
+ return found;
+ });
+ }
}
}
\ No newline at end of file