Archive for March, 2006

Xbox360 and DivX (VLC360)

March 30, 2006

So the Xbox360 got released here on the 23rd of March and for a start I wasn't really planning on getting one (go the ps3 in November 😀 ) but then we decided to go for a little "look". Well….. yeah….. it was raining so the weekend was going to be an inside one…. and November is a long time away…… so yup – before we knew it we were on a mission to Johnsonville (town had sold out) to get one and a couple of hours later we were back getting it all fired up!

I wont go into a talk on the console but my briefest discussion on it is: games are cool, wireless controllers are awesome, os/user interface is very easy to use/well put together, the unit does get hot so dont stand/lie in on the carpet (i got some graphics glitches after about 4 hours of game time – PGR3 – don't know how hard this drives the unit it but it looks like it would be a good test?), its a shame it doesnt support more codecs etc out of the box… but anyway read on 🙂 (/\ndrew sent me a link today of a guy with some water cooling 😀 pretty cool but I think I'll stick with the fans).

Ok so the xbox is running but now I wanted to play my videos, music etc etc. Ah – you need a Windows Media PC (or do you? 😛 ) I couldnt really afford a media pc so I decided to try out the old virtual machine – and it worked! 😀 First I stopped off at and got a free download of VMware Server – very easy to use, performant, and has just become free (or for a time? I'm not to sure on this one), installed Windows XP into a virtual machine with SP2 and then put the Windows Media Center install over the top.

Then I connected up the xbox to the lan and it game me a code when I fired up Media Center on the remote, went to the website and did the 80M download (dont do the small one – 7M one – this will install the software but doesnt ask for the xbox code and it doesnt want to work). All cool – the xbox was now talking to my VM 🙂 I shared up my music and the xbox was away – Now for the video…

First I tried this one (and yeah it does look like it would work – but it didnt want to for me – I'm not sure if the video wasnt supported (Media Encoder loved it, along with Media Player) or maybe I just didnt set something up right….(btw good work to all the guys out there working on all of this stuff – its really cool! – more and more seems to be popping up everyday) ) so I then went on a scout  and found a version of our friend VLC for the 360 here 🙂 .

Its called VLC360 and it just works! Map your network drives (so it can see them and you are away!) My videos are now streaming from my VM pc down to the 360 through a network share off my normal pc – No extra pc needed! 🙂 Its just like I was playing the videos on my pc and seems to be really good quality. I have a 64 bit 3200+ with 2G of RAM and it seems to sit at about 35% CPU utalization – the network traffic is pretty much nil – no hanging, glitching or anything. Really cool – If you have a 360/planning on getting one and you need divx then this install comes highly recommended – and yep – the VM's are a cheap/good option too 🙂


Ruby Books

March 30, 2006

Ok so I havent read all of these yet (see the post above any you'll work it out 😉 – there has been lots of other work in there as well) but from what I have read they seem to answer a lot of what I need to know about Ruby / RoR and are really well put together. These are the books "Agile Web Development with Rails" and "Programming Ruby".

The second book explains the syntax – heavy in a way but good – and the first book is really a leap into Ruby on Rails and a lot of the bits that put it together. It expains things simply and clearly and takes you through a RoR solution from the standard layout right through to deployment and the things you will come across along the way. It is far from a 10 step tutorial but is a really good book to get running with 🙂 I would highly recommend both of these books to anyone that wants to dive in and have a party with Ruby / RoR 🙂

RoR – gem and Authentication

March 19, 2006

The package tool (I don’t know too much here – just enough to get into trouble) for RoR is gem. Following on from the previous post you run gem from the command prompt as well (run the script “use_ruby.cmd” everytime you come to use ruby from Instant Rails after a reboot/shutdown if you havn’t put it in the system path).

Gem is really cool because you can update your packages/install new packages all from the prompt and find out what is available all really quickly – this is normally how I find out about a feature – while looking for something else. To practise with this first I ran: gem list –local > “c:\local_gem.txt”. This will dump out all the locally installed ruby packages to a file and I then ran: gem list –remote > “c:\remote_gem.txt” to get a list of all the packages available from the main ruby site (theres lots).

Comparing the two files I noticed my rake version was not the latest so to get it up to date (and have a little practise) I ran: gem install rake. This installed the new version and I was all set to go! Cool 🙂 Following on from this I wanted to get some authentication going on my site – one command later: gem install login_generator, and I was already to go 🙂

Heres a page: Login Generator on getting some login functionality going – very fast and it does just work 🙂 I haven’t looked into the security model yet and I see theres a few other options but initially I was just like – wow – this is so cool – this is how I have always thought it should work but have had to deal with all sorts of other rubbish just to get something working….(I won’t say what these products are 😉 ).

The best thing about RoR I have seen so far is that to get something to work its easy – only if I want to do something really fancy does it look to become a bit trickier – its not really difficult straight off the bat – very cool!

Ruby on Rails – RoR

March 19, 2006

Recently I’ve just taken a quick look into Ruby on Rails (RoR) and all I can say is – WOW (followed by why don’t “other” languages we know support some of these features straight out of the box :-P). Like I said I’ve only just started looking at it after /\ndrew (start blogging!) gave both JD and myself a quick tutorial/run down on how to get started. The things I love so far are: how quickly you can get started, the power of the framework, how easy it is to get things setup and get working (I normally get annoyed with some of the new/newish tools out there because you have to hack at them to get them work – the RoR stuff is far from that – it really does just work!), the Active Record pattern, the consistancy of the solution setup, the out of the box test framework, … the list goes on.

There really is a lot of cool stuff in it and you can get running really, really quickly. Rather than write about all the cool stuff (because theres just so much) my best advice would be to go and grab the Instant Rails (IR) package at , install it (gives you RoR, Apache and MySQL), and then go through the 2 tutorials at . These services can all be started and stopped with 1 click which makes the IR package really cool – No editing config files here! 😀 Since /\ndrew gave us a bit of a run down first the tutorial was really a breeze. Here’s my dump of things I came across/notes that might not be immediatelly obvious:

1) Install the IR package to the c drive. Although it does an auto configuration if you install it somewhere else I found the scaffolding command (see the tute) when run from the command line didnt generate all the files needed. Maybe it was just me – maybe not….seemed to work once it was on the c drive anyway…

2) Edit the IR “use_ruby.cmd” file as per the online instructions. Then change your Apache web server to run off port 3000 (right click on the IR taskbar icon). This is the same port as the same as the WeBrick server that you use when working with your Ruby Apps. This will stop it complaining that there is already IIS running on port 80. The other option is to stop IIS…

3) Copy the iconv.dll from ../ruby/lib to ../ruby/bin. It says this on the IR setup page – I got the problem they talk about though so it must just be a step to make sure you do.

