Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / MFC

Ramakrishna's Code Project Screen Saver

Rate me:
Please Sign up or sign in to vote.
4.29/5 (4 votes)
19 May 2002CPOL9 min read 197.4K   2.3K   31  
This is a screen saver written in C# and Managed C++ to display data from The Code Project web site
using System;
using CP.Apps.ScreenSaver.com.codeproject.www;

namespace CP.Apps.ScreenSaver.Data
{
	/// <summary>
	/// A class for updating messages
	/// </summary>
	public abstract class MessageUpdate : IPresentationDataUpdater
	{
		protected LatestBrief webService;
		
		protected abstract MessageBrief[] Messages
		{
			get;
		}

		protected abstract int UpdatePeriod
		{
			get;
		}
		
		#region Implementation of IPresentationDataUpdater
		public bool UpdatePresentationData(CP.Apps.ScreenSaver.Data.PresentationData data)
		{
			try
			{
				webService = new LatestBrief();

				MessageBrief[] messages = this.Messages;
				
				PresentationItem[] items = new PresentationItem[messages.Length];
				data.UpdateType = this.GetType().FullName;
					
				for(int i = 0; i < messages.Length; i++)
				{
					PresentationItem item = new PresentationItem();
					item.Author = Util.StripHtml(messages[i].Author);
					item.Text = String.Format("{0} ({1})", Util.StripHtml(messages[i].Subject), messages[i].MsgsInThread);

					items[i] = item;
				}
				
				data.Items = items;

				//Update the update interval
				data.UpdateInterval = this.UpdatePeriod;	
			}
			finally
			{
				if (webService != null)
				{
					webService.Dispose();
					webService = null;
				}
			}

			return true;
		}
	
		#endregion
	}
	
	public class LoungeUpdate : MessageUpdate
	{
		protected override CP.Apps.ScreenSaver.com.codeproject.www.MessageBrief[] Messages
		{
			get
			{
				return webService.GetLatestLoungeBrief(webService.GetMaxLoungeListLength());
			}
		}

		protected override int UpdatePeriod
		{
			get
			{
				return webService.GetLoungeLatestUpdatePeriod();
			}
		}
	}

	public class CommentsUpdate : MessageUpdate
	{
		protected override CP.Apps.ScreenSaver.com.codeproject.www.MessageBrief[] Messages
		{
			get
			{
				return webService.GetLatestCommentsBrief(webService.GetMaxCommentListLength());
			}
		}

		protected override int UpdatePeriod
		{
			get
			{
				return webService.GetCommentLatestUpdatePeriod();
			}
		}
	}
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions