public static Options ParseArguments(string[] args) { // '--test' arg was once named '--collect-only'. This provides backwards compatibility. if (args != null) { var index = Array.IndexOf(args, "--collect-only"); if (index >= 0) { args[index] = "--test"; } } var options = new Options(); // If bad args were passed, will exit and print usage Parser.Default.ParseArgumentsStrict(args, options); return options; }
private static int Main(string[] args) { try { var options = new Options(); var log = SetUpLogConfig(); // If bad args were passed, will exit and print usage Parser.Default.ParseArgumentsStrict(args, options); var settings = ConfigurationParser.ParseSettings(log, options.ConfigFile); Settings.Default = settings; var installController = new InstallController(settings.ServiceName, log); if (options.Uninstall) { installController.Uninstall(); } else if (options.Install) { installController.Install(); } else if (options.Start) { installController.StartService(); } else if (options.Stop) { installController.StopService(); } else if (options.InstallOrStart) { installController.InstallOrStart(); } else { Thread.CurrentThread.Name = "Main"; settings.CollectOnly = options.CollectOnly; log.Debug("Loaded Settings:"); settings.ToLog(log); if (Environment.UserInteractive) { Console.Out.WriteLine("Starting Interactive mode"); RunInteractive(settings); } else { ServiceBase[] services = {new SqlMonitorService(settings)}; ServiceBase.Run(services); } } return 0; } catch (Exception ex) { Console.Out.WriteLine(ex.Message); if (Environment.UserInteractive) { Console.Out.WriteLine(); Console.Out.WriteLine("Press any key to exit..."); Console.ReadKey(); } return -1; } }