static void UnsafeMain(string[] args) { LoggingHelper.ChangeFilenamePostfix("executor"); string cwd = AppDomain.CurrentDomain.BaseDirectory; Directory.SetCurrentDirectory(cwd ?? "."); logger.Info("Current directory is {0}", cwd); // log4net - We are using NLog, so we should adapt the following. //XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config")); if (!IsReleaseVersion && System.Environment.UserInteractive) { ConsoleAppHelper.CatchSpecialConsoleEvents(); } // Disable parser case-sensitivity to allow convertion from string to PlanType - Supported only in CommandLine > 2.0 //CommandLine.Parser.Default.Settings.CaseSensitive = false; if (!CommandLine.Parser.Default.ParseArguments(args, Options)) { return; } PlanExecutor executor = null; try { LoadSettings(); executor = new PlanExecutor(); executor.Run(); LetMeDebugThisBeforeExiting(); } catch (Exception ex) { if (Options.Verbose) { logger.Log(LogLevel.Fatal, ex, "Oops! An unexpected problem happened"); } else { logger.Fatal("Oops! An unexpected problem happened: {0}", ex.Message); } LetMeDebugThisBeforeExiting(); Environment.Exit(1); } if (!IsReleaseVersion && System.Environment.UserInteractive) { // Set this to terminate immediately (if not set, the OS will eventually kill the process) ConsoleAppHelper.TerminationCompletedEvent.Set(); } }
static void UnsafeMain() { LoggingHelper.ChangeFilenamePostfix("gui"); SystemEvents.SessionEnding += (object sender, SessionEndingEventArgs e) => { logger.Info("Session ending due to {0}", e.Reason.ToString()); }; Provider.Setup(); LoadSettings(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new MainForm(); Application.Run(mainForm); Provider.Cleanup(); }
static void UnsafeMain(string[] args) { LoggingHelper.ChangeFilenamePostfix("scheduler"); if (System.Environment.UserInteractive) { if (args.Length > 0) { switch (args[0]) { case "-install": case "-i": ServiceHelper.SelfInstall(); logger.Info("Service installed"); ServiceHelper.SelfStart(); break; case "-r": case "-reinstall": try { ServiceHelper.SelfUninstall(); logger.Info("Service uninstalled"); } catch (Exception ex) { if (ex.InnerException is Win32Exception) { Win32Exception win32ex = ex.InnerException as Win32Exception; if (win32ex.NativeErrorCode != 0x424) // 0x424: ERROR_SERVICE_DOES_NOT_EXIST { throw; } } else { throw; } } ServiceHelper.SelfInstall(); logger.Info("Service installed"); ServiceHelper.SelfStart(); break; case "-uninstall": case "-u": ServiceHelper.SelfUninstall(); logger.Info("Service uninstalled"); break; } } else { ConsoleAppHelper.CatchSpecialConsoleEvents(); Service instance = new Service(); instance.OnStart(args); // If initialization failed, then cleanup/OnStop is already done. if (instance.ExitCode == 0) { // Sleep until termination ConsoleAppHelper.TerminationRequestedEvent.WaitOne(); // Do any cleanups here... instance.OnStop(); // Set this to terminate immediately (if not set, the OS will eventually kill the process) ConsoleAppHelper.TerminationCompletedEvent.Set(); } } } else { ServiceBase.Run(new Service()); } }