Webcast for Latin American Community about HPC with WCF

 

Spanish Version

On December 11, 2008 we gave a Webcast for Latin American Community with my friend and mentor Johnny Halife about how to develop distributed applications by using Windows HPC Server 2008.

The objective of the talk was about to explain the platform that Windows HPC Server 2008 provide us to build distributed applications with a SOA architecture by using Windows Communication Foundation (WCF).

In addition we had the opportunity to make a small demo creating a simple application on our lab deployed at Southworks.

For the ones that couldn’t attend this presentation, you can download or watch it in the following url: http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032390257&Culture=es-AR.

Enjoy it!

 

Visual Studio 2008 templates compliant with Microsoft StyleCop

Motivation

Since Microsoft launched StyleCop, we are running this tool in all Southworks’ projects. From our Engineering Excellence department we’re promoting the use of this tool because it give us source code consistency and homogeneity we want for developers and customers who read the code.

If you’re using this tool, you surely be realized that some Visual Studio templates are not compliant with some of the StyleCop rules, like using directives inside the namespaces, regions, one class for each file, among others. This is quite annoying when you’re coding because each class, interface or test you add to your project has to be stylized to meet that rules.

Project templates like ASP.Net Web MVC Application (Preview 5) have an amount of ~120 warning even avoiding the documentation rules.

The purpose of this post is to give you a workaround to avoid this unnecessary work.

Context

The way that Visual Studio provides these templates is by using a series of compressed zip files, with the base source code inside.

There are two folders inside the %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\” with these templates, one for the items (classes, interfaces, tests, etc.) and one for projects (Class Library, Console Application, MVC Web Application, etc.).

Workaround

The workaround is pretty much straightforward, all you have to do is:

  1. Extract the default Visual Studio template files
  2. Modify them to be compliant
  3. Compress it again
  4. and overwrite the original files

What I did this weekend, is make the work for you for the most used files and projects for me including the Microsoft ASP.Net MVC preview 5 project template :). So below you’ll find a table with the zip files to download and the folder location where you will overwrite them.

Once you have copied the files, ensure you’ve all you Visual Studio instances closed and run as administrator from the console the following command to refresh Visual Studio’s template cache:

“%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" /setup"

Template Files

(*) rootPath = "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\"

template path template file

(*)\ItemTemplates\CSharp\Web\MVC\1033

(*)\ItemTemplates\CSharp\1033

(*)\ItemTemplates\CSharp\Code\1033

(*)\ProjectTemplates\CSharp\Web\1033

(*)\ProjectTemplates\CSharp\Test\1033

You can also download all templates in a single .zip file: AllTemplates.zip

One year and four months later…

Spanish Version

Yesterday night while drinking a couple of beers with some of my Southworks’ colleagues, I returned back to my home and being lying on my bed, I started to think on this last year and four months from when I began working in Southworks.

While I was dating back over time, I remembered in which projects and customers we were worked for, some of them are “Microsoft Architecture Strategy Team”, “Microsoft Depeloper & Platform Evangelism Team”, “Microsoft Connected Services Framework Team”, “Microsoft SQL Server Team”, “Grupo Sancor Seguros” among others, and the important people who I known in person like Eugenio Pace y Gianpaolo Carraro.

Words and technical acronyms came to my mind regarding things I have being acquired and incorporated during this time. So, in this moment I started to imagine something like a mental “Tag Cloud” and it was there when I decided to write this post with the objective of leaving this as a log experience and to compare it in the future with the new words that surely will be added.

Beside all tags am I listing in this post, I wanted to thank all Southies who were helping me to fill my mind with all this knowledge and specially to my two mentors, which are Johnny Halife y Matias Woloski who today I still admiring and respecting, but the ones who I having fun where the computer aren’t close to us.