4) In addtion to the IR package you will need a database viewer so you can look at your mysql database. The tute suggests one but if you are new to this then you could also grab the MySQL one from here (free – not a trial): . When you run this up just connect to the running database (start IR first) with localhost, user = sa, password left blank, port = 3306. You might want to change the password but just get things working first…

5) Play with some RoR :-). To help out here use an editor like SciTE (has an inbuilt propmt which you can use to run your ruby commands from – only problem is the delete key is not forwarded to the command prompt so you have to type it right the first time :-P) and also grab the radrails ide:

So how do I get started with my play apps: (this is also for me so I dont forget – I’m learning too here :-P):

Open a command prompt and run the cmd file “use_ruby.cmd”, run the command “rails ProjectNameHere” – this creates a whole lot of files under /ruby_apps/ProjectNameHere, now open radrails, pick new Rails project, untick the options (for the project skeleton and the WeBrick server), point to the directory under ruby_apps that was just created. Cool – now browse to the config directory and edit the database.yml file (see the online tute). We’re away 🙂 You can now use the database viewer inside the radrails ide – if you are experimenting with passwords etc then this will tell you if you can connect or not – if you can see your files then your config file is all good 🙂

The things that may trick you at first are: RoR follows a naming convention so if you name things in a certain way you can get a lot of wireup for free. Some of these are: name the primary key of a database table “id”. Name tables by there group name e.g. companies, employees etc rather than company, employee… Name foriegn key columns by singularName_id. So an employee would be linked to a company with a column named “company_id”. It’s actually really clever here (I’m not sure if this will bite me one day) but it knows that the singular form of companies is company and not “companie”. So when you run your scaffolds etc use the singular name – otherwise things won’t work auto-magically :-).

Once you have a table you can run various scripts but the fastest is to run a command in the format “rails script\generate scaffold Company”. Which would create all the things necassary for us to start working against the Companies table. This is quite good because it will also write some stub tests as well. You can run all of these tests, check your sripts, commands etc by running the command “rake” (you may need to browse inside the project directory from your command prompt so rake can see the rake file). And check your code by running “rake stats”. After this you pretty much have a simple site – easy a…..(use the command “ruby script\server” to run it up – do this in another command prompt). Once again have a look at the tutes for the full story…. An interesting thing to note is code layout – use good design principles (MVP/MVC) etc to make your code understandable. The tutorial isnt in this format but obviously its just so you can get started…..something to keep in mind though (check the comments for agreement on this one) 🙂

After that go here: and experiment with whats available – all I can say is its fast development wise and very cool. Finally, run rake to find out if it knows about a command, and restart the server if something isn’t refreshing 🙂

Sql Exceptions and ADO.Net

March 15, 2006

Something I found the other day that confused me for a while are sql exceptions and ADO.Net. I had a test that I was expecting to throw an exception but “wouldn’t” – It would in query analyzer but if I got called Execute on the SqlCommand it would appear to go through fine – the data reader even had some rows in it – what was going on…

I would have expected the SqlCommand to throw the exception instantly – its level was high enough for it to fail! Well I found that this exception only bubbles out once you actually read the data down to the point where the exception occurred. I thought this was pretty strange since if you got a result set back then the first 3 reads from the data reader might be fine while the fourth one actually shows that an exception occurred. If you were doing a read followed by some processing counting on the execute having returned a complete and successful set then it could cause you some issues… it appears as though you should go through and get the results out / put them in a dataset or something first just to make sure that they are actually fine (?) – obviously its like that for a reason but it’s definitelly something to watch out for…


March 14, 2006

I’ve been working on a number of things over the last couple of weeks but just haven’t got around to blogging about what I’ve been finding out… lots of little notes here and there so when I get around to it I’ll have to put them up.

One tool that everyone should have is TestDriven.Net – – this is a welcome partner to both NUnit or the VS2005 Test tools. It installs a right click test option into the VS menu allowing you to run tests, run methods as tests, debug into tests, etc. It’s fast (execution and usability wise) and seems very stable (never had a crash even though the site currently lists it as Beta for 2.0). One feature I really like is it gives an error when a test fails that you can click on and it takes you straight to the part of the test that failed – Its one tool that I’m using more and more all the time.

One thing I did come across yesterday when I was running my tests from the right click menu tricked me for a while. You can tag a test with the attribute [ExpectingException(typeof(ExceptionTypeHere))] – the problem is if the class is not marked as public the test will always fail – even though the exception is thrown. Obviously the class had to be marked as public anyway but it was just something I missed when I created my class since VS normally leaves it off when you go right click new class 🙂 So if you are using ExpectingException and getting some weird failing tests then make sure the test class is marked as public! 🙂 Some stub code off the top of my head…

using NUnit.Framework;

public class TestClass // Make sure this public is here!

public void ArgumentExceptionTest()
{ … }

Active Directory dropping groups? .Net 1.1

March 11, 2006

Recently I had a project that the tech boys moved from 1 server to another after some server problems – at first it seemed to be running well but then an AD nightmare unfolded! The AD component runs nightly and puts various users into different groups. One of these groups is quite large and we found that after adding a user almost 70,000 other users would get kicked from the group – what was going on? It had been working fine for a long time – why it would it decide to die now? There’s a few components to the system and we knew we were only ever adding users to groups – how could they ever be removed? After trying a whole heap of different things we decided to scrap through the source – this lead one of the guys to finding this article:

Arrrhhh – because the box was setup quickly to get the site back up running some critical patches had been overlooked – but what a poor bug! Watch out for that one! Lucky 2.0 is in full flight now a 🙂

