FlexTime plugins

For me, FlexTime has become very useful. One of the reasons it is so useful is that I have written a few plug-ins that complement the standard functionality. For example, I have always kept a log of my working hours. It is a simple text file, written in the GNU ChangeLog style (I guess old habits really do die hard.) I use a plug-in that reads the diary file and displays it in FlexTime, providing context to the working hours spent. For me, it is very useful.

Keywords extracted from my diary file.

The projects Doorstop and Jupiter show up as keywords in FlexTime as shown in the image above. I can see at a glance how much time I have spent on each task. Since I write the diary anyway, I find it very useful to let FlexTime extract the tags and display them with time calculations.

I have a public Git repository for most of the plugins that I have written. I hope you might find the code useful too. The repository is hosted at Github.

Using an adorner with WPF DataGrid

Growing tired of manually keeping track of my work time, I wrote FlexTime, a small application that keeps track of the times I work on my computer and then summarize the result in a time sheet each week.

All good fun, but since I had a few moments to spare, I decided to add support for project information: textual information on what I have been working on. So I added a DataGrid and wrote a small plugin framework so that users can roll their own storage backend.

Again, good fun but then I wanted to indicate in each grid cell the plugin name of the particular comment. Just a small, quiet label at the bottom right, like the image below.

DataGrid Adorner
A small, quiet text (“Native”) is placed to the bottom right of each row to indicate the source of the comment.

The obvious solution to use a DataGridTemplateColumn and a Grid with two text boxes has focus problems. Instead, a cleaner solution is to use an Adorner class on a DataGridTextColumn.

The basic idea is to attach the adorner layer to the data grid cell and provide a dependency property where we can set a data template for the adorner using XAML.

First the adorner class. We simply use a ContentPresenter, passing it the template and content.

Then we derive our own class from the DataGridTextColumn where we define a new dependency property for the template and wire up the adorner class.

And finally we can utilize the new adorner column in the XAML:

Both the power and complexity of WPF does not cease to amaze me. Pretty schweet, methinks and great fun too. Look out for the next release of FlexTime.

Map engine for WPF GIS applications

Why is it so hard to buy a map engine to be embedded into a .NET WPF desktop application? When developing your typical command and control system, selecting a GIS component to embed into your WPF based client can be really difficult.

The choices available are either too limited with regards to supported map data formats, requires data pre-processing or have wholly inadequate licensing models, pricing or both. Most, if not all of the better choices are based on ActiveX which makes them somewhat cumbersome to embed in clients built on WPF.

Many organizations are moving to more agile development processes where specific architectural roles are often discouraged. Everybody are expected to be able to work on the complete application stack and that means having access to all the tools needed, including the map engine SDK. Pricing and licensing really becomes an issue for teams wanting to stay truly agile.

I feel that WPF is about to finally break through in corporate business applications. Silverlight has made a difference and the tooling, both the Expression suite and Visual Studio 2010 is getting there, albeit a little late, perhaps. This could mean trouble for the established vendors if they don’t act to accommodate this growing market.

I would like to see a map engine component that does the following:

  • Native .NET WPF control
  • Reference system supported canvas for drawing on layers
  • Complete documentation with a rich set of samples
  • $499 for the SDK
  • No charge for the runtime

I think that there might be a feature list in there somewhere that includes just the right amount of functionality that perfectly executed could have fantastic potential. What do you think?

Using SpatialAce in WPF applications

It’s been a long while since I blogged about SpatialAce. It’s even got a new name since the last time i wrote about it: Carmenta Engine. So I thought I’d write one last post about this excellent GIS map engine; this time about using it in a Windows Presentation Foundation (WPF) application.

Since Carmenta Engine is an ActiveX control, you need to use a WindowsFormsHost wrapper class. I will show a technique where we will create an intermediate WPF wrapper that will enable us to implement a few custom dependency properties that we can use for setting configurations files and view names in XAML.

