Tuesday, March 2, 2010

Book Review: Introducing .NET 4.0

I recently finished reading Alex Mackey’s book, “Introducing .NET 4.0 With Visual Studio 2010”.  VS2010 won’t be launched until April 12, 2010, which is still just over a month away, but I’ve been champing at the bit, ready to dive into .NET 4.0 for months now.  Mackey does a great job of whetting my appetite without drowning me in the minutiae of each new or improved feature. 

.NET 4.0 is all about improvements to pieces that have been slowly coming together over the past few years.  There have been a number of out of band releases to the .NET Framework since .NET 3.5 launched.  .NET 4.0 enhances a lot of those releases, and, in some cases, completely goes back to the drawing board.  There are a few new features that will make developers happy, but for me, the money is in the things Microsoft made better. 

Mackey assumes you have a good knowledge of .NET, as this book targets what is new since 3.5.  He includes things which were included in .NET 3.5. SP1, since not everyone may have gotten into that yet.  I was pleasantly surprised at how much of the SP1 functionality we have actually put to use here, and was able to skim those chapters.

There are parts of the book that were finished before the actual functionality of VS2010 or .NET 4 were finalized, but that’s what you’ll get when you buy a book on a product before the product is released. Caveat Emptor.

By the end of the book, I was able to make some decisions on what functionality to target for further research.  My bets are on three areas that will have the biggest payoffs for my team and my customers:

  • MEF (Managed Extensibility Framework)
  • Entity Framework 4.0
  • Windows Workflow 4

With MEF being such an integral part of Office 2010, a good working knowledge of it is essential to provide process enhancements for our customers.

We use Entity Framework 1.0 in just about every project we work on, and the leap to 4.0 should resolve a number of significant issues and code costs that we have encountered in the past year.  I expect to see a large effort reduction in application development costs due to this upgrade.

If the improvements to Windows Workflow are as good as advertised, then I believe WF will go from shunned cousin to an accepted member of the development family.  There’s a lot of power in WF, but the previous implementation was lacking.  I stopped considering the previous releases as viable last year after a few false starts, but I have much higher hopes for it going forward with V4.

I recommended Introducing .NET 4 to my colleagues as a good getting started guide, and directed some to target certain chapters to match up with the type of work they typically do, or areas where they have yet to become involved in to give them a 40,000 foot view. 

I will probably go out and buy other .NET 4 books as they become available, but will focus on the three areas above as they will have the biggest impact to my architecture choices in the coming months. 

Mackey helps to give that guidance, and gets me excited for the new features.  That’s what I want in an introductory level book.

Cross Site Blogging

Today, I’m proud to announce the launch of a revamped Palador.com web site.  Palador is the consulting company that I work for, and as the Senior Application Architect there, I will be doing my part to blog there, as well as here, and my personal blog as well.  That’s a whole lot of blogging, but I actually get paid to blog there, so hey, I’m okay with taking that on.

Occasionally, I will cross post blogs here and there.  Sometimes things will be posted there and not here, depending on the topic. We’ll see how it goes.

We’ll have five or six of us posting entries on a variety of topics, which is cool as it just goes to show how diverse our skill set is here. 

Anyway, take a spin over to the new site and let us know what you think.  I wrote or edited a lot of the copy there, so if you find issues, let me know.

Monday, February 1, 2010

Living the Evolved Digital Life

Okay, it’s been a couple of months since I evolved my digital life, cut the cord to Premium Digital TV, and got my house in order.  So where am I now?

1.  Lesson Learned:  You cannot run digital video over a wireless router, especially if you have more than 1 wall to go through.  Bite the bullet and pull the ethernet cable if you can.  I was always at 4 bars with the XBox 360, but the router would shutdown every hour or so (sometimes 3 times in a single episode of CSI).  Pulling the cable through the floor was a PITA, but worth it now.

2.  Spend some time and tune your Harmony remote.  It’ll take a lot of time to get it right.  I still have work to do on mine, but each improvement is noticeable, and after a while, you can’t believe you used to use 3 (or 4) remotes.  That said, sometimes it still is a big pain, especially when the kids are sleeping and you switch video inputs, and the sound is cranked up and you can’t get back to turn down the volume down fast enough.  I find myself planning my moves with the remote.

