Friday, July 31, 2009

T4 Gotcha -- fun with text transformations

A colleague of mine was having trouble with some T4 templating, which was giving apparently insane results. Figuring it out and thus fixing it took me rather longer than it ought to have, so just in case anyone else runs into the same problem...

Have some T4 template code that looks like -- after adding all the debug tracing to try and find out what was going wrong:

where obj is defined elsewhere; and you can get results like

Doing property for Address
obj.Property is not null
obj.Property is null
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.TextTemplating32fcf58db1db4a9da645eda11cd4add4.GeneratedTextTransformation.TransformText()

which appear to defy sanity.

What is actually going on is that the intermediate code generated by the TextTransform program looks like

where the leading whitespace in "            <#     { #>" is being processed in such a way as to consume the if statement.

So, despite the official MSFT brace style being Allman, T4 is actually one of those places where the K&R style is going to be much safer.

Or if that is too heretical a notion, then keep the "<#" at the start of lines except where you explicitly want the whitespace or simply do not bracket on a per-line granularity (with the same proviso) --

will help preserve your sanity.

Thursday, July 30, 2009

Gestalt -- first experiences

The Python-in-the-page concept for Mix's Gestalt is great -- but as a beta still has some rough spots. This is the result of some initial playing...

Recompressing the .xap file at high compression will get you around ~25% reduction in size (for the python .xap, at least). The extra 5k saving for minifying the loader script is small change by comparison.

External script files (<script type="text/python" src="script.py"></script>) appear to be not (yet?) supported -- I get an unhandled error when I split the python code for the 02_python.html sample out.

The round-the-houses Invoke() style needed to call into DOM properties is a bit tedious (as seen in the canvas sample).

There do appear to be some subtle interactions with existing scripts -- adding a hello-world button into an existing page with scripts+canvas+... silently did nothing for me -- I've not yet stripped this down to a simple problem case, but do be wary of this.

Wednesday, July 29, 2009

Summer cycling


View 25-Jul-09 in a larger map

Sunday, starting sunny, but with hazy cloud building. The detour into Stowmarket was marked as "ignore this line on the map", but the loop around the back of Stowupland was a nice detour.


View 26-Jul-09 in a larger map

Rain started Sunday night, and was easing by lunchtime Monday, so I decided to chance it and just make the dash. By the time I was fighting my way out of the Tannington Anomaly (where ground and map never quite match up) the little patch of pale blue sky in the west had opened out into sun and fair-weather cloud, so an excuse for a bit of a detour.


View 27-Jul-09 in a larger map

Tuesday dawned bright, slowly building cloud, but no need to race the weather as has so often been the case. So take a combination of the long route suggested, plus bits of the long route from Monday, joined together with bits of signed suggested cycle tours.

Wednesday, July 15, 2009

MMC 3.0 managed snap-ins on WinXP

The problem:

I needed to do some stuff with snap-ins and I didn't want to take the hit of building a new dev box -- but on my XP box I was getting:

>InstallUtil  .\ManagedSnapIn.dll
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053
Copyright (c) Microsoft Corporation.  All rights reserved.


Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll assembly's progress.
The file is located at C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.InstallLog.

Installing assembly 'C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll'.
Affected parameters are:
   logtoconsole =
   assemblypath = C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll
   logfile = C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.InstallLog
An exception occurred while trying to find the installers in the C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll assembly.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Aborting installation for C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll.

An exception occurred during the Install phase.
System.InvalidOperationException: Unable to get installer types in the C:\ManagedSnapIn\bin\Debug\ManagedSnapIn.dll assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to
 load one or more of the requested types. Retrieve the LoaderExceptions property for more information..

The solution:

As noted here, the mmcperf tool registers 3 MMC assemblies to the GAC for you

>mmcperf.exe
Successfully installed assembly C:\WINDOWS\system32\MMCEx.dll to the Global Assembly Cache (GAC).
Successfully installed assembly C:\WINDOWS\system32\MMCEx.dll to the Native Images Cache.
Successfully installed assembly C:\WINDOWS\system32\MMCFxCommon.dll to the Global Assembly Cache (GAC).
Successfully installed assembly C:\WINDOWS\system32\MMCFxCommon.dll to the Native Images Cache.
Successfully installed assembly C:\WINDOWS\system32\Microsoft.ManagementConsole.dll to the Global Assembly Cache
Successfully installed assembly C:\WINDOWS\system32\Microsoft.ManagementConsole.dll to the Native Images Cache.

which let the InstallUtil run successfully -- but you could probably get away with just copying them into the folder with the snap-in (you need the last as an explicit reference anyway).

Sunday, July 12, 2009

Anime — Ristorante Paradiso


Images quoted for purpose of review.

In a quiet little street near the centre of Rome, there is a little restaurant, the Casetta dell'Orso. It is a peculiar place, since all the staff are middle-aged men, who wear glasses, the result of a foible on the part of the proprietor's wife.

This tranquil arrangement is disrupted when Nicoletta, her daughter by a previous marriage, whom she has concealed from her new husband, arrives on the doorstep.

This is the story of Nicoletta working her passage in the restaurant, and the stories of the older men -- married, single, bereaved, divorced -- with whom she is working.

And while she is young enough to be a daughter to any of them, Nicoletta takes more than a professional interest in her colleagues -- leading to a wider happy ending than I had expected, beyond just the reconciliation with her estranged mother.

Short and sweet. Just one question -- where are all the IRL cute 21 year old oyajicons hiding?


Anime — Eden of the East

