A Programmer's Dream

CodePlex & Updated Versions

Posted by Stephen Wrighton on 26 May 2010

CodePlex is Microsoft's Open-Source repository, basically, their gift to the Open Source .NET developers out there. As such, it has a number of useful and worthwhile features in its code base for said Open Source developers, things such as issue trackers and discussion functions.

It's good and I like it.

But there is one place where it is lacking, and that's the ability to have the programs "call home" to the project page and make sure that they are the latest version of the software.

Ideally, the way this would work, is that we would provide a key on the release page, and when a RESTFUL API was called, that key would be returned. Then a simple compare would do the job.

Sadly, that doesn't exist.

Even more sadly, I wanted my project to be able to do this. Basically, my goal is that after the application launches (provided the user wishes for updates to be checked), the application would call the eComic home page, and found out the key for the current 'recommended' release. If it was not the "recommended" release, then an icon would be displayed, and when pressed, launch the eComic home page in the browser, ready for downloads.

Luckily, I figured out a way around this.

Since the site provides an RSS feed detailing project releases, I have a viewpoint into the current release. Or at least, the last release that was edited. The other thing that the site provides is the ability to create "Hidden" releases. Basically, these are releases that you've not finished 100% and thus are not released to the public yet. An important thing to note regarding these hidden releases is that they do not show up in the RSS feed.

So, what I did was I created the following settings in my application:
With the Check for Updates setting, I will allow the user to turn on/off the ability to perform these checks. That's just a simple and nice setting that any application that performs these types of checks should implement.

The Check Update Url is basically a read-only setting, that is the RELEASES RSS feed from the eComic site.

Finally, the Current Version is a read-only setting, in which I placed the string identifier for this release.

After those settings were created, I went and generated a "Hidden" release, and got its Release Id from the query string.

I then plugged that Release Id into the Current Version setting.

Finally, I had a function which would perform a web request to the eComic RELEASE RSS feed. After grabbing the first item, I perform a simple compare on the associated link to see if the returned link held the Current Version value, and displayed my UPDATE icon accordingly.

Placing it into a Timer.Elapsed event kept if off my main thread (meaning that the update check would not impact usability) and made it a slight delay from the application launch as well. The final thing is that the whole kit-n-kaboodle is wrapped in a Try/Catch block as I don't want a failure to connect to the web server to bring down the whole application.




   1:   Private Sub _timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles _timer.Elapsed
   2:          Try
   3:              Dim request As HttpWebRequest = WebRequest.Create(My.Settings.UpdateUrl)
   4:              Dim response As HttpWebResponse = request.GetResponse
   5:              If response.StatusCode = HttpStatusCode.OK Then
   6:                  Dim xDoc As XDocument = XDocument.Load(response.GetResponseStream)

   7:   
   8:                  _currentVersionUrl = (From xe In xDoc.Descendants("item") _
   9:                                                   Select xe.Element("link").Value _
  10:                                                   ).Take(1).SingleOrDefault
  11:                  If Not String.IsNullOrEmpty(_currentVersionUrl) Then
  12:                      If Not _currentVersionUrl.Contains(My.Settings.CurrentRelease) Then
  13:                          Me.DisplayUpdate = True
  14:                      End If
  15:                  End If
  16:              End If
  17:   
  18:              ' Check to ensure the link is a VALID url 
  19:              If Me.DisplayUpdate Then
  20:                  Dim re2 As HttpWebRequest = WebRequest.Create(Me._currentVersionUrl)
  21:                  re2.AllowAutoRedirect = False
  22:                  re2.Method = "Head"
  23:                  re2.KeepAlive = False
  24:                  Dim res As HttpWebResponse = request.GetResponse
  25:                  If Not res.StatusCode = HttpStatusCode.OK Then Me.DisplayUpdate = False
  26:              End If ' Me.DisplayUpdate 
  27:   
  28:   
  29:          Catch ex As Exception
  30:              ' Do Nothing.  If this fails, then I'm not concerned, as I'll just continue happily with the current version 
  31:          End Try
  32:      End Sub

Tweet me @kidananubix if you like this post.

Tweet