Hire me at Go Tripod.

Gateshead Council Website Fail #2After yesterday’s post I didn’t really imagine that it’d attract the attention of anyone in the right departments – I guess I just assumed the problem would get fixed due to someone high up noticing it. What I didn’t imagine is that the problem would get replaced by another totally different issue:

Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Cannot create an object of type 'System.Web.UI.WebControls.Unit' from its string representation 'r_height' for the 'Height' property.

Source Error:

Line 1559: <div class="sys_news">
Line 1560: <div class="sys_standardrepeater">
Line 1561: <asp:literal visible="false" id="D2_Count" runat="server" text="0" /> <contensis_controls:dataviewdatalist id="D2" runat="server" repeatlayout="Flow" cssclass="sys_standardRepeater" height="r_height" repeatdirection="Vertical" repeatcolumns="1" shuffledataset="False" displaytype="SpanLayout" onupdatecommand="dlUpdateCommand" oncancelcommand="dlCancelCommand" oneditcommand="dlEditCommand" ondeletecommand="dlDeleteCommand" onitemcommand="Link_Data_Click" datakeyfield="PageID"><itemtemplate><% D2_Count.Text=cstr(clng(D2_Count.Text)+1) %>
Line 1562: <h2 class="sys_repeaterItemInner">
Line 1563: <%# CustomProcessing_D2(DataBinder.Eval(Container.DataItem,"newsHeading"),"newsHeading") %>

What sort of process is in place to allow a developer to replace a known failing page with another failing page? Surely, knowing that the first version was failing you’d be double-eager to check the latest upload is working? Baffling.

Council Website Fail

July 23rd 2009, 4:45 pm in .NET, Personal.

My local council, Gateshead in the UK, recently had a notice on their website declaring that it would not be updated for two weeks as they were performing essential maintenance. This was WTF number one – I have no idea what happened behind the scenes to make them buy this nonsense but it smacked to me of technical incompetence. What do I know though – like I say, there could have been valid reasons for this decision and it’s really not that big a deal.

So today I went back on their website and it seemed to be up and running with some new updates. I hit the News section to see this message:

Server Error in '/' Application.

Compiler Error Message: BC30569: 'New' cannot be used on a class that is declared 'MustInherit'.

Source Error:

Line 341: DataviewObject(component).GetData
Line 342:
Line 343: Dim RSSWriter As New CMS_API.WebUI.WebControls.BaseRSSFeedWriter
Line 344:
Line 345: Me.Controls.Add(RSSWriter)

Source File: E:\websites\www.gateshead.gov.uk\Council and Democracy\news\home.aspx Line: 343

Ouch. This brought down the page with a bang, no decent error handling. What’s the problem? It looks like someone’s been trying to set up the RSS feed for that page but has used an abstract class instead of the concrete one. Fair enough, that’s a simple mistake but surely WTF number two is that this could be pushed to a production server?

A good provider would have a local test, a staging server, and then production, at the very least. It looks to me like this change has been pushed directly to the site without any kind of quality control.

A possible WTF number three arises when you think again about the error message in general, which should only be shown when debug information is available. This could mean that debug settings are enabled on the web server, which is a definite WTF. Showing any kind of information like this – such as drive names and file paths – probably isn’t a very good idea.

I wouldn’t really care if this was just some corporate website but I know that my tax has gone into the development of this system and it’s painfully clear that the developers are not up to the job. Are open bidding systems in place for this kind of contract? I don’t know, but I bet that even if they are they don’t go on merit. Gateshead Council: shame on you. Can I get a refund? I can certainly recommend so decent software companies with local ties:

http://www.plastiscenic.co.uk/
http://www.gotripod.com/

Fizzler Used to Style WPF

March 11th 2009, 7:33 pm in .NET, CSS, Fizzler, Projects, WPF.

After I wrote Fizzler in a burst of development enthusiasm a few months back, it’s been sat on Google Code – a solution in need of a problem to solve. That is until Colin Eberhardt emailed me to report a bug in the selector engine, and to talk a bit about the way he was using Fizzler when working with WPF. This was totally outside the domain I’d anticipated Fizzler being use in, and Colin E has now revealed his project in full. By wrapping part of Fizzler in a few interfaces, thus abstracting it away from HTML and towards a more general purpose solution, he was able to use it to query a XAML UI definition and apply style declarations. CSS selectors for WPF!

This is an amazing use case for a library which I hope will start to see more use in the future. Thanks to Colin E for letting me know about the work which Scottlogic are doing with Fizzler.

Easing NHibernate Development

January 27th 2009, 1:27 am in .NET, C#, NHibernate.

NHibernate is now my framework of choice for working with a relational database. With a little bit of knowledge and a willingness to research, it’s pretty straightforward to make NH jump through whichever hoops you need it to. That said, there are certainly a number of friction points which can slow down any development effort. Mostly, these can be solved with a couple of tricks and tools which can be applied at various stages of a project.

Fluent NHibernate is a method of cutting down on XML mappings which are commonly associated with NH. While in the past, tools such as ActiveWriter have enabled developers to bypass the most laborious parts of creating mappings, Fluent NH takes it a step further and provides a strongly typed means of setting up your entity mappings without even touching XML. You can either use the auto mapping facility or fully customise the mappings, but it’s all done with full intellisense support and a serious lack of angle brackets.

Once the mappings have been defined – either in XML or in code – you need to start working with the database itself. NHibernate has a built-in facility which can help you out here, by generating the database schema based on your entity mappings. In fact, in the latest releases, you can even update the existing schema without having to delete and recreate, which makes it possible to preserve your test data during development. This allows you to go end-to-end from the mappings direct to the database and keep in that context throughout the development process.

Here’s a quick aside: some of the criticisms put against ORMs are that a developer with great SQL knowledge can tweak and craft code better than any autogenerating tool. From my point of view, every query would have to be written to a high standard, all column choices would have to be perfect every time. NHibernate’s generated code has been reviewed by experts and it will be produced in the same way time after time, to the same level of quality.

With that in mind, I don’t really have a problem letting NH control every part of my database interactions. What I do need is a way of ensuring that if the mappings i’ve created are wrong, or are sub-optimal, that I have a method of finding out what’s going on. NH Profiler is a piece of software which has recently started a beta phase and hooks in to NH itself to provide real-time analysis of what queries and sessions are being used by your application. As well as reporting, it also provides suggestions if it detects sub-optimal behaviour. Lazy loading, for example, can cause some nasty performance problems if used incorrectly, so NH Prof can pick up situations in which it would be better to change mappings to specify eager loading.

Over the last six months, new features and community involvement have transformed NH from a great development framework to the premier ORM for rapid development teams. The bumps have been smoothed, and we can get on with leveraging the wonderful work of the NH team.

“Have you done any Windows Mobile development?”
“A tiny bit. Isn’t it just like Winforms but on a phone?”

And from such an innocent beginning, a world of pain did explode into my universe. Just like Winforms on a phone is it? What’s the difference between the Compact Framework, Smartphone development, Pocket PC development, Windows Mobile? So many terms! So little time!

Windows Mobile is the operating system, just like Windows Vista. The Compact Framework is just like the .NET Framework on the desktop. As for the difference between a Smartphone and a Pocket PC, well, you’ve got me there. I picked Smartphone because my device had phone functionality and it seems to be working so far. There are separate SDKs for each, so I assume there are some key differences which escape me. With Windows Mobile 6, the Smartphone and Pocket PC SDKs are now Windows Mobile 6 Standard and Windows Mobile 6 Professional, respectively. I think.

Actually I think the real difference in these is the templates for projects you create and the emulators you are provided with. Professional, or Pocket PC, provides emulators for bigger screens. Microsoft has this to say about the naming kerfuffle:

With Windows Mobile 6, we are revising our SKU taxonomy and naming to better align our brand and products with the realities of today’s mobile device marketplace. The historical form-factor based distinction between Windows Mobile powered Smartphone and Windows Mobile powered Pocket PC Phone Edition is blurring dramatically. We want our taxonomies and terminology to evolve to better reflect the evolution of the mobile device industry.

So in order to reflect the blurring of the mobile device form factors, they’ve changed from having SDKs named after the types of device to SDKs named “Standard” and “Professional”. Hmm. How about having a single SDK called “Mobile Device SDK” and allow me to pick the device dimensions from within my project on the fly? Back at the start of this tale, I assumed that picking Windows Mobile for development would allow us to target a range of different devices, large and small, and in fact I can do that. I can deploy my application to a Windows Mobile phone with a big screen and to one with a small screen. The SDK split seems pretty artificial with that in mind.

Naming conventions and confusions aside, it is nice to be able to write against a single API and deploy to any Windows Mobile device. Or it would be if it worked.

My bugbear here is with a particular class: CameraCaptureDialog. Take the Samsung Omnia for example. You can certainly pop up the camera using CCD.ShowDialog(), but can you retrieve the filename of the image you took? You cannot. That’s because the Omnia’s camera supports taking multiple images one after the other until you explicitly close it.

How about the HTC Diamond? Well that opens fine, and returns a filename too, but if you try and re-open the camera straight after processing the filename, to allow the user to take another photo, it fails silently and doesn’t show the camera. If you try and do the same thing with the HTC Touch, it freezes.

Part of the issue is that the Compact Framework leaves too much up to the manufacturers and doesn’t give enough control to the developer. We can set the resolution of the camera for example, but we have no shortcut of setting it to the maximum resolution available. If you try and set it to a resolution which is not supported, some devices reset silently to a much lower resolution.

Microsoft need to extend camera support for .NET developers and give a lower level of access. They need to push device manufacturers to adhere to the Windows Mobile APIs and be more precise in how they are specified. And they need to simplify and modernise their mobile development framework so that developers can be fully aware of all the options available to them.

At the moment, the Castle Project is actually host to a number of separate projects. Monorail and Active Record for example, work extremely well together but Monorail does not require Active Record; the same can be said for Windsor.

Previous releases of Castle have contained all of the child projects in one package. In future, this may not be the case. The Castle PMC have decided to split each project off, while still keeping them under the Castle banner. This has the immediate advantage than a Windsor release does not have to wait for a Monorail release, which is surely going to increase the mobility of Castle as a whole. While some sections may lag behind for a while, segments are free to move at their own speed.

It’s been a while since a full Castle release, and I feel that many developers wait for such releases before adopting a project. More frequent official versions of the Castle components could increase adoption and interest in the overall brand, which can only be a good thing.

A Confession : DataGrids

August 19th 2008, 11:41 pm in .NET, Personal.

At one point, nearly five years ago now, I not only used DataGrids…. I liked them. I’ve learned a lot since then, I recall thinking the other day that Microsoft must have had a bit of an off year when they decided to release a web development platform which pretty much relied on the client having Javascript available.

Have you made any claims in the past which you’d like to own up to now? Or do you think any of the current fads of today are going to look foolish in five years time?

http://weblogs.asp.net varies in quality quite a bit, but it’s worth being subscribed just so you always catch ScottGu’s postings. But recently I’ve noticed the Visual WebGui blog. This is effectively a product blog – every post since February is a promo for the Visual WebGui tool. Is this what weblogs.asp.net is about? Should posts like this be a regular feature in the content of this community web site? Is it really in the interest of the community at large? Andrew Stopford also has a blog there, and while he talks about MbUnit a lot, his posts never feel like they were written by a marketing department. He also speaks on quite a range of subjects, so his blog doesn’t leave me with a bad taste in my mouth in the way the Visual WebGui one does.

I guess posters can write whatever they like, but it seems like a waste to turn a good community into an advertising platform.

In my last post I discussed code reuse in the form of an abstract CrudController class: a means of providing create, read, update and delete actions for a given entity. In addition, that class provided the ability to work with an entity specification class to allow for filtered reads – which is just another name for search results.

I’m going to show C# code samples for building with a class like this, but you’ll have to fill in the gaps in terms of how you can work with it. The code to list entities is the most interesting and will demonstrate the concept best, so I’m going to focus on that. To begin with, let’s assume a very simple entity:

public class Post
{
	public DateTime CreatedOn { get; set; }
	public string Headline { get; set; }
	public string Body { get; set; }
	public string Username { get; set; }
}

So, to begin with we’d like to list Posts. A typical method to do so would be:

public void List()
{
    PropertyBag["posts"] = PostRepository.FindAll();
}

But remember that in my case, I’m trying to create a reusable method of doing this, and that I’m also going to be working with ExtJS which is going to consume JSON. So, I have the following class:

public abstract class CrudController<Entity>
{
	private IRepository<Entity> _repository;

	public void GetJsonList()
	{
		RenderText(
			JsonHelper.Serialize(_repository.FindAll())
		);
	}
}

public class PostController : CrudController<Post>{}

I need a shell PostController, but most of the action is happening in the CrudController, and I’m using the magic of Windsor and generics to make it happen. By passing Post as a type parameter to CrudController, Windsor will then give me the correct IRepository<T> to work with, and from there it’s a simple matter of fetching the list of Post Entities in the same way I did in the previous code sample. I want to get a JSON string back, so I’m passing that list to a helper to serialize to JSON.

The next step is to make this listing method a bit more flexible and a bit more powerful. I want to do a couple of things – paging, sorting, and searching. Here’s my new method signature for GetListJson:

void GetListJson(int start, int limit, string sort, string dir, EntitySpecification spec)

The arguments “start” and “limit” are for paging, saying which record I should start from and how many I should return. The “sort” argument tells me the column I should sort on, and “dir” gives me the sort direction. But what about EntitySpecification? Let’s show it in context:

public abstract class CrudController<Entity, EntitySpecification> where EntitySpecification : ISpec
{
	private IRepository<Entity> _repository;

	public void GetJsonList(int start, int limit, string sort, string dir, [DataBind("spec")]EntitySpecification spec)
	{
		spec.AddOrder(sort, dir);
		spec.FindAll(_repository, start, limit);
	}
}

public class PostController : CrudController<Post, PostSpecification>{}

As you can see, EntitySpecification is databound by Monorail; incoming parameters are passed to the specification to build up a criteria for querying, as described in Ayende’s search specification post. That means that I don’t have to explicitly handle searching in my CrudController at all, because it’s all handled by the EntitySpecification. A sample PostSpecification could look like this:

public class PostSpecification : ISpec
{
	private ICriteria _criteria;
	private string _username;

	public virtual string Username
	{
		get { return _username; }
		set {
			_username = value;

			if (value == null)
				return;

			_criteria.Add(
					Expression.Eq("Username", value)
				);
		}
	}

	public void AddOrder(string sort, string dir)
	{
		var order = (dir == "ASC" ? .Order.Asc(sort) : Order.Desc(sort));

		_criteria.AddOrder(new Order());
	}
	public IList<Post> FindAll(IRepository<Post> repo, int start, int limit)
	{
		repo.Find(_criteria, start, limit);
	}
}

When Monorail runs the databinder, the Username property’s getter will be called and the private criteria will be altered. When the specification’s FindAll method is called, that criteria is passed through to filter the returned records.

Let me know if you have any improvements or suggestions, and thank you again to Ayende for the specification ideas.

NHAML on Monorail

June 2nd 2008, 6:23 pm in .NET, Monorail.

Mirvoda Sergey has announced NHAML for Monorail. Andrew Peters brough NHAML to ASP.NET MVC last year, and now us Monorail users can enjoy using a very different kind of templating engine to the others available for Monorail. Check out this HAML tutorial if you’d like to familiarise yourself. Thanks to Mirvoda Sergey!

Next Entries »