Mad Props!

Omniscience is just a Google-search away.

Login

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

Windows 7 Logo and the Windows Flag

Did you know that the new “7” logo is actually the top-right corner of the “Windows flag”? Check out this image:

image

I’ve superimposed the “7” from this site (after rotating it counter-clockwise slightly) onto a Windows Flag image I found in a Google Search. I’m sure I’m not the first to realise this, but I thought it was worth posting the combined image.

Comicster, ComicVine, WCF and REST APIs

I’m a little late to the party, but ComicVine have released an API for their online database of comics, characters, publishers, creators etc. It’s a fairly comprehensive REST API that lets you pull down details for just about anything in XML format. For example, to search for any character with “silver” in their name, you’d visit a URL like this (with your own API key):

http://api.comicvine.com/search/?api_key=…&resources=character&query=silver

I definitely want to build this into my next version of Comicster, and I want to do so in such a way that the user will be able to choose which online database they pull their information from (or upload to, if the database they select supports it).

My first thought when I saw the way this worked was that I’d need to use System.Net.WebClient to pull down the results, and then parse the XML somehow. Then I remembered a blog post from NathanA that I’d bookmarked on del.icio.us a while ago: WCF Web Programming or: How I Learned to Stop Worrying and Love Uri Templates. This post outlines a very cool way to access REST APIs using WCF, with the Flickr API as an example.

So here’s how I’ve started my ComicVine WCF client. First, an interface that gives me access to some of the more common search functions:

[ServiceContract]
internal interface IComicVineApi
{
    [WebGet(UriTemplate = "search/?api_key={key}&resources=character&query={query}&field_list=id,name,aliases,deck,image")]
    [OperationContract]
    XElement FindCharacters(string key, string query);

    [WebGet(UriTemplate = "search/?api_key={key}&resources=person&query={query}&field_list=id,name,aliases,deck,image,site_detail_url")]
    [OperationContract]
    XElement FindCreators(string key, string query);

    [WebGet(UriTemplate = "search/?api_key={key}&resources=publisher&query={query}&field_list=id,name,deck,site_detail_url")]
    [OperationContract]
    XElement FindPublishers(string key, string query);

    [WebGet(UriTemplate = "search/?api_key={key}&resources=volume&query={query}&field_list=id,name,description,image,start_year")]
    [OperationContract]
    XElement FindTitles(string key, string query);
}

As you can see, we simply map the parameters of each method to parameters in the corresponding URL. Each method returns an XElement which I can easily parse using Linq to XML.

To use this interface we spin it up using WCF, like this:

IComicVineApi _channel = new WebChannelFactory<IComicVineApi>(
    new Uri("http://api.comicvine.com")).CreateChannel();

Pretty neat, huh? We just pass the base URL into a WebChannelFactory and call the CreateChannel method to get an implementation of the interface!

All that’s left, then, is to provide a way to search for characters and return them as proper Comicster.Character objects:

public IEnumerable<Character> FindCharacters(string query)
{
    return from x in _channel.FindCharacters(key, query).Elements("results").Elements("character")
           let icon = (string)x.Element("image").Element("icon_url")
           select new Character
           {
               Name = (string)x.Element("name"),
               Details = (string)x.Element("deck"),
               OnlineId = (string)x.Element("id"),
               Aliases = (string)x.Element("aliases"),
               Image = icon == null ? null : new Uri(icon),
           };
}

As you see, it’s a simple Linq to XML query that walks over the returned XElement and instantiates a character for each search result. This particular query does some funky stuff with the “let” keyword so I can “drill into” the <image><icon_url> nested elements and pull out an image URL or leave it null if neither XML tag is present.

No doubt it’ll be a while before I get everything working the way I want (particularly making the online functionality extensible via MEF), but this is a good first step. Kudos to the ComicVine guys for making their data available in such a flexible way!

Windows 7’s XP Mode Considered Harmful

In the news recently was the new “XP Mode” feature of Windows 7. You can read Jeff Atwood’s rundown of it here, and Paul Thurrot’s preview of it here.

Essentially, XP Mode is an instance of Virtual PC that runs applications in their own little Windows XP environment, but does so in such a way that they look like they’re running on your normal Windows 7 desktop. It’s all very funky, and reminiscent of OS/2 Warp’s “seamless” support for Windows 3.x applications.