Start by adding a new WPF Library project to your solution. Name the new project CarmentaEngine. Then add a new Windows Forms UserControl and name it CarmentaEngineFormsControl. Make sure that you choose a Windows Forms control, not the WPF equivalent. In this UserControl, you drop your Carmenta Engine ActiveX control and set it’s dock property to fill.

Now create a WPF UserControl in the same project and drop a WindowsFormsHost into it. Name the WPF UserControl CarmentaEngineControl. We can now add the just created Windows Forms UserControl to the WPF UserControl. Sounds a little complicated? Well, the benefit here is that we can implement dependency properties for Carmenta Engine in the WPF UserControl that we can use from XAML later.

The file CarmentaEngineControl.xaml should look something like this:

  <UserControl x:Class="CarmentaEngine.CarmentaEngineControl"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"             
      xmlns:code="clr-namespace:CarmentaEngine"
      Height="300" Width="300" >
      <Grid>
          <my:WindowsFormsHost Name="windowsFormsHost1">
              <code:CarmentaEngineFormsControl x:Name="carmentaEngineFormsControl"/>
          </my:WindowsFormsHost>
      </Grid>
  </UserControl>


We’d like to expose the ConfigurationFile and ViewName property of the Carmenta Engine ActiveX control as dependency properties. This is very straightforward code, the only thing to look out for is that we should not set the property values until we have both of them. Setting ViewName without a ConfigurationFile value does not make sense. Here’s the code behind from CarmentaEngineControl.xaml.cs:

  public partial class CarmentaEngineControl : UserControl {
  
      public static readonly DependencyProperty ConfigurationFileProperty;
      public static readonly DependencyProperty ViewNameProperty;
  
      private string viewName = null;
      private string path = null;
  
      public CarmentaEngineControl() {
          InitializeComponent();
      }
  
      static CarmentaEngineControl() {
          ConfigurationFileProperty = DependencyProperty.Register
              ("ConfigurationFile", typeof (string), typeof (CarmentaEngineControl), 
               new FrameworkPropertyMetadata
               (null, FrameworkPropertyMetadataOptions.None, OnConfigurationFileChanged));
  
          ViewNameProperty = DependencyProperty.Register
              ("ViewName", typeof(string), typeof(CarmentaEngineControl),
               new FrameworkPropertyMetadata
               (null, FrameworkPropertyMetadataOptions.None, OnViewNameChanged));
      }
  
      private static void OnViewNameChanged
          (DependencyObject d, DependencyPropertyChangedEventArgs e) {
          CarmentaEngineControl control = d as CarmentaEngineControl;
          if (control != null) {
              control.viewName = (string) e.NewValue;
              control.InitializeEngine();
          }
      }
  
      private static void OnConfigurationFileChanged
          (DependencyObject d, DependencyPropertyChangedEventArgs e) {
          CarmentaEngineControl control = d as CarmentaEngineControl;
          if (control != null) {
              control.path = (string) e.NewValue;
              control.InitializeEngine();
          }
      }
  
      public string ConfigurationFile {
          get { return (string) GetValue(ConfigurationFileProperty); }
          set { SetValue(ConfigurationFileProperty, value); }
      }
  
      public string ViewName {
          get { return (string)GetValue(ViewNameProperty); }
          set { SetValue(ViewNameProperty, value); }
      }
  
      private void InitializeEngine() {
          if (path != null && viewName != null) {
  
              FileInfo fileInfo = new FileInfo(path);
              if (fileInfo.Exists) {
                  AxSpaceX spaceX = carmentaEngineFormsControl.axSpaceX1;
                  spaceX.ConfigurationFile = path;
                  spaceX.NameSpace = Path.GetFileNameWithoutExtension(path);
                  spaceX.ViewName = viewName;
  
                  spaceX.Tool = new RoamToolClass();
              }
          }
      }
  }


That’s basically all there is to it. Now, in your original WPF application project, reference the WPF Library project from above and add the following code to your XAML:

  <CarmentaEngine:CarmentaEngineControl 
            Margin="31,0,475.75,19" Height="177" VerticalAlignment="Bottom" 
            ConfigurationFile="path to configuration file"
            ViewName="the name of your view"/>


Don’t forget to reference the CarmentaEngine project in your header:

  xmlns:CarmentaEngine="clr-namespace:CarmentaEngine;assembly=CarmentaEngine"


Since last week, I no longer work at Carmenta so I can’t verify the syntax. I based the code on some notes on how I did this a few weeks ago and I hope I got all the details right. I should also say that this was my first encounter with WPF and I found the MSDN documentation to be a little terse. In other words: there might be syntax errors above and better ways to do this, but I found the technique to have a separate WPF library with custom dependency properties to be pretty powerful.

Serving Mercurial using Apache on Ubuntu

If you have even the slightest interest in revision control systems chances are you have been keeping an eye on the development of distributed systems. The dust has not settled yet but I think that Sun’s decision to go with Mercurial for OpenSolaris and OpenJDK makes that particular program a fairly safe choice. Some history on Sun’s choice here. A good and fairly recent comparison here. Don’t miss out on Linus Torvald’s recommendations to the KDE people.

I have only very briefly tried out distributed revision control systems. The point that stands out for me is the powerful idea of the dual push-pull model. First there is the pull model; sandboxed development where one or more developers collaborate, pulling sources from each other. Each user is responsible for pulling changes from others and the model requires close collaboration and communication. This is the development model usually described and advertised for distributed revision control systems.

The second development model is the push model where changes are pushed to one or more central, master repositories, much like you would check in sources into Subversion or any other centralized version control system. For commercial projects, you will probably want to support this second mode, setting up master repositories that represents the stable state of your project. Sooner or later you will need HTTP read access to the masters. If nothing else, how else will your Hudson build server access the stable branch?

I really like Mercurial’s serve command that starts serving your repository over HTTP. Just type hg serve and others can access your repository for pulling over the net, just like that. This is not what you want for your master repositories though. For those you will want a permanent solution and that means using CGI scripts.

The Mercurial book contains a chapter about serving HTTP using CGI that is a good starting point. There are also a few posts on the net that I also found useful, here and here. The instructions below have been tested on a blank Ubuntu 7.10 (Jeos) box. I have chosen Apache as the web server.

I choose to place the root of the Mercurial repositories at /srv/hg/. See the FHS for more information on that choice. Serving HTTP access is made using a CGI script, shipped with Merurial. I prefer to place the script next to the repositories in a directory called /srv/hg/cgi-bin/.


  # mkdir /srv/hg
  # mkdir /srv/hg/cgi-bin

Below, I’ve chosen to copy the hgwebdir.cgi script which enables access to multiple repositories using the same root.

  
  # cp /usr/share/doc/mercurial/examples/hgwebdir.cgi /srv/hg/cgi-bin/
  # chmod a+x /srv/hg/cgi-bin/hgwebdir.cgi 

Create a file /srv/hg/cgi-bin/hgweb.config that contains the following two lines:


  [collections]
  /srv/hg/ = /srv/hg/

And that’s it as far as Mercurial goes. Just remember that it is Apache that will run the mercurial commands through the CGI scripts. It means that you will need to give read access to the world for the repositories


  # chmod a+rX /srv/hg/your repo(s)

All that’s left to do is setting up a web server to serve the Mercurial CGI script above. There are several servers to choose from. I’ve chosen to use Apache:


  # apt-get install apache2

Rather than edit the default site, I find it cleaner to setup a separate, new Merurial site. Create a new file /etc/apache2/sites-available/hg and add the following lines:


  NameVirtualHost *
  <VirtualHost *>
    ServerAdmin webmaster@localhost

    DocumentRoot /srv/hg/cgi-bin/

    <Directory "/srv/hg/cgi-bin/">
      SetHandler cgi-script
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all
    </Directory>

    ErrorLog /var/log/apache2/hg.log 
  </VirtualHost>

Disable the default site, enable our new Mercurial site and reload the Apache server.


  # a2dissite default
  # a2ensite hg
  # /etc/init.d/apache2 reload

That’s it. You should now be able to see all your repositories if you point your browser to http://yourhost/hgwebdir.cgi/

