GIT with VisualStudio

It’s about a week that I’m trying to use Git with Visual Studio. My intention was to replace SVN by Git because it allows for a more complete development workflow.

The idea is that you can make local commits of your changes and when the changes are mature enough they can be pushed on a central Git or SVN repository. This provides more flexibility and shorten the time between two commits. 

I found the experience of working with a local source controller very convenient and I’m  convinced that this model will soon be adopted on all platforms.  Nevertheless my experience with Git was not completely positive and I’m not planning (any more) to abandon SVN/Ankh/Tortoise. I’m sure that Git makes a perfect fit when developing on Linux but my experience on Windows/VisualStudio was mitigated.

These are my list of pro’s and con’s.
Pros:

  • Enables local commits
  • Very lightweight
  • Command line tools are simple and powerful
  • Branching, Merging and Taggging are easy and reliable
  • Good integration with Windows through TortoiseGit
  • Perfect integration with SVN (you can use Git as a client for SVN)

Cons:

  • Lack of integration with VisualStudio. I tried Git Extensions but compared to AnkhSVN this tool is just a buggy toy.
  • No mature hosting providers. GitHub is the primary repository for Git in the cloud, the one I tested. Frankly I found their security mode (SSH key) not user friendly. Also the tracking tools are poor and at least confusing compared to an Assembla.

Because of these relatively important problems I plan to continue using SVN for the moment. Nevertheless when I need a small local source controller (e.g. when giving courses/presentation) Git is definitely the way to go. Also I plan to use Git when I’m disconnected from the SVN repository for more than a day.

 

Kata2: The Decorator Pattern

 

This the second part of the series of Coding Kata’s. Here we’ll explore the Decorator pattern.

This is the user story:

You need to send alerts to your customers when a new product is available. 
An Alert is represented by the Alert Class:

public class Alert
{
      public String DestinationAddress { get; set; }
      public String SenderAddress { get; set; }
      public String Content { get; set; }
      public string Log { get; set; }
}

Classes used to send the Alerts implement the following interface:

public interface ISender
{
        void Send(Alert alert);
}

 

  • Create an Alerter class that send the appropriate alerts.  
  • Alerts are always send by e-mail.
  • Customers can also subscribe to receive alerts via sms and/or through messenger. 
  • Use the Decorator pattern to configure the Alerter

    You do not need to use real infrastructure code to send the alert, just append a string that contains the Sender through which the message was send.
    ->Append the following text to the Alert.Log when the message is send by:
  • e-mail      : “Message was send by e-mail”
  • sms         : “Message was send by sms”
  • messenger: “Message was send by messenger”

 

Show Solution

 

Coding Kata on design patterns: Kata1, The Abstract Factory Pattern

 

This post is the first in a series dedicated to Coding Kata’s and design patterns.  

Because I’m not always able to remember all the patterns I decided to learn by practice.  

Every week I will try to create a Kata with a simple problem that has to be resolved with one of the Gov’s design patterns.  

Because I want to start smoothly we’ll start with one of the simplest pattern -> the Abstract Factory.

Kata1 ->

- A product has a property Name.  

- Because the Name is used as an identifier it can’t be changed.  

- We need to be able to construct 2 products with following names: Product1, Product2.

- Use the abstract factory pattern so that you’re able to create Products.

 

This is my solution for Kata1.

 

 

Sharepoint 2007 Certification Guide

Here under you can find two usefull ressources to prepare for the exam:

 

-       The Wrox book: Professional Sharepoint 2007 Development

 

-       The Blog of: Adam Roderick

 

By focusing primarily on these two resources I managed to pass the Sharepoint Certification with what could be considered a ‘high score’. 

Create a WCF service and client, using Msmq, programmatically

  download source code

Most of the WCF examples on the web uses the config file to setup the address, binding and contract of a WCF service. I dislike this way of configuring client and service in WCF because most of the time it leads to config files that are full of crab and that becomes unmanageable. I prefer to construct my WCF services programmatically. Therefore I’ve create a bunch of helper classes that contains most of the configuration settings that are applicable in a particular domain.

In this article I discuss one of these classes  I use to create local queues. With local I mean queues used by components making part of the same application. This class can be used as a factory to create the service (serviceHost) as well as the client part (Channel) for components communicating through Msmq.

This article provides a small tutorial on how to create a simple console app. I demonstrate how to create the client and service host without any configuration by using a helper factory class: WCFMsmqFactory

Prerequisite:

- This article assumes you’ve installed Msmq on your box.  If this isn’t the case install Msmq see->  here for Xp & Win server 2003 or here for Vista & Win 2008 & Seven.

- If you’re a vista user you need to register your namespace for by typing in the command (in administrator mode):
netsh http add urlacl url=http://+:8000/BackToOwner/gatewayservice/sms user=[your username]

1) Create a new console application project: ‘WCFMsmqFactory’ and add a reference to

  • System.ServiceModel
  • System.Messaging
  • System.Transactions

 

2) Create a the WcfMsmqFactory class by copying the source code here beneath:

   1:  public class WcfMsmqFactory<I, T> where T : I
   2:     {
   3:         private string _queueAddress;
   4:         public WcfMsmqFactory(string queueAddress)
   5:         {
   6:             _queueAddress = queueAddress; 
   7:   
   8:             if (!MessageQueue.Exists(queueAddress))
   9:                 MessageQueue.Create(queueAddress, true);
  10:         } 
  11:   
  12:         public ServiceHost CreateMsmqServiceHost(string metadataAddress, string namespaceName)
  13:         {
  14:             var sHost = new ServiceHost(typeof(T));
  15:             var binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.None);
  16:             binding.DeadLetterQueue = DeadLetterQueue.System;
  17:             binding.Namespace = namespaceName;
  18:             sHost.AddServiceEndpoint(typeof(I),
  19:                                            binding,
  20:                                            new Uri(String.Format(
  21:                                                        @"msmq.formatname:DIRECT=OS:{0}",
  22:                                                        _queueAddress)
  23:                                                )
  24:                 ); 
  25:   
  26:             // Expose the service metadata on the metadataAddress
  27:             var smb = new ServiceMetadataBehavior();
  28:             smb.HttpGetEnabled = true;
  29:             smb.HttpGetUrl = new Uri(metadataAddress);
  30:             sHost.Description.Behaviors.Add(smb); 
  31:   
  32:             return sHost;
  33:         } 
  34:   
  35:         public I CreateChannel()
  36:         {
  37:             var binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.None);
  38:             var address = new EndpointAddress(String.Format("msmq.formatname:DIRECT=OS:{0}", _queueAddress));
  39:             var channelFactory = new ChannelFactory<I>(binding, address);
  40:             return channelFactory.CreateChannel();
  41:         }
  42:     }
  43:   

This class is perfectly reusable in any project and provide an abstraction on how to create programaticaly WCF services using the msmq binding. To instantiate the class we’ve to pass the interface and his actual implementation. The interface type we’ll be used to create the client & server part. The implementation type (service) will only be used to create the server.
The constructor creates a queue if it’s not already available. Note that the example don’t use security as the transport level security would demand to use active directory. As my pc does not connect to an Active Directory server I had to instantiate the binding without security:

var binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.None);

Not setting this setting resulted to the following error message: ” Binding validation failed because the binding's MsmqAuthenticationMode property is set to WindowsDomain but MSMQ is installed with Active Directory integration disabled. The channel factory or service host cannot be opened”

For the dead letter queue I use the default dead letter queue (see comment) settings:

binding.DeadLetterQueue = DeadLetterQueue.System;

To prevent the service to display the namespace as Tempuri.org it’s important to provide the same namespace settings as in your service contract & behavior directive.

binding.Namespace = namespaceName;

The following code exposes the metadata information (wsdl) on the provided metadata address:

var smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri(metadataAddress);
sHost.Description.Behaviors.Add(smb);

3) Now lets create the message definition.
Add a new class SmsMessage:

public class SmsMessage
{
        public string Number { get; set; }
        public string Body { get; set; }
}

4) Define the service definition:
Add the file SmsService.cs:

   1:  [ServiceContract(Namespace = "http://My.Domain.Services.WCF")]
   2:  [ServiceKnownType(typeof(SmsMessage))]
   3:  public interface ISmsService
   4:  {
   5:      [OperationContract(IsOneWay = true, Action = "*")]
   6:      void SubmitSms(MsmqMessage<SmsMessage> msg);
   7:  } 
   8:   
   9:  [ServiceBehavior(Namespace = "http://My.Domain.Services.WCF")]
  10:  public class SmsService : ISmsService
  11:  {
  12:      public void SubmitSms(MsmqMessage<SmsMessage> msg)
  13:      {
  14:          var sms = msg.Body;
  15:          Console.WriteLine(string.Format(
  16:                                "SMS send to {0} with body='{1}'",
  17:                                sms.Number,
  18:                                sms.Body)
  19:              ); 
  20:   
  21:      }
  22:  }
  23:   

The SmsService class contains the real implementation code. As the purpose of this article is not to demonstrate how to actually send sms messages I didn’t provide the real code here. This demo only output the message on the console.

5) Finally let’s put all the parts together.
Add the following code to the main part of the program:

   1:   static void Main(string[] args)
   2:      {
   3:          //define variables
   4:          const string queueAddress = @".\private$\sms";
   5:          const string metadataAddress = "http://localhost:8000/BackToOwner/gatewayservice/sms";
   6:          const string nameSpaceName = "http://My.Domain.Services.WCF";
   7:          var message = new SmsMessage()
   8:                            {
   9:                                Number = "+322678821",
  10:                                Body = "This is a sample sms message!"
  11:                            };
  12:          var msmqMessage = new MsmqMessage<SmsMessage>(message); 
  13:   
  14:          //define factory 
  15:          var factory = new WcfMsmqFactory<ISmsService, SmsService>(queueAddress); 
  16:   
  17:          //Do the work
  18:          using(var serviceHost = factory.CreateMsmqServiceHost(metadataAddress,nameSpaceName))
  19:          {
  20:              Console.WriteLine("Starting the server...");
  21:              serviceHost.Open();
  22:              Console.WriteLine("Instantiating the client channel...");
  23:              var channel = factory.CreateChannel();
  24:              using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
  25:              {
  26:                  Console.WriteLine("Sending the message...");
  27:                  channel.SubmitSms(msmqMessage);
  28:                  scope.Complete();
  29:              }
  30:              Thread.Sleep(1000);
  31:              Console.WriteLine("Closing the server...");
  32:              serviceHost.Close();
  33:          }
  34:          Console.ReadLine();
  35:      }
  36:  }
  37:   
 

   Running the application should display a console with:
Starting the server...
Instantiating the client channel...
Sending the message...
SMS send to +322678821 with body='This is a sample sms message!'
Closing the server...

The real magic happens here:

var factory = new WcfMsmqFactory<ISmsService, SmsService>(queueAddress);

With this few line of code we’ve instantiated a factory that is able to create the client as the server of our service. The only thing we’ve to pass is the queue address – the rest of the configuration is encapsulated in our Factory class and can be easily reused.   We can provide our factory classes to all the enterprise and create a framework on top of WCF that will standardize and facilitate how WCF is used inside our company.

GVD

kick it on DotNetKicks.com

Visual Studio TextMate Font Black Background

 

 

 

 

 

 

It’s about 2 years now that I use a black background in Visual studio with TextMate inspired font "Monaco" and I still love it. For those who wants to try you can download the fonts and the setting file from my server on http://www.belgianagencies.com/content/Visual Studio 2008_Monaco.zip
Install the fonts by copying the Monaco.ttf to c:\windows\fonts and use the Visual Studio Tools-Import & Export settings wizard to configure the font’s settings.

GVD

View Geoffrey Vandiest's profile on LinkedIn

What is the role of a software architect in an Agile Enterprise?

I’ve defined here under what my vision is on the tasks and responsibilities of a Agile Software Architect role should have in the Enterprise. The Enterprise usualy also  has another role that could be defined as the Enterprise Architect whose role is more strategic and cross project. The list here under is applicable to the first category, the once actively participating in software projects.

Project Tasks

  • Take final responsibility for the quality of the software produced
  • Take the important technical decisions taking all quality aspects of the project into consideration (Cost, Maintainability, Availability, Scalability, Security and all other ty’s)
  • Mesure the quality through metrics and code reviews
  • Enforce changes if quality is not in line with standards
  • Select, in the context of the project, what the software engineering practices should be and how they are applicable for the concrete project
  • Define code coverageCode quality and encouragement of best practices
  • Coaching of and adherence to "Agile" software development principles for module design and implementation
  • Take the lead when building prototypes, common tools, general solutions and reusable components
  • Engage the teams in both defining and executing on such tasks
    The people often best suited to build prototypes are those with knowledge of the intimate details
  • Building reusable components comes from first building usable components
  • Management of common libraries
  • Define based on stakeholders requirements what the Performance, scalability and high-availability requirements are.
  • Interface between technical teams (Service team, Project, Development Center, Quality Assurance…), business stakeholders and development teams on technical matters
  • Coordination with QA and release engineers
  • Integration, performance and load testing strategies
  • Release, migration and upgrade strategies
  • Coaching and working directly with development teams on a regular basis
  • Technical customer to the agile development teams
  • Able to add technical user stories to the product backlog
  • Works directly with the product owners to prioritize and trim the product backlog

Responsabilities

  • Participate in the design of the software engineering process(es)
  • High-level technical vision, planning and documentation
  • Automate and define the tools that support the software engineering process(es)
  • Technical oversight in specific technical domain
    EAI, .Net, Java, Packages, ….

I would like to underline what in my opinion differentiate an agile software architect from how our role is usually perceived.
An Agile software architect doesn’t take part to a project only at its beginning, but during the whole project’s lifecycle to ensure a right implementation of the design and architecture. He also has to keep listening to new requirements to adapt solutions if needed.
Even if I acknowledge that an architect has to step back from his work and the teams’ work, I don’t conceive an architect who would remain far from the implementation team. Indeed, an architect can have to write lines of code (at least to create prototypes), but also has to get his hands dirty with code to validate the quality of what is produced or resolve a particularly technically difficult situation.

Further I would like to refer to some toughts of Martin Fowler expressed in the article by Martin Fowler “Who needs Architect”

http://martinfowler.com/ieeeSoftware/whoNeedsArchitect.pdf

“architecture is the decisions that you wish you could get right early in a project, but that you are not necessarily more likely to get them right than any other”

“A guide is a more experienced and skillful team member who teaches other team members to better fend for themselves yet is always there for the really tricky stuff.”

I would also recommend the following webcast with again Martin Fowler on the role of an architect in an Agile Organization:http://www.infoq.com/presentations/agilists-and-architects

GVD

View Geoffrey Vandiest's profile on LinkedIn

The 5 Pilars of Unit Testing

 

These are, what I consider to be the 5 most desirable quality attributes of a unit test:
 
1.       Unit tests should be accessible, everyone should be able to run them
Running a unit test should not involve more than getting the source code from a source controller, compile the SUT/Test code and clicking on a button to run all the tests. No configuration should be involved. Your tests should not require to setup external components like a DB or SMTP server. 
 
2.       Unit tests should be repeatable
What is the value of a test you can’t trust? Unit tests results should only change when modifications are introduce in the SUT. When the SUT remain the same the unit tests should always return the same result. Therefore unit tests should be state independent and in anyway they should never be dependant on a shared resource like a file or persistent memory.
 
3.       Unit tests should be easy to write and maintain
In an software shop we should only use a practice or tool when this is economical viable meaning that the cost of writing the tests and maintaining it should not exceeds the costs of having a bug and fixing it. To minimize the cost of creating and maintaining tests we should use appropriate practices and tools. We should also have the same quality requirement for test code as for production code. Refactoring is as important for test code as for production code.   
 
4.       Unit tests should be resistant to change
We should write our test in such a way that the amount of tests failing when introducing a change is minimal. When testing the SUT it is common to set his variable in proper state so it can be tested. This type of setup test code is very fragile. We should always try to isolate this type of code so it is easy to change. 
 
5.       Unit tests should run quickly
ideally unit tests should be executed after every build. Having to wait more than 1 minute to execute all the unit tests will decrease the overall productivity of the tests. Unit tests should never be dependant on costly resources to invoke like web services or DB.
 
Is there someting missing here? 
 
GVD
 
View Geoffrey Vandiest's profile on LinkedIn
 

Extensibility for ASP.NET MVC

 

I’m working on an extensibility framework made to be used on top of ASP.NET MVC. My extensibility framework is based on the famous Ioc container: Structuremap .
The use case I’m trying to fulfill is simple: create an application that should have some basic functionality that can be extended for every customer (=multi-tenancy). There should only be one instance of the application hosted but this instance can be adapted for every customer without making any changes to the core website.
I was inspired by the article on multi tenacy wroted by Ayende Rahien: http://ayende.com/Blog/archive/2008/08/16/Multi-Tenancy--Approaches-and-Applicability.aspx Another source of inspiration was the book of Eric Evans on Domain Driven Design. My Extensibility framework is based on the repository pattern and the concept of root aggregates. To be able to use the framework the hosting application should be build around repositories and domain objects. The controllers, repositories or domain objects are bind at runtime by the ExtensionFactory.
A plug-in is simply an asselmbly that contains Controllers or Repositories or Domain Objects that respects a specific naming convention. The naming convention is simple, every class should be prefixed by the customerID e.g.: AdventureworksHomeController.
To extend an application you copy a plug-in assembly in the extension folder of the application. When a user request a page under the customer root folder e.g: http://multitenant-site.com/[customerID]/[controller]/[action] the framework check if there is a plug-in for that particular customer and instantiate the custom plug-in classes otherwise it loads the default once. The custom classes can be Controllers – Repositories or Domain Objects. This approach enables to extend an application at all levels, from the database to the UI, through the domain model, repositories.
When you want to extend some existing features you create a plug-in an assembly that contains subclasses of the core application. When you’ve to create totally new functionalities you add new controllers inside the plug-in. These controllers will be loaded by the MVC framework when the corresponding url is requested. If you want to extend the UI you can create a new view inside the extension folder and reference the view by a new or subclassed controller .To modify existing behavior you can create new repositories or domain objects or sub classing exiting ones. The framework responsibility is to determine which controller/ repository / domain object should be loaded for a specific customer.
I advise to have a look at structuremap (
http://structuremap.sourceforge.net/Default.htm) and especially at the Registry DSL features http://structuremap.sourceforge.net/RegistryDSL.htm .
This is the code I use at the startup of the application to register all plug-in controllers/repositories or domain objects:
protectedvoidScanControllersAndRepositoriesFromPath(string path)
{
   
this.Scan(o =>
    {
       o.
AssembliesFromPath(path);
       o.
AddAllTypesOf<SaasController>().NameBy(type => type.Name.Replace("Controller", ""));
       o.
AddAllTypesOf<IRepository>().NameBy(type => type.Name.Replace("Repository", ""));
       o.
AddAllTypesOf<IDomainFactory>().NameBy(type => type.Name.Replace("DomainFactory", ""));
       });
}
I also use an ExtensionFactory inheriting from the System.Web.MVC. DefaultControllerFactory. This factory is responsible to load the extension objects (controllers/registries or domain objects). You can plugin your own factories by registering them at startup in the Global.asax file:
protectedvoid Application_Start()
{
   
ControllerBuilder.Current.SetControllerFactory(
      
newExtensionControllerFactory()
    );
}
l'll try to find some time to explain my approach more clearly on my blog and hopefully I'll be able to publish my Extesnsibility framework on CodePlex soon.

Is mangling PRINCE2 and SCRUM Agile?

This week I attended a session of the Agile users-group in Belgium. The topic was about: how to mangle SCRUM and PRINCE2. 

The discussions were held following the fishbowl technique. The advantage of  this technique is that it allows the entire group to participate in a conversation.   Five chairs were put in the middle, this was the fishbowl and the rest of the people attending the event were arranged in concentric circles outside the fishbowl. Any member of the audience could, at any time, occupy the empty chair and join the fishbowl. The concept was a real success as everyone went at least once inside the fishbowl.
Interesting thoughts were exchanged. This is what I personally will keep from this evening:
Because PRINCE2 isn’t prescriptive about how the implementation will be performed it perfectly fit with AGILE methodologies. If your management is reluctant to try Agile methodologies like SCRUM you can refrain their fears by using PrinCE2 as a harness for SCRUM. The project manager and the higher management can use PRINCE2 as a governance framework while the developers and testers can use SCRUM practices and values. 
 The risk is to generate a lot of waste. As PRINCE2 is highly document driven your team and especially the project manager will have to generate lots of documents that are not really adding value to an agile team. Another risk is that your whole team would break apart. Developers will naturally tend to adopt the Agile principles and values and the chickens (PM & Customer & Management) will be more comfortable with Prince2. The danger is that the 2 groups will use different vocabulary leading to confusion. The two groups will be less cohesive and you risk ending with the worst of both worlds.
My advice is that you should try to stick to the pure Agile values and practices but if you’re really forced to adopt Prince2, fake it! Prince2 prescribe a min. set of doc and practices, simply adopt this min. set and do the less possible.