Click here to Skip to main content
15,893,668 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.3K   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 Raccoom.Xml;

namespace Raccoom.Windows.Forms
{
	/// <summary>
	/// FavoriteUrlEditDialog belongs to a set of dialogs that are Internet Explorer Favorite clones.
	/// </summary>
	public class FavoritesAddFavoriteDialog : System.Windows.Forms.Form, IRssFeedDataAdaptorAddFavoriteView
	{
		#region fields
		private OpmlOutlineFavorite _opmlOutline;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox _textDesc;
		private System.Windows.Forms.TextBox _textUrl;
		private System.Windows.Forms.Button _pbOK;
		private System.Windows.Forms.Button _pbCancel;
		private System.Windows.Forms.ErrorProvider _errorProvider;
		private OpmlDocument _opmlDocument = null;		
		private System.Windows.Forms.Label label3;
		private Raccoom.Windows.Forms.TreeViewOpmlDocument _tvOutline;
		private System.Windows.Forms.Button _btNewFolder;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.ImageList _imageList;
		private System.Windows.Forms.CheckBox _cbXOpml;
		private System.ComponentModel.IContainer components;
		#endregion

		#region constructors
		public FavoritesAddFavoriteDialog()
		{
			//
			InitializeComponent();
			//
			this.MaximumSize = new Size(this.Width *5, Height*5);
			this.MinimumSize = new Size(this.Width, this.Height);			
		}

		#endregion

		#region public interface		
		/// <summary>
		/// Gets or sets the <see cref="FavoriteUrl"/> to edit.
		/// </summary>
		public OpmlOutlineFavorite Favorite
		{
			get
			{
				return _opmlOutline;
			}
			set
			{
				_opmlOutline = value;
				this._textDesc.Text  = value.Text;
				this._textUrl.Text = value.XmlUrl;
			}
		}
		#endregion

		#region events
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad (e);
			this.label4.Text = string.Format(label4.Text, this.ProductName);
		}

