/// <summary>
        /// Load the notification content based on the culture
        /// </summary>
        /// <param name="cultureString">The culture to load the content for</param>
        /// <param name="contentKeys">The content keys (these would be the Name value in resource files)</param>
        /// <returns></returns>
        public CultureNotificationContent LoadContent(string cultureString, params string[] contentKeys)
        {
            if (string.IsNullOrWhiteSpace(cultureString))
            {
                throw new ArgumentNullException("cultureString");
            }
            if (contentKeys == null)
            {
                throw new ArgumentNullException("contentKeys");
            }

            CultureString = cultureString;

            SetCultureThread();

            var item = new CultureNotificationContent {
                CultureString = cultureString
            };

            foreach (var key in contentKeys)
            {
                var content = item.CultureContents.FirstOrDefault(p => p.CultureString == cultureString && p.ContentKey == key);

                if (content != null)
                {
                    continue;
                }

                var contentString = NotificationManager.LoadNotificationTemplate(key);

                if (contentString.EndsWith(".xslt"))
                {
                    contentString = NotificationManager.LoadXsltNotificationTemplate(contentString);
                }

                item.CultureContents.Add(new CultureContent
                {
                    ContentKey    = key,
                    CultureString = cultureString,
                    Content       = contentString
                });
            }

            ResetCultureThread();

            return(item);
        }
        /// <summary>
        /// Load the notification content based on the culture
        /// </summary>
        /// <param name="cultureString">The culture to load the content for</param>
        /// <param name="contentKeys">The content keys (these would be the Name value in resource files)</param>
        /// <returns></returns>
        public CultureNotificationContent LoadContent(string cultureString, params string[] contentKeys)
        {
            if (string.IsNullOrWhiteSpace(cultureString)) throw new ArgumentNullException("cultureString");
            if (contentKeys == null) throw new ArgumentNullException("contentKeys");

            CultureString = cultureString;

            SetCultureThread();

            var item = new CultureNotificationContent{CultureString = cultureString};

            foreach (var key in contentKeys)
            {
                var content = item.CultureContents.FirstOrDefault(p => p.CultureString == cultureString && p.ContentKey == key);

                if (content != null) continue;

                var contentString = NotificationManager.LoadNotificationTemplate(key);

                if (contentString.EndsWith(".xslt"))
                {
                    contentString = NotificationManager.LoadXsltNotificationTemplate(contentString);
                }

                item.CultureContents.Add(new CultureContent
                    {
                        ContentKey = key,
                        CultureString = cultureString,
                        Content = contentString
                    });
            }

            ResetCultureThread();

            return item;
        }
        /// <summary>
        /// Sends an email to the user that is assigned to the issue
        /// </summary>
        /// <param name="notification"></param>
        public static void SendNewAssigneeNotification(IssueNotification notification)
        {
            if (notification == null) throw (new ArgumentNullException("notification"));
            if (notification.IssueId <= Globals.NEW_ID) throw (new ArgumentOutOfRangeException("notification", "The issue id is not valid for this notification"));

            // TODO - create this via dependency injection at some point.
            IMailDeliveryService mailService = new SmtpMailDeliveryService();

            var issue = DataProviderManager.Provider.GetIssueById(notification.IssueId);
            var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text);

            // data for template
            var data = new Dictionary<string, object> { { "Issue", issue } };
            var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML";
            const string subjectKey = "NewAssigneeSubject";
            var bodyKey = string.Concat("NewAssignee", emailFormatKey);

            var nc = new CultureNotificationContent().LoadContent(notification.NotificationCulture, subjectKey, bodyKey);

            try
            {
                //send notifications to everyone except who changed it.
                if (notification.NotificationUsername.ToLower() == Security.GetUserName().ToLower()) return;

                var user = UserManager.GetUser(notification.NotificationUsername);

                // skip to the next user if this user is not approved
                if (!user.IsApproved) return;
                // skip to next user if this user doesn't have notifications enabled.
                if (!new WebProfile().GetProfile(user.UserName).ReceiveEmailNotifications)
                    return;

                var emailSubject = nc.CultureContents
                    .First(p => p.ContentKey == subjectKey)
                    .FormatContent(issue.FullId);

                var bodyContent = nc.CultureContents
                    .First(p => p.ContentKey == bodyKey)
                    .TransformContent(data);

                var message = new MailMessage
                    {
                        Subject = emailSubject,
                        Body = bodyContent,
                        IsBodyHtml = true
                    };

                mailService.Send(user.Email, message, notification.IssueId);
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
Example #4
0
        /// <summary>
        /// Sends the forgot password email.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="token">The token.</param>
        /// <exception cref="System.ArgumentNullException">
        /// user
        /// or
        /// user
        /// </exception>
        public static void SendForgotPasswordEmail(MembershipUser user, string token)
        {
            if (user == null) throw new ArgumentNullException("user");
            if (user.ProviderUserKey == null) throw new ArgumentNullException("user");

            IMailDeliveryService mailService = new SmtpMailDeliveryService();

            var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text);
            var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML";
            const string subjectKey = "ForgotPasswordSubject";
            var bodyKey = string.Concat("ForgotPassword", emailFormatKey);
            var profile = new WebProfile().GetProfile(user.UserName);

            var nc = new CultureNotificationContent().LoadContent(profile.PreferredLocale, subjectKey, bodyKey);

            var notificationUser = new NotificationUser
            {
                Id = (Guid)user.ProviderUserKey,
                CreationDate = user.CreationDate,
                Email = user.Email,
                UserName = user.UserName,
                DisplayName = profile.DisplayName,
                FirstName = profile.FirstName,
                LastName = profile.LastName,
                IsApproved = user.IsApproved
            };

            var data = new Dictionary<string, object>
                {
                    {"Token", token}
                };

            var emailSubject = nc.CultureContents
                .First(p => p.ContentKey == subjectKey)
                .FormatContent();

            var bodyContent = nc.CultureContents
                .First(p => p.ContentKey == bodyKey)
                .TransformContent(data);

            var message = new MailMessage
            {
                Subject = emailSubject,
                Body = bodyContent,
                IsBodyHtml = true
            };

            mailService.Send(user.Email, message, null);
        }