SQL Server 2008 slips

Microsoft SQL Server 2008 is late. Hardly unusual or perhaps even surprising given the complexity of these things. Microsoft is nowadays even trying to be pretty transparent about such things, blogging about changes to important roadmaps and so on. However, Francois Ajenstat’s announcement that SQL Server has slipped was more opaque than usual and quite frankly somewhat hard to understand. Enough so that Phil Factor wrote very funny reply to the market-speak of Francois Ajenstat. A must read.

You suck at Photoshop

There are plenty of good tutorials on Photoshop available on the Net. Some commercial, some free of charge. However, the “You suck at Photoshop” tutorials by Donnie Hoyle has to be the funniest of them all. There’s four of them on YouTube so far and they’re all hilarious.

  1. Distort, warp and layer effects
  2. Old school
  3. Clone stamp and manual cloning
  4. Paths and masks

“Strap on your stupid and lets get at it.”

Hudson love

Some time ago I tried having a separate build machine performing continuous builds every time I checked my project sources into Subversion and I was quickly hooked. It’s a very simple idea but I always found it a little hard to fully appreciate the benefits before I tried it in a real project.

While having a build machine really shines with unit tests, it has a place even when you don’t have any unit testing at all in place. Firstly, you catch those time-consuming errors not having added all files to the version control system. Breaking a build wastes time for the entire team. Secondly, you have an incentive to keep the build process sane since the system gets built all the time. Building a system really should be as simple as checking the sources out and running a single command. Performing automated builds can help simply because setting up the builds becomes troublesome otherwise!

So here’s a suggestion for you existing project that does not have any unit tests: setup a build machine that builds the project every time someone checks something in. Then create a single unit test and have it run as part of the continuous build process. That’s it. You will now know that your project can be built and that it at least passes some simple test. Moving forward, you can for example make a point of creating a unit test for all new bug reports from customers. You decide, but knowing that your project builds alone can be worth quite a lot.

There are several applications for continuous integration to choose from. Most of them seem to have been developed within the Java community, but they are capable of running much more than Java builds and JUnit tests. The first build system I tried was CruiseControl because it seemed an obvious choice at the time. It has performed very well, though I remember it was a little cumbersome to set up. Since I recently needed to set up CruiseControl from scratch I figured I might just as well try Hudson out.

For me, the major advantage of Hudson, besides the much neater interface, is the packaging and running behavior. Hudson is delivered as a WAR file that you can deploy on any Java servlet container, but it also contains Winstone, a lightweight servlet container so that you can actually run Hudson “self-hosted” by simply going:


$ java -jar hudson.war

Starting a self-hosted Hudson on a Linux box as a daemon, typically requires an System V init.d script. I can post a little information on how to write such a script and have Hudson start each time your System V machine boots if you wish; It’s not hard since Hudson will run as a single process, but a better solution might be to deploy Hudson to a servlet container, like Tomcat, JBoss or Glassfish.

A reasonable choice of servlet container for an Ubuntu box is Tomcat, simply because it is available as an Ubuntu package. Installation requires you to enable the universe and multiverse repositories. Details on how to do that can be found here. Once those repositories are enabled, you can install Tomcat and Hudson on an Ubuntu box by following these steps:

We start by installing Java and Tomcat.


# apt-get install sun-java6-jdk
# apt-get install tomcat5.5

Sun’s Java should be the default but if it is not, you can select the default Java by:


# update-alternatives --config java

Tomcat on Ubuntu comes with the security manager enabled by default and this will cause Hudson not to run. You can disable the security manager by editing the /etc/default/tomcat5.5 file.

Next we need to set the home directory for hudson. Add the following line to /etc/tomcat5.5/context.xml


<Environment name="HUDSON_HOME" value="/srv/hudson" 
  type="java.lang.String" override="false"/>

As you can see, I choose /srv/hudson as the home directory. See the FHS for details on that choice. Whichever directory you choose, create the directory and set the ownership so that the tomcat55 user can use it and restart Tomcat:


# mkdir /srv/hudson
# chown tomcat55.nogroup /srv/hudson/
# /etc/init.d/tomcat restart

Now, simply deploy Hudson by copying the hudson.war file into the /var/lib/tomcat5.5/webapps/ directory. Tomcat will notice the new file and deploy it automatically. Verify that it all works by pointing your browser to http://hostname:8180/hudson/ To update Hudson simply copy the new hudson.war file to the same location, overwriting the old.

If you wish to restrict access to Hudson, add the following two lines to /etc/tomcat5.5/tomcat-users.xml:


<role rolename="admin"/>
<user username="hudson-admin" password="secret" roles="admin"/>

Restart Tomcat and enable security in the Hudson System Configuration panel. Users not logged in will still be able to access builds but cannot adjust the settings or force new builds.

Update 2008-12-28:

I just verified that the installation instructions are still valid on Ubuntu 8.10 using Tomcat 6. All you have to do is replace tomcat55 with tomcat6 above; also, the port seem to have changed from 8180 to 8080. Here’s an updated installation summary:

Install Java and Tomcat.


# apt-get install sun-java6-jdk
# apt-get install tomcat6

Configure or disable the security manager:


  # vi /etc/default/tomcat6

Set the home directory for Hudson by adding the follwowing line to /etc/tomcat6/context.xml


<Environment name="HUDSON_HOME" value="/srv/hudson" 
  type="java.lang.String" override="false"/>

Create the home directory, set the permissions and restart Tomcat


# mkdir /srv/hudson
# chown tomcat6.nogroup /srv/hudson/
# /etc/init.d/tomcat6 restart

Deploy Hudson by copying the hudson.war file into the /var/lib/tomcat6/webapps/ directory. Verify that it works by pointing your browser to http://hostname:8080/hudson/

Sixteen applications on my Mac

I’ve added quite a few applications to my Mac over the last year. Here’s the list:

Adobe Photoshop
And I’ve paid for it.
Aperture
I take thousands of images each year and managing all those photos can be a real problem. Aperture (like Adobe Lightroom) is designed for just that purpose. Previously, I could hesitate taking pictures because I knew I had to sort them out later. I don’t hesitate like that anymore.
AppZapper
It truly is the application that should have been included with my Mac from the start. I fail to see why Apple still has not bought the company and made it part of the OS X.
Disco
Yeah, like you really need a CD burning program. I bought it because my backup disks started spanning multiple DVDs and Disco handles that automatically. And it smokes. Like, really smokes.
Emacs
Emacs. Can’t do without Emacs.
LicenseKeeper
LicenseKeeper keeps all those license keys in order. Sounds a little silly; all you need is a text-file and a mail folder, no? I dunno but LicenseKeeper is one of the neatest little utilities I’ve yet to come across.
Parallels
One of the reasons I bought a Mac was that with Intel Core Duo and Parallels you could run hardware supported virtualization, promising almost native performance for Microsoft Windows. A year later, I can only attest to that promise: it works great.
Picturesque
Neat little thingie to batch process images for a small set of available effects. It doesn’t do a lot but it does it really well.
RapidWeaver
I looked for an alternative to iWeb which is really underwhelming and RapidWeaver seemed an obvious choise. It’s pretty neat when you want to make a site quickly, without any fuss. If you like to fuss, this is not for you.
Scrivener
Don’t use it much anymore but if you are a writer, or needs to write something non-trivial, it makes a lot of sense for the capturing phase. It’s not a word-processor and it’s not a mindmap thing. It’s somehwere in between… a note taking editor organizer, perhaps.
SpamSieve
I use Mail.app and the built in spam filter wasn’t good enough. I was used to the excellent performance of bogofilter on my Debian box and needed something just as good for the Mac. SpamSieve is good. I don’t get as good results as with bogofilter, but close.
SuperDuper!
Stupid name but a nice backup application. In Leopard there is Time Machine, of course, but SuperDuper! is still my choice since the application is so simple to use. But who in their right mind puts an exclamation point in their product name?
Tangerine!
Another application with an exclamation point in the name! What’s wrong with these people? I don’t use it much anymore. It has a lot of promise but fails to deliver. Needs an update!
TextMate
I got it for the buzz and because I heard that die-hard Emacs users where switching. I quickly went back to Emacs again though. I think that you can write plugins to TextMate in several different languages, which seems pretty interesting. Of course, Emacs is not only an editor, it’s a full Lisp interpreter which makes it the undisputed king of all editors.
Transmit
You’ll need a good ftp application and this is the one you are looking for.
VMware Fusion
I’ve always thought less of VMware because of how they case their company name, but they make good hypervisors. I grew tired of Parallels lack of Linux support and got VMware Fusion to replace it.

Med nedpackat spö vid Svanån

När jag svänger in till parkeringen vid Svanån så lättar regnet som fallit under morgonen och jag bestämmer mig: idag ska jag ska inte ens tackla upp mitt spö förrän jag får syn på en fisk. Inget blindfiske här inte. Det är varmt ute, men regnet som föll på vägen upp ger mig lite självförtroende. Början på juni, varmt med växlande sol och regn — det kan bli hur bra som helst. Så jag packar ner kaffe och lunch i ryggsäcken och ger mig ut i skogen för att se om jag inte kan få syn på vakande öring.

SvanånSvanånSvanån

Det är väldigt praktiskt med ett fyrdelat spö. Det är enkelt att ta med sig och om man, som jag gör idag, vandrar utefter ån så är det väldigt smidigt att ha en så kort förpackning med sig. Jag köpte spöt som ett komplement, för att jag skulle kunna ha det med mig på en resa, men nu för tiden så använder jag inte något annat.

Åtminstone ytterligare någon person har varit och gått längs ån sedan jag var här sist för två veckor sedan, jag ser tydliga spår kring parkeringen vid Svanån. Men nedströms, mellan vägbron och parkeringen så är det som om jag är den första som går här denna säsongen. Bitvis är det lite knepigt att ta sig fram eftersom det fortfarande ligger fällen från Gudrun och Per och det kanske är därför som det ser ut att vara så lite folk som är här och fiskar. Jag skrämmer upp en älgkalv som är nere och dricker och det känns som om ån är bara min idag.

Jag spanar och letar efter vak eller andra tecken som kan avslöja en fisk, men solen bryter snart igenom molntäcket och vattnet är minst lika lågt som det var sist. Jag känner på mig att fiskespöt kanske inte kommer fram ur ryggsäcken alls idag. Solen stiger högre på himlen och temperaturen närmar sig 25 grader. Jag sätter mig ner i mossan med en gran som ryggstöd där jag har utsikt över en fin sväng som ån gör över en liten nacke och äter min medhavda soppa. När maten är slut och kaffet urdrucket så har jag fortfarande inte fått se någon fisk tillräckligt stor att fiska på. En del småöring sprätter efter dagsländor som kläcker i enstaka exemplar men de större fiskarna verkar föredra de nedre regionerna.

SvanånSvanånSvanån

Det kliar lite i fingrarna att lägga ut en nymf i den lite djupare strömmen under bron vid parkeringen. Här står ofta regnbåge och lurar bakom stenarna. Men jag har bestämt mig: inget fiskande om jag inte får syn på fisk och spöt förblir i sitt fodral. Att låta bli att fiska är faktiskt ett bra sätt att njuta av Svanån. Den småländska skogen står grön och vacker, inbjudande till strövande nu under juni. Allemansrätten är en underbar uppfinning!

Om jag hade kunnat stanna till kvällen så kanske det hade kunnat bli väldigt annorlunda. Värmen kan kanske få någon kläckning att komma igång och när solen går ner över skogen så kanske det hade kunnat bli ett riktigt fint fiske. Många kanske men strömmande vatten kan verkligen byta personlighet när kvällen kommer och solen sjunker ner bakom träden. Jag stannar en stund efter lunch men måste sedan ge mig av igen. Det har varit en fin dag i skogen, fåglarna har tystnat allt mer de de senaste veckorna men jag får faktiskt höra göken spela, kanske för sista gången i år?