Created new event structure (currently only implemented for Saving/Saved) and new events CollectionSaving, CollectionSaved.
Created new way to raise events and handle their cancellations. Everything is strongly typed so should make working with events much nicer for end users. Also ensures that the Sender is the object raising the event.
This commit is contained in:
59
src/Umbraco.Core/Events/CancellableObjectEventArgs.cs
Normal file
59
src/Umbraco.Core/Events/CancellableObjectEventArgs.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Security.Permissions;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Event args for a strongly typed object that can support cancellation
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[HostProtection(SecurityAction.LinkDemand, SharedState = true)]
|
||||
public class CancellableObjectEventArgs<T> : EventArgs, ICancellableObjectEventArgs
|
||||
{
|
||||
private bool _cancel;
|
||||
|
||||
public CancellableObjectEventArgs(T entity, bool canCancel)
|
||||
{
|
||||
Entity = entity;
|
||||
CanCancel = canCancel;
|
||||
}
|
||||
|
||||
public CancellableObjectEventArgs(T entity)
|
||||
: this(entity, true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flag to determine if this instance will support being cancellable
|
||||
/// </summary>
|
||||
public bool CanCancel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If this instance supports cancellation, this gets/sets the cancel value
|
||||
/// </summary>
|
||||
public bool Cancel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!CanCancel)
|
||||
{
|
||||
throw new InvalidOperationException("This event argument class does not support cancelling.");
|
||||
}
|
||||
return _cancel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!CanCancel)
|
||||
{
|
||||
throw new InvalidOperationException("This event argument class does not support cancelling.");
|
||||
}
|
||||
_cancel = value;
|
||||
}
|
||||
}
|
||||
|
||||
public T Entity { get; private set; }
|
||||
|
||||
}
|
||||
}
|
||||
49
src/Umbraco.Core/Events/EventExtensions.cs
Normal file
49
src/Umbraco.Core/Events/EventExtensions.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for cancellable event operations
|
||||
/// </summary>
|
||||
public static class EventExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Raises the event and returns a boolean value indicating if the event was cancelled
|
||||
/// </summary>
|
||||
/// <typeparam name="TSender"></typeparam>
|
||||
/// <typeparam name="TArgs"></typeparam>
|
||||
/// <param name="eventHandler"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="sender"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsRaisedEventCancelled<TSender, TArgs>(
|
||||
this TypedEventHandler<TSender, TArgs> eventHandler,
|
||||
TArgs args,
|
||||
TSender sender)
|
||||
where TArgs : ICancellableObjectEventArgs
|
||||
{
|
||||
if (eventHandler != null)
|
||||
eventHandler(sender, args);
|
||||
|
||||
return !args.Cancel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the event
|
||||
/// </summary>
|
||||
/// <typeparam name="TSender"></typeparam>
|
||||
/// <typeparam name="TArgs"></typeparam>
|
||||
/// <param name="eventHandler"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <param name="sender"></param>
|
||||
public static void RaiseEvent<TSender, TArgs>(
|
||||
this TypedEventHandler<TSender, TArgs> eventHandler,
|
||||
TArgs args,
|
||||
TSender sender)
|
||||
where TArgs : EventArgs
|
||||
{
|
||||
if (eventHandler != null)
|
||||
eventHandler(sender, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Umbraco.Core/Events/ICancellableObjectEventArgs.cs
Normal file
18
src/Umbraco.Core/Events/ICancellableObjectEventArgs.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for EventArgs clases to implement when they support cancelling operations
|
||||
/// </summary>
|
||||
public interface ICancellableObjectEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// If this instance supports cancellation, this gets/sets the cancel value
|
||||
/// </summary>
|
||||
bool Cancel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flag to determine if this instance will support being cancellable
|
||||
/// </summary>
|
||||
bool CanCancel { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
public class PublishingEventArgs : System.ComponentModel.CancelEventArgs
|
||||
public class PublishingEventArgs : System.ComponentModel.CancelEventArgs
|
||||
{
|
||||
public PublishingEventArgs()
|
||||
{
|
||||
IsAllRepublished = false;
|
||||
}
|
||||
public PublishingEventArgs()
|
||||
{
|
||||
IsAllRepublished = false;
|
||||
}
|
||||
|
||||
public PublishingEventArgs(bool isAllPublished)
|
||||
{
|
||||
IsAllRepublished = isAllPublished;
|
||||
}
|
||||
public PublishingEventArgs(bool isAllPublished)
|
||||
{
|
||||
IsAllRepublished = isAllPublished;
|
||||
}
|
||||
|
||||
public bool IsAllRepublished { get; private set; }
|
||||
}
|
||||
public bool IsAllRepublished { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,15 @@
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
public class SaveEventArgs : System.ComponentModel.CancelEventArgs { }
|
||||
public class SaveEventArgs<TEntity> : CancellableObjectEventArgs<TEntity>
|
||||
{
|
||||
public SaveEventArgs(TEntity entity, bool canCancel) : base(entity, canCancel)
|
||||
{
|
||||
}
|
||||
|
||||
public SaveEventArgs(TEntity entity) : base(entity)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/Umbraco.Core/Events/TypedEventHandler.cs
Normal file
7
src/Umbraco.Core/Events/TypedEventHandler.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Events
|
||||
{
|
||||
[Serializable]
|
||||
public delegate void TypedEventHandler<in TSender, in TEventArgs>(TSender sender, TEventArgs e);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
@@ -603,64 +604,56 @@ namespace Umbraco.Core.Services
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentRepository(uow))
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(content, e);
|
||||
if (!Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
|
||||
return false;
|
||||
|
||||
if (!e.Cancel)
|
||||
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
|
||||
if (content.ParentId != -1 && content.ParentId != -20 && HasPublishedVersion(content.ParentId) == false)
|
||||
{
|
||||
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
|
||||
if (content.ParentId != -1 && content.ParentId != -20 && HasPublishedVersion(content.ParentId) == false)
|
||||
{
|
||||
LogHelper.Info<ContentService>(
|
||||
string.Format(
|
||||
"Content '{0}' with Id '{1}' could not be published because its parent is not published.",
|
||||
content.Name, content.Id));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Content contains invalid property values and can therefore not be published - fire event?
|
||||
if (!content.IsValid())
|
||||
{
|
||||
LogHelper.Info<ContentService>(
|
||||
string.Format(
|
||||
"Content '{0}' with Id '{1}' could not be published because of invalid properties.",
|
||||
content.Name, content.Id));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Publish and then update the database with new status
|
||||
bool published = _publishingStrategy.Publish(content, userId);
|
||||
|
||||
//Since this is the Save and Publish method, the content should be saved even though the publish fails or isn't allowed
|
||||
SetWriter(content, userId);
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
|
||||
if (published)
|
||||
{
|
||||
var xml = content.ToXml();
|
||||
var poco = new ContentXmlDto { NodeId = content.Id, Xml = xml.ToString(SaveOptions.None) };
|
||||
var exists = uow.Database.FirstOrDefault<ContentXmlDto>("WHERE nodeId = @Id", new { Id = content.Id }) != null;
|
||||
int result = exists
|
||||
? uow.Database.Update(poco)
|
||||
: Convert.ToInt32(uow.Database.Insert(poco));
|
||||
|
||||
//Save xml to db and call following method to fire event through PublishingStrategy to update cache
|
||||
if (omitCacheRefresh == false)
|
||||
_publishingStrategy.PublishingFinalized(content);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(content, e);
|
||||
|
||||
Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId == -1 ? 0 : userId, content.Id);
|
||||
|
||||
return published;
|
||||
LogHelper.Info<ContentService>(
|
||||
string.Format(
|
||||
"Content '{0}' with Id '{1}' could not be published because its parent is not published.",
|
||||
content.Name, content.Id));
|
||||
return false;
|
||||
}
|
||||
|
||||
//Content contains invalid property values and can therefore not be published - fire event?
|
||||
if (!content.IsValid())
|
||||
{
|
||||
LogHelper.Info<ContentService>(
|
||||
string.Format(
|
||||
"Content '{0}' with Id '{1}' could not be published because of invalid properties.",
|
||||
content.Name, content.Id));
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
//Publish and then update the database with new status
|
||||
bool published = _publishingStrategy.Publish(content, userId);
|
||||
|
||||
//Since this is the Save and Publish method, the content should be saved even though the publish fails or isn't allowed
|
||||
SetWriter(content, userId);
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
|
||||
if (published)
|
||||
{
|
||||
var xml = content.ToXml();
|
||||
var poco = new ContentXmlDto { NodeId = content.Id, Xml = xml.ToString(SaveOptions.None) };
|
||||
var exists = uow.Database.FirstOrDefault<ContentXmlDto>("WHERE nodeId = @Id", new { Id = content.Id }) != null;
|
||||
int result = exists
|
||||
? uow.Database.Update(poco)
|
||||
: Convert.ToInt32(uow.Database.Insert(poco));
|
||||
|
||||
//Save xml to db and call following method to fire event through PublishingStrategy to update cache
|
||||
if (omitCacheRefresh == false)
|
||||
_publishingStrategy.PublishingFinalized(content);
|
||||
}
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId == -1 ? 0 : userId, content.Id);
|
||||
|
||||
return published;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -674,26 +667,21 @@ namespace Umbraco.Core.Services
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentRepository(uow))
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(content, e);
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
|
||||
return;
|
||||
|
||||
SetWriter(content, userId);
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
SetWriter(content, userId);
|
||||
//Only change the publish state if the "previous" version was actually published
|
||||
if (content.Published)
|
||||
content.ChangePublishedState(false);
|
||||
|
||||
//Only change the publish state if the "previous" version was actually published
|
||||
if (content.Published)
|
||||
content.ChangePublishedState(false);
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
|
||||
if (Saved != null)
|
||||
Saved(content, e);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Content performed by user", userId == -1 ? 0 : userId, content.Id);
|
||||
}
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Content performed by user", userId == -1 ? 0 : userId, content.Id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,44 +701,46 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
var containsNew = contents.Any(x => x.HasIdentity == false);
|
||||
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(contents, e);
|
||||
|
||||
if (!e.Cancel)
|
||||
if (CollectionSaving.IsRaisedEventCancelled(new SaveEventArgs<IEnumerable>(contents), this))
|
||||
return;
|
||||
|
||||
if (containsNew)
|
||||
{
|
||||
if (containsNew)
|
||||
foreach (var content in contents)
|
||||
{
|
||||
foreach (var content in contents)
|
||||
{
|
||||
SetWriter(content, userId);
|
||||
|
||||
//Only change the publish state if the "previous" version was actually published
|
||||
if (content.Published)
|
||||
content.ChangePublishedState(false);
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
|
||||
continue;
|
||||
|
||||
SetWriter(content, userId);
|
||||
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var content in contents)
|
||||
{
|
||||
if (Saving != null)
|
||||
Saving(content, e);
|
||||
//Only change the publish state if the "previous" version was actually published
|
||||
if (content.Published)
|
||||
content.ChangePublishedState(false);
|
||||
|
||||
SetWriter(content, userId);
|
||||
repository.AddOrUpdate(content);
|
||||
}
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(contents, e);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Bulk Save content performed by user", userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var content in contents)
|
||||
{
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
|
||||
continue;
|
||||
|
||||
SetWriter(content, userId);
|
||||
repository.AddOrUpdate(content);
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
|
||||
}
|
||||
}
|
||||
|
||||
CollectionSaved.RaiseEvent(new SaveEventArgs<IEnumerable>(contents, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Bulk Save content performed by user", userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -767,15 +757,14 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentRepository(uow))
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(contents, e);
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
if (!CollectionSaving.IsRaisedEventCancelled(new SaveEventArgs<IEnumerable>(contents), this))
|
||||
{
|
||||
foreach (var content in contents)
|
||||
{
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content.Value), this))
|
||||
continue;
|
||||
|
||||
SetWriter(content.Value, userId);
|
||||
|
||||
//Only change the publish state if the "previous" version was actually published
|
||||
@@ -784,11 +773,12 @@ namespace Umbraco.Core.Services
|
||||
|
||||
repository.AddOrUpdate(content.Value);
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IContent>(content.Value, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(contents, e);
|
||||
|
||||
CollectionSaved.RaiseEvent(new SaveEventArgs<IEnumerable>(contents, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Bulk Save (lazy) content performed by user", userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
}
|
||||
@@ -1348,12 +1338,22 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
|
||||
public static event TypedEventHandler<IContentService, SaveEventArgs<IContent>> Saving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<IContentService, SaveEventArgs<IContent>> Saved;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before saving a collection
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentService, SaveEventArgs<IEnumerable>> CollectionSaving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after saving a collection
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentService, SaveEventArgs<IEnumerable>> CollectionSaved;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Create
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -114,26 +115,21 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional id of the user saving the ContentType</param>
|
||||
public void Save(IContentType contentType, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(contentType, e);
|
||||
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(contentType), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
|
||||
{
|
||||
SetUser(contentType, userId);
|
||||
repository.AddOrUpdate(contentType);
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
|
||||
{
|
||||
SetUser(contentType, userId);
|
||||
repository.AddOrUpdate(contentType);
|
||||
uow.Commit();
|
||||
|
||||
uow.Commit();
|
||||
SavedContentType.RaiseEvent(new SaveEventArgs<IContentType>(contentType, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(contentType, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save ContentType performed by user"), userId == -1 ? 0 : userId, contentType.Id);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save ContentType performed by user"), userId == -1 ? 0 : userId, contentType.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,29 +139,28 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional id of the user saving the ContentType</param>
|
||||
public void Save(IEnumerable<IContentType> contentTypes, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(contentTypes, e);
|
||||
if (CollectionSaving.IsRaisedEventCancelled(new SaveEventArgs<IEnumerable>(contentTypes), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
|
||||
{
|
||||
foreach (var contentType in contentTypes)
|
||||
{
|
||||
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(contentType), this))
|
||||
continue;
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
|
||||
{
|
||||
foreach (var contentType in contentTypes)
|
||||
{
|
||||
SetUser(contentType, userId);
|
||||
repository.AddOrUpdate(contentType);
|
||||
}
|
||||
SetUser(contentType, userId);
|
||||
repository.AddOrUpdate(contentType);
|
||||
uow.Commit();
|
||||
|
||||
uow.Commit();
|
||||
SavedContentType.RaiseEvent(new SaveEventArgs<IContentType>(contentType, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(contentTypes, e);
|
||||
}
|
||||
CollectionSaved.RaiseEvent(new SaveEventArgs<IEnumerable>(contentTypes, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save ContentTypes performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save ContentTypes performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,28 +174,28 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the User saving the ContentTypes</param>
|
||||
public void Save(IEnumerable<Lazy<IContentType>> contentTypes, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(contentTypes, e);
|
||||
if (CollectionSaving.IsRaisedEventCancelled(new SaveEventArgs<IEnumerable>(contentTypes), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
|
||||
{
|
||||
foreach (var content in contentTypes)
|
||||
{
|
||||
if (SavingContentType.IsRaisedEventCancelled(new SaveEventArgs<IContentType>(content.Value), this))
|
||||
continue;
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateContentTypeRepository(uow))
|
||||
{
|
||||
foreach (var content in contentTypes)
|
||||
{
|
||||
content.Value.CreatorId = 0;
|
||||
repository.AddOrUpdate(content.Value);
|
||||
uow.Commit();
|
||||
}
|
||||
content.Value.CreatorId = 0;
|
||||
repository.AddOrUpdate(content.Value);
|
||||
uow.Commit();
|
||||
|
||||
if (Saved != null)
|
||||
Saved(contentTypes, e);
|
||||
}
|
||||
SavedContentType.RaiseEvent(new SaveEventArgs<IContentType>(content.Value, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save (lazy) ContentTypes performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
CollectionSaved.RaiseEvent(new SaveEventArgs<IEnumerable>(contentTypes, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save (lazy) ContentTypes performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -337,26 +332,20 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the user saving the MediaType</param>
|
||||
public void Save(IMediaType mediaType, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(mediaType, e);
|
||||
if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(mediaType), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
|
||||
{
|
||||
SetUser(mediaType, userId);
|
||||
repository.AddOrUpdate(mediaType);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
|
||||
{
|
||||
SetUser(mediaType, userId);
|
||||
repository.AddOrUpdate(mediaType);
|
||||
uow.Commit();
|
||||
SavedMediaType.RaiseEvent(new SaveEventArgs<IMediaType>(mediaType, false), this);
|
||||
}
|
||||
|
||||
|
||||
if (Saved != null)
|
||||
Saved(mediaType, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save MediaType performed by user"), userId == -1 ? 0 : userId, mediaType.Id);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save MediaType performed by user"), userId == -1 ? 0 : userId, mediaType.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -366,29 +355,29 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the user savging the MediaTypes</param>
|
||||
public void Save(IEnumerable<IMediaType> mediaTypes, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(mediaTypes, e);
|
||||
if (CollectionSaving.IsRaisedEventCancelled(new SaveEventArgs<IEnumerable>(mediaTypes), this))
|
||||
return;
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
|
||||
{
|
||||
|
||||
foreach (var mediaType in mediaTypes)
|
||||
{
|
||||
SetUser(mediaType, userId);
|
||||
repository.AddOrUpdate(mediaType);
|
||||
}
|
||||
uow.Commit();
|
||||
foreach (var mediaType in mediaTypes)
|
||||
{
|
||||
if (SavingMediaType.IsRaisedEventCancelled(new SaveEventArgs<IMediaType>(mediaType), this))
|
||||
return;
|
||||
|
||||
SetUser(mediaType, userId);
|
||||
repository.AddOrUpdate(mediaType);
|
||||
uow.Commit();
|
||||
|
||||
if (Saved != null)
|
||||
Saved(mediaTypes, e);
|
||||
}
|
||||
SavedMediaType.RaiseEvent(new SaveEventArgs<IMediaType>(mediaType, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save MediaTypes performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
CollectionSaved.RaiseEvent(new SaveEventArgs<IEnumerable>(mediaTypes, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save MediaTypes performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -569,12 +558,34 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
public static event TypedEventHandler<IContentTypeService, SaveEventArgs<IContentType>> SavingContentType;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<IContentTypeService, SaveEventArgs<IContentType>> SavedContentType;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentTypeService, SaveEventArgs<IMediaType>> SavingMediaType;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentTypeService, SaveEventArgs<IMediaType>> SavedMediaType;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before saving a collection
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentTypeService, SaveEventArgs<IEnumerable>> CollectionSaving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after saving a collection
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IContentTypeService, SaveEventArgs<IEnumerable>> CollectionSaved;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -104,25 +104,20 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Id of the user issueing the save</param>
|
||||
public void Save(IDataTypeDefinition dataTypeDefinition, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(dataTypeDefinition, e);
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
{
|
||||
dataTypeDefinition.CreatorId = userId > -1 ? userId : 0;
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateDataTypeDefinitionRepository(uow))
|
||||
{
|
||||
dataTypeDefinition.CreatorId = userId > -1 ? userId : 0;
|
||||
repository.AddOrUpdate(dataTypeDefinition);
|
||||
uow.Commit();
|
||||
Saved.RaiseEvent(new SaveEventArgs<IDataTypeDefinition>(dataTypeDefinition, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(dataTypeDefinition, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save DataTypeDefinition performed by user"), userId == -1 ? 0 : userId, dataTypeDefinition.Id);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save DataTypeDefinition performed by user"), userId == -1 ? 0 : userId, dataTypeDefinition.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -212,12 +207,12 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
public static event TypedEventHandler<IDataTypeService, SaveEventArgs<IDataTypeDefinition>> Saving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<IDataTypeService, SaveEventArgs<IDataTypeDefinition>> Saved;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -65,24 +65,19 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void SaveStylesheet(Stylesheet stylesheet, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(stylesheet, e);
|
||||
if (SavingStylesheet.IsRaisedEventCancelled(new SaveEventArgs<Stylesheet>(stylesheet), this))
|
||||
return;
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(stylesheet);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(stylesheet);
|
||||
uow.Commit();
|
||||
SavedStylesheet.RaiseEvent(new SaveEventArgs<Stylesheet>(stylesheet, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(stylesheet, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save Stylesheet performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save Stylesheet performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -156,24 +151,19 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void SaveScript(Script script, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(script, e);
|
||||
if (SavingScript.IsRaisedEventCancelled(new SaveEventArgs<Script>(script), this))
|
||||
return;
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateScriptRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(script);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateScriptRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(script);
|
||||
uow.Commit();
|
||||
SavedScript.RaiseEvent(new SaveEventArgs<Script>(script, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(script, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save Script performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save Script performed by user"), userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -248,24 +238,19 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId"></param>
|
||||
public void SaveTemplate(ITemplate template, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(template, e);
|
||||
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(template), this))
|
||||
return;
|
||||
|
||||
var uow = _dataUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateTemplateRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(template);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _dataUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateTemplateRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(template);
|
||||
uow.Commit();
|
||||
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(template, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(template, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save Template performed by user"), userId == -1 ? 0 : userId, template.Id);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save Template performed by user"), userId == -1 ? 0 : userId, template.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -324,12 +309,33 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<ITemplate>> SavingTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<ITemplate>> SavedTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<Script>> SavingScript;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<Script>> SavedScript;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<Stylesheet>> SavingStylesheet;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<Stylesheet>> SavedStylesheet;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -138,25 +138,20 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional id of the user saving the dictionary item</param>
|
||||
public void Save(IDictionaryItem dictionaryItem, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(dictionaryItem, e);
|
||||
if (SavingDictionaryItem.IsRaisedEventCancelled(new SaveEventArgs<IDictionaryItem>(dictionaryItem), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateDictionaryRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateDictionaryRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(dictionaryItem);
|
||||
uow.Commit();
|
||||
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(dictionaryItem, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(dictionaryItem, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save DictionaryItem performed by user", userId == -1 ? 0 : userId,
|
||||
dictionaryItem.Id);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, "Save DictionaryItem performed by user", userId == -1 ? 0 : userId,
|
||||
dictionaryItem.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -237,24 +232,19 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional id of the user saving the language</param>
|
||||
public void Save(ILanguage language, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(language, e);
|
||||
if (SavingLanguage.IsRaisedEventCancelled(new SaveEventArgs<ILanguage>(language), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateLanguageRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(language);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateLanguageRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(language);
|
||||
uow.Commit();
|
||||
SavedLanguage.RaiseEvent(new SaveEventArgs<ILanguage>(language, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(language, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Language performed by user", userId == -1 ? 0 : userId, language.Id);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, "Save Language performed by user", userId == -1 ? 0 : userId, language.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -299,12 +289,22 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<IDictionaryItem>> SavingDictionaryItem;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<IDictionaryItem>> SavedDictionaryItem;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<ILanguage>> SavingLanguage;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<ILocalizationService, SaveEventArgs<ILanguage>> SavedLanguage;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -114,24 +114,19 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="userId">Optional Id of the user deleting the macro</param>
|
||||
public void Save(IMacro macro, int userId = -1)
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(macro, e);
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMacro>(macro), this))
|
||||
return;
|
||||
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMacroRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(macro);
|
||||
uow.Commit();
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMacroRepository(uow))
|
||||
{
|
||||
repository.AddOrUpdate(macro);
|
||||
uow.Commit();
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMacro>(macro, false), this);
|
||||
}
|
||||
|
||||
if (Saved != null)
|
||||
Saved(macro, e);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Macro performed by user", userId > -1 ? userId : 0, -1);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, "Save Macro performed by user", userId > -1 ? userId : 0, -1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -167,12 +162,12 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
public static event TypedEventHandler<IMacroService, SaveEventArgs<IMacro>> Saving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<IMacroService, SaveEventArgs<IMacro>> Saved;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
@@ -340,19 +341,16 @@ namespace Umbraco.Core.Services
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMediaRepository(uow))
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(media, e);
|
||||
|
||||
if (!e.Cancel)
|
||||
{
|
||||
SetUser(media, userId);
|
||||
repository.AddOrUpdate(media);
|
||||
uow.Commit();
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(media), this))
|
||||
return;
|
||||
|
||||
SetUser(media, userId);
|
||||
repository.AddOrUpdate(media);
|
||||
uow.Commit();
|
||||
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(media, false), this);
|
||||
|
||||
if (Saved != null)
|
||||
Saved(media, e);
|
||||
}
|
||||
Audit.Add(AuditTypes.Save, "Save Media performed by user", media.CreatorId, media.Id);
|
||||
}
|
||||
}
|
||||
@@ -367,24 +365,24 @@ namespace Umbraco.Core.Services
|
||||
var uow = _uowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateMediaRepository(uow))
|
||||
{
|
||||
var e = new SaveEventArgs();
|
||||
if (Saving != null)
|
||||
Saving(medias, e);
|
||||
if (CollectionSaving.IsRaisedEventCancelled(new SaveEventArgs<IEnumerable>(medias), this))
|
||||
return;
|
||||
|
||||
if (!e.Cancel)
|
||||
foreach (var media in medias)
|
||||
{
|
||||
foreach (var media in medias)
|
||||
{
|
||||
SetUser(media, userId);
|
||||
repository.AddOrUpdate(media);
|
||||
}
|
||||
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IMedia>(media), this))
|
||||
continue;
|
||||
|
||||
SetUser(media, userId);
|
||||
repository.AddOrUpdate(media);
|
||||
uow.Commit();
|
||||
|
||||
if (Saved != null)
|
||||
Saved(medias, e);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Media items performed by user", userId == -1 ? 0 : userId, -1);
|
||||
Saved.RaiseEvent(new SaveEventArgs<IMedia>(media, false), this);
|
||||
}
|
||||
|
||||
CollectionSaved.RaiseEvent(new SaveEventArgs<IEnumerable>(medias, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Save, "Save Media items performed by user", userId == -1 ? 0 : userId, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,12 +440,22 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saving;
|
||||
public static event TypedEventHandler<IMediaService, SaveEventArgs<IMedia>> Saving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
public static event EventHandler<SaveEventArgs> Saved;
|
||||
public static event TypedEventHandler<IMediaService, SaveEventArgs<IMedia>> Saved;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before saving a collection
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMediaService, SaveEventArgs<IEnumerable>> CollectionSaving;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after saving a collection
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMediaService, SaveEventArgs<IEnumerable>> CollectionSaved;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Create
|
||||
|
||||
@@ -120,6 +120,10 @@
|
||||
<Compile Include="Events\ContentCacheEventArgs.cs" />
|
||||
<Compile Include="Events\CopyEventArgs.cs" />
|
||||
<Compile Include="Events\DeleteEventArgs.cs" />
|
||||
<Compile Include="Events\CancellableObjectEventArgs.cs" />
|
||||
<Compile Include="Events\EventExtensions.cs" />
|
||||
<Compile Include="Events\ICancellableObjectEventArgs.cs" />
|
||||
<Compile Include="Events\TypedEventHandler.cs" />
|
||||
<Compile Include="Events\PublishingEventArgs.cs" />
|
||||
<Compile Include="Events\MoveEventArgs.cs" />
|
||||
<Compile Include="Events\NewEventArgs.cs" />
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Umbraco.Tests.Services
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
|
||||
//this ensures its reset
|
||||
PluginManager.Current = new PluginManager();
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
CreateTestData();
|
||||
}
|
||||
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user