Archive for February, 2008

Published by breki on 29 Feb 2008

Friday Goodies - 29. February

.NET Development

Development

Miscellaneous

Published by breki on 29 Feb 2008

Multiple instance Windows service in C#

The standard way of installing Windows services using the Visual Studio Windows Service project and the InstallUtil.exe tool does not allow the user to specify the service name after the project has been compiled. This is problematic if you want to install two or more instances of a Windows service on the same computer. So in this post I propose a way to achieve this without much effort.

The procedure consists of the steps described below. I’ll assume that you already have a Visual Studio project and you want to extend it with the multiple instance support:

1. Add a new XML file named App.InstallConfig.xml to your project. It should contain the following XML code:

<installconfig>
    <servicename>My Service Name</servicename>
</installconfig>

2. Add a post-build step to the project:

copy $(ProjectDir)App.InstallConfig.xml $(TargetPath).InstallConfig.xml

This will copy the installation configuration file from the project directory to the target and will replace the ‘App’ name with the name of your project’s assembly.

3. Add a new private method to the main (project) installer class:

private void ConfigureInstaller ()
{
    // find the install configuration file
    string assemblyLocation = Assembly.GetExecutingAssembly ().Location;
    string installConfigFile = assemblyLocation + ".InstallConfig.xml";

    // now load the file and parse it
    XmlDocument xmlDoc = new XmlDocument ();
    xmlDoc.Load (installConfigFile);

    XmlNode serviceNameNode = xmlDoc.SelectSingleNode ("InstallConfig/ServiceName");
    if (serviceNameNode != null)
    {
        string serviceName = serviceNameNode.InnerText.Trim ();
        this.ListenerServiceInstaller.ServiceName = serviceName;
    }
}

This method opens the mentioned configuration file and reads the InstallConfig/ServiceName setting which should contain the actual name of the Windows service instance. It uses this name to set the ServiceInstaller.ServiceName before the installation is initiated.

4. And finally, add the call of the ConfigureInstaller() method to the project installer constructor, like this:

public ProjectInstaller()
{
   // This call is required by the Designer.
   InitializeComponent();

   ConfigureInstaller ();
}

NOTE: replace the name of the ProjectInstaller constructor with your own class name.

This should be it. To install the service under the desired name, you just edit the .InstallConfig.xml file before calling the InstallUtil tool.

Extending this further

You can use the same system to include some other Windows service parameters (like the user account under which it will run, for example). The installer class provided by the .NET Framework does not allow setting the Windows service’s description, but there is a way to do this (see the “Adding a description to a .NET Windows Service” article on CodeProject). Then you can add the description tag in the .InstallConfig.xml file and have a different description for each of the service instances.

Also check out the “Windows Services Can Install Themselves” article on how to create self-installing Windows services (be sure to read the article’s comments, they contain some additional tips).

Published by breki on 22 Feb 2008

Kosmos v1.12

crete.png

Hello everybody, after fixing problems with my failed hard disk, I finally managed to produce a new version of Kosmos. So what is new:

  • Coastline processing has been considerably improved. Kosmos should now be able to fill the sea polygons in most situations, not just for isolated islands.
  • Kosmos can now display an elevation coloring raster for a given map area (see the above example of the Greek island of Crete).
  • I added a high-speed drawing menu option in Kosmos GUI. This will render the map more quickly using a lower quality of rendering. Can be useful when you want to quickly move around the map.
  • JOSM download bound boxes can now be displayed in Kosmos GUI.
  • A new TopLevel option for rendering templates was added which enables you to render certain features above all others, regardless of the layer value of an OSM element.
  • Kosmos now officially runs in Mono (with some problems, however).

As always, visit the Kosmos Home page for the download link. Also visit Kosmos OSM Wiki pages for more information about new features.

Published by breki on 22 Feb 2008

Friday Goodies - 22. February

.NET Development

Development

Miscellaneous

Published by breki on 21 Feb 2008

Adventures of a failed disk, part 2

UPDATE: I added migration steps for FileZilla client.

I installed my OS from scratch to a new disk after my old one crashed. Now I’m doing the reinstallation of various applications and migration of my user’s settings for them. I’ve collected a list of some applications and the procedure on how to migrate user settings (NOTE: I’m using Vista, so the paths to user profile are somewhat different from those on Windows XP).

Mozilla Firefox

Copy the contents of \Users\username\AppData\Roaming\Mozilla\Firefox\ from the old location to the new one. This will copy all of your Firefox profiles, including plugins, preferences, even the last opened URLs.

Mozilla Thunderbird

Same here. Copy \Users\username\AppData\Roaming\Thunderbird from the old location to the new one and open the Thunderbird. You’ll get all of your e-mails, email accounts, filters etc. Congratulations on good products, Mozilla guys :)

Yahoo Messenger

Copy the contents of \Program Files\Yahoo!\Messenger\Profiles from the old location to the new one. This will copy some your user’s settings and data (message history, for example), but I didn’t manage to migrate my Yahoo Messenger preferences.

Windows Live Messenger

The situation is similar to the Yahoo Messenger. By copying the contents of \Users\username\AppData\Roaming\Microsoft\MSN Messenger you can only migrate some of your settings, not all of them.

Skype

You should copy the subfolder of the \Users\username\AppData\Roaming\Skype folder which bares the name of your profile.

FeedDemon

Copy the contents of the \Users\username\AppData\Local\FeedDemon\v1 directory. FeedDemon will still ask you to enter your account information the first time you start it, but after going through this wizard, all of your subscriptions, watches and view settings should be migrated.

µTorrent

Copy the contents of the \Users\username\AppData\Roaming\uTorrent folder. This will include all of your settings and you will also be able to resume downloading of files from the last uTorrent session.

