Mad Props!

Omniscience is just a Google-search away.

Login

You're reading Mabsterama, the weblog of Matt Hamilton. Enjoy your stay.

Learning Inversion of Control Containers with Kzu

Daniel Cazzulino (Kzu, of Moq fame) has started releasing a series of screencasts in which he is designing a new IoC (or DI) Container, which he calls Funq. You can read the reasons behind the series here on his blog.

If, like me, you want to learn more about IoC Containers, this is a hell of a place to start. What better way to learn about a technology then to watch a version of it being created from scratch?

The really interesting thing about Funq is that it’s being designed for the .NET Compact Framework, and Kzu intends to fork the project to release a desktop-framework version of it independently. Since one of my big projects here at work is for Windows Mobile, I’m watching Funq’s development with keen interest.

Start watching part 1 here on Viddler.com!

IE8, Google Calculator and Search Suggestions

Just found a funky little feature by accident.

The release candidate for IE8 is out, and I’ve got it installed here at work. It’s really nothing special (in fact, Craig Bailey pretty much nailed it in his rant about Microsoft and complexity over here), but it supports search suggestions as part of its support for OpenSearch providers. That means that if you’re searching Google in the search bar at the top right, you get suggestions as you type.

So anyway, I was going to use Google’s unit conversion feature today, and started to type my conversion (note, the picture below is not what I was searching for) into the search bar. Lo and behold, the search suggestion was the answer I wanted! I didn’t even have to hit enter on my keyboard!

Here’s a screenshot so you can see what I’m getting at:

Google Suggest in IE8

It’s not a world-shattering feature, and I’m sure it’s not unique to Internet Explorer, but it’s kinda cool!

Blue Screen Detective

Interesting afternoon. I arrived home to find my PC sitting at the login screen, as per normal, but when I clicked on my username to log in it logged in fresh rather than into an existing session (indicating that my PC had rebooted).

Once I’d logged in I brought up Task Manager and noticed that the CPU was running hard at 100%. The culprit process was “wmpnetwk.exe” – the Windows Media Player network sharing service. Stopping the service from the Services applet brought the CPU back down to single-digit usage, so that was definitely the problem. Of course, I didn’t want to leave it stopped, because I use it to watch videos on my Xbox 360.

A quick search on the net yielded this post by fellow Aussie Brad Saide late last year. I didn’t bother taking his advice and searching through Media Player’s indexes, because I knew immediately what was happening. A couple of videos had started downloading in uTorrent but the download had been paused by the scheduler. One of them only got to 0.4%, and was therefore showing up as a corrupted file to the indexer, causing it all sorts of problems.

I opened uTorrent’s options dialog and enabled the “Append .!ut to incomplete files” option. Now neither of the files shows up as an AVI to Windows, and the Media Player indexer ignores them.

The point of this is that the CPU running at 100% for the better part of the day had caused my PC to heat up dramatically, and coupled with the fact that the temperature today peaked at just over 40°C, the PC just couldn’t last long before blue-screening and rebooting (in fact, it was lasting about 10 minutes).

The whole ordeal was a bit of a scare – I don’t really want to be in the market for a new PC just yet. Still, it has reinforced this point by Scott Hanselman (coincidence?) that a backup strategy is very important.

The Great Reporting Services Controversy

A few weeks ago we discovered this funky little error starting to pop up around our company when trying to print a Reporting Services report:

Unable to load client print control.

After a bit of searching, we discovered the problem. It turns out that the ActiveX control used to enable printing in Reporting Services had some sort of problem with it in earlier versions of SQL Server 2005. I don’t know exactly what the problem is (not signed correctly or something), but it was a problem that should have prevented it from loading in Internet Explorer. However, IE itself also had a security hole that allowed the ActiveX control to load! So up ’til now nobody has had any errors.

Recently a security update was deployed around the company that patched up the security hold in IE, meaning that now the printing ActiveX control won’t load, leading to the error above.

The fix is … well, reasonably simple: Install a later service pack on the SQL Server. We applied SP3 to one of our servers today to fix this very problem.

A few hours later our CFO wandered down into our office and asked why the dates had “changed” on his reports. It turns out that the calendar control used as a date picker for date parameters was changed in SP3! Here’s a before/after shot:

