Check TFS Online service status using C#

If you use TFS Online you may have experienced some unexpected downtime over the last few months.  Whilst the service is getting better and better all the time, downtime is still an issue.  I have written a little screen scraping tool based on the HTML Agility Pack that will scrape the service status page and report back the current status.

Add the following class to your project;

 

using HtmlAgilityPack;

/// <summary>
/// The TFS heartbeat helper.
/// </summary>
public static class TFSHeartbeatHelper
{
    #region Constants

<pre><code>/// &amp;lt;summary&amp;gt;
/// The service status url.
/// &amp;lt;/summary&amp;gt;
private const string ServiceStatusUrl = &amp;quot;http://www.visualstudio.com/en-us/support/support-overview-vs.aspx&amp;quot;;

#endregion

#region Public Methods and Operators

/// &amp;lt;summary&amp;gt;
/// Gets the TFS service status
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;returns&amp;gt;
/// The &amp;lt;see cref=&amp;quot;ServiceStatus&amp;quot;/&amp;gt;.
/// &amp;lt;/returns&amp;gt;
public static ServiceStatus GetStatus()
{
    HtmlDocument doc = new HtmlWeb().Load(ServiceStatusUrl);

    HtmlNode detailedImage = doc.DocumentNode.SelectSingleNode(&amp;quot;//div[@class='DetailedImage']&amp;quot;);
    HtmlNode supportImageNode = detailedImage.ChildNodes.FindFirst(&amp;quot;img&amp;quot;);

    if (supportImageNode.Id == &amp;quot;Support_STATUS_Check&amp;quot;)
    {
        return ServiceStatus.NoIssues;
    }

    if (supportImageNode.Id == &amp;quot;Support_STATUS_Exclamation_Y&amp;quot;)
    {
        return ServiceStatus.Issues;
    }

    return ServiceStatus.Undetermined;
}

#endregion
</code></pre>

}

/// &lt;summary&gt;
/// The service status.
/// &lt;/summary&gt;
public enum ServiceStatus
{
    /// &lt;summary&gt;
    /// No issues.
    /// &lt;/summary&gt;
    NoIssues,

<pre><code>/// &amp;lt;summary&amp;gt;
/// There are issues.
/// &amp;lt;/summary&amp;gt;
Issues,

/// &amp;lt;summary&amp;gt;
/// Unable to determine the status
/// &amp;lt;/summary&amp;gt;
Undetermined
</code></pre>

}

The usage for this code is as follows;

switch (TFSHeartbeatHelper.GetStatus())
{
    case ServiceStatus.NoIssues:
        ////Good news!
        break;
    case ServiceStatus.Issues:
        ////Bad news!
        break;
    case ServiceStatus.Undetermined:
        ////Erm..not sure :S
        break;
}

I hope you find this little helper useful. Please leave a comment below.

  • Anonymous

    Ooh screen scraping, I like and may have use for this JP, thanks 🙂

    • Thanks … I wrote this because I use TFS online at work and I was getting pretty tired of checking the TFS service status page every 5 minutes. What I will probably do is expand my program to read the service status blog where Microsoft provide more details about down time and display the information neatly on my desktop.

      As soon as I find a better way (web scraping is less than ideal) I’ll be sure to update this page ! 🙂 . Unless you yourself have a better way?