Tuesday, 29 May 2007

Microsoft released Enterprise Libraries 3.1 - May 2007

Microsoft have release Enterprise Library 3.1 which contains a few updates from the previous January 06 version. I've installed it and I much prefer the cleaner start menu options which just take you to the source folder and let you browse away.
Note: If you already have the Enterprise Library 3.0 installed, you must uninstall it before installing the Enterprise Library 3.1. However, you can install the Enterprise Library 3.0 or the Enterprise Library 3.1 when 2.0 is already installed.

The patterns & practices Enterprise Library is a library of application blocks designed to assist developers with common enterprise development challenges. Application blocks are a type of guidance, provided as source code that can be used "as is," extended, or modified by developers to use on enterprise development projects. This release of Enterprise Library includes application blocks for Caching, Cryptography, Data Access, Exception Handling, Logging, Policy Injection, Security and Validation.

Monday, 21 May 2007

Generic collection classes allow nulls

Something to bear in mind when using generic collections in .NET is that they allow you to add null into the collection for reference types. This is not a bug but it means that you need to be careful when iterating through the collection.

For example, if you had a collection declared as
Collection<Customer> customers = new Collection<Customer>();

then add a null into the collection like so:
customers.Add(null);

it adds a null reference into the collection. This means that customers.count returns 1 and all looks well, but this is not so good if you try to iterate around the collection like this:

foreach(Customer customer in customers)
{
customer.Firstname = "test";
}

You would get a null reference exception as the customer object in this case is null. This means you have to clutter your code with null checks as you iterate through the collection. Wouldn't it be nice if the .NET framework provided non-nullable generics collection classes? It's on my list to create a class that enables this. Watch this space.... :)

Thursday, 17 May 2007

How parameters are processed in the Microsoft Data Access Block

I've been using the Microsoft Data Access Block for a while and only came across something that isn't clear in its operation and can have some very nasty side effects. Inside the SqlHelper class, there is a method called AssignParameterValues which "...assigns an array of values to an array of SqlParameters". This sounds good although it's not clear that it does this using index position rather than matching on the parameter name. Therefore, if you create a procedure with 2 parameters both varchars, the order in which you pass the command parameters array to the method is the order in which the SqlHelper executes them against the server. This defeats the purpose of naming your parameters in your code. For example, if you create a method to build your parameters like this:

private static SqlParameter[] CreateMyParameters(string firstname, string surname)
{
SqlParameter firstnameParameter = new SqlParameter("@Firstname", SqlDbType.Varchar);
firstnameParameter.Value = firstname;

SqlParameter surnameParameter = new SqlParameter("@Surname", SqlDbType.Varchar);
surnameParameter.Value = surname;

new SqlParameter[] { firstnameParameter, surnameParameter };
}


then use the

public static int ExecuteNonQuery(SqlConnection connection, string spName, params object[] parameterValues)

method, your nicely named parameters array is attached to the command object based on their position on the array position and not their names. The method that does this is called AssignParameterValues.
However, the same problem does not happen when you use the method

public static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)


The ExecuteReader just attaches the parameters as you created directly to the command object and therefore the parameter names are preserved.

This makes naming the parameters pretty useless for nonquery or scalar operations. It would be nice to see this method modified to use the parameter names which would take advantage of the some of the methods in the SqlHelperParameterCache class.

Tuesday, 15 May 2007

ClearType Font for Visual Studio 2005

If you use ClearType then you may find the Consolas Font Pack for Microsoft Visual Studio 2005 useful.

Optimized for Microsoft ClearType
The Microsoft Consolas Font Family is a set of highly legible fonts designed for ClearType. It is intended for use in programming environments and other circumstances where a monospaced font is specified. This installation package will set the default font for Visual Studio to Consolas.

Ok, it does look a bit typewriterish, but that's the point. However, you do get slightly more text on the screen than you do with the standard Courier New font both vertically and horizontally. It's worth a try anyway. It's easy to switch off if you don't like it. In Studio, goto Tools, Options, Environment, Fonts and Colors and click the use defaults button.

Download Consolas Font Pack for Microsoft Visual Studio 2005

Friday, 11 May 2007

Free books from InfoQ

Whilst trawling the web for information on domain driven design, I came across Domain Driven Design Quickly which can be downloaded in pdf format from InfoQ. If you want to know about domain driven design, this book is an excellent place to start.

There are a lot of free books on InfoQ so it's worth having a browse around their site. Some others of note are:

and some web casts:

Wednesday, 9 May 2007

Converting MMV files to other file formats

Last weekend, I spent some time getting videos off my video camera and onto my computer. I never thought it could be that hard! Then again, I did buy a Sony camera and Sony like all corporate multi-nationals insist on creating proprietary encoding on just about everthing they produce which removes all the choice of software from the end user.
To set the scene I have a Sony DCR-IPV7 which is a nice small camera but as this review states, getting the video off the camera is a awful. Sony not only created a proprietary Micro MV tape, they also encoded the files on the tape as a non standard format. They are saved to the tape as MMV files which are MPEG2 transport stream files which will only play in QuickTime or the software that comes with the camera.

However, you can actually play these files using other players like Media Player Classic. There are also loads of free codec packs like K-Lite Codec Pack, XP Codec Pack to support most file formats that you will come across. With the full codec pack which includes an MPEG2 decoder, you can play MMV files in Media Player Classic.

There is a tool called mmv2mpg.exe which converts mmv (MPEG2 transport stream) files into mpg (mpg program stream) files. There is some help on using it here. I didn't have much success with this tool so started searching for someting else and came across Windows Media Encoder (WME). This is an excellent tool and deals with converting video files from one type to another. It also provides basic screen capture utility which is very handy and the best bit, it's free! It can convert MMV files into wmv files and offers very high levels of compression which is excellent for posting the videos to the web. However, internally, WME uses Media Player to render the files so in order for it to successfully load an MMV file, Media Player must be able to play the file. Media Player 11 can play MMV file, however, it warns you on load that there is no native decoder available so it makes it's best attempt to play the video and it does so successfully. However, when I try to load an MMV file in WME, it crashes! It seems that unless Media Player can play the file natively, WME can't process it. I downloaded the trial version of a Media Player plugin that allowed playback of MPEG2 files called Elecard. Incidentally, www.wmplugins.com is a good site for all your Media Player plugins and you can find Elecard on that site here.
After installing this plugin, WME can successfully convert MMV files to WMV files with a good level of compression. WME also offers a few additional features like video resizing and cropping.

Hello and welcome....

It's been on my todo list for about 2 years and finally, it looks like I've got liftoff. My blog has arrived!

Now the challenge is to make sure posts are added on a reasonably frequent basis ;)

Happy reading... :)