Picking Alchemy Databases on a Server

Earlier today I had a need to choose databases from a server to show up in Alchemy Administrator. The problem was that the server wasn’t on a domain (its my development server which is running in a VirtualPC vm). I couldn’t find the server easily, so I thought there had to be a better way. So I created a tool to make it easier. When you first launch it, you get this:

Enter a server and press Enter to get a list of databases from the server:

If you already have any databases loaded in Alchemy Administrator, they are already selected. Make changes to you selections and click Save. The changes will be persisted to your Alchemy.ini file.

To build this, I had to add a reference to both the Alchemy Object Library 2.0 and the Alchemy Server API and then make the call to load the local options file. Then I populate an ArrayList with the databases that are currently loaded in the ini:

foreach (Alchemy.Database myDatabase in auApp.Databases)
{
    if (myDatabase.Path.StartsWith("alchemy"))
        loadedDatabases.Add(new AuDb(myDatabase.Path));
}

AuDb is a simple class I created that parses out the server, port, and database from the URL based on some regular expressions. Next I populate the list box with the databases under server control:

foreach (int DatabaseID in auServer.DatabaseList)
{
    string databaseUrl = auServer.get_DatabaseUrl(DatabaseID);
    AuDb myDB = new AuDb(databaseUrl);

    dbindex = lbDatabases.Items.Add(databaseUrl);

    if (loadedDatabases.Contains(myDB))
        lbDatabases.SetSelected(dbindex, true);
}

I want the items that are currently in the ini to be selected on the list, so that explains the last two lines. Now I can go through each item in the list box, see if it is selected, and then either add the database or remove it from the Applications databases. Finally, call SaveOptionsFile to save it.

Pretty cool little tool and will definitely save me some time in the future.