3.  Make sure you have enough disk (at least 1TB) on your Media PC.  I still haven’t hooked up my HD tuner because I haven’t wanted to spend any more money on the setup right now to add enough disk to record HD shows.  I’d also like to have a dedicated Media PC with faster processors that can also host PlayOn, but since we have multiple laptops floating around the house, most of the time the PC is a dedicated Media machine.

4.  2010 will be the year Internet TV really takes off.  My wife says we were probably a year or two early jumping online, and maybe we were.  I’m looking at things like Boxee Box and thinking that was probably what I wanted.

5.  We miss having a channel guide on our TV.  We currently have to switch over to the Media center to get it, and because we get more channels on the cable than what the media center allows us to see, we don’t always know what is on at any given time.  This might be worth a little more research.

6.  I don’t use Hulu near as much as I thought I would.  I just don’t want to go back and watch old shows that often.

7.  I watch a lot more Netflix and am willing to break movies up over multiple nights if I need to.

8.  The kids don’t miss on demand that much.  We have a few videos laying around at home, and a few lined up on Netflix.  That seems to get us through rainy Saturday afternoons.

9.  Maybe I’ve just been busy the last couple of months, but I am watching less TV.  That was a side effect I hoped for.  I’m reading more, and watching better TV when I am watching it.  When there is a little resistance to the inertia of just keeping the TV on all evening, you find other things to do pretty quickly.

10.  I haven’t sprung for the XBox Live Gold Membership since I get everything I want through PlayOn, but as I was watching a movie last night, I definitely noticed that the hop across my HomeServer through PlayOn left dark scenes a little blocky.  For $40 a year, it might be worth it to get the membership.

These things always turn out to be a little more complicated than you think they will.  I feel pretty good about it now, but it’ll be a few months before I really forget the pain of the conversion.

Thursday, January 14, 2010

.Net 4.0 and Azure

We were mapping out a release schedule for one of our Azure based applications today, and a major part of the application needs to be completely refactored to eliminate tight coupling between our WPF client and our server application.  This coupling is exacerbated by the inability to properly XML serialize some of our Entity Framework 1.0 objects due to the recursive traversal capabilities of EF 1.0.  We’d like to push the refactor back until EF 4.0 is available, but that brought up the question of when .NET 4.0 would be available on Azure. 

There is no set release data for Azure with .NET 4.0 support at this time. However, Scott Guthrie mentioned on his blog on Dec 17th that

“We are working with the Azure folks right now to try and get .NET 4 installed on it as soon as possible.  Unfortunately I don't have an exact ETA yet.”

However, the Azure team this week (today since Thursday is their deployment day) did a release to include an ‘OS Version’ attribute for roles so you could specify a particular Azure Build level when deploying. It will default to the most current version if you don’t set it, so it is a way to ensure that if you don’t want to be upgraded, you won’t be. Right now, they only support one version of the Azure OS. This has to be a precursor to the .NET 4 rollout, and something we have been trying to get them to include since our very first meeting with the Azure Team back in November 2008.  I haven’t looked at the feature in detail, but I’m glad they’ve addressed the concern.

My guess is that they will have to spin up .NET 4.0 support well before the commercial launch of .NET 4 because of the integral role of Azure in VS2010, and that in order for final testing to happen, they’ll have to allow full .NET 4.0 Azure deployments. Kind of a chicken and egg thing.  Stay tuned.

Setting up VS2008 For Windows Mobile 6.1 Development

There are a few tricks to setting up your PC for Windows Mobile 6.1 Development that are needed to get moving.  Of course some of this will depend on exactly what you want to do in Windows Mobile.

My project was pretty simple.

  1. Create a Windows Mobile Forms app that interfaces with a Motorola M9090-G scanning device that allows a user of the scanner to scan their employee badge barcode, a barcode for a shipping document, and a barcode for a series of packages.
  2. The user will scan a large number of packages, and then send their scan records in a batch to a central database for further processing.  The user may or may not be close to a wireless access point at the time of the scan.
  3. The app has to be fast.   The folks using this device will fly through dozens of packages a minute, and there will be multiple scanners working to unload a truck, but there are logical gaps in the loading and unloading where the app can upload to the database.

It’s pretty obvious I needed a client cache for the data.  I chose Microsoft SQL Server CE.  For the backend data store, we’re using SQL Server 2008 (with Change Tracking turned on)

I didn’t want to custom build a synchronization methodology, and since I played with Microsoft Sync Services a bit last spring on another project, it seemed like a good place to start.

