views:

42

answers:

1

I just finished making a change to an ASP.NET Ajax screen from a few years back. It was harder than expected to build and maintain. On this change, I estimated 12 hours and spent 4 days. Granted I also did extensive refactoring to simplify the code.

This is actually some pretty fun code, but I wonder if there was a better route for the original implementation than the one I took.

To start, here's a screenshot:

The Problem

So obviously this is an editable tree of data. The data behaves very differently at each level -- very different sorting/collision rules and so on.

My solution is actually performant and provides an adequate user experience, but it's nearly 2,000 lines of code spanning 11 classes, which is more than I envisioned going in. I'm curious if you've solved similiar problems and if you were able to find a simpler solution.

It looks pretty straightforward at a glance, maybe that means I did something right. But there is some real complexity here -- obviously you can add and remove items at three different levels, and everything sorts similiar to a netflix queue, but with quirks. It also has to detect collisions on the various entities (in the image, if you changed day 5 to day 1, it would have to figure out which one is actually day one and move the other one).

The biggest problem was keeping track of the state, since users don't want to commit changes to the database as they work. I thought it might be possible to use the actual controls (nested repeaters in this case) to represent this interim state, but that ended up being a dead end due to complexities related to the underlying data.

The Solution

To solve this, I created a full blown XML representation of all the data, which was actually great in some ways since I was able to use LINQ to do a lot of heavy lifting around sorting and querying. Still, there is a lot of code in here related to syncing up the xml to the html and so on, and I had to make a pretty hefty abstraction on top of the xml to make it easy for me to work with it in code.

In case you're interested, I am currently persisting the XML to session state so that it will survive across callbacks, but eventually that should go into the database.

One colleague told me it would be better to use Flex or maybe Silveright for something like this, and I think that might be true since those are both much more stateful, although Silverlight was not ready for prime time back when this started, and I don't know Flex. Maybe using a temp table instead of xml would have been superior in some way.

I'm looking to learn and improve -- what have your experiences been with this type of problem?

A: 

how do you store your data in the database?

akonsu
i do not see a way to add comments to the original post. so i added an answer. i understand that you use a relational database. my question was not that general. i was trying to understand the requirements. it is unclear to me what you are trying to achieve because you did not give enough details. so i thought that i would ask about how the data are stored. i think that in order to devise a good solution here you might think about how to represent the data correctly and after that everything will fall into place.
akonsu
Ok, there is a save button on the screen, and when it gets clicked (a) I call a sproc to delete the data that's already in place -- a practie that will have to change in the future and (b) I iterate the xml and rebuild the data from that. Data access is done using an ORM that relies on ADO.Net under the covers.
Brian MacKay
Brian, how do you represent data in the database? tables, their fields, associations? my understanding is that you want to represent several possibly overlapping time spans with some additional information about them such as when an event occurs inside the span, etc. and you want to represent distance between spans. correct? how do you do this in the database?
akonsu