Click here to Skip to main content
15,867,453 members
Articles / Web Development / ASP.NET
Article

A Code Project Article Information Library (Part 1)

Rate me:
Please Sign up or sign in to vote.
3.05/5 (14 votes)
27 Apr 2008CPOL5 min read 50.8K   442   21   29
This library provides a framework for using Code Project article information in applications, and provides a utility for monitoring articles

codeprojectarticle3.jpg

codeprojectarticle2.jpg

Introduction

This article presents the CodeProject.dll project which may be used to extract information from The Code Project. In the first of a short series of articles, ArticlesSummary is presented which allows extraction of article information by member number. The following information may be extracted;

  • Title
  • Description
  • Web link
  • Last update date
  • Number of page views
  • Rating
  • Number of votes
  • Popularity

By extension it is then possible also to calculate the following information (and others);

  • Number of articles per user
  • Average rating / popularity

Finally an application for monitoring user article changes is presented.

PLEASE DO NOT ABUSE THIS LIBRARY. This library allows automatic updates of information polled from the Code Project website, please do not set the update interval too low or you will effective be performing a denial of service attack. If this happens too often this article will be removed! You have been warned.

Background

This article is based upon the http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=### page, where ### is the member id. Contained within the source of the page is the following;

<span id="ctl00_MC_AR_ctl03_MAS">
   <b><a id="ctl00_MC_AR_ctl03_AT" href="http://www.codeproject.com/KB/WPF/roundbutton.aspx">A
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
 Microsoft Office Style WPF Application Button</a></b>

        

        
        
        
        
   <div id="ctl00_MC_AR_ctl03_SbD" class="subdue SmallText">
      Last Updated: 22 Mar 2008  
      Page Views: 8,278  
      Rating: 3.31 / 5  
      Votes: 6  
      Popularity: 2.57
      </div>
   <div style="margin-top:3;font-size:8pt;">An article presenting ApplicationButton used in 
###LINE BREAK INSERTED TO REDUCE ARTICLE WIDTH###
creating round buttons as per Microsoft Office Style application buttons</div>
</span>

To summarise;

C#
<span id="ctl00_MC_AR_ctl03_MAS">
   <b><a id="ctl00_MC_AR_ctl03_AT" href="###relative web address###">###article title###</a></b>

        

        
        
        
        
   <div id="ctl00_MC_AR_ctl03_SbD" class="subdue SmallText">
      Last Updated: ###date###  
      Page Views: ###page views###  
      Rating: ###rating### / 5  
      Votes: ###number of votes###  
      Popularity: ###popularity###
      </div>
   <div style="margin-top:3;font-size:8pt;">###article description###</div>
</span>

The key elements for parsing are ctl00_MC_AR_ctl03_MAS, ctl00_MC_AR_ctl03_AT and ctl00_MC_AR_ctl03_SbD; where 103 can be any number (usually 100 onwards).

Using the code

The library is based around two classes Article and ArticleSummary, as presented herein.

