Skip to content

Commit

Permalink
add state to cancellable events (#686)
Browse files Browse the repository at this point in the history
Co-authored-by: Arkadiusz Biel <a.biel@ry.com>
  • Loading branch information
2 people authored and KevinJump committed Dec 4, 2024
1 parent b98ba07 commit ce4ea97
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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.Interfaces;

namespace uSync.BackOffice.Notifications;

internal class SyncScopedNotificationPublisher
: ScopedNotificationPublisher<INotificationHandler>
: ScopedNotificationPublisher<INotificationHandler>, IScopedNotificationPublisher
{
private readonly ILogger<SyncScopedNotificationPublisher> _logger;
private readonly IEventAggregator _eventAggregator;
Expand All @@ -43,6 +43,18 @@ public SyncScopedNotificationPublisher(
_uSyncEventService = uSyncEventService;
}

bool IScopedNotificationPublisher.PublishCancelable(ICancelableNotification notification)
{
SetSingleNotificationState(notification);
return base.PublishCancelable(notification);
}

Task<bool> IScopedNotificationPublisher.PublishCancelableAsync(ICancelableNotification notification)
{
SetSingleNotificationState(notification);
return base.PublishCancelableAsync(notification);
}

protected override void PublishScopedNotifications(IList<INotification> notifications)
{
if (notifications.Count == 0) return;
Expand Down Expand Up @@ -71,7 +83,6 @@ protected override void PublishScopedNotifications(IList<INotification> notifica
return Task.CompletedTask;
}
});

}
else
{
Expand All @@ -91,11 +102,16 @@ private void SetNotificationStates(IList<INotification> 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;
}
}
}
}

0 comments on commit ce4ea97

Please sign in to comment.