Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            InitialiseUnhandledExceptionHandling();

            var headless = false;

            foreach (string arg in args)
            {
                if (arg.ToUpper().StartsWith("-CULTURE:"))
                {
                    ForcedCultureInfo = new CultureInfo(arg.Substring(9));
                    Thread.CurrentThread.CurrentUICulture = ForcedCultureInfo;
                    Thread.CurrentThread.CurrentCulture   = ForcedCultureInfo;
                }
                if (arg.ToUpper() == "-DEFAULTFONTS")
                {
                    VirtualRadar.WinForms.FontFactory.DisableFontReplacement = true;
                }
                if (arg.ToUpper() == "-NOGUI")
                {
                    headless = true;
                }
            }
            ApplicationInformation.SetHeadless(headless);

            if (!headless)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
            }

            Factory.Singleton.Register <IApplicationInformation, ApplicationInformation>();
            Factory.Singleton.Register <IExceptionReporter, ExceptionReporter>();
            SQLiteWrapper.Implementations.Register(Factory.Singleton);
            VirtualRadar.Library.Implementations.Register(Factory.Singleton);
            VirtualRadar.Database.Implementations.Register(Factory.Singleton);
            VirtualRadar.WebServer.Implementations.Register(Factory.Singleton);
            VirtualRadar.WebSite.Implementations.Register(Factory.Singleton);
            if (!headless)
            {
                VirtualRadar.WinForms.Implementations.Register(Factory.Singleton);
            }
            else
            {
                VirtualRadar.Headless.Implementations.Register(Factory.Singleton);
                VirtualRadar.Interop.Console.ShowConsole();
            }

            if (args.Contains("-showConfigFolder"))
            {
                var configurationStorage = Factory.Singleton.Resolve <IConfigurationStorage>().Singleton;
                var folderMessage        = String.Format("Configuration folder: {0}", configurationStorage.Folder);
                Console.WriteLine(folderMessage);
                Factory.Singleton.Resolve <IMessageBox>().Show("Configuration Folder");
            }

            var receiverFormatManager = Factory.Singleton.Resolve <IReceiverFormatManager>().Singleton;

            receiverFormatManager.Initialise();

            var rebroadcastFormatManager = Factory.Singleton.Resolve <IRebroadcastFormatManager>().Singleton;

            rebroadcastFormatManager.Initialise();

            var pluginManager = Factory.Singleton.Resolve <IPluginManager>().Singleton;

            pluginManager.LoadPlugins();

            bool mutexAcquired;
            bool allowMultipleInstances = args.Any(a => a.ToUpper().StartsWith("-WORKINGFOLDER:"));

            using (var singleInstanceMutex = CheckForOtherRunningInstances(out mutexAcquired, allowMultipleInstances)) {
                try {
                    CheckForHttpListenerSupport();
                    CheckForDotNetThreePointFive();

                    StartApplication(args);
                } finally {
                    if (mutexAcquired)
                    {
                        singleInstanceMutex.ReleaseMutex();
                    }
                }
            }

            // Calling Environment.Exit rather than falling off the end of Main will ensure that foreground threads get shut down
            Environment.Exit(0);
        }