Friday, September 05, 2008

TeamCity - Continuous Integration Server and Build Management Tool

TeamCity is a continuous integration & build management solution for both .NET and Java development. TeamCity is developed by JetBrains - the producer of the famous Resharper - and shipped in two editions: Professional Edition and Enterprise Edition. The Professional Edition of the team city is free and you can use it without a need for any kind of licenses. This edition is more than enough for small and medium size company or teams.

Build Servers are very useful tool in any development environment where you need to track the build state of your team code. It make sure that all the committed code is not in a breaking state. The integration with the build servers and the continuous integration tools like SVN and sourcesafe help you to assign the responsibilities of the breaking code to specific developer to fix.







TeamCity is a a very powerful build server which has many features to facilitate your project building process. You can download the last version of TeamCity from here. I have downloaded the last version and played a little bit with it and it seems very interesting tool. When you run it for the first time, you will be asked to make a new account. Then you will have to create a new project by entering the main project information. Afterwords, you will be asked to enter the general settings of the project. Then, you will have to enter a new build configuration. You can have more than one build configuration in the same project allowing a kind of switching for the build needs and requirements for your project.







In "Build Configuration" step, you need to define the build numbers format. You can have your own format for the builds numbers like "CG-01" or "MX-01" or whatever suitable format. You can define the criteria of the build failing. For example, you can define the failing criteria if the building execution itself failed, the project test failed, error reported by the build runner and/or the build take more than a specified number of minutes (timeout).

Also in this page there is a nice feature called "Status Widget". This means you can include the status of your build in any external web page or whatever external tracking site you may use internally. When you enable it, you will have to copy and paste small HTML and CSS tags inside this external page to show your build status.




Then you will be asked to enter the build runner information in "Build Runner" step. In this step, you need to define the platform you will use to build the project. Team City provide several build runners for .NET and Java projects as well. I am working with .NET so I choose MSBuild as a build runner. Then I specified the build file virtual path which is the solution file of my project (ex. teamcitytest.sln). When you select MS Build, you define the suitable .NET Framework version for the build. You also define more command line parameters for MSBuild.exe if required.







Then, you will enter the version control settings like the checkout path if it's different than the default directory of the agent. You can also make automatic labeling if the build succeeded.

There is another nice setting in TeamCity which allow you to run the build periodically. You set it by clicking "Edit Configuration Settings" in the top panel of the build progress screen. Then in the left tabs, choose "Build Triggering". Select "Other Triggering". Check "Automatically start a new build when the previous build failed." and specify the time intervals between the builds.





This was a very quick walkthrough for TeamCity. I really like it and recommend it for your development team as a very efficient and customizable build server.


Friday, June 20, 2008

Google Code Jam 08 - Registeration Started

Google Code Jam is a coding competition in which professional and student programmers are asked to solve complex algorithmic challenges in a limited amount of time. The contest is all-inclusive: Google Code Jam lets you program in the coding language and development environment of your choice.

Google Code Jam begins in July and continues in August, when you will compete in online rounds against contestants from around the world. The Top 500 participants will advance to onsite competitions at a local Google office to compete against those in their region (Asia Pacific; Europe, Middle East and Africa; and the Americas). The Top 100 will participate in the final round at the Google Headquarters in Mountain View, California on Friday, November 14.

Google offers more than $80,000 in cash prizes for the winners. Don't be left out! Make sure to register between June 17 and July 17, and show your coding creativity in Google Code Jam.


Friday, June 13, 2008

Code Style Review Using Microsoft Source Analysis

Today, I gave a try for Microsoft Source Analysis aka StyleCop. The tool was internally used inside Microsoft and it's now publicly released. It nicely integrates with Microsoft Visual Studio with the ability to attach the analysis process with the project build - See this post. The tool scan all your C# code and gives you hints for better coding style according to the best practices followed in writing C# code. It gives for example notes regarding the missing comments, formating, missing or extra spaces, extra blank lines and unnecessary brackets.

Here are some sample error messages resulted after running the Source Analysis on one of my projects

- The class must have a documentation header.
- The property must not be placed on a single line. The opening and closing curly brackets must each be placed on their own line.
- Property names begin with an upper-case letter: projectspath.
- All using directives must be placed inside of the namespace.
- The body of the if statement must be wrapped in opening and closing curly brackets.
- Statements or elements wrapped in curly brackets must be followed by a blank line.
- The code must not contain multiple blank lines in a row.
- All properties must be placed after all constructors.



However, there is some drawbacks regarding the tool like it targets only C# developers. More so it can't recognize the spelling mistakes in the code and comments which is one of the most common issues. Another point is that the tool is not flexible regarding its guidelines rules. It doesn't give you the option to exclude a rule in the next time of the analysis scan. For example, it consider putting a preceding underscore in the class private members as a breaking style. However, it is common for most of the C# developers. I think there is already a debate about the best style guidelines for C# coding to follow. The issue even seems to have some historical sides..

I really recommend this tool if you want your team to follow the basics of the C# coding guidelines without caring much about going in details while reviewing their code. It just help you, so that you ignore all the small crappy notes giving all your attention to the real massive mistakes in the coding logic and modules interactions.

You can find more about the tool releases and the future expectations in the Source Analysis blog.


Thursday, June 12, 2008

MbUnit 2.4 - Avoiding Crappy Data Resulted From The Test

One of the nice features in MBUnit 2.4, is the ability to rollback the crappy data in the database resulted from running subsequent test methods. This is really interesting because this crappy data can become a nightmare during the application development or even after the deployment. You will spend pretty much time exploring your data to filter the dirty ones which can lead sometimes to some mistakes.

MbUnit give you the ability to rollback any changes made in the database during the test. Using MbUnit 2.4, this can be done by referring MBUnit.Framework.2.0 in the project references and using RollBack2 attribute for each test method.

[Test]
[RollBack2]
public void InsertNewProductTest()
{
      Product product = Product.CreateNew('Nokia 800', 2300, true);

      Assert.AreEqual('Nokia 800', product.Name);
      Assert.AreEqual(2300, product.Price);
      Assert.AreEqual(true, product.InStock)

      ProductRepository.Persist(product);
}

In the later example, any changes made in the database by persisting the Product object will be rolled back after the test execution. This will keep your tables clean containing only your application live data.

MBUnit uses TransactionScope in System.Transactions to provide the rollback functionality. However, you will need to set some security configurations for the DTC settings in order to make the TransactionScope properly work. To set these settings, open the Component Services in the Administrative tools. Then, show the properties of your computer and select MSDTC tab. Open the Security configurations and setup the needed settings for the remote and local authorization of the transactions on your machine.

As a side note, you are able to track the operating transactions by putting some break points inside your test method. Then, in the Component Services under the Transaction list you will find your active transactions listed there. More so you can check the Transaction Statistics to track the committed and aborted transactions of your test operations.


Friday, April 18, 2008

Thinking In REST

REST or WS-*? The debate which will never end. While REST is taking the lead gradually, the community see many drawbacks in using the traditional WS-*. The complexity and overhead in using WS-*, REST simplicity and how they fit the web architecture are always the main points of the argument. REST is simple, that is it. It has nothing to deal with except three things: Resources, Verbs and URIs. The idea of making use of the HTTP standards to accomplish all the needed CRUD operations on the resources is really interesting from the service development perspective.

It was clear from the beginning of the WS-* evolution that WS-* violates and ignores the architecture of the Web. It replaces the concept that the Web is identified by URIs to the concept that the services is identified by WS addresses. However, in the RESTful architecture, all the addressing is through URIs. This creates a homogeneous architecture comparing to how the web is actually constructed. Even dealing with URIs as your default addressing help in promoting your service in the search engines results and making it more reachable by your consumers.

WSDL doesn't give you much information about the semantic and logical interactions between the services methods. It just provide a listing for the service methods names, parameters and data types. You can't know for example what shall you need to call first to accomplish a specific task or what this service is actually doing. This is not the case in the RESTful services where you can build you own service documentation. You provide a custom HTTP GET request returning an HTML response with the allowed operations for this specific URI along with any custom documentation you may need to attach. However, you still able to describe your services using the WADL Language - the WSDL equivalent - in case you still need to use a descriptive language for your RESTful services.

Another point to mention is about how REST can make use of the HTTP protocol standards. Suppose you want to make a request to some WS-* service and get the response in several formats. You will need to pass the required response type to the service method or even make a separate method for each type! Neither of the two solutions is convenient. In REST, you can make a solid use of the standard HTTP header. You simply modify the "Accept" field in the HTTP request header with the required content-type of the response. In the server side, you will receive the required content-type in the request header so that you will be able to respond with the corresponding format. This way you save the confusion of your service consumers and make uses of the HTTP header to provide some kind of a separation between the needed request parameters and the other non-related ones.

Another point is about error handling. In REST, you are able to make use of the standard HTTP status codes in a very elegant way. You may respond with standard error 505 for example if the requested resource is not found or with error 401 if you're not authorized to access the resource. So you have a rich standard protocol to build your own services on.

RESTful architecture starts to get more and more acceptance in the web development community. Microsoft provide RESTful capabilites in its WCF Web Programming Model. Google, Yahoo, Amazon and all the big entities are now digging in the RESTful Services. There is something there you should start to care about.


Friday, April 11, 2008

Seekda - Seeking Services On The Web

SOA is now one of the most valuable options in building integrable and loosely-coupled applications. As much as the number of the web-services increases on the web, indexing the services to be reachable by the seekers became a vital need. seekda! - by Semantic Technology Institute (STI) - is one of the nice efforts to index the business services around the Web. The project is based on the results of another research project funded by the European Union called DIP - which started on 1st January 2004 and came to an end officially on 31 Dec 2006 with total funding of €16.3 M. The project acts like a link between the services providers and service consumers aiming to increase the transparency of the services market across the web.


Saturday, April 05, 2008

Open XML Appears to Win ISO Approval

After more than 14 months of intensive review, a Joint Technical Committee of the International Standardization Organization (ISO) and the International Electrotechnical Commission (IEC) has concluded its formal process to evaluate Ecma International’s submission of the Draft International Standard (DIS) 29500: Office Open XML (Open XML). While the final vote has not yet been announced formally, publicly available information appears to indicate the proposed Open XML standard received extremely broad support. Open XML now joins HTML, PDF and ODF as ISO- and IEC-recognized open document format standards. Read the full story here.


Monday, March 24, 2008

jQuery Validation Plugin

We start to see several plugins in the web based on the jQuery library. I have the chance today to work a bit with a plugin called: jQuery Validation Plugin by Jörn Zaefferer - which enable you to apply client validation to your web forms using jQuery.

To get started, you have to download the plugin files from this link. And sure the jQuery library as well: jQuery 1.2.2. Then, you should have: jquery.validate.js and jquery.js files reside on your project somewhere and linked in your markup.

IMPORTANT NOTE: I had a problem when using jquery.validate with the new vesrions - higher than 1.2.2 - of jQuery library. jquery.validate uses functions in jQuery library which no longer exist.

The following sample is the simplest one. You use the selector to get the form element. Then, you call the validate function.

<script language="text/javascript">
    $(document).ready( function() {
         $("#simpleSignUp").validate();
    }
</script>


In this case, you will have to set some predefined metadata in the class attribute of the elements telling the library the required rules to apply for the form inputs.
<form id="simpleSignUpForm" action="" method="get">
        <input type="text" id="firstname" class="required" minlength="2"/>
        <input type="text" id="lastname" class="required" minlength="2"/>
        <input type="text" id="username" class="required" minlength="2"/>
        <input type="text" id="email" class="required email" minlength="2"/>
        <input type="text" id="password" class="required" minlength="8" />
        <input type="text" id="website" class="url" />
        <input type="submit" value="Submit" />
</form>


In this case, the plugin will use some defaults error messages for validating the inputs. However, you can have more controls on the errors and rules. The following sample show in details how you can validate a full sign up form elements by specifying the rules with the associated error messages. In this sample, you won't have to apply any CSS styles as you already defines explicitly your rules.
<script type="text/javascript">
        $(document).ready( function() {
               $("#signupForm").validate({
                           rules:{
                                           username:{
                                                               required:true,
                                                               minlength:2
                                           },
                                           password:{
                                                               required:true,
                                                               minLength:5
                                           },
                                           confirm_password:{
                                                               required:true,
                                                               minlength:5,
                                                               equalTo:"#password"
                                           },
                                           email:{
                                                               required:true,
                                                               email:true
                                           },
                                           topic:{
                                                               required:"#newsletter:checked",
                                                               minLength:2
                                           },
                                           agree:"required"
                            },
                            messages:{
                                           username:{
                                                               required:"Please enter a username",
                                                               minLength:"Your username must consist of at least 2 characters"
                                           },
                                           password:{
                                                               required:"Please provide a password"                                                                minLength:"Your password must be at least 5 characters long"
                                           },
                                           confirm_password:{
                                                               required:"Please provide a password",
                                                               minLength:"Your password must be at least 5 characters long",
                                                               equalTo: "Please enter the same password as above"
                                           },
                                           email: "Please enter a valid email address",
                                           agree: "Please accept our policy"
                            }
               });
        }
</script>






For more information about the methods you can use for the validation, check it here.

The way you define your rules and messages are unified and configurable. You define a message per rule which is extremely a need in any web project. It's common to have several validation rules with different error messages in the same web form. When I see this style, I just remember the Design by Contract style in which your requirements (contract) are easily mapped to rules (benefits and obligations). It's similar as you put all your quality matrix in one place. Besides, it's easy to modify as like as you set some configurations to your web form!

Another point to mention is the different scenarios you can have and how this library fit it. In the last sample, you can see how you check for password confirmation, input formats (emails, URLs ... etc.) and user selections.

You can modify the CSS style of your validation errors - i.e how the input controls will look like in case of a validation error occurred. You simply modify the following snippet to have different look for the validated inputs.

div.error { display: none; }
input { border: 1px solid black; }
input:focus { border: 1px dotted black; }
input.error { border: 1px dotted red; }




This plugin is perfect for ASP.NET MVC. Actually, there is already some tries like Validator Toolkit for ASP.NET MVC which enable client and server side validation for MVC. It uses jQuery as well for the client validation. I don't think jQuery Validation is easy to be used in ASP.NET web forms as the page structure actually differs. However, we may find some other versions suitable for ASP.NET Web Forms in the future.

Unlike the ASP.NET validation controls which you need to inject inside your markup, jQuery Validation Plugin puts all the validation rules in one place. I think this really a benefit. In fact, this is one of the benefits of using jQuery itself - thanks for the nice selectors. This style definitely enhance your code readability by separating the validation stuff away from the markup giving the designers - and even the devs - more clean markup to work in.


Saturday, March 01, 2008

Get the Last Run Query in SQL Server 2005

Have you ever run an update or delete query by mistake and you need to roll back or at least want to know the last run query to fix the problem? The following SQL statement can help in that.

SELECT deqs.last_execution_time AS [Time], dest.text AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC
This will retrieve the last run queries with its execution time.


Inversion of Control & Dependency Injection

In the last Thursday, 28th Feb. 2008, we had our internal demoday in SK. The day was really informative. We had many interesting topics in different fields. My topic was an introduction about the inversion of control and the dependency injection. You can download it from here:

Download: Internal_Demoday_28_2_08_IoC_DI.pptx

N.B: Most of the examples in the presentation use Sprint.NET as a DI framework.

If you want to go deeper in the topic, I recommend the following article: Inversion of Control Containers and the Dependency Injection pattern. The author is Martin Fowler - Chief Scientist, ThoughtWorks - and the article is considered to be the ideal reference for the topic.