Monthly Archives: May 2004

TechEd 2004 Australia

Frank has posted up about TechEd 2004 in Australia. This year it is being held in Canberra so it should be easy for most folks on the east coast to get to. Its only about 20 minutes drive from my house. The developer track agenda that Frank posted looks extremely interesting.

If I were you I would start looking at flights as its going to get pretty congested at Canberra airport. Actually its close enough to Sydney and Melbourne that you might even consider a road-trip! We’ll just have to warn the service stations ahead of time that they’ll need to install wireless access points.

I wonder if Chuck and Frank have considered the shortage of wireless access points in Civic.

Advertisements

Finally Made It: Sydney .NET Users Group

I finally made it to the Sydney .NET Users Group last week (different to the Sydney Deep .NET User Group which I made it to earlier in the month). Adam Cogan was out of town so I didn’t get a chance to meet him in person but there were quite a few of his guys there to take up the slack. There was a good range of presentations – I even took a few notes.

One thing that I liked about the way the group kicked off was how the MC asked for any tips or tricks that folks had discovered over the past month. I know some of the other groups do the same thing but it worked really well this time. Cool.

While I was up at North Ryde I managed to catch up with Rose, Frank (happy thirteen years!), Caroline and Troy.

!RowChanged

Over the past couple of weeks I’ve been working a data validation framework. As part of this development effort I needed to listen to the events raised by DataTable instances in order to trigger automatic background validation. This validation would involve spinning through rows in the data-table and arriving at a result, flagging any errors along the way.

Unfortunately I started having problems when rows were added to the data-table and the RowChanged event got fired. You see, the RowChanged event fires BEFORE the data-table has the row added to it – I think that is kind of counter intuitive. Now its probably a bit late to change the .NET framework now, especially since there is probably a bit of code out there that relies of this behaviour, but I would like to see the addition of a number of events – like RowAdded, which only fires AFTER the data-row is accessible.

So, how did I work around it? Well, since this is really proof of concept code I had some scope to implement a bit of a dirty hack, and it goes like this.

public void InjectHack(DataTable dt)
{
  DataRowCollection collection = dt.Rows;
  Type collectionType = collection.GetType();
  FieldInfo fi = collectionType.GetField(
    “list”,
    BindingFlags.Instance | BindingFlags.NonPublic
    );
  ArrayList list = (ArrayList)fi.GetValue(collection);
  WrapperArrayList wrapperList = new WrapperArrayList(list);
  wrapperList.ItemAdded += new EventHandler(wrapperList_ItemAdded);
  fi.SetField(collection, wrapperList);
}

private void wrapperList_ItemAdded(object sender, EventArgs e)
{
  // Put the code you would expect to be able to
  // have in a handler for the RowChanged event.
}

// Filename: WrapperArrayList.cs
public class WrapperArrayList
{
  public WrapperArrayList(ArrayList list)
  {
    this.AddRange(list);
  }

  public override int Add(object value)
  {
    int index = base.Add(value);
    this.OnItemAdded(new EventArgs());
    return index;
  }

  public event EventHandler ItemAdded;
  protected void OnItemAdded(EventArgs e)
  {
    if (this.ItemAdded != null)
    {
      this.ItemAdded(this, e);
    }
  }
}

See what I mean by hack? It does work though, there are a few other ways to tackle this but they are all pretty hacky, and this is the one that I settled for. What it does is use reflection to grab the internal ArrayList that the DataRowCollection uses to store data-rows and replaces it with an instance of an ArrayList-derived class which overrides the Add method and raises an event at the right time.

I’d love to hear your ideas around a better way to do this.

Hey, look, I’m famous!

I was just setting a blog for a mate and at the same time was installing .Text for the first time. As I was reading through the instructions (gasp) I noticed this up the top of one of the sample Web.configs.

<!–
 PreBuilt Web.config for single blog site ( like
http://notgartner.com)
 
 You will likely only need to
  – rename the file to web.config
  – edit the Connectionstring (DbProvider below)
  – edit the email provider
  
  DELETE THESE COMMENTS WHEN YOU ARE DONE!  
–>

How cool is that, my blog has been immortalised in a Web.config file! Kind of gives me a warm fuzzy feeling, oh crap, thats the cup of tea I just spilt on my lap.