Introduction
Web RSS Builder is an open source application for managing RSS files using Web-based and Silverlight-based interfaces. This application is useful when you need to manage RSS files on the server using a web application.
The application is hosted on CodePlex at http://WebRSSBuilder.codeplex.com.
This is part 1 of a three-part post which will describe this application:
Why?
I started working on this when I was asked to adapt an open source Desktop-based application to manage RSS files, and since I was working on a big organization, I felt the need to move to a web application for many reasons:
- It will take a long time to get the feedback, and since no update mechanism is embedded in the software, you will need to reinstall it on each update, i.e. headache for the IT department.
- Employees will need access authority to files on the server, which is not really a good idea; security-wise.
Requirements
The application is quite simple! The requirements are:
- Keep a list of all the RSS files on a server
- Attach each file to a specific role
- Develop a web interface to manage RSS files
Application Architecture
The application will contain three main projects:
- The Core Project: This will contain the data binding classes responsible for representing and controlling RSS files.
- The ASP.NET Project: This will contain the ASP.NET Web application interface.
- The Silverlight Project: Actually they are two: client and server, this will contain the Silverlight application interface.
The Core Component
The application will use the Model-View-Controller (MVC) design pattern and its variations Model-View-ViewModel (MVVM) in Silverlight. The core component's main responsibility is to provide a generic data source for RSS files that will be used in ASP.NET and Silverlight.
Model
The Model classes for RSS files are:
RSSFeed
which represents the RSS file, RSS Feed implements INotifyPropertyChanged
to notify binding object with any change in data, it also contains:
- Properties: such as Title, Category, etc.
- RSS Items
- c. Indexer
RSSItem
represents an RSS item which also implements INotifyPropertyChanged
to notify the Feed object with any change in data, it contains:
- Properties: such as
Author
Description
Pubdata
Controller
The Controller is the object responsible for reading and writing RSS XML files and since that could be done in different ways, the controller is abstracted in an interface IRSSFeedController
This interface defines two basic methods for Loading and Saving:
namespace WebRSSBuilder.Core
{
public interface IRSSFeedController
{
RSSFeed LoadRss(string FileURI);
void SaveFeed(RSSFeed Feed);
}
}
The controller could be implemented in different ways:
- Using XML DOM
- Using LINQ to XML
- Using simple stream text
- And maybe others...
At this stage, I provided one implementation using LINQ to XML through the Class RSSFeedXLinqController
For those who are not familiar with LINQ to XML, I will describe that briefly.
This class contains in addition to the interface Load
and Save
methods, three helper methods:
GetElement
takes an XElement
and searches within it for a specific XML tag.
GetAttribute
takes an XElement
and searches within it for a specific XML attribute.
GenerateChannel
takes a Feed file and generates an XElement
for it, the code is self-descriptive, anyways if anybody has any question, please do ask.
private string GetElement(XElement x, string ElementName)
{
XElement Element = x.Element(ElementName);
return (Element == null ? null : Element.Value.Trim());
}
private string GetAttribute(XElement x, string ElementName)
{
string ElementValue = x.Element(channel).Attribute(ElementName).Value;
return (ElementValue == null ? null : ElementValue.Trim());
}
private XElement GenerateChannel(RSSFeed Feed)
{
XElement Channel = new XElement("channel");
#region Saving Properties
if (Feed.Category != null)
Channel.Add(new XElement("category", Feed.Category));
if (Feed.CloudDomain != null)
{
Channel.Add(new XElement("cloud", new XAttribute("domain", Feed.CloudDomain),
new XAttribute("port", Feed.CloudPort),
new XAttribute("registerProcedure", Feed.CloudRegisterProcedure),
new XAttribute("protocol", Feed.CloudProtocol)
));
}
if (Feed.Copyright != null)
Channel.Add(new XElement("copyright", Feed.Copyright));
...
This class implements IRSSFeedController
LoadRss
This method loads the feed properties through GetElement
and loads the items through LoadItem
SaveFeed
This method generates the XLinq
object using the GenerateChannel
method.
public RSSFeed LoadRss(string FileURI)
{
DateTime help;
XElement root = XElement.Load(FileURI);
RSSFeed Feed = new RSSFeed();
XElement Channel = root.Element("channel");
#region Loading properties
Feed.FileName = FileURI;
Feed.Title = GetElement(Channel, "title");
...
#endregion
IEnumerable<xelement> items = from el in Channel.Elements("item") select el;
foreach (XElement item in items)
{
Feed.Items.Add(LoadItem(item));
}
return Feed;
}
private RSSItem LoadItem(XElement x)
{
RSSItem item = new RSSItem();
DateTime help;
bool b;
int i;
item.Author = GetElement(x, "author");
item.Category = GetElement(x, "category");
item.Comments = GetElement(x, "comments");
...
return item;
}
Next Article
In the next article, we will go through the ASP.NET application that will use what we described here to bind to an RSS data source.
Did You Like the Article?
If you did, please vote for it. :)