diff --git a/src/Umbraco.Core/Services/NotificationService.cs b/src/Umbraco.Core/Services/NotificationService.cs
index 300b34d32f..a750cd77fc 100644
--- a/src/Umbraco.Core/Services/NotificationService.cs
+++ b/src/Umbraco.Core/Services/NotificationService.cs
@@ -320,8 +320,13 @@ namespace Umbraco.Core.Services
{
try
{
- var sender = new SmtpClient();
- sender.Send(mail);
+ using (mail)
+ {
+ using (var sender = new SmtpClient())
+ {
+ sender.Send(mail);
+ }
+ }
}
catch (Exception ex)
{
diff --git a/src/Umbraco.Web/NotificationServiceExtensions.cs b/src/Umbraco.Web/NotificationServiceExtensions.cs
new file mode 100644
index 0000000000..8404a99a0e
--- /dev/null
+++ b/src/Umbraco.Web/NotificationServiceExtensions.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Globalization;
+using Umbraco.Core;
+using Umbraco.Core.Configuration;
+using Umbraco.Core.Models.EntityBase;
+using Umbraco.Core.Services;
+using umbraco;
+using umbraco.BusinessLogic.Actions;
+using umbraco.interfaces;
+
+namespace Umbraco.Web
+{
+ internal static class NotificationServiceExtensions
+ {
+ internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, ApplicationContext applicationContext)
+ {
+ if (global::Umbraco.Web.UmbracoContext.Current == null) return;
+ service.SendNotification(entity, action, global::Umbraco.Web.UmbracoContext.Current);
+ }
+
+ internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext)
+ {
+ if (umbracoContext == null) return;
+ service.SendNotification(entity, action, umbracoContext, umbracoContext.Application);
+ }
+
+ internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext, ApplicationContext applicationContext)
+ {
+ if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
+ if (applicationContext == null) throw new ArgumentNullException("applicationContext");
+
+ var user = umbracoContext.Security.CurrentUser;
+ applicationContext.Services.NotificationService.SendNotifications(
+ user,
+ entity,
+ action.Letter.ToString(CultureInfo.InvariantCulture),
+ ui.Text("actions", action.Alias),
+ umbracoContext.HttpContext,
+ (mailingUser, strings) => ui.Text("notifications", "mailSubject", strings, mailingUser),
+ (mailingUser, strings) => UmbracoConfig.For.UmbracoSettings().Content.DisableHtmlEmail
+ ? ui.Text("notifications", "mailBody", strings, mailingUser)
+ : ui.Text("notifications", "mailBodyHtml", strings, mailingUser));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Strategies/NotificationsHandler.cs b/src/Umbraco.Web/Strategies/NotificationsHandler.cs
new file mode 100644
index 0000000000..dc77a7b745
--- /dev/null
+++ b/src/Umbraco.Web/Strategies/NotificationsHandler.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using Umbraco.Core;
+using Umbraco.Core.Configuration;
+using Umbraco.Core.Models.EntityBase;
+using Umbraco.Core.Services;
+using umbraco;
+using umbraco.BusinessLogic.Actions;
+
+namespace Umbraco.Web.Strategies
+{
+ ///
+ /// Subscribes to the relavent events in order to send out notifications
+ ///
+ public sealed class NotificationsHandler : ApplicationEventHandler
+ {
+
+ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
+ {
+ base.ApplicationStarted(umbracoApplication, applicationContext);
+
+ //Send notifications for the published action
+ ContentService.Published += (sender, args) =>
+ args.PublishedEntities.ForEach(
+ content =>
+ applicationContext.Services.NotificationService.SendNotification(
+ content, ActionPublish.Instance, applicationContext));
+
+ //Send notifications for the update and created actions
+ ContentService.Saved += (sender, args) =>
+ {
+ //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
+ applicationContext.Services.NotificationService.SendNotification(
+ entity, ActionNew.Instance, applicationContext);
+ }
+ else
+ {
+ //it's updating
+ applicationContext.Services.NotificationService.SendNotification(
+ entity, ActionUpdate.Instance, applicationContext);
+ }
+ }
+ };
+
+ //Send notifications for the delete action
+ ContentService.Deleted += (sender, args) =>
+ args.DeletedEntities.ForEach(
+ content =>
+ applicationContext.Services.NotificationService.SendNotification(
+ content, ActionDelete.Instance, applicationContext));
+
+ //Send notifications for the unpublish action
+ ContentService.UnPublished += (sender, args) =>
+ args.PublishedEntities.ForEach(
+ content =>
+ applicationContext.Services.NotificationService.SendNotification(
+ content, ActionUnPublish.Instance, applicationContext));
+
+ }
+
+ }
+}
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index b829f6cc7a..c0e1e010a6 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -338,6 +338,7 @@
+
@@ -407,6 +408,7 @@
+
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/SendPublish.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/SendPublish.aspx.cs
index 208b2a9780..78c4549a55 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/SendPublish.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/SendPublish.aspx.cs
@@ -8,6 +8,7 @@ using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
+using Umbraco.Web;
using umbraco.BusinessLogic;
using umbraco.BusinessLogic.Actions;
using umbraco.cms.businesslogic.web;
@@ -32,9 +33,9 @@ namespace umbraco.dialogs
int docId;
if (int.TryParse(Request.QueryString["id"], out docId))
{
-
- //TODO Send to publish!!
-
+ //send notifications! TODO: This should be put somewhere centralized instead of hard coded directly here
+ ApplicationContext.Services.NotificationService.SendNotification(
+ ApplicationContext.Services.ContentService.GetById(docId), ActionToPublish.Instance, ApplicationContext);
}
}
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/translation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/translation/default.aspx.cs
index 00d1cd76f4..2e5749c4f9 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/translation/default.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/translation/default.aspx.cs
@@ -1,9 +1,13 @@
using System;
using System.Data;
+using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
+using Umbraco.Core;
using Umbraco.Core.Configuration;
+using Umbraco.Core.Models.EntityBase;
+using Umbraco.Web;
using umbraco.BasePages;
using umbraco.BusinessLogic;
using umbraco.BusinessLogic.Actions;
@@ -191,22 +195,15 @@ namespace umbraco.presentation.translation
if (t != null)
{
//user auth and content node validation
- if (t.Node.Id == int.Parse(taskNode.Attributes.GetNamedItem("id").Value) && (t.User.Id == base.getUser().Id || t.ParentUser.Id == base.getUser().Id))
+ if (t.Node.Id == int.Parse(taskNode.Attributes.GetNamedItem("id").Value) && (t.User.Id == UmbracoUser.Id || t.ParentUser.Id == UmbracoUser.Id))
{
// update node contents
var d = new Document(t.Node.Id);
- Document.Import(d.ParentId, getUser(), (XmlElement)taskNode);
+ Document.Import(d.ParentId, UmbracoUser, (XmlElement)taskNode);
- /* d.Text = taskNode.Attributes.GetNamedItem("nodeName").Value.Trim();
-
- // update data elements
- foreach (XmlNode data in taskNode.SelectNodes("data"))
- if (data.FirstChild != null)
- d.getProperty(data.Attributes.GetNamedItem("alias").Value).Value = data.FirstChild.Value;
- else
- d.getProperty(data.Attributes.GetNamedItem("alias").Value).Value = "";
- */
+ //send notifications! TODO: This should be put somewhere centralized instead of hard coded directly here
+ ApplicationContext.Services.NotificationService.SendNotification(d.Content, ActionTranslate.Instance, ApplicationContext);
t.Closed = true;
t.Save();
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs
index a6e2d7e402..1dfa3362da 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs
@@ -7,8 +7,12 @@ using System.Linq;
using System.Web.Script.Services;
using System.Web.Services;
using System.Xml;
+using Umbraco.Core;
+using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
+using Umbraco.Core.Models.EntityBase;
+using Umbraco.Web;
using Umbraco.Web.WebServices;
using umbraco.BasePages;
using umbraco.BusinessLogic;
@@ -160,12 +164,16 @@ namespace umbraco.presentation.webservices
if (parentNode != null)
content.SortNodes(ref parentNode);
+ //send notifications! TODO: This should be put somewhere centralized instead of hard coded directly here
+ ApplicationContext.Services.NotificationService.SendNotification(contentService.GetById(parentId), ActionSort.Instance, UmbracoContext, ApplicationContext);
+
}
catch (Exception ex)
{
LogHelper.Error("Could not update content sort order", ex);
}
}
+
}
[Serializable]