Example #5
0
        /// <summary>
        /// Sends the user registered notification.
        /// </summary>
        /// <param name="userName">The user.</param>
        public static void SendUserRegisteredNotification(string userName)
        {
            if (userName == "") throw new ArgumentNullException("userName");

            var user = GetUser(userName);
            if (user.ProviderUserKey == null) throw new ArgumentNullException("userName");

            // TODO - create this via dependency injection at some point.
            IMailDeliveryService mailService = new SmtpMailDeliveryService();

            var emailFormatType = HostSettingManager.Get(HostSettingNames.SMTPEMailFormat, EmailFormatType.Text);
            var emailFormatKey = (emailFormatType == EmailFormatType.Text) ? "" : "HTML";
            const string subjectKey = "UserRegisteredSubject";
            var bodyKey = string.Concat("UserRegistered", emailFormatKey);
            var profile = new WebProfile().GetProfile(user.UserName);

            var nc = new CultureNotificationContent().LoadContent(profile.PreferredLocale, subjectKey, bodyKey);

            var notificationUser = new NotificationUser
            {
                Id = (Guid)user.ProviderUserKey,
                CreationDate = user.CreationDate,
                Email = user.Email,
                UserName = user.UserName,
                DisplayName = profile.DisplayName,
                FirstName = profile.FirstName,
                LastName = profile.LastName,
                IsApproved = user.IsApproved
            };

            var data = new Dictionary<string, object> { { "User", notificationUser } };

            var emailSubject = nc.CultureContents
                .First(p => p.ContentKey == subjectKey)
                .FormatContent();

            var bodyContent = nc.CultureContents
                .First(p => p.ContentKey == bodyKey)
                .TransformContent(data);

            var message = new MailMessage
            {
                Subject = emailSubject,
                Body = bodyContent,
                IsBodyHtml = true
            };

            mailService.Send(user.Email, message, null);
        }