Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / weblog

Dominic Cronin's weblog

Strange dreams of nightmare code

Posted by Dominic Cronin at Mar 04, 2007 05:00 PM |
Filed under: ,

One morning this week I woke up to a very strange combination of life and programming. Kind of a "things that make ya go hmm..." moment. Here's how it went:

Some considerable time ago, I began work on a re-write of a Tridion events system. The existing system was so gunged up with layer upon layer of cruft that we decided it was unmaintainable and that we wouldn't touch it unless absolutely necessary. The fickle winds of project management have now blown us back onto the jagged rocks; we ended up dispatching from the new system back to the old code, which turns out to be fairly broken, and I have to mend it. Ouch!

No big deal, you may think, until you realise that the broken piece is a thirty page long stretch of Visual Basic 6. That's thirty pages all in one function. This code handles a Tridion OnComponentSavePost event, and in the process, saves the component four separate times. Each of these saves causes a recursion into the handler, each time from a different place and with a different data state. Depending on the state, various if-then-else blocks either fire or don't, leading to the code being executed in an order very different from what you see laid out as you hit page-down thirty-odd times. As you can imagine, before making even minor changes to this stuff, you have to marinate in the code for quite some time, tracing the various paths of illogic through the smoke-trails of your predecessor's brain-damaged nightmare. One thing's for sure - you know if you touch anything, there's a huge risk that you'll break something else.

If you've ever done this kind of work, you'll know that once you've lived in the code for a few days, there's every likelihood that you'll spend your nights dreaming of it too.

During this time, our seven-month old son, Finlay has had a virus, resulting in some fairly disrupted sleep for us all. Perhaps once every hour or two through the night, the poor lad would cry out, and you'd find yourself awake in response. After a night of this, it becomes increasingly hard to come up out of deep sleep, and one morning at five or six o'clock, and  I found myself in the middle of a dream of scrolling code, hearing a cry, but hearing it as a bug. Huh? How does that work? You hear of people with psychological disorders hearing colours and so forth, and I suppose in the dream world there are no rules. I heard a cry, and experienced it as a sort of "Oh shit, there's another bug." moment.

Finlay's back to health now, and (mostly) sleeping through the night. Maybe some time soon, I will too.

Music licensing petition

Posted by Dominic Cronin at Feb 24, 2007 12:35 PM |

On the 10th December last year, I took advantage of the new e-petitions feature of the Prime Minister's web site, to create a petition highlighting the problems caused by the current regime in the UK for licensing music and dance (or indeed entertainment in general).


I'm a libertarian at heart, and I believe that unless there's a good reason against it, people should be pretty much allowed to get on with their lives. Unfortunately, the Sir Humphreys managed to slip an act through parliament which made it illegal to perform music and the like in many situations which previously had been unencumbered by such nonsense. Well that plainly won't do, and neither will the fact that they ignored the previous petition.

I'm delighted to say that in such a short space of time, the petition has gathered sufficient signatures to put it in the top five. It has attracted press attention from Libby Purves of The Times, and more recently has been the subject of an article in The Stage.

I really hope it's going to do some good. The cynic in my says the jury's still out, but in the meantime, let's keep our fingers crossed.


More information can be found over at http://http//www.cronin.co.uk/licensing

Dutch web site accessibility law

Posted by Dominic Cronin at Jan 12, 2007 09:30 PM |

Quirksmode noted that, since September, Dutch government websites have had to be accessible. Oh and then Ajaxian linked quirksmode with "Be Accessible, or Break the Law", and all of a sudden it's a hot topic.

I've worked on Dutch government web sites myself, back when this was an internal initiative called "Drempels weg" (Removing obstacles). After retro-fitting a text-only version of one important site, we were very glad that the next one we worked on had accessibility designed in from the beginning.

Here then is a shout-out to all the people I worked with on those sites, and to my numerous colleagues that are currently busy with other government sites.

Sometimes, it's nice to be able to see a bit of progress. I'm sure this is all very much appreciated by the people who need web sites to be accessible.

Watin

Posted by Dominic Cronin at Jan 11, 2007 09:45 PM |

(Via Jeremy Miller)

 

WATIR was the first thing that ever made me interested enough to install Ruby. The idea is great; browser-based testing of your web site. You write scripts that drive the browser. When the main output of your software development process is a web site, any tools that allow you to run automated tests are at a premium.

The only thing that made me break stride was Ruby. Sure enough - I like playing with new languages, but it was a disappointment to learn that I'd have to learn yet another to get the benefit. Anyway - your customer doesn't want to hear that you're planning to add yet another hot skill to the training requirements for the team.


But now, there's Watin. All the same good stuff as Watir, but you can write your scripts in C#. I'm itching to have a go.

