My Resume

  • My Resume (MS Word) My Resume (PDF)


Affiliations

  • Microsoft Most Valuable Professional
  • INETA Community Champion
  • Leader, NJDOTNET: Central New Jersey .NET User Group

Sunday, April 20, 2008

Central New Jersey MS Certification Study Group

We had our inaugural meeting of the "NJDOTNET Spring '08 MCTS Study Group" this past Thursday, and I thought it was a wild success!  I had just under 30 people register (express interest) over the past few weeks, about 5 email me before the meeting to let me know that they wouldn't be able to attend this first one (but, yes, they are very excited!), and an even 20 people actually show up.  I sure am happy with those numbers!  My favorite part about the whole thing is the positive energy and just raw desire to dive deep into .NET that all of the members are showing.  It really is a great thing to know that you'll be able to meet up with these people (and this energy) for at least a few hours every week.

For those of you who haven't heard through the various other channels, we can still squeeze a few more members in.  So, if you're interested in getting your MCTS certification in Windows Forms or ASP.NET, please feel free to let me know.  We meet every Thursday night at 6:30 PM at the Infragistics headquarters just outside of Princeton, NJ.  Check the NJDOTNET Website for more information, including directions.

Using Plain Old WebForms Controls in your ASP.NET MVC Views

Still wanna use all those nifty controls that you had access to back when you were developing in the Dark Ages of WebForms?  Well, you can!  ... sort of.

If you're like me, one of the first things you did when you started writing your first ASP.NET MVC app was say to yourself, "Hmmm... wonder what happens when I drop this TextBox control on my View?"  I don't think anyone is surprised when you see something along the lines of "[...] type 'TextBox' must be placed inside a form tag with runat=server."  I'm sure most seasoned ASP.NET developers have gotten this error at some point in your coding life when you're writing a new page from scratch and forget to wrap your page in that oh-so-important "<form runat='server'>" tag.  What you may or may not know (I didn't realize this until I got into MVC Land and tried it) is that not all tags have this constraint.  Tags such as the Image tag (and a handful of others) are just there to generate markup and don't really care whether or not they're in a form.  Feel free to litter your pages with them and they should do some pretty good work for you.  Unfortunately, tags like TextBox and his cronies really like the secure feeling they get by having that nice warm <form> tag wrapped around them.  And - after all - things like <input> tags are "form" elements, right?  It's understandable that they need the <form> tag to live.

...or do they?

The short answer is, "Yes, they do."  In order to use these controls - the visual representatives of the Web Forms Way - the way that you're used to, they do need that <form> tag and all that it entails (like ViewState - ech!).  However, that answer simply wasn't enough for me.  When I switched over to ASP.NET MVC, I knew that I was going to lose a lot of the convenience that WebForms and ViewState gave me... but I also knew (or at least hoped!) I'd be getting rid of the problems that came with it, too.  So, I'm already in that mindset when I'm working on my MVC app, but I get frustrated when I have to copy code all over the place to generate "static" HTML like image buttons and the like.  Like I am with the MVC framework in general, I am more than willing to give up the advanced features of the Web Forms controls (like event handling and the like) if only I could just continue to utilize the markup they generated so well.

So, my mission was simple: I needed a way to get rid of that error message and allow these controls to generate the HTML I so desperately missed.  And - lucky for me - I found a way!  here's the magic:

Avoiding the Error
    public class BaseViewPage : ViewPage
{
public override void VerifyRenderingInServerForm(Control control)
{
return;
}
}



That's it.  Just overriding "VerifyRenderingInServerForm" on the ViewPage keeps the error from occurring and lets the controls try to output the markup they are tasked to. 



I'll be the first to say - this works with varying degrees of success, depending heavily on which control you're trying to use and how you're trying to use it.  But, hey - anything is more than you had before, right?  It's a neat little trick that may end up saving you from having to duplicate some of the work that those bright folks at Microsoft have already done for you.  And, it may just help you make your markup a bit cleaner.

Tuesday, April 15, 2008

Unit Test Project Structure

I recently came across Phil Haack's interesting blog post and associated poll about structuring your unit test projects - do you have separate unit test assemblies or not? - and was not entirely surprised by the results.  They were more or less in line what what I'd expect.  At the beginning of my TDD "career" I'd actually considered for a brief second whether it'd be better to put my unit tests in line with the code they're testing (not "inline" as in the same file, but close) or in a completely separate assembly.  After a few minutes of thought, I came away with what it seems most other people come away with - and emphatic "NO!"  I'm honestly left wondering - and I don't mean any disdain, but - what are these 8% of "Yes" voters are thinking!?  Is it laziness, or some other motive that I'm not getting?  Really - I'd love to know!

Sunday, April 13, 2008

NHibernate Lazy Loading Snafu

Oh, man did I get thrown for a loop last night... 

I've got a test project I'm working on that uses NHibernate.  In this project, I've got a Building class, which has an Address attribute, of type Address, for which I overrode the ToString() method like so:

image

I've also got a page that grabs a bunch of Buildings from the NHibernate session and binds them to a Repeater.  For my initial tests, just to see if everything worked, I just bound right to the Address property on the Building in my markup and everything worked fine.  That is, the address printed out just as it was supposed to - in just the right format I'd set in the ToString() overload.  Then I went to refactor the page and break the address out into it's individual bits to show them in a slightly different way...  and was greeted with a null reference exception!

I was troubleshooting for a good half hour or so before I came across this dialog:

image

WTF!?  How in the world could my ToString() overload be generated correctly when all of its properties are null!?  And then I realized - lazy loading!  D'oh!  I went to my NHibernate mapping file for the Building class and updated it, adding the "lazy='false'" attribute, so it ended up looking like so:

image

and now everything works like a charm!  This fix doesn't really bother me because the Address probably shouldn't have been lazily loaded to begin with, but I never did end up figuring out how exactly that AddressProxy was able to give info to my ToString() override but was not nice enough to populate my properties for me!  Looks like I've got to learn about lazy loading and NHibernate Proxy classes!

If you've got some ideas on how this happened, please leave a comment - I'd love to know!  But for now, I'm just happy I figured it out!

Wednesday, March 26, 2008

ASP.NET MVC ViewData Extensions

I've been playing a little bit with ASP.NET on my own (outside of the CodeCampServer project that I'm involved with) and I'm starting to really find out the cool uses and limits of the new framework the ASP.NET team has released to us.  The most awkward thing IMHO is dealing with ViewData; specifically, having to jump through hoops to get typed data out in your view when all you want to do is just use it and not really have to worry about it.

