This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on http://www.jameschambers.com/.

Thursday, December 24, 2009

Visual Studio 2010 Wishlist

It’s Christmas and so here’s a short list of things that I am asking Santa to bring me for Christmas (or in the March CTP) for the next build of Visual Studio 2010.

More Collapsible Regions

I would think this one would be easy enough because there is an implementation built in at a higher level.  Let’s also have the ability to collapse whiles, ifs, foreaches, switches and the like.

Collapsible Selections

I would like to be able to highlight a block of code and have that highlight turn into a collapsible region.  We are given collapsibles on certain blocks of functionality (methods, classes, comment regions) and if my first wish is granted than on other constructs as well, but not on selections.

While this is good:

image

…allowing me to collapse this would be even better:

image

…and by putting a image in the margin the team should be able to use the existing functionality they’ve implemented.

Intelligent Collapsible Regions – With Style!

Okay, so what if we could get those selections and regions collapsed?  We’d also like a way to preview those hidden bits, right?

Thankfully the editor is written in WPF now, so this shouldn’t be much more work than creating adorners for the collapsed hints.

And while they’re already doing it to some level (hover over the ellipses on a collapsed region) it is grey, without syntax highlighting and in a non-fixed-width font.  Let’s jazz it up.  In fact, let’s have two views: the first would reveal comments in the /// style and then an expander would animate open to reveal a little code browser.

There has got to be an intern working on the IDE team that could use a project like this as a learning experience ;o)

Code Browsing

Since we’re talking browsing, let’s hit my last item on the list for today: an alternative way to browse code.

If you don’t write them yourself, you likely work with someone who does: long code files.  I have a big monitor, so I am able to fit about 55 lines of code onscreen at a time.  But many of the classes I work in are 200+ lines of code (especially any DAL work). 

Other scenarios where traditional code browsing techniques break down are in tool-generated code.  When you’re looking through a LINQ to SQL generated class there can be literally thousands of lines of code.

Getting your head around ‘where’ you are in the file is not easy to do.

But what if you had a thumbnail view of the code?  That thumbnail could have highlighting for keys that you select in the legend. As you hover over the miniature version of the class, you get tooltips that reveal method names or a preview of a comment.  Clicking on the ‘map’ would take you to that place in your code.

There are about 100 different things you could implement in that, some of which would even be useful.

Or a Lump of Coal

image Visual Studio 2010 (I’m on Beta 2 as I write this) is loaded with treats and it runs fast…and the IDE team has already promised better performance in the next build we see.  If all I got for Christmas (even if it was a late gift) was a release copy of VS2010 I’d be a happy kid.

The .NET Framework 4.0 is a game-changer, and you’ll need Visual Studio 2010 to get in the game.  As the various parts of IDE continue to evolve, things like browsing code or manipulating the view of your code will become more and more integrated with your flow of development.

And when you see the above features show up, you can send me a Christmas Card. ;o)

Merry Christmas to everyone.  May you be blessed with the Joy, Peace, Love and Hope that this season was intended to bring.

Wednesday, December 23, 2009

Getting Started with Workflow Foundation 4.0

I am working in Visual Studio 2010 Beta 2 with Windows Workflow Foundation 4.0.  Generally speaking, it is a little easier to get around, the designer is more straightforward, the samples are fairly complete but documentation is lacking in some areas.

There is also very little by way of best practices, and I haven’t fully explored the pros/cons of the samples that Microsoft has put forward, but I am working through them and trying to get my head around this space.

Here are some sites that can help you get started:

WCF and WF Samples for .NET Framework 4.0 Beta 2

MSDN Discussion Forums for Workflow Foundation Beta 2

The Problem Solver blog on persistence and other things WF

I highly recommend the samples if you’re interested in WF; if you’re running Visual Studio 2010 they all load/compile relatively easily and some of the examples are fairly comprehensive.

As a tip, make sure you compile the application prior to loading the WF designers in the samples.  I have crashed VS.NET’s designer and hung the IDE once so far by trying to drill in prior to compilation.

Monday, December 21, 2009

A Really Useful Search

Raven’s web-based administration and CRM module got a big upgrade in its search capabilities with last Friday’s build.  For reasons of simplicity and time-to-integrate, the first builds’ search capabilities were based off the legacy application’s model of defaulting to a customer name search and using a combo box to change what you’re searching “against”.

Searching for Business Return

The first implementation wasn’t without its smarts, however; I built in some metrics to determine what users were actually searching on and discovered that last name searches were only used about 10% of the time, and of all the fields used to search against (27), there are really only 8 things people use to find customers (and Account Number would have been a better default).

I took those results and went to speak with the users about their search experience.  It turns out that most of these search techniques were learned because of how they found customers in the legacy system.  Depending on what you were going to search for, you could be as many as 8 clicks away from a customer record in that app, so they have even mentally trained themselves to pattern searches in the easiest way the software works, not necessarily what they have for information at hand.

Also, for the most part, there was a common problem with how they searched for things and where they had to go to do so.  Rather than focusing on the task the user would try to execute on a daily basis, the software was organized into groups of data that were related on the database.  The search for customer was in a different spot than the search for a tower.  Could you imagine if Google had a different page for each search topic?  Beyond that, the summary information returned from the search was only useful to confirm the result was what the user was looking for; users had to drill into multiple results and then back out if they didn’t find what they were looking for.

