Monthly Archive for April, 2009

So long Linux, remember the good times…

Last night I was fighting with repairing my MythTV box, the final remaining linux PC in my house.  My video card went down and trying to replacing it the nVidia that was in there with the ATI replacement I picked up turned out to be too frustrating.  Steps I went through

  1. Backup/Restore of KnoppMyth
  2. #2 caused a bad xorg.conf to be used, and install crashed
  3. Un-tarred the backup, replaced bad xorg.conf with a failsafe xorg.conf, re-tarred
  4. Repeat #2
  5. Video card works, KnoppMyth installation crashes
  6. Powered through, MythTV up and running, can’t talk to backend
  7. Reconfigure backend, can see recordings, can’t watch them
  8. Networking doesn’t work
  9. TV-Out doesn’t work
  10. Give Up
  11. Try to pull recordings onto portable hard drive (NTFS formatted, ha, good try)
  12. Download Knoppix w/ NTFS write support
  13. Run LiveCD
  14. Copy files to portable hard drive

Remaining steps

  1. Wipe linux
  2. Install Windows
  3. Install GB-PVR

Before I started working at Magenic none of my computers booted into Windows by default.  My laptop ran VectorLinux (based off Slackware) and my main PC ran Fedora, Ubuntu, etc based on what I wanted to try that week.

The MythTV box was running rock-solid for years, and I loved it.  It was the last bastion of my free-spirited geekiness in my increasingly Microsoft focused world.  Now, it has but hours left to live.  Maybe I’ll put Ubuntu on my laptop for old time’s sake at some point.  Who knows?

Speaking of, Windows 7 RC is out now to MSDN.  THAT is going on my laptop immediately tonight.  I think I’ve been fully assimilated.  Even Winston eventually saw the light and learned to love Big Brother. 

Hosting WPF in WinForms

I’ve done a lot of WPF and Silverlight, but always as standalone apps.  In one project, we actually embedded Silverlight inside a WPF application using a browser control.

I’ve been firmly convinced that XAML is the way of the future for some time now.  But recently I’ve gotten to see a very real, tangible benefit of hosting WPF inside a windows form application.

A lot of time businesses will want some fancy visualization or way to view their data.  In Windows Forms if you want anything “cool” out of the box you’ve got one of these options: paying for a 3rd party set of controls, finding a half-baked control online at CodePlex or CodeProject, or writing it yourself.

Most of the time the project budget and plan don’t include time or money for options 1 and 3.  Option 2 is Russian roulette.  Sometimes you get some really cool stuff, sometimes the control you find is garbage.  In WPF, it becomes almost trivial to do the sort of complex control customization that was such a pain in WinForms.  At the same time, most business probably don’t want to start off by rewriting their existing app in WPF.

Using the ElementHost control and some custom WPF UserControls you can embed some very cool UI functionality with minimal effort and impact to your existing application. My WPF UserControls don’t look like “WPF”.  At least not all the LOB demos you see where there are fancy transitions and gradients slapped in everywhere.  But it’s blowing away the end users.  The integration is seamless, it looks like WinForms, but simply using some stylish DataTemplates and the WPF TreeView we’ve improved the customers user experience ten-fold.  We’re using it 3 critical places of the app where the user needed some better visualization of the data that was coming in.  With WPF we could do that much faster and better with minimal impact to the rest of the application.

Code Generation with T4

I was first exposed to T4 in January/February of 2008 when I was ramping up for a project that used the Guidance Automation packages.  Even though that fell through, it was still worthwhile for getting exposure to a cool little utility like this.

T4 stands for Text Template Transformation Tool and is a built-in feature for Visual Studio 2008 and as an add-on for 2005.  It’s an engine that can be used for generating code from any data source you want.

Add a template
In any project in VS, right click and Add -> New Item., select a text file and rename it so it has the extension .tt.  This keys Visual Studio into the fact that it’s dealing with a T4 file.

Now would also be a good time to install the Clarius add-on for T4.  http://www.visualt4.com/

This tool gives you a bit more design time support than you normally get with T4 out of the box.  Note to the faint of heart: Unless your willing to shell out for the not-free editions your about to step back in time to a place before Intellisense, AutoComplete, Syntax highlighting and other things we’re all accustomed to.

The best way to think about T4 is back to web scripting languages like PHP, ASP, etc.  You have your template, and you have blocks of code for control flow for logic.  Let’s take a look at a simple template

<#@ template language="C#" debug="true" hostspecific="true" #>
<#@ output  extension="txt" #>
<#
 for(int i=0; i < 10; i++)
 {
#>
I'm a template on line <#= i #>
<#
 }
#>

Which tells us the control flow is done in C# and the output is a text file.  When you save the file the template engine will run.  You can also run the engine by right clicking and choosing “Run Custom Tool”.

You can see our output is now nested under our item in Solution Explorer.

t4-1

There are two tags to be aware of here <# #> and <#= #>, the first allows for control flow code to be inserted and the second one is for outputting values.

That’s enough for a start, I’ll be back in another post about going a little more in depth.