Windows 7 XP ModeIt wasn’t until I had read the Coding Horror post that I realised why this is important. After all, Windows 7 can run any old application – even DOS applications. Why would I need a full-blown VM just to run Windows XP applications? The truth is that this feature will become much more important in future versions of Windows. It’s no secret that Windows is embarrassingly backwards-compatible, but having to keep all that cruft around so that 16-bit applications can still run doesn’t do it any favours. XP Mode is the beginning of the end for native backwards-compatibility. Some future version of Windows could drop support for old applications altogether, but as long as it could run a virtual machine you’d still be able to fire up Comicster and add that latest issue of Fantastic Four.

Having said all that, I’m not sure XP Mode is good news. It’s great that the feature exists, and it opens up a whole new world of Windows versions free of the shackles of backwards-compatibility, but here’s the rub: People read about XP Mode and immediately assume that it’s there because Windows 7 won’t run their Windows XP applications without it.

It’s true! I’ve already spoken to a few people who have read about XP Mode on the web and, while technical enough to know what Windows 7 is, aren’t technical enough to grasp the reasons behind the existence of the feature. Heck – like I said, I didn’t even fully grasp them before reading that blog post.

What do you think? Should Microsoft have kept quiet on XP Mode, except for maybe a mention on an MSDN or TechNet page somewhere? Do you think it’s damaging to Windows 7’s compatibility reputation?

PowerShell, RSS Feeds and MSDN Blogs

I noticed this morning that a bunch of my RSS subscriptions weren’t updating. Closer inspection revealed that they were predominantly from http://blogs.msdn.com, and their URL ended with “rss.aspx”. When I visited a couple of the blogs in question, I noticed that their RSS links had changed to “rss.xml”. I’m not sure if this is a recent thing (perhaps MSDN upgraded their blogging software) but I did know that it was going to be tiresome to unsubscribe each of those feeds and resubscribe in Internet Explorer.

PowerShell to the rescue!

Using the Common FeedStore provider which I wrote (and you can get it as part of the PowerShell Community Extensions on CodePlex), I was able to find and fix all of the offending feeds with one command! Behold!

dir feed:\ -rec
    | ? {$_.Type -eq "feed" 
        -and $_.Url.StartsWith("http://blogs.msdn.com")
        -and $_.Url.EndsWith(".aspx") }
    | % {$_.Url = $_.Url.Replace(".aspx", ".xml") }

So … I’m getting (recursively) all the feeds in my “feed:” drive (that is, all the feeds I’m subscribed to) whose URL starts with the MSDN blogs address and ends with “.aspx”, and then replacing the “.aspx” with “.xml” in each feed.

Problem solved! Thanks, PowerShell!

Code Camp Oz 2009

This weekend we attended Code Camp Oz at Wagga. I say “we” because three of my co-workers came along, making for a full car both days. Here’s a quick run-down of the sessions we got to:

Saturday

SharePoint - follow the yellow brick road to public web-sites

Adam Cogan presented on creating public-facing web sites using SharePoint. Adam’s company, SSW, recently completed a major project in the Worley Parsons web site, and anyone who visits that site would have to admit that it’s a fine-looking site. The thing is, though, that the bulk of Adam’s presentation was about the things SharePoint does wrong when it comes to public-facing sites, so it came across as more of a warning against using SharePoint than an advocacy talk. I’m not convinced that SharePoint is the right tool for the job, despite the fact that I love the product for intranet sites.

ALT.NET

Liam McLennan ran a short session on the ALT.NET community and philosophy. Liam did a good job covering the major points around ALT.NET and didn’t say anything too controversial. Certainly he doesn’t seem to be part of the “NHibernate Mafia” which is the most aggravating part of the ALT.NET crowd. A solid presentation (pun intended for those who get it).

ServiceBus Introduction

Chris Hewitt’s short presentation on the .NET ServiceBus was an introduction to the concept more than anything. I don’t know that I can see any immediate uses of a service bus architecture for my own projects, but anybody doing communications over the Internet as part of their applications would definitely want to use something like this.

A lap around the Managed Extensibility Framework (MEF)

David Kean from the MEF team ran this session, and it was the best introduction/demo of MEF I’ve seen. Unfortunately this session highlighted the drawback of having a laptop at Code Camp, because half way through it made me break out my Comicster source code and start tooling around with the way it uses MEF. This meant that I wasn’t paying full attention to the second half of David’s presentation, and I think I missed some important points. I’m sure I’ll catch up on them elsewhere though.