FileZilla Client

Copy the contents of the \Users\username\AppData\Roaming\FileZilla folder to migrate your FileZilla settings (like the FTP site list).

Published by breki on 19 Feb 2008

Adventures of a failed disk, part 1

I was planning to write yesterday about a new Kosmos version, but my home computer had other ideas. Basically, the system hard disk (IBM Hitachi 250 GB SATA, bought less than a year ago) started failing and Vista didn’t want to boot any more (or was booting veeery slowly). I tested the drive using the Drive Fitness Test and it reported "defective device" errors after running tests, so I guess the disk is going to the dogs.

Luckily I have my source code repositories backed up regularly to an external hard drive and I also started playing with Amazon S3 storage which I plan to use as a remote backup destination for SVN repositories. But what I didn’t do is to backup my system partition using an image backup software.

So before continuing my work on Kosmos, I have to reinstall the system, which will probably take a day or to of my spare time. But I hope this is my last OS reinstall for the foreseeable future, since I plan to use Acronis True Image to regularly backup the system drive. I read some good reviews of this software and hopefully it will satisfy my needs. Anyway, hard disk failures aren’t that rare, so I want to make my life a little bit easier when they do occur.

Published by breki on 15 Feb 2008

Friday Goodies - 15. February

.NET Development

Development

GPS

Published by breki on 15 Feb 2008

Kosmos - progress on rendering coastlines

Kosmos coastline rendering

Since I didn’t do too much posting lately, I just wanted to write a status report on Kosmos development. I managed to improve the coastline rendering algorithm - now it should be able to render any kind of coastline situation, not just islands isolated from the mainland. On the top of the page you can see one example: rendering of Croatia’s gulf of Kvarner. I added relief shading to improve the looks.

How does it work? Kosmos uses bounding boxes recorded in OSM files which are written by JOSM to indicate boundaries of map data downloaded from the OSM server. Kosmos then slices the coastlines and creates polygons using those boxes.

The next step will be to extend coastline rendering support for data downloaded using other means, which does not necessarily hold bounding boxes. After that and after testing the algorithm to remove any glitches, you can expect a new version of Kosmos.

Published by breki on 10 Feb 2008

Kosmos 1.10

After two weeks of hard work, I am pleased to announce that a new version of Kosmos is here. Go to Kosmos Home for the download link.

New Features:

  • Wiki rendering rules table can now be split into several separate tables. This makes editing the rules more easy, since the rendering page can be organized into several sections and those sections edited separately.
  • I added a “subrules” feature for rendering rules: you can now specify a parent rule (say, highway=primary) and child rules (bridge=yes and *). Each child rule can have its own templates, so this enables rendering of bridges separately from other parts of the highway.
  • Added support for {{tag|key}} rendering rule selector. This selector will select all OSM elements which are tagged with the specified key, regardless of its value.
  • Added support for loading of bz2 and gzip OSM files.
  • Icon template now has HAlign and VAlign parameters. This helps when rendering features such as towers as you can now position the tower base right at the OSM node’s location.
  • Text template now has a tag fallback feature: you can specify more than one tag in the TagToUse parameter and Kosmos will use the first tag that exists for an OSM element. Example: TagToUse=nat_name;name will cause national names to be rendered for OSM features. If a national name does not exist, a common default name will be used.
  • Text template now supports drawing a rectangle around the text.
  • Print area can now be set. See below for more.
  • Added menu options in Kosmos.Gui for setting the print area to the current map view or to the whole map.

Bugfixes:

  • Kosmos now doesn’t fail when duplicate OSM elements are loaded. You can now load two or more adjacent OSM areas which share certain OSM elements.
  • Ways with missing nodes are now ignored by Kosmos. In previous versions Kosmos would fail if a way with missing nodes is loaded.
  • Fixed the backslash issue when generating tile file paths - this did not work on Linux.
  • Rasters are no longer lost when ‘Show unused…” options are toggled.
  • Page counts in the printing dialog are now refreshed when page settings change.
  • Printing page settings are now remembered when the print dialog is closed.
  • Added a workaround code for the MS bug (http://support.microsoft.com/?id=814355).
  • All GDI+ objects are now disposed of correctly. There was a resource leak in the previous version when creating new GDI+ pens.
  • Added handling and reporting of fatal errors in Kosmos.Gui.
  • Fixed a problem with loading obsolete user settings for Kosmos.

Setting the print area

You can now set your own area of the map you want to print. Just select the View|Show Print Area option and click on the blue rectangle to select it. You can reposition the rectangle by moving its corners. Its a little bit clumsy at the moment and also the selection indicators tend to disappear when you click somewhere outside the map. I haven’t yet found a good way of showing and hiding those indicators without redrawing the map. I will try to improve this for the next versions of Kosmos.

Kosmos source code

From this version on Kosmos releases will come together with the source code (Kosmos is now licensed under the BSD license), so I guess this makes it an open source project ;). The code documentation is quite patchy, I’ll try to improve this as the development progresses. Note that 3rd party libraries and tools are not included in the source ZIP - there is just too many stuff to include and also I doubt it would be possible due to license limitations of some of these tools.

What comes next?

I have to admit I’ve been neglecting Kosmos tile server, so now I will try to add some new features for it (including shaded relief in tiles, for example). Also, I’ll start working on a solution for the coastline rendering, so that the sea is filled blue in all situations, not just around islands. There is also some talk of making Kosmos run on Mono, we’ll see how that goes. Anyway, expect some new stuff in the following weeks :)

Published by breki on 08 Feb 2008

Friday Goodies - 08. February

Development

Web Services

.NET Development

VisualStudio

GPS

Misc

Next »