From 4346f73159f2645c8dfed72a2cd298257bfa0b0f Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 10 Jan 2014 15:13:25 +1100 Subject: [PATCH] Fixes naming conventions from old Notification class --- .../businesslogic/workflow/Notification.cs | 102 +++++++----------- 1 file changed, 38 insertions(+), 64 deletions(-) diff --git a/src/umbraco.cms/businesslogic/workflow/Notification.cs b/src/umbraco.cms/businesslogic/workflow/Notification.cs index 68bdd7bc25..29fc8ed319 100644 --- a/src/umbraco.cms/businesslogic/workflow/Notification.cs +++ b/src/umbraco.cms/businesslogic/workflow/Notification.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Net.Mail; using System.Runtime.CompilerServices; using System.Text; @@ -47,20 +48,20 @@ namespace umbraco.cms.businesslogic.workflow /// /// Sends the notifications for the specified user regarding the specified node and action. /// - /// The node. + /// The node. /// The user. - /// The action. - public static void GetNotifications(CMSNode Node, User user, IAction Action) + /// The action. + public static void GetNotifications(CMSNode node, User user, IAction action) { User[] allUsers = User.getAll(); foreach (User u in allUsers) { try { - if (!u.Disabled && u.GetNotifications(Node.Path).IndexOf(Action.Letter.ToString()) > -1) + if (u.Disabled == false && u.GetNotifications(node.Path).IndexOf(action.Letter.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) > -1) { - LogHelper.Debug(string.Format("Notification about {0} sent to {1} ({2})", ui.Text(Action.Alias, u), u.Name, u.Email)); - sendNotification(user, u, (Document)Node, Action); + LogHelper.Debug(string.Format("Notification about {0} sent to {1} ({2})", ui.Text(action.Alias, u), u.Name, u.Email)); + SendNotification(user, u, (Document)node, action); } } catch (Exception notifyExp) @@ -71,8 +72,7 @@ namespace umbraco.cms.businesslogic.workflow } ///TODO: Include update with html mail notification and document contents - private static void sendNotification(User performingUser, User mailingUser, Document documentObject, - IAction Action) + private static void SendNotification(User performingUser, User mailingUser, Document documentObject, IAction action) { // retrieve previous version of the document DocumentVersionList[] versions = documentObject.GetVersions(); @@ -90,14 +90,14 @@ namespace umbraco.cms.businesslogic.workflow string newText = p.Value != null ? p.Value.ToString() : ""; // replace html with char equivalent - ReplaceHTMLSymbols(ref oldText); - ReplaceHTMLSymbols(ref newText); + ReplaceHtmlSymbols(ref oldText); + ReplaceHtmlSymbols(ref newText); // make sure to only highlight changes done using TinyMCE editor... other changes will be displayed using default summary - ///TODO PPH: Had to change this, as a reference to the editorcontrols is not allowed, so a string comparison is the only way, this should be a DIFF or something instead.. + //TODO PPH: Had to change this, as a reference to the editorcontrols is not allowed, so a string comparison is the only way, this should be a DIFF or something instead.. if (p.PropertyType.DataTypeDefinition.DataType.ToString() == "umbraco.editorControls.tinymce.TinyMCEDataType" && - string.Compare(oldText, newText) != 0) + string.CompareOrdinal(oldText, newText) != 0) { summary.Append(""); summary.Append(" Note: "); @@ -108,7 +108,7 @@ namespace umbraco.cms.businesslogic.workflow summary.Append(" New " + p.PropertyType.Name + ""); summary.Append("" + - replaceLinks(CompareText(oldText, newText, true, false, + ReplaceLinks(CompareText(oldText, newText, true, false, "", string.Empty)) + ""); summary.Append(""); @@ -116,7 +116,7 @@ namespace umbraco.cms.businesslogic.workflow summary.Append(" Old " + oldProperty.PropertyType.Name + ""); summary.Append("" + - replaceLinks(CompareText(newText, oldText, true, false, + ReplaceLinks(CompareText(newText, oldText, true, false, "", string.Empty)) + ""); summary.Append(""); @@ -139,12 +139,12 @@ namespace umbraco.cms.businesslogic.workflow string[] subjectVars = { HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.Url.Port + - IOHelper.ResolveUrl(SystemDirectories.Umbraco), ui.Text(Action.Alias) + IOHelper.ResolveUrl(SystemDirectories.Umbraco), ui.Text(action.Alias) , documentObject.Text }; string[] bodyVars = { - mailingUser.Name, ui.Text(Action.Alias), documentObject.Text, performingUser.Name, + mailingUser.Name, ui.Text(action.Alias), documentObject.Text, performingUser.Name, HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.Url.Port + IOHelper.ResolveUrl(SystemDirectories.Umbraco), @@ -155,8 +155,8 @@ namespace umbraco.cms.businesslogic.workflow /*umbraco.library.NiceUrl(documentObject.Id))*/ documentObject.Id + ".aspx", protocol) - ///TODO: PPH removed the niceURL reference... cms.dll cannot reference the presentation project... - ///TODO: This should be moved somewhere else.. + //TODO: PPH removed the niceURL reference... cms.dll cannot reference the presentation project... + //TODO: This should be moved somewhere else.. }; // create the mail message @@ -182,7 +182,7 @@ namespace umbraco.cms.businesslogic.workflow // nh, issue 30724. Due to hardcoded http strings in resource files, we need to check for https replacements here // adding the server name to make sure we don't replace external links - if (GlobalSettings.UseSSL && !String.IsNullOrEmpty(mail.Body)) + if (GlobalSettings.UseSSL && string.IsNullOrEmpty(mail.Body) == false) { string serverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"]; mail.Body = mail.Body.Replace( @@ -195,7 +195,7 @@ namespace umbraco.cms.businesslogic.workflow sender.Send(mail); } - private static string replaceLinks(string text) + private static string ReplaceLinks(string text) { string domain = GlobalSettings.UseSSL ? "https://" : "http://"; domain += HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + @@ -232,7 +232,7 @@ namespace umbraco.cms.businesslogic.workflow /// /// Returns the notifications for a node /// - /// + /// /// public static IEnumerable GetNodeNotifications(CMSNode node) { @@ -289,23 +289,23 @@ namespace umbraco.cms.businesslogic.workflow /// /// Creates a new notification /// - /// The user. - /// The node. - /// The action letter. + /// The user. + /// The node. + /// The action letter. [MethodImpl(MethodImplOptions.Synchronized)] - public static void MakeNew(User User, CMSNode Node, char ActionLetter) + public static void MakeNew(User user, CMSNode node, char actionLetter) { bool exists = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( "SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action", - new { userId = User.Id, nodeId = Node.Id, action = ActionLetter.ToString()}) > 0; + new { userId = user.Id, nodeId = node.Id, action = actionLetter.ToString()}) > 0; if (exists == false) { ApplicationContext.Current.DatabaseContext.Database.Insert(new User2NodeNotifyDto { - Action = ActionLetter.ToString(), - NodeId = Node.Id, - UserId = User.Id + Action = actionLetter.ToString(), + NodeId = node.Id, + UserId = user.Id }); } } @@ -313,25 +313,25 @@ namespace umbraco.cms.businesslogic.workflow /// /// Updates the notifications. /// - /// The user. - /// The node. - /// The notifications. + /// The user. + /// The node. + /// The notifications. [MethodImpl(MethodImplOptions.Synchronized)] - public static void UpdateNotifications(User User, CMSNode Node, string Notifications) + public static void UpdateNotifications(User user, CMSNode node, string notifications) { // delete all settings on the node for this user - DeleteNotifications(User, Node); + DeleteNotifications(user, node); // Loop through the permissions and create them - foreach (char c in Notifications) - MakeNew(User, Node, c); + foreach (char c in notifications) + MakeNew(user, node, c); } /// /// Replaces the HTML symbols with the character equivalent. /// /// The old string. - private static void ReplaceHTMLSymbols(ref string oldString) + private static void ReplaceHtmlSymbols(ref string oldString) { oldString = oldString.Replace(" ", " "); oldString = oldString.Replace("’", "'"); @@ -340,33 +340,7 @@ namespace umbraco.cms.businesslogic.workflow oldString = oldString.Replace("”", "”"); oldString = oldString.Replace(""", "\""); } - - /// - /// Compares the text. - /// - /// The old text. - /// The new text. - /// - private static string CompareText(string oldText, string newText) - { - return CompareText(oldText, newText, true, true); - } - - /// - /// Compares the text. - /// - /// The old text. - /// The new text. - /// if set to true [display inserted text]. - /// if set to true [display deleted text]. - /// - private static string CompareText(string oldText, string newText, bool displayInsertedText, - bool displayDeletedText) - { - return CompareText(oldText, newText, displayInsertedText, displayDeletedText, - "", ""); - } - + /// /// Compares the text. ///