Positioning the ASP.NET MVC Framework

Thu, March 20, 2008, 07:19 PM under Links
In the latest issue of the MSDN Flash, ScottHa wrote an article that, in my opinion, perfectly positions the ASP.NET MVC Framework. Read the 500 words here (scroll down).

UK 2008 Launch resources

Thu, March 20, 2008, 07:13 PM under Events | Orcas
On Wednesday we had the 1-day free multi-track event in the UK to celebrate the launch of Visual Studio 2008, Windows Server 2008 and SQL Server 2008.

The Windows and SQL tracks basically took the identical slides/demos from the US launch and found local speakers to deliver them. The benefit of that is that the content is not a million miles from the UK Virtual Launch site (which has the US recordings).

For the Visual Studio track I specified session titles and abstracts for 8 complementary developer sessions and "recruited" top speakers to deliver it. If you were there and need to contact the speakers for resources here are links for finding them: Guy Smith-Ferrier, David Gristwood, Andy Wigley, Michael McClary, James O'Neill, Amanda Silver, Mike Taulty, Mike Ormond and mine.

Five VS2008 Smart Client features

Thu, March 20, 2008, 07:10 PM under dotNET | Orcas | VisualStudio
I have created a Smart Client session that I am repeating at various events and it is basically 5 demos. If you attended that session and heard me refer to my blog for more detailed videos of the 5 things, then please find the list below:

1. WPF and WinForms Interop: blog, screencast.
2. Managed AddIn Framework: blog, screencast and code.
3. Client Application Services: blog, screencast and code.
4. ADO.NET Sync Services v1.0: blog, screencast and code.
5. VSTO v3.0: blog and screencasts.

In addition to those links, when people ask me about other Visual Studio 2008 resources I always point them to the Top 10 and they are happy so hope you are too :)

DDS: attend my Parallel Extensions talk

Mon, March 17, 2008, 04:02 AM under Events
There is a great agenda of sessions for the Scottish Developer Day (DDS) in May and I hope you'll choose to come to my session on Parallel Extensions. Register here.

Use of Silverlight at Tech Ed US site

Mon, March 17, 2008, 03:59 AM under Events
Tech Ed in Orlando is in June and I have a couple of sessions there (more on that nearer to the time). I like how they used Silverlight 2 to list the speakers (although the z-ordering is not as accurate as I was expecting it). Give it a go, have a play.

Decompiling Silverlight 2 Apps – Enter the XAP

Sun, March 9, 2008, 10:40 AM under Silverlight
When you build a Silverlight 2 application, you compile your source files (inc. XAML and embedded resources) into assemblies (dlls). Those assemblies (plus any 3rd party ones plus MS assemblies that are not part of Silverlight) are then collected together along with a manifest into a packaged archive – or in other words, a ZIP file. Except, the extension is changed to be a .XAP (pronounced "ZAP"). The benefits of packaging everything into a XAP should be obvious but in case they are not, Pete has discussed that on his blog (inc. screenshots). Note that if your web server is on IIS (prior to version 7) you need to register that MIME type. As an aside, my web server happens to be Apache (shocking I know!) and I had to configure nothing – it just worked.

So, if I had given you a Winforms EXE file you wouldn't ask me for the source code, you would probably just pass it through your favourite decompiler and you've got it all. Same with Silverlight apps: if I point you to my web page that is running a Silverlight app (e.g. the one from this post) all you have to do is:

1. View HTML source, e.g. for this: http://www.danielmoth.com/SL/HtmlBridge/index.html

2. Locate the tag that points to a XAP file and copy the full path, e.g. ClientBin/DemoIntegration.xap

3. Use that path to "Save As" the xap file locally.

4. Rename the XAP file to ZIP and explode it to get the DLLs inside.

5. Party away by tossing the DLL(s) to the decompiler, e.g. Reflector.

Obviously authors of serious SL apps may not condone that behaviour, but feel free to do it with all of mine, for example the DeepZoom/MultiScaleImage that I have now updated to also use mouse wheel.

Silverlight Browser Integration aka HTML Bridge

Sat, March 8, 2008, 11:12 AM under Silverlight
Given that Silverlight applications sit in the browser via a plug in, it would be silly if you couldn't interact from managed SL code with other browser elements, such as html elements and script so that you could, for example, reuse existing assets. I have heard the browser-agnostic integration featured described as HTML Bridge and it is implemented in the System.Windows.Browser.dll assembly in a same named namespace. You can see the types from that namespace on the following image (click on it for the expanded version):

The important inheritance hierarchy to be aware of is that HtmlDocument and HtmlElement inherit from HtmlObject (that allows handling script events via AttachEvent) which inherits from ScriptObject (that allows you to execute scripts via its Invoke and InvokeSelf methods). HtmlPage is a great entry point because you can navigate across its Window property to an HtmlWindow (that allows e.g. to Navigate URLs) and across its Document property to an HtmlDocument (that offers e.g. access to Cookies and QueryString). Also note the 2 Attribute classes: ScriptableType and ScriptableMember. Those are used for exposing Silverlight managed classes to script in the browser combined with HtmlPage.RegisterScriptableObject and RegisterCreateableType methods. Open the expanded class diagram in a separate window and identify the aforementioned methods. Notice there how HtmlDocument allows you to create new elements and retrieve existing ones (CreateElement and GetElementById). Once you have references to those HtmlElements you can do things like SetAttribute, SetStyleAttribute and AppendChild to name a few. Script events are handled in your managed ScriptEventHandler method that accepts an HtmlEventArgs which you can find on the class diagram along with its relationships (e.g. MouseButtons). You should also checkout the HttpUtility class and its self-explanatory methods such as UrlEncode.

Phew! Take a moment to study the two class diagrams using the previous paragraph as a guide and also note that all links above are direct links to the API documentation (i.e. this blog post becomes my bookmark into MSDN ;)). You can also follow a quickstart (DOM access), two walkthroughs (calling managed from script and script from managed), and for those that want even more, follow this 2-hour lab (ZIP).

To see some of the browser integration in action, I have here the ugliest and most basic SL app that simply proves some of the concepts.

Class Diagram item template missing from SL projects

Fri, March 7, 2008, 10:13 AM under Silverlight
It is a well known fact that I love the Class Designer that was introduced in VS2005 and I had fed back a lot during its early stages (good and missing). This is the tool I use to explore any new library/framework that comes out before dropping to the code editor to really play with the API (btw, that answers this FAQ I get when people talk to me about this job).

So I did the same for Silverlight 2 Beta1 and noticed that the option to add a "Class Diagram" was not there! These are all the item templates a Silverlight project will offer:

Some overzealous filtering took place there IMO. I see no reason to omit it since the CD is reflection-based and can hence handle any .NET library. Anywho, all is not lost as you can right click on any code file in Solution Explorer and select "View Class Diagram" from there. Panic (and trivia) over.

Session 0 Isolation

Fri, March 7, 2008, 03:58 AM under Windows | Vista | WindowsServer2008
In the latest issue of the MSDN Flash we introduced 2 new features: a poll (you'll see the results in the next issue) and the ability to have a non-MS person write the 500 word article. Kenny kindly accepted the challenge and he wrote a great article on a security topic that may affect your code on Windows Vista and Windows Server 2008. Read it here (scroll down).

MultiScaleImage with mouse support-ish

Thu, March 6, 2008, 07:13 AM under Silverlight
One of the demos that captures people's attention with some Silverlight 2 demos is the Seadragon-based technology that in Silverlight is called "DeepZoom". To see a good example of that in action look at the Hard Rock Memorabilia site or visit the Vertigo site (the guys that built the HR experience). The control behind all that is the MultiScaleImage control. You need to point the Source property of that to the output you get when you use the DeepZoomComposer tool. The tool basically takes an image and chops it up to more download-friendly bits that it distributes to folders.

My colleague MikeT had a play with it all and has a quickstart on his blog. One of the downsides of that approach is that it uses the keyboard for panning around and zooming. I thought I'd take that and try to offer navigation (left/up/right/down) via dragging the mouse and also zooming in by clicking the mouse. To zoom out, I had to keep with using the keyboard (Spacebar was my choice). Assuming that you have the Silverlight 2 runtime installed, the results are here. The source is work in progress but should anyone care about it too much I can share.

It was actually more work than I anticipated. Detecting mouse movement is easy, but making it scroll half-sensibly dependent on how zoomed in or out it is, and also to vary the drag speed dependent on how aggressively the mouse is moved was not as straightforward (to me). My example also doesn't really make as a good sample because I used an image that isn't sufficiently large or deep. To truly experience the beauty of the control, please visit the links at the top.

If you visit the links at the top you will also find that scrolling is much more natural because in addition to mouse clicking for zooming in, the mouse wheel is also used. Mouse wheel events are not directly supported in managed code and require javascript assistance. There is a sample that shows you how to do that on mharsh's blog (but it doesn't include the panning and zooming on click).

So if you aggregate all the sources of information I list above, you can come up with the complete sample ;-).

MIX08 Keynote Announcements

Wed, March 5, 2008, 01:16 PM under Links
If you missed the keynote (live in Vegas or online), Tim Sneath was updating his blog live for it so you can read an outline here.

- You already know about ASP.NET MVC Preview 2 form my previous blog post.

- Many Silverlight 2 Beta 1 related downloads – Guy had all the links here before anyone else I think. You'll be hearing a lot more from me on that technology on this blog so stay tuned...

- Internet Explorer 8 Beta 1 is out with unprecedented standards support. Choose the most appropriate download for you.

- There were many other announcements (such as Silverlight for Windows Mobile and Nokia) but nothing that we can actually get our hands on right now.

One of the most impressive keynote demos was actually not appreciated as much as I thought it would be (judging from audience reaction... maybe it is the wrong crowd?). Hardware accelerated performance improvements in WPF. The application was doing all kinds of crazy 3D effects and the CPU utilisation in task manager was barely moving! I can't wait to get my hands on that when it is released in the summer. Move the thumb of the video to 02:08:10 to watch it...

ASP.NET MVC Preview 2

Tue, March 4, 2008, 07:24 PM under Links
UPDATE: It went dead for a while but now it is back - same URL ;-)

Just spotted the ASP.NET MVC Preview 2 download. Three things to say about the subject in reverse order of importance:

3. I'll be doing half a session on this in Newcastle in May (but more on that closer to the time)

2. It is now separated out from the larger ASP.NET 3.5 Extensions package

1. You can go get it here.

The ABCDEFGHI of setting up Visual Studio for Demos

Mon, March 3, 2008, 02:16 PM under AboutPresenting
Following on from the tips on how to setup your laptop for demos (with some great ones from you in the comments!), I thought I'd follow up with how to setup Visual Studio specifically.

Whilst the language I use below is prescriptive as always, please note that I am far from an authority so all I am doing here is sharing my views. I'll start with 2 that I know are controversial and then move on to a mixture of mainstream points with a couple tips that I suspect most of you have not come across before.

A) Don't change colours; don't use "themes". Use the default settings.
I've been in presentations where the presenter puts a lamp of code on the screen and I am trying to compile it in my head except all the stuff I am familiar with has changed: default colours of types, keywords, comments, strings and even code editor background! "Why would you ever do that to the audience? Why do you hate them so much?". To be clear, it is fine for you to "pimp your IDE" for working purposes. However, when showing dozens (if not hundreds or thousands) of other people a demo using Visual Studio, what is the lowest common denominator that you can assume about them? Answer: that they are familiar with the default settings of Visual Studio. Unless your goal is to prove how smart/artistic you are, instead of trying to make it as easy as possible for them to follow your code, please take heed.

B) Leave the 3rd party productivity addins at home.
In case you are not familiar with them, there are 3rd party enhancements to Visual Studio (such as resharper, coderush, codesmith, visualassist, [insert your favourite here], etc) that can truly increase your productivity multi-fold. However, recall from point A above that the majority of your audience will not be familiar with them. When we show code during a demo, all effort from the audience should be concentrated on understanding the API/pattern that you are explaining and not be distracted by seeing menus they are not familiar with and being confused by how you managed to accomplish something with a shortcut that they never heard of before. Unless, of course, you are actually an evangelist for those products and/or you need the productivity boost during your demo because you are coding it for the first time instead of having rehearsed what you are showing. Do you really want your attendees coming out of your session and talking about how they enjoyed learning about one of the said products, instead of walking out with the intended take away that you had in mind?

C) Use large enough fonts everywhere.
Don't wait for the audience member to shout out to you to enlarge your fonts. Go to Tools->Options->Fonts and Colors and change the "Text Editor" font to at least 14 (and for some rooms 16). In fact, when you reach the room you are presenting in, launch Visual Studio and go seat on the last row of chairs starring at the projector; can you read your code? Furthermore, change the font for things like Tooltips, the intellisense window and all the other "Tool Windows" (hint: look at the top combobox with the label of "Show settings for:").

