2007-11-13 - Upcoming Architecture Chat

Yep, that time again, the 20th Architecture chat will be held this thursday, 11:30am at the Sylvia Park in Auckland (at Garrisons), all are welcome to come along.

Some topics (off the top of my head) this week include:

  • Java & .Net (didn't make it in last week)
    • The IKVM project (Java VM implemented in .Net)

  • ORM Love
    • NHibernate 2.0 features/maturation (and yes, it looks like the Castle trunk will be moving to it, hurray!)
    • Lightspeed 1.1 has been released.
    • Experiences of writing a Linq to query parser.

  • VS2008 very close
    • But ReSharper for C# 3.0 a while off.
    • Tempted by TeamSystem just to get the in-line "annotate" functionality.

And if anyone else has suggestions, feel free to throw me a comment/email etc. - obviously a bit topic light at the moment.

See you all Thursday!

Read More

Thoughts on CAML.Net

So first off... for those who don't know SharePoint...  CAML is a bit of swiss army knife... if you understand it, can stand it, and know where to stick it you can pull off some interesting and useful results with SharePoint... I'm no expert however, having only touched it for querying and tweaking it here and there for some custom views. Though I think I can confidently say CAML is a wonderful example of XML Abuse :)

At any rate, one aspect of CAML is being able to write CAML queries to query data sources i.e. SharePoint Lists.... I'm against constructing strings for querying data sources, because they're ugly - and difficult to mutate with code, so I decided to give CAML.Net a try (and ended up using it, albeit reluctantly) - here's an example query in CAML:

    My Content Type      

And then in CAML.Net - at first glance it looks ok:
Console.WriteLine(CAML.Where( CAML.Or( CAML.Eq( CAML.FieldRef("ContentType"), CAML.Value("My Content Type")), CAML.IsNull( CAML.FieldRef("Description")))));

But of course then you look a little closer and see that CAML.Where, CAML.Or, CAML.Eq etc. all return strings... so your not actually building a model of your query - which to me immediately removes a large part of the value for this solution.

Looking around the blog-sphere I see lots of people using CAML.Net, and yet nobody seems to have a problem with the way it works?... it puzzles me... At any rate.. let's dive into why I don't like this approach... with another example:

Console.WriteLine(CAML.Where( CAML.Or( CAML.Eq( CAML.FieldRef("Title"), CAML.Value("My Title")), CAML.Or( CAML.Eq( CAML.FieldRef("ContentType"), CAML.Value("My Content Type")), CAML.IsNull( CAML.FieldRef("Description"))))));

And here's the CAML for that:
    My Title     My Content Type       

Notice the Or inside an Or... this is direct feedback from the CAML query language itself - notably that you can't construct a query with multiple root-level criteria, so your left to construct a tree of Or and And's as required to represent your query - which is ugly, and ultimately confusing - it doesn't express intent well... So my first problem with the CAML.Net approach is it makes me aware of the problems in CAML, when they could've been abstracted away for me... now let's look at a reasonably dynamic CAML query.
string title = "My Title"; string contentType = "My Content Type"; List orFragments = new List(); if (!string.IsNullOrEmpty(title)) { orFragments.Add(CAML.Eq( CAML.FieldRef("Title"), CAML.Value(title))); } if (!string.IsNullOrEmpty(contentType)) { orFragments.Add(CAML.Eq( CAML.FieldRef("ContentType"), CAML.Value(contentType))); } orFragments.Add(CAML.IsNull(CAML.FieldRef("Description"))); string query = CAML.Where( OrCamlRange(orFragments.ToArray()));

And suddenly I'm forced into a world of pain - having to manage the various criteria myself, and strings no less - in this case I'm only using Or's - so I can use a little function to stitch everything into a valid query:
private static string OrCamlRange(string[] items) { if ((items == null) || (items.Length < 1))="" throw="" new="" argumentnullexception("items");="" if="" (items.length="=" 1)="" return="" items[0];="" string[]="" remainingitems="new" string[items.length="" -="" 1];="" array.copy(items,="" 1,="" remainingitems,="" 0,="" remainingitems.length);="" return="" caml.or(items[0],="" orcamlrange(remainingitems));="">

But I can't help feeling that an opportunity for CAML.Net to really shine has been tarnished by an initial design choice of returning strings, instead of models.  At least for my use cases, I would've been much happier with something that returned a model which I could post-parse - to smarten up the experience so I could identify misspelled fields, mutate the query based on user choices etc.

Finally, just to be clear - this is not a dig at John Holliday - CAML.Net's author, he's a smart guy who knows a lot more then I ever will about SharePoint!  It's merely an opinion/observation on the negatives of query building approaches which don't embrace an intermediate model which can be parsed or mutated.

Read More

Trung Nguyên Coffee

So I rediscovered my Vietnamese coffee dripper today... and a small cache of Trung Nguy?n coffee I had secreted away after getting back from my Asian excursion a while ago... a little dubious as to whether it would have stood the test of time I brewed a test batch...

And had completely forgotten just how strong it is... yikes - I've been on caffeine buzz for the last hour or so ... it has such a distinctive flavor too... took me straight back to sitting in 35 degree heat, drinking extremely strong coffee mixed with ice cubes and condensed milk in the Vietnamese jungle... (it was a lot more fun then it sounds, though the sweetened condensed milk is a bit too sweet for my liking)

So at any rate - I'm starting to unwind after an incredibly busy period of work - think 16+ hour days for a couple of months ... which has left me a little shattered to say the least... so I'm unwinding a little today...  The lawns are mowed, the sun is
shining and I've started to read  Beautiful Code - which I've heard mixed reviews of, but I
figure it'd be a nice change from SharePoint blogs and should hopefully put me in the right frame of mind as a shift my focus back to projects revolving around ALT.Net technologies once again.

Read More

More SharePoint hacks

Here are some more SharePoint hacks (continuing on from my last
post here)

First off some hacks for the SPGridView which is actually a pretty useful control, but
fails to do a few things, like displaying attachment columns
as-per SharePoint's default List views (with a little paper-clip
symbol), and the second (and much more annoying) it doesn't use
the current users regional settings / timezone for formatting
DateTime values.

The hacks:

And finally support for a ListForm replacement web part -
after trying to customize the ListForm to suit a customers
requirements by creating a CustomListForm in SharePoint designer I
gave up in disgust because it's just too limited in what it lets
you achieve, and worst of all, it breaks attachments support! 
So I wrote a small web part to replace it, which allows for
fine-grained control of visibility and editability (if that's even
a word) of each field, and as an added bonus it doesn't break the
attachments functionality.  I also wanted to add additional
links/buttons to the form which triggered a save including
validation etc. - so I did a little hack to implement that as
I might have a few more to post before the end of the project
- but it's almost wrapped up, so these may be the last for a

Hopefully someone out there finds them useful.
Read More

Hacking SharePoint

I've been working with SharePoint lately, it's a technology of highs and lows... the highs are when you've finally got something to work that should've worked in the first place, the lows are well... all the times in between.

Ok, so that sounds cynical - SharePoint is actually quite a cool product - there's a lot of good in there... stuff that would take you a while to write yourself... but it just tends to drive you a bit crazy, things that look easy from a distance become hard to achieve because of poor documentation, lack of extension points and the difficulty in building testable code.

At any rate, while on this project I've been compiling a list of hacks that other people may find useful, which I used to solve a few of the problems I was hitting while developing... here are the first few:

There are some more coming shortly.
Read More