diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs
index fae26db8f7..0d22e4c83c 100644
--- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs
+++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs
@@ -75,10 +75,11 @@ namespace Umbraco.Cms.Core.Services.Implement
///
public void SaveStylesheet(IStylesheet stylesheet, int userId = Cms.Core.Constants.Security.SuperUserId)
{
- using (var scope = ScopeProvider.CreateScope())
+ using (IScope scope = ScopeProvider.CreateScope())
{
- var saveEventArgs = new SaveEventArgs(stylesheet);
- if (scope.Events.DispatchCancelable(SavingStylesheet, this, saveEventArgs))
+ EventMessages eventMessages = EventMessagesFactory.Get();
+ var savingNotification = new StylesheetSavingNotification(stylesheet, eventMessages);
+ if (scope.Notifications.PublishCancelable(savingNotification))
{
scope.Complete();
return;
@@ -86,8 +87,7 @@ namespace Umbraco.Cms.Core.Services.Implement
_stylesheetRepository.Save(stylesheet);
- saveEventArgs.CanCancel = false;
- scope.Events.Dispatch(SavedStylesheet, this, saveEventArgs);
+ scope.Notifications.Publish(new StylesheetSavedNotification(stylesheet, eventMessages).WithStateFrom(savingNotification));
Audit(AuditType.Save, userId, -1, "Stylesheet");
scope.Complete();
@@ -200,18 +200,18 @@ namespace Umbraco.Cms.Core.Services.Implement
///
public void SaveScript(IScript script, int userId = Cms.Core.Constants.Security.SuperUserId)
{
- using (var scope = ScopeProvider.CreateScope())
+ using (IScope scope = ScopeProvider.CreateScope())
{
- var saveEventArgs = new SaveEventArgs(script);
- if (scope.Events.DispatchCancelable(SavingScript, this, saveEventArgs))
+ EventMessages eventMessages = EventMessagesFactory.Get();
+ var savingNotification = new ScriptSavingNotification(script, eventMessages);
+ if (scope.Notifications.PublishCancelable(savingNotification))
{
scope.Complete();
return;
}
_scriptRepository.Save(script);
- saveEventArgs.CanCancel = false;
- scope.Events.Dispatch(SavedScript, this, saveEventArgs);
+ scope.Notifications.Publish(new ScriptSavedNotification(script, eventMessages).WithStateFrom(savingNotification));
Audit(AuditType.Save, userId, -1, "Script");
scope.Complete();
@@ -761,7 +761,7 @@ namespace Umbraco.Cms.Core.Services.Implement
if (snippetName.IsNullOrWhiteSpace() == false)
{
//create the file
- var snippetPathAttempt = TryGetSnippetPath(snippetName);
+ Attempt snippetPathAttempt = TryGetSnippetPath(snippetName);
if (snippetPathAttempt.Success == false)
{
throw new InvalidOperationException("Could not load snippet with name " + snippetName);
@@ -784,21 +784,25 @@ namespace Umbraco.Cms.Core.Services.Implement
}
}
- using (var scope = ScopeProvider.CreateScope())
+ using (IScope scope = ScopeProvider.CreateScope())
{
- var newEventArgs = new NewEventArgs(partialView, true, partialView.Alias, -1);
- if (scope.Events.DispatchCancelable(CreatingPartialView, this, newEventArgs))
+ EventMessages eventMessages = EventMessagesFactory.Get();
+ var creatingNotification = new PartialViewCreatingNotification(partialView, eventMessages);
+ if (scope.Notifications.PublishCancelable(creatingNotification))
{
scope.Complete();
return Attempt.Fail();
}
- var repository = GetPartialViewRepository(partialViewType);
- if (partialViewContent != null) partialView.Content = partialViewContent;
+ IPartialViewRepository repository = GetPartialViewRepository(partialViewType);
+ if (partialViewContent != null)
+ {
+ partialView.Content = partialViewContent;
+ }
+
repository.Save(partialView);
- newEventArgs.CanCancel = false;
- scope.Events.Dispatch(CreatedPartialView, this, newEventArgs);
+ scope.Notifications.Publish(new PartialViewCreatedNotification(partialView, eventMessages).WithStateFrom(creatingNotification));
Audit(AuditType.Save, userId, -1, partialViewType.ToString());
@@ -820,26 +824,26 @@ namespace Umbraco.Cms.Core.Services.Implement
private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int userId = Cms.Core.Constants.Security.SuperUserId)
{
- using (var scope = ScopeProvider.CreateScope())
+ using (IScope scope = ScopeProvider.CreateScope())
{
- var repository = GetPartialViewRepository(partialViewType);
- var partialView = repository.Get(path);
+ IPartialViewRepository repository = GetPartialViewRepository(partialViewType);
+ IPartialView partialView = repository.Get(path);
if (partialView == null)
{
scope.Complete();
return true;
}
- var deleteEventArgs = new DeleteEventArgs(partialView);
- if (scope.Events.DispatchCancelable(DeletingPartialView, this, deleteEventArgs))
+ EventMessages eventMessages = EventMessagesFactory.Get();
+ var deletingNotification = new PartialViewDeletingNotification(partialView, eventMessages);
+ if (scope.Notifications.PublishCancelable(deletingNotification))
{
scope.Complete();
return false;
}
repository.Delete(partialView);
- deleteEventArgs.CanCancel = false;
- scope.Events.Dispatch(DeletedPartialView, this, deleteEventArgs);
+ scope.Notifications.Publish(new PartialViewDeletedNotification(partialView, eventMessages).WithStateFrom(deletingNotification));
Audit(AuditType.Delete, userId, -1, partialViewType.ToString());
scope.Complete();
@@ -860,20 +864,21 @@ namespace Umbraco.Cms.Core.Services.Implement
private Attempt SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = Cms.Core.Constants.Security.SuperUserId)
{
- using (var scope = ScopeProvider.CreateScope())
+ using (IScope scope = ScopeProvider.CreateScope())
{
- var saveEventArgs = new SaveEventArgs(partialView);
- if (scope.Events.DispatchCancelable(SavingPartialView, this, saveEventArgs))
+ EventMessages eventMessages = EventMessagesFactory.Get();
+ var savingNotification = new PartialViewSavingNotification(partialView, eventMessages);
+ if (scope.Notifications.PublishCancelable(savingNotification))
{
scope.Complete();
return Attempt.Fail();
}
- var repository = GetPartialViewRepository(partialViewType);
+ IPartialViewRepository repository = GetPartialViewRepository(partialViewType);
repository.Save(partialView);
- saveEventArgs.CanCancel = false;
+
Audit(AuditType.Save, userId, -1, partialViewType.ToString());
- scope.Events.Dispatch(SavedPartialView, this, saveEventArgs);
+ scope.Notifications.Publish(new PartialViewSavedNotification(partialView, eventMessages).WithStateFrom(savingNotification));
scope.Complete();
}
@@ -1064,59 +1069,5 @@ namespace Umbraco.Cms.Core.Services.Implement
}
// TODO: Method to change name and/or alias of view template
-
- #region Event Handlers
-
- ///
- /// Occurs before Save
- ///
- public static event TypedEventHandler> SavingScript;
-
- ///
- /// Occurs after Save
- ///
- public static event TypedEventHandler> SavedScript;
-
- ///
- /// Occurs before Save
- ///
- public static event TypedEventHandler> SavingStylesheet;
-
- ///
- /// Occurs after Save
- ///
- public static event TypedEventHandler> SavedStylesheet;
-
- ///
- /// Occurs before Save
- ///
- public static event TypedEventHandler> SavingPartialView;
-
- ///
- /// Occurs after Save
- ///
- public static event TypedEventHandler> SavedPartialView;
-
- ///
- /// Occurs before Create
- ///
- public static event TypedEventHandler> CreatingPartialView;
-
- ///
- /// Occurs after Create
- ///
- public static event TypedEventHandler> CreatedPartialView;
-
- ///
- /// Occurs before Delete
- ///
- public static event TypedEventHandler> DeletingPartialView;
-
- ///
- /// Occurs after Delete
- ///
- public static event TypedEventHandler> DeletedPartialView;
-
- #endregion
}
}
diff --git a/src/Umbraco.Infrastructure/Services/Notifications/StylesheetSavedNotification.cs b/src/Umbraco.Infrastructure/Services/Notifications/StylesheetSavedNotification.cs
new file mode 100644
index 0000000000..18d2465356
--- /dev/null
+++ b/src/Umbraco.Infrastructure/Services/Notifications/StylesheetSavedNotification.cs
@@ -0,0 +1,20 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details
+
+using System.Collections.Generic;
+using Umbraco.Cms.Core.Events;
+using Umbraco.Cms.Core.Models;
+
+namespace Umbraco.Cms.Infrastructure.Services.Notifications
+{
+ public class StylesheetSavedNotification : SavedNotification
+ {
+ public StylesheetSavedNotification(IStylesheet target, EventMessages messages) : base(target, messages)
+ {
+ }
+
+ public StylesheetSavedNotification(IEnumerable target, EventMessages messages) : base(target, messages)
+ {
+ }
+ }
+}
diff --git a/src/Umbraco.Infrastructure/Services/Notifications/StylesheetSavingNotification.cs b/src/Umbraco.Infrastructure/Services/Notifications/StylesheetSavingNotification.cs
new file mode 100644
index 0000000000..ccdb95870d
--- /dev/null
+++ b/src/Umbraco.Infrastructure/Services/Notifications/StylesheetSavingNotification.cs
@@ -0,0 +1,20 @@
+// Copyright (c) Umbraco.
+// See LICENSE for more details
+
+using System.Collections.Generic;
+using Umbraco.Cms.Core.Events;
+using Umbraco.Cms.Core.Models;
+
+namespace Umbraco.Cms.Infrastructure.Services.Notifications
+{
+ public class StylesheetSavingNotification : SavingNotification
+ {
+ public StylesheetSavingNotification(IStylesheet target, EventMessages messages) : base(target, messages)
+ {
+ }
+
+ public StylesheetSavingNotification(IEnumerable target, EventMessages messages) : base(target, messages)
+ {
+ }
+ }
+}