Goals for Improving Enterprise Search

There were three major things I wanted to accomplish:

  1. Infer the search type based on the user’s input.
  2. Increase the relevancy of the information returned.
  3. Provide search access from anywhere in the application.

I’ll start with three.  It was the last thing on the stack.  ;o)

I took a bit of a shortcut on number three and have spent the least amount of time on it, but it is still an improvement over the legacy system.  All I’ve done here to-date is incorporate a dashboard system and an easy way to get back to the dashboard from anywhere in the system.  At the top of the dashboard is the search bar, which has focus on page load.  Users are now two clicks away from seeing their search results from anywhere in the application.

Popping off the stack, we’ll discuss number two next: search result summary.  I have to admit on this one I’ve taken a bit of a cue from the major search engines.  You know how if Bing thinks you’re looking for videos, it will show you a few videos?  Or if you search for something that seems like an image on the main Google search, it will show you a few image results?  Well, I took a bit of that approach.  If a user is searching for a tower, they don’t need to see a phone number or street address, they want to see number of customers on that tower, and the status of that tower.  Likewise, if they are searching for a customer, there are certain pieces of information that are more relevant to the user. 

I even took that one step further, because the role of the user influences the styling and information contained in the search result.  For example, an account manager is likely looking for contact information and contract details, whereas a help desk technician is looking for recent tickets and the current status of a customer’s connection.

That accomplished, I needed to tackle number one on the list: inferred search type.

This turned out to be a lot easier than I was expecting.  I have written a series of regex expressions to identify the kind of search a user is performing and compiled them to a DLL.  I pass the search string into a method which returns the appropriate search provider and takes care of building queries, LINQ to SQL or calls to stored procs (depending on the system I am accessing).

To tie one and two together, I use the search provider to return a function mapped back to a controller, which then executes the appropriate build and bind sequence for the result list.  This is done through AJAX/jQuery and the MVC framework.

Acceptance?

It’s different.  It isn’t what people have been using for the last eight years, so I expect some friction. But a big positive is that everyone agrees it’s faster and I’m getting all kinds of suggestions for things to add, which means they’re using it (and are interested enough to see it move forward)!

For the time being, the legacy application is still the workhorse in the enterprise, but I’ve now created a bridge from Raven into that system.  What users have now is the ability to search much more quickly and then use the bridge to link into the old system, hopefully that doesn’t prove to be a pain and over the long term it helps the users transition into Raven.

Friday, December 18, 2009

Easy Fix for Visual Studio 2010 Beta 1 Uninstall Problems

I had downloaded and installed Visual Studio 2010 and I’m pretty sure I do so via the web installer from MSDN Subscriber downloads.

As you can expect with beta software, it’s likely that there will be crumbs left all over the place while a vendor works out the kinks in the deployment/installation experience.

I had one laptop left that I hadn’t updated at home, and so moving to Visual Studio Beta 2 was tonight’s project.

Insert Disk to Continue

The uninstaller was looking for the EXE used to install “Microsoft Team Foundation Server 2010 Beta 1 Object Model”. Of course, if I used the web installer – which I think I did – I never would have had a disk.

On a different, unrelated issue, I found uninstall instructions for Visual Studio 2010 Beta 1 here.

I actually started the first step, fired up my screen cap to show that it was indeed working, and before the snipping tool kicked in the uninstall was actually complete.

So, here’s a gratuitous shot of the snipping tool in Windows 7:

image

If you didn’t uninstall the TFS Components first, you would have seen them in this list:

image

There are quite a few posts and random tidbits about machines becoming unstable with botched VS 2010 uninstalls.  I’m glad I ran into a snag before I got myself into trouble.

UPDATE: If you’re interested, the order of instructions worked flawlessly and Beta 2 is now getting installed.

Visual Studio 2010 Release Date Delayed

I think this is a really good call by the folks at Microsoft.  There was a huge jump in performance from Beta 1 to Beta 2, which I think allowed people to believe their feedback was being heard, thus making them comfortable giving more feedback.

The releases are here:

http://weblogs.asp.net/scottgu/archive/2009/12/17/visual-studio-2010-and-net-4-0-update.aspx

http://blogs.msdn.com/somasegar/archive/2009/12/17/visual-studio-2010-and-net-framework-4-beta-period-extended.aspx

Feedback Loop

As someone who has been actively participating in the Visual Studio 2010 Beta cycle, I can certainly vouch for their comments about listening to the users.

When I pushed a performance issue to a Microsoft-er, he wrangled in two other folks to help figure out where the problem would be.  We went back and forth for two weeks to identify and rule out some issues, then they got me to do a couple of performance profiles and send them in via secure upload site.

By the end of the process there were seven or eight Microsoft employees participating in the email chain and recommending different configuration settings, suggesting workarounds and requesting information about usage on the product.

A Different Microsoft

I entered my career in the development world as a snot-nosed teen, lovin’ Torvalds and putting the big hate on for “Micro$oft”.  I started to tinker with the first bits released for .Net and quickly got hooked. 

I understood and believed many of the criticisms of Microsoft in the 90’s, but the company has changed.  The way that they responded to my performance concerns in Visual Studio 2010 shows a level of commitment that I have not seen with anyone I pay money too; not my vehicle manufacturer, not the builder of my house, not any of my household appliances.  Call Apple and ask them to fix something on your iPod and see how far you get.

