Not that I'm questioning the value of Wikipedia. Oh no.

by Matt 12. November 2007 04:28

My two year old daughter watches a TV programme called Wonder Pets. She's the very example of their target audience.

And yet it has a wikipedia page.

Now I'm torn between the need to capture, document and collate the zeitgeist for future generations to study, and the thought that some people have too much time on their hands.


Happy Birthday Helvetica

by Matt 6. November 2007 18:19

Oh wow. Just sitting in front of the telly and on comes a documentary about Helvetica. Yep, the font. I have a minor obsession with typefaces; they're a secret that's staring people in the face, one which most are completely oblivious to. But I know that someone has agonised over every single curve and line. It's nice to step into their world, become a part of the secret, while idly looking at a sign or advert or logo. And now primetime(-ish) TV is indulging my geeky little pastime. This is why I pay my license fee.


A photo printing wizard miscellany

by Matt 26. October 2007 11:12

Despite being surprisingly inflexible about it's print sizes, I do like that photo printing wizard. As long as you play by its rules, it's very good.

Just remember to check out the "Options" link at the bottom right of the wizard. You get a dialog like this:

Print Settings

I've turned off the "Sharpen for printing" option, and it's made a huge difference to my photos; they look much more natural now. I haven't been overly pleased with how they've have been printing - everything's been a little too crisp, with very hard edges. I'm very glad to have sorted this out. I'd also recommend having a wander through your printer's colour settings - my Epson was thoughtfully "enhancing" my photos. Not any more.

Anyway, if you feel the urge to add this wizard to your application, you can find it in the Windows Image Acquisition SDK. Simply create WIA.CommonDialog and call ShowPhotoPrintingWizard passing in a list of filenames. It's even been around since XP (Service Pack 1).

And it's nice to know that I'm not alone in wanting to be able to print at arbitrary sizes. But according to an online chat held by Microsoft TechNet, I might be out of luck:

Q: Will the photo printing wizard allow custom sized photos?
A: There are no current plans to support this.

Q: Will the photo printing wizard allow for custom layouts?
A: We are looking at making the templates extensible in the next version.

This was from way back in June 2002. Maybe in Windows 7.


Printing photos. What could be easier?

by Matt 25. October 2007 15:55

Things have been a little busy lately. In a good way, mind, but just a little busy. The main reason for this has afforded me the chance to take and print a load of photos. I've been using Windows Photo Gallery (and lately Windows Live Photo Gallery) to organise my piccies, and can't speak highly enough of it. Speedy, great tagging capabilities and you've just got to love the ever-so-simple red-eye removal. A heartily recommended download, especially for all you XP users.

The printing support is a real highlight, too. A very friendly good wizard allows you to print full page, or at certain standard photo sizes, such as 13 x 18, 10 x 15, 9 x13.

Print Pictures

But there's no print to 7 x 7.

I've got a square picture frame, and I want to print to this size. I've cropped the image ready (another nice Gallery feature). But this is going to print out to 9 x 9. And I've got another picture frame at 4 x 4.

There's no way to customise the output of the print pictures wizard.

So, I downloaded You can resize the canvas (without resizing the actual image) and it lets you resize by centimetres, not just pixels. So I should be able to resize it to 7 centimetres square and we'll all be happy.

Except when you click print, you get the same print pictures dialog.

Now, when it works - when you want to print full page, or to a certain (standard photo) size, it works brilliantly. I love it. But when you want to print to a non-standard size, or even when you just want to bypass the wizard and let the app control the size - you're out of luck.

Of course, it's not even that easy. When I open the image in and try to resize the canvas, I'm told that it's currently at 44.77 centimetres square, because for some reason, the resolution is set at an apparently arbitrary 28.35 pixels per centimetre.

Canvas Size

I need to change this to make it fit to 7 x 7. Changing the print size doesn't change the resolution, but changes the pixel size. Time to whip out the calculator. Set the resolution to 181 pixels/cm and we've got a 7 x 7 image.

I can now change the print size to 9 x 9 and we're good to go - I've got a 7 x 7 image centred in a 9 x 9 white background. Printing this let's me choose the 9 x 13 print option, and hey presto, I've got my 7 x 7 print for my 7 x 7 picture frame. That was almost too easy.

