CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Glenn Block

January 2008 - Posts

  • Tweaking the WCSF Validation Bundle

    Jarod has a nice post where he demonstrates how to reduce the number of postbacks that occur when using the ServerSideValidationExtender included as part of the Validation Bundle.

    Jarod demonstrates how to subclass the PropertyProxyValidator and override the EvaluateIsValid() method to not validate on a full postback. He then shows how to modify the ServerSideValidationExtender so that it tracks the current value for the associated control and only re-runs the validation if the value has changed. 

    If you are using the Validation bundle and you are experiencing too many postbacks, then check out his fix. Jarod's even dropped the full source with his fixes applied.

    Thanks Jarod!

  • Seattle CodeCamp Recap

    image

    Like all good things, sadly Seattle CodeCamp has come to an end. I had a great time and enjoyed hanging out with all the CodeCampers. I particularly enjoyed hearing about the different challenges customers are facing in their implementations. I also took part in more than a few discussions about our p&p deliverables including perceptions on the new Unity container and our newly announced "Prism" project. In general I heard no complaints and a lot of support for the new emphasis we've been putting on simplifying our deliverables and giving more options as to how you use them.

    As to my talks, well they certainly didn't turn out as I had planned ;)

    My WCSF talk was originally scheduled to be around an advanced topic of how to replace the default Session-State injection mechanism in the factory. However, I quickly switched gears and ended up doing an overview on Composite applications, Dependency Injection and the Web Client Software Factory. Notwithstanding the change in topic the session was really enjoyable. The coding was all ad-hoc and apparently I scored a few brownie points when it compiled the first time :) We ended the talk at a point when we could have dove into the original topic, however there wasn't enough time.

    My day two talk followed suit which switching gears yet again, this time covering the Smart Client Software Factory. As before the session was not planned, but I think it went well. At the end of this talk a few of the attendees requested that they would really like to cover the topic I originally planned (the DSA) now that they understand the basics of Smart Client Software Factory. It turned out that there was a free slot at 3 PM which I happily agreed to (though my wife on the other hand was less than pleased ;) )

    During the last talk we did a deep dive into how the Disconnected Service Agent works under the hood, and how you can go about replacing it's default mechanism which supports a simple Request-Response message exchange pattern, to instead use a Duplex channel. The one annoying part to the talk was that I was experiencing connectivity issues and the connection monitor infrastructure was working too well keeping my application in an off-line state. We finally got around this by connecting to the internet through a USB connection to one of the attendees cell phones :)

    Actually the connection monitor does allow you to configure a DesktopConnection which you can use to simulate connectivity even if you are not connected. I spent about 30 minutes trying to get this configured before my talk (as I realized it might be a problem), but I was unsuccessful. Anyway, all and all I think the talk went well though it had a few hiccups, but hey this is CodeCamp :)

    You can find all the code and decks for the talks (both the originally planned and the actual ones delivered) posted on a skydrive here.

    • "Custom Session State Injection" contains the sample for my original WCSF talk. Take a look at the helpers folder in the Shell project to see the custom mechanism. In the web site, GetSessionValue.aspx and SetSessionValue.aspx demonstrate the functionality.
    • "DSAQuickStart" contains the original Disconnected Service Agent Quickstart that uses the Request-Response message exchange.
    • "CustomDSAQuickStart" contains the modified version that uses a WCF Duplex channel to allow multiple callbacks. When you run the code you will notice only a partial list of restaurants appears to be returned. This is because we changed the code in the session to do a call back every 5 items. The client app however was not written to deal with multiple responses, so the second callback overrides the first.
    • "DemoApp" contains the account site that we build in the WCSF overview talk. Within the sample we show recursive DI in that the AuditingService has a dependency on the AuditingTransportService.
    • "DemoClient" contains the simple (and I do mean simple) app we through together in the SCSF talk.

    Note: You'll need SQL Compact to be installed in order to run the DSA samples which are built on VS2005. If you upgrade the projects to VS2008 they will work, but you will need to use Upgrade utility to convert the compact DB to the latest version. Aside from the DSA, all the other samples are in VS2008.

    Also I have added a few links below to blog posts where you can read about the different techniques.

    http://staff.southworks.net/blogs/siacomuzzi/archive/2007/09/24/Enabling-WCF-Duplex-Channel-in-DSA-solution.aspx

    http://staff.southworks.net/blogs/siacomuzzi/archive/2007/10/05/How-to-replace-our-Sessions-State-strategy-in-Web-Client-Software-Factory-with-a-custom-one.aspx

    Thanks to everyone for making it a fun event. Until next year!

  • Seattle CodeCamp talks

    I forgot to post on this, well better late than never. This weekend I'm speaking at the Seattle CodeCamp on WCSF and SCSF. Actually Day one is over, which leaves one more talk left tomorrow on using SCSF and the Disconnected Service Agent.

    Session state injection your way with WCSF - Saturday, 1:45 to 3:00 PM

    The StateValue mechanism in Web Client Software Factory provides a nice clean way of injecting values to and from ASP.NET's session state. One of it's big advantages is it provides for testability, allowing the values to be substituted in a unit test. Another big advantage is that it allows a declarative way for values from ASP.NET Session's state to be plugged in. But what happens if you aren't relying on ASP.NET Session and have a custom or third-party mechanism? Are you "up the creek without a paddle"? Actually no. Come to this session and I'll show you to "Have it your way" and make our Session State strategy bow to submission.

    Track: ASP.NET

    Black Belt DSA, building Duplex Agents - Sunday, 10:45 to 12 PM

    The Disconnected Service Agent in the Smart Client Software Factory allows you to queue up web service calls to a remote server when disconnected. These calls are played back once the connection returns. This is great for simple message exchange patterns that instantly return a response. However, it does not help you in the case of a long-running operation in which the response is to be returned out-of-band. Come to this session and see how we can tweak the DSA to allow it receive an asynchronous response. We'll utilize a WCF Duplex channel to provide an agent that will make a call and go about it's merry way until it receives a call back from the server. This functionality is beneficial beyond offline scenarios, I'll show you how you can also use this technique to faciliate exchange patterns with multiple responses. For example requesting a large result set of data that is returned in a chunked fashion over multiple successive calls. If you are developing with SCSF / CAB, don't miss this session.

    Track: WCF and WF

    Today I delivered my WCSF talk which quickly changed from what I had intended to speak on into a deep dive into WCSF. I guess you could call this Agile presenting. Although I didn't deliver the topic I expected, the session went well with a very small but engaged group. A real treat for me was attending Brad Wilson and Jim Newkirk's talk on XUnit.net. In addition to learning about a lot of the history behind NUnit, I took away the following: The problem with TDD is [Test], and it's a brave new world of [Fact]s and [Theory]s. Another treat was being able to geek out with a bunch of the attendees including my work buddies.

    I'll post decks and code from the talks after the conference. Hope to see you there!

  • Spiking around Notification and Generics Part I

    As part of the new work we are doing in the new Composite WPF, we're looking at notification (Pub/Sub). In the CAB world, the way we handled notification was via our EventBroker functionality which provides a loosely coupled mechanism for notification.

    Essentially the way it works is this, to publish, you create an event, then you decorate the event with the [EventPublication] attribute. As part of the attribute you specify an event topic, which is simply a string that represents the name of the event. You also specify a scope which is either the current WI, global or module level. For the subscription,  you create a handler either in the same or a different module and decorate it with the [EventSubscription] attribute. In the subscription you specify the topic, as well as the which thread you'd like to have the event marshalled to.

    At runtime, the EventBroker strategy plugged into ObjectBuilder strategies come into play to wire up the publishers and subscribers in an indirect fashion. The actual brokering is handled by the root WorkItem so don't go bother looking for an EventBroker, because you won't find one :). The Root WI is subscribed to all the event publishers and holds WeakRef pointers to all the event subscribers. Then whenever the publisher event is fired, the Root WI handles that event and then invokes the delegates on each of the references. There are other ways to do this without having OB do all the magic for you and you can wire things up manually to the Root WI yourself. The most common method is through the autowiring.

    Here is an illustration of how this all works

    image_thumb8_thumb[3]

    Examples of how this looks in code are below.

    [EventPublication("topic://EventBrokerQuickStart/StartProcess", 
       PublicationScope.WorkItem)]
    public event EventHandler<DictionaryEventArgs> StartProcess;
    
    [EventSubscription("topic://EventBrokerQuickStart/StartProcess", 
       Thread = ThreadOption.Background)]
    public void StartProcessHandler(object sender, DictionaryEventArgs args)

    One of the major benefits of EventBroker is that it keeps the publishers and subscribers completely agnostic from one another, unlike the traditional .NET event model in which the publisher explicitly has references to all of it's subscribers. The facility we provided in CAB was very powerful, however there have been more than a few criticisms such as those in Jeremy's "Build your own CAB" post. Within the post he makes the following main points about our implementation.

    Too complicated / difficult to debug, relying on attribute magic.
    Too generic with semantics that do not clearly indicated intention.

    I have also heard these additional concerns.

    • Too tightly coupled with CAB.
    • Mixing of concerns, should not be handled by the WorkItem.
    • Scopes are either too granular or not needed.
    • Performance is impacted by having to use reflection on each build-up to locate publishers and subscribers.

    Jeremy then goes on in his post to describe how he implemented event aggregation in StoryTeller using two sets of interfaces, one for the publisher and one for the subscriber. The subscriber interface simply contains an interface that defines a specific for a set of methods for handling the notifications, for example Queued, Completed, etc.

    public interface ITestObserver {   
       void StateIsUnknown(Guid testId);
       void StartedRunning(Guid testId);  
       void Completed(TestResult result);
       void Queued(Guid testId);
    }

    The publisher interface includes methods for firing each of the tests.

    [PluginFamily("Default", Scope = InstanceScope.Singleton)]
    public interface ITestEventPublisher {
       void RegisterForTestEvents(ITestObserver observer, Test test);
       void UnRegister(ITestObserver observer, Test test);   
       void PublishResult(Test test, TestResult result);   
       void MarkAsQueued(Test test);  
       void MarkAsUnknown(Test test);   
       void MarkAsExecuting(Test Test);   
       TestResult GetLastResult(Guid testId);
    }

    You can see the parameters for the methods on the observer are not the same as those passed in to the publisher. This decoupling is a good thing in that it allows the publisher to transform the data it receives before it gets to the subscribers. In the case of CAB this is not possible since the signatures have to match and the whole pipeline of the event is invisible from the caller.

    Within the publisher he keeps a dictionary of observers. As an observer subscribes for notification, they are added to the dictionary. Then In each of the publishing methods he reads through that dictionary of observers and then invokes the correct method based on what is being published. For example below, is the code for MarkAsQueued.

    public void MarkAsQueued(Test test) {   
       test.Status = TestStatus.Queued;
       foreach (ITestObserver observer in GetObservers(test))   {
          observer.Queued(test.TestId);   
       }
    }

    The benefit of this explicit strongly typed approach is immediately obvious when you see how cleanly the code looks for subscribing, notifying and handling the events.

    publisher.RegisterForTestEvents(this, subject);
    publisher.MarkAsQueued(test1);
    
    public void Queued(Guid testId)
    {   
       ...
    }

    this as opposed to

    [EventPublication("topic://StoryTeller/Queued", PublicationScope.WorkItem)]
    public event EventHandler<Test> MarkAsQueued;
    
    [EventSubscription("topic://StoryTeller/Queued", Thread = ThreadOption.Background)]
    public void QueuedHandler(object sender, Test args)

    Jeremy's version for one thing has type safety. Because everything is strong-typed, if you make a change to the signature of say Queued, then the code actually breaks at compile time. Not so for the EB case, where if I change the signature completely, it won't break until runtime. Another benefit is that the event signatures are easy to browse and locate. I can even put the interfaces in a namespace that will be easy to discover. Using the class viewer / intellisense, I can quickly see what the available notifications and the parameters are. However, in the case of EB, I have to know by a constant name, which associated class represents the event args. This requires that I have some kind of convention, keep a master list somewhere or hunt through the code to track down which signature to use. As CAB applications span many modules (assemblies), this could be an arduous task.

    And so armed with all the feedback and Jeremy's post, I decided to spike for Composite WPF to see if we could come up with a more loosely coupled and intuitive method for notification than what we had delivered in CAB. What came out of that spike was a generic Notification service that allows publishers and subscribers to explicitly wire themselves up. I took advantage of generics and .NET 3.5 lambda magic to "have my cake and eat it too" providing the benefits of Jeremy's approach without having to hand-code the publication mechanism.

    I also introduced a generic scope concept to allow you to have notifications at a particular scope level. Scoping is a important part of the CAB infrastructre, however it was limited. In this case the Scope is entirely generic allowing you to be as coarse or fine-grained as you see necessary and to choose what you use to represent Scope. Scopes are hierarchical so I can have a ParentScope that contains a ChildScope. This means when I publish at the ParentScope all the subscribers in the ParentScope and ChildScope will be notified. If however I only publish at the ChildScope than only the ChildScope will be notified. To put this in the real world, imagine a batch of orders being one scope, and each order within the batch being a separate child scope. When I notify the batch, all the orders also get notified.

    You'll notice when you look at the mechanism that the Notification service uses the same signature for the publisher and subscriber as it is generic. This however can easily be the infrastructure that is then called by something similar to the ITestEventPublisher described in Jeremy's post.

    Anyway, I'll discuss how all this works in a later post. It's late and i need to get to bed. But to wet your appetite, here's the code from one of the unit tests. I've also attached the code.

     

    [TestMethod]public void When_Publish_Method_Is_Called_At_Parent_Scope_Then_
       Child_Scope_Is_Invoked()
    {   
       MockRepository mocks = new MockRepository();
       NotificationService<string> publisher = new NotificationService<string>("parent");
    
       IStockPriceEventManager parentSubscriber = 
          mocks.CreateMock<IStockPriceEventManager>();   
       IStockPriceEventManager childSubscriber = 
          mocks.CreateMock<IStockPriceEventManager>();   
       
       StockPriceArgs args = new StockPriceArgs(5);   
       
       Expect.Call(parentSubscriber.StockPriceChanged(args)).Return(true);
       Expect.Call(childSubscriber.StockPriceChanged(args)).Return(true);
    
       publisher.Subscribe<IStockPriceEventManager>(parentSubscriber, "parent"); 
       publisher.Subscribe<IStockPriceEventManager>(childSubscriber, "child");
       publisher.AddChildScopes("parent", new List<string> { "child" }); 
    
       mocks.ReplayAll(); 
       
       publisher.Publish<IStockPriceEventManager>(x => x.StockPriceChanged(args), 
          "parent");   
       mocks.VerifyAll();
    }
  • What's wrong with the ALT.NET lists?

    Oren and I were just having one of our many discussions, and we got to the subject of the list. After much thought I realized what the real problem with the lists stems from:

    Human beings are in it!

    OK, flame on.

    Posted Jan 05 2008, 02:02 PM by gblock with 4 comment(s)
    Filed under:
  • How we work in the patterns & practices client program

    Several weeks ago, I was interviewed along with Blaine Wastell (Program Manager) by http://howsoftwareisbuilt.com around how be operate in patterns & practices, specifically in the client program. We talk about both the product planning / strategic side as well as how the dev team functions. We also talk about the future of p&p, and the shifts we're making in how we deliver our guidance. As always, I monopolize the conversation ;)

    Check it out here....http://howsoftwareisbuilt.com/2007/12/05/interview-with-blaine-wastell-and-glen-block-patterns-and-practices-microsoft/

    Oh, and for the record, my name is Glenn not Glen.

  • IoC.AddComponent<IBloggingStrategy, CodeBetterBloggingStrategy>();

    public class BlogIntro {
      public BlogIntro(IBloggingStrategy blogger) {
        blogger.Post(“Hello CodeBetter”);
      }
    }

    Hello CodeBetter!

    Hi guys, I am excited to be joining the CodeBetter community. Rather than bore everyone with a lot of history, I’ll give a quick intro. I am the product planner for the client program in patterns & practices at Microsoft (apparently the first MSFTie to join the blogging ranks here). You probably heard of some of our deliverables like CAB, SCSF, WCSF, and Mobile Client. As product planner I define the roadmap for the client program and work with the engineering team to provide them the vision for what we deliver. We’re an agile team (XP/Scrum) and I am the customer proxy. That puts a big weight on my shoulders, so to relieve it I do my best to connect with as many customers as possible.

    I’ve been at Microsoft for about two years in different planning roles. In years prior, I worked professionally as an Architect / Lead Dev / Dev for about 10 years mostly on the Microsoft platform, but with a short stint in the Java / Linux world. Outside of a professional capacity, I have been coding practically since I could ride a bike. I spent several years working with various OS offerings like NUnit, NANT, NVelocity, etc. I missed the whole NHibernate / Castle wave (until recently), though I did lead a team that built Yet Another ORM Framework (before NHibernate was released). Needless to say, that experience changed my view of inheritance based frameworks and I no longer think of them as "all that".

    So why code better? About 7 years ago I got really serious about my coding. I let go of all my old VB inspired see how fast I can hack something together and started really looking at Software Development as a craft. My first stop was learning about design patterns, my next stop was getting in to refactoring to those patterns (and refactoring in general), and my third stop was agile development. Since then, I have constantly been a quest to “code better”. In the last year one of the places that has really helped in that quest is CodeBetter.com. Blogs that I have frequented here are those of Jeremy Miller, David Hayden and Jeffrey Palermo as well as the infamous Mr Scott Bellware.  The other place that has helped greatly has been working with my team at patterns & practices. At p&p, I am learning new techniques each day and constantly being reminded just how much I don't know. We’re perpetually seeking to improve, reevaluating how we develop, refactoring our code and refactoring our techniques.

    I am hoping to use this blog to share our team experiences as we continue our journey. This does not mean I’ll be using this blog specifically to promote p&p deliverables, I won’t as my other blog is for that. I’ll also probably share some of my own personal experiences as I explore different tools and OS offerings like Castle, StructureMap, RhinoMocks, etc as well as delve into approaches to Software Development like BDD, DDD, etc. I have a personal goal to learn Ruby this year and to build something of meaning to benefit developers. It’s quite likely that I’ll blog about some of those adventures as well. I'll also (based on prodding from Oren) probably share a few of the pains I've experienced along the way throughout my twelve years as a professional software developer.

    Let me know if there’s anything in particular you’d like me to talk about on this blog. I value your feedback so please don't hesitate to share your thoughts (as long as it's in a constructive fashion)

    Thanks for inviting me!

    Posted Jan 03 2008, 12:21 AM by gblock with 14 comment(s)
    Filed under:
More Posts

This Blog

Syndication

News

View Glenn Block's profile on LinkedIn

Me