Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / Visual Basic

RSS Feed Aggregator and Blogging Smart Client

Rate me:
Please Sign up or sign in to vote.
4.91/5 (85 votes)
16 Aug 2005CPOL52 min read 1.1M   2.4K   397  
RSS Feed aggregator and blogging Smart Client which uses Enterprise Library, Updater Application Block, lots of XML hacks and desktop tricks. A comprehensive guide to real life hurdles of Smart Client development.
// Copyright � 2005 by Omar Al Zabir. All rights are reserved.
// 
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
// 
// website http://www.oazabir.com, email OmarAlZabir@gmail.com, msn oazabir@hotmail.com

using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Logging;
namespace RSSFeeder
{
	using RSSCommon;
	using RSSCommon.Helper;
	using Helpers;

	/// <summary>
	/// Summary description for Newspaper.
	/// </summary>
	public class Newspaper : System.Windows.Forms.Form
	{
		#region designer
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox channelDropDown;
		private System.Windows.Forms.Label dateLabel;
		private System.Windows.Forms.LinkLabel markAsReadLink;
		private System.Windows.Forms.LinkLabel manageFeedsLink;
		private AxSHDocVw.AxWebBrowser browserControl;
		private System.Windows.Forms.LinkLabel linkLabel1;
		private System.Windows.Forms.StatusBar statusBar;
		private System.Windows.Forms.Panel pnlMove;
		private System.Windows.Forms.NumericUpDown itemCountUpDown;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.LinkLabel minimizeLink;
		private System.Windows.Forms.LinkLabel maximizeLink;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

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

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

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

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Newspaper));
			this.label1 = new System.Windows.Forms.Label();
			this.channelDropDown = new System.Windows.Forms.ComboBox();
			this.dateLabel = new System.Windows.Forms.Label();
			this.pnlMove = new System.Windows.Forms.Panel();
			this.maximizeLink = new System.Windows.Forms.LinkLabel();
			this.minimizeLink = new System.Windows.Forms.LinkLabel();
			this.label2 = new System.Windows.Forms.Label();
			this.linkLabel1 = new System.Windows.Forms.LinkLabel();
			this.manageFeedsLink = new System.Windows.Forms.LinkLabel();
			this.markAsReadLink = new System.Windows.Forms.LinkLabel();
			this.itemCountUpDown = new System.Windows.Forms.NumericUpDown();
			this.browserControl = new AxSHDocVw.AxWebBrowser();
			this.statusBar = new System.Windows.Forms.StatusBar();
			this.pnlMove.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.itemCountUpDown)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.browserControl)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Font = new System.Drawing.Font("Trebuchet MS", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.ForeColor = System.Drawing.Color.White;
			this.label1.Location = new System.Drawing.Point(2, 10);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(239, 31);
			this.label1.TabIndex = 0;
			this.label1.Text = "The Daily Blogpaper";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.label1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnlMove_MouseMove);
			this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlMove_MouseDown);
			// 
			// channelDropDown
			// 
			this.channelDropDown.Cursor = System.Windows.Forms.Cursors.Default;
			this.channelDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.channelDropDown.Location = new System.Drawing.Point(555, 27);
			this.channelDropDown.Name = "channelDropDown";
			this.channelDropDown.Size = new System.Drawing.Size(224, 21);
			this.channelDropDown.TabIndex = 2;
			this.channelDropDown.SelectedIndexChanged += new System.EventHandler(this.channelDropDown_SelectedIndexChanged);
			// 
			// dateLabel
			// 
			this.dateLabel.AutoSize = true;
			this.dateLabel.BackColor = System.Drawing.Color.Transparent;
			this.dateLabel.ForeColor = System.Drawing.Color.White;
			this.dateLabel.Location = new System.Drawing.Point(9, 45);
			this.dateLabel.Name = "dateLabel";
			this.dateLabel.Size = new System.Drawing.Size(92, 17);
			this.dateLabel.TabIndex = 4;
			this.dateLabel.Text = "Saturday, May 21";
			this.dateLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.dateLabel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnlMove_MouseMove);
			this.dateLabel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlMove_MouseDown);
			// 
			// pnlMove
			// 
			this.pnlMove.BackColor = System.Drawing.Color.DimGray;
			this.pnlMove.Controls.Add(this.maximizeLink);
			this.pnlMove.Controls.Add(this.minimizeLink);
			this.pnlMove.Controls.Add(this.label2);
			this.pnlMove.Controls.Add(this.linkLabel1);
			this.pnlMove.Controls.Add(this.manageFeedsLink);
			this.pnlMove.Controls.Add(this.markAsReadLink);
			this.pnlMove.Controls.Add(this.label1);
			this.pnlMove.Controls.Add(this.dateLabel);
			this.pnlMove.Controls.Add(this.channelDropDown);
			this.pnlMove.Controls.Add(this.itemCountUpDown);
			this.pnlMove.Cursor = System.Windows.Forms.Cursors.SizeAll;
			this.pnlMove.Dock = System.Windows.Forms.DockStyle.Top;
			this.pnlMove.Location = new System.Drawing.Point(0, 0);
			this.pnlMove.Name = "pnlMove";
			this.pnlMove.Size = new System.Drawing.Size(792, 80);
			this.pnlMove.TabIndex = 10;
			this.pnlMove.DoubleClick += new System.EventHandler(this.pnlMove_DoubleClick);
			this.pnlMove.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnlMove_MouseMove);
			this.pnlMove.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlMove_MouseDown);
			// 
			// maximizeLink
			// 
			this.maximizeLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.maximizeLink.AutoSize = true;
			this.maximizeLink.Cursor = System.Windows.Forms.Cursors.Hand;
			this.maximizeLink.Font = new System.Drawing.Font("Wingdings", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
			this.maximizeLink.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
			this.maximizeLink.LinkColor = System.Drawing.Color.Snow;
			this.maximizeLink.Location = new System.Drawing.Point(758, 5);
			this.maximizeLink.Name = "maximizeLink";
			this.maximizeLink.Size = new System.Drawing.Size(14, 16);
			this.maximizeLink.TabIndex = 15;
			this.maximizeLink.TabStop = true;
			this.maximizeLink.Text = "o";
			this.maximizeLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.maximizeLink_LinkClicked);
			// 
			// minimizeLink
			// 
			this.minimizeLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.minimizeLink.AutoSize = true;
			this.minimizeLink.Cursor = System.Windows.Forms.Cursors.Hand;
			this.minimizeLink.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.minimizeLink.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
			this.minimizeLink.LinkColor = System.Drawing.Color.Snow;
			this.minimizeLink.Location = new System.Drawing.Point(738, 4);
			this.minimizeLink.Name = "minimizeLink";
			this.minimizeLink.Size = new System.Drawing.Size(11, 17);
			this.minimizeLink.TabIndex = 14;
			this.minimizeLink.TabStop = true;
			this.minimizeLink.Text = "_";
			this.minimizeLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.minimizeLink_LinkClicked);
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.Cursor = System.Windows.Forms.Cursors.Default;
			this.label2.ForeColor = System.Drawing.Color.White;
			this.label2.Location = new System.Drawing.Point(410, 30);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(99, 17);
			this.label2.TabIndex = 13;
			this.label2.Text = "Items per channel:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// linkLabel1
			// 
			this.linkLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.linkLabel1.AutoSize = true;
			this.linkLabel1.Cursor = System.Windows.Forms.Cursors.Hand;
			this.linkLabel1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
			this.linkLabel1.LinkColor = System.Drawing.Color.Snow;
			this.linkLabel1.Location = new System.Drawing.Point(778, 4);
			this.linkLabel1.Name = "linkLabel1";
			this.linkLabel1.Size = new System.Drawing.Size(12, 17);
			this.linkLabel1.TabIndex = 7;
			this.linkLabel1.TabStop = true;
			this.linkLabel1.Text = "X";
			this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
			// 
			// manageFeedsLink
			// 
			this.manageFeedsLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.manageFeedsLink.AutoSize = true;
			this.manageFeedsLink.BackColor = System.Drawing.Color.Transparent;
			this.manageFeedsLink.Cursor = System.Windows.Forms.Cursors.Default;
			this.manageFeedsLink.ForeColor = System.Drawing.Color.White;
			this.manageFeedsLink.LinkColor = System.Drawing.Color.Snow;
			this.manageFeedsLink.Location = new System.Drawing.Point(560, 56);
			this.manageFeedsLink.Name = "manageFeedsLink";
			this.manageFeedsLink.Size = new System.Drawing.Size(76, 17);
			this.manageFeedsLink.TabIndex = 5;
			this.manageFeedsLink.TabStop = true;
			this.manageFeedsLink.Text = "Manage Feeds";
			this.manageFeedsLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.manageFeedsLink_LinkClicked);
			// 
			// markAsReadLink
			// 
			this.markAsReadLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.markAsReadLink.AutoSize = true;
			this.markAsReadLink.BackColor = System.Drawing.Color.Transparent;
			this.markAsReadLink.Cursor = System.Windows.Forms.Cursors.Default;
			this.markAsReadLink.ForeColor = System.Drawing.Color.White;
			this.markAsReadLink.LinkColor = System.Drawing.Color.Snow;
			this.markAsReadLink.Location = new System.Drawing.Point(648, 56);
			this.markAsReadLink.Name = "markAsReadLink";
			this.markAsReadLink.Size = new System.Drawing.Size(131, 17);
			this.markAsReadLink.TabIndex = 6;
			this.markAsReadLink.TabStop = true;
			this.markAsReadLink.Text = "Mark as read and more...";
			this.markAsReadLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.markAsReadLink_LinkClicked);
			// 
			// itemCountUpDown
			// 
			this.itemCountUpDown.Cursor = System.Windows.Forms.Cursors.Default;
			this.itemCountUpDown.Location = new System.Drawing.Point(512, 28);
			this.itemCountUpDown.Name = "itemCountUpDown";
			this.itemCountUpDown.Size = new System.Drawing.Size(35, 21);
			this.itemCountUpDown.TabIndex = 12;
			this.itemCountUpDown.Value = new System.Decimal(new int[] {
																		  4,
																		  0,
																		  0,
																		  0});
			this.itemCountUpDown.ValueChanged += new System.EventHandler(this.itemCountUpDown_ValueChanged);
			// 
			// browserControl
			// 
			this.browserControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.browserControl.Enabled = true;
			this.browserControl.Location = new System.Drawing.Point(-2, 78);
			this.browserControl.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("browserControl.OcxState")));
			this.browserControl.Size = new System.Drawing.Size(792, 432);
			this.browserControl.TabIndex = 0;
			this.browserControl.StatusTextChange += new AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.browserControl_StatusTextChange);
			this.browserControl.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(this.browserControl_NewWindow3);
			this.browserControl.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.browserControl_NavigateComplete2);
			this.browserControl.BeforeNavigate2 += new AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.browserControl_BeforeNavigate2);
			// 
			// statusBar
			// 
			this.statusBar.Location = new System.Drawing.Point(0, 570);
			this.statusBar.Name = "statusBar";
			this.statusBar.Size = new System.Drawing.Size(792, 22);
			this.statusBar.TabIndex = 11;
			this.statusBar.Text = "Ready";
			// 
			// Newspaper
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.BackColor = System.Drawing.Color.White;
			this.ClientSize = new System.Drawing.Size(792, 592);
			this.ControlBox = false;
			this.Controls.Add(this.statusBar);
			this.Controls.Add(this.pnlMove);
			this.Controls.Add(this.browserControl);
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "Newspaper";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Resize += new System.EventHandler(this.Newspaper_Resize);
			this.Load += new System.EventHandler(this.Newspaper_Load);
			this.Deactivate += new System.EventHandler(this.Newspaper_Deactivate);
			this.pnlMove.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.itemCountUpDown)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.browserControl)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#endregion
		
		#region Private variables

		/// <summary>
		/// Sets the default channel that needs to be automatically selected and shown when
		/// this form loads.
		/// </summary>
		private int _ChannelId = 0;
		
		/// <summary>
		/// Holds reference to the RSS Items currently being shown on newspaper. 
		/// It is used later on to mark these feeds as read.
		/// </summary>
		private IList _CurrentRSSItems = new ArrayList();
		
		/// <summary>
		/// Holds reference to the channels loaded to show the newspaper. It is
		/// used later on to mark the channels as read
		/// </summary>
		private IList _CurrentChannels = new ArrayList();

		#endregion
		
		#region Private Methods

		private void ReadMore()
		{
		}

		private void LoadChannels()
		{
			Channel dummy = new Channel();
			dummy.Title = "All Channels";
			channelDropDown.Items.Add(dummy);

			// 1. Get all channels
			IList channels = DatabaseHelper.GetChannels();

			// 2. Add in drop down
			foreach( Channel channel in channels )
			{
				channelDropDown.Items.Add( channel );
			}

			channelDropDown.SelectedIndex = 0;

			if( this._ChannelId > 0 )
				this.SelectChannelById( this._ChannelId );

			#region Log
			Logger.Write("Newspaper loaded");
			#endregion
		}

		/// <summary>
		/// Preselect the channel in the channel combo box
		/// </summary>
		/// <param name="channelId"></param>
		private void SelectChannelById( int channelId )
		{
			foreach( Channel channel in channelDropDown.Items )
			{
				if( channel.Id == channelId )
				{
					channelDropDown.SelectedItem = channel;
					break;
				}
			}
		}

		/// <summary>
		/// Generate the newspaper for the selected channel(s)
		/// </summary>
		private void ShowNewspaper()
		{
			// Clear RSS items cache
			this._CurrentRSSItems.Clear();
			// Clear channel cache
			this._CurrentChannels.Clear();
				
			// Create a temporary news paper page
			string fileName = Path.Combine( ApplicationSettings.ApplicationDataPath, "newspaper.html" );
			FileStream file = new FileStream( fileName, FileMode.Create );

			#region Log
			Logger.Write("Generating newspaper: " + fileName );
			#endregion

			// Create a string buffer to hold on to all the channel XMLs
			MemoryStream stream = new MemoryStream( 100 * 1024 );
			
			using( StreamWriter streamWriter = new StreamWriter( stream, System.Text.Encoding.ASCII ) )
			{
				XmlTextWriter writer = new XmlTextWriter( streamWriter );
				writer.Namespaces = false;
				writer.Formatting = Formatting.Indented;

				//writer.WriteRaw( "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\">" );
				writer.WriteStartElement("rss");
				writer.WriteAttributeString("version", "2.0");
				writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
				writer.WriteAttributeString("xmlns:trackback", "http://madskills.com/public/xml/rss/module/trackback/");
				writer.WriteAttributeString("xmlns:wfw", "http://wellformedweb.org/CommentAPI/");
				writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

				if( 0 == channelDropDown.SelectedIndex )
				{
					// 1. Get all channels
					IList channels = DatabaseHelper.GetChannels();
				
					// 2. Prepare XML for each channel
					foreach( Channel channel in channels )
					{
						IList rssItems = this.PrepareChannelXML( channel, writer, streamWriter );					
						this.AddRSSItemsInCache( channel, rssItems );
					}	
				}
				else
				{
					// Get the single channel specifically seleced
					Channel channel = channelDropDown.SelectedItem as Channel;
				
					// Prepare XML for the channel
					IList rssItems = this.PrepareChannelXML( channel, writer, streamWriter );

					// Store the feeds in cache
					this.AddRSSItemsInCache( channel, rssItems );
				
				}

				writer.WriteEndElement();

				// Generate the newspaper file
				writer.Flush();
				writer.Close();
			}

			String xml = System.Text.Encoding.ASCII.GetString( stream.ToArray() );

			//XMLHelper.GenerateXMLForChannel( Configuration.Instance.NewspaperXSL, xml, file );
			XMLHelper.TransformXml( Configuration.Instance.NewspaperXSL, xml, file );


			file.Close();

			#region Log
			Logger.Write("Newspaper generated, showing in browser...");
			#endregion

			// Show the file in browser control
			object url = fileName as object;
			object nil = System.Reflection.Missing.Value;
			this.browserControl.Navigate2( ref url, ref nil, ref nil, ref nil, ref nil );
			this.browserControl.Focus();
		}

		/// <summary>
		/// Store the specified items in cache
		/// </summary>
		/// <param name="channel"></param>
		/// <param name="rssItems"></param>
		private void AddRSSItemsInCache( Channel channel, IList rssItems )
		{
			// Store the items in a cache
			foreach( RssFeed feed in rssItems )
				this._CurrentRSSItems.Add( feed );
		}

		/// <summary>
		/// Marks all displayed RSS Feeds as read and refreshes the unread count of the channels
		/// </summary>
		private void MarkFeedsAsRead()
		{
			markAsReadLink.Tag = markAsReadLink.Text;
			markAsReadLink.Text = "Marking...";
			markAsReadLink.Refresh();

			#region Log
			Logger.Write("Mark items as read");
			#endregion

			// 1. Mark all shown feeds as read
			foreach( RssFeed feed in this._CurrentRSSItems )
			{
				DatabaseHelper.MarkAsRead( true, feed.Guid, feed.ChannelID, false );
			}

			// 2. Update the unread count of the channels
			foreach( Channel channel in this._CurrentChannels )
			{
				DatabaseHelper.RefreshChannelCounts( channel.Id );
			}

			// 3. Show reloading progress while loading new feeds
			markAsReadLink.Text = "Reloading...";
			markAsReadLink.Refresh();

			// 4. Reload further feeds
			this.ShowNewspaper();

			markAsReadLink.Text = (string)markAsReadLink.Tag;
		}

		private IList PrepareChannelXML( Channel channel, XmlTextWriter writer, StreamWriter streamWriter )
		{
			// Write the channel header
			writer.WriteStartElement("channel");
			writer.WriteElementString( "title", channel.Title );
			writer.WriteElementString( "link", channel.FeedURL.ToString() );
			
			// Store all rss items in the buffer
			IList items = DatabaseHelper.GetTopRssItems( channel.Id, (int)itemCountUpDown.Value, false );
			
			foreach( RssFeed feed in items )
			{
				streamWriter.WriteLine( feed.XML );
			}
			
			writer.WriteEndElement();

			return items;
		}

		#endregion

		#region Public Methods

		public void ShowChannel( int id )
		{
			this.SelectChannelById( id );
		}
		#endregion

		#region Control Events

		
		private void minimizeLink_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			this.WindowState = FormWindowState.Minimized;		
		}

		
		private void itemCountUpDown_ValueChanged(object sender, System.EventArgs e)
		{
			this.ShowNewspaper();
		}

		
		private void Newspaper_Deactivate(object sender, System.EventArgs e)
		{
			MemoryHelper.ReduceMemory();
		}

		private void readMoreLink_Click(object sender, System.EventArgs e)
		{
			this.ReadMore();
		}

		vbAccelerator.Components.Controls.FlatControl flatComboBox = new vbAccelerator.Components.Controls.FlatControl();

		private void Newspaper_Load(object sender, System.EventArgs e)
		{
			this.LoadChannels();
			flatComboBox.Attach( this.channelDropDown );
			dateLabel.Text = DateTime.Today.ToLongDateString();

			Newspaper_Resize( sender, e );
		}

		private void channelDropDown_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.ShowNewspaper();
		}

		private void manageFeedsLink_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			EntryPoint.ShowMainForm( (channelDropDown.SelectedItem as Channel).Id );

			this.Close();
		}

		private void markAsReadLink_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			this.MarkFeedsAsRead();
		}

		private void browserControl_StatusTextChange(object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
		{
			statusBar.Text = e.text;
		}

		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			this.Close();
		}

		private void Newspaper_Resize(object sender, System.EventArgs e)
		{
			browserControl.Height = this.ClientRectangle.Height - browserControl.Top - 2;
		}

		private void browserControl_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
		{
			browserControl.Focus();
		}

		private void browserControl_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
		{
			string url = e.uRL as string;
			if( null == url ) return;

			if( BrowserHelper.IsURLFile( url ) || url == "about:blank" ) 
			{				
				return;
			}
			else
			{
				e.cancel = true;
				// User has dragged an URL to this browser, perform RSS discovery
				//this.AddNewChannel( e.uRL as string );
				BrowserHelper.BrowseURL( url );
			}
		}

		private void browserControl_NewWindow3(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)
		{
			e.cancel = BrowserHelper.BrowseURL( e.bstrUrl );
		}

		
		private void pnlMove_DoubleClick(object sender, System.EventArgs e)
		{
			if( base.WindowState == FormWindowState.Normal )
				base.WindowState = FormWindowState.Maximized;
			else
				base.WindowState = FormWindowState.Normal;
		}

		private void maximizeLink_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			base.WindowState = FormWindowState.Maximized;
		}
		
		#endregion

		#region Move Window

		private Point offset;
		private void pnlMove_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			offset = new Point(-e.X - pnlMove.Left, 
				-e.Y - pnlMove.Top);
		}

		private void pnlMove_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if( e.Button==MouseButtons.Left)
			{
				Point mousePos = Control.MousePosition;
				mousePos.Offset(offset.X, offset.Y);
				base.Location = mousePos;
			}

		}
		#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 Code Project Open License (CPOL)


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions