Click here to Skip to main content
11,417,390 members (45,521 online)
Click here to Skip to main content
Articles » Languages » C# » Samples » Downloads
Add your own
alternative version

RSS 2.0 Framework

, 19 Jan 2013 LGPL3
RSS 2.0 framework implements the RSS 2.0 specification in strongly typed classes. The framework enables you to create and consume valid RSS 2.0 feeds in your code in just a few minutes.
rssframework_bin.zip
Raccoom.Xml.dll
Raccoom.Xml.Editors.exe
DockingManagerExtender.dll
MagicLibrary.DLL
Raccoom.Windows.Forms.dll
rssframework_demo.zip
Raccoom.Bin
DockingManagerExtender.dll
MagicLibrary.DLL
nunit.framework.dll
Raccoom.Windows.Forms
Windows
Forms
Design
Raccoom.Xml
Properties
Raccoom.Xml.csproj.user
Xml
atom.xsx
Raccoom.Xml.Editors
ActionList
Actions
Design
App.ico
Raccoom.Xml.Editors.csproj.user
Windows
Forms
Raccoom.Xml.Test
Resources
rsschannel.rss
bin
rssframework_help.zip
Raccoom.Xml.chm
rssframework_src.zip
rsschannel.rss
Raccoom.Xml.csproj.user
atom.xsx
setup.zip
setup.exe
// Copyright � 2006 by Christoph Richner. All rights are reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
// website http://www.raccoom.net, email support@raccoom.net, msn chrisdarebell@msn.com

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Raccoom.Xml;
namespace Raccoom.Windows.Forms
{
	/// <summary>
	/// RSS 2.0 Generator Form was basically created as non sophisticated demo application for the RSS.NET classes. After some hours of coding the generator transformed to a RSS 2.0 Editor. The editor provides three different views: <list><item>edit view</item><item>preview mode</item><item>xml view</item></list>. The editor can load and save rss xml documents from local storage or from the intranet/internet.
	/// </summary>
	public class FormWindowKindRss : System.Windows.Forms.Form, IChildWindow
	{
		#region fields

		private System.ComponentModel.IContainer components;
		private RssChannel _rssChannel;
		private string _filename = string.Empty;
		private System.Windows.Forms.TabControl _tabControl;
		private System.Windows.Forms.TabPage _tbTechnical;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.ColumnHeader columnHeader3;
		private System.Windows.Forms.ColumnHeader columnHeader4;
		private System.Windows.Forms.ListView _lvFeed;
		private System.Windows.Forms.ListBox _lbChanges;
		private NJFLib.Controls.CollapsibleSplitter splitter1;
		private string _fileDialogFilter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
		private System.Windows.Forms.MenuItem _mnuFile;
		private System.Windows.Forms.MenuItem _mnuView;
		private System.Windows.Forms.ImageList _imageList;
		private System.Windows.Forms.TabPage _tbPreview;
		private System.Windows.Forms.PropertyGrid _propertyGrid;
		/// <summary>Flag specify that views have to refresh cause data changes</summary>
		private bool _refreshViews = false;
		private System.Windows.Forms.MainMenu _mainMenu;
		private bool _isChannelDirty = false;
		private MenuItem _lastSelectedView;
		private System.Net.WebProxy _webProxy = null;
		#endregion

		public FormWindowKindRss()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();	
			this.Text = this.ProductName;			
		}


