Click here to Skip to main content
15,895,142 members
Articles / Web Development / ASP.NET

RSS 2.0 Framework

Rate me:
Please Sign up or sign in to vote.
4.92/5 (67 votes)
19 Jan 2013LGPL37 min read 508.6K   15.2K   361  
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.
// 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>
	/// 
	/// </summary>
	public class FormWindowKindOpml : System.Windows.Forms.Form, IChildWindow
	{
		#region fields		

		private System.ComponentModel.IContainer components;
		private OpmlDocument _opmlDocument;
		private string _filename = string.Empty;
		private System.Windows.Forms.MenuItem _mnuView;
		private System.Windows.Forms.ImageList _imageList;
		/// <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.Windows.Forms.TabPage _tbTechnical;
		private TreeViewOpmlDocument _tvOutline;
		private System.Windows.Forms.Splitter splitter2;
		private System.Windows.Forms.PropertyGrid _propertyGrid;
		private NJFLib.Controls.CollapsibleSplitter splitter1;
		private System.Windows.Forms.ListBox _lbChanges;
		private System.Windows.Forms.TabControl _tabControl;
		private System.Windows.Forms.ContextMenu _cmTreeView;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem2;
		#endregion

		public FormWindowKindOpml()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();			
		}


		#region internal interface
		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._opmlDocument = new OpmlDocument(uri);				
				_opmlDocument.PropertyChanged += new PropertyChangedEventHandler(_opmlDocument_PropertyChanged);
				//				
				_lbChanges.Items.Clear();				
				_propertyGrid.SelectedObject = _opmlDocument;				
				// local storage system
				_filename = (uri.Host.Length==0) ? location : string.Empty;				
			} 
			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 PopulateTreeViewRoot()
		{
			this._tvOutline.Populate(this._opmlDocument);		
		}
		private void RefreshView()
		{			
			PopulateTreeViewRoot();
		}
	
		private void OpenHyperlink(string url)
		{
			System.Diagnostics.Process.Start(url);
		}
		private void NewChannel()
		{
			_opmlDocument = new OpmlDocument();
			_opmlDocument.PropertyChanged += new PropertyChangedEventHandler(_opmlDocument_PropertyChanged);			
			
			_lbChanges.Items.Clear();
			_propertyGrid.SelectedObject = _opmlDocument;
			_filename = string.Empty;			
		}
		
		private void CloseChannel()
		{
			_opmlDocument = null;
			_propertyGrid.SelectedObject = null;
			this._tvOutline.Nodes.Clear();			
			this.Text = this.ProductName;
			Dirty= 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);
			}			
		}
		
		private void _tvOutline_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if(e.Node ==null) return;
			TreeNodeOpmlOutline n = e.Node as TreeNodeOpmlOutline;
			this._propertyGrid.SelectedObject =(n.OpmlOutlineItem!=null) ?  (object) n.OpmlOutlineItem :  (object) this._opmlDocument;
			
		
		}
		
		/// <summary>
		/// Rss channel is dirty
		/// </summary>
		private void _opmlDocument_PropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			// set flag to specify that next time preview or xml view is displayed they need to redraw
			_refreshViews = true;
			this.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._tvOutline.SelectedNode==null) return;
			OpmlOutline item = this._tvOutline.SelectedNode.Tag as OpmlOutline;
			//
			if(item==null || item.XmlUrl==null) return;
			//
			OpenHyperlink(item.XmlUrl);
		}
		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 _mnuHelpWebSite_Click(object sender, System.EventArgs e)
		{
			OpenHyperlink("http://raccoom.sytes.net");
		}
        private void _axWebBrowserHtml_BeforeNavigate2(object sender, WebBrowserNavigatingEventArgs  e)
		{
			if(e.Url.ToString().IndexOf("http://")!=-1)
			{
				e.Cancel = true;
				OpenHyperlink(e.Url.ToString());

			}
		}
		private void _actClose_Update(object sender, System.EventArgs e)
		{
			Dirty = 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(FormWindowKindOpml));
			this._imageList = new System.Windows.Forms.ImageList(this.components);
			this._mainMenu = new System.Windows.Forms.MainMenu();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this._mnuView = new System.Windows.Forms.MenuItem();
			this._tbTechnical = new System.Windows.Forms.TabPage();
			this._tvOutline = new TreeViewOpmlDocument(this.components);
			this._cmTreeView = new System.Windows.Forms.ContextMenu();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.splitter2 = new System.Windows.Forms.Splitter();
			this._propertyGrid = new System.Windows.Forms.PropertyGrid();
			this.splitter1 = new NJFLib.Controls.CollapsibleSplitter();
			this._lbChanges = new System.Windows.Forms.ListBox();
			this._tabControl = new System.Windows.Forms.TabControl();
			this._tbTechnical.SuspendLayout();
			this._tabControl.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.Transparent;
			// 
			// _mainMenu
			// 
			this._mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem2,
																					  this._mnuView});
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.MergeType = System.Windows.Forms.MenuMerge.Remove;
			this.menuItem2.Text = "&File";
			// 
			// _mnuView
			// 
			this._mnuView.Index = 1;
			this._mnuView.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
			this._mnuView.Text = "&View";
			// 
			// _tbTechnical
			// 
			this._tbTechnical.Controls.Add(this._tvOutline);
			this._tbTechnical.Controls.Add(this.splitter2);
			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";
			// 
			// _tvOutline
			// 
			this._tvOutline.AllowDrop = true;
			this._tvOutline.ContextMenu = this._cmTreeView;
			this._tvOutline.Dock = System.Windows.Forms.DockStyle.Fill;
			this._tvOutline.FullRowSelect = true;
			this._tvOutline.LabelEdit = true;
			this._tvOutline.Location = new System.Drawing.Point(0, 0);
			this._tvOutline.Name = "_tvOutline";
			this._tvOutline.Size = new System.Drawing.Size(285, 320);
			this._tvOutline.TabIndex = 6;
			this._tvOutline.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this._tvOutline_AfterSelect);
			// 
			// _cmTreeView
			// 
			this._cmTreeView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						this.menuItem3});
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 0;
			this.menuItem3.Text = "&New Item";
			// 
			// splitter2
			// 
			this.splitter2.Dock = System.Windows.Forms.DockStyle.Right;
			this.splitter2.Location = new System.Drawing.Point(285, 0);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(3, 320);
			this.splitter2.TabIndex = 5;
			this.splitter2.TabStop = false;
			// 
			// _propertyGrid
			// 
			this._propertyGrid.CommandsVisibleIfAvailable = true;
			this._propertyGrid.Dock = System.Windows.Forms.DockStyle.Right;
			this._propertyGrid.LargeButtons = false;
			this._propertyGrid.LineColor = System.Drawing.SystemColors.ScrollBar;
			this._propertyGrid.Location = new System.Drawing.Point(288, 0);
			this._propertyGrid.Name = "_propertyGrid";
			this._propertyGrid.Size = new System.Drawing.Size(208, 320);
			this._propertyGrid.TabIndex = 0;
			this._propertyGrid.Text = "propertyGrid1";
			this._propertyGrid.ViewBackColor = System.Drawing.SystemColors.Window;
			this._propertyGrid.ViewForeColor = System.Drawing.SystemColors.WindowText;
			// 
			// 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;
			// 
			// _tabControl
			// 
			this._tabControl.Alignment = System.Windows.Forms.TabAlignment.Bottom;
			this._tabControl.Controls.Add(this._tbTechnical);
			this._tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
			this._tabControl.ImageList = this._imageList;
			this._tabControl.ItemSize = new System.Drawing.Size(67, 19);
			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);
			// 
			// FormWindowKindOpml
			// 
			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 = "FormWindowKindOpml";
			this.Text = "Opml Document";
			this._tbTechnical.ResumeLayout(false);
			this._tabControl.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion						

		#region nested class
		public class TreeNodeOpml : System.Windows.Forms.TreeNode
		{
			#region fields
			private OpmlOutline _outline;
			#endregion fiels

			#region constructor
			public TreeNodeOpml()
			{
			}
			public TreeNodeOpml(string text) : base(text)
			{
			}			
			public TreeNodeOpml(string text,int imageIndex,	int selectedImageIndex) : base(text, imageIndex, selectedImageIndex)
			{
			}
			#endregion

			#region public interface
			/// <summary>
			/// Adds a dummy node to the parent node
			/// </summary>		
			public virtual void AddDummyNode()
			{
				Nodes.Add(new TreeNodeOpml("@@Dummy@@"));
			}
			/// <summary>
			/// Removes the dummy node from the parent node.
			/// </summary>		
			public virtual void RemoveDummyNode()
			{
				if ((Nodes.Count == 1 ) & (Nodes[0].Text == "@@Dummy@@"))
				{
					Nodes[0].Remove();
				}
			}			
			public virtual OpmlOutline Outline
			{
				get
				{
					return _outline;
				}
				set
				{
					_outline = value;
				}
			}
			#endregion
		}
		#endregion

		#region IChildWindow Members
		string IChildWindow.XsltStyleSheet
		{
			get
			{
				return "Raccoom.Xml.Editors.opml.xslt";
			}
		}	
		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
		string IChildWindow.Filename{
			get
			{
				return this._filename;
			}
			set
			{
				_filename = value;
			}
		}
		public override string Text
		{
			get
			{
				return (_opmlDocument!=null && _opmlDocument.Head.Title!=null && _opmlDocument.Head.Title.Length>0) ? _opmlDocument.Head.Title : "Opml 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 _opmlDocument;
			}
		}
		
		#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)


Written By
Software Developer (Senior)
Switzerland Switzerland
My interest is in the future because I am going to spend the rest of my life there. (Charles Kettering)

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 - 2016 C#, Azure PaaS, Identity, OWIN, OData, Web Api
  • 2017 - now C#, aspnet.core, IdentityServer4, TypeScript & Angular @ Azure IaaS or PaaS

Interests

  • family & friends
  • chilaxing ,)
  • coding

Comments and Discussions