D) Change your highlight colour for selected text.
This is my only rule that goes against A above. Simply put, if you leave your "highlight" as the automatic default of "Blue", your text is not visible to the audience – not sure why people don't get that. You are having the opposite effect of your goal when you highlighted that piece of code. So, as per the instructions of C above, find the "Selected Text" and change the "Item Background" to "Yellow". FYI in the past I used "Lime" but I have found that some projectors show lime darker than what it is on my screen, so I have switched back to yellow.

E) One docked tool window.
I've seen demos where the presenter had multiple docked windows on all sides. How much of the code in the editor is viewable at any given time at 1024x768 resolution at 120 DPI? Every demo you do will have different windowing requirements, but in my experience I have never needed more than one side for docked tool windows (for me that is on the right, but right or left is a mute point IMO). Of course, I'll bring out a tool window from the other side (on the left for me) and also from the bottom but they are set to auto hide so they get used quickly and then disappear. You may also be tempted to autohide all tool windows but in most demos I find it useful to have solution explorer always visible because attendees can easily glance at it during the demo to remind themselves of the big picture (instead of viewing just a single code file). Regardless, windows that are set to autohide but are never used during a demo should be closed/exited instead – what is the point of having tool window tabs(=clutter) in the IDE if they are not going to be used? TIP: for prebaked demos, you can layout all the tool windows (dock/autohide/close) and then save/close the solution and the next time you open it you'll find them all in the right place!

F) Two toolbar rows; for all documents.
Again, this has to do with space-saving and with clutter removal. You may be tempted to get rid of the toolbars completely but, not only that looks weird (recall the point on familiarity), but I actually use the toolbar for some actions instead of using keyboard shortcuts so I can make very obvious to the audience what it is I am doing. I doubt there is any demo that requires more than 1 row of toolbars, but in the interest of familiarity I leave the first toolbar appear as it does with default Visual Studio settings and then customise the 2nd row to match whatever my demo(s) require – so I always have 2, no more no less. You may find that when you switch between document types the toolbars "dance" around so you must make sure you preserve the height (i.e. the 2 toolbar rows). For example, you open a Windows Form in code view and you have 2 toolbars showing but when you switch to design view then one of them (annoyingly) disappears – it is down to you to enable another toolbar for design view too, so as to preserve the overall toolbar height when switching between documents.

G) Tab Size = Indent Size = 2 spaces.
There are religious arguments between developers as to whether the editor should be using spaces or tabs (for indentation). There are also disagreements on whether the correct number of spaces (or tab size) for an indent is 2 or 4. I have little interest in opening that debate and when you are developing at home, do as you please. For presentation purposes though, you must eliminate horizontal scrolling (I hope that is an axiom and hence I don't need to prove it) and given that you are running with large font at 1024x768 at 120 DPI, guess what is a low hanging fruit? That's right, make the Indent = 2 spaces and you've just saved yourself a ton of white space and with it unnecessary h-scrolling. You can make this change from Tools->Options->Text Editor->[Your language]->Tabs.

H) Remove namespace declarations.
This one is along similar lines to the previous item – saving horizontal scrolling and unnecessary white space. For most prebaked demos, there really is no reason to have a namespace (which gets generated by default in C# code files). So simply go and remove them all and save yourself another 2 horizontal columns per file e.g.
namespace MyNamespace   // delete this
{ // delete this
class MyClass
} // delete this
...and then hit Ctrl+K,Ctrl+D to reformat it all nicely.

I) Maximise, in more ways than one.
I kid you not; I have been in a session where the presenter did the whole show without ever maximising Visual Studio! I was this close (imagine me holding my thumb and index finger close together) to getting up on stage and hitting the maximise button of Visual Studio to occupy the whole screen. Besides that obvious advice, what helps with some of the goals of some of the items above is to maximise the code editor (Shift+Alt+Enter) at opportune moments, especially if you are going to spend a lot of time in one code file.

There are other things that I do in Visual Studio but I don't want to go through the entire alphabet here ;-). For example, I am such a strong believer in "including" as much of the audience as possible and not appearing biased, that when I first run up Visual Studio after installation, I select General Settings (instead of C# or Visual Basic).

Do you agree with all of the above? Do you vehemently disagree with some of it? How do you utilise Visual Studio for demos? I look forward to reading your comments below...