Tuesday, September 09, 2008

Running Visual Studio Web Server as Part of a CI Build

I wanted to get our WatiN acceptance tests to run as part of a CC.Net build.  It was a bit harder than I thought to get the web server up and running before the tests ran so I thought I'd document the steps.

 

  1. Get WebDev.WebHost.dll and WebDev.WebServer2.exe into you solution folder somewhere (I chose SharedLibs\WebServer)
  2. Create a batch file (startserver.bat) that has the line:
    start 
    SharedLibs\WebServer\WebDev.WebServer2.exe
    /port:3699 /path:%~dp0MyProject.Web
  3. Download the Async exec task from here.  Add it to your solution structure.  I put it in SharedLibs\MSBuild.
  4. Add a reference to the AsyncExec task to your ms build file:
    <UsingTask 
         AssemblyFile="SharedLibs\MSBuild\AsyncExec.dll" 
         TaskName="AsyncExec.AsyncExec" />
  5. Execute and kill the server in the msbuild file like this:
        <AsyncExec Command="startserver.bat" />
            
        <Exec ... tests .../> 
    
        <Exec Command="taskkill /F /IM WebDev.WebServer2.exe" 
    IgnoreExitCode="true" />

Notes:

  • Another method might have been to get an IIS site running, but all the tests were set up for local developers to run with the built-in server.
  • The Async exec task is needed as the built-in msbuild task never returns
  • The kill command kills all webdev instances.  This was OK for my solution but may not be for yours!

Tuesday, August 19, 2008

Sharepoint Error Viewing Site Content and Structure Reports

Another weird Sharepoint error.  Suddenly our MOSS site started throwing errors when viewing reports in the "Site Content and Structure" screens. 

 

The default "All Documents" report was fine, but others such as "Checked out to Me" gave this helpful error:

 

Exception occurred. (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))   at Microsoft.SharePoint.Library.SPRequestInternalClass.ReleaseResources()
   at Microsoft.SharePoint.Library.SPRequest.ReleaseResources()

 

Simply adding "<Lists ServerTemplate="850"/>" into the CAML list type for the report got everything up and running again

 

I've no idea what caused it but many thanks to this forum post for the cure!

Programmatically adding items to Sharepoint Choice Field

This has just caused me a bit of hassle, and it wasn't very easy to find a solution.  Sharepoint seems to store choice columns in this format:

 

";#Choice 1;#Choice 2;#"

 

The one thing that is crucial to remember is that the list has to start and end with ";#".

 

I missed out the last "#" and it failed to recognise the list.

Friday, July 11, 2008

Sharepoint Web Part Causing Authentication Prompt

I just spent god-knows how long tracking down a simple issue with a Sharepoint web part. Basically a simple web part was causing the authentication box to pop up for anonymous users. The web part was doing a query of sub-webs to compile a list. Because it was using the Sharepoint object model, it required higher privileges than the anonymous user.

Following this article, it was easy enough to raise the privileges for the chunk of code that required it. The main problem though was a small call to SPContext.Current that I didn't spot.

Simply removing this, and instead passing in the ID of the current site to the elevated method solved the problem. I'll know for next time...

Sunday, June 22, 2008

ALT.NET Mailing List: YMMV

I finally caught up with my reading on the Alt.Net mailing list.  I can't say that I'm a frequent contributor to the group - I'm usually a good few days behind any conversation and also I'm still on the learning path myself so can't usually provide any answers.

Unfortunately the threads on the list seem to be degenerating into the same old Alt.Net catfights. There seems to be far too much "You're doing it wrong", or "you should be using pattern/technology/tool XYZ, anything else is useless".

What I would find more useful, and certainly more pleasing to read, would be along the lines of "I did something similar and used pattern/technology/tool XYZ, but YMMV"

For some reason this doesn't seem to happen on the other groups I read.  The BDD, DDD, TDD groups generally seem a bit friendlier.  I also recently joined the Agile Testing group and saw this on the introduction page:

We would like most of the discussion to be specific:
Q: "I am in situation X. I've run into problem Y. Does anyone have any advice?"
A; "I was in a very similar situation last year. We tried Z, and it worked OK."

Now that's more like it. 

Why ASP.NET is like Progressive Rock

I like Progressive Rock.  There, I've said it.  All out in the open now - nothing to be embarrassed about.

