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
bielu and Arkadiusz Biel authored Dec 2, 2024
1 parent b3d1533 commit 4c877df
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions uSync.BackOffice/Notifications/SyncScopedNotificationPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<INotificationHandler>
: ScopedNotificationPublisher<INotificationHandler>, IScopedNotificationPublisher
{
private readonly ILogger<SyncScopedNotificationPublisher> _logger;
private readonly IEventAggregator _eventAggregator;
Expand All @@ -43,6 +41,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 +81,6 @@ protected override void PublishScopedNotifications(IList<INotification> notifica
return Task.CompletedTask;
}
});

}
else
{
Expand All @@ -91,11 +100,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 4c877df

Please sign in to comment.