First off, VS2008 SP1 comes with a number of emulators built in, but no Windows Mobile 6 emulators.  In order to get the right emulators installed, download the following, and install in the following order.  You’ll need to shut down VS2008 to complete this install.

  1. Windows Mobile 6 Profession and Standard Software Development Kits Refresh
  2. Windows Mobile 6 Professional Images (USA).msi
  3. Microsoft Windows Mobile Device Center Driver
  4. Microsoft SQL Server CE for Devices
  5. Microsoft Synchronization Services for ADO.NET for devices – note that you cannot user Sync Services 2.0, as it is not device ready yet.

You should now be able to fire up VS2008 and create a new Smart Device Project.  Make sure you set it up for Windows Mobile 6, or you’ll not have all the options you need, and will have to start over.

One mistake I made, was not realizing that there is a different version of Microsoft SQL Server CE for Devices than for PCs.  You will need to download the correct version to get everything to work.

I strongly suggest creating two solutions for this type of an application.  One for the Mobile client, and one for the WCF Service, whether it be a Windows Service or a Web Service.  It makes it a lot easier to debug, and helps to ensure that you don’t try to deploy Mobile targeted assemblies to the server and vice versa.  The IDE should prevent you from doing it, but it doesn’t hurt to take this approach anyway.

I like writing code, but I like getting projects done even more.  So if I find code out there that works, I’m not afraid to put it to use.  There were a couple of projects I found that really help to do some of the heavy lifting:

  1. SyncComm on Codeplex.  This provides you with all the plumbing you need to get Windows Mobile Sync working in your project.  If there is one thing I would change (and did) in the project, it was to break the ClientService.cs up into another partial class to remove the customizations that were done to it.  I have found three methods that I moved into a separate file.  Otherwise the code gets wiped out when you regenerate it.  Cost me an hour of work.  See code below.
  2. Custom Message Encoder: Compression Encoder on MSDN.  Download the sample there.  The download link is trickily hidden under the title of the article.  This provides you with all kinds of samples.  The one you want to go to is under <installroot>\WCFSamples\WCF\Extensibility\MessageEncoder\Compression\CS.  Take the GZipEncoder and add the project to your server solution.
public ServerClient(System.ServiceModel.EndpointAddress endPointAddress, BindingType bindingType)



        : this(GetBinding(bindingType), endPointAddress)



    { }



 



    static Binding GetBinding(BindingType bindingType)



    {



        Binding binding;



 



        switch (bindingType)



        {



            case BindingType.Basic:



                binding = CreateDefaultBinding();



                break;



            case BindingType.Compressed:



                binding = CreateCompressionBinding();



                break;



            default:



                throw new ArgumentException("BindingType value not excepted");



        }



 



        return binding;



    }



 



    //NOTE:



    //set compressed endpoint binding custom properties here



    public static Binding CreateCompressionBinding()



    {



        // Create a CustomBinding



        var customBinding = new CustomBinding();



        // Create a compression binding element



        var compressionBindingElmnt = new CompressionMessageEncodingBindingElement();



        // ..and add to the custom binding



        customBinding.Elements.Add(compressionBindingElmnt);



 



        // Create an HttpTransportBindingElement and add that as well



        var httpBindingElement = new HttpTransportBindingElement();



 



 



        //TODO



        //Set here desired values. Take care to match such values 



        //in app.config in SyncComm host project



        //max buffer size



        //httpBindingElement.MaxBufferSize = int.MaxValue;



        //max received message size



        //httpBindingElement.MaxReceivedMessageSize = long.MaxValue;



        //max buffer pool size



        //httpBindingElement.MaxBufferPoolSize = long.MaxValue;



 



        customBinding.Elements.Add(httpBindingElement);



 



        return customBinding;



 



    }




In order to get WCF to connect from the Windows Mobile 6 Emulator to a Web Service on the local host, you’ll need to follow the steps listed by Chris Brandsma on StackOverflow.  This is critical and can cause a lot of frustration if you don’t do it.



So as of today, I have a client on my Windows 6 Emulator, a Web Service, and the basic data flowing, though I have a lot of work left to do to test and refine the processing, and to test on an actual device.  I’m sure I’ll find a few more issues, but I wanted to note what I had done to this point, just in case I need to replicate the process on another PC or build server here in the near future.



Let me know if this doesn’t work for you.