Sergio and the sigil

Video - ThoughtWorks Cruise at Chicago ALT.NET

Posted by Sergio on 2008-08-20

This video was captured at the Chicago ALT.NET August 13th meeting. This first video is the Cruise presentation.

Cruise and Agile discussed - videos forthcoming

Posted by Sergio on 2008-08-15
Update: The videos of the presentation and discussion have been posted.

This month's Chicago ALT.NET meeting was pretty awesome and it was all caught in video. As soon as I have some time to do some post-production on the raw material (read, just stitch pieces together) I'll make it available somehow.

As previously mentioned we started off with a presentation of ThoughtWorks Cruise, where Robert Norton explained the idea of CI server, Agents, Pipelines and went through many of Cruise features, system requirements, and futures. He also clarified his company's position regarding CruiseControl.net, which will most likely not receive a lot of attention in terms of funding, being left for the community to keep it going.

Cruise seemed promising to me but it's clearly a typical version 1 product that needs some work to get enthusiastic thumbs up from me. Hopefully they move quickly and release a few updates before the year is over to make the product top notch. I don't mean to say Cruise in unusable. It's definitely usable and does things in a very smart way. Given time I'm sure they will take care of the rough edges and have a chance to answer customer feedback. My particular concerns tend to be on the side of ability to integrate with other systems in the enterprise, like your bug/feature tracker.

After the presentation portion we all sat together for an open discussion. The fallback topic was CI practices but what the group really wanted to talk about was Agile teams and their dynamics, so that's what the discussion became. As usual, that's my favorite part of the meeting and it's a pity that only 50% of the attendance stuck around for it.

It's nice when you go to a meeting like this and can take home a lot of new knowledge.

Software I can't work without

Posted by Sergio on 2008-07-31

I'm about to configure a new development machine this week. It's going to be my 3rd install from scratch in the last 12 months, which I know is not all that much, but certainly more than I wish I had to.

Besides the common software development tools, like Visual Studio, SQL Server, Ruby, Office, Firefox, SVN, etc, over the years I've collected a number of small tools that I make sure are installed before I start doing anything else.

The list is volatile but some utilities have been there for years. Here's my current list in no particular order:

  • Taskbar Shuffle - I'm sort of a neat freak and this little wonder does only one thing. It lets you rearrange the application buttons in the taskbar. I don't understand how this is still not enabled in Windows out of the box. UPDATE: We have been heard. Windows 7 finally allows you to rearrange the taskbar buttons.
  • Slickrun - I need a command/app launcher and I've settled on Slickrun for some time now. I don't need much from it but I definitely need it. On my mac, as you can imagine, I use Quicksilver.
  • EditPlus - Every serious developer has his favorite text editor. Mine is EditPlus, at least on Windows. It's simple, extensible, has most of the features you'd expect from a text artisan's toolbox. Again, on the mac I'm more obvious and use TextMate, which is quickly becoming my new favorite if I can work on the mac.
  • Truecrypt - In case you aren't familiar with it, Truecrypt is a data encryption software that creates encrypted file systems that that you can mount in Windows, Mac OS X, and Linux. Truecrypt makes encryption a piece of cake and I have been using it since when it's non-Windows support was laughable.
  • Timesnapper - This tool has a very simple premise, it takes screenshots of your desktop on a regular interval. You can later relive your day just like a movie. This application is like my backup memory when I'm preparing my timesheets. It works great with Truecrypt in case you are concerned with having your whereabouts "caught on camera."
  • Lutz Red Gate's .NET Reflector - There's no .NET development without Reflector, I should not even need to mention that I use it. Let's start a campaign to have Reflector bundled with Visual Studio. Update: Reflector was acquired by Red Gate shortly after I wrote this post. I guess they moved quicker than Microsoft and our campaing to have that tool be part of the SDK or Visual Studio is severely at risk.
  • Daemon Tools - Mount ISO images as CD/DVD ROM drives. Update: Apparently I was using a much older version of Daemon Tools and that tool now install spyware even if opt out of installing the stupid toolbar. I'm starting to use Virtual Clone Drive now and it has been alright.
  • Hamachi - VPN made easy as pie. 'Nuff said.
  • Foxit Reader - I can't stand Adobe Acrobloat. Foxit isn't the greatest thing on earth but is good enough and very lightweight.
  • Filezilla - Sooner or later I'll need a FTP client. Filezilla has been good to me.
  • Firebug for Firefox - If there's no .NET development without Reflector, then Firebug is like Reflector for Web development. But I'm sure you already know that.
  • YSlow for Firebug - This nice add-on helps me by suggesting possible ways to improve page loading performance. While you're at it take a look at these other Firebug extensions.
  • 7-zip - Because we all need a shell-integrated compression tool.
  • Tabbed Console - I'm not exactly a command line ninja, but I find myself at the black screen very often. Often enough that it's not rare that I have more than one of those open. The tabbed Console utility allows me to have all my command prompt sessions in the same window. And more than that, I can have flavored command windows tabs, like one for the regular cmd.exe, one for IRb (the Ruby console), one for PowerShell, one for Cygwin, VS Command Prompt, and on, and on.
  • Sysinternals stuff - Sometimes you need to bring the big guns.

What about you? Do you have tools that you feel naked without?

Trying to get rid of MS Access

Posted by Sergio on 2008-04-09

I have this small personal organizer application that helps me keeping track of where my hard earned money is going. There's nothing special about this application other that it was designed to be used only by myself and it works exactly the way I think it should.

This application has been a trusty companion for the last 10 years and it needs its well deserved retirement. This is the last piece of VB6 that I have installed on my system. Since I stopped installing Visual Studio 6 years ago, this means I have been dealing with a couple of known bugs. I also have not added any new feature in a long time (maybe since the year 2000).

This year I decided to finally rewrite this app in .Net and I have an interesting choice to make. The old app uses MS Access for its database and, while I know I could very well keep using Access, I just don't want to deal with Access anymore. It's a technology from the last century and I think there must be something better out there.

A few things I need the database to support:

  • I need to be able to carry the app in a thumb drive and run in any system that only has .Net installed
  • Must be in-process (no service, sorry SQL Express, mySQL)
  • Must be as much compatible with SQL-92 as possible
  • Even better if it's supported by the popular ORM tools

After a brief research I chose a few candidates that seemed convenient: SQLce (because of my familiarity with SQL Server) and SQLite (because it's everywhere, comes on the mac, trivial to install in Linux, it's the new Rails 2.0 default database).

As I'm increasingly living in a multi-platform environment, I think I'm leaning towards SQLite, but I'll welcome other suggestions that fit in the requirements.

I'll return to this topic with my findings and overall development experience with the chosen database in the near future. For now I'll leave these useful SQLite links.

Creating Windows Services

Posted by Sergio on 2008-03-31
How to Create Windows Services

It's not uncommon for an enterprise application to need some form of background processes to do continuous work. These could be tasks such as

  • Cleanup abandoned shopping carts
  • Delete temporary files left behind by some report or image generation feature
  • Send email notifications
  • Create daily reports and send them out
  • Check an email inbox
  • Pull messages from a queue
  • Perform daily or monthly archiving
  • etc

For many of these things there are dedicated tools that provide that feature, like a reporting service (SSRS or BO,) scripts that run in the email server, or even simple executables that are fired by the Windows Task Scheduler. When you have only one or two background tasks, using something like the task scheduler may be OK, but administration quickly becomes painful when the number of tasks grows. The dedicated services like SSRS or BO can be overkill depending on the size of your application or organization.

One approach I like to take is to create a Windows Service for the application, grouping all the different background tasks under a single project, a single .exe, and a single configuration file. Visual Studio has always had a Windows Service project type, but the process of creating a working service is not as simple as you would hope, especially when your service performs more than one independent task.

After creating a couple of services, I realized that I definitely needed to stash all that monkey work somewhere I could just reuse later. I decided to create a helper library to assist creating and maintaining Windows services.

The library doesn't help with all kinds of Windows services, but has helped me a lot with the type of tasks I explained above. The key to the library is the ITask interface.

public interface ITask: IDisposable
{
    bool Started { get; }
    string Name { get; }
    void Start();
    void Stop();
    void Execute();
}

This interface shown all that is needed to create a task that can be started, stopped, and invoked by the service process. But this interface has too many members and many tasks are common enough that these members will be implemented almost identically. For example, tasks that execute on a regular interval will be almost identical, the only different member will be the Execute method. That's why the library comes with some handy base classes as shown in this diagram.

Now when I need to implement a task that runs repeatedly I simply inherit a task from PeriodicalTask or ScheduledTask as seen below. These classes will be part of my service project, from which I remove all the other classes that were added by default.

class CleanupTask : PeriodicalTask
{
    readonly static log4net.ILog Log =
        log4net.LogManager.GetLogger(
           System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public override void Execute()
    {
        //time to run....
        //TODO: write the actual code here
        // ShoppingCart.DeleteAbandonedCarts();
        Log.InfoFormat("Executed: {0}", this.GetType().Name);
    }
}


class DailyReportTask : ScheduledTask
{
    readonly static log4net.ILog Log =
        log4net.LogManager.GetLogger(
              System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    protected override void Execute(DateTime scheduledDate)
    {
        //time to run....
        //TODO: write the actual code here
        // SalesReport.SendDailySummary();
        Log.InfoFormat("Executed: {0}", this.GetType().Name);
    }
}

Instead of hard coding the interval or the scheduled time of the above tasks, we use the service's .config file for that:

<WindowsService>
    <tasks>
        <task name="CleanupTask" interval="600"  />
        <task name="DailyReportTask" time="21:30"  />
    </tasks>
</WindowsService>

There are only a few more things we need to do to get this service ready. First we need to add a new WindowsService item. Here we are naming it MyAppService and making it inherit from from SPServiceBase.

partial class MyAppService : SPServiceBase
{
    public const string MyAppSvcName = "MyAppSVC";
    public MyAppService()
    {
        InitializeComponent();
        //Important.. use the constant here AFTER 
        //   the call to InitializeComponent()
        this.ServiceName = MyAppSvcName;
    }
}

We also need to add an Installer Class, which I'll name simply Installer and which will be invoked during the service installation phase to add the appropriate registry entries to make the service be listed in the Services applet. Here's how this class looks like. Note that it inherits from another base class from the library.

[RunInstaller(true)]
public class Installer : SergioPereira.WindowsService.ServiceInstaller
{
    //That's all we need. Hooray!
}

I mentioned that the installer will add the necessary registry information. Some of that are the name and description of the service. We provide that with an assembly attribute that you can put in the AssemblyInfo.cs or anywhere you like in a .cs file (outside any class or namespace.)

[assembly: ServiceRegistration(
    SampleService.MyAppService.MyAppSvcName, // <-- just a string constant
    "MyApp Support Service",
    "Supports the MyApp application performing several " + 
           "critical background tasks.")
]

A Windows service is compiled as an .exe, so it needs an en entry point, a static Main function. Let's add a Program.cs like this:

class Program
{
    static void Main(string[] args)
    {
        if (!SelfInstaller.ProcessIntallationRequest(args))
        {

            MyAppService svc = new MyAppService();

            svc.AddTask(new CleanupTask());
            svc.AddTask(new DailyReportTask());
            //add more tasks if you have them

            svc.Run();
        }
    }
}

The code above is pretty simple, we are creating the tasks and telling our service to take care of them. Then we start the service. The interesting thing is the call to ProcessIntallationRequest. This is where we added the self-installing capability of the service. If you wrote a service in the past, you know that they get installed by using InstallUtil.exe. One potential problem is that InstallUtil.exe may not be present on the server or not in the PATH, making an scripted installation a little more complicated. Instead, by using the that call from SelfInstaller, we enabled our service to be invoked like the following to install or uninstall it (remember to execute as an Administrator).

SampleService.exe -i[nstall]
SampleService.exe -u[ninstall]

After installing it, you should see the service in the Services applet.

Here's the final structure of our project.

If you want, download the library source code along with a sample service project. There's more in the library than I have time to explain here, including an auto-update task and extra configuration properties for each task.