The six dumbest ideas in computer security

Posted by Dominic Cronin at Nov 26, 2006 07:50 PM |

An excellent round-up of some of the stupidity you have to deal with in the world. I recently came across an organisation that were so into "Penetrate and Patch" that they thought it meant they'd secured their network.



Anyway - go and read it http://www.ranum.com/security/computer_security/editorials/dumb/


If you want to subscribe, his feed is at http://www.ranum.com/index.rss20

Process Monitor - say goodbye to FileMon and RegMon

Posted by Dominic Cronin at Nov 09, 2006 07:05 PM |

If I were to tell you that there's a new utility that combines the benefit of both FileMon and RegMon, and aces them both, you'd be right to be skeptical, unless of course the new tool came from the same stable. Well there you have it, Sysinternals, newly under the Microsoft umbrella, have re-written these tools, and simultaneously combined and enhanced them.

It's worth the upgrade just to get file and registry activity interleaved in the same view.

You are hereby ordered to immediately download Process Monitor and put it on your USB stick.

Batch-fu

Posted by Dominic Cronin at Nov 08, 2006 11:00 PM |

Batch-fu

Today I had a problem with Tridion Content Porter. This is an application that can be used to move data in and out of the Tridion web content management system. It has an "unattended" mode of operation which allows you to run it from the command line, passing a reference to a configuration file as a parameter. I discovered that sometimes (and if anyone can tell me exactly when that is, I'd be grateful),  if you try to run it this way, instead of "blocking" it returns asynchronously and continues to run in the background, writing data to disk that you'd really rather wait for before you embark on further processing.

I called this in to customer support, but I can't wait for them to fix it, so in the meantime, I cracked my knuckles and settled down to figuring out a workaround for my batch script. This post isn't about Tridion Content Porter; this is a generic technique that you can use in batch scripts for any process that you'd like to give a chance to finish.

This (with most of the irrelevant stuff elided) is what I came up with:

REM Dump out the data using Content Porter
.... ContentPorter.exe .... config.xml .... /unattended

:TEST_FOR_CONTENT_PORTER
for /f "usebackq" %%i in (`tasklist ^| find /C "ContentPorter.exe"`) DO if /I %%i GTR 0 GOTO TEST_FOR_CONTENT_PORTER

REM do something with the exported data
So what's going on here?

Back on the air

Posted by Dominic Cronin at Oct 28, 2006 10:00 PM |

Back on the air

At long last this blog is back on the air. A few weeks ago, I started hearing a deathwatch-beetle-like ticking noise coming from under the television. It turned out to be coming from the hard drive of the server which used to support this web site. To my shame, I didn't have any proper backups. In any case, there's only one right thing to do with a ticking hard drive; it had to go.

In the intervening period, my free time has been taken up with the following tasks, among others:

  • Go out and buy a second hand computer to become my new server
  • Install Gentoo Linux on it.
  • Install and configure Apache, Zope, Plone and EasyBlog

 

Needless to say, it wasn't quite as simple as that, and I've had various technical challenges to overcome along the way. Still, with this web site, or rather cluster of web sites (the same server hosts web sites for the whole family) that's what it says on the tin. One of the primary goals of this activity has always been to erm.. "boldly go".

 

As has been said before, I choose to use technologies that I wouldn't usually encounter in my working life, even though I'm a computer programmer who works mainly with web sites and the software used to manage them. This sometimes means that the home projects are a little amateur, but hopefully not amateurish.

 

Now all I have to do is put some new content on the web sites, and pretty them up. For the content, I'll be trying to recover some of the old data, but don't hold your breath. For the look and feel, well there again, I'll be trying to do things a different way to try and learn something along the way, so I hope it doesn't take too long. In the meantime things are going to look distincly plone-ish around here.

How to set up the location of your .NET .config file when you're doing COM+ interop

Posted by Dominic Cronin at Jul 31, 2006 10:00 PM |
Filed under:

How to set up the location of your .NET .config file when you're doing COM+ interop

Today I was struggling with trying to get my .NET application to pick up it's config file. I'd tried creating a .config in the same directory as the application dll, but it didn't work. This was because the application in question is activated via COM+ interop using the /codebase setting. (In other words, the COM+ settings in the registry tell the COM+ loader to use the CLR, and additionally specify the location of the assembly DLL for the benefit of the .NET loader.) This means that as far as .NET is concerned, the directory isn't the "base" of the application.

 

This was a tough problem, and I might have ended up doing one of two ugly things to solve it:

  • Creating a %windir%/system32/dllhost.exe.config file
  • Adding my configuration settings to machine.config

Either of these would have polluted a much wider area than I'd have liked.

Then I came across a blog entry by Rinat Shagisultanov which gave me sufficient of a clue to find a much better solution. The basic idea is this:

  • Configure the application in COM+ (if necessary adding sufficient System.EnterpriseServices goo to make this work)
  • Create a directory and point to it from the ApplicationRootDirectory setting of the COM+ application
  • Create a .manifest file

Now the CLR will regard that directory as the base of your application, and look there for the config file.

 

Thanks Rinat.

XPath and the dreaded distinction between default namespace and no namespace.

Posted by Dominic Cronin at Jun 12, 2006 10:00 PM |
Filed under:

XPath and the dreaded distinction between default namespace and no namespace.

I thought I was pretty much an old hand at XML by now, and that the standard gotchas wouldn't catch me any more. Not so!  The standardest gotcha of 'em all jumped up out of the slime today like something undead and there I was, gotcha'd again.

 

I suppose I was led astray by putting too much trust in the notion that the methods surfaced in an API would always be relevant. Stupid really, but perhaps if you follow along with the story you'll forgive me.  The API in question was that of the .NET framework; specifically the XmlNamespaceManager class.

Let's say you have some XML like this:

 

<?xml version='1.0'?>
<a:one xmlns:a='aaa'>
	<two xmlns='bbb'/>
</a:one>

 

If you have this in an XmlDocument and you want to XPath to the < two/> element, the first thing you'd usually do is create an XmlNamespaceManager and add the namespaces that you want to use in your XPath expression. This allows you to create a mapping between the namepace prefixes in your expression and the namespaces they represent. In the document itself, the same thing is achieved by the namespace declarations you can see in the sample above, but these don't exist in the XPath expression; it needs its own namespace context, or it won't be able to address anything that's in a namespace. But more of this just now...

 

So there I was today trying to demonstrate some techniques to a colleague, and I wrote some code something like this:

            NameTable nt = new NameTable();
            XmlNamespaceManager nm = new XmlNamespaceManager(nt);
            nm.AddNamespace("a", "aaa");
            nm.AddNamespace(String.Empty, "bbb");

            if (null == doc.SelectSingleNode("a:one/two", nm))
                Console.WriteLine ("Couldn't match default namespace");
            else
                Console.WriteLine ("Matched default namespace");

... and to my horror the match failed. After a few quick changes I had something like this:

            nm.AddNamespace("b", "bbb");
            if (null == doc.SelectSingleNode("a:one/b:two", nm))
                Console.WriteLine("Couldn't match b: namespace");
            else
                Console.WriteLine("Matched b: namespace");

... and on this occasion the match succeeded.

 

What was going on?  Could I possiibly be the first human to set foot on a previously undiscovered bug in the framework? Suffice it to say that my moment of glory will have to wait. A quick hunt around on Microsoft's web site showed that half a dozen other people had reported this as a bug, and that Microsoft's response was "Won't fix."

 

What was going on?

Five or so years ago Martin Gudgin and the other luminaries teaching Developmentor's "Guerilla XML" course, had gone to extraordinary lengths to teach me and my fellow victims the difference between a node that is in a namespace, and one that isn't. Sorry Martin, I failed you.

It turns out that in the XPath standard it says the following

A QName in the node test is expanded into an expanded-name using the namespace
declarations from the expression context.  This is the same way
expansion is done for element type names in start and end-tags except
that the default namespace declared with xmlns is not used: if the QName does not have
a prefix, then the namespace URI is null (this is the same way attribute names are 
expanded).  It is an error if the QName has a prefix for which there is
no namespace declaration in the expression context.

So - in XPath, no prefix means not in any namespace at all, just like for attributes. Microsoft's implementation is correct. Otherwise, if you had XML like this:

<?xml version='1.0'?>
<one>
	<two xmlns='bbb'>
		<c:three xmlns:c="po"/>
	</two>
<one>

... you'd be unable to write an XPath from the root element down to <c:three/>.

 

Now for the part where you forgive me for my stupidity:

If you look at the documentation for XmlNamespaceManager, it states very clearly that you can use the empty string to set the Default namespace. (To be fair, the documentation for selectSingleNode has a note which attempts to clarify matters.)

 

If you look at the rest of the API of XmlNamespaceManager, the reason for the confusion becomes clear. XmlNamespaceManager also supports methods like PushScope, GetNamespacesInScope, etc. which plainly aren't intended for use with XPath at all. It looks rather as though you could use an XmlNamespaceManager for managing your namespaces as you navigate through an XmlDocument, perhaps with a streaming library. In that context, setting the default namespace makes perfect sense. If you're using it with XPath though, it's completely irrelevant.

 

So repeat after me: A default namespace isn't the same thing as the empty namespace (aka null namespace, no namespace, not in a namespace, etc.)