Files
Umbraco-CMS/src/Umbraco.Web/Components/NotificationsComponent.cs

68 lines
2.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Components;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
2018-03-27 10:04:07 +02:00
using Umbraco.Core.Services;
2017-12-28 09:18:09 +01:00
using Umbraco.Core.Services.Implement;
2018-03-27 10:04:07 +02:00
using Umbraco.Web._Legacy.Actions;
2018-03-27 10:04:07 +02:00
namespace Umbraco.Web.Components
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public sealed class NotificationsComponent : UmbracoComponentBase, IUmbracoCoreComponent
{
public void Initialize(INotificationService notificationService)
{
ContentService.SentToPublish += (sender, args) =>
notificationService.SendNotification(args.Entity, ActionToPublish.Instance);
//Send notifications for the published action
ContentService.Published += (sender, args) =>
2018-05-03 15:09:56 +02:00
{
foreach (var content in args.PublishedEntities)
notificationService.SendNotification(content, ActionPublish.Instance);
};
//Send notifications for the update and created actions
ContentService.Saved += (sender, args) =>
{
var newEntities = new List<IContent>();
var updatedEntities = new List<IContent>();
//need to determine if this is updating or if it is new
foreach (var entity in args.SavedEntities)
{
var dirty = (IRememberBeingDirty) entity;
if (dirty.WasPropertyDirty("Id"))
{
//it's new
newEntities.Add(entity);
}
else
{
//it's updating
updatedEntities.Add(entity);
}
}
notificationService.SendNotification(newEntities, ActionNew.Instance);
notificationService.SendNotification(updatedEntities, ActionUpdate.Instance);
};
//Send notifications for the delete action
ContentService.Deleted += (sender, args) =>
2018-05-03 15:09:56 +02:00
{
foreach (var content in args.DeletedEntities)
notificationService.SendNotification(content, ActionDelete.Instance);
};
2017-07-20 11:21:28 +02:00
//Send notifications for the unpublish action
2018-10-03 14:27:48 +02:00
ContentService.Unpublished += (sender, args) =>
2018-05-03 15:09:56 +02:00
{
foreach (var content in args.PublishedEntities)
2018-10-03 14:27:48 +02:00
notificationService.SendNotification(content, ActionUnpublish.Instance);
2018-05-03 15:09:56 +02:00
};
}
}
}