Programming · Summer of Code 2007

FastCGI ASP.NET Server Status Report 5

This is a status report for the week of June 25 – June 29. This week started out rather slow, but I managed to get a large part of the configuration system completed.

THIS WEEK’S ACCOMPLISHMENTS

One goal of the project is to make it easy to configure the server. This week I created the backing for a configuration system, which allows users to specify server options through either command line options or an XML file (that will be editable by a configuration ASP.NET application).

Features:

1. Settings can be done written a number of ways that are both Linux and Windows friendly:

Via the command line:

 /arg=VALUE
--arg=VALUE
 -arg=VALUE
 /arg VALUE
--arg VALUE
 -arg VALUE

Via XML:

<Setting Name="arg" Value="VALUE" />
<Setting>
    <Name>arg</Name>
    <Value>VALUE</Value>
</Setting>

2. All configuration options are stored in an XML definition file making it easy to add new arguments:

<Setting Name="port" AppSetting="MonoServerPort" Type="UInt16"
    ConsoleVisible="True">
    <Description>
        <para>Specifies the TCP port number to listen on.<br />
        To use this argument, "socket" must be set to "tcp".</para>
    </Description>
</Setting>

3. The configuration manager does the basic checks and conversions:

try {
   port = (int) configmanager["port"];
} catch (ApplicationException e) {
   Console.WriteLine (e.Message);
   return 1;
}

Reads the port argument and tries to convert it to a UInt16, and fails with:

Error in argument "port". "xxx" cannot be converted to an integer.

This also does checks for file and directory existence.

4. Boolean options that default to true can be set to false in the command line:

/multiplex=False

5. All option descriptions are stored in an XML format that can be used by both the web and the console, with whitespace being gracefully ignored:

    <Setting Name="nonstop" Type="Bool" ConsoleVisible="True">
        <Description>
            <para>Specifies not to stop the server by if "Enter" is pressed. This must be used when the server has no controlling terminal.</para>
        </Description>
    </Setting>

and

    <Setting Name="nonstop" Type="Bool" ConsoleVisible="True">
        <Description>
            <para>Specifies not to stop
            the server by if "Enter" is
            pressed. This must be used
            when the server has no
            controlling terminal.</para>
        </Description>
    </Setting>

both yield the following when –help is called:

  /nonstop[=True|=False]     Specifies not to stop the server by if "Enter" is
                             pressed. This must be used when the server has no
                             controlling terminal.

6. Options can be set via the the application with all the same conversions:

configmanager ["port"] = "1234";
ushort port = (ushort) configmanager ["port"];

7. Order of precedence:

When reading a setting, the command line is checked first, then the XML file (if loaded), then the AppSettings (stored in myexecutable.exe.config)

Hopefully, this class will be useful in other applications as well.

In other news:

Instead of just not working at all on Apache, it now fails badly. Needless to say, that’s very exciting news. It was very last minute that this change occurred, so there will be much work to do next week.

PLANS FOR THE COMING WEEK

Next week will be continuing with the work of this week. I will continue to work the Apache angle and hopefully get things working, and I’ll finish up the ConfigurationManager and add a custom ApplicationHost that can bond with it. This week I got through the harder problem of “Where do I even begin?” so next week should feature a lot of progress.

CHALLENGES I’M FACING

It was really hard to get grounded on an initial idea for the ConfigurationManager. There were a lot of issues like how to organize things, what the XML should look like, etc. It really slowed me down and I went through many iterations I didn’t really like before I reached my final solution.

RESOURCES USED THIS WEEK

  • Pencil and Paper – Organizing my thoughts on paper is usually the last thing I want to do, but it really helps clarify a lot of things and I think makes your brain operate on a different level than usual.
  • MSDN – Looking up NameValueCollection.
  • Google – Searching for information on the ConfigurationManager.

Sincerely,
Brian Nickel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s