		private void _btNewFolder_Click(object sender, System.EventArgs e)
		{
			FavoritesNewFolderDialog inputBox = new FavoritesNewFolderDialog();
			if(inputBox.ShowDialog() != DialogResult.OK) return;
			OpmlOutline outline = new OpmlOutline();
			outline.Text = inputBox.Title;
			TreeNodeOpmlOutline node = _tvOutline.CreateNewFolder(_tvOutline.SelectedNode as TreeNodeOpmlOutline ,outline);
			node.EnsureVisible();
			_tvOutline.SelectedNode = node;
		}
		/// <summary>
		/// Fired if description text changed, used to enable ok button if text length greater 0.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnDescTextChanged(object sender, System.EventArgs e)
		{
			this._pbOK.Enabled = _textDesc.Text.Length>0;			
		}
		private void _textUrl_TextChanged(object sender, System.EventArgs e)
		{
			// suggest 
			if(_textUrl.Text.ToLower().IndexOf(".opml")!=-1) this._cbXOpml.Checked = true;
		}
		/// <summary>
		/// Fired if user hit enter or ESC, validates the given data and apply the changes made to <c>FavoriteUrl</c> property if validation is ok.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnClick(object sender, System.EventArgs e)
		{
			if(sender.Equals(_pbOK))
			{
				try
				{					
					new Uri(_textUrl.Text);
				} 
				catch(System.Exception ex)
				{
					this._errorProvider.SetError(_textUrl, ex.Message);
					return;
				}
				this.DialogResult = DialogResult.OK;
				//
				if(this._opmlOutline == null)
				{
					this._opmlOutline = new OpmlOutlineFavorite();					
				}
				//
				if(this._cbXOpml.Checked) _opmlOutline.Type = OpmlOutline.OpmlTypeLinkReference;
				//
				TreeNodeOpmlOutline node = this._tvOutline.SelectedNode as TreeNodeOpmlOutline;				
				if(node!=null)
				{
					node.OpmlOutlineItem.Items.Add(_opmlOutline);
				} 
				else
				{
					this._opmlDocument.Body.Items.Add(_opmlOutline);
				}
				this._opmlOutline.Text = this._textDesc.Text;
				this._opmlOutline.XmlUrl = _textUrl.Text;
			}
			this.Close();		
		}
		#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(FavoritesAddFavoriteDialog));
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this._textDesc = new System.Windows.Forms.TextBox();
			this._textUrl = new System.Windows.Forms.TextBox();
			this._pbOK = new System.Windows.Forms.Button();
			this._pbCancel = new System.Windows.Forms.Button();
			this._errorProvider = new System.Windows.Forms.ErrorProvider();
			this._tvOutline = new Raccoom.Windows.Forms.TreeViewOpmlDocument(this.components);
			this.label3 = new System.Windows.Forms.Label();
			this._btNewFolder = new System.Windows.Forms.Button();
			this.label4 = new System.Windows.Forms.Label();
			this._imageList = new System.Windows.Forms.ImageList(this.components);
			this._cbXOpml = new System.Windows.Forms.CheckBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 64);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Name:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 88);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 23);
			this.label2.TabIndex = 1;
			this.label2.Text = "Url:";
			// 
			// _textDesc
			// 
			this._textDesc.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this._textDesc.Location = new System.Drawing.Point(56, 56);
			this._textDesc.Name = "_textDesc";
			this._textDesc.Size = new System.Drawing.Size(264, 20);
			this._textDesc.TabIndex = 0;
			this._textDesc.Text = "";
			this._textDesc.TextChanged += new System.EventHandler(this.OnDescTextChanged);
			// 
			// _textUrl
			// 
			this._textUrl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this._textUrl.Location = new System.Drawing.Point(56, 88);
			this._textUrl.Name = "_textUrl";
			this._textUrl.Size = new System.Drawing.Size(264, 20);
			this._textUrl.TabIndex = 1;
			this._textUrl.Text = "";
			this._textUrl.TextChanged += new System.EventHandler(this._textUrl_TextChanged);
			// 
			// _pbOK
			// 
			this._pbOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this._pbOK.Enabled = false;
			this._pbOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this._pbOK.Location = new System.Drawing.Point(336, 16);
			this._pbOK.Name = "_pbOK";
			this._pbOK.TabIndex = 2;
			this._pbOK.Text = "&OK";
			this._pbOK.Click += new System.EventHandler(this.OnClick);
			// 
			// _pbCancel
			// 
			this._pbCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this._pbCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this._pbCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this._pbCancel.Location = new System.Drawing.Point(336, 48);
			this._pbCancel.Name = "_pbCancel";
			this._pbCancel.TabIndex = 3;
			this._pbCancel.Text = "&Cancel";
			this._pbCancel.Click += new System.EventHandler(this.OnClick);
			// 
			// _errorProvider
			// 
			this._errorProvider.ContainerControl = this;
			// 
			// _tvOutline
			// 
			this._tvOutline.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this._tvOutline.HideSelection = false;
			this._tvOutline.Location = new System.Drawing.Point(70, 144);
			this._tvOutline.Name = "_tvOutline";
			this._tvOutline.ShowLines = false;
			this._tvOutline.ShowRootLines = false;
			this._tvOutline.Size = new System.Drawing.Size(246, 152);
			this._tvOutline.TabIndex = 4;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 136);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 23);
			this.label3.TabIndex = 7;
			this.label3.Text = "Create in:";
			// 
			// _btNewFolder
			// 
			this._btNewFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this._btNewFolder.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this._btNewFolder.Location = new System.Drawing.Point(336, 136);
			this._btNewFolder.Name = "_btNewFolder";
			this._btNewFolder.TabIndex = 5;
			this._btNewFolder.Text = "&New Folder";
			this._btNewFolder.Click += new System.EventHandler(this._btNewFolder_Click);
			// 
			// label4
			// 
			this.label4.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label4.ImageIndex = 0;
			this.label4.ImageList = this._imageList;
			this.label4.Location = new System.Drawing.Point(8, 16);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(304, 32);
			this.label4.TabIndex = 8;
			this.label4.Text = "{0} will add this page to your Favorites list.";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// _imageList
			// 
			this._imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
			this._imageList.ImageSize = new System.Drawing.Size(36, 36);
			this._imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("_imageList.ImageStream")));
			this._imageList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// _cbXOpml
			// 
			this._cbXOpml.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this._cbXOpml.Location = new System.Drawing.Point(56, 112);
			this._cbXOpml.Name = "_cbXOpml";
			this._cbXOpml.Size = new System.Drawing.Size(256, 24);
			this._cbXOpml.TabIndex = 9;
			this._cbXOpml.Text = "Favorite item is a opml file, add reference";
			// 
			// FavoritesAddFavoriteDialog
			// 
			this.AcceptButton = this._pbOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this._pbCancel;
			this.ClientSize = new System.Drawing.Size(416, 302);
			this.Controls.Add(this._cbXOpml);
			this.Controls.Add(this.label4);
			this.Controls.Add(this._btNewFolder);
			this.Controls.Add(this.label3);
			this.Controls.Add(this._tvOutline);
			this.Controls.Add(this._pbCancel);
			this.Controls.Add(this._pbOK);
			this.Controls.Add(this._textUrl);
			this.Controls.Add(this._textDesc);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "FavoritesAddFavoriteDialog";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Edit favorite";
			this.ResumeLayout(false);

		}
		#endregion		

		#region IRssFeedDataAdaptorAddFavoriteView Members
		public void InitializeView(OpmlDocumentFavorites favorites)
		{
			_opmlDocument = favorites;
			//
			this._tvOutline.Populate(this._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