From 03782bca866460ea71f029007a30546e88c22cd6 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Fri, 26 Mar 2021 10:43:07 +0000 Subject: [PATCH 01/10] New generic Deleting Notification to match the DeletedNotification and Saving/Saved ones --- src/Umbraco.Core/Events/DeletingNotification.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/Umbraco.Core/Events/DeletingNotification.cs diff --git a/src/Umbraco.Core/Events/DeletingNotification.cs b/src/Umbraco.Core/Events/DeletingNotification.cs new file mode 100644 index 0000000000..c4e6046652 --- /dev/null +++ b/src/Umbraco.Core/Events/DeletingNotification.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace Umbraco.Cms.Core.Events +{ + public abstract class DeletingNotification : CancelableEnumerableObjectNotification + { + protected DeletingNotification(T target, EventMessages messages) : base(target, messages) + { + } + + protected DeletingNotification(IEnumerable target, EventMessages messages) : base(target, messages) + { + } + + public IEnumerable DeletedEntities => Target; + } +} From 022c5feaf62f520a24b592b62b647a7221cb0936 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Fri, 26 Mar 2021 10:44:07 +0000 Subject: [PATCH 02/10] Notifications for EntityContainers in DataTypeService aka Folders for DataTypes --- .../EntityContainerDeletedNotification.cs | 11 +++++++ .../EntityContainerDeletingNotification.cs | 11 +++++++ .../EntityContainerRenamedNotification.cs | 11 +++++++ .../EntityContainerSavedNotification.cs | 11 +++++++ .../EntityContainerSavingNotification.cs | 11 +++++++ .../Services/Implement/DataTypeService.cs | 31 +++++++++---------- 6 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 src/Umbraco.Core/Events/EntityContainerDeletedNotification.cs create mode 100644 src/Umbraco.Core/Events/EntityContainerDeletingNotification.cs create mode 100644 src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs create mode 100644 src/Umbraco.Core/Events/EntityContainerSavedNotification.cs create mode 100644 src/Umbraco.Core/Events/EntityContainerSavingNotification.cs diff --git a/src/Umbraco.Core/Events/EntityContainerDeletedNotification.cs b/src/Umbraco.Core/Events/EntityContainerDeletedNotification.cs new file mode 100644 index 0000000000..eca96962be --- /dev/null +++ b/src/Umbraco.Core/Events/EntityContainerDeletedNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class EntityContainerDeletedNotification : DeletedNotification + { + public EntityContainerDeletedNotification(EntityContainer target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/EntityContainerDeletingNotification.cs b/src/Umbraco.Core/Events/EntityContainerDeletingNotification.cs new file mode 100644 index 0000000000..58d0830cf9 --- /dev/null +++ b/src/Umbraco.Core/Events/EntityContainerDeletingNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class EntityContainerDeletingNotification : DeletingNotification + { + public EntityContainerDeletingNotification(EntityContainer target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs b/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs new file mode 100644 index 0000000000..3fac1fdd40 --- /dev/null +++ b/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class EntityContainerRenamedNotification : SavedNotification + { + public EntityContainerRenamedNotification(EntityContainer target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/EntityContainerSavedNotification.cs b/src/Umbraco.Core/Events/EntityContainerSavedNotification.cs new file mode 100644 index 0000000000..108d6649df --- /dev/null +++ b/src/Umbraco.Core/Events/EntityContainerSavedNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class EntityContainerSavedNotification : SavedNotification + { + public EntityContainerSavedNotification(EntityContainer target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/EntityContainerSavingNotification.cs b/src/Umbraco.Core/Events/EntityContainerSavingNotification.cs new file mode 100644 index 0000000000..98a8a34926 --- /dev/null +++ b/src/Umbraco.Core/Events/EntityContainerSavingNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class EntityContainerSavingNotification : SavingNotification + { + public EntityContainerSavingNotification(EntityContainer target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs index a2ef8f4544..78bf7f062e 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs @@ -31,13 +31,14 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly ILocalizationService _localizationService; private readonly IShortStringHelper _shortStringHelper; private readonly IJsonSerializer _jsonSerializer; + private readonly IEventAggregator _eventAggregator; public DataTypeService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IDataTypeRepository dataTypeRepository, IDataTypeContainerRepository dataTypeContainerRepository, IAuditRepository auditRepository, IEntityRepository entityRepository, IContentTypeRepository contentTypeRepository, IIOHelper ioHelper, ILocalizedTextService localizedTextService, ILocalizationService localizationService, IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer) + IJsonSerializer jsonSerializer, IEventAggregator eventAggregator) : base(provider, loggerFactory, eventMessagesFactory) { _dataTypeRepository = dataTypeRepository; @@ -50,6 +51,7 @@ namespace Umbraco.Cms.Core.Services.Implement _localizationService = localizationService; _shortStringHelper = shortStringHelper; _jsonSerializer = jsonSerializer; + _eventAggregator = eventAggregator; } #region Containers @@ -68,7 +70,8 @@ namespace Umbraco.Cms.Core.Services.Implement CreatorId = userId }; - if (scope.Events.DispatchCancelable(SavingContainer, this, new SaveEventArgs(container, evtMsgs))) + var savingEntityContainerNotification = new EntityContainerSavingNotification(container, evtMsgs); + if (scope.Notifications.PublishCancelable(savingEntityContainerNotification)) { scope.Complete(); return OperationResult.Attempt.Cancel(evtMsgs, container); @@ -77,7 +80,8 @@ namespace Umbraco.Cms.Core.Services.Implement _dataTypeContainerRepository.Save(container); scope.Complete(); - scope.Events.Dispatch(SavedContainer, this, new SaveEventArgs(container, evtMsgs)); + scope.Notifications.Publish(new EntityContainerSavedNotification(container, evtMsgs).WithStateFrom(savingEntityContainerNotification)); + // TODO: Audit trail ? return OperationResult.Attempt.Succeed(evtMsgs, container); @@ -153,7 +157,8 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - if (scope.Events.DispatchCancelable(SavingContainer, this, new SaveEventArgs(container, evtMsgs))) + var savingEntityContainerNotification = new EntityContainerSavingNotification(container, evtMsgs); + if (scope.Notifications.PublishCancelable(savingEntityContainerNotification)) { scope.Complete(); return OperationResult.Attempt.Cancel(evtMsgs); @@ -161,7 +166,7 @@ namespace Umbraco.Cms.Core.Services.Implement _dataTypeContainerRepository.Save(container); - scope.Events.Dispatch(SavedContainer, this, new SaveEventArgs(container, evtMsgs)); + scope.Notifications.Publish(new EntityContainerSavedNotification(container, evtMsgs).WithStateFrom(savingEntityContainerNotification)); scope.Complete(); } @@ -186,7 +191,8 @@ namespace Umbraco.Cms.Core.Services.Implement return Attempt.Fail(new OperationResult(OperationResultType.FailedCannot, evtMsgs)); } - if (scope.Events.DispatchCancelable(DeletingContainer, this, new DeleteEventArgs(container, evtMsgs))) + var deletingEntityContainerNotification = new EntityContainerDeletingNotification(container, evtMsgs); + if (scope.Notifications.PublishCancelable(deletingEntityContainerNotification)) { scope.Complete(); return Attempt.Fail(new OperationResult(OperationResultType.FailedCancelledByEvent, evtMsgs)); @@ -194,7 +200,7 @@ namespace Umbraco.Cms.Core.Services.Implement _dataTypeContainerRepository.Delete(container); - scope.Events.Dispatch(DeletedContainer, this, new DeleteEventArgs(container, evtMsgs)); + scope.Notifications.Publish(new EntityContainerDeletedNotification(container, evtMsgs).WithStateFrom(deletingEntityContainerNotification)); scope.Complete(); } @@ -220,8 +226,7 @@ namespace Umbraco.Cms.Core.Services.Implement _dataTypeContainerRepository.Save(container); scope.Complete(); - // TODO: triggering SavedContainer with a different name?! - scope.Events.Dispatch(SavedContainer, this, new SaveEventArgs(container, evtMsgs), "RenamedContainer"); + scope.Notifications.Publish(new EntityContainerRenamedNotification(container, evtMsgs)); return OperationResult.Attempt.Succeed(OperationResultType.Success, evtMsgs, container); } @@ -529,21 +534,15 @@ namespace Umbraco.Cms.Core.Services.Implement #region Event Handlers - public static event TypedEventHandler> SavingContainer; - public static event TypedEventHandler> SavedContainer; - public static event TypedEventHandler> DeletingContainer; - public static event TypedEventHandler> DeletedContainer; - /// /// Occurs before Delete /// - public static event TypedEventHandler> Deleting; + //public static event TypedEventHandler> Deleting; /// /// Occurs after Delete /// public static event TypedEventHandler> Deleted; - /// /// Occurs before Save /// From e78b8776199a9b560d6fa91d6c899d302dfac265 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Fri, 26 Mar 2021 12:18:10 +0000 Subject: [PATCH 03/10] Remove reference to old events --- .../Cache/DistributedCacheBinder_Handlers.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index 1aa4906029..d4dfad145e 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -67,12 +67,6 @@ namespace Umbraco.Cms.Core.Cache Bind(() => LocalizationService.SavedDictionaryItem += LocalizationService_SavedDictionaryItem, () => LocalizationService.SavedDictionaryItem -= LocalizationService_SavedDictionaryItem); - // bind to data type events - Bind(() => DataTypeService.Deleted += DataTypeService_Deleted, - () => DataTypeService.Deleted -= DataTypeService_Deleted); - Bind(() => DataTypeService.Saved += DataTypeService_Saved, - () => DataTypeService.Saved -= DataTypeService_Saved); - // bind to stylesheet events Bind(() => FileService.SavedStylesheet += FileService_SavedStylesheet, () => FileService.SavedStylesheet -= FileService_SavedStylesheet); From 3cd2d9722632d7eda87024b76513b641c66629f9 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Fri, 26 Mar 2021 12:23:27 +0000 Subject: [PATCH 04/10] Move last events to notifications --- .../Events/DataTypeDeletedNotification.cs | 11 +++ .../Events/DataTypeDeletingNotification.cs | 11 +++ .../Events/DataTypeMovedNotification.cs | 11 +++ .../Events/DataTypeMovingNotification.cs | 11 +++ .../Events/DataTypeSavedNotification.cs | 16 +++++ .../Events/DataTypeSavingNotification.cs | 16 +++++ .../Services/Implement/DataTypeService.cs | 69 ++++++------------- 7 files changed, 98 insertions(+), 47 deletions(-) create mode 100644 src/Umbraco.Core/Events/DataTypeDeletedNotification.cs create mode 100644 src/Umbraco.Core/Events/DataTypeDeletingNotification.cs create mode 100644 src/Umbraco.Core/Events/DataTypeMovedNotification.cs create mode 100644 src/Umbraco.Core/Events/DataTypeMovingNotification.cs create mode 100644 src/Umbraco.Core/Events/DataTypeSavedNotification.cs create mode 100644 src/Umbraco.Core/Events/DataTypeSavingNotification.cs diff --git a/src/Umbraco.Core/Events/DataTypeDeletedNotification.cs b/src/Umbraco.Core/Events/DataTypeDeletedNotification.cs new file mode 100644 index 0000000000..b3461e27f1 --- /dev/null +++ b/src/Umbraco.Core/Events/DataTypeDeletedNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class DataTypeDeletedNotification : DeletedNotification + { + public DataTypeDeletedNotification(IDataType target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/DataTypeDeletingNotification.cs b/src/Umbraco.Core/Events/DataTypeDeletingNotification.cs new file mode 100644 index 0000000000..16b2ee68ac --- /dev/null +++ b/src/Umbraco.Core/Events/DataTypeDeletingNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class DataTypeDeletingNotification : DeletingNotification + { + public DataTypeDeletingNotification(IDataType target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/DataTypeMovedNotification.cs b/src/Umbraco.Core/Events/DataTypeMovedNotification.cs new file mode 100644 index 0000000000..10e42c7a82 --- /dev/null +++ b/src/Umbraco.Core/Events/DataTypeMovedNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class DataTypeMovedNotification : MovedNotification + { + public DataTypeMovedNotification(MoveEventInfo target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/DataTypeMovingNotification.cs b/src/Umbraco.Core/Events/DataTypeMovingNotification.cs new file mode 100644 index 0000000000..4b48f51a00 --- /dev/null +++ b/src/Umbraco.Core/Events/DataTypeMovingNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class DataTypeMovingNotification : MovingNotification + { + public DataTypeMovingNotification(MoveEventInfo target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/DataTypeSavedNotification.cs b/src/Umbraco.Core/Events/DataTypeSavedNotification.cs new file mode 100644 index 0000000000..09c42d32a9 --- /dev/null +++ b/src/Umbraco.Core/Events/DataTypeSavedNotification.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class DataTypeSavedNotification : SavedNotification + { + public DataTypeSavedNotification(IDataType target, EventMessages messages) : base(target, messages) + { + } + + public DataTypeSavedNotification(IEnumerable target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/DataTypeSavingNotification.cs b/src/Umbraco.Core/Events/DataTypeSavingNotification.cs new file mode 100644 index 0000000000..dd110df5a3 --- /dev/null +++ b/src/Umbraco.Core/Events/DataTypeSavingNotification.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class DataTypeSavingNotification : SavingNotification + { + public DataTypeSavingNotification(IDataType target, EventMessages messages) : base(target, messages) + { + } + + public DataTypeSavingNotification(IEnumerable target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs index 78bf7f062e..b96f54dc14 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs @@ -346,8 +346,10 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { var moveEventInfo = new MoveEventInfo(toMove, toMove.Path, parentId); - var moveEventArgs = new MoveEventArgs(evtMsgs, moveEventInfo); - if (scope.Events.DispatchCancelable(Moving, this, moveEventArgs)) + // var moveEventArgs = new MoveEventArgs(evtMsgs, moveEventInfo); + + var movingDataTypeNotification = new DataTypeMovingNotification(moveEventInfo, evtMsgs); + if (scope.Notifications.PublishCancelable(movingDataTypeNotification)) { scope.Complete(); return OperationResult.Attempt.Fail(MoveOperationStatusType.FailedCancelledByEvent, evtMsgs); @@ -364,9 +366,8 @@ namespace Umbraco.Cms.Core.Services.Implement } moveInfo.AddRange(_dataTypeRepository.Move(toMove, container)); - moveEventArgs.MoveInfoCollection = moveInfo; - moveEventArgs.CanCancel = false; - scope.Events.Dispatch(Moved, this, moveEventArgs); + scope.Notifications.Publish(new DataTypeMovedNotification(moveEventInfo, evtMsgs).WithStateFrom(movingDataTypeNotification)); + scope.Complete(); } catch (DataOperationException ex) @@ -386,12 +387,15 @@ namespace Umbraco.Cms.Core.Services.Implement /// Id of the user issuing the save public void Save(IDataType dataType, int userId = Cms.Core.Constants.Security.SuperUserId) { + var evtMsgs = EventMessagesFactory.Get(); dataType.CreatorId = userId; using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs(dataType); - if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) + + var savingDataTypeNotification = new DataTypeSavingNotification(dataType, evtMsgs); + if (scope.Notifications.PublishCancelable(savingDataTypeNotification)) { scope.Complete(); return; @@ -409,8 +413,8 @@ namespace Umbraco.Cms.Core.Services.Implement _dataTypeRepository.Save(dataType); - saveEventArgs.CanCancel = false; - scope.Events.Dispatch(Saved, this, saveEventArgs); + scope.Notifications.Publish(new DataTypeSavedNotification(dataType, evtMsgs).WithStateFrom(savingDataTypeNotification)); + Audit(AuditType.Save, userId, dataType.Id); scope.Complete(); } @@ -434,12 +438,14 @@ namespace Umbraco.Cms.Core.Services.Implement /// Boolean indicating whether or not to raise events public void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents) { + var evtMsgs = EventMessagesFactory.Get(); var dataTypeDefinitionsA = dataTypeDefinitions.ToArray(); - var saveEventArgs = new SaveEventArgs(dataTypeDefinitionsA); + //var saveEventArgs = new SaveEventArgs(dataTypeDefinitionsA); using (var scope = ScopeProvider.CreateScope()) { - if (raiseEvents && scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) + var savingDataTypeNotification = new DataTypeSavingNotification(dataTypeDefinitions, evtMsgs); + if (raiseEvents && scope.Notifications.PublishCancelable(savingDataTypeNotification)) { scope.Complete(); return; @@ -453,8 +459,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { - saveEventArgs.CanCancel = false; - scope.Events.Dispatch(Saved, this, saveEventArgs); + scope.Notifications.Publish(new DataTypeSavedNotification(dataTypeDefinitions, evtMsgs).WithStateFrom(savingDataTypeNotification)); } Audit(AuditType.Save, userId, -1); @@ -473,10 +478,11 @@ namespace Umbraco.Cms.Core.Services.Implement /// Optional Id of the user issuing the deletion public void Delete(IDataType dataType, int userId = Cms.Core.Constants.Security.SuperUserId) { + var evtMsgs = EventMessagesFactory.Get(); using (var scope = ScopeProvider.CreateScope()) { - var deleteEventArgs = new DeleteEventArgs(dataType); - if (scope.Events.DispatchCancelable(Deleting, this, deleteEventArgs)) + var deletingDataTypeNotification = new DataTypeDeletingNotification(dataType, evtMsgs); + if (scope.Notifications.PublishCancelable(deletingDataTypeNotification)) { scope.Complete(); return; @@ -511,8 +517,8 @@ namespace Umbraco.Cms.Core.Services.Implement _dataTypeRepository.Delete(dataType); - deleteEventArgs.CanCancel = false; - scope.Events.Dispatch(Deleted, this, deleteEventArgs); + scope.Notifications.Publish(new DataTypeDeletedNotification(dataType, evtMsgs).WithStateFrom(deletingDataTypeNotification)); + Audit(AuditType.Delete, userId, dataType.Id); scope.Complete(); @@ -532,36 +538,5 @@ namespace Umbraco.Cms.Core.Services.Implement _auditRepository.Save(new AuditItem(objectId, type, userId, ObjectTypes.GetName(UmbracoObjectTypes.DataType))); } - #region Event Handlers - - /// - /// Occurs before Delete - /// - //public static event TypedEventHandler> Deleting; - - /// - /// Occurs after Delete - /// - public static event TypedEventHandler> Deleted; - /// - /// Occurs before Save - /// - public static event TypedEventHandler> Saving; - - /// - /// Occurs after Save - /// - public static event TypedEventHandler> Saved; - - /// - /// Occurs before Move - /// - public static event TypedEventHandler> Moving; - - /// - /// Occurs after Move - /// - public static event TypedEventHandler> Moved; - #endregion } } From 4ef6c798fc57297ca54cc1eaf3e77d6146c4119f Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 29 Mar 2021 08:48:42 +0100 Subject: [PATCH 05/10] Remove leftover comments from migrating this over --- .../Services/Implement/DataTypeService.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs index b96f54dc14..fd1b40eb2f 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs @@ -346,7 +346,6 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { var moveEventInfo = new MoveEventInfo(toMove, toMove.Path, parentId); - // var moveEventArgs = new MoveEventArgs(evtMsgs, moveEventInfo); var movingDataTypeNotification = new DataTypeMovingNotification(moveEventInfo, evtMsgs); if (scope.Notifications.PublishCancelable(movingDataTypeNotification)) @@ -440,7 +439,6 @@ namespace Umbraco.Cms.Core.Services.Implement { var evtMsgs = EventMessagesFactory.Get(); var dataTypeDefinitionsA = dataTypeDefinitions.ToArray(); - //var saveEventArgs = new SaveEventArgs(dataTypeDefinitionsA); using (var scope = ScopeProvider.CreateScope()) { From 6d73051beaa4321ff135b348df94d9870868ece1 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 29 Mar 2021 09:19:45 +0100 Subject: [PATCH 06/10] Fixup failing unit test - we no longer using the EventArgs --- .../Cache/DistributedCacheBinderTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs index 6a263cb6ae..0b38e849c8 100644 --- a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs @@ -47,9 +47,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache new EventDefinition>(null, UserService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, UserService, new DeleteEventArgs(Enumerable.Empty())), - 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())), From 44b90d5993d377c5857e26183261a3947a68d23e Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Mon, 29 Mar 2021 11:08:14 +0100 Subject: [PATCH 07/10] Implment a Renaming & Renamed notification for DataType Container --- .../EntityContainerRenamedNotification.cs | 2 +- .../EntityContainerRenamingNotification.cs | 11 ++++++++++ .../Events/RenamedNotification.cs | 20 +++++++++++++++++++ .../Events/RenamingNotification.cs | 20 +++++++++++++++++++ .../Services/Implement/DataTypeService.cs | 9 ++++++++- 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Core/Events/EntityContainerRenamingNotification.cs create mode 100644 src/Umbraco.Core/Events/RenamedNotification.cs create mode 100644 src/Umbraco.Core/Events/RenamingNotification.cs diff --git a/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs b/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs index 3fac1fdd40..dc1b858bd9 100644 --- a/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs +++ b/src/Umbraco.Core/Events/EntityContainerRenamedNotification.cs @@ -2,7 +2,7 @@ using Umbraco.Cms.Core.Models; namespace Umbraco.Cms.Core.Events { - public class EntityContainerRenamedNotification : SavedNotification + public class EntityContainerRenamedNotification : RenamedNotification { public EntityContainerRenamedNotification(EntityContainer target, EventMessages messages) : base(target, messages) { diff --git a/src/Umbraco.Core/Events/EntityContainerRenamingNotification.cs b/src/Umbraco.Core/Events/EntityContainerRenamingNotification.cs new file mode 100644 index 0000000000..f2408a1faf --- /dev/null +++ b/src/Umbraco.Core/Events/EntityContainerRenamingNotification.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Models; + +namespace Umbraco.Cms.Core.Events +{ + public class EntityContainerRenamingNotification : RenamingNotification + { + public EntityContainerRenamingNotification(EntityContainer target, EventMessages messages) : base(target, messages) + { + } + } +} diff --git a/src/Umbraco.Core/Events/RenamedNotification.cs b/src/Umbraco.Core/Events/RenamedNotification.cs new file mode 100644 index 0000000000..81a568b6df --- /dev/null +++ b/src/Umbraco.Core/Events/RenamedNotification.cs @@ -0,0 +1,20 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.Collections.Generic; + +namespace Umbraco.Cms.Core.Events +{ + public abstract class RenamedNotification : EnumerableObjectNotification + { + protected RenamedNotification(T target, EventMessages messages) : base(target, messages) + { + } + + protected RenamedNotification(IEnumerable target, EventMessages messages) : base(target, messages) + { + } + + public IEnumerable Entities => Target; + } +} diff --git a/src/Umbraco.Core/Events/RenamingNotification.cs b/src/Umbraco.Core/Events/RenamingNotification.cs new file mode 100644 index 0000000000..f215a8ea54 --- /dev/null +++ b/src/Umbraco.Core/Events/RenamingNotification.cs @@ -0,0 +1,20 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.Collections.Generic; + +namespace Umbraco.Cms.Core.Events +{ + public abstract class RenamingNotification : CancelableEnumerableObjectNotification + { + protected RenamingNotification(T target, EventMessages messages) : base(target, messages) + { + } + + protected RenamingNotification(IEnumerable target, EventMessages messages) : base(target, messages) + { + } + + public IEnumerable Entities => Target; + } +} diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs index fd1b40eb2f..455f88a70f 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs @@ -223,10 +223,17 @@ namespace Umbraco.Cms.Core.Services.Implement container.Name = name; + var renamingEntityContainerNotification = new EntityContainerRenamingNotification(container, evtMsgs); + if (scope.Notifications.PublishCancelable(renamingEntityContainerNotification)) + { + scope.Complete(); + return OperationResult.Attempt.Cancel(evtMsgs, container); + } + _dataTypeContainerRepository.Save(container); scope.Complete(); - scope.Notifications.Publish(new EntityContainerRenamedNotification(container, evtMsgs)); + scope.Notifications.Publish(new EntityContainerRenamedNotification(container, evtMsgs).WithStateFrom(renamingEntityContainerNotification)); return OperationResult.Attempt.Succeed(OperationResultType.Success, evtMsgs, container); } From 4c50c57c1f34720fe76faaff6452ea429e304e6c Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Tue, 30 Mar 2021 08:48:45 +0100 Subject: [PATCH 08/10] Remove unused eventAggregator --- .../Services/Implement/DataTypeService.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs index 455f88a70f..4bb1e46c29 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs @@ -31,14 +31,13 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly ILocalizationService _localizationService; private readonly IShortStringHelper _shortStringHelper; private readonly IJsonSerializer _jsonSerializer; - private readonly IEventAggregator _eventAggregator; public DataTypeService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IDataTypeRepository dataTypeRepository, IDataTypeContainerRepository dataTypeContainerRepository, IAuditRepository auditRepository, IEntityRepository entityRepository, IContentTypeRepository contentTypeRepository, IIOHelper ioHelper, ILocalizedTextService localizedTextService, ILocalizationService localizationService, IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, IEventAggregator eventAggregator) + IJsonSerializer jsonSerializer) : base(provider, loggerFactory, eventMessagesFactory) { _dataTypeRepository = dataTypeRepository; @@ -51,7 +50,6 @@ namespace Umbraco.Cms.Core.Services.Implement _localizationService = localizationService; _shortStringHelper = shortStringHelper; _jsonSerializer = jsonSerializer; - _eventAggregator = eventAggregator; } #region Containers From 7b34b495afbd986ab07a9688b1587e2c4938ba4b Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Tue, 30 Mar 2021 09:25:34 +0100 Subject: [PATCH 09/10] Implement the events now as notifications for DataType Service --- .../Cache/DistributedCacheBinder_Handlers.cs | 18 +++++++----------- .../Cache/DistributedCacheBinderTests.cs | 3 --- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index 0782579497..a6b0dd73db 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -33,7 +33,9 @@ namespace Umbraco.Cms.Core.Cache INotificationHandler, INotificationHandler, INotificationHandler, - INotificationHandler + INotificationHandler, + INotificationHandler, + INotificationHandler { private List _unbinders; @@ -64,12 +66,6 @@ namespace Umbraco.Cms.Core.Cache _logger.LogInformation("Initializing Umbraco internal event handlers for cache refreshing."); - // bind to data type events - Bind(() => DataTypeService.Deleted += DataTypeService_Deleted, - () => DataTypeService.Deleted -= DataTypeService_Deleted); - Bind(() => DataTypeService.Saved += DataTypeService_Saved, - () => DataTypeService.Saved -= DataTypeService_Saved); - // bind to stylesheet events Bind(() => FileService.SavedStylesheet += FileService_SavedStylesheet, () => FileService.SavedStylesheet -= FileService_SavedStylesheet); @@ -191,15 +187,15 @@ namespace Umbraco.Cms.Core.Cache #region DataTypeService - private void DataTypeService_Saved(IDataTypeService sender, SaveEventArgs e) + public void Handle(DataTypeSavedNotification notification) { - foreach (var entity in e.SavedEntities) + foreach (var entity in notification.SavedEntities) _distributedCache.RefreshDataTypeCache(entity); } - private void DataTypeService_Deleted(IDataTypeService sender, DeleteEventArgs e) + public void Handle(DataTypeDeletedNotification notification) { - foreach (var entity in e.DeletedEntities) + foreach (var entity in notification.DeletedEntities) _distributedCache.RemoveDataTypeCache(entity); } diff --git a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs index 2d9bcf2c9d..80488e91b1 100644 --- a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs @@ -42,9 +42,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache var definitions = new IEventDefinition[] { - 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())), From 84d98f48c79489c82f611235e00bc37f602a3267 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 30 Mar 2021 11:14:50 +0200 Subject: [PATCH 10/10] Register notifications for DistributedCacheBinder --- .../Cache/DistributedCacheBinder_Handlers.cs | 8 ++++++-- .../Compose/NotificationsComposer.cs | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index a6b0dd73db..41195be9fe 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -189,14 +189,18 @@ namespace Umbraco.Cms.Core.Cache public void Handle(DataTypeSavedNotification notification) { - foreach (var entity in notification.SavedEntities) + foreach (IDataType entity in notification.SavedEntities) + { _distributedCache.RefreshDataTypeCache(entity); + } } public void Handle(DataTypeDeletedNotification notification) { - foreach (var entity in notification.DeletedEntities) + foreach (IDataType entity in notification.DeletedEntities) + { _distributedCache.RemoveDataTypeCache(entity); + } } #endregion diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs index be6539ac55..e9e7bf30af 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs @@ -78,7 +78,11 @@ namespace Umbraco.Cms.Core.Compose .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler(); // add notification handlers for auditing builder