Friday, February 5, 2010

Creating Customized UserControls (Deriving from ContentControl) in WPF 4

Creating Customized UserControls (Deriving from ContentControl) in WPF 4


Creating Customized UserControls (Deriving from ContentControl) in WPF 4

Posted: 05 Feb 2010 01:26 PM PST

Another twitter question. As usual, I'm targeting WPF 4 here, but just about everything here works with Silverlight 4 as well. (read from bottom up) Let's say you want to create a standardized "gadget" for your application, from which anyone can derive...( read more )...(read more)

Kaxaml Update + Downloads + A Request

Posted: 05 Feb 2010 10:36 AM PST

Kaxaml Update I had a great conversation with Rob Relyea (Mr. XAML) yesterday about the future of Kaxaml and he shared a lot of very useful pointers about how to use some upcoming .NET 4.0 features to make Kaxaml super awesome. Looks like he's already...( read more )...(read more)

Silverlight Cream for February 05, 2010 -- #793

Posted: 05 Feb 2010 09:51 AM PST

In this Issue: Joel Neubeck , James Bacon , Jeremy Likness , John Stockton , Fredrik Normén , Subodh Pushpak , Alexander Golesh , PhaniRajuYN , Victor Gaudioso , and Syed Mehroz Alam . Shoutouts: Michael Sync posted the material for his My WPF MVVM Session...( read more )...(read more)

Test Driven Silverlight Body Snatchers

Posted: 05 Feb 2010 08:31 AM PST

    This posting is part of the Silverlight HyperVideo Platform documentation and a Silverlight Mini-tutorial . The information in this posting, however, should be of interest to anyone writing meaningful Line of Business applications with Silverlight...( read more )...(read more)

Test Driven Silverlight Body Snatchers

Posted: 05 Feb 2010 08:31 AM PST

 

MiniTutorialLogo

 SLHvpLogoNoBorderThis posting is part of the Silverlight HyperVideo Platform documentation and a Silverlight Mini-tutorial. The information in this posting, however, should be of interest to anyone writing meaningful Line of Business applications with Silverlight.

[This is the first of two parts on Test Driven Development. Part 2 will walk through creating Unit Tests in "real time"]

 

The premise of the classic 1956 film Invasion of the Body Snatchers is that there are "pod people" among us, who are converting "normal" people into pod people one by one.

 

"Once you are a pod person, you think everyone should be one"

Once you begin seeing the benefits of TDD you tend to evangelize; its working great for you and you want everyone to become one.  This can be helpful, annoying or alarming depending on who you're talking to.  My daughters, for example, are quite sick of hearing about it.

"They're here already! You're next! You're next!"

It seems reasonable to many developers to create unit tests for their code; but the presumed high cost of doing so implies for waiting for a project that is not in "crunch mode."  Most developers will be waiting a long, long, long time.

Experience indicates that TDD actually saves time – you spend less time debugging and more time coding. Unfortunately, that sounds like "a good theory" and we all know that In theory, theory and practice are the same,
But in practice, they never are.

The bigger problem is Isaac Newton. Most of us suffer from Newton's first law (significant inertia) and when confronted with an evangelist, we are governed by his third law (the more you push, the more I push back.)

"Give Up! You Can't Get Away From Us! We're Not Going To Hurt You!"

That said, for the past few years I've had the nagging sense that I was missing something important.  Especially given that some of the folks I respect most in the industry were strong proponents; not least my mentors in all things good:  RMSquaredF: Robert (Uncle Bob) Martin and Martin Fowler who laid the ground work and established best practices in their seminal works Refactoring: Improving the Design of Existing Code (Fowler) and Clean Code: A Handbook of Agile Software Craftsmanship (Martin).  In the latter book, Robert Martin summarizes his approach which I paraphrase here:

  1. Don't write production code until you've written a failing unit test
  2. Write just enough of a test to fail. 
  3. Write just enough code to pass the test 

What you are aiming for is about a 30 second cycle of write-test, write-code, Run-test.

Uncle Bob's premise is that you tremendously reduce your risk and thus your fear because your production code never gets ahead of what you know; and you know it because you've tested for it.

"I Don't Want Any Part Of It." 
"But You're Forgetting Something….. You Have No Choice."

 Invasion poster A second premise of folks who evangelize TDD is that you really have no choice; it is a case of "pay me now, or pay me later." Either you create the unit tests or you spend that much time and a good deal more on debugging. 

The Silverlight HyperVideo Platform project offered the ideal opportunity to take on TDD, and the only way to do so was by Fiat. Thus, I made the executive decision to require unit tests for all code checked into the project (not hard to enforce so far, as at the moment all the code in the project is mine).

 

"The words, the gesture, the tone of voice, everything else is the same, but not the feeling."

The rules for writing good tests are very similar to writing good code, but with a couple extra requirements.  Stealing again from Robert Martin, here is a paraphrase of the good-test rules developed at his company, Object Mentor:

  • Test must be quick. The slower a test runs the less likely you are to run it.
  • Tests must be independent of one another; any side effects or dependencies must be avoided
  • Tests must be repeatable: running the same test against the same code base must give the same results
  • Tests must return unambiguous results
  • Tests must be isolated from the production code

 

Configuration – ViewModel Objects

I published a plan for configuration that made use of Xaml files. I realized yesterday, in one of those forehead slapping moments, that a design that relies on placing configuration files on the client of course will not work due to access limitations.  No harm done: the Xaml files were just a mechanism for creating the configuration business objects; and there are natural server-side analogs.

We'll use the Xaml file approach for enabling the user to maintain the state of the program when suspended or shut down (using local storage), post V1.

