From d53513347e870632897b71432731ba89b4c0fffe Mon Sep 17 00:00:00 2001 From: Arkadiusz Biel Date: Wed, 27 Nov 2024 13:01:28 +0000 Subject: [PATCH] add state to cancellable events --- .../SyncScopedNotificationPublisher.cs | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs b/uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs index 5fcc6f78..f0aee0df 100644 --- a/uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs +++ b/uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs @@ -3,20 +3,18 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; - using Microsoft.Extensions.Logging; - using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Infrastructure.HostedServices; - using uSync.BackOffice.Configuration; using uSync.BackOffice.Services; using uSync.BackOffice.SyncHandlers; namespace uSync.BackOffice.Notifications; + internal class SyncScopedNotificationPublisher - : ScopedNotificationPublisher + : ScopedNotificationPublisher, IScopedNotificationPublisher { private readonly ILogger _logger; private readonly IEventAggregator _eventAggregator; @@ -43,6 +41,18 @@ public SyncScopedNotificationPublisher( _uSyncEventService = uSyncEventService; } + bool IScopedNotificationPublisher.PublishCancelable(ICancelableNotification notification) + { + SetSingleNotificationState(notification); + return base.PublishCancelable(notification); + } + + Task IScopedNotificationPublisher.PublishCancelableAsync(ICancelableNotification notification) + { + SetSingleNotificationState(notification); + return base.PublishCancelableAsync(notification); + } + protected override void PublishScopedNotifications(IList notifications) { if (notifications.Count == 0) return; @@ -71,7 +81,6 @@ protected override void PublishScopedNotifications(IList notifica return Task.CompletedTask; } }); - } else { @@ -91,11 +100,16 @@ private void SetNotificationStates(IList notifications) { foreach (var notification in notifications) { - if (notification is StatefulNotification stateful) - { - stateful.State[uSync.EventStateKey] = true; - stateful.State[uSync.EventPausedKey] = _uSyncEventService.IsPaused; - } + SetSingleNotificationState(notification); + } + } + + private void SetSingleNotificationState(INotification notification) + { + if (notification is StatefulNotification stateful) + { + stateful.State[uSync.EventStateKey] = true; + stateful.State[uSync.EventPausedKey] = _uSyncEventService.IsPaused; } } -} +} \ No newline at end of file