Posts

Showing posts from October, 2008

How I would like to write code

Image
Aspect Oriented Programming looks great. It's something I have always wanted to use, but I avoid it because it doesn't work exactly how I would like it to. The first thing I want to avoid is lots of reflection at runtime (compile time is fine), it is for this reason I have mainly been interested in PostSharp . PostSharp looks great! You decorate your class with attributes that you create yourself. After compiling your assembly PostSharp inspects the result for Attributes that are descended from one of its own special PostSharp AOP classes. When it sees these attributes it modifys your code in a specific way. To use the same example as everyone else in the world (yawn) you could create an attribute from the method-boundard attribute. Override the methods declared on that attribute for entry/exit of the method, and write some code in there to write to the IDE's output window using System.Diagnostics.Debug.WriteLine(). Now when I add that attribute to a method on one of my cla

Sufficient architecture

I have a friend who once decided to teach himself VB. We had a mutual friend who was the manager of a video shop so he decided to write some new software for him. He started off by creating an MS Access database to hold the data for his application. Each week I'd pop around to his house and he'd have MS Access open, reworking his tables etc. After a few months I asked "Have you started to write the app yet?". "No, not yet." He replied, "I am trying to get the DB right first, then I will get onto writing the application". I asked what he meant by getting the DB right. He explained that he wanted to make this the best video-hire software ever, and that I should hear about some of the features that are going into it as a result of the DB structure he has made. Record the cast of the film. Record the director, producer etc. Record the genre; horror, comedy, etc. Record film information for films due to be released in the future. All sorts of stu

Accommodation manager - runtime error

I've just spotted something I omitted before zipping up my AccommodationManager app and making it available. When you run the app in Release mode you will experience SQL errors. These errors are intermittent, and a query that worked only seconds ago might not always work. The reason for this is that ECO executes all queries within a transaction; SQLite creates a journal file for every transaction and then deletes it when done; and my anti-virus decides it wants to take a look at this new journal file to see what's inside it; resulting in SQLite not being able to open its own journal file exclusively. This was something I noticed a while ago in another ECO+SQLite app of mine and the guy who writes the library spent a couple of hours with me on MSN trying to work out what the problem was (he had a fix to me by the next morning!). Anyway, I have updated the project so that the connection string tells SQLite not to delete the journal file when it has finished with it, as a conse

ECO, Winforms, ASP.NET, and WCF

The technologies I used in an app I wrote for friends recently. The app manages properties at different locations, bookings, and tariffs. In addition to this the application (which uses SQLite) connects to their website using WCF and updates their database so that people can check prices and availability. I need to get them using it now so that there is data available by the time I put up their website .

Implementing complex unit testing with IoC

I have a method that looks something like this public void DoSomething(SomeClass someInstance, User user) {   var persistence = someInstance.AsIObject.GetEcoService<IPersistenceService>();   persistence.Unload(someInstance.AsIObject());      if (someInstance.CurrentUser != null)     throw new ..........;   someInstance.CurrentUser = user;   persistence.UpdateDatabase(someInstance); } This unloads the local cache before ensuring someInstance.CurrentUser == null, it then sets someInstance.CurrentUser and updates the DB. The unit test I wanted would check what happens when two users try to perform this at the same time. What I wanted was User A: Unload User B: Unload User A: Check == null, it is User B: Check == null, it is User A: Change + update DB User B: Change + update DB + experience a lock exception What I didn't want was User A: Unload User B: Unload User A: Check == null, it is User A: Change + update DB User B: Check == null, it isn't To achieve two things runnin