ArticleSummary performs the actual data requests and has the following events, methods, and properties;

  • event ArticleAddedEventDelegate ArticleAdded* - Fires when a new article is detected.
  • ArticlesSummary(String userID) - Constructor accepts the member number of the user to monitor.
  • String UserID {get;} - Returns the user being monitored.
  • TimeSpan UpdateInterval {get;set;} - Used when AutoUpdate is true, the time between data retrieval.
  • bool AutoUpdate {get;set;} - Enables or disables automatic updates (essentially calls update() at UpdateInterval intervals.
  • List<Article> Articles {get;} - Returns a list of articles for the specified member name (or empty list if update has not yet been called).
  • void update() and void update(WebProxy proxy) - Updates the articles list; all event firing generation happens within the timescale of this function.

Article encapsulates all information about an article, and has the following properties and events;

  • event TitleChangedEventDelegate TitleChanged* - Fired when the title of the article changes (typically only fired when a new article is added).
  • event DescriptionChangedEventDelegate DescriptionChanged* - Fired when the article description changes.
  • event LinkChangedEventDelegate LinkChanged* - Fired when the web address of the article changes.
  • event LastUpdatedChangedEventDelegate LastUpdatedChanged* - Fires when the article is updates.
  • event PageViewsChangedEventDelegate PageViewsChanged* - Fires when the number of page views changes.
  • event RatingChangedEventDelegate RatingChanged* - Fires when the page rating changes.
  • event VotesChangedEventDelegate VotesChanged* - Fires when the number of votes changes.
  • event PopularityChangedEventDelegate PopularityChanged* - Fires when the popularity of the article changes.
  • String Title {get;} - Returns the article title.
  • String Description {get;} - Returns a description of the article.
  • String Link {get;} - Returns the relative web address of the article.
  • DateTime LastUpdated {get;} - Returns the date of the last update.
  • int PageViews {get;} - Returns the number of article views.
  • double Rating {get;} - Returns the article rating (out of 5).
  • int Votes {get;} - Returns the number of votes for the article.
  • double Popularity {get;} - Returns the popularity of the article.
  • string ToString() - Returns a debug string.

* Fired in response to update being called upon a ArticleSummary.

About the Article Monitor

The article monitor is a utility that can be left running and displays a popup message indicating a new article, number of votes changed, popularity changed, and rating changed. It is a very basic utility and is primarily released as a demonstration of the CodeProject.dll library.

The monitor comprises of several parts, the top row allows setting of the member number. The centre section displays information are the known articles for the user (once connect has been clicked); the information is updated once a minute. The bottom row allows disabling of the popup alerts and a manual update button.

All the article data is stored in a DataTable which is displayed on a WPF control (not described in this article). The data view is updated via the updateTable() method.

When the connect button is clicked a new ArticlesSummary object is created and the ArticleAdded event is attached. Finally the AutoUpdate property is set before a call to update() is made (forces instant initial synchronisation).

C#
summary = new ArticlesSummary(memberIDTextBox.Text);
summary.ArticleAdded += new ArticlesSummary.ArticleAddedEventDelegate(summary_ArticleAdded);
summary.AutoUpdate = true;
summary.update();

The ArticleAdded event is handled, and the sent article has the various event handlers attached. A new DataRow is added to the DataTable which corresponds to the article added. Finally the table view is updated.

C#
DataRow dr = dataTable.NewRow();
dataRows.Add(article, dr);
dataTable.Rows.Add(dr);

article.TitleChanged += new Article.TitleChangedEventDelegate(article_TitleChanged);
article.LastUpdatedChanged += new Article.LastUpdatedChangedEventDelegate(article_LastUpdatedChanged);
article.PageViewsChanged += new Article.PageViewsChangedEventDelegate(article_PageViewsChanged);
article.RatingChanged += new Article.RatingChangedEventDelegate(article_RatingChanged);
article.VotesChanged += new Article.VotesChangedEventDelegate(article_VotesChanged);
article.PopularityChanged += new Article.PopularityChangedEventDelegate(article_PopularityChanged);

dr["Title"] = article.Title;
dr["Last Updated"] = article.LastUpdated;
dr["Page Views"] = article.PageViews;
dr["Rating"] = article.Rating;
dr["Votes"] = article.Votes;
dr["Popularity"] = article.Popularity;

The article event handlers update the corresponding data row and specified attribute before updating the table. If the event is not fired during the initial update() call on the ArticleSummary then a popup is displayed showing the new information (assuming the popups are not disabled). For example, the VotesChange event handler is as follows;

C#
private void article_VotesChanged(object sender, int value)
   {
      this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, 
                                new RefreshDelegate(delegate()
      {
         dataRows[(Article)sender]["Votes"] = ((Article)sender).Votes;
         if (!initialSync)
         {
            updateTable();

            if ((bool)soundAlertCheckBox.IsChecked)
            {
               SimplePopup.ShowPopup(((Article)sender).Title 
                                            + " votes changed to " + value);
            }
      }
   }));
}

Note that the event handler forces processing onto the event dispatch thread as the events are fired from the thread calling ArticleSummary.update(), which in the case of auto updating is not the event dispatch thread.

History

Version 1.0.0.0 - Initial build.

Version 1.0.0.1 - Added User class (see part 2)

Useful Links

codeprojectarticle.aspx (Part 1, Articles)

codeprojectuser.aspx (Part 2, Users)

codeprojectkevinbacon.aspx (Part 3, Kevin Bacon)

Additional Licensing Notes