If you complain about the things you don’t like about Microsoft and you haven’t given them a chance to fix them, you have to drop the chip on your shoulder and get involved in the beta cycles.  I’m using VS2010 daily, sending emails, participating in forums, submitting feedback and blogging about things I’d like to see. 

Heck, I’m a programmer and Visual Studio 2010 was my idea.

;o)

Wednesday, December 16, 2009

VS 2010 – Validation Warnings in ASP.NET

I was getting a whole host of errors on even the simplest of web pages or components (aspx or ascx) in Visual Studio 2010 Beta 2.

Validation (): Element 'content' is not supported.

…or…

Validation ($SCHEMA$): Element 'div' is not supported.

…and others.  Basically, all ASP.NET controls and all HTML tags were not validating.  Here’s a shot from a simple page with about 30 controls on it:

image

The Perils of First Place

It turns out that there was a bug with the user settings from earlier betas of Visual Studio 2010.  When you are an early adopter you sometimes have to eat the weird situations of non-workingness.  Removing the older IDE would leave behind some zombies that attacked the recognition abilities of Beta 2, thus generating loads of validation warnings.

The webdevtools folks published an article on this which helps.  They don’t mention the zombies, but I’m pretty sure they are there.

To get around the problem, simply run Tools –> Import and Export Settings and reset everything.  Unless you are particularly attached to something in your user settings don’t bother saving what you currently have.  It takes a few moments to reset the IDE…image

…and then you’re done.

image

Project Pinning in Visual Studio 2010

Visual Studio has in the past allowed us to set how many projects are displayed when we have a view of recent work.  In Visual Studio 2010, that feature is extended further with the ability to “pin” frequently used projects to our list.

The recent projects list is displayed in the Visual Studio start page, if you have that option turned on (it is by default.  If you have turned it off, you can restore the start page by navigating to Tools –> Options and then to the Environment –> Startup property page.

image

You get the thumbtack icon when you hover over a project item.  Click it to have it stick around. Below is hover state of an unpinned item.

image

Also, in the flavour of ‘handy’ is the ability to control how many items appear in the Recent Projects list.  I mentioned this earlier so here’s how to do that.  Above I have 6 showing, which is set under Tools –> Options in the Environment –> General property page.

image

I am fortunate enough to have a good sized monitor, so I like the ability to fill the white space on the Start Page with about a dozen or so recent projects. 

This Ain’t Your Daddy’s IDE

But then, chances are, there are few of us with Daddies who had IDEs.  But, I digress…

I’m using Visual Studio 2010 about 80% of the time right now, but still hanging on to 2008 for a couple of projects that aren’t playing nicely.  With simple, trivial but yet productive time-saving features like this and others, it’s been the easiest switch of IDEs for this 12 year vet to the industry.

Here are some other suggestions I had, including my first mention of Project Pinning.

Tuesday, December 15, 2009

Google Gets Naked

Google has made a refreshing change to their start page: they took everything away except for search.

image

That’s all you see when you hit http://www.google.com, there are no links to news, images, email or your account.  Nothing, that is, until you move your mouse.

Is Less More?

I was immediately taken by the simplicity of the page, which is a stark contrast to the factoid-a-day implementation of Bing:

image

Bing’s front page is often an inspiring, if not productivity killing, start to your search experience and gives you something new and worldly to learn each day.

Change (Un?)Apparent

The new Google start page sure feels clean.  I don’t know if that’s better, but it is different and eye-catching in its simplicity. 

It is also short-lived, as moving your mouse fades in the same-old burdened UI that continues to grow as Google crams more features in.  On one hand it looks like they’ve nailed something and made it fresh, on the other they missed a chance to push a new UI. 

Either way it’s showing that two leading companies have a very different take on what user experience should be.

Now I’ve Heard of Vendors Not Playing Nicely Together…

…but this is ridiculous!

This is what happens to a can of Pepsi if you put it in a portable Coke refrigerator:

image

The Pepsi can exploded behind me in my office.  It blew the door open on the fridge and sprayed all over the contents of the cooler, the latch mechanism and the into the seals.  The carpet had nearly a full can of Pespi soaked into it in about 2 seconds.  The fridge door is now quite hard to open, even after repeated washings.  I even used soap.

Embarrassingly enough, I nearly ended up flat on my back on the floor.  I was startled (it was a lot louder than you would think) and I nearly rolled off the exercise ball I use as a chair.

What made the Coca-Cola refrigerator detonate a can of Pepsi? Was it malicious anti-competitive measures?

Well, that would certainly be a more interesting story. Sadly there is no blue versus red to report here.  But do heed my experience-born advice: when using a portable refrigerator and storing carbonated beverages, ensure the operating switch on the back is set to “Cool” and not “Heat”.

Unless, of course, you are trying to blow the door off with an exploding can of boiling Pepsi.

Thursday, December 10, 2009

Troubleshooting AJAX Pages in ASP.NET MVC

Drubbing through some work this morning I came across an error while trying to implement some AJAX on an ASP.NET MVC web page.

Microsoft JScript runtime error: 'Sys' is undefined

I had added my script references with absolute paths to the Site.Master page, so I thought I had my basis covered.  To confuse things further, I would get the error message hit ‘Ignore’ and then the expected result would be rendered on a new page.

Defining ‘Sys’

Unfortunately I was barking up the wrong tree when I was trying to Bing an answer up.  The error message, while absolutely true, didn’t actually reveal the root of the problem.

Searching for this error message ends up with pages of early AJAX builds, people talking about pre-release software and links to ScottGu’s blog on how to remove preview versions of Microsoft’s AJAX libraries.

I’m working in Visual Studio 2010 Beta 2, and have other pages running AJAX just fine, so I was pretty sure I had no compatibility issues with earlier versions of AJAX libraries.

What I Missed

I like shortcuts and speed-ups as much as possible.  It turns out that I dragged the JavaScript files into my header, giving me this:

image

Note that the above code actually isn’t a problem.  But I have a nasty habit of switching everything to absolute paths, so I did this (notice the ~):

image

…which of course would be fine if there was something that was actually processing the path.  Unfortunately I got this far (and a lot further) without running the page or making AJAX calls, so I put this little tweak out of mind.

The problem, of course, is that the path can’t be resolved for the browser to locate and download the JavaScript file.

Using Absolute Paths for JavaScript src Attributes

The fix is actually quite simple.  If you want to use absolute paths, just take advantage of the fact that the master page is run through the compiler and the path can be resolved quite easily:

image

Other Things That Indicate Path Problems

There is another symptom of not being able to resolve the src file.  If you’re not debugging you won’t get the error messages, but your browser will render the output of the AJAX call as a new page.  You might want to check your script paths if that is the case.

One other give-away is by checking the Solution Explorer while debugging.  The debugger inserts a Script Documents folder at the top of the solution and shows all the loaded documents.

image

If the JavaScript files you anticipate to be there aren’t, this would be a good answer to why you are getting the “'Sys' is undefined” error.

Wednesday, December 9, 2009

Bug, or Implementation Problem?

A problem with implementation might not always be a bug.  I’m not sure which this one falls into, because it’s two competing features that are designed to help, but almost make each other less useful in certain situations.

Box Selection and Multi-Line Editing in Visual Studio 2010

By now, you’ve likely seen Brittany Behrens and teams’ implementation of Box Selection in the VS2010 IDE.  It allows you to modify your selection based on screen real estate (rather than characters and lines) and then edit the selection in intuitive ways.  You can see Brittany’s walkthrough here and my lovin’ it here.

Where it Falls Short

Unfortunately, as rosy as it is, I don’t think it’s yet been fully implemented…or at least it doesn’t go as far as it could.

When working in the HTML editor in Visual Studio 2010, the box selection feature works brilliantly until you try to close tags.  What you end up with is a poorly-formatted HTML document as a result of the multi-line editing feature.

That’s because it butts heads with the auto-complete feature on HTML tags.  If you were trying to get a bunch of anchored list items into an unordered list, for example, the output becomes:

image

As you close the last HTML tag, only the last line item is properly completed, leaving all other lines non-compliant.

Is it a Bug?

I don’t think you can classify this as a bug, however, as it’s just supplemental functionality that is, perhaps, not being used as originally intended.  If, however, multi-line editing is to server more than just code files and classes, and the HTML editor was in-scope for the feature, this could be classified as a defect.

I’ll leave that up to the smarter-folks-than-I on the IDE team.

Thankfully, the workaround is built into the feature ;o)

