//[MTAThread] static void Main(string[] args) { ConsoleQuickEdit.Disable(); if (args.Count() == 0 || args.Contains("/?")) { ShowHelp(); return; } // show version? if (args[0] == "-v" || args[0] == "-version" || args[0] == "/v") { Console.WriteLine(Assembly.GetEntryAssembly().GetName().Version.ToString()); Environment.Exit(0); return; } for (int i = 0; i < args.Count(); i = i + 2) { string key = args[i].StartsWith("-") ? args[i].Substring(1) : args[i]; string val = i + 1 < args.Count() ? args[i + 1].Trim() : String.Empty; argsDictionary[key] = val; } string paramFileName, runtype; string failOnTestFailed = "N"; argsDictionary.TryGetValue("runtype", out runtype); argsDictionary.TryGetValue("paramfile", out paramFileName); TestStorageType enmRuntype = TestStorageType.Unknown; if (!Enum.TryParse <TestStorageType>(runtype, true, out enmRuntype)) { enmRuntype = TestStorageType.Unknown; } if (string.IsNullOrEmpty(paramFileName)) { ShowHelp(); return; } ShowTitle(); ConsoleWriter.WriteLine(Resources.GeneralStarted); var apiRunner = new Launcher(failOnTestFailed, paramFileName, enmRuntype); apiRunner.Run(); }
//[MTAThread] static void Main(string[] args) { ConsoleWriter.WriteLine(Resources.GeneralStarted); ConsoleQuickEdit.Disable(); Console.OutputEncoding = System.Text.Encoding.GetEncoding("utf-8"); if (args.Count() == 0 || args.Contains("/?")) { ShowHelp(); return; } for (int i = 0; i < args.Count(); i = i + 2) { string key = args[i].StartsWith("-") ? args[i].Substring(1) : args[i]; string val = i + 1 < args.Count() ? args[i + 1].Trim() : String.Empty; argsDictionary[key] = val; } string paramFileName, runtype; string failOnTestFailed = "N"; argsDictionary.TryGetValue("runtype", out runtype); argsDictionary.TryGetValue("paramfile", out paramFileName); TestStorageType enmRuntype = TestStorageType.Unknown; if (!Enum.TryParse <TestStorageType>(runtype, true, out enmRuntype)) { enmRuntype = TestStorageType.Unknown; } if (string.IsNullOrEmpty(paramFileName)) { ShowHelp(); return; } var apiRunner = new Launcher(failOnTestFailed, paramFileName, enmRuntype); apiRunner.Run(); }
//[MTAThread] static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += (s, e) => { int code = Environment.ExitCode; if (code == 0) { Console.Out.WriteLine("The launcher tool exited with code: 0"); } else { Console.Error.WriteLine("The launcher tool exited with error code: {0}", code); } }; ConsoleQuickEdit.Disable(); ConsoleWriter.Initialize(); if (!args.Any() || args.Contains("/?")) { ShowHelp(); return; } // show version? if (args[0] == "-v" || args[0] == "-version" || args[0] == "/v") { Console.WriteLine(Assembly.GetEntryAssembly().GetName().Version.ToString()); Environment.Exit(0); return; } for (int i = 0; i < args.Length; i += 2) { string arg = args[i].Trim(); if (arg.StartsWith("--")) { // --<flag> means it is a flag without value string key = arg.Substring(2); argsDictionary[key] = string.Empty; i -= 1; } else { string key = arg.StartsWith("-") ? arg.Substring(1) : arg; string val = i + 1 < args.Length ? args[i + 1].Trim() : string.Empty; argsDictionary[key] = val; } } // verbose output mode? if (argsDictionary.ContainsKey("verbose")) { ConsoleWriter.EnableVerboseOutput = true; } // redirect output if required string redirectOutPipeName; if (argsDictionary.TryGetValue("redirect-out-pipe", out redirectOutPipeName)) { // need to redirect stdout to the specified pipe var outPipe = new NamedPipeClientStream(".", redirectOutPipeName, PipeDirection.Out); outPipe.Connect(); // create stream write for stdout var sw = new StreamWriter(outPipe) { AutoFlush = true }; Console.SetOut(sw); ConsoleWriter.WriteVerboseLine("The stdout is redirected via the named pipe: " + redirectOutPipeName); } // redirect error if required string redirectErrPipeName; if (argsDictionary.TryGetValue("redirect-err-pipe", out redirectErrPipeName)) { // need to redirect stderr to the specified pipe var errPipe = new NamedPipeClientStream(".", redirectErrPipeName, PipeDirection.Out); errPipe.Connect(); // create stream write for stderr var sw = new StreamWriter(errPipe) { AutoFlush = true }; Console.SetError(sw); ConsoleWriter.WriteVerboseLine("The stderr is redirected via the named pipe: " + redirectErrPipeName); } string paramFileName, runtype; string failOnTestFailed = "N"; argsDictionary.TryGetValue("runtype", out runtype); argsDictionary.TryGetValue("paramfile", out paramFileName); TestStorageType enmRuntype = TestStorageType.Unknown; if (!Enum.TryParse <TestStorageType>(runtype, true, out enmRuntype)) { enmRuntype = TestStorageType.Unknown; } if (string.IsNullOrEmpty(paramFileName)) { ShowHelp(); return; } ShowTitle(); ConsoleWriter.WriteLine(Resources.GeneralStarted); try { if (StartNewLauncherProcess(args)) { // the new launcher process is launched and everthing shall already be handled in the StartNewLauncherProcess // so here returns, that is, this process shall exit return; } } catch (Exception ex) { Console.Error.WriteLine("Warning: Error occurred when creating the new process in the user session:"); Console.Error.WriteLine("-------------------------------"); Console.Error.WriteLine(ex.Message); ConsoleWriter.WriteVerboseLine(ex.ToString()); Console.Error.WriteLine("-------------------------------"); Console.Error.WriteLine("Warning: Test(s) will be run in non-user session, however, the test(s) might fail."); } var launcher = new Launcher(failOnTestFailed, paramFileName, enmRuntype); if (launcher.IsParamFileEncodingNotSupported) { Console.WriteLine(Properties.Resources.JavaPropertyFileBOMNotSupported); Environment.Exit((int)Launcher.ExitCodeEnum.Failed); return; } launcher.Run(); }