Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial revision

svn path=/trunk/monologue/; revision=18540
  • Loading branch information...
commit d3b3c50b51c547529dfa599f7c48ba1ed6f0ecd4 0 parents
Ben Maurer authored
7 Makefile
@@ -0,0 +1,7 @@
+worker :
+ make -C worker
+
+run : worker
+ (cd www \
+ mono ../monologue-worker.exe bloggers.xml monologue.rss & \
+ xsp)
4 worker/Makefile
@@ -0,0 +1,4 @@
+MCS=mcs
+
+monologue-worker.exe : monologue-worker.cs
+ $(MCS) /debug /r:RSS.NET.dll /out:$@ $^
BIN  worker/RSS.NET.dll
Binary file not shown
125 worker/monologue-worker.cs
@@ -0,0 +1,125 @@
+using System;
+using System.Collections;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+using Rss;
+
+class MonologueWorker {
+ static string bloggersFile;
+ static string outputFile;
+ static DateTime lastReadOfBloggersFile;
+
+
+ static RssFeed outFeed;
+ static BloggerCollection bloggers;
+
+ static void Main (string [] args)
+ {
+ if (args.Length != 2)
+ throw new Exception ("monologue-worker.exe BLOGGERS_FILE OUTPUT_FIILE");
+
+ bloggersFile = args [0];
+ outputFile = args [1];
+
+ do {
+ Console.WriteLine ("Updating");
+ RunOnce ();
+ System.Threading.Thread.Sleep (60 * 1000);
+ } while (true);
+ }
+
+ static void RunOnce ()
+ {
+ if (bloggers == null || File.GetLastWriteTime (bloggersFile) > lastReadOfBloggersFile) {
+ lastReadOfBloggersFile = File.GetLastWriteTime (bloggersFile);
+ bloggers = BloggerCollection.LoadFromFile (bloggersFile);
+ }
+
+ bool somethingChanged = false;
+
+ foreach (Blogger b in bloggers.Bloggers)
+ somethingChanged |= b.UpdateFeed ();
+
+ if (!somethingChanged)
+ return;
+
+ outFeed = new RssFeed ();
+ RssChannel ch = new RssChannel ();
+ ch.Title = "Monologue";
+ ch.Generator = "Monologue worker: b-diddy powerd";
+ ch.Description = "The voices of Mono";
+ ch.Link = new Uri ("http://dunno.com");
+
+ ArrayList stories = new ArrayList ();
+
+ foreach (Blogger b in bloggers.Bloggers) {
+ foreach (RssItem i in b.Channel.Items)
+ stories.Add (i);
+ }
+
+ stories.Sort (new ReverseRssItemComparer ());
+
+ foreach (RssItem itm in stories)
+ ch.Items.Add (itm);
+
+ outFeed.Channels.Add (ch);
+ outFeed.Write (outputFile);
+ }
+
+ public class ReverseRssItemComparer : IComparer {
+ int IComparer.Compare( Object x, Object y )
+ {
+ return DateTime.Compare (((RssItem)y).PubDate, ((RssItem)x).PubDate.Date);
+ }
+ }
+}
+
+public class BloggerCollection {
+ static XmlSerializer serializer = new XmlSerializer (typeof (BloggerCollection));
+
+ public static BloggerCollection LoadFromFile (string file)
+ {
+ return (BloggerCollection)serializer.Deserialize (new XmlTextReader (file));
+ }
+
+ [XmlElement ("Blogger", typeof (Blogger))]
+ public ArrayList Bloggers;
+}
+
+public class Blogger {
+ [XmlAttribute] public string Name;
+ [XmlAttribute] public string Email;
+ [XmlAttribute] public string RssUrl;
+
+ RssFeed feed;
+ [XmlIgnore]
+ public RssChannel Channel {
+ get {
+ if (feed == null)
+ throw new Exception ("Must update feed before getting the channel");
+
+ return feed.Channels [0];
+ }
+ }
+
+ public bool UpdateFeed ()
+ {
+ if (feed == null) {
+ feed = RssFeed.Read (RssUrl);
+ foreach (RssItem i in feed.Channels [0].Items)
+ i.Author = Name;
+ return true;
+ } else {
+ RssFeed old = feed;
+ feed = RssFeed.Read (feed);
+ if (feed != old) {
+ foreach (RssItem i in feed.Channels [0].Items)
+ i.Author = Name;
+
+ Console.WriteLine ("Updated {0}", Name);
+ }
+ return feed == old;
+ }
+ }
+}
BIN  www/bin/RSS.NET.dll
Binary file not shown
6 www/bloggers.xml
@@ -0,0 +1,6 @@
+<BloggerCollection>
+ <Blogger Name="Ben Maurer" Email="bmaurer@users.sourceforge.net" RssUrl="http://codeblogs.ximian.com/blogs/benm/index.xml" />
+ <Blogger Name="Miguel de Icaza" Email="miguel@ximian.com" RssUrl="http://primates.ximian.com/~miguel/miguel.rss2" />
+ <Blogger Name="Jackson Harper" Email="jackson@ximian.com" RssUrl="http://www.jacksonh.net/jackson/blog/jackson.rss2" />
+
+</BloggerCollection>
129 www/index.aspx
@@ -0,0 +1,129 @@
+<%@ Page Language="C#" %>
+<%@ import namespace="Rss" %>
+<html>
+<head>
+<script language="C#" runat="server">
+
+ void Page_Load(object src, EventArgs e)
+ {
+ if (!Page.IsPostBack){
+ DaysList.DataBind ();
+ }
+
+ }
+
+ IList GetDaysCollectionList ()
+ {
+ Hashtable ht = new Hashtable ();
+
+ foreach (RssItem itm in RssFeed.Read (Server.MapPath ("monologue.rss")).Channels [0].Items) {
+ ArrayList ar = ht [itm.PubDate.Date] as ArrayList;
+ if (ar != null) {
+ ar.Add (itm);
+ } else {
+ ht [itm.PubDate.Date] = ar = new ArrayList ();
+ ar.Add (itm);
+ }
+ }
+
+ ArrayList ret = new ArrayList (ht.Values);
+ ret.Sort (new ReverseRssItemColComparer ());
+ return ret;
+ }
+
+ public class ReverseRssItemColComparer : IComparer {
+ int IComparer.Compare( Object x, Object y )
+ {
+ return DateTime.Compare (((RssItem)((ArrayList)y) [0]).PubDate.Date, ((RssItem)((ArrayList)x) [0]).PubDate.Date);
+ }
+ }
+
+
+</script>
+
+ <title>Monologue::</title>
+<style type="text/css">
+h1 {
+color: #efefef;
+font-size: 14pt;
+font-family: "Trebuchet MS";
+
+border: 0;
+
+margin: 0;
+
+padding: 1em;
+
+background: #666666;
+}
+
+h2, h3, h4, h5, h6 {
+font-family: Verdana,sans-serif;
+font-weight: bold;
+margin: 9pt;
+}
+
+h2, h3 {
+font-size: 18px;
+}
+
+h2 {
+padding: 3px;
+color: #000000;
+}
+
+h3 {
+font-size: 13px;
+border-bottom: 2px solid #dddddd;
+}
+
+body, table {
+background-color: #ffffff;
+font-family: Verdana, sans-serif; font-size: 12px;
+color: black;
+margin: 0;
+padding: 0;
+border: 0;
+}
+
+.blogentry {
+margin-left: 2em;
+margin-right: 2em;
+}
+
+.blogentry h1, .blogentry h2, .blogentry h3 {
+padding:0;
+margin:0;
+border:0;
+}
+
+img {
+border: 0;
+vertical-align: top;
+}
+
+</style>
+</head>
+<body>
+
+<h1>Monologue</h1>
+
+<asp:Repeater id="DaysList" runat="server" DataSource="<%# GetDaysCollectionList () %>">
+<ItemTemplate>
+ <h2><%# ((RssItem)(((ArrayList)Container.DataItem) [0])).PubDate.Date.ToString ("M") %></h2>
+ <asp:Repeater id="NewsItems" runat="server" DataSource="<%# Container.DataItem %>">
+ <ItemTemplate>
+ <h3><%# ((RssItem)(Container.DataItem)).Author %>: <%# ((RssItem)(Container.DataItem)).Title %></h3>
+ <div class="blogentry">
+ <%# ((RssItem)(Container.DataItem)).Description %>
+ <div>Posted on <%# ((RssItem)(Container.DataItem)).PubDate %></div>
+ </div>
+ </ItemTemplate>
+ </asp:Repeater>
+</ItemTemplate>
+</asp:Repeater>
+
+</body>
+</html>
+
+
3,049 www/monologue.rss
3,049 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.