image All you need to do is reselect the boundary space (between the characters) with box selection, and then complete the tag manually.  Multi-line editing takes over and lets us complete (in the example above) all four lines at once.

Monday, December 7, 2009

Visual Studio 2010 Debugging Tips

I continue to find gems scattered across Microsoft Visual Studio 2010; these ones are from the debugging story in the code editor window and are largely made possible as a result of Microsoft deciding to use WPF as their display engine for the IDE.

Here are a couple of very cool tips to help yourself out while debugging in Visual Studio 2010.

Pinning Watched Variables

You can now hover over a variable or object and pin it to the debug window.  This expands on the idea of watches and puts the data right in the source code editor.  You’ll see the power of this the first time you’re trying to see what’s happening to a set of data or variables through a loop. 

Hit the thumb tack on the right to “pin” the variable.

image

Combine pinning with conditional breakpoints and you have some very powerful scrubbing capabilities.  This is essential in my work as I am eternally sifting through 3500+ rows of data, looking for non-conforming values and objects.

Debug Comments

Once pinned, you can also add comments to your watched variables.  Note that in the left-hand column of the editor there is a corresponding thumb tack (you’ll need that for later use).  There is an expander in the mini tool window for your pinned variable that reveals a comment text box for you. 

image

The comments are persistent from session to session, so the next time you run your code you’ll see what you’ve previously typed.  This is great stuff.

Out-of-Debug Experience

Even better is that those debug comments stick around into your post-debug experience.  When you finish debugging and return to your code editor the thumb tacks hang around.  Hovering over a thumb tack reveals the pinned variable or object and shows the last value displayed in the debug session as well as your comments.

image

This works across source code files and is a real improvement over the tried-and-testing watch window: rather than a slew of watches from across a solution, variable values stay in context to the code you’re reviewing.

Get Good at Debugging

