public void RunServer(IList<string> args)
{
string port = null;
string securePort = null;
string certFile = null;
string keyFile = null;
string user = null;
string assembly = null;
string ipaddress = null;
string browse = null;
string docroot = null;
var p = new OptionSet () {
{ "p|port=", v => port = v },
{ "P|secureport=", v => securePort = v },
{ "c|certfile=", v => certFile = v },
{ "k|keyfile=", v => keyFile = v },
{ "u|user=", v => user = v },
{ "a|assembly=", v=> assembly = v},
{ "l|listen=", v => ipaddress = v },
{ "b|browse=", v => browse = v },
{ "d|docroot=", v => docroot = v}
};
args = p.Parse(args);
ServerCommand cmd = new ServerCommand (Environment, args);
if(assembly != null)
{
cmd.ApplicationAssembly = assembly;
}
if (port != null) {
int pt;
if (!Int32.TryParse (port, out pt))
throw new ArgumentException ("Port value is not an integer.");
if (pt <= 0)
throw new ArgumentOutOfRangeException ("port", "Port must be a positive integer.");
cmd.Port = pt;
}
if (securePort != null) {
if (certFile == null)
throw new ArgumentException ("Certificate file required for TLS.");
if (keyFile == null)
throw new ArgumentException ("Certificate private key required for TLS.");
int pt;
if (!Int32.TryParse (securePort, out pt))
throw new ArgumentException ("Secure port value is not an integer.");
if (pt <= 0)
throw new ArgumentOutOfRangeException ("secureport", "Secure port must be a positive integer.");
cmd.SecurePort = pt;
cmd.CertificateFile = certFile;
cmd.KeyFile = keyFile;
}
if (user != null)
cmd.User = user;
if (ipaddress != null)
cmd.IPAddress = ipaddress;
if (docroot != null)
cmd.DocumentRoot = docroot;
if (browse != null)
cmd.Browse = browse;
cmd.Run ();
}