Aspect Orientated Programming in .NET

Paul Stovell & Omar Besiso ran a presentation covering a few of the products/tools that are out there for doing AOP in .NET. Up ‘til this talk I’d really only known about the tools that do IL weaving to introduce new code after the assembly is compiled, so it was an eye-opener to see other implementations (such as the Policy Injection Application Block) that happen at runtime and are part of your code. I’m sure a lot of people walked away from this talk with some ideas to take back to their own projects.

Sunday

6 Design Patterns that Every Developer Should Know

Justin King took us through six common design patterns. Let’s see if I can remember the ones he covered: Singleton, Factory, Command, Adapter, Decorator and Strategy. Design-pattern presentations are often handy just to give a name to a technique you’ve always been doing, but sometimes they can help you understand a better way to solve a problem in your code. I think Justin did a great job of demonstrating the usefulness of each of the patterns he covered.

WCF: Configuring the Bastard

This presentation from Michael O’Dea-Jones suffered from the same problem as the “Line of Business with WPF” session last year, in that it was grossly misnamed. Michael’s presentation, in my opinion, was more of an introduction to WCF than a talk focused on configuration. If I had one main complaint about this presentation it would be that Michael spent almost as much time talking about himself as he did WCF, but it was apparently the first presentation he’d ever done so I have to give him full credit.

The Evolution of Software Development

The scheduled talk for this time slot had to be dropped so Mitch Denny stepped in with a presentation he’d done previously about the past and future of the business of software development. It was an interesting talk but I still wish he’d gone for the other option (PowerShell development). Still, he raised some provocative ideas which are generating discussion even today in our workplace, such as the notion that five to ten years from now there will be no internal software development teams in non-software companies (since they’ll be outsourcing all work to dedicated development shops).

Windows 7 & Windows 2008 R2: Booting from VHD

I wasn’t actually looking forward to this demo from Bill Chesnut, but it turned out to be quite informative and entertaining. The best part was when he realised that his laptop wouldn’t talk to the projector while booting, so he pointed another laptop’s built-in webcam at the screen and used that instead! Genius!

Cloud Computing - A-Life using Windows Azure

The best session of the entire camp, hands down. David Burela took us through an introduction to Windows Azure (and cloud computing in general) and started off by building a “massively-scalable Hello World” application (essentially a simple ASP.NET page that ran on a localised “virtual cloud”). He then set the bar very high for future presentations by demonstrating a genetic algorithm for solving the travelling salesman problem which ran on Windows Azure (and could thus crunch the numbers very quickly). His Silverlight application rendered the path between the cities visually as the algorithm evolved, and while it didn’t run as fast as it could have (because he was recording the session with a screen capture program in the background) it was still mucho impressive.

Overall this was a fun couple of days, again made extra fun by the twittering between attendees. Looking forward to next April!

Internet Censorship TV Coverage

A couple of videos you can check out if you’re interested at all in the debate over Internet censorship raging in this country right now (with intelligent, free-thinking people on the “against” side, and politicians and Christian fundamentalists on the “for” side):

ABC’s Q&A from Thursday, March 26 2009

SBS’s Insight from Tuesday, March 31 2009

Both of these programs let you watch the episodes online. Tell your friends! We need more Australians to get involved and voice their opposition to this senseless waste of time, money and human resources.

Tasmania 2009

On Thursday the 19th (yes, it has been a while since I posted) we flew from Melbourne to Hobart and stayed in Tasmania for five nights. A week after returning I figure I’d better put together a post chronicling our Tasmanian adventures while the trip is still relatively fresh in my mind.

Since this trip is part of our preparation for a larger holiday in Europe a few years from now, we’d deliberately made very few up-front arrangements. We booked a car, and we booked the first night’s accommodation in Launceston. After that we were winging it for the rest of the trip. So from the airport we proceeded directly to the rent-a-car office to pick up our car. We’d only paid for a Mitsubishi Lancer (or equivalent) but we were given a free upgrade to a Nissan X-Trail, which is a mid-range 4WD. I was a bit daunted by having to drive something like that around for five days, but it turned out to be good value because of the large windows – great for sightseeing!

Once on the road, we high-tailed it for Launceston. Took us a few wrong-turns as we initially headed into Hobart, but once we’d gotten onto the right highway we were on our way. This turned out to be about two hours’ drive and a great introduction to the Tasmanian experience. Even the relatively flat land between Hobart and Launceston was vividly green – a sign that the state wasn’t having quite the problem with lack of rainfall that the mainland is. That first drive also highlighted something that would become a hallmark of the trip – the roadkill. Seriously, I have never seen so much roadkill as on the roads in Tasmania. It’s a wonder they have any wildlife left at all!

Launceston is a fairly large town (by Australian standards – around 100,000 population) sitting where three rivers merge, making it a bit of a water-town despite its inland location. We were staying a bit out of town at something of a resort that Sal had found online, called Grindelwald. It’s kind of a Swiss-themed “mini village” with a few local attractions, though we didn’t hang around there too much to indulge.

Our mission statement for the trip to Tasmania was, as Samuel L Jackson would say, “gourmet shit” … and Launceston would set the bar very high in terms of food. The meal we had there that first evening was probably the best meal I’ve ever had dining out. It was at a bar/restaurant called Alchemy and unfortunately the best link I can find is to their Yellow Pages entry. Suffice to say that the food was delicious and reasonably priced. We’re not “haute cuisine” people by any stretch, but this really pushed all the right buttons.

From Launceston we travelled eastward to the coast, and followed the coast south back towards Hobart looking for somewhere nice to stay. We had fish and chips on the beach at St Helens and drove north to the Bay of Fires for some sightseeing. I can tell that the Bay of Fires would be an awesome spot to explore by boat – it was the most beautiful beach I’ve ever seen. Hopefully that Google-images search will give you an idea of what I’m talking about.

From St Helens it was about another hour and half of driving until we got to Swansea, further down on the coast. This was where we decided to stay for the night, and we found an awesome B&B called Meredith House which I can highly recommend. The owners, Noel and Neal, were really friendly and had lots to tell us about the local region and our next destination, and their breakfast (cooked to order) was amazing!

The next day was Saturday, and Sal was keen to check out the Salamanca Markets in Hobart, so we set off to catch them before lunch. I was kind of over them after about five minutes, but we walked around for a while and checked out the various stalls before heading south once more. Our plan was to head to Huonville for lunch, but Huonville turned out to not have much to offer in the way of “gourmet shit” so we kept driving until we found the Petty Sessions restaurant in Franklin. I’d been thinking all morning that I wanted to have chowder for lunch, and abalone chowder featured prominently on the menu there! It was a no-brainer (and quite delicious, if expensive).

From Franklin our next destination would be Geeveston and the AirWalk over the Tahune Forest. That was great fun, with great views of the Huon River.

With still a few hours of daylight left, we decided to head from Geeveston down to Dover and find somewhere to stay. Despite all the evidence to the contrary so far, I had a mental picture of Dover as being quite a large town with plenty of dining and accommodation options. Alas, it was not to be. Dover had a pub/hotel and one B&B that we could see. No point staying there if there was nowhere nice to eat – it would go against our “gourmet shit” policy! So it was on to Southport! Southport, however, was even smaller! It had a pub, too, but hardly any houses that we could see. Perturbed, we stopped at the The Jetty House, the only B&B in the town that we could find an enquired if they had any rooms available. Why yes, replied Ros, the nice lady who owned the house, we have one left! She offered to make us a coffee while we got settled in, but when we dragged the suitcase into the room it became obvious that it wasn’t a place we wanted to stay. There was (look away now if you are easily disturbed) NO TV!!!

We made our apologies to Ros and headed even further south to see if there were other options. We made it almost as far south as it’s possible to drive in Australia before realising that we were in the land of Deliverance and there was no choice but to turn back towards Dover. Luckily Sal had collected a brochure with several B&Bs listed, and we started making phone calls on my perilously-low-batteried mobile phone. After a few tries we found a room available way back near Geeveston at Lilly’s Loft.

Kelly at Lilly’s Loft was really friendly and had a great B&B. We camped there for the night and had a mediocre dinner back at Kermandie near Geeveston.

The next day, Sunday, was my 36th birthday, and our plans for the day began with a tour of the Hastings Caves near Southport. This was awesome (I love caves) and made for a great birthday present from Sal. We then drove back up to Hobart where, two days earlier, we’d booked the next two nights’ accommodation at the Mercure in the city.

Not much to say about our last two days at Hobart except that the food was exceptional (we ate at Fish 349 and Catch), the casino was ordinary, and the roads were confusing. More than once we ended up stuck on the highway that would take us back towards Southport with a few kilometres of driving before the next exit!

