Friday, September 12, 2008

TechEd Online Prism Session is live

Glenn Block (Microsoft) and I did a video interview on buidling composite WPF applications with WPF at TechEd this year, and that interview has now gone live. You can find it in various formats off the TechEd Online landing page or here is a direct link to the low res version.





Friday, September 12, 2008 2:43:45 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Tuesday, September 02, 2008

MSDN Magazine Article Live - Routed Events and Commands

My article on WPF Routed Events and Commands has gone live at http://msdn.microsoft.com/en-us/magazine/cc785480.aspx. In the article I discuss both how to use them, what is going on under the covers, and how to go beyond their limitations.

 

Also be sure to check out Glenn Block's article on Prism in the same issue: http://msdn.microsoft.com/en-us/magazine/cc785479.aspx





Tuesday, September 02, 2008 2:02:09 PM (GMT Standard Time, UTC+00:00)
Comments [1]  | 


  Monday, September 01, 2008

Custom Refactor Pro Plug-in - Convert Property

UPDATE: Thanks to some excellent feedback from Rory Becker, I changed my plug in from a Refactor provider to a Code provider. A refactoring should be structural and should not change the functionality of the code, whereas this plug in changes behavior. That just means the prompting is a little different as shown in the updated screen grab below. I also made it work for VB as well with some more help from the DevExpress folks. The code download at the bottom gives you the latest version.

Something I frequently find myself doing is starting a type out with simple, auto-implemented properties in C# along these lines:

public string Name { get; set; }

 

Then at some point I realize I want that type to implement INotifyPropertyChanged and have that property and possibly some of the others raise PropertyChanged notifications when they change. I got really tired of doing this manually, and my first way of automating it was to just create a code snippet for a property changed notification property, and I would overwrite the simple property with the property changed property.

But then I found myself needing to see if INotifyPropertyChanged was already implemented, if not add it, resolve it, see if the property already had a backing member variable, if not add it, yadda yadda... screaming for automation.

Unfortunately code snippets in VS are not that powerful, but fortunately I already use a tool that I think every developer should have on their desktop - CodeRush + Refactor Pro.

These two products are built on top of an extensibility engine called DxCore, which allows them as well as VS to be extensible based on a fairly straightforward API (that is all managed code, unlike the VS extensibility model).

In this case what I really wanted was an intelligent refactoring where I could just right click on an existing property, have it figure out if it had a member variable or not, if not add one, see if the type had INotifyPropertyChanged implemented, if not add it, add the using statement for System.ComponentModel if it was not already there, and add the PropertyChanged event with an anonymous method subscriber (so that you don't need to null check and don't have to worry about multithreaded race conditions with unsubscribing).

With a few hints and a starter project from my friends at DevExpress I got a Refactor Pro plug-in working in no time that does just that. I can invoke Refactor Pro (keystroke or a mouse click) on a simple property (auto-backing member or not) and get this:

refactor

When I invoke the conversion, it adds the INotifyPropertyChanged implementation if needed. So the following simple class:

public class Customer
{
    public string Name { get; set; }
}

 

Becomes this:

