Rules for Object Composition

I have found the following rules make reuse easier:

  1. Contained objects should not be aware of the container.
  2. Containers should be aware of the contents.
  3. Event handlers should be used for communication from the contained to the container.
  4. Inter object event handlers should be established by the Container and should be explicitly set up in code.

These simple rules permit reuse of the contained control.  Objects developed along these lines are much easier to extend and reuse.  It also makes it very quick to rearrange the top level container. 

These rules also apply recursively so that a container may be contained in an outer container. 

Boo and MSBuild

Msbuild is microsofts answer to Ant. This is a build tool for the .Net Platform.

It has the minor benfit of being the native file format of the Visual Studio 2005 project files.

You need the .Net Framework 2 installed and to add the Microsoft Framework to your path statement

Boo is a lightweight .Net language.

Here is a sample that gets a task written in Boo for msbuild:

=== MyTask.boo ===

import Microsoft.Build.Framework
import Microsoft.Build.Utilities
import Boo.Lang

class MyTask(Task):
public override def Execute():
Log.LogMessage(MyProperty)
return true

private _MyProperty as string

MyProperty as string:
get:
return _MyProperty
set:
_MyProperty = value

=== Test.proj ===

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
DefaultTargets="MyTarget"
InitialTargets="BuildMyTask"
>

<Target Name="BuildMyTask">
<Exec command="booc MyTask.boo -t:library"/>
</Target>

<UsingTask TaskName="MyTask" AssemblyFile="MyTask.dll"/>

<Target Name="MyTarget">
<MyTask MyProperty="Hello!"/>
</Target>
</Project>

===

You also need Boo installed (and on your path).
Copy Boo.Lang into the directory that you created these scripts in.

At the command line type: msbuild
This will build and run the minimal boo task.
I am planning to add a real msbuild task for boo.

Why is it so hard to move data from Excel to SQL Server?

Business users love Excel.  It is there prefered format of data.

If you can get report data into Excel then they rarely require other reports.

The problem comes when you want to take data the other way.

I have an application that has it’s business logic implemented as a set of stored procedures.  It is a data transformation application so this is the best place to do this.

We need to source certain data from Excel.  OPENDATASOURCE is the recommended solution as follows:

SELECT *
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
  'Data Source="c:Financeaccount.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions

Aside from the drive mapping problems that you can get when the data is not on a local drive on the server there are the following issues:

Data types are implied from the data.  When you let Excel guess it has a better than 50% chance of being wrong.

If there are empty columns for a few rows it assumes the entire row is NULL. 

These two can be complete showstoppers.

The only solution was to move to feeding the data from access… 

Code Sample for Datasets and DataGridViews

        public Form1()
        {
            InitializeComponent();
            SqlConnection cnt = new SqlConnection(GetConnectionString());

            cnt.Open();
            SqlCommand cmd = cnt.CreateCommand();
            cmd.CommandText = “select * from Orders; select * from [Order Details]”;
            northwind.Load( cmd.ExecuteReader(), LoadOption.OverwriteChanges, “Orders”,”Order Details”);
            cnt.Close();
        }

        static private string GetConnectionString()
        {
            // To avoid storing the connection string in your code,
            // you can retrieve it from a configuration file, using the
            // System.Configuration.ConfigurationSettings.AppSettings property
            return “Data Source=(local);Initial Catalog=Northwind;”
                + “Integrated Security=SSPI;”;
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            string s = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
            orderDetailsBindingSource.Filter = “OrderId=” + s;
        }

Software Requirement Specifications

I have been working on a number of SRS’ lately. These do help in the developement of the application. At least you have a formal definition of what the project is trying to do.

A SRS helps in the development of the test plan.

Recently we have found one slight flaw. If the customer does not read the SRS it’s value decreases significantly. If the customer is not interested in reading a large formal document then a few small technical memos would have a greater chance to be read.

SQL Server Error handling problems part 2

SQL Server 2000 has even more error handling problems than I blogged about before.

It would appear that error handling has not been thought through at all.

Take the RAISERROR command as an example. This appears to be a very elegant means of raising errors to the user.  You only need to use sp_addmessage to register a new message. The problem is that the messages are server global.

This means that if you server is ever to host a third party application you cannot safely define your own messages for fear of a third party app stamping all over them.  This should be scoped at a database level, providing at least some control.

The more I look at sql server error handling the more depressed I get. 

NDoc for VS2005

One of the key rights of an open source licence (and therefore a key property of an open source project) is the right to fork. If you think that a project has stagnated or been terminated then you have the right to pick up the pieces and take it in a direction of your own – provided that you have the time, inclination and ability (or can hire someone to do that for you). This is just not available in the closed source world.

NDoc2 died due to lack of resources (and due to the vapourware that is Sandcastle). However NDoc2005 lives on. This is only a beta version. However beta in the open source world means a lot more than beta in the closed source world – especially for a development tool.

This seems to work just fine as is. It creates MSDN style documentation from C# 2.0 source. I had it working without reading the manual in about five mins. This is in comparison to Sandcastle (the microsoft equivalent) where I have yet to generate a single file. This may get my project sufficient documentation to last until Sandcastle catches up (in a year or so).

Windows Genuine Advantage – for who?

Microsofts Genuine Advantage program will check whether you have a registered copy of Windows.

This is a bit of a liberty – don’t they trust me? I have a fully licenced version of XP Pro on this machine.

OK I don’t mind performing this once to download a particular piece of software. However once I have demonstrated to Microsoft that my machine is genuine that should be it. However Microsoft have a different opinion. Every time that you needto install software that is protected by WGA you need to go through the same hoops. How can my machine that is already a Genuine Windows machine stop being a genuine windows machine? Can they decide that it has been revoked?