The working design now looks like this (using a relational database for persisting the configuration information, and WCF-RIA Services for moving the objects to the client. (A forthcoming blog entry will walk through that aspect of the implementation in detail)

slhvpDBTables

(Click on image for full size)

Links Vs Units

Links are a unique identification of a Unit, and Units are not represented by a class. A Unit is a set of Items (and the selected item), each item's set of topics (and the selected topic) and each item's set of links (and which links are currently displayed).  Notice that units are identified by a URL.  In V1 the selected item and selected topic are the first in the set, and this design is used only for configuration.

After v1, we'll move from read-only to read-write, allowing the user to persist the current unit and to recreate the state of the application at a later time.

From Tables To Objects

The diagram above was created to show how the RDB would work, but it is a bit misleading.  What we really want is not tables but rather objects.  There is a very small jump (in this case) from the tables to the business objects as shown here:

TDDObjects 
(Click on image for full size)

There are a number of advantages to creating these objects, the most significant of which is that I can go ahead and implement the configuration without regard to how these objects were created, providing two implicit benefits:

  • I don't have to get all the WCF Ria Services code working before I can make configuration work and…
  • The design now allows me to substitute virtually any persistence mechanism (database, Xaml configuration files, etc.) to back these business objects.

Further, these objects are part of the ViewModel, and facilitate binding the View to the ViewModel (as discussed in my mini-tutorial on MVVM).

  

Implementation

We're now (finally) ready to implement this, and as an experiment in open, honest and direct explanation I'm going to do this in real time, documenting my experience of creating the Unit Tests and the classes and their methods as I do it

One of the contributors to the slhvp project, Abby Fichtner (aka Hacker Chick) said to me just last night,

The great advantage of testing first is that it forces you to think about what the ideal API would be to each of your classes.

Exactically.  

The Configuration Objects

The first implementation issue is this:  I already have the following objects in the project:

It isn't clear if the existing Item, Link and Topic (location) classes can be used for configuration, and I have a nagging feeling that I want something more. But here is where Agile development comes to the rescue: Design for what you need right now

Next up, A Real Time Walkthrough of Test-Driven Development….

ASP.NET MVC 2 (Release Candidate 2) Now Available

Posted: 05 Feb 2010 12:44 AM PST

[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu ] Earlier this evening the ASP.NET team shipped ASP.NET MVC (Release Candidate 2) for VS 2008/.NET 3.5.  You can download it here . The RC2 release of ASP.NET MVC 2 is a follow-up to the first ASP.NET MVC 2 RC build that we shipped in December.  It includes a bunch of bug fixes, performance work, and some final API and behavior additions/changes.  Below are a few of the changes between the RC1 and RC2 release (read the release notes for even more details): The new ASP.NET MVC 2 validation feature now performs model-validation instead of input-validation (this means that when you use model binding all model...(read more)

MIX 2010 Zune HD app

Posted: 04 Feb 2010 11:57 PM PST

We're starting to get pretty excited over here about MIX and SXSW . We will have a presence at both, but I have to admit I'm kind of partial to mix. So in celebration of MIX 2010 and the great music that is the heart of SXSW I built a zune hd music "mix...( read more )...(read more)

Installing and Setting Up and Encoding for IIS 7 Smooth Streaming and Silverlight

Posted: 04 Feb 2010 11:17 PM PST

I heard someone saying they were having trouble setting up Smooth Streaming for IIS, so I wanted to try it myself. If you just want to see Smooth Streaming work, visit http://www.smoothhd.com/ for some sample demos. They'll adapt to your bandwidth and...( read more )...(read more)

Installing and Setting Up and Encoding for IIS 7 Smooth Streaming and Silverlight

Posted: 04 Feb 2010 11:17 PM PST

I heard someone saying they were having trouble setting up Smooth Streaming for IIS, so I wanted to try it myself. If you just want to see Smooth Streaming work, visit http://www.smoothhd.com/ for some sample demos. They'll adapt to your bandwidth and Read More......(read more)

Installing and Setting Up and Encoding for IIS 7 Smooth Streaming and Silverlight

Posted: 04 Feb 2010 11:17 PM PST

I heard someone saying they were having trouble setting up Smooth Streaming for IIS, so I wanted to try it myself. If you just want to see Smooth Streaming work, visit http://www.smoothhd.com/ for some sample demos. They'll adapt to your bandwidth and look as nice as they can. If you want to fake a low-bandwidth situation, you can use the player at http://www.iis.net/media/experiencesmoothstreaming and play with limiting the bit rate. Step 0: Got IIS? I've got IIS 7 because I've got Win 7. If your Win 7 installation doesn't have IIS yet, go to Programs and Features and click "Turn Windows Features On or Off" and select Internet Information Services. Don't forgot to go through the tree and turn on the things you...(read more)

ASP.NET MVC 2 RC 2 Released

Posted: 04 Feb 2010 09:10 PM PST

Today I'm pleased to announce the availability of Release Candidate 2 for ASP.NET MVC 2 . After receiving feedback from our last release candidate back in December, we decided it would be prudent to have one more release candidate that incorporated the feedback. You can read the release notes for everything that changed, there's not a whole lot. The biggest change in this release was described by Brad Wilson in his blog post on Input Validation vs. Model Validation in ASP.NET MVC . Also included in this release are an assortment of bug fixes and performance improvements. The window to provide feedback on this release is going to be very short as we are closing in on the RTM. If you want to provide input into this release, please do take the...(read more)

Developing the world’s first interactive Silverlight banner: Metia’s perspective

Posted: 04 Feb 2010 04:34 PM PST

January 2010 saw the launch the new Mass Effect 2 game, and EA Games in the UK wanted to mirror the game innovation with their digital marketing. Developing the world's first interactive Silverlight banner to be ad-served on the MSN platform was an ideal...( read more )...(read more)

Back to Basics - Keep it Simple and Develop Your Sense of Smell - From Linq To CSV

Posted: 04 Feb 2010 02:26 PM PST

I was working with a friend recently on a side thing they were doing. They wanted to create an "Export" function for some small bit of data and start it from their website. You'd hit a URL after logging in Some data would come out of a database You'd get a .CSV file downloaded You could open it in Excel or whatever. I spoke to my friend and they said it was cool to share their code for this post. This post isn't meant to be a WTF or OMG look at that code, as is it meant to talk about some of the underlying issues. There's few things going on here and it's not all their fault, but it smells . They are using a Page when a IHttpHandler will do. Not a huge deal, but there's overhead in making a Page, and they're...(read more)

Upcoming Deal on my Silverlight 4 Book for Blog Subscribers

Posted: 04 Feb 2010 02:37 PM PST

If you subscribe to my blog (you're here, and it's easy, just do it .. dooo itttt ;) click the RSS link above) there's a Manning deal on my book coming next week. It'll only be around for one day (Manning sets the terms, not me...( read more )...(read more)

No comments:

Post a Comment