Out of the box, there's System.Web.Mvc.ViewPage which is what all of the beginner samples say to use.  Then, once your needs evolve a bit (just a bit is all it takes - you grow out of that quite quickly!) you realize that you need a way to easily access typed data in the view.  The MVC framework's answer to that (at least in the Preview 2 bits) is the generic version of the aforementioned ViewPage class (appropriately System.Web.Mvc.ViewPage<T>) which allows you to pass in one type to use as your ViewData.  This is a step in the right direction, but it still falls short since you find yourself creating all of these new classes just to hold a bunch of different types of view data and it often ends up being one new, custom class per page/view...  hardly a reuse of code there, and very (uncomfortably) reminiscent of Web Forms style development.

You need a middle-ground - a nice way to interact with the ViewData collection in a strongly-typed way, but without having to create new classes to go along with each of your new views.  Jeffrey Palermo came up with a nice way of handling this with his SmartBag (that he describes in this post and subsequently implemented in the CodeCampServer project).  I really liked the idea at first because it solved a problem and it did it pretty well... not to mention somebody else did the work of creating it for me so all I had to do was just use it. :)  However, when I tried to start using it in my projects, it became all too clear just how much work Jeffrey had to go through to introduce it.  After thinking for a bit I remembered a powerful new tool that .NET 3.0 has provided us with - Extension Methods!  With these, you can tack on functionality to pretty much any class - or even interface - you want, and so I started tinkering...

What I came up with was a set of extension methods on top of the Controller.ViewData property's type (IDictionary<x,y>) to make adding the strongly-typed data a lot easier using generics...  very simple, but very powerful and very helpful.  Then, going back to the whole impetus for this mess - I made a matching set of extension methods on top of the ViewPage.ViewData property (which is of type ViewData, interestingly enough) to help get access to the values we so easily tucked away using the Controller.ViewData extension methods.  I've been using it for a few weeks now and it seems to be working like a charm!

Without further ado, here's the code!

The Add Extension Method (to get data IN)
                
/// <summary>
/// Add a value to a dictionary, using its type name as the key
/// </summary>
/// <param name="dictionary" />Dictionary to add to</param>
/// <param name="data" />Data to be added</param>
public static void Add(this IDictionary<string,object> dictionary, object data)
{
// Get the object's type name to use as the key
string typeName = data.GetType().FullName;

// Check to see if it already exists and if it does, throw an exception
if (dictionary.ContainsKey(typeName))
throw new System.Data.DuplicateNameException(typeName);

// Add the data to the dictionary using the type name as the key
dictionary[typeName] = data;
}

And then, to pull it back out on the view, I added these Extension Methods to the ViewData class: ViewData Extension Methods

   
/// <summary>
/// Get the object saved in ViewData of this type.
/// </summary>
/// <typeparam name="T">Type of object to get</typeparam>
/// <param name="viewData" />ViewData collection to retrieve from</param>
/// <returns>
/// The typed data value (if found).
/// Otherwise, the default value for type T.
/// </returns>
public static T Get<T>(this ViewData viewData)
{
return Get<T>(viewData, typeof(T).FullName);
}
/// <summary>
/// Get the object saved in ViewData of this type.
/// </summary>
/// Type of object to get</typeparam>
/// <param name="viewData" />ViewData collection to retrieve from</param>
/// <param name="key" />The key used to save the data.</param>
/// <returns>
/// The typed data value (if found).
/// Otherwise, the default value for type T.
/// </returns>
public static T Get<T>(this ViewData viewData, string key)
{
T returnValue;

if (viewData.ContainsDataItem(key))
returnValue = (T)viewData[key];
else
{
// Since we're in the view, just play nice
// and return the default value if it the
// key doesn't exist.
returnValue = default(T);
}
return returnValue;
}


Simple enough, but I find them to be wicked useful! I hope you will, too.



Edit: I noticed as I was looking through the CodeCampServer source tonight (just after finishing this post, no less) that Jeffrey had actually updated his SmartBag concept to something much more along the lines of this. Hey, I never said it was incredibly original, but it sure is nice to have your thoughts validated by someone else (especially one as knowledgeable as Jeffrey!).

Sunday, March 23, 2008

MIX 08 Recap

I got back from MIX 08 two weeks ago and I think I've just about recovered.  Not only from the conference (and Vegas) itself, but the hole 1+ month of heads-down coding that came leading up to it.  I've finally gotten some time to come up for air and talk a little but about my trip and some of the cool things they were talking about.  It was a dangerous conference this year - what with one presenter falling off the stage and another one actually passing out - but the risks were certainly worth it, having gotten to see a whole bunch of really cool, exciting things.

I'd have to say one of the coolest parts was the keynote, complete with a Deep Zoom demo and Scott Guthrie juggling.  There were quite a few interesting topics in here, but one of my favorites had to be the showing-off of the up-coming Silverlight 2.0 application that's going to be leading NBC's online Olympics coverage later this summer.  We've had Picture-In-Picture technology for quite some time - and in fact I never really saw much value in it - but there was something amazing about seeing in on the PC... and in your browser, no-less.  Traditional TV-based PiP always seemed so clunky and annoying to use to the point that it just wasn't worth setting up, but offer a mouse and keyboard interaction and all the sudden it's become much easier and much more practical!  Truly awesome.

Also during the keynote I also noticed a UI paradigm being used that I'd seen plenty of times before, but had not realized the power of until now - the "baseball card" effect.  It was shown in the context of an HR management app (or something like that) where the user scrolled through a sort of virtual Rolodex.  I'll try to explain the concept that struck me by using an example:

You start out with a whole bunch of "cards", each with two sides:

  • Each of the cards has a "front", which contains a picture (say, of a client) and the general overview or the important details, such as a persons name and general location.
  • Then they each have a "back", which has little to no graphics, but is more data-oriented.  Here you might find the client's full information, included detailed address, phone number, likes, dislikes, etc. much like you'd find a baseball player's stats on the back of a baseball card.

There's an important third aspect (or dimension, if you will) to this whole equation that UI frameworks like WPF and Silverlight bring to the table that haven't been readily accessible to most developers until now - animation.  Well, that's the functional tool we've been provided with...  the real power is using this now tool to give us the ability to make a painless switch in context between the front and the back of these cards by using an animation of the card flipping over.  The important link that this creates that of the card's front and back and not just switching between two "pages" that just happen to have detail about the same person. Instead, it allows us to make a more physical link between the two sides by representing them as being two parts of the same whole by showing the whole motion of "flipping the card over".  What's really cool is that this is a concept that you can further exploit by collecting many of these "cards" - each one containing data for a specific person - and do things with them, like shuffling them, pouring them out onto a table, or stuffing them into a virtual Rolodex.  These paradigms certainly aren't new, it's just that they were - until recently - only available to visual designers and those with madd grafikal skillz.  Well, not any more!  Now all you need is a bit of XAML knowledge to start harnessing these powerful paradigms - how exciting!

Saturday, March 22, 2008