So I was quite amused last year when we were asked to develop an internal, bespoke application called Genesis.  What I didn't realise at the time was just how the development of the application would mirror the history of the group Genesis. The application was my first foray into many new techniques such as MVP (with web forms), IoC, NHibernate etc.  Here's how it went:

 

The Group

The Application

The Gabriel Years  
Something different! A strange front-man (Gabriel) backed by some brilliant musicians (Banks, Phillips, Hackett) creating something new and exciting. Something different! A strange front-end (MVP with webforms) backed by some brilliant technologies (NHibernate, Windsor) creating something new and exciting.
The Hackett Years  
The front-man was a bit too eccentric and difficult, so Collins steps up to the mic.  The rest of the band really gel and produce some of their best music of their career. The front-end was a bit too eccentric and difficult to maintain, so simple webforms are back in the frame.  The rest of the technologies really gel and produce the best development experience of the project
The Collins Years  
The new front-man starts to dominate and it all starts to become familiar and mainstream.  The other two (Banks, Rutherford are still going strong but their contribution seems to get overlooked. The webforms front-end is starting to dominate development with bugs and it's all starting to feel familiar and mainstream.  Windsor and NHibernate still going strong but I keep forgetting they are there as there are so few bugs.
Calling All Stations  
Oh dear.  A brief flirtation with a new front-man.  He's quite good in his own right, but not really the man to replace Collins in this group. A brief flirtation with Monorail.  It's great for new projects but it's too much effort to replace Webforms in this project.
The Present  
Collins, Banks, Rutherford ticking along quite nicely - know what they're good at and quite happy to settle for a pay cheque at the end of the day. Webforms, NHibernate and Windsor ticking along quite nicely and quite happy to release at the end of the day.
The Future  
Definitely past it, and time to move on to fresh blood such as Frost* Webforms are definitely past it and time to move on to Monorail/ASP.NET MVC

Monday, June 16, 2008

Book Review: .Net Domain-Driven Design with C#

Occasionally, an idea comes along that completely changes the way I think about developing software.  Eric Evans' Domain-Driven Design: Tackling Complexity in the Heart of Software was one of those.  As a database-first developer it suddenly seemed so obvious where I was going wrong. 

The only trouble with Evans' book is that it very much deals in the abstract.  Unlike other patterns books that give small snippets of code as examples, many of the DDD patterns in the book are left as an exercise for the reader.  Some people have tried to remedy this, such as Jimmy Nilsson with his book

Applying Domain-Driven Design and Patterns: With Examples in C# and .NET but ultimately that was a good source of information with very little source code. 

There is also much heated debate about how to implement these ideas online.  Some people believe that just having a class called Repository in your code makes it DDD, others seem to be drawn in by the endless possibilities of the Specification pattern.  There's very few examples of an end-to-end application though.
Tim McCarthy has bravely stuck his head above the parapet and written a full DDD example, and documented it in his book.  I've just finished reading it, and here's a quick review of what I liked and disliked:

 

The Good:

  • At last, some end-to-end source code!
  • The book wisely stays away from the religious ORM argument, and just implements a repository using standard SQL.  This allows more focus for the domain creation
  • Because of this, other techniques that might usually be taken care of by an ORM, such as Unit Of Work, are created.  I think this allows a better understanding of what they are there for.
  • I quite like the implementation of the Specification pattern he uses, as it is similar to the way I use it.

The Not So Good:

  • The first criticism is actually not directed at this book, but rather the Wrox "Problem - Design - Solution" books.  This is the second one I have read, and both of them seemed to spend huge amounts of time describing the source code.  If I want to see the source I can download it from Codeplex. I think the space would have been better spent going into more detail about the process of design, the thought behind some of the decisions and maybe more detail on the evolution of the code. 
  • As an example of this, on p70 McCarthy describes You Ain't Gonna Need It and then on p73 makes a class abstract because "who knows, later on having it as an abstract class might turn out to be useful".  Fair enough, it was useful, but not at that moment...
  • Although I've also listed it as a good point, the SQL repository  can also be a bad point (you just can't win!).  I think most people will use some ORM in their solution, so this could be a bit misleading.  I wonder how easy it would be to do an NHibernate repository...

 

In summary, I would say that whilst Tim McCarthy has done a good job in bringing the idea of DDD to more people, the most benefit can be gained from downloading the code and studying it.  There's too much regurgitated code from the source in the text of the book, and the space would have been much better used to describe some thought processes along the development path.