Umbraco Interaction Layer - Preview 3

Thursday, Nov 6, 2008 4 minute read Tags: Umbraco.InteractionLayer umbraco
Hey, thanks for the interest in this post, but just letting you know that it is over 3 years old, so the content in here may not be accurate.

In between the time spent packing and unpacking while moving house I've been working on my next release of the UIL, and I'm happy to say that it is ready and it is exciting.

There is a breaking change between Preview 2 and Preview 3, but there are also a few new juicy features.

Breaking changes

The biggest breaking change with Preview 3 is that I have removed the interface IDocType. While working on the UIL I came to realise that having both an abstract base class and an interface was some-what redundant. When ever downcasting is needed it should always be done to the base class, so I have removed the interface to avoid confusion.

Another major change is the dependencies of this release, no longer is the generated code supporting .NET 2+, it's now only supporting .NET 3.5+ (ok, I haven't tested it with .NET 4, but I'm just guessing there :P).

Juicy new bits

So I said there were some juicy new bits in this release and I'm quite excited about them, so let's have a look.

Better support for the Umbraco API

I have done some work to improve the features of the DocTypeBase class to have more of the Umbraco API operations, for that I have done the following changes:

  • CreatedDate property
    • Now you can access the date that the Umbraco document was created
  • Save overload method
    • I have added an overload to Save which now mimics the Save & Publish function from the Umbraco UI

 So now it is even easier to programmatically create Umbraco pages and publish them on your site!

Support for Umbraco v4

Yep, that's right, I have finally got official support for the Umbraco v4 API!

If anyone had been brave and tried Preview 2 in an Umbraco 4 site they would have seen the failure which ensued. Turns out that the Umbraco devs have finally upgraded all the GetAll methods to return List, not an array. A nice little change (keep in mind that Umbraco was originally .NET 1.1 so the array was probably a hold over from the pre-generics days), but it did mean that the UIL failed as the property signatures no longer matched what it was compiled against.

But never fear, this release supports v4 (there are actually 2 download packages available, one for v3 and one for v4).

This does not mean I am stopping v3 support, Umbraco v3 will be supported along with Umbraco v4.

VB support

Ok, I kind of already had this, the UIL has always been able to generate Visual Basic files, but if anyone had tried to use them well they would have seen that it didn't go so well. I'm not a Visual Basic developer, I haven't used VB for a number of years now so it was always there but I never tested it. Well it turned out that the VB files I was generating were no good at all. Preview 3 has been fully tested and now created compiling VB files!

LINQ to Umbraco

That's right sports fans, I now have a working implementation of LINQ to Umbraco.

*cue applause*

Check this shit out:

HomePage home = new HomePage(1000);
var textPages = home.TextPages.Where(tp => tp.CreatedDate == DateTime.Now.AddDays(-7)).OrderBy(tp => tp.CreatedDate).GroupBy(tp => tp.Keywords);

(I used Lambda syntax cuz otherwise my formatting will be broken horribly).

What LINQ to Umbraco is and what it isn't

Ok, I need to make one thing clear, this LINQ to Umbraco implementation is not super clean. The current Umbraco API does not really support what I want to do, which means that I have had to have some hacks in place.

The first thing you'll notice if you have a look at the code is that it's not really optimised. There is no query language in the Umbraco API for me to use, which means I have to rely on standard IEnumerable extension methods.

So when you're accessing the child items you will be given all the items and then a filter will be applied.
Unfortunately there isn't a way around this, not in the current API at least.

That doesn't mean that this implementation isn't useful, it just means that if you're going into large child structures be aware that it may be slow and it may have a large memory footprint.

Additionally I (currently) don't support the saving of child items/ adding child items to Umbraco. So if you do get an item from the collection make sure that you call Save on it.
I am working on this and it should be ready soon for the next release.

But at the very least we now have an API for Umbraco which is fully LINQ enabled and completed .NET runable.

I really would love to solve the performance problem but I don't think that it can be done with the current API, not without a lot of ugly code.'



So if you want to check out Preview 3 make sure you grab the right one for your Umbraco: