Developer Reference Installing Loose Cells

We're often asked how to install ENC charts without a transmittal...

The email conversation goes like this "How do I display my ENC charts - I've got a load of 000 files"

"You have to import them all into a chart folder (a SENC) first. Are they in a transmittal with a CATALOG.031 file and so on?"

"No I've just got 000 files, what's a transmittal?"

What's a transmittal?

A transmittal is the best way for a chart provider to distribute S-57/ENC chart cells. It can neatly handle updates to cells, withdrawn cells, auxiliary files and so on. Lots of stuff that has to be done carefully. Chart providers like NOAA, IC-ENC, Primar, Chartworld ship ENC cells as part of a transmittal. Transmittals are really crucial when dealing with encrypted commercial ENC cells.

In some local situations people end up with "loose" charts cells that aren't in a transmittal. Often it's just "base cells" (.000 files) but sometimes there are update cells as well (.001, .002, ... etc).

Loose files and Chersoft

We really want people to use transmittals. The reason people buy a chart SDK is so they don't have to invest time in having a deep understanding of how ENCs work - transmittals help wrap up a load of detail associated with ENC distribution. It's easier for us to support.

So if you run the ManageENC UI you cannot install loose ENC cells. If you really need to do that - if you can't get transmittals from the chart source - then you can write code against ManageENC's API. That's what I'll show in this article.

There is also a related article with more of an overview of the ManageENC API. You need to read this and follow some of the instructions for this article to work!

Code to install a loose chart

I've written a C# command line application to do this (included with the ENCX sample applications).

It just takes 2 parameters - the path to the charts folder (SENC) where the charts will get installed to and a link to the charts.

InstallLooseCells c:\mySenc c:\charts\looseFiles

To add to an existing application, add a reference to the ManageENC API (as shown in the related article).

I'll pick out a few highlights and comment on a few things in the code here.

Events

We create a manager object and wire up some events. In the event handlers we write text out to the console to give a running commentary...

ManageENC.Manager installer = new ManageENC.Manager();
installer.OnMessage += new ManageENC._IManagerEvents_OnMessageEventHandler(OnMessage);
installer.OnProgress+= new ManageENC._IManagerEvents_OnProgressEventHandler(OnProgress);
installer.OnFinished += new ManageENC._IManagerEvents_OnFinishedEventHandler(OnFinished);

Finding some files to install

We just recurse through the folder structure testing each filename (or rather each extension). If the file extension is 3 numbers long (000-999) then we take it.

What order to install in

Sometimes we get files where only the extension differs. (Probably) 000 is the base file, 001 is an update, 002 is another update and so on. The best we can do is apply everything in order.

Base files (000) contain all the information necessary for a cell but updates (001-999) just contain changes. This means that 001 file cannot be installed without a 000 file of the same cell being previously installed. The problem is that chart providers sometimes issue new base cells to consolidate the updates that they have made. We cannot guarantee that a given 001 file is an update for a given 000 file - that 000 file may contain updates 001-010 anyway.

Sometimes update cells are ignored because a base file has already provided the information and sometimes an update can't be applied because the current chart holding is not up to date enough. As long as you apply all the files you have in the right order the design is robust. It is worth paying a little attention to the messages that emerge from the cell installation process (a text log of changes is kept in a log folder inside the SENC folder).

Ok, so we are going to install all the 000s, all the 001s and so on. We keep it simple and use a pair of loops...

for(int n = 0; n < 1000; ++n)
{
    foreach(FileInfo file in cellFiles)
    {
        if(NumberFromExt(file) == n)
        {
            InstallCell(installer, file);
        }
    }
}

Installing a cell

installer.InstallCellFile(cellFileInfo.FullName, false);
while(installer.Busy)
{
    Thread.Sleep(100);
}

We call InstallCellFile with the path to the cell file and false as the second parameter. This indicates that the chart is not "commercial"; commercial is a synonym for encrypted in this situation (I think it is very rare for encrypted ENC data to not be supplied with a transmittal).

As I discussed the main ManageENC API article all the chart installation functions work asynchronously. This is a big advantage if you have a GUI that you want to keep responsive. In our command line app we don't - so we just sit and wait in a while loop until ManageENC stops being busy.

During that time we will receive events into the OnMessage and OnProgress methods to keep us up to date with what's going on with the install.

Update (from ENCX Version 2.2)

To rebuild the chart catalogue after all the loose cells have been installed, version 2.2 of ENCX added a new method RefreshDirectory.  This replaces the previous technique of installing an "empty" update and waiting for the installer to complete.

installer.RefreshDirectory();

If this method is not called, then the chart catalogue file isn't rebuilt and the charts won't show up on the display.