		#region internal interface
		private void OpenHyperlink(string url)
		{
			System.Diagnostics.Process.Start(url);
		}
		private delegate void LoadChannelDelegate(string location);
		/// <summary>
		/// Create a new RssChannel and update the UI
		/// </summary>
		private void LoadChannel(string location)
		{
			this.Cursor = Cursors.WaitCursor;
			try
			{
				Uri uri = new Uri(location);				
				this._rssChannel = new RssChannel(uri, _webProxy);				
				_lbChanges.Items.Clear();
				_rssChannel.PropertyChanged += new PropertyChangedEventHandler(_rssChannel_PropertyChanged);
				_propertyGrid.SelectedObject = _rssChannel;
				PopulateListView();
				// local storage system
				_filename = (uri.Host.Length==0) ? location : string.Empty;				
				//
				this.Text = _rssChannel.ToString();
			} 
			catch (System.Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.Cursor = Cursors.Default;
		}
		/// <summary>
		/// Refresh the listview with the current rss channel items.
		/// </summary>
		private void PopulateListView()
		{
			_lvFeed.BeginUpdate();
			_lvFeed.Items.Clear();
			foreach(IRssItem item in _rssChannel.Items)
			{
				ListViewItem lvItem = new ListViewItem(item.Title);
				lvItem.Tag = item;
				lvItem.SubItems.Add(item.Description);
				lvItem.SubItems.Add(item.PubDate.ToUniversalTime().ToString());
				lvItem.SubItems.Add(item.Category);
				_lvFeed.Items.Add(lvItem);
			}
			_lvFeed.EndUpdate();
		}
		private void RefreshView()
		{			
			PopulateListView();
		}
		private void NewChannel()
		{
			_rssChannel = new RssChannel();			
			_lbChanges.Items.Clear();
			_rssChannel.PropertyChanged += new PropertyChangedEventHandler(_rssChannel_PropertyChanged);
			_propertyGrid.SelectedObject = _rssChannel;
			_filename = string.Empty;			
		}
		private void OpenChannelLocal(string filename)
		{
			try
			{
				if(filename==null)
				{
					OpenFileDialog saveFileDialog1 = new OpenFileDialog(); 
					saveFileDialog1.Filter = _fileDialogFilter;					
					saveFileDialog1.RestoreDirectory = true; 
					if(saveFileDialog1.ShowDialog() != DialogResult.OK) return;
					_filename = saveFileDialog1.FileName;
				} 
				else
				{
					_filename = filename;
				}
				try
				{
					_isChannelDirty= false;
					LoadChannel(_filename);	
				} 
				catch (System.Exception ex)
				{
					System.Diagnostics.Debug.Write(ex.Message);
				}
			} 
			catch (System.Exception ex)
			{
				MessageBox.Show(ex.Message);
			}			
		}		
		
		private void CloseChannel()
		{
			_rssChannel = null;
			_propertyGrid.SelectedObject = null;
			this._lvFeed.Items.Clear();
			
			this.Text = this.ProductName;
			_isChannelDirty= false;
		}	
		#endregion

		#region events
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);
			//
			for(int i = _tabControl.TabPages.Count-1;i>=0;i--)
			{
				TabPage page = _tabControl.TabPages[i];
				System.Windows.Forms.MenuItem item = new System.Windows.Forms.MenuItem(page.Text);				
				item.Click += new EventHandler(OnViewMenuItemClick);
				page.Tag = item;
				this._mnuView.MenuItems.Add(0,item);
			}
		}
		/// <summary>
		/// Rss channel is dirty
		/// </summary>
		private void _rssChannel_PropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			// set flag to specify that next time preview or xml view is displayed they need to redraw
			_refreshViews = true;
			Dirty = true;
			//
			_lbChanges.Items.Insert(0,sender.GetType().Name+" - " + e.PropertyName);		
		}

		/// <summary>
		/// user clicked on a rss channel item in the listview. If the item link is set, load it.
		/// </summary>
		private void _lvFeed_DoubleClick(object sender, System.EventArgs e)
		{
			if (this._lvFeed.SelectedItems.Count == 0) return;
			RssItem item = this._lvFeed.SelectedItems[0].Tag as RssItem;
			//
			if(item==null || item.Link==null) return;
			//
			OpenHyperlink(item.Link);
		}
		private void _tabControl_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(_lastSelectedView!=null) _lastSelectedView.Checked = false;
			((MenuItem)this._tabControl.SelectedTab.Tag).Checked = true;
			_lastSelectedView = this._tabControl.SelectedTab.Tag as MenuItem;
			//
			if(this._tabControl.SelectedIndex > 0 && _refreshViews) 
			{
				this.RefreshView();
				//
				_refreshViews = false;
			}
		}
		private void OnViewMenuItemClick(object sender, EventArgs e)
		{
			foreach(TabPage page in _tabControl.TabPages)
			{
				if(page.Text == ((MenuItem)sender).Text)
				{
					_tabControl.SelectedTab = page;
					break;
				}
			}
		}
		
		private void _actClose_Update(object sender, System.EventArgs e)
		{
			_isChannelDirty = false;			
		}
		
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormWindowKindRss));
			this._imageList = new System.Windows.Forms.ImageList(this.components);
			this._propertyGrid = new System.Windows.Forms.PropertyGrid();
			this._tabControl = new System.Windows.Forms.TabControl();
			this._tbTechnical = new System.Windows.Forms.TabPage();
			this.splitter1 = new NJFLib.Controls.CollapsibleSplitter();
			this._lbChanges = new System.Windows.Forms.ListBox();
			this._tbPreview = new System.Windows.Forms.TabPage();
			this._lvFeed = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
			this._mainMenu = new System.Windows.Forms.MainMenu();
			this._mnuFile = new System.Windows.Forms.MenuItem();
			this._mnuView = new System.Windows.Forms.MenuItem();
			this._tabControl.SuspendLayout();
			this._tbTechnical.SuspendLayout();
			this._tbPreview.SuspendLayout();
			this.SuspendLayout();
			// 
			// _imageList
			// 
			this._imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
			this._imageList.ImageSize = new System.Drawing.Size(16, 16);
			this._imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("_imageList.ImageStream")));
			this._imageList.TransparentColor = System.Drawing.Color.Magenta;
			// 
			// _propertyGrid
			// 
			this._propertyGrid.CommandsVisibleIfAvailable = true;
			this._propertyGrid.Dock = System.Windows.Forms.DockStyle.Fill;
			this._propertyGrid.LargeButtons = false;
			this._propertyGrid.LineColor = System.Drawing.SystemColors.ScrollBar;
			this._propertyGrid.Location = new System.Drawing.Point(0, 0);
			this._propertyGrid.Name = "_propertyGrid";
			this._propertyGrid.Size = new System.Drawing.Size(496, 320);
			this._propertyGrid.TabIndex = 0;
			this._propertyGrid.Text = "propertyGrid1";
			this._propertyGrid.ViewBackColor = System.Drawing.SystemColors.Window;
			this._propertyGrid.ViewForeColor = System.Drawing.SystemColors.WindowText;
			// 
			// _tabControl
			// 
			this._tabControl.Alignment = System.Windows.Forms.TabAlignment.Bottom;
			this._tabControl.Controls.Add(this._tbTechnical);
			this._tabControl.Controls.Add(this._tbPreview);
			this._tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
			this._tabControl.ImageList = this._imageList;
			this._tabControl.Location = new System.Drawing.Point(0, 0);
			this._tabControl.Name = "_tabControl";
			this._tabControl.SelectedIndex = 0;
			this._tabControl.ShowToolTips = true;
			this._tabControl.Size = new System.Drawing.Size(504, 398);
			this._tabControl.TabIndex = 4;
			this._tabControl.SelectedIndexChanged += new System.EventHandler(this._tabControl_SelectedIndexChanged);
			// 
			// _tbTechnical
			// 
			this._tbTechnical.Controls.Add(this._propertyGrid);
			this._tbTechnical.Controls.Add(this.splitter1);
			this._tbTechnical.Controls.Add(this._lbChanges);
			this._tbTechnical.ImageIndex = 6;
			this._tbTechnical.Location = new System.Drawing.Point(4, 4);
			this._tbTechnical.Name = "_tbTechnical";
			this._tbTechnical.Size = new System.Drawing.Size(496, 371);
			this._tbTechnical.TabIndex = 1;
			this._tbTechnical.Text = "Design";
			this._tbTechnical.ToolTipText = "Shows the strong typed rss channel";
			// 
			// splitter1
			// 
			this.splitter1.AnimationDelay = 20;
			this.splitter1.AnimationStep = 20;
			this.splitter1.BorderStyle3D = System.Windows.Forms.Border3DStyle.Flat;
			this.splitter1.ControlToHide = this._lbChanges;
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter1.ExpandParentForm = false;
			this.splitter1.Location = new System.Drawing.Point(0, 320);
			this.splitter1.Name = "splitter1";
			this.splitter1.TabIndex = 4;
			this.splitter1.TabStop = false;
			this.splitter1.UseAnimations = true;
			this.splitter1.VisualStyle = NJFLib.Controls.VisualStyles.DoubleDots;
			// 
			// _lbChanges
			// 
			this._lbChanges.Dock = System.Windows.Forms.DockStyle.Bottom;
			this._lbChanges.Location = new System.Drawing.Point(0, 328);
			this._lbChanges.Name = "_lbChanges";
			this._lbChanges.Size = new System.Drawing.Size(496, 43);
			this._lbChanges.TabIndex = 3;
			// 
			// _tbPreview
			// 
			this._tbPreview.Controls.Add(this._lvFeed);
			this._tbPreview.ImageIndex = 7;
			this._tbPreview.Location = new System.Drawing.Point(4, 4);
			this._tbPreview.Name = "_tbPreview";
			this._tbPreview.Size = new System.Drawing.Size(496, 371);
			this._tbPreview.TabIndex = 0;
			this._tbPreview.Text = "Preview";
			this._tbPreview.ToolTipText = "RSS channel items filled into listview";
			// 
			// _lvFeed
			// 
			this._lvFeed.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																					  this.columnHeader1,
																					  this.columnHeader2,
																					  this.columnHeader3,
																					  this.columnHeader4});
			this._lvFeed.Dock = System.Windows.Forms.DockStyle.Fill;
			this._lvFeed.FullRowSelect = true;
			this._lvFeed.GridLines = true;
			this._lvFeed.Location = new System.Drawing.Point(0, 0);
			this._lvFeed.MultiSelect = false;
			this._lvFeed.Name = "_lvFeed";
			this._lvFeed.Size = new System.Drawing.Size(496, 371);
			this._lvFeed.TabIndex = 0;
			this._lvFeed.View = System.Windows.Forms.View.Details;
			this._lvFeed.DoubleClick += new System.EventHandler(this._lvFeed_DoubleClick);
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "Title";
			this.columnHeader1.Width = 96;
			// 
			// columnHeader2
			// 
			this.columnHeader2.Text = "Description";
			this.columnHeader2.Width = 152;
			// 
			// columnHeader3
			// 
			this.columnHeader3.Text = "Date";
			this.columnHeader3.Width = 121;
			// 
			// columnHeader4
			// 
			this.columnHeader4.Text = "Category";
			this.columnHeader4.Width = 102;
			// 
			// _mainMenu
			// 
			this._mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this._mnuFile,
																					  this._mnuView});
			// 
			// _mnuFile
			// 
			this._mnuFile.Index = 0;
			this._mnuFile.MergeType = System.Windows.Forms.MenuMerge.Remove;
			this._mnuFile.Text = "&File";
			// 
			// _mnuView
			// 
			this._mnuView.Index = 1;
			this._mnuView.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
			this._mnuView.Text = "&View";
			// 
			// FormWindowKindRss
			// 
			this.AllowDrop = true;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(504, 398);
			this.Controls.Add(this._tabControl);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this._mainMenu;
			this.Name = "FormWindowKindRss";
			this.Text = "Rss Document";
			this._tabControl.ResumeLayout(false);
			this._tbTechnical.ResumeLayout(false);
			this._tbPreview.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		#region nested class
		[Serializable]
		public class RssGeneratorFormSettings
		{
			#region fields
			private Rectangle _desktopBounds;
			private System.Collections.Specialized.StringCollection _recentFileList;	
			private NetworkCredentialInfo _proxySettings;
			#endregion

			public RssGeneratorFormSettings()
			{
				this._recentFileList = new System.Collections.Specialized.StringCollection();
				this.ProxySettings = new NetworkCredentialInfo();				
			}
			public NetworkCredentialInfo ProxySettings
			{
				get
				{
					return _proxySettings;
				}
				set
				{
					_proxySettings = value;
				}
			}
			public Rectangle DesktopBounds
			{
				get
				{
					return _desktopBounds;
				}
				set
				{
					_desktopBounds = value;
				}
			}
			public System.Collections.Specialized.StringCollection RecentFileList
			{
				get
				{
					return _recentFileList;
				}
				set
				{
					_recentFileList = value;
				}
			}
			
			[Serializable]
			public class NetworkCredentialInfo
			{
				private string _user;
				private string _password;
				private string _domain;
				private Uri _uri;

				public System.Net.NetworkCredential NetworkCredential
				{
					get
					{
						return new System.Net.NetworkCredential(_user, _password, _domain);
					}
					set
					{
						if(value == null)
						{
						} 
						else
						{
							this._user = value.UserName;
							this._password = value.Password;
							this._domain = value.Domain;
						}
					}
				}
				public string Username
				{
					get
					{
						return _user;
					}
					set
					{
						_user = value;
					}
				}
				public string Password
				{
					get
					{
						return _password;
					}
					set
					{
						_password = value;
					}
				}
				public string Domain
				{
					get
					{
						return _domain;
					}
					set
					{
						_domain = value;
					}
				}
				public Uri Uri
				{
					get
					{
						return _uri;
					}
					set
					{
						_uri = value;
					}
				}
			}
		}
		#endregion

		#region IChildWindow Members
		string IChildWindow.XsltStyleSheet
		{
			get
			{
				return "Raccoom.Xml.Editors.gotdotnet.xslt";
			}
		}	
		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
		string IChildWindow.Filename
		{
			get
			{
				return this._filename;
			}
			set
			{
				_filename = value;
			}
		}
		public override string Text
		{
			get
			{
				return (_rssChannel!=null && _rssChannel.Title!=null && _rssChannel.Title.Length>0) ? _rssChannel.Title : "Rss Document";
			}
			set
			{
				base.Text = value;
			}
		}

		
		void IChildWindow.Close()
		{
			this.Close();
		}
		void IChildWindow.Refresh()
		{
			this.RefreshView();
		}

		public void Open(Uri uri)
		{
			if(uri!=null)
			{
				this.LoadChannel(uri.AbsoluteUri);
			} 
			else 
			{
				this.NewChannel();
			}
		}

		public bool Dirty
		{
			get
			{				
				return this._isChannelDirty;
			}
			set
			{
				_isChannelDirty = value;
				if(PropertyChanged!=null) PropertyChanged(this, new PropertyChangedEventArgs(""));
			}
		}		
		Raccoom.Xml.IPersistentManager IChildWindow.Object
		{
			get
			{
				return _rssChannel;
			}
		}
		#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 GNU Lesser General Public License (LGPLv3)

Share

About the Author

Chris Richner
Software Developer (Senior) Zeit AG
Switzerland Switzerland
Biography
  • 1996 - 1998 PC Board PPL, HTML, DHTML, Javascript and ASP
  • 1999 - 2001 coding Centura against Sql Database (SqlBase,MSSQL,Oracle)
  • 2002 - 2004 C# Windows Forms
  • 2005 - 2006 C# ASP.NET, Windows Forms
  • 2006 - 2009 C#, WCF, WF, WPF
  • 2010 - 2012 C#, Dynamics CRM, Sharepoint, Silverlight
  • 2013 - 2013 C#, WCF DS (OData), WF, WPF
  • 2014 - now C#, Azure PaaS, Identity, OWIN, OData, Web Api
Interests
  • family & friends
  • chilaxing ,)
  • coding
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150427.4 | Last Updated 20 Jan 2013
Article Copyright 2003 by Chris Richner
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid