TDD developer

June 28, 2009

Google Web Toolkit (GWT) on Ubuntu Desktop 9.04

Filed under: Uncategorized — makka @ 12:20 pm

After watching a Google Wave video presentation my interest in the Google Web Toolkit (GWT) grown so I decided to create Virtual Machine with all the stuff I need to play with GWT. I’m using a VMWare virtual machine with Ubuntu Desktop 9.04.

Im order to setup the development environment I found this great blog post with detailed informations on how to set up Glassfish, Eclipse, Google Web toolkit (GWT), Development Environment on Ubuntu Desktop 9.04.

I follow the instruction step by step. I’m not a Linux geek but everything was quite easy. Here below you can see my first application build with GWT.

Capture

Technorati Tag: ,,

June 25, 2009

Moonlight on Ubuntu 9 with Firefox

Filed under: Uncategorized — makka @ 7:14 pm

Just few mouse clicks and it works like a charm.

Here below you can see the site of the italian national television build with silverlight 2.0

Capture

Technorati Tag: ,,

June 21, 2009

NHibernate 2.1.0 beta 2

Filed under: .NET, nhibernate — makka @ 5:15 pm
Tags: ,

Today NHibernate team released version 2.1.0 beta 2

This version contains a fix for bug that cause some problem with MS Sql server execution plans (more details here).

Be carefull if you use an HQL query cause the actual parser is not still able to use the correct parameter type. I hope also this issue will be solved in the future versions but in the meantime you can use the solution I wrote in post linked above.

Technorati Tag: ,

April 19, 2009

LINQ to NHibernate

Filed under: .NET, nhibernate — makka @ 2:29 pm
Tags: , ,

This is a very great news for NHibernate!

Time for another update; it’s been a while since the last one. Good progress has been made on the new HQL AST Parser port from Hibernate, and it’s now in a state where it’s usable, passing the vast majority of the tests within the NHibernate test suite. Of those that are failing (around 8 out of over 1600), we are currently discussing on the developers group whether we will live with these minor breaking changes, or do continued work on the parser to get everything passing.

March 10, 2009

NHibernate queries & sql server execution plans

Filed under: .NET, nhibernate — makka @ 8:57 pm
Tags: , , ,

In these days I’m working with Andrea on a web application using ASP.NET & SQL Server . You should kwon that Andrea, is a SQL Server MVP, but fortunately is not a T-SQL taliban so he agree without hesitation when I proposed to use NHibernate to build our data access layer. When a tool can help us while building an application why not use it ?

As you can image a skilled DBA like Andrea can rapidly find a bottleneck in any query fired to a database. While writing a simple query using NHibernate API we noticed a strange behavior of NHibernate 2.0 with parameters. Here is the code we wrote:

using (ISession session = factory.OpenSession())
{
	//nvarchar(4)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetString("desc", "zon%")
		.List();

	//nvarchar(5)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetString("desc", "zone%")
		.List();
}

This code generates these two sql queries:


exec sp_executesql N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',N'@p0 nvarchar(4)',@p0=N'zon%'

exec sp_executesql N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',N'@p0 nvarchar(5)',@p0=N'zone%'

As you can see the parameter type is different in the two statements. This unfortunately cause SqlServer to generate two different exection plans. If you need the best performace you should avoid this behaviour. If you send to the database queries using the same parameter (type & size) SqlServer use his internal cache. You have already pay for it so why not to use it ?

I had the pleasure to discuss with Fabio Maulo about this topic (you can read here. The conversation is in italian). At the end I found this solution:

I edited my hibernate.cfg.xml file adding this node to the xml

<property name="prepare_sql">true</property>

and then I wrote this code:

using (ISession session = factory.OpenSession())
{

	//nvarchar(10)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "zoneh%", TypeFactory.GetStringType(10))
		.List();

	//nvarchar(10)
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "neh%", TypeFactory.GetStringType(10))
		.List();
}

Now with this code NHibernate generates these two sql queries:

declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@p0 nvarchar(10)',N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',@p0=N'zoneh%'
select @p1

declare @p1 int
set @p1=2
exec sp_prepexec @p1 output,N'@p0 nvarchar(10)',N'select region0_.RegionId as RegionId0_, region0_.RegionDescription as RegionDe2_0_ from Region region0_ where (region0_.RegionDescription like @p0 )',@p0=N'neh%'
select @p1

This is better cause the parameters length is always the same. Now your database will thank you for this! But wait you can still do something better.

If your database column type is a varchar and not nvarchar you can improve your code using a different SqlDbType. How ? Whit his code:

using (ISession session = factory.OpenSession())
{
	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "z%", TypeFactory.GetAnsiStringType(15))
		.List();

	session.CreateQuery("from Region r where r.Description like :desc")
		.SetParameter("desc", "za%", TypeFactory.GetAnsiStringType(15))
		.List();
}

Now the parameter type is a varchar and the size is always 15. Whit this latest improvement you remove a CONVER_IMPLICIT operation from your query execution plan (futher details here but in italian ). This cast operation cost something so if you don’t need it why to remove it ?

I hope this will help someone (dev & dba) in the future!

February 1, 2009

NAnt sucks and Rake rocks

Filed under: continuous integration — makka @ 1:34 pm
Tags: , , ,

In these days I’m moving my build scripts from NAnt to Rake. The main reason for doing this is that I’m moving from external dsl to an internal dsl. Internal DSLs are often the most approachable form of DSLs to write. Unlike external DSLs you don’t need to learn about grammars and language parsing, unlike language workbenches you don’t need any special tools. With internal DSLs you work in your regular language environment.

This means that now I build my build scritps just with ruby. I believe this is a good way to learn this nice language. Rake in fact is nothing more that a Ruby library.

Getting started with Rake and .NET is very easy:

  • Download the Ruby for windows one click installer.
  • Install it
  • Create a file Rakefile.rb (type is text file)
  • Type:
    task :default => :build
    
    task :build => [:compile, :test, :deploy] 
    
    task :compile do
      params = '/t:Rebuild /nologo /v:m /p:Configuration=Release src\demo.sln'
      msbuid = 'C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe'
      sh "#{msbuid} #{params}"
    end
    
    task :test do
     runner = 'tools\\Gallio\\Gallio.Echo.exe'
     assemblies = FileList["src/**/bin/Release/*.Fixture.exe"]
     extension = '' #'/e:TeamCityExtension,Gallio.TeamCityIntegration'
     sh "#{runner} #{assemblies} #{extension}"
    end
    
    task :deploy do
        sh "echo Task not yet implemented!"
    end
  • Open a command prompt (Start->Run->Cmd)

  • Type: cd c:\[my RakeFile.rb folder] (obviously put your own path in)

  • Type: rake
  • Done!

As you can see here above with rake there is no need to learn some crazy xml syntax. Whit this little script I compile my solution and run all unit tests. No need to write xml, only some ruby code.

Nothing more nothing less.

Technorati Tag: ,,,

January 6, 2009

PowerCommands for Visual Studio 2008

Filed under: .NET — makka @ 1:18 pm
Tags: ,

I think Visual Studio 2008 is a great development environment but you can still improve its usability with some free add-in. For example "PowerCommands for Visual Studio 2008" is a set of useful extensions for VS 2008 that add a bunch of cool features to the IDE.

You can download the installer from here

Technorati Tag: ,

January 5, 2009

NAnt + NDepend.Console.exe and relative paths

Filed under: continuous integration — makka @ 1:31 pm
Tags: , ,

If you read the documentation of NDepend.Console.exe you learn that relative paths are not supported. These remarks also apply to paths provided with options /InDirs /OutDir and /XslForReport.

Here you can see the result of a wrong line command

image

and here the result of a right line command

image

Unfortunately this is a problem for my solutions cause I need always relative path. My solution are continuous integrated using TeamCity and in my setup the build agent checks out sources in a random folder on the build agent machine (for eg. C:\BuildAgent\work\12724a65ddd4c6d0).

Here the Version Control Settings page of my project inside my TeamCity server where you can set the checkout directory.

image

Using relative path for me is a plus cause allow developers to freely decise the checkout project folder. For some of our customer this has been a project requirement.

Ok now you know why I need relative paths. Now I want to explain how I use NAnt + NDepend inside my continuous integrated solution. 

This is the target I use to run NDepend.Console.exe.

image

As you can see using the directory::get-current-directory I can build an absolute path at run-time. Maybe this result can be obtained using the built-in property  ${nant.project.basedir} but this is marked as deprecated so I prefer to use the directory::get-current-directory function.

December 25, 2008

Microsoft Sync Framework using IronRuby

Filed under: .NET, Uncategorized — makka @ 11:38 am
Tags: ,

Microsoft Sync Framework is a comprehensive synchronization platform that enables collaboration and offline access for applications, services and devices. It features technologies and tools that enable roaming, sharing, and taking data offline. Using Microsoft Sync Framework, developers can build sync ecosystems that integrate any application, with any data from any store using any protocol over any network.

In these days we used Microsoft Sync Framework to develop some occasionally connected application. These application use Microsoft Sync Framework to synchronize their local storage with the centralized database hosted on-line.

Microsoft Sync Framework includes a number of providers that support common data sources. The following providers are included:

  • Sync Services for ADO.NET: Synchronization for ADO.NET enabled data sources
  • Sync Services for File Systems: Synchronization for files and folders
  • Sync Services for FeedSync: Synchronization for RSS and ATOM feeds

Key features of the File system provider include:

    • Incremental synchronization of changes between two file system locations specified via a local or UNC path.
    • Synchronization of file contents, file and folder names, file timestamps, and attributes.
    • Support for optional filtering of files based on filename/extensions, sub-directories, or file attributes
    • Optional use of file hashes to detect changes to file contents if file timestamps are not reliable
    • Reliable detection of conflicting changes to the same file and automatic resolution of conflicts with a no-data-loss policy
    • Allow for limited user undo operation by optionally allowing file deletes and overwrites to be moved to the Recycle Bin
    • Support for Preview mode which provides a preview of the incremental sync operation without committing changes to the file system
    • First-class support for the scenario where the user may start synchronization with equal or partially equal file hierarchies on more than one replica.
    • Support for graceful cancellation of an ongoing sync operation such that the remaining changes can be synchronized later without having to re-sync changes that were already synchronized.

An example of Sync Services for File Systems usage can be found here. In order to test IronRuby I decided to convert this sample from C# to Ruby

require "mscorlib" require "Microsoft.Synchronization.dll" require "Microsoft.Synchronization.Files.dll" include System include Microsoft::Synchronization include Microsoft::Synchronization::Files class Syncronizer def DoWork replica1RootPath, replica2RootPath idFileName = "filesync.id"; replica1Id = GetReplicaId( replica1RootPath + "/" + idFileName) replica2Id = GetReplicaId( replica2RootPath + "/" + idFileName) options = FileSyncOptions.RecycleDeletedFiles filter = FileSyncScopeFilter.new filter.FileNameExcludes.Add idFileName DetectChangesOnFileSystemReplica replica1Id, replica1RootPath, filter, options DetectChangesOnFileSystemReplica replica2Id, replica2RootPath, filter, options SyncFileSystemReplicasOneWay replica1Id, replica2Id, replica1RootPath, replica2RootPath, filter, options SyncFileSystemReplicasOneWay replica2Id, replica1Id, replica2RootPath, replica1RootPath, filter, options end def GetReplicaId path id = Guid.NewGuid if File.exist? path str = File.read path id = Guid.new(str) else File.open(path, 'w') {|f| f.write(id.ToString) } end id end def DetectChangesOnFileSystemReplica replicaId, rootPath, filter, options provider = FileSyncProvider.new(replicaId, rootPath, filter, options) provider.DetectChanges; provider.Dispose end def SyncFileSystemReplicasOneWay sourceReplicaId, destinationReplicaId, sourceReplicaRootPath, destinationReplicaRootPath, filter, options agent = SyncOrchestrator.new agent.LocalProvider = FileSyncProvider.new(sourceReplicaId, sourceReplicaRootPath, filter, options) agent.RemoteProvider = FileSyncProvider.new(destinationReplicaId, destinationReplicaRootPath, filter, options) agent.Direction = SyncDirectionOrder.Upload agent.Synchronize end end sync = Syncronizer.new sync.DoWork "D:/tmp/SyncFXSamples/A", "D:/tmp/SyncFXSamples/B"

I have uploaded a little zip here that contains all the stuff you need to get ready. If you want to run the sample you have to run the command: ir sync.rb as show below

image

Technorati Tag: ,

December 1, 2008

Use NAnt to run mbunit tests using gallio

Filed under: Uncategorized — makka @ 7:55 pm
Tags: , ,

Gallio has a great build-in support for NAnt!
Unfortunately at the moment this is not well document so if you need to create a target to execute all tests inside an assembly you can write this xml fragment inside your NAnt project file:

<target name=”test” depends=”build”>
  <gallio
    result-property=”exitCode”
    failonerror=”false” >
    <runner-extension value=”TeamCityExtension,Gallio.TeamCityIntegration” />
    <assemblies>
      <!– Specify the tests assemblies –>
      <include name=”${src.dir}Data.Fixturebin${project.config}Data.Fixture.dll”/>
    </assemblies>
  </gallio>
  <fail if=”${exitCode != ‘0′}” >One or more tests failed. Please check the log for more details</fail>   
</target>

don’t forget to load Gallio NAnt Tasks before start with this line of xml

<loadtasks assembly=”.toolsGallioGallio.NAntTasks.dll” />

If you need more information you can take a look at comment in the source code here

Technorati Tag: ,,
Next Page »

Blog at WordPress.com.