NHiberate Configuration

March 4, 2006

One of the things that kind of confused me when I first started with NHibernate was the configuration and session factory etc. With the use of the NHibernate Contrib package the code in the configuration section changes a little.

(btw an excellent book to read is Hibernate in Action by Christian Bauer and Gavin King if you are just starting out with NHibernate – although Hibernate is the java version with NHibernate being the .Net port the Hibernate examples, patterns, help etc are all VERY relevant – you do the same stuff with NHibernate – this was something I didnt realise when I first started out so if your checking out NHibernate then google Hibernate because that will probibly throw up the answer you are looking for 🙂 )

Anyway, back to configuration – when you use the attribute package load the classes mappings use something like the following:

NHibernate.Cfg.Configuration nhConfig = new NHibernate.Cfg.Configuration();

using (Stream s = new MemoryStream())
     HbmSerializer.Default.Serialize(s, typeof(Business.Mappings.Team));
     s.Position = 0;

_nhFactory = nhConfig.BuildSessionFactory();

If you arent using the contrib package and are using xml mapping files then make sure the mapping file is included as a resource in the project and then replace the whole using block with: nhConfig.AddClass(typeof(Business.Mappings.Team));

Here I prefer to load one class at a time rather than the whole assembly because if you havent remembered to include the xml mapping file as a resource then that class map wont be loaded and it wont be obvious why (you’ll be stumped at why something isnt working / isnt saved – so easy to miss) and if there is a problem with a mapping you know exactly where to look – when you load the entire assembly at once you just get told theres an error but it may not tell you where – very hard to fix – when you load them one at a time it will point you straight to the class with the problem 🙂

Another tip here is NOT to call nhConfig.Configure(); If you call this it will go looking for an xml configuration file for the NHibernate settings rather than looking in the App.Config. You dont want any other configuration files to look after (or maybe you do – its up to you) so just let it do its thing and it will look for the nhibernate configuration section in your App.Config 🙂 (just make sure its in there of course)



NHibernate – Generics

March 4, 2006

 Following on from my last post here’s what I found and how I used the package at for generics in NHibernate 1.0.2 and 1-many type relationship mappings:

Your variables need to follow a particular naming notation (otherwise it will complain that it cant find it). This can be overridden but I found it was just easier to make sure that your classes followed the default expected notation which is: underscore followed by a small letter followed by anything else eg: _oTeam, _riders etc would be valid member variables – _OTeam, m_riders etc would be invalid. Pretty simple since thats probibly the notation most people use anyway but it is something to watch out for 🙂 There are two classes you should know about to just get something running with generics at the very minimum. EntityRef of T and EntityList of T.  At one end of the relationship you will have the collection (in the example this is in the Team class and the collection is of type Rider), In the team class we have something like:

private EntityList _riders;

and in the default constructor you would have:

public Team()


_riders = new EntityList(

delegate(Rider o) { o.OTeam = this; },

delegate(Rider o) { o.OTeam = null; });


The first part of the delegate is what happens when a rider is added to the teams riders collection (links it up) while the second part is when the rider is removed from the teams riders collection (breaks the link). So now you dont need to do any special linking code in other methods – you can get rid of those .AddX methods 🙂 (I hadnt thought about using this so I was like – oh yeah – good thinking 🙂 )

You need to use delegates in the default constructor to setup the adding / removing functionality for the collections – once you start using them you get to understand what is going on but at the start you may be like – say what? If you have any other constructors then just use a : this() to make sure the default constructor is called and all these delegates are setup each time 🙂

The attribute markup for the collection would be (note the Access attribute and lack of setter):

[NHMA.Bag(0, Lazy = true,
                     Inverse = true,
                     Cascade = NHMA.CascadeStyle.AllDeleteOrphan,
                     Access = “NHibernate.Generics.GenericAccessor, NHibernate.Generics”,
                     Name = “Riders”)]
[NHMA.Key(1, Column = “TeamID”)]
[NHMA.OneToMany(2, ClassType = typeof(Rider))]
public IList Riders
       get { return _riders; }