Moq Triqs – Mocking an IDbCommand

Knocked up this handy little extension method last week to help us mock the use of IDbCommand (and its associated classes) to test some ADO.NET code. The idea is that you pass in the text and type of the command, and an anonymous type representing the parameter names and values that you expect it to be called with.

public static Mock<IDbCommand> CreateDbCommand<T>(this MockFactory factory, 
    string commandText, CommandType commandType, T parameters)
    where T : class
{
    var cmd = factory.Create<IDbCommand>();
    var parms = factory.Create<IDataParameterCollection>();

    var pq = new Queue<IDbDataParameter>();

    foreach (var prop in parameters.GetType().GetProperties())
    {
        object val = prop.GetValue(parameters, null);

        var par = factory.Create<IDbDataParameter>();
        par.ExpectSet(p => p.ParameterName, prop.Name);
        par.ExpectSet(p => p.Value, val ?? DBNull.Value);
        pq.Enqueue(par.Object);

        parms.Expect(c => c.Add(par.Object)).Returns(0);
    }

    cmd.ExpectSet(c => c.CommandText, commandText);
    cmd.ExpectSet(c => c.CommandType, commandType);
    cmd.ExpectGet(c => c.Parameters).Returns(parms.Object);
    cmd.Expect(c => c.CreateParameter()).Returns(() => pq.Dequeue());
    cmd.Expect(c => c.Dispose());
    return cmd;
}

So if you have a stored procedure called “GetFooByID” and you expect to pass it an “@id” parameter with a value of 1, you simply construct your mock like this:

var cmd = mockFactory.CreateDbCommand("GetFooByID", CommandType.StoredProcedure, new { id = 1 });

… and then, of course, set up your expectations about how the command will be executed (presumably with an ExecuteReader in this scenario).

Note that is code is still using the “Expect” syntax in Moq rather than the new “Setup” syntax, so your mileage may vary. It’s certainly made life easy for us when mocking ADO.NET commands.

Damn you, Internet!

Last night on Lateline there was (finally) a story about the current government’s plan to introduce a mandatory, ISP-level Internet filter. I don’t need to expand on why this is such a bad idea – there has been plenty written about it. Right now it’s only a subset of the government and a few wowsers that support the idea; the rest of the country vehemently opposes it for a host of reasons. If you want to learn more about the issue, a good place to start is the numerous discussion threads about it in the Whirlpool Broadband forum.

Anyway, the story on Lateline (read the transcript here) included some vox-pops from a suburban mum who supported the idea of the filter to “protect” her daughter online. Her words:

It's a gamble as to what can come up. That some of the images that can freely pop up on the internet without protection are exploitive, you know, there may be non-consensual sex.

I couldn’t agree more! I hate when I’m using the Internet, innocently searching Google for, say, lambda based inversion of control containers, and suddenly an image of violent rape pops up in front of me! This seems to happen all the time! I imagine the problem is even worse when you’re looking at sites about Spongebob Squarepants or Ben 10!

Seriously though – it’s amazing how often you hear about this supposed problem from people who never actually access the Internet. What kind of sites are people visiting that are showing them random pop-ups of non-consensual, exploitative sex? I’ve been using the Internet since before there was a web (as have most of my readers, I assume) and I’ve never “stumbled upon” this sort of content.

AWDNUG Feburary 2009

Last night was the first meeting of the Albury/Wodonga .NET User Group for 2009. It was a pleasant surprise to see four or five new faces, as Anton (one of our original members) has scored a new job at Charles Sturt University and managed to drag some of his co-workers along with him! Not only that, but he managed to convince them to present!

The presentation was a bit “outside the box” for us, because it was all about Perl. CSU is deep into Perl and use it for all kinds of things (from login scripts to web forums) so they were keen to give us a (re)introduction to the language. I’m sure it was the first time some of our members have seen regular expressions, and I’m equally sure that they’ll take something away that they can use in their .NET development, since the CLR’s implementation of RegEx is very similar to Perl’s “gold standard”. Many thanks to Ben and the guys for an interesting presentation!

Next month I’m putting my money where my mouth is and demonstrating MEF for everyone! I downloaded Preview 4 last night and gave it a whirl, and there are a lot of positive changes in this release. I’m really looking forward to March! See you there!