/// <summary> /// Sends an email to the user that is assigned to the issue /// </summary> /// <param name="issueId">The issue id.</param> /// <param name="newAssigneeUserName">New name of the assignee user.</param> public static void SendNewAssigneeNotification(int issueId, string newAssigneeUserName) { if (issueId <= Globals.NewId) throw (new ArgumentOutOfRangeException("issueId")); Issue issue = DataProviderManager.Provider.GetIssueById(issueId); EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text); //load notification plugins NotificationManager nm = new NotificationManager(type); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadEmailNotificationTemplate("NewAssignee"); Dictionary<string, object> data = new Dictionary<string, object>(); data.Add("Issue", issue); template = nm.GenerateNotificationContent(template, data); string subject = nm.LoadNotificationTemplate("NewAssigneeSubject"); string displayname = ITUser.GetUserDisplayName(Security.GetUserName()); string notificationUserDisplayName = ITUser.GetUserDisplayName(newAssigneeUserName); try { //send notifications to the new assignee nm.SendNotification(newAssigneeUserName, String.Format(subject, issue.FullId), template, notificationUserDisplayName); } catch (Exception ex) { ProcessException(ex); } }
/// <summary> /// Sends the new issue comment notification. /// </summary> /// <param name="issueId">The issue id.</param> /// <param name="newComment">The new comment.</param> public static void SendNewIssueCommentNotification(int issueId, IssueComment newComment) { if (issueId <= Globals.NewId) throw (new ArgumentOutOfRangeException("issueId")); if (newComment == null) throw new ArgumentNullException("newComment"); Issue issue = DataProviderManager.Provider.GetIssueById(issueId); List<IssueNotification> issNotifications = DataProviderManager.Provider.GetIssueNotificationsByIssueId(issueId); EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text); //load notification plugins NotificationManager nm = new NotificationManager(type); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadEmailNotificationTemplate("NewIssueComment"); Dictionary<string, object> data = new Dictionary<string, object>(); data.Add("Issue", issue); data.Add("Comment", newComment); template = nm.GenerateNotificationContent(template, data); string subject = nm.LoadNotificationTemplate("NewIssueCommentSubject"); string userDisplayName = ITUser.GetUserDisplayName(Security.GetUserName()); foreach (IssueNotification notify in issNotifications) { try { string notificationUserDisplayName = ITUser.GetUserDisplayName(notify.NotificationUsername); nm.SendNotification(notify.NotificationUsername, String.Format(subject, issue.FullId, userDisplayName), template, notificationUserDisplayName); } catch (Exception ex) { ProcessException(ex); } } }
/// <summary> /// Sends the issue notifications. /// </summary> /// <param name="issueId">The issue id.</param> /// <param name="issueChanges">The issue changes.</param> public static void SendIssueNotifications(int issueId, List<IssueHistory> issueChanges) { // validate input if (issueId <= Globals.NewId) throw (new ArgumentOutOfRangeException("issueId")); Issue issue = DataProviderManager.Provider.GetIssueById(issueId); List<IssueNotification> issNotifications = DataProviderManager.Provider.GetIssueNotificationsByIssueId(issueId); EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text); //load notification plugins NotificationManager nm = new NotificationManager(type); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadEmailNotificationTemplate("IssueUpdatedWithChanges"); Dictionary<string, object> data = new Dictionary<string, object>(); data.Add("Issue", issue); System.IO.StringWriter writer = new System.IO.StringWriter(); using (System.Xml.XmlWriter xml = new System.Xml.XmlTextWriter(writer)) { xml.WriteStartElement("IssueHistoryChanges"); foreach (IssueHistory issueHistory in issueChanges) { issueHistory.Save(); xml.WriteRaw(issueHistory.ToXml()); } xml.WriteEndElement(); data.Add("RawXml_Changes", writer.ToString()); } template = nm.GenerateNotificationContent(template, data); string subject = nm.LoadNotificationTemplate("IssueUpdatedSubject"); string displayname = ITUser.GetUserDisplayName(Security.GetUserName()); foreach (IssueNotification notify in issNotifications) { try { //send notifications to everyone except who changed it. //if (notify.NotificationUsername != Security.GetUserName()) string notificationUserDisplayName = ITUser.GetUserDisplayName(notify.NotificationDisplayName); nm.SendNotification(notify.NotificationUsername, String.Format(subject, issue.FullId, displayname), String.Format(template, issueChanges), notificationUserDisplayName); } catch (Exception ex) { ProcessException(ex); } } }
/// <summary> /// Sends an email to all users that are subscribed to a bug /// </summary> /// <param name="issueId">The bug id.</param> public static void SendIssueNotifications(int issueId) { if (issueId <= Globals.NewId) throw (new ArgumentOutOfRangeException("issueId")); Issue issue = DataProviderManager.Provider.GetIssueById(issueId); List<IssueNotification> issNotifications = DataProviderManager.Provider.GetIssueNotificationsByIssueId(issueId); //TODO: Move this internal to the notification manager ?? //pass in a notification type parameter to decide which notification to send and the issue. //load plugins EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text); NotificationManager nm = new NotificationManager(type); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadEmailNotificationTemplate("IssueUpdated"); Dictionary<string, object> data = new Dictionary<string, object>(); data.Add("Issue", issue); template = nm.GenerateNotificationContent(template, data); string subject = nm.LoadNotificationTemplate("IssueUpdatedSubject"); string displayname = ITUser.GetUserDisplayName(Security.GetUserName()); foreach (IssueNotification notify in issNotifications) { try { //send notifications to everyone except who changed it. if (notify.NotificationUsername != Security.GetUserName()) { string notificationUserDisplayName = ITUser.GetUserDisplayName(notify.NotificationDisplayName); nm.SendNotification(notify.NotificationUsername, String.Format(subject, issue.FullId, displayname), template, notificationUserDisplayName); } } catch (Exception ex) { ProcessException(ex); } } }
/// <summary> /// Sends the user registered notification. /// </summary> /// <param name="user">The user.</param> public static void SendUserRegisteredNotification(string userName) { if (userName == "") throw new ArgumentNullException("user"); EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text); MembershipUser user = ITUser.GetUser(userName); WebProfile profile = new WebProfile().GetProfile(user.UserName); //load notification plugins NotificationManager nm = new NotificationManager(type); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadEmailNotificationTemplate("UserRegistered"); string subject = nm.LoadNotificationTemplate("UserRegisteredSubject"); Dictionary<string, object> data = new Dictionary<string, object>(); ITUser u = new ITUser() { CreationDate = user.CreationDate, Email = user.Email, UserName = user.UserName, DisplayName = new WebProfile().GetProfile(user.UserName).DisplayName, IsApproved = user.IsApproved }; data.Add("User", u); template = nm.GenerateNotificationContent(template, data); //all admin notifications sent to admin user defined in host settings, string AdminNotificationUsername = HostSetting.GetHostSetting("AdminNotificationUsername"); nm.SendNotification(AdminNotificationUsername, subject, template); }
/// <summary> /// Sends the user password reminder. /// </summary> /// <param name="username">The username.</param> /// <returns></returns> public static void SendUserPasswordReminderNotification(MembershipUser user, string passwordAnswer) { if (user == null) throw new ArgumentNullException("user"); //load notification plugins NotificationManager nm = new NotificationManager(); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadNotificationTemplate("PasswordReminder"); string subject = nm.LoadNotificationTemplate("PasswordReminderSubject"); string displayname = ITUser.GetUserDisplayName(user.UserName); nm.SendNotification(user.UserName, subject, String.Format(template, HostSetting.GetHostSetting("ApplicationTitle"), user.GetPassword(passwordAnswer))); }
/// <summary> /// Sends the user new password notification. /// </summary> /// <param name="user">The user.</param> /// <param name="newPassword">The new password.</param> public static void SendUserNewPasswordNotification(MembershipUser user, string newPassword) { if (user == null) throw new ArgumentNullException("user"); EmailFormatTypes type = (EmailFormatTypes)HostSetting.GetHostSetting("SMTPEMailFormat", (int)EmailFormatTypes.Text); NotificationManager nm = new NotificationManager(type); nm.LoadNotificationTypes(); //load template and replace the tokens string template = nm.LoadEmailNotificationTemplate("PasswordReset"); string subject = nm.LoadNotificationTemplate("PasswordResetSubject"); string displayname = ITUser.GetUserDisplayName(user.UserName); Dictionary<string, object> data = new Dictionary<string, object>(); ITUser u = new ITUser() { CreationDate = user.CreationDate, Email = user.Email, UserName = user.UserName, DisplayName = new WebProfile().GetProfile(user.UserName).DisplayName, IsApproved = user.IsApproved }; data.Add("User", u); data.Add("Password", newPassword); template = nm.GenerateNotificationContent(template, data); nm.SendNotification(user.UserName, subject, template); }