One of the new features in Power Pack 3 is a dashboard-style plug-in for Windows Media Center that gives you a snapshot of the Home Server’s status on your TV. Now, I don’t use Media Center (long live Popcorn Hour), but I do think that a dashboard status view is pretty cool.

The question becomes, then, how do we co-opt the Media Center plug-in for our own nefarious uses?


Data Acquisition

The Media Center plug-in reads from an XML file published through the Windows Home Server “system” web site (the one that runs on port 55000, that you can grab the Connector installer from). Take a look at http://yourserver:55000/health/health.xml (the actual file lives in C:\Inetpub\Intranet\health\health.xml).

You’ll see something like this:

image

There is some tasty information in there, including the IP address of each client machine currently connected to the server, all sorts of storage counters, and even your system’s uptime.


Schema Generation

We need to read this file, of course, and the easiest way to do that is to deserialize the XML into a usable .NET class. Bring on xsd.exe.

  1. Download health.xml and save it somewhere
  2. Start up your Visual Studio command prompt
  3. Run xsd health.xml to generate a health.xsd file
  4. Run xsd health.xsd /classes to generate a health.cs file (you can specify /language:vb if you’re a Visual Basic person)
  5. Import health.cs into your Visual Studio project

Helpfully, xsd has sort of mangled our new class a bit. Open health.cs and you’ll see a bunch of private fields.

public partial class HomeServerHealth {
    
    private HomeServerHealthStorageStorageInfo[][] storageField;
    private HomeServerHealthSharesShareInfo[][] sharesField;
    private HomeServerHealthBackupComputerInfo[][] backupField;
	...

We need to fix those arrays so the XML deserializer won’t throw its toys out of the cot. Do a find and replace across the whole file, replacing “[][]” with “[]”, so we get this:

public partial class HomeServerHealth {
    
    private HomeServerHealthStorageStorageInfo[] storageField;
    private HomeServerHealthSharesShareInfo[] sharesField;
    private HomeServerHealthBackupComputerInfo[] backupField;
	...

Much better.


Deserialization

I’ve covered XML serialization before. This is just more of the same, except we’re downloading a file from the server rather than opening one from disk.

I created a new WinForms project, and dropped a Button and DataGridView control onto the Form. This gives me a quick and dirty way to preview the data. The Button’s Click event looks like this:

private void button1_Click(object sender, EventArgs e)
{
    WebClient downloader = new WebClient();

    using (Stream xmlStream = downloader.OpenRead(@"http://yourserver:55000/health/health.xml"))
    {
        XmlSerializer serializer = new XmlSerializer(typeof(HomeServerHealth));
        HomeServerHealth health = (HomeServerHealth)serializer.Deserialize(xmlStream);

        dataGridView1.DataSource = health.Disks;
    }
}

You can see I’m binding the Disks array to the DataGridView. Running the project and clicking the button downloads the current health.xml and displays the contents of the Disks array.

image

Binding to Shares instead of Disks shows this:

image


Usage

The health.xml file gets updated quite often (once per minute, from what I can tell), so you can get up-to-date status just by polling the URL. The LastUpdated property also contains the exact time the file was updated by Windows Home Server.

There are a bunch of arrays you can loop through to gather interesting statistics:

  • Backup (client computer information, including number of days since last backup and IP address)
  • Disks
  • Hardware (manufacturer of the server, WHS version and uptime)
  • MediaCounts (the number of media files in each media Shared Folder, and how many more you can fit)
  • Notifications (the current Notification queue, including Notifications normally hidden from the WHS Console)
  • Shares (including duplication status)
  • Storage (aggregate storage usage for some high-level categories, the same as the WHS Console pie chart)

I’m very interested to see who runs with this new functionality. Given that the web site isn’t published (port 55000 is only accessible inside the network by default), you’d need to build another ASP.NET app to make this data externally accessible. But then you could make a neat mobile phone version (or whatever) to view the data.

I think this is a great direction for the WHS SDK team to go; this is the first time we have a way for applications to get status information from WHS without having to reference specific Home Server assemblies, making the data a lot more portable.

posted on Saturday, November 28, 2009 6:22 PM | Filed Under [ Windows Home Server Development ]

Comments

Gravatar
# re: Health.xml in Power Pack 3 (JammerX19 @ 11/29/2009 4:04 AM)

Great stuff. Thanks for posting it. However, when I follow your steps and import the Health.cs into VS 2008, the Intellisense won't pick up the HomeServerHealth reference and it won't compile. Any ideas?
 
Gravatar
# re: Health.xml in Power Pack 3 (JammerX19 @ 11/29/2009 4:07 AM)

Oops! Never mind. Did mine as a web app and forgot about the App_Code folder. :)
 
Gravatar
# re: Health.xml in Power Pack 3 (Sam Wood @ 11/29/2009 9:02 AM)

Sweet :) What are you building, Jammer?
 
Gravatar
# re: Health.xml in Power Pack 3 (JammerX19 @ 11/30/2009 4:00 AM)

I made a web page to display the pertinent parts of that XML. I have some questions about WHS dev in general. Would you mind if I emailed you directly with a couple?
 
Gravatar
# re: Health.xml in Power Pack 3 (Sam Wood @ 11/30/2009 6:47 AM)

Happy to answer anyquestions. Easiest way to get in touch is to use the Contact form (http://tentaclesoftware.com/blog/contact.aspx).

Post Comment

Title *
Name *
Email
Url
Comment *  
Remember me
Please add 2 and 2 and type the answer here:

Search

Site Sections

Recent Posts

Archives

Post Categories

WHS Add-In Tutorial

WHS Blogs

WHS Development