Click here to Skip to main content
Click here to Skip to main content
Go to top

A Code Project Article Information Library (Part 1)

, 27 Apr 2008
Rate this:
Please Sign up or sign in to vote.
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;

<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).

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.

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;

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)

Share

About the Author

Derek Bartram
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 PinmvpScott Dorman14-Jul-08 5:42 
Interesting article. I've done some similar work extracting/parsing the recent comments data from a user profile. You might want to take a look at the HTML parser in this article[^]. It's a much easier way to deal with the page structure than reading it as text and doing string comparisons.
 
Scott Dorman
Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
 
[Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

GeneralVertigo PinmemberRama Krishna Vavilala9-May-08 5:16 
GeneralRe: Vertigo PinmemberDerek Bartram9-May-08 8:04 
GeneralRe: Vertigo PinmemberJaime Olivares14-Oct-08 22:53 
GeneralRe: Vertigo PinmemberDerek Bartram15-Oct-08 1:12 
GeneralRe: Vertigo PinmemberJaime Olivares15-Oct-08 2:55 
GeneralRe: Vertigo PinmemberDerek Bartram15-Oct-08 3:44 
QuestionWhat about a codeproject service web API PinmemberChris Richner28-Apr-08 19:23 
AnswerRe: What about a codeproject service web API PinmemberDerek Bartram30-Apr-08 5:25 
AnswerRe: What about a codeproject service web API (resend) PinmemberDerek Bartram30-Apr-08 5:25 
GeneralRe: What about a codeproject service web API (resend) PinmemberRavi Bhavnani1-May-08 7:55 
GeneralRe: What about a codeproject service web API (resend) PinmemberDerek Bartram1-May-08 8:15 
GeneralRe: What about a codeproject service web API (resend) PinmemberRavi Bhavnani1-May-08 9:04 
GeneralRe: What about a codeproject service web API (resend) PinmemberDerek Bartram1-May-08 9:47 
GeneralFormatting PinmemberMark Nischalke27-Apr-08 10:40 
GeneralRe: Formatting PinmemberDerek Bartram27-Apr-08 11:39 
GeneralRe: Formatting PinmemberMark Nischalke27-Apr-08 12:21 
GeneralRe: Formatting PinmemberDerek Bartram27-Apr-08 12:40 
GeneralRe: Formatting PinmemberMark Nischalke27-Apr-08 13:00 
GeneralRe: Formatting PinmvpJeffrey Walton27-Apr-08 18:55 
GeneralRe: Formatting PinmemberDerek Bartram30-Apr-08 1:52 
GeneralRe: Formatting PinmemberDerek Bartram30-Apr-08 5:04 
GeneralRe: Formatting PinmemberDerek Bartram30-Apr-08 1:51 
GeneralRe: Formatting PinmemberMark Nischalke30-Apr-08 2:14 
GeneralRe: Formatting PinmemberDerek Bartram30-Apr-08 5:04 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 27 Apr 2008
Article Copyright 2008 by Derek Bartram
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid