2.23.2010

Creating my first TFS 2010 Build

My work this iteration on my project is setting up a CI build and then migrating all our POC code to the solution.

Right now I am creating a simple build as practice for setting up the actual build.

I am approaching this from a complete n00b when it comes to creating a TFS build. I have created builds before but they have been small and just simple MSBuild files. This is the first time I am using TFS and creating not only a build but a continuous integration environment.

I created a Team Project and added a simple C# project to source control. I then looked at the Team Explorer and noticed that there is a Builds section under my project. Intuitively I right clicked and found where I can create a New Build Definition.

image

I looked at the options available to me on the Build Window and noticed a Trigger section. Investigating the Trigger section allowed me to select what triggers this build. Oh look a CI trigger that builds after each check-in!

image

I then had to set an output folder so I created a folder on our build machine and set the folder to that.

image

And then I was done.

I do have to say we already had a TFS Build Controller setup so I can’t comment on that for now.

I then ran a couple of experiments. I first added a class foo to my project and checked in. I then double clicked on my Build under the TFS explorer and was given two reports. One report showed the current queued builds and the other had a list of the completed builds.

After I ran my first successful build I then made a compile error and checked it in. I then had a failed build.

image

When I double clicked the failed build I got this UI.

image

I then created a test project and then made a failing test. Now my build looks like this:

image

And when I double clicked I got this report.

image

So that was a real quick run through with creating a CI build with TFS 2010. I have to say… I was surprised that it was that easy. I am continuing my work with the build but it looks like the simple scenario was incredibly easy!

2.18.2010

ISubscribe

I believe Jimmy Bogard has a similar technique (IHandler<T>) with ASP .Net MVC but I thought I would still share the convention I’ve been using to wire up subscriptions to the Prism Event Aggregator.

Whenever an object is built with StructureMap, it goes through all the TypeInterceptors. I have a SubscriptionTypeInterceptor:

public class SubscriptionInterceptor : TypeInterceptor
    {
        public object Process(object target, IContext context)
        {
            var eventAggregator = context.GetInstance<IEventAggregator>();

            // Get interface ISubscribe<E>
            var interfaces = target.GetType().GetInterfaces().Where(i => i.Name.Contains("ISubscribe"));

            foreach (var type in interfaces)
            {
                // typeof(E)
                var eventType = type.GetGenericArguments()[0];

                var setupMethod = GetType().GetMethod("Setup");
                setupMethod.MakeGenericMethod(eventType).Invoke(this, new[] { target, eventAggregator });
            }

            return target;
        }

        public bool MatchesType(Type type)
        {
            return type.ImplementsInterfaceTemplate(typeof(ISubscribe<>));
        }

        public void Setup<T>(ISubscribe<T> subscriber, IEventAggregator eventAggregator)
        {
            eventAggregator
                .GetEvent<CompositePresentationEvent<T>>()
                .Subscribe(subscriber.Subscribe);
        }
    }

So it finds all the ISubscribe<T> interfaces the target implements and then subscribes the target to the event T in the event aggregator.

public interface ISubscribe<E>
{
    void Subscribe(E e);
}

A simple example of usage:

public class SecurityController : IController,
                                  ISubscribe<RequestUserLoginEvent>
{
    public void Subscribe(RequestUserLoginEvent e)
    {
        Publish.Event().ShowModal<IRequestUserLoginViewModel>();
    }
}

CodeCast #68 : Convention over Configuration

I recorded a podcast with Markus and Ken on Tuesday and it was published last night. :)

We talked about Convention over Configuration using tools like Structure Map, PostSharp, Prism, etc

You can download the podcast using itunes or online at:

http://www.code-magazine.com/codecast/index.aspx?messageid=0001bf99-1394-45c2-8949-388c673ac7a5

2.17.2010

View + ViewModel + ViewRegistry

In preparation for the Advanced WPF Workshop on Saturday Feb 20th, I thought I would throw together some blog posts around some techniques / code I will be sharing. JP asked the other day whether Views should have references to their ViewModels or should ViewModels have references to Views. Unfortunately twitter is a great medium for asking this question but not the best medium for answering the question.

I am going to try using the dry marker board as a form of communication with my blogs. I have little patience for lining up pretty lines and colored boxes with Visio or Power Point. A dry marker board is fast and allows for a free flowing expression of my ideas.

Let me try to diagram out how I currently manage my Views and ViewModels.

IMG_0356

  1. We ask the StructureMap container for the ViewModel
  2. The VM instance is intercepted by a ViewModelTypeInterceptor
  3. Inside the VMTypeInterceptor
    1. Get the V for out VM from the container
    2. Get the ViewRegistry from the container
    3. Register the V with the VM in the ViewRegistry
    4. Return the VM
  4. And finally our VM is returned being registered with a V in the ViewRegistry

In short my ViewModel has no reference to my View, my View has no reference to my ViewModel (beyond setting the DataContext), and my View Registry registers the mappings between View and ViewModel.

The best code to look for this is in the ViewModelInterceptor:

public class ViewModelInterceptor : TypeInterceptor
{
    public object Process(object target, IContext context)
    {
        var name = target.GetType().Name;

        var view = context.GetInstance<IView>(name);

        context.GetInstance<IViewRegistry>()
            .RegisterViewWith(target as IViewModel, view);

        return target;
    }

    public bool MatchesType(Type type)
    {
        return type.CanBeCastTo(typeof (IViewModel));
    }
}

Advanced WPF Workshop

On February 20th from 9 am (central) until we get bored… I guess 1pm, we will be having a free Advanced WPF Workshop here at EPS.

Let me emphasize ….

FREE!!!!!!

When : Feb 20th 9am - 1pm+

Where : EPS Office

6605 Cypresswood Dr, Suite 300

Spring, TX 77379


View Larger Map

And online at : https://www2.gotomeeting.com/register/902909498

There will be lunch which at the moment is BBQ, but I might change my mind. ;)

Currently the agenda looks like:

  • INotifyPropertyChange
    • Normal
    • Type Safe
    • Dynamic Proxy
    • AOP
  • View + ViewModel
    • Typical methods
    • IView extensions
    • IView<VM>
    • ViewRegistry
    • Also will be covering StructureMap conventions (TypeScanners) and Type Interceptors
  • Event Aggregator
    • using Events
    • Publish extension method
    • ISubscribe
    • Putting it all together with a Region Controller
  • Commands
    • ICommand
    • Action / Delegate Command
    • Decorating with a Named Command
    • * might be using commands with a convention
  • Resource Locator
    • Resource Dictionary Convention
    • Image Convention
  • And anything else that comes up during our discussions
  • Potential additions:
    • Paul Stovell’s MicroModel
    • Dependency Property Inheritance
    • Attached Dep Property Behaviors
    • Blend Behaviors
    • Visual State Manager

We will be recording the session so have no fear if you can’t come or join us online.

I am very excited about the workshop! Its a great opportunity to share some stuff I’ve been doing with WPF. User groups and brown bags offer only limited exposure to these techniques. With this workshop we get to dive into code and get rapid interactions. I hope to see you there.