Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add state to cancellable events #686

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}