Thoughts, Code, Other

Technical blog of Nik Smit

rainbow

exception hunter

Visual Studio 2008 continues to push the bar in terms of developer experience. As more of my colleagues and friends migrate (sometimes requiring telling their employers the upgrade is "esential" - an illusion they seem happy to play along with), the glowing reports continue. Personally I feel like a proud parent, having used every version of Visual Studio since its inception - its finally reaching out to its potential.

But no matter how good the tool (or platform), somehow the 3rd party ecosystem continues to innovate and "fill in the blanks" where Microsoft missed bits, or more likely didn't have the time to get to before RTM.

A lot of people are familiar with the brilliant Resharper from JetBrains - the side-kick to C# that once you try, you'll wonder how you ever did without it.

The one I'd like to call out today has just been released from redgate software. They're a small Cambridge, UK based company that you may know for Sql Prompt, which brings intellisense to sql scripting interfaces. Incidentally, redgate have a great poster at Cambridge rail station, trying to tempt developers away from London :) Clearly its working, as their product suite seems to be growing pretty quickly.

Exception Hunter is their new tool that I wouldn't be surprised to find in VS.Next. This has happened before - functionality found in their ANTS Profile tool is now in VS 2008 - vendors play a cat and mouse game with MS in this respect and most continually innovate.

Exception Hunter promotes more stable code by allowing you to find the blindspots in your exception handling. Since .Net 2.0 this has become even more important, with unhandled exceptions now bringing down the entire application (previously the behaviour was more undefined). If you can afford their license (seems a tad steep to me), it would be a great tool to run in conjunction with fxcop before releasing your app into the wild. Find a video demo of the tool here.

Dynamic data bliss on the way?

Sometimes being a developer means you're too close to the problem. If you've ever had a non-developer watch you develop a basic site that allows CRUD access to a database, no doubt it will seem like a LOT of work. Many developers are not against this notion - it aids job security. The honest truth is that until their is a quantum leap in artificial intelligence, there will always be a strong need for developers, no matter how good the tools become. Abstracting away the plumbing as much as possible (and letting it be implemented and tested in one place) is a very good thing.

Today the ASP.Net team released a new preview of the 3.5 Extensions. Here's a copy and paste of what's in it :

ASP.NET MVC

ASP.NET MVC provides model-view-controller (MVC) support to the existing ASP.NET 3.5 runtime, which enables developers to more easily take advantage of this design pattern. Benefits include the ability to achieve and maintain a clear separation of concerns, as well as facilitate test driven development (TDD).

The ASP.NET MVC Toolkit provides HTML rendering helpers and dynamic data support for MVC.

ASP.NET Dynamic Data

ASP.NET Dynamic Data helps developers build a fully customizable, data-driven app quickly. It provides a rich scaffolding framework that allows rapid data driven development without writing code, yet it is easily extendible using the traditional ASP.NET programming model.

ASP.NET AJAX

New additions to ASP.NET AJAX include support for managing browser history (Back button support).

ADO.NET Entity Framework

ADO.NET Entity Framework is a new modeling framework that enables developers to define a conceptual model of a database schema that closely aligns to a real world view of the information. Benefits include easier to understand and easier to maintain application code that is shielded from underlying database schema changes.

ADO.NET Data Services

ADO.NET Data Services provide new services that find, manipulate and deliver data over the web using simple URIs. Benefits include an easy and flexible way to access data over the web, while enabling the separation of presentation and data access code.

Silverlight Controls for ASP.NET

You can integrate the rich behavior of Microsoft Silverlight into your Web application by using two new ASP.NET server controls: a MediaPlayer server control that enables easy integration of media sources such as audio (WMA) and video (WMV) into your Web application, and a Silverlight server control that allows an ASP.NET page to reference both XAML objects and their event handlers.

The features I want to call your attention to here are Dynamic Data and Entity Framework. Both of these promise to drastically reduce the effort required to manipulate and display ith data in our applications. In some scenerarios the effect will be very impressive, allowing us to focus more on creativity and business logic, less on the mundane (but essential).

The dynamic data controls in particular are extremely impressive if you've never seen them, allowing you to produce webpages allowing CRUD access to your db tables, without a single line of code, or indeed even an aspx file!

Be sure to check them out.

More info :

linqpad

Ryan put me on to linqpad - a tool that allows you to query your sql DB directly, using LINQ! This is a great way to learn LINQ if you're doing so - the constant everyday use of LINQ for your normal db query chores will cement the new language's syntax in your head. Goodbye query analyser / SQL Server Management Studio!

Visit the linqpad homepage for more info

Make ASP.Net controls implement modern layout principles

One of ASP.Net's greatest strengths is surely its built-in controls. With each iteration of the product their features expand, and they do their bit towards programming's greatest goal :

Reducing the plumbing, increase the productivity.

Microsoft generally also does an excellent job of facilitating "drag-n-drop" component use, while still allowing the developer to customise behaviour, layout and so on.

So it was that recently I wanted to use the Menu component, for this site actually. Up until now for some reason I've always used 3rd party tools (such as ComponentArt's Menu), or rolled my own. So there I was thinking this would be easy - declare a <asp:menu> object, assign it a sitemap, a bit of CSS assignment, and be on my way.

It was not to be.

Unless you've been asleep at the wheel as a web developer for the last couple years, you'll know that using table elements for layout is frowned upon. For very good reasons. Tables are fine for tabular data, but sites are more flexibile and resiliant to change when layed out in CSS. (Check out this link for help with migrating your site from tables).

Plus, if you're using a CSS template (I know great design when I see it, I leave it to the designers to come up with it!), like those available here, you'll want to be emitting clean CSS so that you can mark it up easily with your chosen template.

Unfortunately, some ASP.Net still produce table layout code, and Menu is one of them. How to solve this conundrum? Check out the ASP.Net 2.0 CSS Friendly Adapters. These adapters plug into the ASP.Net controls

  • ChangePassword
    CreateUserWizard
    DataList
    DetailsView
    FormView
    GridView
    Login
    LoginStatus
    Menu
    PasswordRecovery
    TreeView

and cause them to emit nice clean divs, while not requiring any code changes on your part. This is done using ASP.Net's "control adapters" which allow you to override, modify and/or tweak the rendering output logic of any ASP.NET server control.

Problem solved! Almost....

The css class the control uses (after being adapted) for the selected menu item is AspNet-Menu-Selected. This overrides any settings related to the style of the selected item you may have set on the menu. Which is fine normally, you can go ahead and alter that css style in the supplied css file to meet your own needs, but as I said, my goal was to plug in a provided css template, with its own style.

In other words, I still wanted to be able to say : StaticSelectedStyle-CssClass="myTemplateStyle", in the Menu's declaration.

One quick change to MenuAdapter.cs, and we're done :

 
private string GetSelectStatusClass(MenuItem item)
{
string value = "";
if (item.Selected)
{
value += " AspNet-Menu-Selected";
 
Menu menu = Control as Menu;
if (menu.StaticSelectedStyle != null &amp;&amp; !String.IsNullOrEmpty(menu.StaticSelectedStyle.CssClass))
{
value += " " + menu.StaticSelectedStyle.CssClass;
}
}
else if (IsChildItemSelected(item))
{
value += " AspNet-Menu-ChildSelected";
}
else if (IsParentItemSelected(item))
{
value += " AspNet-Menu-ParentSelected";
}
 
return value;
}
 

You are currently browsing the Thoughts, Code, Other blog archives.