Date pickers in SSRS

The one on the right definitely looks nicer, but notice that it now starts the week on a Monday, whereas in the previous version it started on a Sunday!

This caused all sorts of consternation among our accounting girls, who do actually run their reports from Sunday to Saturday and had become used to picking dates from one side of the calendar to the other.

I explained to the poor folks that they’d probably have to direct their complaints to one S. Ballmer of Redmond, WA and went about my business. However, half an hour later one of the other accountants came to see me, complaining that he was receiving an error when trying to print: Something, he said, along the lines of “cannot load client print control”!

When I arrived at his desk and watched him run the report, it turned out that he was simply ignoring the prompt to install the newer version of the ActiveX control, which meant it wasn’t being updated and therefore giving him the error. I don’t know how to react to that, because generally I would advise people not to blindly install ActiveX controls when prompted, so really he was doing the right thing.

What’s funny about these little issues is that the explanation behind the “start day of the week” and “ActiveX installation prompt” stories is quite reasonable, but try explaining ActiveX signing issues and fortuitous browser security flaws to an average user! All they know is that someone messed around with their reports today and caused them grief.

I don’t know that there’s a moral to this story, but if nothing else it’s worth noting that the latest SQL Server Reporting Services version starts the week on a Monday!

2008 Blog Stats

The post statistics for Mabsterama will be a bit skewed this year because I switched from Community Server to Graffiti at the end of June. This, therefore, is really the “stats post” for the latter half of 2008.

Firstly, the top ten most-viewed posts published on my blog in 2008 since the end of June:

  1. For vs Foreach Performance (1509)
  2. C# Feature Idea: Static Extension Methods (1171)
  3. LINQ to SQL and NOLOCK Hints (1076)
  4. Moq Triqs - Successive Expectations (786)
  5. Enter-to-Tab in WPF (758)
  6. Adding IDbCommand Parameters with Anonymous Types (747)
  7. Another C# Idea: Interface Method Chaining (719)
  8. Playing with Graffiti (592)
  9. A Custom 404 Page for Graffiti (587)
  10. Is IEditableObject Too Hard? (510)

And here are the top five most-commented-on posts published this year:

  1. C# Feature Idea: Static Extension Methods (27)
  2. Developing with Confidence (15)
  3. For vs Foreach Performance (11)
  4. Another C# Idea: Interface Method Chaining (9)
  5. Adding IDbCommand Parameters with Anonymous Types (8)

Overall 2008 has been a pretty good year for me, and I look forward to 2009.

Faking IDataReader with ToDataReader()

Have you ever tried to test code that uses an implementation of IDataReader? Perhaps one that uses SqlCommand.ExecuteReader() to return an SqlDataReader. Such code is pretty hard to test because mocking or faking an IDataReader is pretty cumbersome. You’re forced to either mock every successive call to the reader’s Read() and Get*() methods, or you have to set up a DataTable (complete with dummy rows) and call its CreateDataReader() method.

To simplify all this I’ve created a ToDataReader() extension method which operates on IEnumerable<T>. You simply create an array of anonymous types and turn them into an IDataReader. Here’s some sample code to show you what I’m talking about:

var rows = new[]
{
    new { Id = 1, Name = "Foo" },
    new { Id = 2, Name = "Bar" }
};

using (var rdr = rows.ToDataReader()) 
{
    while (rdr.Read())
    {
        Console.WriteLine("{0}\t{1}", rdr.GetInt32(0), rdr.GetString(1));
    }
}

Pretty cool, huh? Provided you give your anonymous types the same order, property names and data types as the columns you expect your query to return, you can pass the ToDataReader() instance to any method expecting an IDataReader and it’ll return those values.

As an experiment, I’ve thrown the code (as well as a couple of other helpful extension methods on IDataRecord) onto the MSDN Code Gallery. You can reach it here: http://code.msdn.microsoft.com/datareaderext

Xmas 360

This year mum and I did our bit to stimulate the economy by purchasing two Xbox 360s as Christmas presents: one from me to my brother and nephews, and one from mum to dad.

Dad's Xbox LIVE Avatar Rather than paying around $400 for a pro console with a 60GB drive, we opted for the Arcade SKU without the hard drive. Picked them up from Dick Smith Electronics for $238 apiece, which is still a great price. I knew that I didn’t want them to run the NXE off a memory unit, so I did plan to pick up a hard drive for them eventually, but I had no idea that hard drives were so expensive! $199 for a 120GB drive (with neither Ben nor dad will ever use since we don’t have a video marketplace in Australia)! That’s nearly the entire cost of the Xbox just for a hard drive!

Then I remembered that Microsoft have a special offer going at the moment: The Xbox 360 Storage Upgrade offer. You type in your 360’s serial number and console ID, and you can pick up a refurbished 20GB hard drive for only $35! I unpacked both consoles before Christmas and did just that, and yesterday I received the two hard drives.

Now, when we first set dad’s 360 up at his place on Christmas day I wanted to get his Xbox LIVE gamertag going straight away. I soon discovered, however, that you can’t join Xbox LIVE until you’ve pulled down the dashboard upgrade! Begrudgingly I did just that, storing the NXE on their 512MB memory unit. It all went swimmingly but I was concerned that when the hard drives arrived there’d be some problem when I unplugged the memory unit.

So yesterday I drove round there and gave it a whirl. I followed these steps:

  1. Turned off the 360, plugged in the hard drive, and turned it back on
  2. Moved his gamer profile and any saved data from the memory unit to the hard drive
  3. Turned off the 360, unplugged the MU and turned it back on, fingers crossed.

As it turns out, the 360 must store a kind of “kernel” for the dashboard upgrade internally, because it booted up just fine and prompted me to “apply” the update. That involved re-downloading, which took about 20 minutes. Once that was done, everything was back to normal, except without the need for a memory unit!

Having done that I introduced mum and dad to the joys of Hexic HD and Zuma, and I can foresee them getting right into those sorts of games in the future.

Christmas Haul 2008!

Brace yourself! It’s this year’s Christmas Haul! It’s only about 2pm but already we’ve seen everybody on both sides of the family, so I can now reveal the haul this year.

I’ll start with this baby because I want to make sure you click the link and look at some of the interior photos on Amazon, because it’s simply amazing:

With me so far? So I’ve opened all these presents and everything’s good. There were some clothes thrown in there as well which I’m not going to try to find links/images of. Then I open a present and it contains this:

What the—? Well, Sal knows that I want to buy myself a Blu-ray player in the new year, so she must’ve gotten me that so I’d have something to play on it! I give her a confused look, and she says, “Oops! Guess you’d better open that present behind you then!”

I look around at the pile of presents we’d stacked up for the rest of the family, and right behind me there’s a big box. Tentatively I open it up, and lo and behold:

Holy crap! She bought me a freakin’ Blu-ray player!!! Better yet, Sal knew exactly which one I wanted. I had been looking at the Panasonic because it can be modified such that it’s region free! That means I’ll be able to pay reasonable prices for my Blu-ray discs rather than the $40-$50 per disc that they charge here!

From mum and dad I got a nice white business shirt and some vouchers for dining out at two of the top local restaurants, and from Ben and Amanda we received a book of movie tickets, which we’ll put to good use over the next few months.

And to top off the Blu-ray surprise, Sal’s mum and dad gave me these:

Vista Reliability After a Year

I first paved my work machine and installed Vista a little over a year ago. I thought it’d be fun for the one-year anniversary to fire up the Performance and Reliability Monitor and post a screenshot:

image

As you can see (if you click on the image, at least) my reliability index is currently sitting on 8.78. I’d say that’s pretty good, particularly since I was back up to 9.14 as recently as the 10th of this month, only to drop with a few random “Application Failures” since then.

What’s your reliability index? You can find out (in Vista) by clicking the Start button and typing “reliability” to find the shortcut.

Google Adds Forum Metadata

I don’t know how long this has been around, but I only noticed it late last week. Google has added a bit of metadata to their search results when a result comes from a forum (or a site structured similarly). Check out the results from this search:

image

Notice the number of posts under each link? Google has detected that Stack Overflow is a “post-based” site, like a forum, and is giving us that extra bit of detail in the search results. For some forums it’s even including the date (and sometimes time) of the last post, which is really handy for determining how up-to-date the conversation is.

Update! For the propeller-heads among you, it looks like this is the RFC that governs threading in published feeds (which is probably how Google's doing it).