diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index e8479de307..a1071b71f0 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -23,7 +23,15 @@ namespace Umbraco.Cms.Core.Cache INotificationHandler, INotificationHandler, INotificationHandler, - INotificationHandler + INotificationHandler, + INotificationHandler, + INotificationHandler, + INotificationHandler, + INotificationHandler, + INotificationHandler, + INotificationHandler, + INotificationHandler, + INotificationHandler { private List _unbinders; @@ -54,16 +62,6 @@ namespace Umbraco.Cms.Core.Cache _logger.LogInformation("Initializing Umbraco internal event handlers for cache refreshing."); - // bind to user and user group events - Bind(() => UserService.SavedUserGroup += UserService_SavedUserGroup, - () => UserService.SavedUserGroup -= UserService_SavedUserGroup); - Bind(() => UserService.DeletedUserGroup += UserService_DeletedUserGroup, - () => UserService.DeletedUserGroup -= UserService_DeletedUserGroup); - Bind(() => UserService.SavedUser += UserService_SavedUser, - () => UserService.SavedUser -= UserService_SavedUser); - Bind(() => UserService.DeletedUser += UserService_DeletedUser, - () => UserService.DeletedUser -= UserService_DeletedUser); - // bind to data type events Bind(() => DataTypeService.Deleted += DataTypeService_Deleted, () => DataTypeService.Deleted -= DataTypeService_Deleted); @@ -103,10 +101,6 @@ namespace Umbraco.Cms.Core.Cache () => MacroService.Deleted -= MacroService_Deleted); // bind to member events - Bind(() => MemberService.Saved += MemberService_Saved, - () => MemberService.Saved -= MemberService_Saved); - Bind(() => MemberService.Deleted += MemberService_Deleted, - () => MemberService.Deleted -= MemberService_Deleted); Bind(() => MemberGroupService.Saved += MemberGroupService_Saved, () => MemberGroupService.Saved -= MemberGroupService_Saved); Bind(() => MemberGroupService.Deleted += MemberGroupService_Deleted, @@ -126,12 +120,6 @@ namespace Umbraco.Cms.Core.Cache //Bind(() => ContentService.DeletedBlueprint += ContentService_DeletedBlueprint, // () => ContentService.DeletedBlueprint -= ContentService_DeletedBlueprint); - // bind to public access events - Bind(() => PublicAccessService.Saved += PublicAccessService_Saved, - () => PublicAccessService.Saved -= PublicAccessService_Saved); - Bind(() => PublicAccessService.Deleted += PublicAccessService_Deleted, - () => PublicAccessService.Deleted -= PublicAccessService_Deleted); - // bind to relation type events Bind(() => RelationService.SavedRelationType += RelationService_SavedRelationType, () => RelationService.SavedRelationType -= RelationService_SavedRelationType); @@ -141,14 +129,15 @@ namespace Umbraco.Cms.Core.Cache #region PublicAccessService - private void PublicAccessService_Saved(IPublicAccessService sender, SaveEventArgs e) + public void Handle(PublicAccessEntrySavedNotification notification) { _distributedCache.RefreshPublicAccess(); } - private void PublicAccessService_Deleted(IPublicAccessService sender, DeleteEventArgs e) + public void Handle(PublicAccessEntryDeletedNotification notification) { _distributedCache.RefreshPublicAccess(); + } #endregion @@ -293,29 +282,36 @@ namespace Umbraco.Cms.Core.Cache #region UserService - private void UserService_SavedUser(IUserService sender, SaveEventArgs e) + public void Handle(UserSavedNotification notification) { - foreach (var entity in e.SavedEntities) + foreach (IUser entity in notification.SavedEntities) + { _distributedCache.RefreshUserCache(entity.Id); + } } - private void UserService_DeletedUser(IUserService sender, DeleteEventArgs e) + public void Handle(UserDeletedNotification notification) { - foreach (var entity in e.DeletedEntities) + foreach (IUser entity in notification.DeletedEntities) + { _distributedCache.RemoveUserCache(entity.Id); + } } - private void UserService_SavedUserGroup(IUserService sender, SaveEventArgs e) + public void Handle(UserGroupWithUsersSavedNotification notification) { - foreach (var entity in e.SavedEntities) + foreach (UserGroupWithUsers entity in notification.SavedEntities) + { _distributedCache.RefreshUserGroupCache(entity.UserGroup.Id); + } } - private void UserService_DeletedUserGroup(IUserService sender, DeleteEventArgs e) + public void Handle(UserGroupDeletedNotification notification) { - - foreach (var entity in e.DeletedEntities) + foreach (IUserGroup entity in notification.DeletedEntities) + { _distributedCache.RemoveUserGroupCache(entity.Id); + } } #endregion @@ -377,14 +373,14 @@ namespace Umbraco.Cms.Core.Cache #region MemberService - private void MemberService_Deleted(IMemberService sender, DeleteEventArgs e) + public void Handle(MemberDeletedNotification notification) { - _distributedCache.RemoveMemberCache(e.DeletedEntities.ToArray()); + _distributedCache.RemoveMemberCache(notification.DeletedEntities.ToArray()); } - private void MemberService_Saved(IMemberService sender, SaveEventArgs e) + public void Handle(MemberSavedNotification notification) { - _distributedCache.RefreshMemberCache(e.SavedEntities.ToArray()); + _distributedCache.RefreshMemberCache(notification.SavedEntities.ToArray()); } #endregion diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs index fd35a5111f..be6539ac55 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs @@ -70,7 +70,15 @@ namespace Umbraco.Cms.Core.Compose .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler(); // add notification handlers for auditing builder diff --git a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs index 794fd09934..aba40333b0 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/MemberService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -796,7 +796,6 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { scope.Notifications.Publish(new MemberSavedNotification(member, evtMsgs).WithStateFrom(savingNotification)); - scope.Events.Dispatch(Saved, this, new SaveEventArgs(member, false)); } Audit(AuditType.Save, 0, member.Id); @@ -835,7 +834,6 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { scope.Notifications.Publish(new MemberSavedNotification(membersA, evtMsgs).WithStateFrom(savingNotification)); - scope.Events.Dispatch(Saved, this, new SaveEventArgs(membersA, false)); } Audit(AuditType.Save, 0, -1, "Save multiple Members"); @@ -877,7 +875,6 @@ namespace Umbraco.Cms.Core.Services.Implement // a member has no descendants _memberRepository.Delete(member); scope.Notifications.Publish(new MemberDeletedNotification(member, evtMsgs).WithState(notificationState)); - scope.Events.Dispatch(Deleted, this, new DeleteEventArgs(member, false)); // media files deleted by QueuingEventDispatcher } @@ -1073,16 +1070,6 @@ namespace Umbraco.Cms.Core.Services.Implement #endregion - #region Event Handlers - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for MemberDeletedNotification instead.")] - public static event TypedEventHandler> Deleted; - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for MemberSavedNotification instead.")] - public static event TypedEventHandler> Saved; - - #endregion - #region Membership diff --git a/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs b/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs index 3d44ed2cf8..b6d12784c6 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/PublicAccessService.cs @@ -11,7 +11,7 @@ using Umbraco.Extensions; namespace Umbraco.Cms.Core.Services.Implement { - public class PublicAccessService : RepositoryService, IPublicAccessService + internal class PublicAccessService : RepositoryService, IPublicAccessService { private readonly IPublicAccessRepository _publicAccessRepository; @@ -115,7 +115,7 @@ namespace Umbraco.Cms.Core.Services.Implement { entry = _publicAccessRepository.GetMany().FirstOrDefault(x => x.ProtectedNodeId == content.Id); if (entry == null) - return OperationResult.Attempt.Cannot(evtMsgs); // causes rollback // causes rollback + return OperationResult.Attempt.Cannot(evtMsgs); // causes rollback var existingRule = entry.Rules.FirstOrDefault(x => x.RuleType == ruleType && x.RuleValue == ruleValue); if (existingRule == null) @@ -140,7 +140,6 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Complete(); scope.Notifications.Publish(new PublicAccessEntrySavedNotification(entry, evtMsgs).WithStateFrom(savingNotifiation)); - scope.Events.Dispatch(Saved, this, new SaveEventArgs(entry, false)); } return OperationResult.Attempt.Succeed(evtMsgs, entry); @@ -177,7 +176,6 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Complete(); scope.Notifications.Publish(new PublicAccessEntrySavedNotification(entry, evtMsgs).WithStateFrom(savingNotifiation)); - scope.Events.Dispatch(Saved, this, new SaveEventArgs(entry, false)); } return OperationResult.Attempt.Succeed(evtMsgs); @@ -204,7 +202,6 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Complete(); scope.Notifications.Publish(new PublicAccessEntrySavedNotification(entry, evtMsgs).WithStateFrom(savingNotifiation)); - scope.Events.Dispatch(Saved, this, new SaveEventArgs(entry, false)); } return OperationResult.Attempt.Succeed(evtMsgs); @@ -231,16 +228,9 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Complete(); scope.Notifications.Publish(new PublicAccessEntryDeletedNotification(entry, evtMsgs).WithStateFrom(deletingNotification)); - scope.Events.Dispatch(Deleted, this, new DeleteEventArgs(entry, false)); } return OperationResult.Attempt.Succeed(evtMsgs); } - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for PublicAccessEntrySavedNotification instead.")] - public static event TypedEventHandler> Saved; - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for PublicAccessEntryDeletedNotification instead.")] - public static event TypedEventHandler> Deleted; } } diff --git a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs index e29eeefc01..b7b52ae616 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/UserService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/UserService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data.Common; using System.Globalization; @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// /// Represents the UserService, which is an easy access to operations involving , and eventually Backoffice Users. /// - public class UserService : RepositoryService, IUserService + internal class UserService : RepositoryService, IUserService { private readonly IUserRepository _userRepository; private readonly IUserGroupRepository _userGroupRepository; @@ -142,7 +142,6 @@ namespace Umbraco.Cms.Core.Services.Implement _userRepository.Save(user); scope.Notifications.Publish(new UserSavedNotification(user, evtMsgs).WithStateFrom(savingNotification)); - scope.Events.Dispatch(SavedUser, this, new SaveEventArgs(user, false)); scope.Complete(); } @@ -256,7 +255,6 @@ namespace Umbraco.Cms.Core.Services.Implement _userRepository.Delete(user); scope.Notifications.Publish(new UserDeletedNotification(user, evtMsgs).WithStateFrom(deletingNotification)); - scope.Events.Dispatch(DeletedUser, this, new DeleteEventArgs(user, false)); scope.Complete(); } } @@ -300,7 +298,6 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { scope.Notifications.Publish(new UserSavedNotification(entity, evtMsgs).WithStateFrom(savingNotification)); - scope.Events.Dispatch(SavedUser, this, new SaveEventArgs(entity, false)); } scope.Complete(); @@ -354,7 +351,6 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { scope.Notifications.Publish(new UserSavedNotification(entitiesA, evtMsgs).WithStateFrom(savingNotification)); - scope.Events.Dispatch(SavedUser, this, new SaveEventArgs(entitiesA, false)); } //commit the whole lot in one go @@ -865,7 +861,6 @@ namespace Umbraco.Cms.Core.Services.Implement { scope.Notifications.Publish(new UserGroupSavedNotification(userGroup, evtMsgs).WithStateFrom(savingNotification)); scope.Notifications.Publish(new UserGroupWithUsersSavedNotification(userGroupWithUsers, evtMsgs).WithStateFrom(savingUserGroupWithUsersNotification)); - scope.Events.Dispatch(SavedUserGroup, this, new SaveEventArgs(new UserGroupWithUsers(userGroup, addedUsers, removedUsers), false)); } scope.Complete(); @@ -892,7 +887,6 @@ namespace Umbraco.Cms.Core.Services.Implement _userGroupRepository.Delete(userGroup); scope.Notifications.Publish(new UserGroupDeletedNotification(userGroup, evtMsgs).WithStateFrom(deletingNotification)); - scope.Events.Dispatch(DeletedUserGroup, this, new DeleteEventArgs(userGroup, false)); scope.Complete(); } @@ -1172,17 +1166,5 @@ namespace Umbraco.Cms.Core.Services.Implement } #endregion - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for UserSavedNotification instead.")] - public static event TypedEventHandler> SavedUser; - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for UserDeletedNotification instead.")] - public static event TypedEventHandler> DeletedUser; - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for UserGroupSavedNotification instead.")] - public static event TypedEventHandler> SavedUserGroup; - - [Obsolete("Will be removed in an upcoming version. Implement an INotificationHandler for UserGroupDeletedNotification instead.")] - public static event TypedEventHandler> DeletedUserGroup; } } diff --git a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs index 6a263cb6ae..b0d62778cf 100644 --- a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs @@ -42,11 +42,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache var definitions = new IEventDefinition[] { - new EventDefinition>(null, UserService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, UserService, new DeleteEventArgs(Enumerable.Empty())), - 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())), @@ -70,9 +65,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache new EventDefinition>(null, MacroService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, MacroService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, MemberService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, MemberService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, MemberGroupService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, MemberGroupService, new DeleteEventArgs(Enumerable.Empty())), @@ -80,9 +72,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache //new EventDefinition>(null, ContentService, new SaveEventArgs(Enumerable.Empty()), "SavedBlueprint"), //new EventDefinition>(null, ContentService, new DeleteEventArgs(Enumerable.Empty()), "DeletedBlueprint"), - new EventDefinition>(null, PublicAccessService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, PublicAccessService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, RelationService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, RelationService, new DeleteEventArgs(Enumerable.Empty())), diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs index 61334940e1..695a281d0a 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.Extensions.Logging; using NUnit.Framework; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.DependencyInjection; @@ -14,7 +13,6 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.Implement; using Umbraco.Cms.Core.Sync; -using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure.PublishedCache; using Umbraco.Cms.Infrastructure.Services.Notifications; using Umbraco.Cms.Infrastructure.Sync; @@ -55,7 +53,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler(); builder.AddNotificationHandler(); } @@ -76,18 +75,18 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping var user = (IUser)new User(GlobalSettings, "name", "email", "username", "rawPassword"); service.Save(user); - // global cache contains the entity + // User has been saved so the cache has been cleared of it var globalCached = (IUser)globalCache.Get(GetCacheIdKey(user.Id), () => null); + Assert.IsNull(globalCached); + // Get user again to load it into the cache again, this also ensure we don't modify the one that's in the cache. + user = service.GetUserById(user.Id); + + // global cache contains the entity + globalCached = (IUser)globalCache.Get(GetCacheIdKey(user.Id), () => null); Assert.IsNotNull(globalCached); Assert.AreEqual(user.Id, globalCached.Id); Assert.AreEqual("name", globalCached.Name); - // get user again - else we'd modify the one that's in the cache - user = service.GetUserById(user.Id); - - _distributedCacheBinder = new DistributedCacheBinder(new DistributedCache(ServerMessenger, CacheRefresherCollection), GetRequiredService(), GetRequiredService>()); - _distributedCacheBinder.BindEvents(true); - Assert.IsNull(scopeProvider.AmbientScope); using (IScope scope = scopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped)) {