Eden of the East starts like The Bourne Identity, revels in western cinema, detours into strange places, and ends like the very beginning says it will. Oh, and it's about Japan's NEET problem.

Saki is on a post-graduation trip to America, the spring after next, some weeks after a missile attack on Japan, dubbed "Careless Monday" by the media. While she's throwing something at the White House, the cops are distracted by the arrival of this naked guy wandering around a chilly Washington DC...

While Akira tries to figure out how he came to be standing there, amnesiac, with just a gun and a cellphone (with 8 billion yen on account, and a concierge who will spend the money at his request and keep on encouraging him to be a Messiah), there are other players in the game. And 20,000 missing NEETs in Japan. And a few more, who, on the other side of the Pacific, would not be NEETs at all, but founders of their own start-up (LOL, Japan).

Not quite a romance, not quite a thriller -- though with a cinematic spectacular of a climax -- this slightly flawed bit of Japanese introspection is still a fun watch. And I wonder how long the reworking of the old slang term Johnson will reverberate around anime circles.

Oh, and all those enigmatic pieces of text in the OP... Here they are:

Eden of the East

Careless Monday

I saw you in Heaven and heard of your glory

You saved our world from the fallen angel

Selecao

Careless

I saw Messiah standing

Standing before me with no words
Nothing but "Hope"

When we lost dread, a Demon was laughing

Eden of the East

But now you are showing us wonder

Giving your love

I've got to know
you're the one
The only one
reveals the world

Eden of the East

With awe, down on my knees again
I've got to know you're the one
The only one reveals the world

Eden of the East

I saw you in Heaven
and heard of your glory
You saved our world from the fallen angels
I saw Messiah standing
Standing before me with no words
Nothing but "Hope"
When we lost dread, a Demon was laughing 
But now you are showing us wonder
Giving your love
With awe, down on my knees again
I've got to know you're the one
The only one reveals the world

The abuse of greatness
is when
it disjoins remorese
from power

Mail
Own date
Media tool
Appli
Camera
Phone book
Iseg
Music
Service
Setting

Noblesse

You've got mail

Calling

Talking

noblesse oblige

10 Billion Charged

noblesse oblige

The King has come!
To lighten up our feet

The King has come!
With justice till the end

The King has come!
To save us from the dark
Who could ever doubt? We have faith

You've got mail

Calling

The abuse of greatness
is when
it disjoins remorse
from power

Juiz

Selecao system
12 persons selected in Japan

GAME

Mr. Outside

Eden

Let me walk with you when I'm lost in the wild
I know you always lead me to another Eden
Let me bless your name, O Lord, O Lord
Your words will never fade away
Since we believe you're the light on earth
Reveals the world

Wednesday, July 08, 2009

IronPython for build scripting

Following on from the earlier post with the snippet about generating GUIDs -- and covering a good chunk of what's been occupying me since...

I have ended up in charge of the build system for the current project at work. This started out with one framework that used a number of custom projects inside a solution to perform unit test, FxCop and coverage analysis, with a lot of magic happening in post-build steps, including direct calls to Wix command-line utilities. Another team had developed a better separated MSBuild-based system, which split out things like the analysis and installer building from the assembly-building solution. We can argue the merits of taking the unit tests out of every checking compile; but separating out the installer build does have a significant benefit in terms of cycle time for a recompilation.

Frankensteining the two together was an interesting task; and IronPython has been a valuable component of the mix. As I noted quite a while ago, the convenience of an XCOPY install on a machine with a current .net installation (any build or dev machine), and the access to the full APIs makes for a powerful tool during a build -- it's not just the fact that you get better string manipulation than a batch file, or can easily spawn off a call to source control to get a synch-level value to stamp an assembly with.

In the current context, there are a number of components being built with a common architecture, so there are plenty of opportunities to DRY the system out.

  • There are repetitive pieces of code (declaring concrete subtypes of shared base classes, to inject component specific information) which can be run by having a couple of .py files (just containing a single map initialization with common keys and component or project specific values) to define the files affected and the component-specific substitutions to make (including in some cases stable but component specific GUIDs, that can be keyed off the component specific names)
  • The shared architecture makes the MSBuild .proj file just as valid for such String.Format based substitution
  • Wix source files are just XML documents -- they can be generated programmatically from XML fragments, inspecting the solution output and filling in the appropriate entities.
  • So are Wix project files (or any MSBuild project for that matter) -- a project to build a 64-bit installer can be derived from a 32-bit installer project by a similar set of XML manipulations.

Taking the latter as an example

Of course, assumes that the .wxs files have Win64='$(var.X64)' attributes sprinkled appropriately.

Film — Red Cliff

Work, summer in the garden, moderating the flood around the new Eva movie and a sudden backlog of things to review have kept posting light these last couple of weeks.

So, to start the catch-up:

Red Cliff is John Woo taking Hollywood production values to the Chinese film industry, in this 2 and a half hour epic -- and even at that length, there is little fat to cut out -- only a little bit of landscapes, some self-indulgence with the CGI, and the obligatory sex scene.

This is clearly a Chinese style action movie -- you can tell that the Generals of the army are the highest level fighters, with the hit-points and special feats to match, like hurling spears and catching them on the far side they go through the target -- and the action builds up in ever bigger skirmishes, up to the final climactic battle. It's really like a live action equivalent of Senkogu Basara, only without the Engrish, and with added bullet-time whenever they had something supposedly cool going on to merit it instead. (Me, I prefer the Engrish.)

The action movie of the summer, without a doubt.