Glad my mom doesn't need to print out photos. Oh wait...


Windows Mobile not syncing?

by Matt 17. October 2007 09:22

This might be a useful tip if your ActiveSync has stopped working. I've just been reading Larry Osterman's post on his Ping of Death story and there's a comment about how ActiveSync connections create network connections in device manager.

In a fit of fortuitous timing, I've been messing around with developing on Windows Mobile, and the device emulator has just stopped working with ActiveSync (well, Windows Mobile Device Centre). Setting the DEVMGR_SHOW_NONPRESENT_DEVICES environment variable (I set it to 1) then running Device Manager (compmgmt.msc) and selecting "Show hidden devices" gave me a couple of Windows Mobile Devices in my Network adapters.

Sure enough, deleting these and re-cradling the emulator fired up the "installing drivers" notifications and voila! up pops Windows Mobile Device Centre and I'm in. Since I had done a hard reset and I hadn't properly set up a partnership, I've no idea if it loses any existing partnerships, but it got me working...


Should Microsoft bundle open source software?

by Matt 26. September 2007 10:28

Phil Haack asked this a couple of weeks ago. Time for a quick thought experiment.

Let's assume we're in a parallel universe where Microsoft had bundled nunit with Visual Studio 2005.

There's been a bit of a buzz about lately. It aims to improve on nunit (although Roy Osherove might disagree).

See where I'm going with this yet?

What would happen if the, alpha geeks decided that nunit was far too passé and was the future?

How does Microsoft handle this?

Do they continue to bundle nunit for compatibility, or do they jump ship to and force their customers to migrate? Bundle both and try to educate the customer which to use?

Has been released in enough time to get into Visual Studio 2008? If not, when and how do they release it?

What needs to happen for their international customers?

Who do Microsoft's customers call when they have a problem with How do patches get distributed to Visual Studio customers?

Or would they use a framework over which they had control?


HTML 5. Shiny new elements!

by Matt 14. August 2007 10:00

Just when you thought you knew HTML, they've gone and announced HTML 5.

It looks like they're running with some of the Semantic Web ideas, and have added elements specifically designed to give semantic meaning to parts of a web page. My particular favourite is the <time> element. I've wanted something like this for ages. Currently, when you put a time on a web page, the reader generally has no idea when it is. E.g. what time is 9.50? Is that AM? What time zone? Similarly, is 01/02/2007 February 1st (of course it is) or the 2nd of January? And look at all those blog posts, every one of them with a date and time on them.

Anyway, the <time> element wraps around a bit of text (such as "Sunday") and in the attributes can provide an exact date, time and time zone. The only downside is that there isn't a recommended rendering for the element. Indeed, the browser should probably just render the content of the element, so perhaps the actual date and time (preferably translated to local time) would be available as a tooltip? But that's not very discoverable, is it?

Interestingly, this won't break compatibility with existing browsers because a downlevel browser will ignore the element and just render the content.

But the real question is, why do we need this? The microformats movement have been embedding semantic meaning into web pages via the use of CSS class attributes for ages. Take a look at this example:

<abbr class="dtstart" title="20070501">May 1st 2007</abbr>.

Does exactly the same as the <time> element. There's a good comment further down that page that claims this is bad for accessibility reasons - screen readers will read out the title attribute of the abbreviation element for clarity. But then it's easily fixed by simply using a <span> element.

So, HTML5 and Microformats. Which is Betamax, and which is VHS?


One mighty gotcha for System.Diagnostic activity Ids

by Matt 14. August 2007 06:28

I've been scratching my head on this one for several days.

After spending a number of posts looking at System.Diagnostics for tracing, and especially at the concept of activity IDs, I decided to put into a project I'm working on. And it all went wrong.

Here's the scenario. I have a WPF application. At start up, it goes straight into a business process that is neatly encapsulated in a model-view-presenter style, written using the Supervising Controller pattern (well, WPF's databinding is so powerful and so pervasive, it'd be rude not to). When I spin up my controller, I create and transfer to a new activity. Events logged at this point correctly live in the new activity.

When I click a button to make something happen, a (custom) event is raised from the view, and handled by the controller. Events logged here are suddenly not part of the activity. The activity Id has been reset to a zero guid.

