Beispiel #1
0
        static void Main(string[] args)
        {
            bool service = false;
            bool standalone = false;
            string cfgFile = "AlarmSystemConfig.xml";
            bool showHelp = false;

            cmd = new OptionSet()
            {
                {"d|daemon", "Start as background daemon", s => service = s != null},
                {"s|standalone", "Start not as daemon, but standalone", s => standalone = s != null},
                {"c|config=", "Set the config {FILE} to use", s => cfgFile = s},
                {"h|help", "Show help", s => showHelp = s != null}
            };

            cmd.Parse(args);

            if (service && standalone)
            {
                Console.WriteLine("Sorry, you cannot start as daemon and standalone at the same time.");
                PrintHelp();
            }
            else
            {
                AlarmSystemService alarmsys = new AlarmSystemService();
                alarmsys.ConfigFile = cfgFile;

                if (service)
                {
                    ServiceBase.Run(alarmsys);
                }
                else if(standalone)
                {
                    alarmsys.Start();

                    Console.ReadLine();

                    alarmsys.Stop();
                }
                else if(showHelp)
                {
                    PrintHelp();
                }
                else
                {
                    PrintHelp();
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            bool   service    = false;
            bool   standalone = false;
            string cfgFile    = "AlarmSystemConfig.xml";
            bool   showHelp   = false;

            cmd = new OptionSet()
            {
                { "d|daemon", "Start as background daemon", s => service = s != null },
                { "s|standalone", "Start not as daemon, but standalone", s => standalone = s != null },
                { "c|config=", "Set the config {FILE} to use", s => cfgFile = s },
                { "h|help", "Show help", s => showHelp = s != null }
            };

            cmd.Parse(args);

            if (service && standalone)
            {
                Console.WriteLine("Sorry, you cannot start as daemon and standalone at the same time.");
                PrintHelp();
            }
            else
            {
                AlarmSystemService alarmsys = new AlarmSystemService();
                alarmsys.ConfigFile = cfgFile;

                if (service)
                {
                    ServiceBase.Run(alarmsys);
                }
                else if (standalone)
                {
                    alarmsys.Start();

                    Console.ReadLine();

                    alarmsys.Stop();
                }
                else if (showHelp)
                {
                    PrintHelp();
                }
                else
                {
                    PrintHelp();
                }
            }
        }