2014-04-23 20:19:36 +10:00
|
|
|
using System;
|
2017-02-06 17:26:06 +11:00
|
|
|
using System.Collections.Concurrent;
|
2015-03-31 17:06:13 +11:00
|
|
|
using System.Collections.Generic;
|
2013-03-16 08:47:55 +06:00
|
|
|
using Umbraco.Core;
|
2014-02-17 17:45:59 +11:00
|
|
|
using Umbraco.Core.Events;
|
2013-03-16 08:47:55 +06:00
|
|
|
using Umbraco.Core.Models;
|
2014-02-17 17:45:59 +11:00
|
|
|
using Umbraco.Core.Models.Membership;
|
|
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
2013-02-06 09:53:13 +06:00
|
|
|
using Umbraco.Core.Services;
|
2013-02-12 04:13:29 +06:00
|
|
|
using umbraco.BusinessLogic;
|
2013-02-06 09:53:13 +06:00
|
|
|
using umbraco.cms.businesslogic;
|
|
|
|
|
using System.Linq;
|
2017-02-06 17:26:06 +11:00
|
|
|
using System.Reflection;
|
2015-07-08 16:54:38 +02:00
|
|
|
using Umbraco.Core.Logging;
|
2016-11-24 17:37:20 +01:00
|
|
|
using Umbraco.Core.ObjectResolution;
|
2015-03-30 17:36:54 +11:00
|
|
|
using Umbraco.Core.Publishing;
|
2013-07-09 11:47:46 +10:00
|
|
|
using Content = Umbraco.Core.Models.Content;
|
2013-07-02 17:47:20 +10:00
|
|
|
using ApplicationTree = Umbraco.Core.Models.ApplicationTree;
|
2014-02-17 17:45:59 +11:00
|
|
|
using DeleteEventArgs = umbraco.cms.businesslogic.DeleteEventArgs;
|
2013-02-06 09:53:13 +06:00
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2013-02-07 04:45:05 +06:00
|
|
|
/// Class which listens to events on business level objects in order to invalidate the cache amongst servers when data changes
|
2013-02-06 09:53:13 +06:00
|
|
|
/// </summary>
|
2016-11-28 09:38:50 +01:00
|
|
|
[Weight(int.MinValue)]
|
2013-02-07 04:45:05 +06:00
|
|
|
public class CacheRefresherEventHandler : ApplicationEventHandler
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
|
|
|
|
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
2015-07-08 16:54:38 +02:00
|
|
|
{
|
|
|
|
|
LogHelper.Info<CacheRefresherEventHandler>("Initializing Umbraco internal event handlers for cache refreshing");
|
|
|
|
|
|
2013-04-04 21:57:41 +06:00
|
|
|
//bind to application tree events
|
2017-02-06 17:26:06 +11:00
|
|
|
ApplicationTreeService.Deleted += ApplicationTreeService_Deleted;
|
|
|
|
|
ApplicationTreeService.Updated += ApplicationTreeService_Updated;
|
|
|
|
|
ApplicationTreeService.New += ApplicationTreeService_New;
|
2013-04-04 21:57:41 +06:00
|
|
|
|
|
|
|
|
//bind to application events
|
2017-02-06 17:26:06 +11:00
|
|
|
SectionService.Deleted += SectionService_Deleted;
|
|
|
|
|
SectionService.New += SectionService_New;
|
2013-04-04 21:57:41 +06:00
|
|
|
|
2014-01-28 12:13:27 +11:00
|
|
|
//bind to user / user type events
|
2017-02-06 17:26:06 +11:00
|
|
|
UserService.SavedUserType += UserService_SavedUserType;
|
|
|
|
|
UserService.DeletedUserType += UserService_DeletedUserType;
|
|
|
|
|
UserService.SavedUser += UserService_SavedUser;
|
|
|
|
|
UserService.DeletedUser += UserService_DeletedUser;
|
2013-03-22 05:04:32 +06:00
|
|
|
|
2013-03-23 01:59:25 +06:00
|
|
|
//Bind to dictionary events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
LocalizationService.DeletedDictionaryItem += LocalizationService_DeletedDictionaryItem;
|
|
|
|
|
LocalizationService.SavedDictionaryItem += LocalizationService_SavedDictionaryItem;
|
2013-03-23 01:59:25 +06:00
|
|
|
|
2013-03-22 05:04:32 +06:00
|
|
|
//Bind to data type events
|
|
|
|
|
//NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979
|
2015-05-18 16:06:22 +10:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
DataTypeService.Deleted += DataTypeService_Deleted;
|
|
|
|
|
DataTypeService.Saved += DataTypeService_Saved;
|
2013-03-22 05:04:32 +06:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
//Bind to stylesheet events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
FileService.SavedStylesheet += FileService_SavedStylesheet;
|
|
|
|
|
FileService.DeletedStylesheet += FileService_DeletedStylesheet;
|
2013-03-16 08:47:55 +06:00
|
|
|
|
2013-03-22 00:49:07 +06:00
|
|
|
//Bind to domain events
|
|
|
|
|
|
2015-01-22 12:17:36 +11:00
|
|
|
DomainService.Saved += DomainService_Saved;
|
|
|
|
|
DomainService.Deleted += DomainService_Deleted;
|
2013-03-22 00:49:07 +06:00
|
|
|
|
2013-03-22 00:35:15 +06:00
|
|
|
//Bind to language events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
LocalizationService.SavedLanguage += LocalizationService_SavedLanguage;
|
|
|
|
|
LocalizationService.DeletedLanguage += LocalizationService_DeletedLanguage;
|
2013-03-22 00:35:15 +06:00
|
|
|
|
2013-03-16 08:47:55 +06:00
|
|
|
//Bind to content type events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentTypeService.SavedContentType += ContentTypeService_SavedContentType;
|
|
|
|
|
ContentTypeService.SavedMediaType += ContentTypeService_SavedMediaType;
|
|
|
|
|
ContentTypeService.DeletedContentType += ContentTypeService_DeletedContentType;
|
|
|
|
|
ContentTypeService.DeletedMediaType += ContentTypeService_DeletedMediaType;
|
|
|
|
|
MemberTypeService.Saved += MemberTypeService_Saved;
|
|
|
|
|
MemberTypeService.Deleted += MemberTypeService_Deleted;
|
2013-02-12 04:13:29 +06:00
|
|
|
|
2013-04-04 00:30:28 +06:00
|
|
|
//Bind to permission events
|
|
|
|
|
|
2015-01-22 12:17:36 +11:00
|
|
|
//TODO: Wrap legacy permissions so we can get rid of this
|
2013-04-04 00:30:28 +06:00
|
|
|
Permission.New += PermissionNew;
|
|
|
|
|
Permission.Updated += PermissionUpdated;
|
|
|
|
|
Permission.Deleted += PermissionDeleted;
|
2014-02-17 17:45:59 +11:00
|
|
|
PermissionRepository<IContent>.AssignedPermissions += CacheRefresherEventHandler_AssignedPermissions;
|
2013-04-04 00:30:28 +06:00
|
|
|
|
2013-02-07 05:26:53 +06:00
|
|
|
//Bind to template events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
FileService.SavedTemplate += FileService_SavedTemplate;
|
|
|
|
|
FileService.DeletedTemplate += FileService_DeletedTemplate;
|
2013-02-07 05:26:53 +06:00
|
|
|
|
2013-02-07 04:45:05 +06:00
|
|
|
//Bind to macro events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
MacroService.Saved += MacroService_Saved;
|
|
|
|
|
MacroService.Deleted += MacroService_Deleted;
|
2013-02-07 04:45:05 +06:00
|
|
|
|
|
|
|
|
//Bind to member events
|
2013-02-06 09:53:13 +06:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
MemberService.Saved += MemberService_Saved;
|
|
|
|
|
MemberService.Deleted += MemberService_Deleted;
|
2014-02-12 17:14:16 +11:00
|
|
|
MemberGroupService.Saved += MemberGroupService_Saved;
|
|
|
|
|
MemberGroupService.Deleted += MemberGroupService_Deleted;
|
2013-02-06 09:53:13 +06:00
|
|
|
|
2013-02-07 04:45:05 +06:00
|
|
|
//Bind to media events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
MediaService.Saved += MediaService_Saved;
|
|
|
|
|
MediaService.Deleted += MediaService_Deleted;
|
|
|
|
|
MediaService.Moved += MediaService_Moved;
|
|
|
|
|
MediaService.Trashed += MediaService_Trashed;
|
|
|
|
|
MediaService.EmptiedRecycleBin += MediaService_EmptiedRecycleBin;
|
2013-07-09 11:47:46 +10:00
|
|
|
|
2014-03-06 17:50:08 +11:00
|
|
|
//Bind to content events - this is for unpublished content syncing across servers (primarily for examine)
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentService.Saved += ContentService_Saved;
|
|
|
|
|
ContentService.Deleted += ContentService_Deleted;
|
|
|
|
|
ContentService.Copied += ContentService_Copied;
|
2014-04-23 20:19:36 +10:00
|
|
|
//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;
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentService.Trashed += ContentService_Trashed;
|
|
|
|
|
ContentService.EmptiedRecycleBin += ContentService_EmptiedRecycleBin;
|
2014-03-27 14:28:45 +11:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentService.Published += ContentService_Published;
|
|
|
|
|
ContentService.UnPublished += ContentService_UnPublished;
|
2015-03-30 17:36:54 +11:00
|
|
|
|
2014-03-27 14:43:07 +11:00
|
|
|
//public access events
|
2015-01-28 13:16:50 +11:00
|
|
|
PublicAccessService.Saved += PublicAccessService_Saved;
|
2016-11-09 13:05:23 +01:00
|
|
|
PublicAccessService.Deleted += PublicAccessService_Deleted;
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
RelationService.SavedRelationType += RelationService_SavedRelationType;
|
|
|
|
|
RelationService.DeletedRelationType += RelationService_DeletedRelationType;
|
2013-02-06 09:53:13 +06:00
|
|
|
}
|
2016-11-09 13:05:23 +01:00
|
|
|
|
2017-01-23 17:48:03 +01:00
|
|
|
// for tests
|
|
|
|
|
internal void Destroy()
|
|
|
|
|
{
|
|
|
|
|
//bind to application tree events
|
2017-02-06 17:26:06 +11:00
|
|
|
ApplicationTreeService.Deleted -= ApplicationTreeService_Deleted;
|
|
|
|
|
ApplicationTreeService.Updated -= ApplicationTreeService_Updated;
|
|
|
|
|
ApplicationTreeService.New -= ApplicationTreeService_New;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//bind to application events
|
2017-02-06 17:26:06 +11:00
|
|
|
SectionService.Deleted -= SectionService_Deleted;
|
|
|
|
|
SectionService.New -= SectionService_New;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//bind to user / user type events
|
2017-02-06 17:26:06 +11:00
|
|
|
UserService.SavedUserType -= UserService_SavedUserType;
|
|
|
|
|
UserService.DeletedUserType -= UserService_DeletedUserType;
|
|
|
|
|
UserService.SavedUser -= UserService_SavedUser;
|
|
|
|
|
UserService.DeletedUser -= UserService_DeletedUser;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to dictionary events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
LocalizationService.DeletedDictionaryItem -= LocalizationService_DeletedDictionaryItem;
|
|
|
|
|
LocalizationService.SavedDictionaryItem -= LocalizationService_SavedDictionaryItem;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to data type events
|
|
|
|
|
//NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
DataTypeService.Deleted -= DataTypeService_Deleted;
|
|
|
|
|
DataTypeService.Saved -= DataTypeService_Saved;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to stylesheet events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
FileService.SavedStylesheet -= FileService_SavedStylesheet;
|
|
|
|
|
FileService.DeletedStylesheet -= FileService_DeletedStylesheet;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to domain events
|
|
|
|
|
|
|
|
|
|
DomainService.Saved -= DomainService_Saved;
|
|
|
|
|
DomainService.Deleted -= DomainService_Deleted;
|
|
|
|
|
|
|
|
|
|
//Bind to language events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
LocalizationService.SavedLanguage -= LocalizationService_SavedLanguage;
|
|
|
|
|
LocalizationService.DeletedLanguage -= LocalizationService_DeletedLanguage;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to content type events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentTypeService.SavedContentType -= ContentTypeService_SavedContentType;
|
|
|
|
|
ContentTypeService.SavedMediaType -= ContentTypeService_SavedMediaType;
|
|
|
|
|
ContentTypeService.DeletedContentType -= ContentTypeService_DeletedContentType;
|
|
|
|
|
ContentTypeService.DeletedMediaType -= ContentTypeService_DeletedMediaType;
|
|
|
|
|
MemberTypeService.Saved -= MemberTypeService_Saved;
|
|
|
|
|
MemberTypeService.Deleted -= MemberTypeService_Deleted;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to permission events
|
|
|
|
|
|
|
|
|
|
//TODO: Wrap legacy permissions so we can get rid of this
|
|
|
|
|
Permission.New -= PermissionNew;
|
|
|
|
|
Permission.Updated -= PermissionUpdated;
|
|
|
|
|
Permission.Deleted -= PermissionDeleted;
|
|
|
|
|
PermissionRepository<IContent>.AssignedPermissions -= CacheRefresherEventHandler_AssignedPermissions;
|
|
|
|
|
|
|
|
|
|
//Bind to template events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
FileService.SavedTemplate -= FileService_SavedTemplate;
|
|
|
|
|
FileService.DeletedTemplate -= FileService_DeletedTemplate;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to macro events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
MacroService.Saved -= MacroService_Saved;
|
|
|
|
|
MacroService.Deleted -= MacroService_Deleted;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to member events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
MemberService.Saved -= MemberService_Saved;
|
|
|
|
|
MemberService.Deleted -= MemberService_Deleted;
|
2017-01-23 17:48:03 +01:00
|
|
|
MemberGroupService.Saved -= MemberGroupService_Saved;
|
|
|
|
|
MemberGroupService.Deleted -= MemberGroupService_Deleted;
|
|
|
|
|
|
|
|
|
|
//Bind to media events
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
MediaService.Saved -= MediaService_Saved;
|
|
|
|
|
MediaService.Deleted -= MediaService_Deleted;
|
|
|
|
|
MediaService.Moved -= MediaService_Moved;
|
|
|
|
|
MediaService.Trashed -= MediaService_Trashed;
|
|
|
|
|
MediaService.EmptiedRecycleBin -= MediaService_EmptiedRecycleBin;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//Bind to content events - this is for unpublished content syncing across servers (primarily for examine)
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentService.Saved -= ContentService_Saved;
|
|
|
|
|
ContentService.Deleted -= ContentService_Deleted;
|
|
|
|
|
ContentService.Copied -= ContentService_Copied;
|
2017-01-23 17:48:03 +01:00
|
|
|
//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;
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentService.Trashed -= ContentService_Trashed;
|
|
|
|
|
ContentService.EmptiedRecycleBin -= ContentService_EmptiedRecycleBin;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
ContentService.Published -= ContentService_Published;
|
|
|
|
|
ContentService.UnPublished -= ContentService_UnPublished;
|
2017-01-23 17:48:03 +01:00
|
|
|
|
|
|
|
|
//public access events
|
|
|
|
|
PublicAccessService.Saved -= PublicAccessService_Saved;
|
|
|
|
|
PublicAccessService.Deleted -= PublicAccessService_Deleted;
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
RelationService.SavedRelationType -= RelationService_SavedRelationType;
|
|
|
|
|
RelationService.DeletedRelationType -= RelationService_DeletedRelationType;
|
2017-01-23 17:48:03 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-30 17:36:54 +11:00
|
|
|
#region Publishing
|
|
|
|
|
|
2017-02-14 11:10:09 +01:00
|
|
|
// IPublishingStrategy (obsolete) events are proxied into ContentService, which works fine when
|
|
|
|
|
// events are actually raised, but not when they are handled by HandleEvents, so we have to have
|
|
|
|
|
// these proxy methods that are *not* registered against any event *but* used by HandleEvents.
|
|
|
|
|
|
|
|
|
|
static void PublishingStrategy_UnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
|
|
|
|
|
{
|
|
|
|
|
ContentService_UnPublished(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void PublishingStrategy_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
|
|
|
|
|
{
|
|
|
|
|
ContentService_Published(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_UnPublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
|
2015-03-30 17:36:54 +11:00
|
|
|
{
|
|
|
|
|
if (e.PublishedEntities.Any())
|
|
|
|
|
{
|
|
|
|
|
if (e.PublishedEntities.Count() > 1)
|
|
|
|
|
{
|
|
|
|
|
foreach (var c in e.PublishedEntities)
|
|
|
|
|
{
|
|
|
|
|
UnPublishSingle(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var content = e.PublishedEntities.FirstOrDefault();
|
|
|
|
|
UnPublishSingle(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the xml cache for a single node by removing it
|
|
|
|
|
/// </summary>
|
2017-02-06 17:26:06 +11:00
|
|
|
private static void UnPublishSingle(IContent content)
|
2015-03-30 17:36:54 +11:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RemovePageCache(content);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
|
2015-03-30 17:36:54 +11:00
|
|
|
{
|
|
|
|
|
if (e.PublishedEntities.Any())
|
|
|
|
|
{
|
|
|
|
|
if (e.IsAllRepublished)
|
|
|
|
|
{
|
|
|
|
|
UpdateEntireCache();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.PublishedEntities.Count() > 1)
|
|
|
|
|
{
|
|
|
|
|
UpdateMultipleContentCache(e.PublishedEntities);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var content = e.PublishedEntities.FirstOrDefault();
|
|
|
|
|
UpdateSingleContentCache(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the xml cache for all nodes
|
|
|
|
|
/// </summary>
|
2017-02-06 17:26:06 +11:00
|
|
|
private static void UpdateEntireCache()
|
2015-03-30 17:36:54 +11:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllPageCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the xml cache for nodes in list
|
|
|
|
|
/// </summary>
|
2017-02-06 17:26:06 +11:00
|
|
|
private static void UpdateMultipleContentCache(IEnumerable<IContent> content)
|
2015-03-30 17:36:54 +11:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshPageCache(content.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the xml cache for a single node
|
|
|
|
|
/// </summary>
|
2017-02-06 17:26:06 +11:00
|
|
|
private static void UpdateSingleContentCache(IContent content)
|
2015-03-30 17:36:54 +11:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshPageCache(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-03-27 14:43:07 +11:00
|
|
|
#region Public access event handlers
|
2014-03-27 14:28:45 +11:00
|
|
|
|
2015-01-28 13:16:50 +11:00
|
|
|
static void PublicAccessService_Saved(IPublicAccessService sender, SaveEventArgs<PublicAccessEntry> e)
|
2014-03-27 14:43:07 +11:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshPublicAccess();
|
2015-01-28 13:16:50 +11:00
|
|
|
}
|
2014-03-27 14:43:07 +11:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void PublicAccessService_Deleted(IPublicAccessService sender, DeleteEventArgs<PublicAccessEntry> e)
|
2016-01-07 12:18:57 +01:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshPublicAccess();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-27 14:43:07 +11:00
|
|
|
#endregion
|
2014-03-06 17:50:08 +11:00
|
|
|
|
2013-07-09 11:47:46 +10:00
|
|
|
#region Content service event handlers
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_EmptiedRecycleBin(IContentService sender, RecycleBinEventArgs e)
|
2014-04-23 20:19:36 +10:00
|
|
|
{
|
|
|
|
|
if (e.RecycleBinEmptiedSuccessfully && e.IsContentRecycleBin)
|
|
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RemoveUnpublishedCachePermanently(e.Ids.ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-07-09 11:47:46 +10:00
|
|
|
/// <summary>
|
2014-04-23 20:19:36 +10:00
|
|
|
/// Handles cache refreshing for when content is trashed
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// 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
|
|
|
|
|
/// </remarks>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_Trashed(IContentService sender, MoveEventArgs<IContent> e)
|
2014-04-23 20:19:36 +10:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshUnpublishedPageCache(
|
|
|
|
|
e.MoveInfoCollection.Select(x => x.Entity).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles cache refreshing for when content is copied
|
2013-07-09 11:47:46 +10:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2014-03-06 17:50:08 +11:00
|
|
|
/// <remarks>
|
2016-11-24 17:37:20 +01:00
|
|
|
/// When an entity is copied new permissions may be assigned to it based on it's parent, if that is the
|
2014-03-06 17:50:08 +11:00
|
|
|
/// case then we need to clear all user permissions cache.
|
|
|
|
|
/// </remarks>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_Copied(IContentService sender, CopyEventArgs<IContent> e)
|
2013-07-09 11:47:46 +10:00
|
|
|
{
|
|
|
|
|
//check if permissions have changed
|
|
|
|
|
var permissionsChanged = ((Content)e.Copy).WasPropertyDirty("PermissionsChanged");
|
|
|
|
|
if (permissionsChanged)
|
|
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllUserPermissionsCache();
|
|
|
|
|
}
|
2014-03-06 17:50:08 +11:00
|
|
|
|
2014-04-23 20:19:36 +10:00
|
|
|
//run the un-published cache refresher since copied content is not published
|
2014-03-06 17:50:08 +11:00
|
|
|
DistributedCache.Instance.RefreshUnpublishedPageCache(e.Copy);
|
2013-07-09 11:47:46 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2014-03-06 17:50:08 +11:00
|
|
|
/// Handles cache refreshing for when content is deleted (not unpublished)
|
2013-07-09 11:47:46 +10:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_Deleted(IContentService sender, DeleteEventArgs<IContent> e)
|
2013-07-09 11:47:46 +10:00
|
|
|
{
|
2014-03-06 17:50:08 +11:00
|
|
|
DistributedCache.Instance.RemoveUnpublishedPageCache(e.DeletedEntities.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles cache refreshing for when content is saved (not published)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
/// <remarks>
|
2016-11-24 17:37:20 +01:00
|
|
|
/// When an entity is saved we need to notify other servers about the change in order for the Examine indexes to
|
2014-03-06 17:50:08 +11:00
|
|
|
/// stay up-to-date for unpublished content.
|
2016-11-24 17:37:20 +01:00
|
|
|
///
|
|
|
|
|
/// When an entity is created new permissions may be assigned to it based on it's parent, if that is the
|
2014-03-06 17:50:08 +11:00
|
|
|
/// case then we need to clear all user permissions cache.
|
|
|
|
|
/// </remarks>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentService_Saved(IContentService sender, SaveEventArgs<IContent> e)
|
2014-03-06 17:50:08 +11:00
|
|
|
{
|
|
|
|
|
var clearUserPermissions = false;
|
|
|
|
|
e.SavedEntities.ForEach(x =>
|
|
|
|
|
{
|
|
|
|
|
//check if it is new
|
|
|
|
|
if (x.IsNewEntity())
|
|
|
|
|
{
|
|
|
|
|
//check if permissions have changed
|
|
|
|
|
var permissionsChanged = ((Content)x).WasPropertyDirty("PermissionsChanged");
|
|
|
|
|
if (permissionsChanged)
|
|
|
|
|
{
|
2016-11-24 17:37:20 +01:00
|
|
|
clearUserPermissions = true;
|
|
|
|
|
}
|
2014-03-06 17:50:08 +11:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (clearUserPermissions)
|
2013-07-09 11:47:46 +10:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllUserPermissionsCache();
|
|
|
|
|
}
|
2014-03-06 17:50:08 +11:00
|
|
|
|
|
|
|
|
//filter out the entities that have only been saved (not newly published) since
|
|
|
|
|
// newly published ones will be synced with the published page cache refresher
|
|
|
|
|
var unpublished = e.SavedEntities.Where(x => x.JustPublished() == false);
|
|
|
|
|
//run the un-published cache refresher
|
|
|
|
|
DistributedCache.Instance.RefreshUnpublishedPageCache(unpublished.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-07-09 11:47:46 +10:00
|
|
|
#endregion
|
|
|
|
|
|
2013-04-04 21:57:41 +06:00
|
|
|
#region ApplicationTree event handlers
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ApplicationTreeService_New(ApplicationTree sender, EventArgs e)
|
2013-04-04 21:57:41 +06:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllApplicationTreeCache();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ApplicationTreeService_Updated(ApplicationTree sender, EventArgs e)
|
2013-04-04 21:57:41 +06:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllApplicationTreeCache();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ApplicationTreeService_Deleted(ApplicationTree sender, EventArgs e)
|
2013-04-04 21:57:41 +06:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllApplicationTreeCache();
|
2016-11-24 17:37:20 +01:00
|
|
|
}
|
2013-04-04 21:57:41 +06:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Application event handlers
|
2017-02-06 17:26:06 +11:00
|
|
|
static void SectionService_New(Section sender, EventArgs e)
|
2013-04-04 21:57:41 +06:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllApplicationCache();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void SectionService_Deleted(Section sender, EventArgs e)
|
2013-04-04 21:57:41 +06:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshAllApplicationCache();
|
2016-11-24 17:37:20 +01:00
|
|
|
}
|
2013-04-04 21:57:41 +06:00
|
|
|
#endregion
|
|
|
|
|
|
2013-04-04 03:43:05 +06:00
|
|
|
#region UserType event handlers
|
2017-02-06 17:26:06 +11:00
|
|
|
static void UserService_DeletedUserType(IUserService sender, DeleteEventArgs<IUserType> e)
|
2013-04-04 03:43:05 +06:00
|
|
|
{
|
2014-01-28 09:22:01 +11:00
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserTypeCache(x.Id));
|
2013-04-04 03:43:05 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void UserService_SavedUserType(IUserService sender, SaveEventArgs<IUserType> e)
|
2013-04-04 03:43:05 +06:00
|
|
|
{
|
2014-01-28 09:22:01 +11:00
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserTypeCache(x.Id));
|
2013-04-04 03:43:05 +06:00
|
|
|
}
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-04-04 03:43:05 +06:00
|
|
|
#endregion
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-03-23 01:59:25 +06:00
|
|
|
#region Dictionary event handlers
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void LocalizationService_SavedDictionaryItem(ILocalizationService sender, SaveEventArgs<IDictionaryItem> e)
|
2013-03-23 01:59:25 +06:00
|
|
|
{
|
|
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshDictionaryCache(x.Id));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void LocalizationService_DeletedDictionaryItem(ILocalizationService sender, DeleteEventArgs<IDictionaryItem> e)
|
2013-03-23 01:59:25 +06:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveDictionaryCache(x.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2013-03-22 05:04:32 +06:00
|
|
|
#region DataType event handlers
|
2017-02-06 17:26:06 +11:00
|
|
|
static void DataTypeService_Saved(IDataTypeService sender, SaveEventArgs<IDataTypeDefinition> e)
|
2013-03-22 05:04:32 +06:00
|
|
|
{
|
2013-05-07 19:37:57 -10:00
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshDataTypeCache(x));
|
2013-03-22 05:04:32 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void DataTypeService_Deleted(IDataTypeService sender, DeleteEventArgs<IDataTypeDefinition> e)
|
2013-03-22 05:04:32 +06:00
|
|
|
{
|
2013-05-07 19:37:57 -10:00
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveDataTypeCache(x));
|
2013-03-22 05:04:32 +06:00
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-03-22 05:04:32 +06:00
|
|
|
#endregion
|
|
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#region Stylesheet and stylesheet property event handlers
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void FileService_DeletedStylesheet(IFileService sender, DeleteEventArgs<Stylesheet> e)
|
2013-03-22 01:49:34 +06:00
|
|
|
{
|
2013-03-23 01:59:25 +06:00
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveStylesheetCache(x));
|
2013-03-22 01:49:34 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void FileService_SavedStylesheet(IFileService sender, SaveEventArgs<Stylesheet> e)
|
2013-03-22 01:49:34 +06:00
|
|
|
{
|
2013-03-23 01:59:25 +06:00
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshStylesheetCache(x));
|
2013-03-22 01:49:34 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Domain event handlers
|
2015-01-22 12:17:36 +11:00
|
|
|
|
|
|
|
|
static void DomainService_Saved(IDomainService sender, SaveEventArgs<IDomain> e)
|
2013-03-22 00:49:07 +06:00
|
|
|
{
|
2015-01-22 12:17:36 +11:00
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshDomainCache(x));
|
2013-03-22 00:49:07 +06:00
|
|
|
}
|
|
|
|
|
|
2015-01-22 12:17:36 +11:00
|
|
|
static void DomainService_Deleted(IDomainService sender, DeleteEventArgs<IDomain> e)
|
2013-03-22 00:49:07 +06:00
|
|
|
{
|
2015-01-22 12:17:36 +11:00
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveDomainCache(x));
|
2013-03-22 00:49:07 +06:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2013-03-22 00:49:07 +06:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#region Language event handlers
|
2013-03-22 00:35:15 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a langauge is deleted
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void LocalizationService_DeletedLanguage(ILocalizationService sender, DeleteEventArgs<ILanguage> e)
|
2013-03-22 00:35:15 +06:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveLanguageCache(x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a langauge is saved
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void LocalizationService_SavedLanguage(ILocalizationService sender, SaveEventArgs<ILanguage> e)
|
2013-03-22 00:35:15 +06:00
|
|
|
{
|
|
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshLanguageCache(x));
|
|
|
|
|
}
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2013-03-22 00:35:15 +06:00
|
|
|
|
2014-01-23 13:33:58 +11:00
|
|
|
#region Content/media/member Type event handlers
|
2013-03-21 01:04:27 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a media type is deleted
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentTypeService_DeletedMediaType(IContentTypeService sender, DeleteEventArgs<IMediaType> e)
|
2013-03-21 01:04:27 +06:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveMediaTypeCache(x));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a content type is deleted
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentTypeService_DeletedContentType(IContentTypeService sender, DeleteEventArgs<IContentType> e)
|
2013-03-21 01:04:27 +06:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(contentType => DistributedCache.Instance.RemoveContentTypeCache(contentType));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 13:33:58 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a member type is deleted
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MemberTypeService_Deleted(IMemberTypeService sender, DeleteEventArgs<IMemberType> e)
|
2014-01-23 13:33:58 +11:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(contentType => DistributedCache.Instance.RemoveMemberTypeCache(contentType));
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-16 08:47:55 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a media type is saved
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentTypeService_SavedMediaType(IContentTypeService sender, SaveEventArgs<IMediaType> e)
|
2013-03-16 08:47:55 +06:00
|
|
|
{
|
2013-03-21 08:38:18 +06:00
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshMediaTypeCache(x));
|
2013-03-16 08:47:55 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a content type is saved
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void ContentTypeService_SavedContentType(IContentTypeService sender, SaveEventArgs<IContentType> e)
|
2013-03-22 01:49:34 +06:00
|
|
|
{
|
2013-03-21 08:38:18 +06:00
|
|
|
e.SavedEntities.ForEach(contentType => DistributedCache.Instance.RefreshContentTypeCache(contentType));
|
2014-01-23 13:33:58 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fires when a member type is saved
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MemberTypeService_Saved(IMemberTypeService sender, SaveEventArgs<IMemberType> e)
|
2014-01-23 13:33:58 +11:00
|
|
|
{
|
|
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshMemberTypeCache(x));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2014-02-17 17:45:59 +11:00
|
|
|
#region User/permissions event handlers
|
2017-02-06 17:26:06 +11:00
|
|
|
|
|
|
|
|
//fixme: this isn't named correct
|
2014-02-17 17:45:59 +11:00
|
|
|
static void CacheRefresherEventHandler_AssignedPermissions(PermissionRepository<IContent> sender, SaveEventArgs<EntityPermission> e)
|
|
|
|
|
{
|
|
|
|
|
var userIds = e.SavedEntities.Select(x => x.UserId).Distinct();
|
|
|
|
|
userIds.ForEach(x => DistributedCache.Instance.RefreshUserPermissionsCache(x));
|
|
|
|
|
}
|
2013-04-04 00:30:28 +06:00
|
|
|
|
|
|
|
|
static void PermissionDeleted(UserPermission sender, DeleteEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InvalidateCacheForPermissionsChange(sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void PermissionUpdated(UserPermission sender, SaveEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InvalidateCacheForPermissionsChange(sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void PermissionNew(UserPermission sender, NewEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
InvalidateCacheForPermissionsChange(sender);
|
|
|
|
|
}
|
2014-01-28 12:13:27 +11:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void UserService_SavedUser(IUserService sender, SaveEventArgs<IUser> e)
|
2014-01-28 12:13:27 +11:00
|
|
|
{
|
|
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshUserCache(x.Id));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void UserService_DeletedUser(IUserService sender, DeleteEventArgs<IUser> e)
|
2014-01-28 12:13:27 +11:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveUserCache(x.Id));
|
|
|
|
|
}
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-04-04 00:30:28 +06:00
|
|
|
private static void InvalidateCacheForPermissionsChange(UserPermission sender)
|
|
|
|
|
{
|
|
|
|
|
if (sender.User != null)
|
|
|
|
|
{
|
2013-07-09 11:47:46 +10:00
|
|
|
DistributedCache.Instance.RefreshUserPermissionsCache(sender.User.Id);
|
2013-04-04 00:30:28 +06:00
|
|
|
}
|
2013-07-09 11:47:46 +10:00
|
|
|
else if (sender.UserId > -1)
|
2013-04-04 00:30:28 +06:00
|
|
|
{
|
2013-07-09 11:47:46 +10:00
|
|
|
DistributedCache.Instance.RefreshUserPermissionsCache(sender.UserId);
|
2013-04-04 00:30:28 +06:00
|
|
|
}
|
2013-07-09 11:47:46 +10:00
|
|
|
else if (sender.NodeIds.Any())
|
2013-04-04 00:30:28 +06:00
|
|
|
{
|
2013-07-09 11:47:46 +10:00
|
|
|
DistributedCache.Instance.RefreshAllUserPermissionsCache();
|
2013-04-04 00:30:28 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2013-02-12 04:13:29 +06:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#region Template event handlers
|
2013-03-22 02:08:55 +06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes cache for template
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void FileService_DeletedTemplate(IFileService sender, DeleteEventArgs<ITemplate> e)
|
2013-03-22 02:08:55 +06:00
|
|
|
{
|
|
|
|
|
e.DeletedEntities.ForEach(x => DistributedCache.Instance.RemoveTemplateCache(x.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refresh cache for template
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2017-02-06 17:26:06 +11:00
|
|
|
static void FileService_SavedTemplate(IFileService sender, SaveEventArgs<ITemplate> e)
|
2013-03-22 02:08:55 +06:00
|
|
|
{
|
|
|
|
|
e.SavedEntities.ForEach(x => DistributedCache.Instance.RefreshTemplateCache(x.Id));
|
|
|
|
|
}
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2013-02-07 05:26:53 +06:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#region Macro event handlers
|
2013-10-31 17:22:10 +11:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MacroService_Deleted(IMacroService sender, DeleteEventArgs<IMacro> e)
|
2013-10-31 17:22:10 +11:00
|
|
|
{
|
|
|
|
|
foreach (var entity in e.DeletedEntities)
|
|
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RemoveMacroCache(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MacroService_Saved(IMacroService sender, SaveEventArgs<IMacro> e)
|
2013-10-31 17:22:10 +11:00
|
|
|
{
|
|
|
|
|
foreach (var entity in e.SavedEntities)
|
|
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RefreshMacroCache(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-24 17:37:20 +01:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2013-02-07 04:45:05 +06:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#region Media event handlers
|
2014-04-23 20:19:36 +10:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MediaService_EmptiedRecycleBin(IMediaService sender, RecycleBinEventArgs e)
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
2014-04-23 20:19:36 +10:00
|
|
|
if (e.RecycleBinEmptiedSuccessfully && e.IsMediaRecycleBin)
|
|
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RemoveMediaCachePermanently(e.Ids.ToArray());
|
|
|
|
|
}
|
2013-02-06 09:53:13 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MediaService_Trashed(IMediaService sender, MoveEventArgs<IMedia> e)
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
2014-04-23 20:19:36 +10:00
|
|
|
DistributedCache.Instance.RemoveMediaCacheAfterRecycling(e.MoveInfoCollection.ToArray());
|
2013-02-06 09:53:13 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MediaService_Moved(IMediaService sender, MoveEventArgs<IMedia> e)
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
2014-04-23 20:19:36 +10:00
|
|
|
DistributedCache.Instance.RefreshMediaCacheAfterMoving(e.MoveInfoCollection.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MediaService_Deleted(IMediaService sender, DeleteEventArgs<IMedia> e)
|
2014-04-23 20:19:36 +10:00
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RemoveMediaCachePermanently(e.DeletedEntities.Select(x => x.Id).ToArray());
|
2013-02-06 09:53:13 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MediaService_Saved(IMediaService sender, SaveEventArgs<IMedia> e)
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
2013-02-12 07:35:47 +06:00
|
|
|
DistributedCache.Instance.RefreshMediaCache(e.SavedEntities.ToArray());
|
2016-11-24 17:37:20 +01:00
|
|
|
}
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2013-02-06 09:53:13 +06:00
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#region Member event handlers
|
2013-10-18 16:23:33 +11:00
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MemberService_Deleted(IMemberService sender, DeleteEventArgs<IMember> e)
|
2013-10-18 16:23:33 +11:00
|
|
|
{
|
2016-11-24 17:37:20 +01:00
|
|
|
DistributedCache.Instance.RemoveMemberCache(e.DeletedEntities.ToArray());
|
2013-02-06 09:53:13 +06:00
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void MemberService_Saved(IMemberService sender, SaveEventArgs<IMember> e)
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
2014-03-06 18:25:38 +11:00
|
|
|
DistributedCache.Instance.RefreshMemberCache(e.SavedEntities.ToArray());
|
2013-10-18 16:23:33 +11:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2014-02-12 17:14:16 +11:00
|
|
|
|
|
|
|
|
#region Member group event handlers
|
|
|
|
|
|
2014-03-06 18:25:38 +11:00
|
|
|
static void MemberGroupService_Deleted(IMemberGroupService sender, DeleteEventArgs<IMemberGroup> e)
|
2013-10-18 16:23:33 +11:00
|
|
|
{
|
2014-02-12 17:14:16 +11:00
|
|
|
foreach (var m in e.DeletedEntities.ToArray())
|
2013-10-18 16:23:33 +11:00
|
|
|
{
|
2014-02-12 17:14:16 +11:00
|
|
|
DistributedCache.Instance.RemoveMemberGroupCache(m.Id);
|
2013-10-18 16:23:33 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-06 18:25:38 +11:00
|
|
|
static void MemberGroupService_Saved(IMemberGroupService sender, SaveEventArgs<IMemberGroup> e)
|
2013-02-06 09:53:13 +06:00
|
|
|
{
|
2014-02-12 17:14:16 +11:00
|
|
|
foreach (var m in e.SavedEntities.ToArray())
|
|
|
|
|
{
|
|
|
|
|
DistributedCache.Instance.RemoveMemberGroupCache(m.Id);
|
|
|
|
|
}
|
2016-11-09 13:05:23 +01:00
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Relation type event handlers
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void RelationService_SavedRelationType(IRelationService sender, SaveEventArgs<IRelationType> args)
|
2016-11-09 13:05:23 +01:00
|
|
|
{
|
|
|
|
|
var dc = DistributedCache.Instance;
|
|
|
|
|
foreach (var e in args.SavedEntities)
|
|
|
|
|
dc.RefreshRelationTypeCache(e.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 17:26:06 +11:00
|
|
|
static void RelationService_DeletedRelationType(IRelationService sender, DeleteEventArgs<IRelationType> args)
|
2016-11-09 13:05:23 +01:00
|
|
|
{
|
|
|
|
|
var dc = DistributedCache.Instance;
|
|
|
|
|
foreach (var e in args.DeletedEntities)
|
|
|
|
|
dc.RemoveRelationTypeCache(e.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 01:49:34 +06:00
|
|
|
#endregion
|
2017-02-06 17:26:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This will inspect the event metadata and execute it's affiliated handler if one is found
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="events"></param>
|
|
|
|
|
internal static void HandleEvents(IEnumerable<IEventDefinition> events)
|
|
|
|
|
{
|
|
|
|
|
foreach (var e in events)
|
|
|
|
|
{
|
|
|
|
|
var handler = FindHandler(e);
|
|
|
|
|
if (handler == null) continue;
|
|
|
|
|
|
|
|
|
|
handler.Invoke(null, new object[] { e.Sender, e.Args });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to cache all candidate handlers
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly Lazy<MethodInfo[]> CandidateHandlers = new Lazy<MethodInfo[]>(() =>
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to cache all found event handlers
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly ConcurrentDictionary<IEventDefinition, MethodInfo> FoundHandlers = new ConcurrentDictionary<IEventDefinition, MethodInfo>();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-02-06 09:53:13 +06:00
|
|
|
}
|
|
|
|
|
}
|