/// <summary> /// The Virtual Radar Server main thread when running as a service. /// </summary> /// <param name="state"></param> private void ServiceThread(object state) { try { var args = (string[])state; ProgramLifetime.InitialiseUnhandledExceptionHandling(); ProgramLifetime.PrepassCommandLineArgs(args); ProgramLifetime.Headless = true; ApplicationInformation.SetHeadless(ProgramLifetime.Headless); InitialiseClassFactory(); ProgramLifetime.InitialiseManagers(); ProgramLifetime.LoadPlugins(); ProgramLifetime.RegisterPlugins(); ProgramLifetime.SingleInstanceStart(args); } catch (ThreadAbortException) { ; } catch (Exception ex) { try { var log = Factory.ResolveSingleton <ILog>(); log.WriteLine("Caught exception in ServiceThread: {0}", ex); } catch { ; } Stop(); } }
static void Main(string[] args) { ProgramLifetime.InitialiseUnhandledExceptionHandling(); ProgramLifetime.PrepassCommandLineArgs(args); ApplicationInformation.SetHeadless(ProgramLifetime.Headless); if (!ProgramLifetime.Headless) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); } InitialiseClassFactory(); if (ProgramLifetime.Headless) { VirtualRadar.Interop.Console.ShowConsole(); } if (args.Contains("-showConfigFolder")) { ShowConfigurationFolder(); } ProgramLifetime.InitialiseManagers(); ProgramLifetime.LoadPlugins(); ProgramLifetime.RegisterPlugins(); ProgramLifetime.SingleInstanceStart(args); // Calling Environment.Exit rather than falling off the end of Main will ensure that all threads get shut down Environment.Exit(0); }
static void Main(string[] args) { var exitCode = 0; var verbose = (args ?? new string[0]).Any(r => String.Equals(r, "-verbose", StringComparison.OrdinalIgnoreCase)); try { ProgramLifetime.Headless = true; ProgramLifetime.InitialiseUnhandledExceptionHandling(); ProgramLifetime.ConfigureSecurityProtocols(); Factory.Register <IApplicationInformation, ApplicationInformation>(); VirtualRadar.SQLiteWrapper.Implementations.Register(Factory.Singleton); VirtualRadar.Headless.Implementations.Register(Factory.Singleton); VirtualRadar.Library.Implementations.Register(Factory.Singleton); VirtualRadar.Database.Implementations.Register(Factory.Singleton); ProgramLifetime.InitialiseManagers(); var appInfo = Factory.Resolve <IApplicationInformation>(); Console.WriteLine($"{appInfo.ApplicationName}, version {appInfo.ShortVersion}, built {appInfo.BuildDate} UTC"); Console.WriteLine(appInfo.Copyright); Console.WriteLine(); LoadDatabasePlugins(); CommandRunner commandRunner = null; var options = OptionsParser.Parse(args); switch (options.Command) { case Command.ApplySchema: commandRunner = new CommandRunner_ApplySchema(); break; case Command.Import: commandRunner = new CommandRunner_Import(); break; default: OptionsParser.Usage("Missing command"); break; } commandRunner.Options = options; if (!commandRunner.Run()) { exitCode = 1; } } catch (Exception ex) { if (!verbose) { Console.WriteLine($"Caught exception: {ex.Message}"); } else { Console.WriteLine($"Caught exception: {ex.ToString()}"); Console.WriteLine(); } try { var log = Factory.ResolveSingleton <ILog>(); log.WriteLine($"Caught exception in BaseStationImport: {ex.ToString()}"); Console.WriteLine("Full details have been recorded in the log"); } catch (Exception iEx) { Console.WriteLine($"The exception could not be logged: {iEx.Message}"); } exitCode = 2; } Environment.Exit(exitCode); }