Click here to Skip to main content
15,879,239 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 36.8K   770   41  
Xenta architecture overview
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Xml;
using SiberTek.Xenta.Enums;
using SiberTek.Xenta.Presentation;
using SiberTek.Xenta.Presentation.Presenters;
using SiberTek.Xenta.Presentation.Resources;
using SiberTek.Xenta.Presentation.Utils;
using SiberTek.Xenta.Presentation.Views;
using SiberTek.Xenta.Web.Utils;
using SiberTek.Xenta.Utils;

namespace SiberTek.Xenta.Web.Home.Handlers
{
    public class RSSHandler : IHttpHandler
    {
        #region Properties
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
        #endregion

        #region Methods
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();

            string language = HttpHelper.GetQueryParam(context, "Language");

            if(!String.IsNullOrEmpty(language))
            {
                int languageID = LocalizationHelper.GetLanguageID(language);
                XmlDocument xml = new XmlDocument();

                XmlDeclaration elDecl = xml.CreateXmlDeclaration("1.0", "utf-8", String.Empty);
                XmlElement elRss = xml.CreateElement("rss");
                XmlElement elChannel = xml.CreateElement("channel");
                XmlElement elChannelTitle = xml.CreateElement("title");
                XmlElement elChannelLink = xml.CreateElement("link");
                XmlElement elChannelDescr = xml.CreateElement("description");
                XmlElement elChannelCopyright = xml.CreateElement("copyright");

                elRss.SetAttribute("version", "2.0");

                elChannelTitle.InnerText = StringManager.GetString("Home.RSSHandler.Channel.Title");
                elChannelLink.InnerText = UrlHelper.GetUrl("home");
                elChannelDescr.InnerText = StringManager.GetString("Home.RSSHandler.Channel.Description");
                elChannelCopyright.InnerText = String.Format(StringManager.GetString("Home.RSSHandler.Channel.Copyright"), UserContext.Current.LocalDateTime.Year);

                xml.AppendChild(elDecl);
                xml.AppendChild(elRss);
                elRss.AppendChild(elChannel);
                elChannel.AppendChild(elChannelTitle);
                elChannel.AppendChild(elChannelLink);
                elChannel.AppendChild(elChannelDescr);
                elChannel.AppendChild(elChannelCopyright);

                try
                {
                    PublicationPresenter presenter = new PublicationPresenter();
                    PublicationListView pList = new PublicationListView();

                    presenter.AttachToView(pList);
                    presenter.Initialize();

                    pList.DataContainer["SearchTerm"] = String.Empty;
                    pList.DataContainer["LanguageID"] = languageID;
                    pList.DataContainer["PublishedOnEnd"] = UserContext.Current.LocalDateTime;
                    pList.DataContainer["ShowHidden"] = false;
                    pList.DataContainer["StartIndex"] = 0;
                    pList.DataContainer["Count"] = AppHelper.GetAppSetting<Int32>("Home.RSSHandler.Channel.Size");

                    presenter.LoadCollection();

                    foreach(ViewDataContainer p in pList.DataContainer["PublicationCollection"] as List<ViewDataContainer>)
                    {
                        XmlElement elItem = xml.CreateElement("item");
                        XmlElement elItemTitle = xml.CreateElement("title");
                        XmlElement elItemDescription = xml.CreateElement("description");
                        XmlElement elItemLink = xml.CreateElement("link");
                        XmlElement elItemAuthor = xml.CreateElement("author");
                        XmlElement elItemPubDate = xml.CreateElement("pubDate");

                        elItemTitle.InnerText = (string)p["Title"];
                        elItemDescription.InnerText = (string)p["Description"];
                        switch((PublicationType)p["Type"])
                        {
                            case PublicationType.Article:
                                elItemLink.InnerText = UrlHelper.FormatUrl("home", "articles/{0}.aspx", p["PublicationID"]);
                                break;
                            case PublicationType.News:
                                elItemLink.InnerText = UrlHelper.FormatUrl("home", "news/{0}.aspx", p["PublicationID"]);
                                break;
                        }
                        elItemAuthor.InnerText = MembershipHelper.GetUsername((int)p["AuthorID"]);
                        elItemPubDate.InnerText = String.Format("{0:R}", (DateTime)p["PublishedOn"]);

                        elChannel.AppendChild(elItem);
                        elItem.AppendChild(elItemTitle);
                        elItem.AppendChild(elItemDescription);
                        elItem.AppendChild(elItemLink);
                        elItem.AppendChild(elItemAuthor);
                    }

                    using(Stream os = context.Response.OutputStream)
                    {
                        xml.Save(os);
                    }

                    context.Response.ContentType = "text/xml";
                }
                catch(Exception ex)
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(ex.Message);
                }
            }
            context.Response.End();
        }
        #endregion

        #region Classes
        private class PublicationListView : IView
        {
            #region Fields
            private readonly ViewDataContainer _dataContainer;
            #endregion

            #region Constructors
            public PublicationListView()
            {
                _dataContainer = new ViewDataContainer();
            }
            #endregion

            #region Properties
            public ViewDataContainer DataContainer
            {
                get
                {
                    return _dataContainer;
                }
            }
            #endregion
        }
        #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