2016-09-01 19:06:08 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Components;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
2018-01-15 11:32:30 +01:00
|
|
|
|
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;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
2018-03-27 10:04:07 +02:00
|
|
|
|
namespace Umbraco.Web.Components
|
2016-09-01 19:06:08 +02:00
|
|
|
|
{
|
2016-10-07 14:34:55 +02:00
|
|
|
|
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
|
2016-09-01 19:06:08 +02:00
|
|
|
|
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);
|
|
|
|
|
|
};
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
2016-09-01 19:06:08 +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
|
|
|
|
};
|
2016-09-01 19:06:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|