Ejemplo n.º 1
0
        /// <summary>
        /// Creates new options from the command line arguments
        /// </summary>
        /// <param name="args">Arguments</param>
        public RdfServerOptions(String[] args)
        {
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-help":
                        this.ShowUsage();
                        this._mode = RdfServerConsoleMode.Quit;
                        break;

                    case "-p":
                    case "-port":
                        if (i < args.Length - 1)
                        {
                            i++;
                            int port;
                            if (Int32.TryParse(args[i], out port))
                            {
                                this._port = port;
                                if (!this._quiet)
                                {
                                    Console.WriteLine("rdfServer: Port Set to " + this._port);
                                }
                            }
                            else
                            {
                                Console.Error.WriteLine("rdfServer: Error: Expected a valid port number after the -p/-port option - will use default port 1986");
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfServer: Error: Expected an argument after the -p/-port option to specify the port number - will use default port 1986");
                        }
                        break;

                    case "-h":
                    case "-host":
                        if (i < args.Length - 1)
                        {
                            i++;
                            this._host = args[i];
                            if (!this._quiet)
                            {
                                Console.WriteLine("rdfServer: Host set to " + this._host);
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfServer: Error: Expected an argument after the -h/-host option to specify the host name - will use the default host name localhost");
                        }
                        break;

                    case "-c":
                    case "-config":
                        if (i < args.Length - 1)
                        {
                            i++;
                            this._configFile = args[i];
                            if (!this._quiet)
                            {
                                Console.WriteLine("rdfServer: Configuration File set to " + this._configFile);
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfServer: Error: Expected an argument after the -c/-config option to specify the configuration file - will use the default file default.ttl");
                        }
                        break;

                    case "-v":
                    case "-verbose":
                        if (!this._quiet)
                        {
                            Console.WriteLine("rdfServer: Verbose Mode on - all requests and errors will be logged to the Console in the specified Log Format");
                        }
                        this._verbose = true;
                        break;

                    case "-q":
                    case "-quiet":
                        this._quiet = true;
                        break;

                    case "-l":
                    case "-log":
                        if (i < args.Length - 1)
                        {
                            i++;
                            this._logFile = args[i];
                            if (!this._quiet)
                            {
                                Console.WriteLine("rdfServer: Log File set to " + this._logFile);
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfServer: Error: Expected an argument after the -l/-log option to specify the log file - no log file will be used");
                        }
                        break;

                    case "-f":
                    case "-format":
                        if (i < args.Length - 1)
                        {
                            i++;
                            this._logFormat = args[i];
                            if (!this._quiet)
                            {
                                Console.WriteLine("rdfServer: Log Format set to " + this._logFormat);
                            }
                            this._logFormat = ApacheStyleLogger.GetLogFormat(this._logFormat);
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfServer: Error: Expected an argument after the -f/-format option to specify the log format string - Common Log Format will be used");
                        }
                        break;

                    case "-b":
                    case "-base":
                        if (i < args.Length - 1)
                        {
                            i++;
                            this._baseDir = args[i];
                            if (this._baseDir.Equals("."))
                            {
                                this._baseDir = Environment.CurrentDirectory;
                            }
                            if (!this._baseDir.EndsWith(new String(new char[] { Path.DirectorySeparatorChar })))
                            {
                                this._baseDir += Path.DirectorySeparatorChar;
                            }
                            if (Directory.Exists(args[i]))
                            {
                                if (!this._quiet)
                                {
                                    Console.WriteLine("rdfServer: Running with HTTP Server enabled - static files (HTML, Plain Text, Images etc) will be served from the base directory " + this._baseDir);
                                }
                            }
                            else
                            {
                                this._baseDir = null;
                                Console.Error.WriteLine("rdfServer: Error: The Base Directory specified for the -b/-base option does not exist");
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("rdfServer: Error: Expected an argument after the -b/-base option to specify the base directory from which to serve static content");
                        }
                        break;

                    case "-r":
                    case "-rest":
                        this._restControl = true;
                        if (!this._quiet)
                        {
                            Console.WriteLine("rdfServer: RESTful Control enabled, POST a request to /control with a querystring of operation=restart or operation=stop to control the server");
                        }
                        break;

                    default:
                        Console.Error.WriteLine("rdfServer: Error: Unknown option/argument '" + args[i] + "' was ignored");
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new in-process harness
 /// </summary>
 /// <param name="server">Server</param>
 /// <param name="logFormat">Log Format</param>
 public InProcessServerHarness(HttpServer server, String logFormat)
 {
     this._server    = server;
     this._logFormat = ApacheStyleLogger.GetLogFormat(logFormat);
 }