I swear that the single most beneficial thing you can do as a programmer is learn to use your debugger.  This is even more important than test-driven development and writing unit tests.  I have worked with too many “senior” programmers who don’t know how to attach to a running process or how to use breakpoints and watches to help solve logic or transformation problems.

These tips are hopefully an extension to your debugging tool bag.

Thursday, December 3, 2009

Yowsers…Bing Maps is the new Black

The new version of Bing Maps (still in Beta) has been built from the ground up on Silverlight.  They’ve integrated not only the features from the original maps software, but also way better image streaming, smoother scrolling, Photosynths, and…wait, did I just say Photosynths?

Oh yes, I sure did.

image

That’s pretty cool stuff, right there. 

Deep Integration for Developers

Along with the built-in things that are pushing the envelope of what we will expect from mapping software comes this integrated platform that developers can leverage to enhance (or pervert) the mapping experience.

image

There appears to be 16 current applications that are tuned-in to the user’s current view, coming from a variety of application providers.  Some of the applications, such as Twitter Maps by Bing, are actually doing some pretty cool things to leverage streams of data.  I zoomed into Union Square in New York City and began to see tweet indicators, some adorned with plus signs.  When you hover over those tweets, they cleverly expand to reveal via animation that multiple tweets have come from the same location.

image

Also interesting is that you can refine your search to only include tweets about certain keywords, topics or Twitter users.  Hrm…not too far from a dating service and nearly crosses the line to stalking service.

Now, on a tangent, it sort of makes me wonder if we aren’t heading into the age of reverse-Orwellianism. Rather than Big Brother watching where you are, where you go, people are actually broadcasting this information freely and readily to the world?  Weird.  I wonder if they even know they’re doing it…have we become that narcissistic?

Oh wait.  I guess I’m blogging, aren’t I?  Perhaps we are.

</tangent>

Some application developers are “getting it”, too, by providing baked-in examples of how their software works and in which contexts.  So, the travel-oriented web cam application has a list of popular (or selected) web cams and will take you right to the place on the globe where the camera is hosted from.  From there, you see all the other served web cams in the area and can view live images from those.

General Shiny-ness

The features flow together well and when you get into the apps side of Bing (are they called Map-apps?) you can start to see some really interesting convergence.

The animations can be quite smooth, though the experiences are always the same.  For example, when you use the Hotel Finder application when focused on an area, it will zoom out, pan over and zoom back into the next hotel you click on.  This is nice, as it give you a sense of spatial relationship to the two locations.  However, when you do a search in the Bing bar, the locations returned are located by a simple pan animation (and it’s really fast on my PC) so you lose a little of the context to the distance.

I must say, however, that overall this is a very slick products as far as betas go.

Image troubles…

…just switching over to a new web server and having a little difficulty posting images.  Apologies if you’re not seeing images on the blog for the next little while…

Wednesday, December 2, 2009

Coding for Christmas Cheer

Our office has decided this year to take part in the local Christmas Cheer Registry.  Families sign up, requesting a food and goods hamper, and then people or organizations attempt to fill all the needs of the community.  It really is a great cause.

Merry ASP.NET MVC to You

The MVC framework that is now available for ASP.NET is quite powerful.  Last night I was able to create a web-based application for our company where we can input the items, allow our staff to “claim” the items (indicating that they will donate them) and keep track of when the donations have been brought in.

While it’s not by any means fancy, I was able to implement all features in about an hour.  After sending out the email to invite others to participate, we nearly filled the list (and it looks like we’re going to adopt another family!).

image

LINQ to Christmas Chicken

What would otherwise be a chore to imagedevelop was made quite simple with LINQ functionality.   This is an extremely simple data model, with only two tables.  I used an mdf in the App_Data directory rather than a full-blown SQL Server Deployment.

LINQ to SQL starts things off for us nice and easy to give us a simple data access layer.  Because the dbml tools end up generating partial classes, I was able to easily extend the model to add properties to the Donations data.

image

For the purposes of this site, a hamper item is considered ‘claimed’ when a name is assigned to the item.  While there is no Boolean value saved in the database, the model (and subsequently the auto-generated Views) is easily adapted to provide this information at the class level.  Now, I have an easy way to test for claimed or unclaimed hamper items without having to check for nulls.

MVC – Making it Viable for Christmas

…but also known as Model-View-Controller.  It’s one of the oldest recognized patterns but it is also an entirely different direction from the Page-Controller experience we’ve had since the inception of ASP.NET.

Without taking into account the recent addition of Areas in MVC, you can think of the organization in this way: there are three folders, one each for your Models, your Controllers and your Views.  The Models are the objects you are working with.  The Views are what the user looks at.  The Controllers respond to user input, build up the models (or load them) and send them back with the appropriate View.

There will obviously be larger projects in your future, but for ours I knew we’d hit a limit of 8-10 views and therefore just elected to use the default Home controller.  I stripped out account management and opted to use the domain name of the user to simplify even further.  There is no about page and very few management pages.

image Creating the views was almost as simple as creating the LINQ to SQL diagram.  Visual Studio 2010 has integrated some editor tooling that picks up on code cues and prompts you for the magic.

To access the Add View wizard you simply right-click in the code editor for your controller.  The view name is pulled from the controller method where you clicked – in my case, AddDonation was the name of my method – but you can also customize as you feel is appropriate.  For my view I have also asked the wizard to use a template and create a draft of my data class Donation.  The template is driven from my View content selection “Create”, which stubs out a form for new records using the fields from my model.

Christmas Cheer in an Hour

There you have it.  A total of 1 controller, two classes in my model (one of them the DBML, so it was created with the designer), and a combined 10 views – all of which were largely auto-generated – and we’re well on our way to helping out a family for Christmas.  In fact, as I finish this note there are only two items left on the list and almost half of the items have already been brought in.

Though it may be early, this geek wishes you the Merriest of Christmases this year.

Monday, November 23, 2009

Talking Shop with Scott Guthrie

I’m in an online session right now in the LIDNUG group with Scott Guthrie who is answering questions related to PDC announcements, ASP.Net and Silverlight. 

image

I asked him about a couple of things, here are his responses:

  1. Will there be better tooling for ASP.NET MVC 2 Areas in the IDE?
    1. Yes, some of those tools were released with the last bits and Scott has a blog post coming up on that soon.
  2. The level-of-depth for the Nerd Dinner MVC example was great for beginners, but we don’t all need that level of depth for MVC 2.  For the next version can there be a walkthrough for people with more development experience?
    1. Yes, in an upcoming blog post Scott is going to do a feature walkthrough, highlighting what is important and why in MVC 2 without the introductory-level code bits.

Sorting Out Entities with Multiple Relationships in LINQ to SQL

There is a very common scenario in data design where you define a table as having two relationships with a single (other) table.  This especially comes into play if you have anything in your model with an “assignment” where someone assigns something to someone else.

In this case, We are tracking work tickets that are created by someone for someone else.  Both are stored in the ticket table.

image

Above is a snip from the DBML designer for LINQ to SQL. The two arrows represent the relationships between Person and Ticket, namely, that CreatedFor and CreatedBy are Person references.  If you have set up the foreign keys in the database, these associations are created for you automatically.

Convenient, yes, but code-revealing, no.  Here’s the result of the default naming as a result of the relationship being automagically created:

image

Now, which is which?  Are you looking for Tickets or Tickets1?  The default method for selecting a name is pretty ambiguous.

Directing LINQ to SQL Naming

Thankfully, the designer gives us a way to control the code generation tool and its naming conventions.  Click on one of the association lines on the DBML canvas and look at your properties windows.  Verify the members that are in use in the “Participating Properties” property, then drill into the Child Property detail.

There, you can set the name of the Child property to something more meaningful to developers using your code down the road.  Or, for yourself six months from now.

image You also have a chance to disambiguate the Parent property.  And, as a result, you have more readable syntax working from the child and walking to the parent record.

Wednesday, November 18, 2009

SqlGeography and Linq to Sql

I have a love-hate relationship with Microsoft SQL Server 2008’s Geography type.

I love working with it, but I hate it’s inaccessibility with some of my other favourite technologies. 

Specifically, I am trying to store GPS co-ordinates in the database as geography types.  This is a simple use, however, and although I’m only using points right now, we have other, more complex shapes that we must store.

I have figured out a couple of workarounds (that really aren’t workarounds at all) that allow me to use tables with the geography type in Linq to Sql.  These only really work for the point type and would get increasingly arduous as the shapes contain greater complexity.

Making SQL Server’s Geometry Play Nice with Linq to Sql

Unfortunately the Linq to Sql provider does not contain the data type support required for geometry or geography.  We’re not left with many options, at that point.

I tried a couple of hacks by creating the table by hand in the designer (it won’t let you drag the table onto the canvas) and stubbing in the field as a string, then banging up the code-behind to make it jive with the right types.

No go.  At the provider level it is not happy and there is no visible way to coax it into supporting the type.  Even if you cross your fingers AND your toes, you still get an error to the tune of:

The specified type 'geography' is not a valid provider type.

image

So, we’re stuck with less-pretty approaches.  I’m going with number one.

  1. Use Lat and Long as float types in the tables.  This allows seamless use in the Linq-to-Sql editor.  Create views that represent those columns as a single geometry point for reading the data in non-Linq-to-Sql scenarios.
  2. Store the co-ordinates in a geography field in the table and use stored procs to read and insert data as floats (lat and long).  Convert the data in the procs both ways.  Add the procs to your DBML.  This isn’t as good, because we lose some of the coupling in being able to ‘walk’ across your model in code.

I have also seen a recommendation to store the geo data as xml in the database and then do conversion on the client (casting to the proper types in code when needing to tap the data), or even pushing the data around as varbinary.  This approach would work, but generally I’m working with points right now and won’t need the added complexity.

Future Versions of Linq to Sql and Geometry

There have been suggestions from Microsofties on the forums that there will be support for these types down the road.  Right now, I’m sure it has to do with the fact that the assembly you need to access the type isn’t in the GAC by default and can’t be relied on to be present when someone’s in the throws of development (must have SQL Server installed to even get at the assembly in question).  Perhaps promoting the types to a more common distribution surface would alleviate this and open up the designer (and provider) to supporting them.

For now, Visual Studio 2010 Ultimate, Beta 2, does not have the support added.

Rx Comes to Fruition

