/// Runs the command and returns the exitcode private static int Run(string[] args) { try { return(Executor.Execute(Paths.DirName(Paths.Binary()), "class", "xp.unittest.Runner", new string[] { "." }, args)); } catch (Exception e) { Console.Error.WriteLine("*** " + e.GetType() + ": " + e.Message); return(-1); } }
/// Delegate: Serve web with development webserver static int Develop(string profile, string server, string port, string web, string root, string config, string[] inc) { return(Service(profile, server, port, web, root, config, () => { var proc = Executor.Instance(Paths.DirName(Paths.Binary()), "web", "", inc, new string[] { }); proc.StartInfo.Arguments = ( "-S " + server + ":" + port + " -t \"" + root + "\"" + " -duser_dir=\"" + config + "\" " + proc.StartInfo.Arguments ); return proc; })); }
protected static void Execute(string runner, string tool, string[] modules, string[] includes, string[] args) { // Execute try { Environment.Exit(Executor.Execute(Paths.DirName(Paths.Binary()), runner, tool, modules, includes, args)); } catch (Exception e) { Console.Error.WriteLine("*** " + e.GetType() + ": " + e.Message); Environment.Exit(0xFF); } }
/// Entry point static void Main(string[] args) { Execution action = Develop; var addr = new string[] { "localhost" }; var inc = new List <string>(new string[] { "." }); var web = "."; var root = ""; var config = ""; var profile = "dev"; // Parse arguments var i = 0; while (i < args.Length) { switch (args[i]) { case "-p": profile = args[++i]; break; case "-r": root = args[++i]; if (!Directory.Exists(root)) { Console.Error.WriteLine("*** Document root {0} does not exist, exiting.", root); Environment.Exit(0x03); } break; case "-w": web = args[++i]; break; case "-c": config = args[++i]; if ("-" == config) { // No configuration, serve static content } else if (File.Exists(Paths.Compose(config, "web.ini"))) { // Web layout comes from $config/web.ini config = Paths.Resolve(config); } else { // Web layout comes from class $config config = ":" + config; } break; case "-cp": inc.Add(Paths.Resolve(args[++i])); break; case "-i": action = Inspect; break; case "-m": var mode = args[++i]; if ("develop" == mode) { action = Develop; } else { action = (_profile, _server, _port, _web, _root, _config, _inc) => { return(Service(_profile, _server, _port, _web, _root, _config, () => { return Executor.Instance(Paths.DirName(Paths.Binary()), "class", "xp.scriptlet.Server", _inc, new string[] { _web, _config, _profile, _server + ":" + _port, mode }); })); }; } break; case "-?": Execute("class", "xp.scriptlet.Usage", inc.ToArray(), new string[] { "xpws.txt" }); return; default: addr = args[i].Split(':'); break; } i++; } // If no "-c" argument given, try checking ./etc for a web.ini, fall back to // "no configuration" if (String.IsNullOrEmpty(config)) { var etc = Paths.Compose(".", "etc"); config = File.Exists(Paths.Compose(etc, "web.ini")) ? etc : "-"; } // If no document root has been supplied, check for an existing "static" // subdirectory inside the web root; otherwise just use the web root web = Paths.Resolve(web); if (String.IsNullOrEmpty(root)) { var path = Paths.Compose(web, "static"); root = Directory.Exists(path) ? path : web; } else { root = Paths.Resolve(root); } // Run Environment.Exit(action( profile, addr[0], addr.Length > 1 ? addr[1] : "8080", web, root, config, inc.ToArray() )); }
static void Main(string[] args) { var pid = System.Diagnostics.Process.GetCurrentProcess().Id; var addr = new string[] { "localhost" }; var profile = "dev"; var root = ""; var i = 0; var parsing = true; // Parse arguments while (parsing && i < args.Length) { switch (args[i]) { case "-p": profile = args[++i]; break; case "-r": var dir = args[++i]; Environment.SetEnvironmentVariable("DOCUMENT_ROOT", dir); root = " -t " + dir; break; case "-?": Execute("class", "xp.scriptlet.Usage", new string[] { "." }, new string[] { "xpws.txt" }); return; default: addr = args[i].Split(':'); parsing = false; break; } i++; } // Verify we have a web.ini if (!System.IO.File.Exists(Paths.Compose("etc", "web.ini"))) { Console.Error.WriteLine("*** Cannot find the web configuration web.ini in etc/, exiting."); Environment.Exit(0x03); } var server = addr[0]; var port = addr.Length > 1 ? addr[1] : "8080"; if (i > 0) { Array.Copy(args, i, args, 0, args.Length - i); Array.Resize(ref args, args.Length - i); } // Execute var proc = Executor.Instance(Paths.DirName(Paths.Binary()), "web", "", new string[] { "." }, args); proc.StartInfo.Arguments = "-S " + server + ":" + port + root + " " + proc.StartInfo.Arguments; try { Environment.SetEnvironmentVariable("SERVER_PROFILE", profile); proc.Start(); Console.Out.WriteLine("[xpws-{0}#{1}] running @ {2}:{3}. Press <Enter> to exit", profile, pid, server, port); Console.Read(); Console.Out.WriteLine("[xpws-{0}#{1}] shutting down...", profile, pid); proc.Kill(); proc.WaitForExit(); Environment.Exit(proc.ExitCode); } catch (SystemException e) { Console.Error.WriteLine("*** " + proc.StartInfo.FileName + ": " + e.Message); Environment.Exit(0xFF); } finally { proc.Close(); } }