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); }
/// <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(); } }
/// <summary> /// Initialises the database plugins. /// </summary> /// <remarks><para> /// In the field the utility will be running in the same folder as VirtualRadar.exe and will have /// access to all of VRS's plugins. The LoadPlugins call will load every plugin into the process. /// However we only want the database plugins to do any work, so the function does not call the normal /// RegisterImplementations on the plugin manager to get all of them hooked into the system. Rather it /// picks out the database plugins and just calls RegisterImplementations on those. The other plugins /// remain loaded but impotent. /// </para><para> /// The other thing to be aware of is that the utility's version number will be used by the VRS library /// code that loads plugins. If plugins unexpectedly fail to load then make sure that the utility's /// version number falls within the range of version numbers that the plugin's manifest is asking for. /// </para> /// </remarks> private static void LoadDatabasePlugins() { var pluginManager = Factory.ResolveSingleton <IPluginManager>(); ProgramLifetime.LoadPlugins(); foreach (var plugin in pluginManager.LoadedPlugins) { switch (plugin.Id) { case "VirtualRadarServer.Plugin.SqlServer": plugin.RegisterImplementations(Factory.Singleton); break; } } }
/// <summary> /// Initialises the database plugins. /// </summary> /// <remarks><para> /// In the field the utility will be running in the same folder as VirtualRadar.exe and will have /// access to all of VRS's plugins. The LoadPlugins call will load every plugin into the process. /// However we only want the database plugins to do any work, so the function does not call the normal /// RegisterImplementations on the plugin manager to get all of them hooked into the system. Rather it /// picks out the database plugins and just calls RegisterImplementations on those. The other plugins /// remain loaded but impotent. /// </para><para> /// The other thing to be aware of is that the utility's version number will be used by the VRS library /// code that loads plugins. If plugins unexpectedly fail to load then make sure that the utility's /// version number falls within the range of version numbers that the plugin's manifest is asking for. /// </para> /// </remarks> private static void LoadDatabasePlugins() { var pluginManager = Factory.ResolveSingleton <IPluginManager>(); ProgramLifetime.LoadPlugins(); var countLoaded = 0; foreach (var plugin in pluginManager.LoadedPlugins) { switch (plugin.Id) { case "VirtualRadarServer.Plugin.SqlServer": plugin.RegisterImplementations(Factory.Singleton); Console.WriteLine($"Plugin {plugin.Id} loaded"); ++countLoaded; break; } } Console.WriteLine($"{countLoaded:N0} plugin(s) loaded"); Console.WriteLine(); }