From the msdn docs on CorrelationManager:

The CorrelationManager class provides methods used to store a logical operation identity in a thread-bound context and automatically tag each trace event generated by the thread with the stored identity.

So obviously my first thought was that this is a threading issue. Turns out it is, but not how you'd expect.

I verified that the thread I started the activity on and the thread used to execute the event handlers were the same, so they should really have the same activity Id.

A serious session of spelunking with Reflector later (and I do mean serious), I had my answer. The CorrelationManager uses Remoting's CallContext to store the activity Id (which has the nice side effect of being transferred across AppDomain boundaries, propagating the activity Id). Cutting a long story short, the data set via the CallContext ends up (indirectly) in an instance of a class called ExecutionContext.

And it's ExecutionContext that causes all the trouble. Again, from the msdn docs:

The ExecutionContext class provides a single container for all information relevant to a logical thread of execution.

The key word there is "logical".

Ever wondered how your security impersonation data is transferred between threads? What about your call stack for Code Access Security? Yep. ExecutionContext.

Every time you start a thread or queue an operation on the thread pool, the current ExecutionContext is carried with it. This is really rather cool when you think about it.

How does that cause problems for me? Well, WPF, like Windows Forms, needs to marshal calls onto the correct thread to prevent deadlocks. That needs an ExecutionContext. If the ExecutionContext is grabbed before I make my change to the activity Id, it won't get propagated. The existing ExecutionContext, which contains the previous, empty activity Id will be used. Practically, this means that all event handlers run under an ExecutionContext created by WPF, and it's this ExecutionContext I am seeing as having no activity Id. And the ExecutionContext is used even if you're already on the correct thread - presumably for CAS and impersonation reasons.

I can see two ways to fix this problem. If you noticed in the description of my problem - I was starting the activity in code that got evaluated from Main, not from the message pump. If I set it from the message pump, I think I'd be using the same ExecutionContext that WPF uses for the event handlers. I suspect that would look something like:

Dispatcher.Invoke(DispatcherPriority.Normal, delegate {
  _previousActivityId = Trace.CorrelationManager.ActivityId;
  Guid newActivityId = Guid.NewGuid();
  _traceSource.TraceTransfer(0, null, newActivityId);
  Trace.CorrelationManager.ActivityId = newActivityId;
  _traceSource.TraceEvent(TraceEventType.Start, 0, "New activity");

But I haven't tried it, so can't be sure - I don't actually know where the WPF ExecutionContext gets created, or even how often it gets created. Relying on this is too flaky for my liking. (But I do like how elegant it is to be able to execute an arbitrary anonymous delegate on the UI thread. Just try doing that in Win32.)

As usual, we can solve this by adding an extra level of abstraction. I think I'm going to add a new class that will encapsulate starting and transferring an activity. All logging will go through this, too, and before each log it will check that the current activity is the correct one. If not, it will set it, log the event and reset it back to what it was. Simple, and effective.

Just to be clear, this won't be a problem for most uses of activities. If you have a bounded activity - i.e. if you both start and stop the activity in a single method, then you'll always be on a single thread of execution, always using the same ExecutionContext and all will be good. If you start an activity and then queue up an operation on the thread pool, the current ExecutionContext (with the current activity Id) will go with it, and again, all will be good. You're only going to have a problem when you have pieces of your activity executing in different contexts, such as with Windows Forms or WPF event handlers.


Tracing. A bit of a wrap up

by Matt 1. August 2007 10:21

As can be seen from the last few posts (if you ignore the monsters one), I've been having a bit of a deep dive into the System.Diagnostics tracing classes, and especially the concept of activities (as glorified by WCF's Service Trace Viewer).

I needed a logging solution for a project at work. This was all about seeing if System.Diagnostics was up to the job. Here are the key points I see from this.

Boring Logging Solved

If your requirements are just for simple but flexible logging, then you're sorted. Knock yourself out.

Reducing Dependencies

I don't want my project to have to take on dependencies it doesn't need. It has to be downloaded to a client's desktop. I'd rather not have to download log4net, or Enterprise Library.

Asynchronous Logging

Unfortunately, logging is synchronous, which would mean a performance hit. You'll need to weigh up if this matters to you. Logging in a client application will likely not have as much of an impact as logging on a high volume server side app.

We can mitigate this by writing an asynchronous TraceListener. Or just use Enterprise Library's MSMQ trace listener. There goes point #2 above.

Logging Arbitrary/Ambient Data

You can enable the logging of certain types of standard data, such as process id, thread id and callstack, which is very useful. You can also use TraceSource.TraceData to output custom data, such as a customer identifier. If you always wanted to output the customer identifier (what I'm calling ambient data), you'll need to write a wrapper API.

The nice thing is that once the extra data has been serialised, Service Trace Viewer can search and filter on it, thanks to custom xpath expressions.

End to End Tracing

The value in being able to join up logging at the client side with logging at the server side and view them in a nice tool like Service Trace Viewer shouldn't be underestimated.

But sometimes end to end tracing isn't enough. If you're interested in knowing the steps a customer took to get to a certain point, you need to group all customer interactions into a form of session.

A simple solution would be to have a session identifier as the form of ambient data that always gets output. Then Service Trace Viewer could filter on this.

Another solution would be to write a particular event that ties the session identifier to a specific activity id, then correlate all the activity ids from that.

End to End Tracing Analysis

Which nicely brings me to the analysis of the end to end tracing.

Service Trace Viewer is a nice tool, but I think it's more of a visualisation/inspection tool than an analysis tool.

End to end tracing is a graph. To get all of the records in a single end to end call, I need to walk that graph and follow the transfer of activities. This is fairly straightforward when we're in an xml file that I'll need to process linearly anyway, but if we stored the data in a database? That'd make an interesting query...

But we can still mitigate this. There's nothing stopping storing a session identifier in each record, either at runtime or post processing.

File Formats

Hang on. Databases? Oh.

Service Trace Viewer only supports flat files.

And you can only use STV if you use the XmlWriterTraceListener.

Propogation of Activities/Context

This Just Works when you're using WCF, and is easy to implement if your not, and the gains in end to end tracing are very cool.

Custom Logging in Service Trace Viewer

It appears that WCF interacts so nicely with Service Trace Viewer by chucking out more information. WCF has built a whole load of plumbing on top of System.Diagnostics, all of which is internal, but it helps dump full exception details, give friendly names to activities and so on. I need to investigate this a bit more.


It's clear that System.Diagnostics isn't the final word on tracing and logging, but it's certainly Good Enough, and given its extensibility, it's definitely a Good Start.

I wanted to be able to tick enough boxes that I could just use the logging out of the box, without having to go and evaluate any other frameworks. I think I've done that, but only just. Simple logging is handled, but I really like the activities idea. Yet to make it easy to use that, I think I'm going to have to write some wrappers. And if there's extra stuff to output to make Service Trace Viewer play nicer, then maybe that'll be a few more wrappers. That's a little disappointing.


Gravatars and monsters

by Matt 30. July 2007 08:11

The Gravatar is a fiendishly simple idea; register an image with your email address, and that image is displayed in the comments of (supporting) blog software. A nice easy way to maintain a visual cue on who people are, and who's talking when in the conversation.

But if you haven't registered a gravatar, what then? Normally, you get a blank image, but you can supply a fallback redirect url with your gravatar link.

Phil Haack and Jon Galloway created an HttpHandler implementation of Don Park's Identicon idea - a way to generate abstract geometric shapes based on an IP address. And of course, used it as the fallback to the gravatar image.

But if that's just a little too abstract for you (and since it's based on IP address, not permanent), you could always use a MonsterID, which is the same sort of idea, but based on the same MD5 hash of your email adress that gravatar uses, and displaying, well, monsters. (More examples and details are on the announcement page than the project page. And here's an alternate template, but I can't find a download link.)

Fractals, anyone?

So that's comments sorted - what about trackbacks? Well, you could use a WebSnapr thumbnail, but that might be just too small to be any use, so how about a favatar? (That's an avatar taken from the favicon of the website sending the trackback/pingback.) There doesn't appear to be a .net implementation, but it shouldn't be too hard.

Now all you need is a server side cache of some sort so that you're not continually regenerating all these images (and proper etag handling for client side caching)...



Month List


Comment RSS