The RxTeam last night announced the official release of the Rx Extensions (which has been called the Reactive Framework as well as the Rx Framework).  Developers now have a suitable set of tools – complete with concurrency support – for tackling asynchronous computation scenarios that respond to UI- and UX-driven events (or anything else that you need to subscribe to).

We no longer have to use the IL-hacked version of the library that targeted the Win-friendly version of mscorlib.

If you haven’t used it or heard of it already, Rx is the baby of Erik Meijer, the brains behind Linq.  The library is a collection of extension methods, interfaces and helpers that let us (subscribers) listen to events (publishers) in a Linq-friendly and developer-friendly way.

image

Above is the picture of Erik.  I wanted to post this snapshot of the video to ensure that t-shirt was recorded for all of mankind in the future to witness.   Assuming they will read this blog, that is…

The process of developing a standard library to encapsulate the long-standing Observer pattern went through many cycles between many teams.  The result is a set of extensions that flow seamlessly through from what we already know about working with collections: the Linq methods we have been working with for the last few years have been ported over to the Observable bits.

In addition to that, some new helpers and methods were spawned from the process that served IObservable really well.  Because it is the dual of IEnumerable, the team saw benefit to back-porting that functionality to original interface.  Read another way: IEnumerable isn’t being left behind as the dumb older brother.  The old dog is learning new tricks.

A lot of learning ahead, folks, get the bits and start playing!

Friday, November 13, 2009

Reactive Framework –> Hello World

Here’s a really quick sample on how to get into the upcoming Rx Framework, aka the Reactive Framework.  I’m using System.Linq.Observable as the source object to “observe”.

image 



To get this to run, download this version of System.Reactive (re-jiggered for the non-Silverlight folks), create a console application and paste the code below in Main.



var cookiePieces = Observable.Range(1, 10);

cookiePieces.Subscribe(x => Console.WriteLine(
"{0}! {0} pieces of cookie!", x),
ex => Console.WriteLine("Never going to happen in this sample..."),
() => Console.WriteLine("Ah! Ah! Ah! Ah!"));

Console.ReadLine();



All we’re really doing here is a little pump that executes 5 cycles and exits.  The Observable class implements the IObservable interface and gives us some structure to test again (like they do in the Silverlight bits that came out in the summer).



I’m exploring the framework more and more and working through several composition scenarios.  I’m liking what Rx has to offer at this point, especially the bits that allow for the extension of Linq to events.

Friday, November 6, 2009

Installation of TFS 2010

If you’re installing Team Foundation Server 2010 and you run into error TF255352 you might have a problem with your firewall.

Here’s the text of the message:

Permissions could not be verified because an error occurred while communicating with the following report server: [my server] 

And also, in a second warning:

The server returned the following error: The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing.

I missed a step in the install guide (how can you not…it’s just under four billion pages hehehe) and didn’t configure my firewall.  After adding the required port exceptions, I reran the pre-check, got all green lights, and installation continued as planned.

A Little Too Hot

Thankfully our servers didn’t suffer the same fate as the folks down under at Designwyse (the picture links to a Gizmodo article), but we came into the imageoffice this morning to find our server room A/C unit blowing hot air.  Ouch.

Most of our internal network was limping and we had general connectivity problems, VOIP issues, etc.  General yuck stuff you have to deal with.

The UPSs were failing, all the Dell server equipment we had was shutting itself off (overheating preventative measure) and our chassis temperatures were all over 50°C (that’s over 120°F) and alarms were sounding.  The room is 12x10 with about over 50 servers in it.  The metal on the racks was hot to touch.

Methinks the redesign on the server room and A/C upgrades planned for early next year might be getting bumped up in time frame…

Of interest, our Big Bertha that handles virtualization did a great job.  She’s taken over 20 machines on board (most physical-to-virtual conversions) and I can’t imagine how how it would have been in there if there were another 20 machines running.  It could have been disastrous.

Thursday, November 5, 2009

Apple Will Ruin the World

image A very startling realization came to me yesterday: Pixar Animations Studios has prophesized that Apple Computer will spell the end of Planet Earth.

By now, you’ve likely seen the movie Wall-E. The story takes place 700 years into the future where humans have lived in the outer reaches of space for several centuries, mostly unaware of the plight of the planet they once called home.

We are introduced to the main character and join him as he makes his way through a typical day, compacting garbage, making building replicas and collecting interesting bits of junk.

image

So…what is Apple’s part in world devestation?

You might be wondering how this ties into my theory. Who cares if a little robot is left here to clean up our mess? And what does that have anything to do with Apple? Well, let’s look at it from another angle:

  • Why did the humans leave Earth? There was too much garbage.
  • Why was there too much garbage? Because Buy-n-Large convinced consumers to buy into a perpetual model of perceived obsolescence (“Wear red, it’s the new blue!”). Everyone replaced everything without caring about anything. Buy-n-Large had them trained perfectly.
  • How did Wall-E learn about humans? He watched videos rigged up with an iPod.
  • Did he know a lot about iPods? Of course, he had it wired up to not only view stored content, but indirect input from VHS tapes and players. This cat had intricate knowledge of the device…he almost knew it’s inner workings too well…
  • Did he have a deeper connection to iPods at all? Well, maybe not, but he makes the Apple start-up sound when he wakes up.
  • Wait! The Apple start-up sound? Yes, one in the same.
  • But I thought Buy-n-Large made all the Wall-E units to clean up planet Earth?!

