Missing format specifier.

I’ve been practicing my F# recently – I took a gap for a little bit, and just got back into it. I’ve been working through my ‘Foundations of F#’ book, and have hit a slight snag.

There is one line of code I can’t get to compile, I get the ‘Missing format specifier.’ error for the following line:

let print x = printfn “A%” x

The intellisense highlights under the “A%” bit.. Any ideas?

The hunt continues!
Update – worked it out, it should be “%A” rather than “A%” – looks like a typo!!

Printing a word document from C# – how the **** do you change the paper type???????

You wouldn’t have thought it would be that hard to print word documents from within C# – hook up the project to the Word Interop dlls – open the document and print. Easy.

In fairness – a lot of it is like this – and setting up a printer is pretty easy;

PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = printerName;
word.ActivePrinter = printerName;
word.PrintOut(....)

Even selecting a given tray is manageable – either via the ‘WdPaperTray’ enum – or even searching for it via a string.
But try as I might – I cannot find a way to change the paper type – and by that I mean from ‘Plain’ to ‘Preprinted’.

The basic problem is that I need to print to (say) ‘Tray 1’ which contains ‘Preprinted’ paper – and is set up as so on the printer. Attempting to print a plain paper printout gets stuck at the printer with a Paper type is mismatched error – which is fair enough.

Does anyone know how to do this????

Setting up TeamCity…

I’m gradually in the process of shifting our CruiseControl based CI service to use JetBrain’s TeamCity Professional solution (both are free).

The main reason for moving to TeamCity is that whilst CruiseControl worked and did our CI adequately, TeamCity provided more bang for your buck (and when the buck is 0, it’s win-win). TC is effectively CC but with a nicer front end and provision for stats about the builds etc. It’s definitely worth checking out if you are just getting into CI. The only major drawback is the source control integration it has – i.e. it only works with selected source control solutions at the moment (SourceSafe etc) – If you have one of these SCC then give it a try!

Anyhews – migration – easy?
Yes and no – Adding my VS2008 projects to TeamCity was a breeze – they’d never been CC’d so no migration required – just point TC to the SourceSafe database, and then tell it which sln file to open.

Migrating the existing VS2005 projects has been a bit harder, and to be honest most of it is to do with the unit test setup, and they way we have some of our solutions setup – dependency nightmares. I’m pretty certain this is covered by a thing called ‘Artifacts’ in the TC world, but I have yet to explore them properly.

Setting up a TC project consists of 3 main steps,
1. Name the project, describe it etc, decide on the numbering of builds – so you can have 1.x where ‘x’ increments, or just ‘x’ (which is default & the same as cruise control).
2. Set up the source control – point it to the right root project, give it a check out name (or not should you choose).
3. Set up the build runner – in all my cases – based on an sln file, but you can use MSBuild, Ant and many more. This is the usual stuff – configuration, etc.

This is enough to get it to run, but there are even more options – you can set up dependencies, triggers and ‘Agent requirements’.

Agents are one of the really cool things about TC, an Agent is basically a machine that does the compilation. You can have 3 Agents in the Professional edition (and pay for more if needed). At the moment the build server we have doesn’t have .NET 3.5 installed on it, so my VS2008 applications won’t build there, but (obviously) my machine does. So I can have one Build Agent on the build server – for all .NET 2.0 apps, and then my machine with .NET 3.5 as another agent.

Effectively my machine can build any of the .NET 2.0 solutions as well, so now we can do two builds at the same time. TC knows which agents are idle and pushes the build requests to an idle agent – based on a ‘power’ order, i.e. the most powerful agent first.

Anyhews – a few more projects to migrate!

Invoking UI Changes in WPF

Again another reminder, in WinForms I would have done:

private delegate void UpdateUiTextDelegate(Control control, string text);
private void UpdateUiText(Control control, string text)
{
if(InvokeRequired)
{
Invoke(new UpdateUiTextDelegate(UpdateUiText), new object[] {control, text});
return;
}
control.Text = text;
}

Using the same delegate we need to use the Dispatcher.Invoke method – this is (as far as I’m aware at the moment) the sort-of equivalent of the Invoke method on a Form.


private void UpdateUiText(Control control, string text)
{
if(!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(DispatcherPriority.Send, new UpdateUiTextDelegate(UpdateUiText), control, text);
return;
}
control.Text = text;
}

To be honest, I think I’ve read somewhere that the Dispatcher isn’t equivalent – but it does the job for now… I need to read into it more!

Enabling / Disabling buttons in WPF

I’m really only putting this in to remind myself — having come from a WinForms background, I’m used to:

_btnOK.Enabled = false;

but in WPF this is:

_btnOK.IsEnabled = false;

For some reason I (without fail) forget this!

WPF – working with designers – will it work?

One of the main advantages of WPF is that you can write all the backend code and then shunt the design work to a professional designer – you know – one of those guys who thinks that Cyan and Magenta just don’t go together.

I’ve been knocking up a couple of WPF apps in the past month or so and have some very basic Windows pieced together. The app basically works, and now I’m looking at passing the XAML to the designer to get her to make it look good. It’s kind of exciting – I’m really interested to see what she’ll come up with – given free reign and a package hopefully allowing her to do what she wants.

She’ll be predominantly using Expression Blend (and presumably Photoshop) to do the design work. I guess my only reservation is that designing an application where you can use timelines etc is a different kettle of fish to a website, and I hope that we can work together to put some of the cooler WPF stuff into the app.

The other concern is how it will work – should I just give her a document detailing the data that needs to be represented and let her make the window up as she likes, or should I knock up a basic window and then she can just rip it apart etc (again as she likes)…??

I’ll try to blog more when I know how the process is going to go and keep up to date on how it is actually going.

Here’s going forward optimistically!