public class Customer : INotifyPropertyChanged
{
    string m_Name;
    public string Name
    {
        get
        {
            return m_Name;
        }
        set
        {
            if (value != m_Name)
            {
                m_Name = value;
                PropertyChanged(this, new PropertyChangedEventArgs("Name"));
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged = delegate { };
}

It also adds the using statement for System.ComponentModel if not already present. If I invoke it on another simple property in that class, it just adds the expanded property syntax and leaves the type declaration alone.

The code is a little too long to list here, but you can download the plug-in code here. If there is enough demand through comments, I'll do a follow on post with a walk through of the code.





Monday, September 01, 2008 10:41:58 PM (GMT Standard Time, UTC+00:00)
Comments [3]  | 

Accelerating Code Analysis and Improving Code Quality with NDepend

I've been working on a project for a customer where a fairly large pile of code has been written by an offshore vendor and I was brought in to do a code review and some clean up and verification of the logic. As I dove into the code, the smells started to become overwhelming.

Trying to work through the entire code base and figure out where to focus my clean up efforts first was a daunting task. However, a wonderful tool called NDepend came to the rescue. If you haven't ever heard of this awesome tool and you have oversight responsibility for a team of developers, you should really check it out.

I can't show screenshots here because the code has namespaces that reveal the client name, but you can find a number of screenshots on the NDepend site itself.

Basically NDepend will do a static analysis of your code base and help you identify everything from tightly coupled code containing too many dependencies (thus the name), but tons of other code metrics including line of code count, cyclomatic complexity, and others. It has a rich interactive UI for drilling into the code from the graphical charts that present you color coded views of where you need to focus as well as a web report generated view that you can view through a browser. You can analyze the code through a number of metrics, and it comes with a powerful query language called CQL (Code Query Language) that lets you look for particular patterns that you want to focus on.

I'd say this is a tool any technical lead, senior developer, or architect in charge of code quality should have in their toolbox.





Monday, September 01, 2008 4:31:08 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Friday, August 22, 2008

TechEd Online Session posted

One of the many events I had at TechEd this year was recording a TechEd Online video interview. That has finally gone online. The subject was Selecting the Right Client Technology.

You can find all of the TechEd Online sessions here:

http://msdn.microsoft.com/en-us/events/teched/cc676818.aspx

You can download / view my session from the following links:

Hi Res: 08_NA_Dev_techtalk_48_high.wmv

Low Res: 08_NA_Dev_techtalk_48_low.wmv

Audio Only: 08_NA_Dev_techtalk_48_audio.MP3





Friday, August 22, 2008 9:17:36 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 

Composite Application Guidance podcast is up

I recorded a podcast on Composite Application Guidance for WPF (aka Prism) this week and it just went live. If you are trying to get your head around how to build complex UI applications with WPF and have been considering Composite WPF as a way to help manage the complexity, you should check it out.

http://getpixel8ed.com/shows/prism





Friday, August 22, 2008 9:13:38 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 


  Thursday, July 03, 2008

Composite Application Guidance for WPF (aka Prism) Ships!

I'm psyched that the Composite Application Guidance for WPF thingy from patterns and practices has shipped. This is a project I worked on as a part time developer for Microsoft for the last 6 months. It is something that you should really take a look at if you are building complex WPF applications and care about decoupling, testability, and maintainability.

You can find some more high level info on Glenn Block's blog here, and my previous post here.

You can get the bits here.

The only thing I'm unhappy with is what the hell to call this thing. We called it Prism as a code name during development. For legal reasons, we could not use that as a release name. The p&p guys don't want us calling it CAG because there were some negative connotations with that acronym. It has a set of libraries in it that are collectively called CAL (Composite Application Libraries), but the thing that is shipping includes documentation, how-to's, a reference implementation app, and quickstarts, so the shipping thingy is a lot more than just CAL. Due to mainly internal politics at Microsoft, you can't call it a "product" because p&p is not a product team and therefore can't ship "products". p&p also makes some subtle distinction and says this is not a "Guidance Package", as some of their previous offerings have been called. Its a "set of Guidance", whatever that is...

So I'm continuing to call it Prism for now. Its a lot easier to say in a sentence than "the Composite Application Guidance for WPF set of guidance which is not a product or a guidance package but which you get a bunch of stuff with".

Anyway, check it out and expect some more detailed posts and possibly some screencasts showing how to use it.





Thursday, July 03, 2008 5:14:13 PM (GMT Standard Time, UTC+00:00)
Comments [3]  | 


  Saturday, June 07, 2008

TechEd Sessions Done - WIN306, SOA305, SOA308-TLC

Finished up my last three sessions yesterday with the subject sessions.

WIN306 was a talk on Prism with Glenn Block. You can get the code from the codeplex site. We will be releasing by the end of June.

SOA305 was on hosting and communications of Workflows. You can get the code here.

The final one SOA308-TLC was a TLC session on Building Workflow Services. You can get the code here.

Another year down, looking forward to TechEd next year in Los Angeles and hoping I will have about half the sessions and can have a little more fun and less stress next year. :)





Saturday, June 07, 2008 3:24:53 PM (GMT Standard Time, UTC+00:00)
Comments [3]  | 


  Thursday, June 05, 2008

TechEd US - 3 down, 3 to go

Three days down on TechEd, and no, not three more days to go, only one (for TechEd Developers). But I am giving 6 talks this year, and the numbers are the talks down and talks to go. I wanted to get the demos out there for the attendees now so they don't have to wait for the other sessions to be done tomorrow. Anyone is of course welcome to check them out.

The sessions I've given so far are:

WIN315 - Data Binding in WPF. I went through the types of objects you can bind to, how data contexts work, what a binding is and how to hook it up, along with some of its advanced properties. I went through collection view and data providers, converter and validation, and data templates.

You can find the demos for WIN315 here.

WIN 301 - WPF in Windows Forms and Vice Versa. This one covered the interop features for placing WPF controls in a Windows Forms app, and putting Windows Forms controls in a WPF app. I covered using the ElementHost control in Windows Forms and the WindowsFormsHost control in WPF. I also discussed some of the interop challenges and how to overcome them, and showed how to use property maps to drive appearance and behavior in the hosted control. I closed with showing the Windows Forms designer support for adding the ElementHost and configuring its hosted control.

You can find the demos for WIN301 here.

ARC304 - Selecting the Right Client Technology. This was an architecture track, so didn't spend a lot of time in the demos but more on the concepts of what are the driving factors to make you choose between smart client or browser-based apps, and from amongst WPF, Windows Forms, Silverlight, ASP.NET, and mobile apps. I also highlighted the client software factories that have been produced by patterns and practices at Microsoft to help manage the complexity of client applications.

You can find the demos (including links to the public web apps I ran) for ARC304 here. Also keep your eyes out for an Arcast session I recorded today on the same subject that recaps some of the key points I discussed in my talk in an interview format. I'll make sure to blog with the link when it goes live.





Thursday, June 05, 2008 10:48:19 PM (GMT Standard Time, UTC+00:00)
Comments [3]  | 


  Saturday, May 10, 2008

Upcoming TechEd Talks

It will definitely be a busy TechEd for me this year. I'll be giving six sessions at TechEd Developers Orlando in June, as well as spending a lot of time in the TLCs and at the RD booth..

The sessions are as follows:

Tue, 3 June, 11:30-12:30 AM: Vista Ask the Experts area

Doing Q&A on selecting the right client technology.

Tue, 3 June, 1:15-2:30 PM: WIN315 - Data Binding in WPF

This talk will cover the A-Z of data binding capabilities in WPF. I'll start by talking about the different kinds of data sources you can bind to and the interfaces those data sources need to support to have high fidelity data binding. Then I'll go through what data contexts are and how they allow you to flow data into you UI in a more decoupled fashion. Then I'll get into Binding objects and how you use them to hook up the data binding to your controls, and the many capabilities they expose. Then I cover navigating and filtering your data with collection views, and finally finish up with data validation.

Tue, 3 June, 4:00-5:00 PM: Vista Ask the Experts area

Doing Q&A on WPF Data Binding

Wed, 4 June, 10:15-11:30 AM: ARC304 - Selecting the Right Client Technology

This talk covers the spectrum of options that exist for building client UI applications today, helping you to make the right choice when getting started with a new UI application. I start by talking about the decision between smart client and browser based applications, drawing out the pros and cons of each approach. Then I get into each of the current technologies including WPF, Windows Forms, ASP.NET, ASP.NET AJAX, and Silverlight, and talk about the pros/cons, differences/similarities between each of those technologies.

Thu, 5 June, 4:30-5:45 PM: WIN301 - Windows Presentation Foundation in Windows Forms and Vice Versa

This talk covers the interoperability story between Windows Forms and WPF, which is a great one. I start with the motivations of why you would want to use interop as opposed to building a homogenous application in one or the other technology. Then I show how to embed WPF controls in a Windows Forms application, and Windows Forms controls in a WPF application. If it were just about the code required to do those things, I could give this talk in about 10 minutes. But of course, there are always other considerations and hazards to be aware of when doing interop between technology stacks, so I then let you know what those hazards are and how to address them.

Fri, 6 Jun, 8:30-9:45 AM: WIN306 Building Differentiated UI Applications Using Composite Windows Presentation Foundation

I'll be joining Glenn Block from p&p to code monkey for this session on using Prism to build composite WPF solutions. I've been working with the team part time building this, so Glenn was nice enough to invite me to help present.

Fri, 6 June, 1:00-2:15 PM: SOA305 - Getting Workflows Running and Talking in Your Applications

This talk covers the hosting and communications aspects of Windows Workflow Foundation (WF). You will learn how to set up the host environment for running workflows, how to leverage persistence and tracking, how to pass parameters into a workflow and get them back out when it completes, and how to make calls from the host application into the workflow. I'll also briefly discuss making service calls into and out from a workflow, but don't demo those in details because my TLC session (listed next) covers doing that in detail.

Fri, 6 June, 2:45-4:00 PM: SOA08-TLC - Developing Service Oriented Workflows

This talk shows you how to leverage the new WCF related capabilities in WF 3.5 to build workflows that particpate directly in your service oriented architecture. You'll see how to use the Receive and Send activities, the context bindings that take care of automatically routing incoming messages to the right workflow instance, and the WorkflowServiceHost class to host your workflows. This is a TLC session down on the show floor, and the rule of the game there is max interaction, and minimum if any PowerPoint. I in fact have only two slides planned, a couple architecture diagrams to couch the discussion, and the rest will be all code demos showing you how to really leverage this stuff.

I also plan to spend an hour after each session in the associated TLC area, and then most of the rest in the RD booth.

If you are going to be at TechEd, I hope to see you at one of my sessions. If so, stop by and say hi and let me know you are one of the few who actually read my blog. :)



Speaking

Saturday, May 10, 2008 2:18:47 PM (GMT Standard Time, UTC+00:00)
Comments [0]  | 

The evil sou file - fighting and winning with Visual Studio

There is an important trick I learned years ago that I always refer to as "The evil suo file" that I thought was more common knowledge than I guess it is. I realized this when I had to show it to my esteemed colleague Michele and she had never heard of it. It has happened to me dozens and dozens of times and dates back to VS 2003 or VS 2002 was when I first learned it, source long forgotten.

Here is the deal. If you are debugging and you are staring at the code and have something weird happening in Visual Studio. If you can convince yourself there is no way this could be happening, the code just can't/shouldn't be doing what you are seeing. In Michele's case we were stepping through the code, watching one line of code setting a property, seeing that no other code set the property through a breakpoint in the setter, and then a line of code read the property and it was a different value than last set.

One thing you should try is to close VS, delete the suo file in the solution folder, and open the solution and try it again. Like I said, dozens and dozens of times, this has made something really squirrely go away for me.

My general fighting and winning with VS is this. Convince myself that I am not just trying to blame VS for something wrong with my code. VS is a wonderful, powerful, amazing tool that makes our lives SO much easier than they used to be.

1) If VS is doing something weird, close and reopen, and try again.

2) If VS is still doing something weird, close delete suo, and reopen and try again.

3) If VS is still doing something weird, close and Clean Sources (delete suo and all obj/bin folders), reopen  and try again.

4) If VS is complaining about references to do with a project, remove it from the solution and add it back in. This happened with a customer this week where VS was insisting we were trying to add a circular reference when trying to add a ref to a particular project in the solution, and it was just lying. Removing it from the solution and adding it back in (and of course patching all the removed references from all the dependent project) fixed it.

5) If you have any add-ins, go to Tools > Add in manager and uncheck the startup box for all add ins. Close and reopen studio and see if the problem goes away. If so you may have a problematic add-in.

If those don't do it, it was probably your code in the first place.

Again, VS is an awesome dev environment. We really have it good. However, it is not perfect like most software. Don't waste hours chasing goblins in your code when it may just be a touch of gas in the VS belly.





Saturday, May 10, 2008 2:00:07 PM (GMT Standard Time, UTC+00:00)
Comments [4]  | 





















Sign In
Copyright © 2006-2007 Brian Noyes. All rights reserved.
designed by NUKEATION STUDIOS