…and then BANG! You get it! Apple IS Buy-n-Large. Just as many people I know are on their second, third (or more) iPod or iPhone, Apple is already convincing people that the things they buy are legacy the moment it comes home.


It’s easy to see what would happen to Earth if Apple becomes the conglomerate, all-goods store that they do in the movie Wall-E. People already buy into their model of things becoming junk in just months or years.

image Long gone is a time when people would patch jeans or take shoes to a repair shop. There’s a whole new class of disposable electronics – DVD players, ink-jet printers, MP3 players – and we’re pretty much headed on a crash-course with garbage overload.

Just as Pixar suggests, with Apple hiding behind a name as blatantly anti-Earth as “Buy-n-Large”, by purchasing Mac Products you will help Steve Jobs bring an end to this planet.

There, glad I got that off my chest.

:oD

…and by the way, this is the most tongue-in-cheekiest post I’ve ever made. Play along, it’s just for fun! ;o)

Wednesday, November 4, 2009

A Simple Image Display

In response to a forum thread on MSDN, I wrote a quick app that uses two quick methods to display a picture on a form.  The solution (Visual Studio 2008) is available for download here.  The class in question is System.Drawing.Graphics and the forum member was simply looking to display an image.

The app is pretty simple:

image

One method (Easy Open) loads an image from a file and sets the Image property of the PictureBox.  The other method (Harder Open) loads (and caches) and image to a member variable and keeps it around for a custom paint event on the PictureBox.

The poster also mentioned some performance metrics, so I stubbed out some placeholders for that as well.

Visual Studio 2010 Goody Bag

A couple of quick things that you’re going to like when you start using Visual Studio 2010…

Visual Token Recognition

  This is a form of syntax highlighting that exposes variable use throughout the current class file.  This is actually a significant boost when you’re trying to assess the potential impact of a refactoring.  You can place your cursor on the member definition and every instance of the token will be highlighted throughout your file.

image

Even cooler is that it works not just on variables but also on other tokens, such as methods and properties:

image 

You may also notice from the above shot that your cursor doesn’t have to be in the method/property/variable declaration; in fact, if you cursor into any member usage, all other instances are lit up.  Brilliant.

Collapsible Section Highlighting

Here’s another visual enhancement (it is subtle, so it will be hard to see on a non-contrasty display):

image

Okay…artiste, I am not.  But I had to draw in the cursor where it was hovering when I got the block of code to light up.  There is a light-grey highlight behind the entire collapsible section.

More Ways to Learn the Code

imageIf you’ve ever been assigned a defect on a system that you are new to or haven’t worked on in a while, it doesn’t really matter how experienced a developer you are, you’d probably enjoy a bit of help.  The above enhancements are good tools for that. 

So are these: Generate Sequence Diagram and View Call Hierarchy.

Both of these features are available from the right-context menu of the code editor in Visual Studio 2010.

The call hierarchy is very similar to the debug experience in previous versions of Visual Studio in that you can see where the code walks from where you’ve queried.  This is a bit different from the debug version, where your hierarchy are inferred from the current execution point.

imageThe Generate Sequence Diagram feature is a great aid in discovery as well and a welcome addition. If an SD is one of your deliverables, I can assure you that it’s just as slick as the View Class Diagram feature from previous versions. Though they can get quite complex if you fully include all options, they can also be very descriptive – including code snippets – and will give any viewer a good idea of the execution path for the areas of your software you’ve included.

Several external tools have been created over the years, and some of us have had to slog away in things like Visio before (which is where I did my assignments in my UML courses. Echk.)

If You Don’t Use These, It’s Only Because You Don’t Use Them YET.

Right from the start Visual Studio looks and feels like it will provide developer productivity improvements.  While productivity is usually a seller for management, these types of improvements are actually good for developers and equip us to better navigate our code, legacy code and code that you might fear.  Because the IDE allows us to target different versions of the .Net Framework, we can also leverage these gains on older projects.

Monday, November 2, 2009

Restoring RSS Feed Syncronization

One of the things I really loved about Outlook in Office 2007 and the release of Internet Explorer 7 was the marriage between the two with the concept of the Common Feed List from Windows. Unfortunately that seemed to go away with Internet Explorer 8 and Outlook 2010.  While troubleshooting another issue I came across the option to sync the RSS feeds in Outlook with the CFL:

image

image To locate this, you need to get at the Backstage (learn to love it!), hit Options under Outlook and then navigate to the Advanced menu as indicated above. Make sure you have Synchronize RSS Feeds to the Common Feed List (CFL) in Windows checked off and bing! you’ll have all the feeds you subscribe to in Internet Explorer automatically downloaded in Outlook.

Don’t use this feature?  You should!  Check this out: when you go to your favourite blogs or news sites in Internet Explorer 7 and up you will most likely see the RSS feeds button light up.  It’s located on the same line as the tabs are, next to your Home Pages icon.  If there are multiple feeds, there will be a dropdown box that will give you options.  For instance, when I check out Gizmodo’s home page I see this:

image

When you click on any of the feed choices, you see the raw feed, almost detached looking from the main site.  At the top of the new page you’ll have an option to subscribe to that feed and forever be at oneness with your favourite site.

image

Go ahead, try it here! ;o)