Tuesday, May 16, 2006

At this moment I'm diving into Design Patterns and Business Objects.  Later I will blog more about these items, but now I just put down the resources I have at this moment:

I also have bought a few books:

  • Head First Design Patterns (Eric & Elisabeth Freeman), which I'm reading now.  This book has it's examples in Java, but that should be no problem.
  • Expert C#2005 Business Objects (Rockford LHotka)

At the project I'm working this moment, we are using Design Patterns like the state Machine Pattern.  We have created a base business object based on LHotka.  We have included the rule manager for broken rules of LHotka.  At last we also included the use of property bags (-Collections).  We have prepared the base in the first project.  All of this will be extended during the next projects.  We have seen that we have the need for some extensions, but have chosen for the pragmatic approach (also because of the project deadline ;-) ).

5/16/2006 8:43:39 PM (Romance Standard Time, UTC+01:00)  #     | 
 Monday, May 15, 2006

The previous post was just about the basic principles of code snippets in VS2005.  Now we will describe the power boost of code snippets: the $name$ notation (or the literal replacement) and the object replacement.

The literal replacement.

When you want to create a code snippet with some customized parts (like variable type, variable name, ...) that must replaced by the developer after inserting the code snippet, you can use a literal.

How do you create this?
In the Snippet element place an element called "Declarations".  In this element you place your literals which can be one or more literals.  The literal element has a few elements:

  • ID: The ID of the literal
  • Default: The default value for the literal

Optional you can add:

  • Function: Function to execute when the literal receives focus in Visual Studio
  • Tool tip: short description of the literal

Now you have created your literal, but you have to place it in your code snippet.  This is done by placing the $ sign in front and at the end of your Literal ID element.  Now go to the code element.  Within your code place the $literalID$ notation where you want it.  The next time you add the code snippet you will see a green rectangle.  This is the place where you have added your literal.  If you have inserted a default value this will be filled in the rectangle.

You can have multiple insertions for the same $literalID$ element.  This gives us a nice effect in Visual Studio.  Only for the first entry you will see the green rectangle.  After filling in the rectangle, Visual Studio will automatically replace all the other literals with the same ID with your filled in value.

Two examples:
Example 1: One literal

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>My MessageboxSnippet</Title>
<Shortcut>mmbs</Shortcut>
<Description>My Snippet for messagebox in c#</Description>
<Author>
</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>YourMessage</ID>
<ToolTip>Place your message here</ToolTip>
<Default>Place your message here</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[MessageBox.Show("$YourMessage$");]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

Example 2 : More literals and used more than one time

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>My MessageboxSnippet</Title>
<Shortcut>mmbs</Shortcut>
<Description>My Snippet for messagebox in c#</Description>
<Author>
</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>YourMessage</ID>
<ToolTip>Place your message here</ToolTip>
<Default>Place your message here</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>Title</ID>
<ToolTip>Place your message title here</ToolTip>
<Default>Place your message title here</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[MessageBox.Show("$YourMessage$","$Title$");
MessageBox.Show("$YourMessage$");]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

As you can see, code snippets in VS2005 give some great power to developers.  I have created or downloaded and changed them to our needs, several good code snippets. Every developer has installed them locally.

5/15/2006 6:08:07 PM (Romance Standard Time, UTC+01:00)  #     | 
 Thursday, May 11, 2006

Code snippets can make the life of a developer a lot easier.  Already in VS2003 you had the possibility to add code snippets to your toolbox or make use of a third party tool.  In VS2005 Microsoft has added a code snippet manager.  We will explain in short how to create such a code snippet.

The format of the code snippet is XML base.  An example of a code snippet file:

<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
     <Title>My MessageboxSnippet</Title>
     <Description>My Snippet for messagebox in c#</Description>
     <Shortcut>mmbs</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Windows.Forms.dll</Assembly>
</Reference>
</References>
<Code Language="VB">
<![CDATA[MessageBox.Show("My first own snippet")]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

We have several parts:

  • Header
    • Title: Name of the snippet
    • Description : Description of the snippet
    • Shortcut : Shortcut to access the snippet
  • Snippet
    • Reference: references to DLL's needed when implementhing the snippet.  Be aware that this is only supported by VB.Net snippets.  Snippets for other code needs to add the reference manually in your solution.
    • Code language: the language of the code
      • VB
      • CSharp

The only thing left now is to save the snippet as a .snippet file and place it in the snippet directory.  By default your snippet directory can be found here : My Documents\Visual Studio 2005\Code Snippets\ and then the language and then the directory "My Code snippets".

A complete course can be found in the MSDN.

But there is an easier way.  The VS Editor Team has released a PowerToy named Snippy.  This is a very handy tool for creating your own snippets.  Click here for more info.

Some interesting code snippets:
Microsoft: http://msdn.microsoft.com/vstudio/downloads/codesnippets/default.aspx
NUnit: http://codebetter.com/blogs/scott.bellware/archive/2006/02/28/139446.aspx
Public property: http://weblogs.asp.net/jeffwids/archive/2005/09/08/424679.aspx

I also found a great tool for world wide snippet sharing: http://www.codexchange.net/
And like gotdotnet there's also a gotcodesnippet site: http://gotcodesnippets.com/

5/11/2006 9:23:04 PM (Romance Standard Time, UTC+01:00)  #     | 
 Tuesday, May 02, 2006

First of all I want to thank Diederik Krols for his help with a few problems I had.

CruiseControl.Net

In this chapter we will explain more CruiseControl.Net and CCTray.Net.

Installation of CruiseControl.Net

Download the latest version at the Thoughtworks website.

Now run the downloaded file (CruiseControl.NET-1.1-Setup.exe) to install CruiseControl.Net.  Just follow the instruction on screen and leave all options as default.  At the end restart your server.

Here we have encountered a problem (only one time).  It seems that our virtual directory isn’t created during the installation phase.  The error we got was that the user and password wasn’t correct, but the installation continued.

This could be solved by manually adding the Virtual Directory.  To do so, follow the next steps:

  1. Open IIS
  2. Create a new virtual directory
    1. Name : ccnet
    2. Directory : the standard installation dir (C:\Program Files\CruiseControl.NET\webdashboard)
    3. Add in the default documents also default.aspx.

Next step is to start the ccNet service manually.  But keep in mind that when starting the service it will run under the local account.  This account doesn’t have network rights to connect to the SourceSafe DB.  So you must have an account with enough rights.  Because for test purpose we are installing everything on our local machine and we will use our own account for the service.  If installing on a server ask the security people for a correct account.

From now on you could access the web dashboard of CruiseControl.net:

Local host: http://localhost/ccnet/
Access from other computers: :/ccnet">http://<servername>:<portnumber>/ccnet

Installation of CCtray

CCTray is a small client application for the team members.  With this application, they can follow up the build progress and is visible in the windows tray. 

To install CCTray, you can go to the web dashboard; there you will find a link for downloading CCTray.  Download this file and run it for the installation.  Just follow the instructions on the screen.

The color of the icon changes depending on the status of the CuirseControl.Net server:

  •  : The most recent build was successful
  •  : The most recent build failed
  •  : The server is unavailable, or returned an error status
  •  : The server is currently building the code

Right-clicking on a project displays a popup menu:

  • Force build Wakes the CruiseControl.NET server from its sleep and tells it to start building immediately.
  • Display Web Page Opens a browser at the CruiseControl.NET build web page for this project. The web page may also be launched by double-clicking the project.

Tray Icons

The following rules are applied, in this order, to determine the icon color:

  • If at least one build is red, the icon is red
  • If no builds are red but at least one is yellow, the icon is yellow
  • If no build are red or yellow, but least one is grey, the icon is grey
  • If all the builds are green, the icon is green

Balloon notifications

Balloon notifications use the standard Windows tray icon popup balloon whenever a build completes. Balloon notifications may be enabled/disabled.

Configuration

Advanced

Two configuration settings can be adjusted only by editing the configuration file directly:

  • Balloon messages
  • Icons

This is done in the cctray-settings.xml file.

Projects

After starting up CCTray doesn’t contain any projects.

You have to fill in your own projects.  To this follow these steps:

  1. Go to File - Settings
  2. At the bottom you will find the Build Servers section.  Here you can add your build servers and projects.  Click on the add button.
  3. Fill in the server with port number (ex: Servername:21234) and click Add Server.  No you will see a list of projects on this server.
  4. Choose your project and click OK.

Now you’re back in the setting screen of CCTray.  You will see that in the build server section, the selected project is visible.

Click on the OK button for leaving this screen.  You’re back on the main screen of CCTray.  And you see that the projects are also added here.

So this is it for this part.  In the next part we will describe how to add your VS 2003 projects in CruiseControl.Net with a Continuous Integration Build configuration.  In part 4 we will talk about using NAnt for our projects.


 

Overview Buildserver chapters on my blog :

Chapter 1 : Introduction
Chapter 2 : CruiseControl.Net
Chapter 3 : Projects
Chapter 4 : Project Structure
Chapter 5 : NAnt and all our buildscripts

5/2/2006 8:34:55 PM (Romance Standard Time, UTC+01:00)  #     | 

I had to explain to a junior developer why using select * is a bad practice.
Well, I had a few reasons for it and after searching the net for more, here’s a list of the top 8 reasons:

    1. By selecting only the fields that you want you don't return any superfluous fields. This results in an immediate speed increase. Suppose we wish to create a drop down select box. To do this we really only need to the information from the first two fields (CustomerID and CustomerName). However, if we use SELECT * then we are pulling all the information for each customer from the database as we write each record, even if we don't need it (i.e. we are pulling data in the CustomerAddress and CustomerComments fields even though we don't need this information). By only selecting the fields we need we reduce the amount of data pulled from the database and thus speed up our application.
    2. At some point in time you'll want to look at using the Recordset Object's .getRows() method to convert a recordset into an array and close your recordset objects earlier. However you will not be able to do this effectively unless you know which fields correspond to which array elements (which requires you to enumerate the fields in the SELECT statement).
    3. At some point you will also look at using the Recordset Object's .getString() method which is even faster than the .getRows() method for returning recordsets to the screen. If you use SELECT * you will have no control over the order in which columns are displayed on the screen.
    4. If you have Access Memo type fields, or SQL Server Text type fields these need to be selected last in your SQL statement, otherwise you will start to run into the problem where these records either do not appear on the screen, or are truncated (see Microsoft's KB article: Q200124).
    5. SELECT * is lazy coding practice. It's probably best to start with good habits early. As well the old saying of "a stitch in time saves nine" is very true. Imagine having to trawl through a 1000 line ASP page that you coded 6 months ago trying to find all the fields you used to edit a SELECT statement at the top of the page. Then imagine doing this for 1000 pages! Better to do it right the first time.
    6. This last point is not a fact, but merely supposition at this point in time. I've heard that if you do SELECT * the database needs to find out what fields are actually in the table before it can then select them all. By specifying the field names the database engine can use those names straight away rather than having to do an extra lookup. However there is very little evidence on the web to say one way or the other.
    7. You need to find errors as soon as possible.  So when a column is deleted, you will get the error directly and not somewhere later in your code.
    8. Interface like programming or program by contract.  Your columns are like the interface.  You define what can be used.

A small example with some time figures can be found here : http://www.tom-muck.com/blog/index.cfm?newsid=36

5/2/2006 7:34:12 PM (Romance Standard Time, UTC+01:00)  #     | 
 Thursday, March 30, 2006

Introduction

At this moment I have installed the first part of a build server for the customer I’m working at the moment.  We are using VS.Net 2003.

We have installed a Continuous Integration Build server.  The first part exists only of following steps:

  • Get latest version of SourceSafe
  • Build de solution
  • If necessary, create the IIS Virtual Directory

Somewhere in April, I’m going to add several tools to the build process:

  • nDepend
  • nUnit
  • FxCop
  • Simian

As for the build server itself, we use NAnt.  For our source control system we use Microsoft’s Visual Source Safe.
So stay tuned, as I will try to write down all my experience and how to set up a build server.  It will be in several parts and sometimes a file must be changed again.

At the moment we have following versions:

  • Microsoft Visual Studio .Net 2003
  • Microsoft Visual Source Safe : 6.0d
  • NAnt : 0.85 RC3
  • NAnt Contrib : 0.85 RC3
  • Cruise Control.Net : 1.1
  • CCTray : 1.1


Overview Buildserver chapters on my blog :

Chapter 1 : Introduction
Chapter 2 : CruiseControl.Net
Chapter 3 : Projects
Chapter 4 : Project Structure
Chapter 5 : NAnt and all our buildscripts

3/30/2006 9:23:09 PM (Romance Standard Time, UTC+01:00)  #     | 
 Monday, February 20, 2006
We have encountered a problem when regenerating our dataset (or even rebuilden the project/solution) This was the situation
  • Project is in SourceSafe
  • We checked out our dataset file
  • Following files are included:
    • Dataset.xsd
    • Dataset.vb
    • Dataset.xsx
  • Make changes to the dataset
  • Run custom tool
  • Now we have following files
    • Dataset.xsd
    • Dataset1.vb
    • Dataset.xsx
As you can see our VB file has another name.When viewing the source code the class name is correct.This is because the vb-file isn't checked out (a bug in Visual Studio .Net 2003?) and you can't checkout the file anymore because for Visual Studio it's already checked out. To solve this, follow the next steps
  • Delete the vb-file from your solution
  • Save the solution
  • Close the solution
  • Go to explorer en locate your files
  • Delete here also the vb-file.You will get a warning about the read-only state.
  • Go to the project file
  • Search for your dataset
  • Delete the line "LastGenOutput = "DataSet1.vb"
  • Reopen your solution
  • Run again the custom tool

After this the situation will be back normal, so these files are included:

  • Dataset.xsd
  • Dataset.vb
  • Dataset.xsx
2/20/2006 8:04:58 AM (Romance Standard Time, UTC+01:00)  #     | 
 Tuesday, January 24, 2006

Windows Blackcomb the next windows version after Windows Windows Vista, will get Windows Vienna as codename.  This doesn't indicate that there are big changes in this version, but just as before Microsoft likes to use names from cities or location with a beautiful view (vistas).

Names like Whistler were coming from a Canadian ski-place. Longhorn (codename of Windows Vista) comes from a certain saloon "Longhorn Saloon

(Info found on the Belgium newspaper "Het Laatste Nieuws")

Common | News
1/24/2006 8:20:29 AM (Romance Standard Time, UTC+01:00)  #     | 
 Friday, January 20, 2006

The 7th and 8th march of this year, the Developer & IT Pro days 2006 are held in Ghent.  VS 2005, Team System 2005, SQL 2005, Biztalk 2006, WSS 3.0, Windows Vista and Office 12 and much more will be discussed during those two days.  Speakers like Peter Himschoot, Jan Tielens, Joris Poelmans, Hans Verbeeck and many more will be present.

More info about the agenda and speakers can be found here : http://www.microsoft.com/belux/nl/devitprodays/

1/20/2006 7:47:04 AM (Romance Standard Time, UTC+01:00)  #     |