MainFeed.aspx.cs :  » Bloggers » SubText » Subtext » Web » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » Subtext » Web » MainFeed.aspx.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
using Subtext.Framework.Providers;
using Subtext.Framework.Tracking;
using Subtext.Framework.Web;
using Subtext.Web.UI.Controls;

namespace Subtext.Web{
    /// <summary>
    /// This class writes out a consolidated rss feed for every blog in the system. 
    /// This is used by hosted solutions that contain an aggregate blog.
    /// </summary>
    public class RSSPage : AggregatePage
    {
        /// <summary>
        /// Returns the "Accept-Encoding" value from the HTTP Request header. 
        /// This is a list of encodings that may be sent to the browser.
        /// </summary>
        /// <remarks>
        /// Specifically we're looking for gzip.
        /// </remarks>
        /// <value></value>
        protected string AcceptEncoding
        {
            get { return Request.Headers["Accept-Encoding"]; }
        }

        protected override void OnLoad(EventArgs e)
        {
            int? groupId = GetGroupIdFromQueryString();

            var hostInfo = HostInfo.Instance;

            if(hostInfo.AggregateBlog == null)
            {
                HttpHelper.SetFileNotFoundResponse();
                return;
            }

            ICollection<Entry> entries = Repository.GetRecentEntries(
                hostInfo.AggregateBlog.Host, groupId, 25);

            //TODO: Use our other feed generation code.
            if(entries != null && entries.Count > 0)
            {
                string rssXml = GetRSS(entries, Request.ApplicationPath);
                Response.ContentEncoding = Encoding.UTF8;
                Response.ContentType = "text/xml";
                Response.Write(rssXml);
            }
            base.OnLoad(e);
        }

        private string GetRSS(IEnumerable<Entry> entries, string appPath)
        {
            if(!appPath.EndsWith("/"))
            {
                appPath += "/";
            }

            var sw = new StringWriter();
            var writer = new XmlTextWriter(sw);

            //RSS ROOT
            writer.WriteStartElement("rss");
            writer.WriteAttributeString("version", "2.0");
            writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
            writer.WriteAttributeString("xmlns:trackback", "http://madskills.com/public/xml/rss/module/trackback/");
            writer.WriteAttributeString("xmlns:wfw", "http://wellformedweb.org/CommentAPI/");
            writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

            //Channel
            writer.WriteStartElement("channel");
            //Channel Description
            writer.WriteElementString("title", ConfigurationManager.AppSettings["AggregateTitle"]);
            writer.WriteElementString("link", Context.Request.Url.ToString());
            writer.WriteElementString("description", ConfigurationManager.AppSettings["AggregateDescription"]);
            writer.WriteElementString("generator", VersionInfo.VersionDisplayText);

            string baseUrl = "http://{0}" + appPath + "{1}/";

            bool useAggBugs = Config.Settings.Tracking.EnableAggBugs;

            foreach(Entry entry in entries)
            {
                writer.WriteStartElement("item");
                writer.WriteElementString("title", entry.Title);

                string baselink = string.Format(baseUrl, entry.Blog.Host, entry.Blog.Subfolder);
                string link = string.Format(CultureInfo.InvariantCulture, baselink + "archive/{0:yyyy/MM/dd}/{1}.aspx",
                                            entry.DateCreated, entry.EntryName);
                writer.WriteElementString("link", link);

                DateTime entryTime = entry.DateCreated;

                writer.WriteElementString("pubDate", entry.Blog.TimeZone.ToUtc(entryTime).ToString("r"));
                writer.WriteStartElement("guid");
                writer.WriteAttributeString("isPermaLink", "true");
                writer.WriteString(link);
                writer.WriteEndElement();

                writer.WriteElementString("wfw:comment", string.Format(baselink + "comments/{0}.aspx", entry.Id));
                writer.WriteElementString("wfw:commentRss",
                                          string.Format(baselink + "comments/commentRss/{0}.aspx", entry.Id));
                writer.WriteElementString("comments", link + "#comment");
                writer.WriteElementString("slash:comments", entry.FeedBackCount.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("trackback:ping",
                                          string.Format(baselink + "services/trackbacks/{0}.aspx", entry.Id));


                writer.WriteStartElement("source");
                writer.WriteAttributeString("url", baselink + "rss.aspx");
                writer.WriteString(entry.Blog.Title);
                writer.WriteEndElement();

                string aggText = useAggBugs
                                     ? TrackingUrls.AggBugImage(string.Format(baselink + "aggbug/{0}.aspx", entry.Id))
                                     : string.Empty;

                writer.WriteElementString("description",
                                          string.Format(CultureInfo.InvariantCulture, "{0}{1}", entry.Description,
                                                        aggText));
                writer.WriteElementString("dc:creator", entry.Author);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.WriteEndElement();
            writer.Flush();
            writer.Close();
            sw.Close();
            return sw.ToString();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.