Please feel free to use this in your work, however please be aware that a modified The Code Project Open License (CPOL) is in use; basically it is the same as the standard license except that this code must not be used for commercial or not-for-profit commercial use without prior authorisation. Please see license.txt or license.pdf in the included source and demo files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Rail Research UK
United Kingdom United Kingdom
I originally studied for a masters in engineering of software engineering at The University of Birmingham during 2000-2004, of which I received a 2:1. I continued at Birmingham University working with Civil Engineering and Rail Research UK where I am currently in my final year of a 3 year PhD project developing a Computational Intelligent Approach to Railway Intervention Planning. Although my work has a significant focus on railway engineering and associated practices much of my work is with data mining (on SQL Server 2008) and computational intelligence (CI) techniques. My key areas of expertise in CI are clustering algorithms (including Rival Penalised Competitive Learning) and evolutionary algorithms.

Outside of my formal work I enjoy testing the latest technologies such as .NET 3.5 and the many frameworks of which it comprises (mainly WPF). I have several projects on the go including a .NET and DirectX port of Quake 3 and many utility libraries. I also maintain an extensive website coded in Cold Fusion which is regularly updated; more information is available about me there.

Comments and Discussions

 
GeneralHTML Parsing Pin
Scott Dorman14-Jul-08 5:42
professionalScott Dorman14-Jul-08 5:42 
GeneralVertigo Pin
Rama Krishna Vavilala9-May-08 5:16
Rama Krishna Vavilala9-May-08 5:16 
GeneralRe: Vertigo Pin
Derek Bartram9-May-08 8:04
Derek Bartram9-May-08 8:04 
GeneralRe: Vertigo Pin
Jaime Olivares14-Oct-08 22:53
Jaime Olivares14-Oct-08 22:53 
GeneralRe: Vertigo Pin
Derek Bartram15-Oct-08 1:12
Derek Bartram15-Oct-08 1:12 
GeneralRe: Vertigo Pin
Jaime Olivares15-Oct-08 2:55
Jaime Olivares15-Oct-08 2:55 
GeneralRe: Vertigo Pin
Derek Bartram15-Oct-08 3:44
Derek Bartram15-Oct-08 3:44 
QuestionWhat about a codeproject service web API Pin
Chris Richner28-Apr-08 19:23
Chris Richner28-Apr-08 19:23 
AnswerRe: What about a codeproject service web API Pin
Derek Bartram30-Apr-08 5:25
Derek Bartram30-Apr-08 5:25 
AnswerRe: What about a codeproject service web API (resend) Pin
Derek Bartram30-Apr-08 5:25
Derek Bartram30-Apr-08 5:25 
GeneralRe: What about a codeproject service web API (resend) Pin
Ravi Bhavnani1-May-08 7:55
professionalRavi Bhavnani1-May-08 7:55 
GeneralRe: What about a codeproject service web API (resend) Pin
Derek Bartram1-May-08 8:15
Derek Bartram1-May-08 8:15 
GeneralRe: What about a codeproject service web API (resend) Pin
Ravi Bhavnani1-May-08 9:04
professionalRavi Bhavnani1-May-08 9:04 
GeneralRe: What about a codeproject service web API (resend) Pin
Derek Bartram1-May-08 9:47
Derek Bartram1-May-08 9:47 
GeneralFormatting Pin
Not Active27-Apr-08 10:40
mentorNot Active27-Apr-08 10:40 
GeneralRe: Formatting Pin
Derek Bartram27-Apr-08 11:39
Derek Bartram27-Apr-08 11:39 
GeneralRe: Formatting Pin
Not Active27-Apr-08 12:21
mentorNot Active27-Apr-08 12:21 
GeneralRe: Formatting Pin
Derek Bartram27-Apr-08 12:40
Derek Bartram27-Apr-08 12:40 
GeneralRe: Formatting Pin
Not Active27-Apr-08 13:00
mentorNot Active27-Apr-08 13:00 
GeneralRe: Formatting Pin
Jeffrey Walton27-Apr-08 18:55
Jeffrey Walton27-Apr-08 18:55 
GeneralRe: Formatting Pin
Derek Bartram30-Apr-08 1:52
Derek Bartram30-Apr-08 1:52 
GeneralRe: Formatting Pin
Derek Bartram30-Apr-08 5:04
Derek Bartram30-Apr-08 5:04 
GeneralRe: Formatting Pin
Derek Bartram30-Apr-08 1:51
Derek Bartram30-Apr-08 1:51 
GeneralRe: Formatting Pin
Not Active30-Apr-08 2:14
mentorNot Active30-Apr-08 2:14 
GeneralRe: Formatting Pin
Derek Bartram30-Apr-08 5:04
Derek Bartram30-Apr-08 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.