In the riders class we need the other part of the link. This is where the EntityRef comes in.

private EntityRef _oTeam;

In the Rider constructor we also need to setup some delegates (note the Add/Remove):

public Rider()

           _oTeam = new EntityRef(
                     delegate(Team o) { o.Riders.Add(this); },
                     delegate(Team o) { o.Riders.Remove(this); }

and then finally the attribute markup for the team would be something like the following (note the .Value, the type  – Team not EntityRef, and the Access attribute):

[NHMA.ManyToOne( Name = “OTeam”,
                Access = “NHibernate.Generics.GenericAccessor, NHibernate.Generics”,
                Column = “TeamID”,
                NotNull = true,
                ClassType = typeof(Team) )]
  public Team OTeam
           get { return _oTeam.Value; }
           set { _oTeam.Value = value; }

So as you can see – a few tricks to get this one working but it does work – just reference the dll and away you go. Should keep fill the gap while the NHibernate 2.0 effort is underway 🙂 The source code and the tests/examples at the svc source are a good place to start to see what is available and how something is done. If you havent got an svc client then a good one can be found here : (thanks JD!)

NHibernate – Generation, Attributes, Nullables, and Generics

March 4, 2006

Over the past few months I’ve been working on a little generator which will generate a thin layer (classes, data access objects, configuration etc) that will sit over NHibernate from a database schema and allow you to work against a particular database. Its pretty simple at the moment – Just point and click go. As I’ve learnt a bit more about it and found out some of the little tricks here and there I’ve gradually extended the template to a point where it is pretty solid (as always theres still some ironing out to do). The things I’ve been integrating into the generation template so far have been:

1) Using classes decorated with attributes (this attribute package is found in the NHibernate Contrib package) rather than the xml mapping files. I decided that the xml mapping files where just something extra to look after in the solution – I thought the less the better. The attributes on the other hand do make these base classes a bit messy but I figured I should never have to look at the generated code – The classes should just be there to use. Although generating the mapping files from the database/inserting attributes like this is really chucking out a whole heap of functionality that NHibernate will allow, I figured I could go back at a later time and extend the generator to provide a richer model. At the moment I just purely want a single class to table mapping and it should just all work.

2) Adding support for Nullable types (I’m using a dll I found called NHibernate.Nullables2.dll – not the one in the NHibernate Contrib package. This can be found here: This is a very cool package as it allows us to use the new .Net 2.0 nullable type notation eg. bool? _flag; in our code/base classes but in the attribute or mapping fies declare it as a special type like: NullableBooleanType 😀 Whats cool here is that from our program side of things these types are transparent while from the NHibernate side of things it understands what we are talking about. And using it is so easy – just reference the dll and change the type in the mapping file :-D. Here’s at example of using NHibernate.Nullables2 with the attribute package:

[NHMA.Property( Name = “RiderNumber”,Column = “RiderNumber”,NotNull = false,TypeType = typeof(NullableInt32Type) )]public int? RiderNumber{get { return _riderNumber; }set { _riderNumber = value; }}

 On the other hand when you use the Nullable package from the contrib you have to use the special types throughout your program code – not very nice 😦

3) Adding in the support for generic collections. This has been what I’ve been working on for the last week or so after work (when I can), and after playing around a bit I have it working – not as nicely as I would have liked but working none the less. The package I used to provide support for generics can be found here: (this is a cool blog too – add it to your feeds if you have one 🙂 ).

The reason putting generics in there was so important for me was that I’m working in .Net 2.0 and then suddenly with NHibernate only under 1.1. I had to go back to using IList – as the developer you have to remember what is in that collection when you come to use it. Generics on the otherhand provide a strongly typed collection IList of T so when you come to use it you know exactly what it is! No casting exceptions for me :-). To get this to work is not the easiest (not hard – but more a case of looking at an example and then just copying it) and then fixing the errors that come up when you run the app up. I’ll give an example of these bits and pieces in another post since this ones getting pretty long …

4) Working on adding enumeration suppport to the generation process – this is working but I’ll keep you posted once I have tested it and used it a couple of times in some app’s I’m working on at the moment 🙂