Here is my "Mind Tag Cloud":

  Refactoring    Code Analysis    Retrospective    TDD    WCF    WSDL    Continuous Integration    Patterns    Cluster Server    ISO    Virtualization    SOA    Singleton    Cyclomatic Complexity    WPF    Model View Controller    REST    Linq to XML    Mocks    Paravirtualization    Sprint    Hyper-V    Lamda Expressions    Repository    SAN    Synchronization Framework    iSCSI    LUN    Powershell    SCRUM    Ssds    Agile    Spike    NAS    Iteration Planning    Dependency Injection    Factory    Linq to SQL    Code Coverage    Subversion    Security Token Service    CMMi    StyleCop    Model View Presenter    Strategy  FxCop    Serialization    Apache    Prototype    Datamember    Composite Application Block    Build Server    RSS    DIT    S+S    Backlog    Commitment    Inversion Of Control    Scaffolding    Abstract Factory    Reflection    LCOM    Iteration Review    Software As A Service    DataContract    TFS    Code Query Language    SOAP    Dynamic Language Runtime    Lightweight Directory Services 

Avoiding duplicated items in Fxcop analysis using MSBuild

In my previous post, I started with a posts series that describe the tasks we’ve included in the Southworks SDC Tasks we recently published at Google Code.

Today, I’m going to focus in a useful and interesting task which is RemoveDuplicatedFileNames and the reason of why we had the need to create it.

So let’s start.

The Problem

Imagine you have a solution where your assemblies are referenced as depicted in the picture below:

image

When you compile this solution you’ll realize that the Contracts.dll assembly will be generated into the Services and in WebUx folders, that’s right?

So far, there is no problem regarding compilation, but what happens if we define an ItemGroup in our MSBuild project that includes all our solution assemblies to be examined by FxCop by using WildCards like this?

<ItemGroup>
  <Assemblies Include="$(SampleDirectory)\**\*.dll" />
</ItemGroup>

The answer is that FxCop will analyze the same assembly twice, which will generate duplicated warnings and Code Analysis errors.

Our solution approach

As I told you previously we created a simple task called RemoveDuplicatedFileNames that basically remove items from an ItemGroup on the MSBuild process, to avoid the problem described above.

So let me show you how you should configure your project file to use this task

  1. Reference the Southworks SDC Tasks assembly RemoveDuplicatedFileNames in your project file
    <UsingTask AssemblyFile="$(ToolsPath)\Southworks.Sdc.Tasks.dll"
               TaskName="RemoveDuplicatedFileNames"/>

  2. Create your ItemGroup including your assembly files
    <ItemGroup>
      <Assemblies Include="$(SampleDirectory)\**\*.dll" />
    </ItemGroup>

  3. Inside the target that runs FxCop include the following lines
    <RemoveDuplicatedFileNames Input="@(Assemblies)">
      <Output TaskParameter="FilteredItems" 
              ItemName="CodeAnalysisItems" />
    </RemoveDuplicatedFileNames>

  4. Finally, instead of using the Assemblies defined in the first point, you should use the new filtered ItemGroup generated in the previous point
    <FxCop Assemblies="@(CodeAnalysisItems)"
           OutfileName="$(CCNetArtifactDirectory)\fxcop.xml"
           ProjectFilePath="$(CCNetArtifactDirectory)\project.fxcop"
           ToolPath="$(FxCopPath)"
           ProjectTemplateFilePath="$(ToolsPath)\template.fxcop" />

Note: The FxCop task is not part of Southworks SDC Tasks, you can get it from the Microsoft SDC Tasks at Codeplex. There are many useful tasks for your build process!

Verification

in order to verify if your assemblies are no duplicated you should add a Message task on the same target to display the contained values on both ItemGroup, Assemblies and CodeAnalysisItems.

<Message Text="Unfiltered Assemblies" />
<Message Text="=====================" />
<Message Text="@(Assemblies)" />
 
<Message Text="Filtered Assemblies" />
<Message Text="===================" />
<Message Text="@(CodeAnalysisItems)" />

Technorati Profile

Updating your Assembly Info files with Southworks SDC tasks

Spanish Version

Johnny and Ezequiel had published in they blogs about the Southworks SDC Tasks we published two weeks ago in Google Code. This project is a set of comprehensive MSBuild tasks that we built along with the maturity of our build process.

I’ll give you a walkthrough for these tasks we developed by giving you a sample of each one of them.

In this post you will find how you can easily update your assembly info files with company information by using the UpdateAssemblyinfo task.

This task is pretty much straight-forward, so I will create a simple .proj file to demonstrate how it works.

Reference the SDC assembly in your project file

The first step is to add the assembly reference for this specific task by giving the AssemblyFile and the TaskName values:

<Project DefaultTargets="UpdateAssemblyInfos" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask AssemblyFile="d:\test\Southworks.Sdc.Tasks.dll"
             TaskName="UpdateAssemblyInfo"/> 
</Project>

Notice that the DefaultTargets property indicates which target will be first executed, I’m going to include this target later.

Defining the files to be updated

Then, you need to specify which files will be updated and where they’re located. To do that create a new ItemGroup. If you want to know more about including and/or including Items, see http://msdn.microsoft.com/en-us/library/646dk05y.aspx.

<Project DefaultTargets="UpdateAssemblyInfos"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  <UsingTask AssemblyFile="d:\test\Southworks.Sdc.Tasks.dll"
             TaskName="UpdateAssemblyInfo"/>  
  <ItemGroup>
    <AssemblyInfos Include="d:\test\**\AssemblyInfo.cs"/>
  </ItemGroup>
 
</Project>

Configure the UpdateAssemblyinfo target

Finally create and configure a new target by specifying the information to be replaced on the files we defined in the previous step.

<Project DefaultTargets="UpdateAssemblyInfos" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
  <UsingTask AssemblyFile="d:\test\Southworks.Sdc.Tasks.dll"
             TaskName="UpdateAssemblyInfo"/>
  
  <ItemGroup>
    <AssemblyInfos Include="d:\test\**\AssemblyInfo.cs"/>
  </ItemGroup>
 
  <Target Name="UpdateAssemblyInfos">
    
    <UpdateAssemblyinfo Include="@(AssemblyInfos)"
                      AssemblyCopyright="Southworks (r) copyright"
                      AssemblyCompany="Southworks"
                      AssemblyProduct="Sample product " />
  </Target>
  
</Project>

To see if all it’s working as expected, you could run the project file with MSBuild as depicted bellow:

image

Open the sample AssemblyInfo.cs file and see how it was updated:

image

thanks, stay tuned!

Folder wildcards like \**\ in CruiseControl.Net

Spanish Version

Last week we were working on our Build Server using CruiseControl.Net to allow multiple Test / Code Coverage tasks for two or more solutions.

Once we’ve configured the .proj file to run a set of two RunTests / RunCodeCoverage tasks we needed to merge the results file to the MSBuild log after running them.

So, our first approach was modifying the ccnet.config file to merge the files generated by these tasks using the same pattern of MSBuild, I mean, using "\**\", something like this:

<merge>
  <files>
    <file>D:\srv\ccnet\logs\project\**\*.trx</file>
    <file>D:\srv\ccnet\logs\project\**\*.cvg</file>
  </files>
</merge>

At this point, we have figured out that Cruise Control .Net does not have this functionality, only it allows to run something like D:\srv\ccnet\logs\project\theProject\*.trx, and since the CruiseControl.Net source code is available I started to writing some lines to modify the ThoughtWorks.CruiseControl.Core assembly to allow that.

In this post you will find the source code of the spike I wrote with a series of tests to implement that feature and the WildCardPath.cs source code from the core CruiseControl.Net project updated.

  • Spike solution with tests [Download]
  • WildCardPath class file of CruiseControl.Net Core assembly [Download]

Once you have updated the Core project with the new implementation of the WildCardPath class, you need to do the following tasks to keep it running.

  1. Compile the Core project
  2. Stop the CruiseControl.Net service
  3. Replace the ThoughtWorks.CruiseControl.Core assembly with the new one.

And that’s it, use wildcards as in MSBuild :)

Microsoft Source Analysis for C# 4.2 was published

Spanish Version

Microsoft has published a great tool called Microsoft Source Analysis for C#, formerly known as StyleCop.

This tool allow us to review and improve our source code quality. It’s is fully integrated with Visual Studio, so with a single right click in a solution, project or file, we can check our code against the best practices defined in a series of rules depicted below.

You will find a detailed explanation on the Announcing the release of Microsoft Source Analysis for C# post and download the latest bits from here.

 

Also you can customize which rules should be checked using the built-in configuration tool.

Finally, another good point is that we can integrate that tool on our build process with MSBuild. I recomend you the Jason Allor’s blog post on the Source Analysis Blog page where he explains how to do that.

Here is another good post from MSBuild Team Blog also, announcing this release.

Enjoy it and say goodbye to the documents with code-standards :)

ASP.Net MVC Online Conference on MSDN

Spanish Version

On Tuesday (May 11, 2008) Matias Woloski and I, gave a webcast about the ASP.Net MVC framework for the Spanish community.

I want to thank you for attend this talk and I hope we continue giving more talks about latest technologies with Microsoft.

As I promised you, in this post you will find the some source code different versions for the sample application we showed during the demo:

  • Translator Demo [MVC Preview 2 (original)] : Download
  • Translator Demo [MVC Preview 2 + TDD (using MoQ) + WCF Services] : Download
  • Translator Demo [MVC Preview 3 + TDD (using MoQ) + WCF Services] : Download

I hope you find these samples useful and I you have any question, please let me know by posting a comment right here.

If you want to know more about the changes on the Preview 3, I recommend you to take a look at this ScottGu's post http://weblogs.asp.net/scottgu/archive/2008/04/16/asp-net-mvc-source-refresh-preview.aspx

How to get the testId generated by Visual Studio in a .loadtest file

Spanish Version

During these days I have been working on a tool that automates the execution of a load test.

Our objective was to parse a .loadtest template file, based on a template, which has been configured for a specific scenario with a set of counters. Once we have parsed the template we are ready to add the TestMix node and a TestProfile node for each test that we want to execute from those defined on test assembly.

The Obstacle

When I was creating the TestProfile node, I realized that each unit test has an specific Id (represented by a unique identifier a.k.a Guid). What I didn’t noticed until we’ve run the load test is that this identifier was generated dynamically by Visual Studio.

We tried going under the hood , unluckily, using reflector to analyze some of Visual Studio assemblies in order to find how these identifiers were generated.

The suggested workaround

Searching on the web I found a post with a method which generates the Guid we’re looking for:

private static Guid GetGuidFromString(string value)
{
    SHA1CryptoServiceProvider provider = new SHA1CryptoServiceProvider();
    byte[] buffer1 = provider.ComputeHash(Encoding.Unicode.GetBytes(value));
    byte[] buffer2 = new byte[0x10];
    Array.Copy(buffer1, buffer2, 0×10);
    return new Guid(buffer2);
}

Using the recently created function we’re able to retrieve the Guid for a given assembly as I’m showing below

private static IList<TestEntry> GetUnitTests()
{
    IList<TestEntry> unitTests = new List<TestEntry>();
    Assembly assembly = Assembly.LoadFrom(“Tests\\PerformanceTests.dll“);
    Type[] assemblyTypes = assembly.GetTypes(); 
 
    foreach (Type type in assemblyTypes)
    {
        if (type.IsClass && 
            type.GetCustomAttributes(typeof(TestClassAttribute), false).Length > 0)
        {
            MethodInfo[] info = type.GetMethods(); 
 
            foreach (MethodInfo m in info)
            {
                if (m.GetCustomAttributes(typeof(TestMethodAttribute), false).Length > 0)
                {
                    Guid testGuid = GetGUIDFromString(type.FullName + “.“ + m.Name);
                    unitTests.Add(new TestEntry(testGuid, m.Name));
                }
            }
        }
    } 
 
    return unitTests;
}

Hope you find it useful!

The three quarrymen

Spanish Version

I would like to share with you a story that I’ve read in a Spanish book called “Companies’ Failure’s causes” (how to learn from other people’s experience) by Enrique Zamorano. So, this extract says…

There are three quarrymen at the foot of a cathedral doing the same job: sculpting stones.

A stranger gets closer to one of them and asks: “What are you doing?

The quarryman answers: “I’m sculpting stones” and, with his bad-tempered look, he adds: “Can’t you see it?

The second one replies saying: “I’m earning my living” and his gesture seems to say: “It’s too hard, you know?

When the third man hears the question, he brings up his head, glances up, and with his eyes shining, he says: “I’m building a cathedral

Conclusion

The same action could have different meanings. The third quarryman is, indeed, who does his job with excellence: he takes his work as a challenge and does it with passion.

Next Page »