ASP.NET MVC Framework Sample Project (CodeCampServer)

Back in early January, I jumped at the opportunity to answer Jeffery Palermo's call for OSS developers to help out with his new project dubbed CodeCampServer and used as a vehicle for exploring the new ASP.NET MVC Framework.  I had hit the ground running and helping out in any way I could with a bunch of checkins and chatter on the groups and learned a lot.  Unfortunately, the whole of February I was pretty much heads-down coding Infragistics' new property - Pixel8 - so I wasn't able to be as active as I'd hoped, but I'm looking forward to getting back into the loop and back into churning out some code.

Before I joined the project, I have been a pretty avid reader of the CodeBetter blogs for some time and for the most part I really appreciate not only what they have to say but especially the new concepts, ideas and viewpoints they can provide.  I often related most with Jeffery's posts and being involved in a project with him has been not only fun but incredibly educational.  Jeffery's emphasis on agile methodologies and concepts - particularly TDD and composition over inheritance - were a refreshing change from what I've been traditionally exposed to and it's nice to start branching out.

CodeCampServer is definitely only going to be a nice, useful piece of software.  However, I think its best use may just be as a learning tool for anyone looking to dive in to any of the myriad concepts and practices the project exemplifies, such as:

  • ASP.NET MVC (of course...)
  • test-driven design and development
  • composition over inheritance
  • using StructureMap
  • using NHibernate
  • setting up a build environment using NAnt
  • ...and probably many more that I'm not even able to pick out!

So, if you're interested in learning about any of those topics, be sure to head on over to the CodeCampServer source code repository browser available online and glance through the code... or download the whole lot and run it for yourself!

It's been a real joy to be involved in this project, and I'd like to thank Jeffrey and Ben for working so hard to set it up and keep it going.  Plus, if the quality of their up-coming book is anything close to the quality of this project, it's bound to be an incredible tomb of knowledge.

ASP.NET MVC Source Code Released

Just found out some cool news a little while ago:  the ASP.NET team graciously released the source code for their new wicked-cool framework on Wednesday.  You can get it at their CodePlex project http://www.codeplex.com/aspnet (and here's a link directly to the download page).

This is a great development in the ongoing push that Microsoft seems to be making to become more and more transparent... or at the very least more agile.  And, I must say - I do like it!  So, if you haven't gotten a chance to play with the MVC framework stuff yet, go grab all the bits; if you have already been playing with it, now you can check out the source, too!

Tuesday, March 11, 2008

Pixel8 is born!

I've been heads-down coding for the past two months or so, trying to get a whole slew of things ready and out for MIX '08.  Now that MIX is over (and I'm back and recharged from Vegas - ouch!) I can finally get back to doing some blogging.

The major project I've been working on during my 9-5 (ha - yeah right!) is the recently-released Pixel8 (http://pixel8.infragistics.com).  It's Infragistics' newest web property - adding yet one more to the exhaustive list of sites under my purview - with relevant development pod- and vid-casts streaming through our Silverlight media player... and I think it's pretty darn cool.  It all started when late last year we were finally able to woo Craig Shoemaker of Polymorphic Podcast fame to come work for us and keep churning out his awesome content, but let us still our name on it... and man has he delivered!  It's been only days since we released the site and we've already got over 8 audio and video shows live and ready for public devouring.  This was a really exciting project for me not only because I got to work side-by-side with Craig, but also due to the joys of working with the ASP.NET AJAX framework, ASP.NET Futures controls, and of course Silverlight (albeit only 1.0...).  I had a lot of fun and learned some valuable things.

So, if you've got a few minutes - or a few hours - to kill, head on over to http://pixel8.infragistics.com and fire up our new player and watch some shows.  I'm sure you'll enjoy what you see.

Saturday, February 16, 2008

Server-Side ASP.NET Variables Meet Client-Side JavaScript

I came across Rick Strahl's awesome blog post tonight about something that's consistently been a thorn in my side: I've got an ASP.NET variable/value (say, a control's ClientID, or "a $Ch~!'unk of T==ex_t '1'$li%20ke"`th"is~!") that I want to populate a JavaScript variable with on the client side.  My first instinct has always been to just do a handy little in-line <%= MyVariable %> and for the most part that usually works... for the most part.  But, there are plenty of cases - such as special characters, encoding issues, or simply the fact that you're trying to mix inline code with external (aka - static) script files - where this solution won't work.  However, Rick's nice little class takes a stab at addressing that problem, and I think it does it pretty darn well.  I'm looking forward to trying this out in my next project.

Keep 'em coming, Rick. :)