Click here to Skip to main content
15,896,063 members
Articles / Web Development / ASP.NET

Open Source Extensible Enterprise n-tier Application Framework with Multilayered Architecture

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
3 Dec 2010MIT3 min read 37K   770   41  
Xenta architecture overview
using SiberTek.Xenta.Entities;
using SiberTek.Xenta.Enums;
using SiberTek.Xenta.Managers;

namespace SiberTek.Xenta.Extensions
{
    /// <summary>
    /// Contains message manager extension methods
    /// </summary>
    public static class CoreMessageManagerExtesion
    {
        #region Methods
        public static bool SendContactMessage(this MessageManager mgr, int languageID, string replyTo, string msgSubject, string msgText)
        {
            MessageTemplateInfo template = mgr.GetMessageTemplateByName(languageID, "contact-message");

            if(template == null)
            {
                return false;
            }

            string subject = template.Subject;
            string text = template.Text;

            subject = subject.Replace("[Token:Message.Subject]", msgSubject);
            subject = subject.Replace("[Token:Message.From]", replyTo);
            text = text.Replace("[Token:Message.Subject]", msgSubject);
            text = text.Replace("[Token:Message.From]", replyTo);
            text = text.Replace("[Token:Message.Text]", msgText);

            MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, template.To, template.BccTo, replyTo, subject, text);

            return message != null;
        }

        public static bool SendAccountInstructions(this MessageManager mgr, int userID)
        {
            UserInfo user = UserManager.Instance.GetUser(userID);

            if(user == null)
            {
                return false;
            }

            MessageTemplateInfo template = mgr.GetMessageTemplateByName(user.LanguageID, "account-instructions");

            if(template == null)
            {
                return false;
            }

            string subject = template.Subject;
            string text = template.Text;

            text = text.Replace("[Token:User.FullName]", user.FullName);
            text = text.Replace("[Token:User.Username]", user.Username);
            text = text.Replace("[Token:User.Email]", user.Email);
            text = text.Replace("[Token:User.Guid]", user.Guid.ToString());
            text = text.Replace("[Token:User.Password]", user.ClearTextPassword);

            MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, user.Email, template.BccTo, subject, text);

            return message != null;
        }

        public static bool SendSubscriptionInstructions(this MessageManager mgr, int subscriptionID)
        {
            SubscriptionInfo subscription = SubscriptionManager.Instance.GetSubscription(subscriptionID);

            if(subscription == null)
            {
                return false;
            }

            MessageTemplateInfo template = mgr.GetMessageTemplateByName(subscription.LanguageID, "subscription-instructions");

            if(template == null)
            {
                return false;
            }

            string subject = template.Subject;
            string text = template.Text;

            text = text.Replace("[Token:Subscription.Guid]", subscription.Guid.ToString());

            MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, subscription.Email, template.BccTo, subject, text);

            return message != null;
        }

        public static bool SendPasswordReminder(this MessageManager mgr, int userID)
        {
            UserInfo user = UserManager.Instance.GetUser(userID);

            if(user == null)
            {
                return false;
            }

            MessageTemplateInfo template = mgr.GetMessageTemplateByName(user.LanguageID, "password-reminder");

            if(template == null)
            {
                return false;
            }

            string subject = template.Subject;
            string text = template.Text;

            text = text.Replace("[Token:User.FullName]", user.FullName);
            text = text.Replace("[Token:User.Username]", user.Username);
            text = text.Replace("[Token:User.Email]", user.Email);
            text = text.Replace("[Token:User.Guid]", user.Guid.ToString());
            text = text.Replace("[Token:User.Password]", user.ClearTextPassword);

            MessageInfo message = mgr.CreateMessage(MessageType.Email, template.From, user.Email, template.BccTo, subject, text);

            return message != null;
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions