diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index 0782579497..9a36d9df7d 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -33,7 +33,8 @@ namespace Umbraco.Cms.Core.Cache INotificationHandler, INotificationHandler, INotificationHandler, - INotificationHandler + INotificationHandler, + INotificationHandler { private List _unbinders; @@ -70,12 +71,6 @@ namespace Umbraco.Cms.Core.Cache Bind(() => DataTypeService.Saved += DataTypeService_Saved, () => DataTypeService.Saved -= DataTypeService_Saved); - // bind to stylesheet events - Bind(() => FileService.SavedStylesheet += FileService_SavedStylesheet, - () => FileService.SavedStylesheet -= FileService_SavedStylesheet); - Bind(() => FileService.DeletedStylesheet += FileService_DeletedStylesheet, - () => FileService.DeletedStylesheet -= FileService_DeletedStylesheet); - // bind to domain events Bind(() => DomainService.Saved += DomainService_Saved, () => DomainService.Saved -= DomainService_Saved); @@ -93,8 +88,6 @@ namespace Umbraco.Cms.Core.Cache // bind to template events Bind(() => FileService.SavedTemplate += FileService_SavedTemplate, () => FileService.SavedTemplate -= FileService_SavedTemplate); - Bind(() => FileService.DeletedTemplate += FileService_DeletedTemplate, - () => FileService.DeletedTemplate -= FileService_DeletedTemplate); // bind to macro events Bind(() => MacroService.Saved += MacroService_Saved, @@ -317,12 +310,13 @@ namespace Umbraco.Cms.Core.Cache /// /// Removes cache for template /// - /// - /// - private void FileService_DeletedTemplate(IFileService sender, DeleteEventArgs e) + /// + public void Handle(TemplateDeletedNotification notification) { - foreach (var entity in e.DeletedEntities) + foreach (ITemplate entity in notification.DeletedEntities) + { _distributedCache.RemoveTemplateCache(entity.Id); + } } /// @@ -336,10 +330,6 @@ namespace Umbraco.Cms.Core.Cache _distributedCache.RefreshTemplateCache(entity.Id); } - // TODO: our weird events handling wants this for now - private void FileService_DeletedStylesheet(IFileService sender, DeleteEventArgs e) { } - private void FileService_SavedStylesheet(IFileService sender, SaveEventArgs e) { } - #endregion #region MacroService diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs index be6539ac55..a0895762ea 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs @@ -78,7 +78,8 @@ namespace Umbraco.Cms.Core.Compose .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler(); // add notification handlers for auditing builder diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index 67e0607292..1dfd4db498 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -12,6 +12,7 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Strings; +using Umbraco.Cms.Infrastructure.Services.Notifications; using Umbraco.Extensions; namespace Umbraco.Cms.Core.Services.Implement @@ -96,25 +97,26 @@ namespace Umbraco.Cms.Core.Services.Implement /// public void DeleteStylesheet(string path, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var stylesheet = _stylesheetRepository.Get(path); + IStylesheet stylesheet = _stylesheetRepository.Get(path); if (stylesheet == null) { scope.Complete(); return; } - var deleteEventArgs = new DeleteEventArgs(stylesheet); - if (scope.Events.DispatchCancelable(DeletingStylesheet, this, deleteEventArgs)) + EventMessages eventMessages = EventMessagesFactory.Get(); + var deletingNotification = new StylesheetDeletingNotification(stylesheet, eventMessages); + if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); - return; // causes rollback // causes rollback + return; // causes rollback } _stylesheetRepository.Delete(stylesheet); - deleteEventArgs.CanCancel = false; - scope.Events.Dispatch(DeletedStylesheet, this, deleteEventArgs); + + scope.Notifications.Publish(new StylesheetDeletedNotification(stylesheet, eventMessages).WithStateFrom(deletingNotification)); Audit(AuditType.Delete, userId, -1, "Stylesheet"); scope.Complete(); @@ -219,25 +221,25 @@ namespace Umbraco.Cms.Core.Services.Implement /// public void DeleteScript(string path, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var script = _scriptRepository.Get(path); + IScript script = _scriptRepository.Get(path); if (script == null) { scope.Complete(); return; } - var deleteEventArgs = new DeleteEventArgs(script); - if (scope.Events.DispatchCancelable(DeletingScript, this, deleteEventArgs)) + EventMessages eventMessages = EventMessagesFactory.Get(); + var deletingNotification = new ScriptDeletingNotification(script, eventMessages); + if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); return; } _scriptRepository.Delete(script); - deleteEventArgs.CanCancel = false; - scope.Events.Dispatch(DeletedScript, this, deleteEventArgs); + scope.Notifications.Publish(new ScriptDeletedNotification(script, eventMessages).WithStateFrom(deletingNotification)); Audit(AuditType.Delete, userId, -1, "Script"); scope.Complete(); @@ -586,17 +588,18 @@ namespace Umbraco.Cms.Core.Services.Implement /// public void DeleteTemplate(string alias, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var template = _templateRepository.Get(alias); + ITemplate template = _templateRepository.Get(alias); if (template == null) { scope.Complete(); return; } - var args = new DeleteEventArgs(template); - if (scope.Events.DispatchCancelable(DeletingTemplate, this, args)) + EventMessages eventMessages = EventMessagesFactory.Get(); + var deletingNotification = new TemplateDeletingNotification(template, eventMessages); + if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); return; @@ -604,8 +607,7 @@ namespace Umbraco.Cms.Core.Services.Implement _templateRepository.Delete(template); - args.CanCancel = false; - scope.Events.Dispatch(DeletedTemplate, this, args); + scope.Notifications.Publish(new TemplateDeletedNotification(template, eventMessages).WithStateFrom(deletingNotification)); Audit(AuditType.Delete, userId, template.Id, ObjectTypes.GetName(UmbracoObjectTypes.Template)); scope.Complete(); @@ -1063,36 +1065,6 @@ namespace Umbraco.Cms.Core.Services.Implement #region Event Handlers - /// - /// Occurs before Delete - /// - public static event TypedEventHandler> DeletingTemplate; - - /// - /// Occurs after Delete - /// - public static event TypedEventHandler> DeletedTemplate; - - /// - /// Occurs before Delete - /// - public static event TypedEventHandler> DeletingScript; - - /// - /// Occurs after Delete - /// - public static event TypedEventHandler> DeletedScript; - - /// - /// Occurs before Delete - /// - public static event TypedEventHandler> DeletingStylesheet; - - /// - /// Occurs after Delete - /// - public static event TypedEventHandler> DeletedStylesheet; - /// /// Occurs before Save /// diff --git a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs index 2d9bcf2c9d..e0e4e13ca8 100644 --- a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs @@ -45,9 +45,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache new EventDefinition>(null, DataTypeService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, DataTypeService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, FileService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, FileService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, DomainService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, DomainService, new DeleteEventArgs(Enumerable.Empty())), @@ -60,7 +57,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache new EventDefinition>(null, MemberTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, FileService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, FileService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, MacroService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, MacroService, new DeleteEventArgs(Enumerable.Empty())),