Moved files to core to enable reuse + use them

This commit is contained in:
Bjarke Berg
2021-03-18 09:43:00 +01:00
parent 2901cb10f8
commit c6d647149c
26 changed files with 69 additions and 56 deletions

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class CancelableEnumerableObjectNotification<T> : CancelableObjectNotification<IEnumerable<T>>
{

View File

@@ -1,9 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class CancelableObjectNotification<T> : ObjectNotification<T>, ICancelableNotification where T : class
{

View File

@@ -1,9 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class CopiedNotification<T> : ObjectNotification<T> where T : class
{

View File

@@ -1,9 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class CopyingNotification<T> : CancelableObjectNotification<T> where T : class
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class DeletedNotification<T> : EnumerableObjectNotification<T>
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class EnumerableObjectNotification<T> : ObjectNotification<IEnumerable<T>>
{

View File

@@ -55,6 +55,30 @@ namespace Umbraco.Cms.Core.Events
PublishNotification(notification);
Task.WaitAll(PublishNotificationAsync(notification));
}
public bool PublishCancelable<TCancelableNotification>(TCancelableNotification notification)
where TCancelableNotification : ICancelableNotification
{
if (notification == null)
{
throw new ArgumentNullException(nameof(notification));
}
Publish(notification);
return notification.Cancel;
}
public async Task<bool> PublishCancelableAsync<TCancelableNotification>(TCancelableNotification notification)
where TCancelableNotification : ICancelableNotification
{
if (notification == null)
{
throw new ArgumentNullException(nameof(notification));
}
await PublishAsync(notification);
return notification.Cancel;
}
}
/// <summary>

View File

@@ -29,5 +29,23 @@ namespace Umbraco.Cms.Core.Events
/// <param name="notification">The notification object.</param>
void Publish<TNotification>(TNotification notification)
where TNotification : INotification;
/// <summary>
/// Publishes a cancelable notification to the notification subscribers
/// </summary>
/// <typeparam name="TNotification">The type of notification being handled.</typeparam>
/// <param name="notification"></param>
/// <returns>True if the notification was cancelled by a subscriber, false otherwise</returns>
bool PublishCancelable<TCancelableNotification>(TCancelableNotification notification)
where TCancelableNotification : ICancelableNotification;
/// <summary>
/// Publishes a cancelable notification async to the notification subscribers
/// </summary>
/// <typeparam name="TNotification">The type of notification being handled.</typeparam>
/// <param name="notification"></param>
/// <returns>True if the notification was cancelled by a subscriber, false otherwise</returns>
Task<bool> PublishCancelableAsync<TCancelableNotification>(TCancelableNotification notification)
where TCancelableNotification : ICancelableNotification;
}
}

View File

@@ -3,7 +3,7 @@ using Umbraco.Cms.Core.Packaging;
namespace Umbraco.Cms.Core.Events
{
public class ImportedPackageNotification : INotification
public class ImportedPackageNotification : StatefulNotification
{
public ImportedPackageNotification(InstallationSummary installationSummary, IPackageInfo packageMetaData)

View File

@@ -2,7 +2,7 @@ using Umbraco.Cms.Core.Models.Packaging;
namespace Umbraco.Cms.Core.Events
{
public class ImportingPackageNotification : ICancelableNotification
public class ImportingPackageNotification : StatefulNotification, ICancelableNotification
{
public ImportingPackageNotification(string packageName, IPackageInfo packageMetaData)
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class MovedNotification<T> : ObjectNotification<IEnumerable<MoveEventInfo<T>>>
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class MovingNotification<T> : CancelableObjectNotification<IEnumerable<MoveEventInfo<T>>>
{

View File

@@ -1,9 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class ObjectNotification<T> : StatefulNotification where T : class
{

View File

@@ -1,9 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class RolledBackNotification<T> : ObjectNotification<T> where T : class
{

View File

@@ -1,9 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class RollingBackNotification<T> : CancelableObjectNotification<T> where T : class
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class SavedNotification<T> : EnumerableObjectNotification<T>
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class SavingNotification<T> : CancelableEnumerableObjectNotification<T>
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class SortedNotification<T> : EnumerableObjectNotification<T>
{

View File

@@ -2,9 +2,8 @@
// See LICENSE for more details.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class SortingNotification<T> : CancelableEnumerableObjectNotification<T>
{

View File

@@ -1,9 +1,8 @@
// Copyright (c) Umbraco.
using System.Collections.Generic;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Infrastructure.Services.Notifications
namespace Umbraco.Cms.Core.Events
{
public abstract class StatefulNotification : IStatefulNotification
{

View File

@@ -1,7 +1,4 @@
using System;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Core.Events
namespace Umbraco.Cms.Core.Events
{
/// <summary>
/// Used to notify that an Unattended install has completed

View File

@@ -11,7 +11,6 @@ using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Migrations.Install;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Core.Events;
namespace Umbraco.Cms.Core
{

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -120,13 +120,12 @@ namespace Umbraco.Cms.Core.Services.Implement
var compiledPackage = GetCompiledPackageInfo(packageFile);
if (compiledPackage == null) throw new InvalidOperationException("Could not read the package file " + packageFile);
// Trigger the Importing Package Notification
var notification = new ImportingPackageNotification(packageFile.Name, compiledPackage);
_eventAggregator.Publish(notification);
// Stop execution if event/user is cancelling it
if (notification.Cancel)
// Trigger the Importing Package Notification and stop execution if event/user is cancelling it
var importingPackageNotification = new ImportingPackageNotification(packageFile.Name, compiledPackage);
if (_eventAggregator.PublishCancelable(importingPackageNotification))
{
return new InstallationSummary { MetaData = compiledPackage };
}
var summary = _packageInstallation.InstallPackageData(packageDefinition, compiledPackage, userId);
@@ -135,7 +134,7 @@ namespace Umbraco.Cms.Core.Services.Implement
_auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'.");
// trigger the ImportedPackage event
_eventAggregator.Publish(new ImportedPackageNotification(summary, compiledPackage));
_eventAggregator.Publish(new ImportedPackageNotification(summary, compiledPackage).WithStateFrom(importingPackageNotification));
return summary;
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Infrastructure.Services.Notifications

View File

@@ -55,8 +55,6 @@ using Umbraco.Cms.Web.Common.Routing;
using Umbraco.Cms.Web.Common.Security;
using Umbraco.Cms.Web.Common.Templates;
using Umbraco.Cms.Web.Common.UmbracoContext;
using Umbraco.Core.Events;
using static Umbraco.Cms.Core.Cache.HttpContextRequestAppCache;
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;
namespace Umbraco.Extensions

View File

@@ -9,7 +9,6 @@ using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Core.Events;
using Umbraco.Extensions;
namespace Umbraco.Cms.Web.Common.Install