Пример #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            bool install = false, uninstall = false, console = false, rethrow = false;

            try
            {
                foreach (string arg in args)
                {
                    switch (arg)
                    {
                        case "-i":
                        case "-install":
                            install = true; break;
                        case "-u":
                        case "-uninstall":
                            uninstall = true; break;
                        case "-c":
                        case "-console":
                            console = true; break;
                        default:
                            Console.Error.WriteLine("Argument not expected: " + arg);
                            break;
                    }
                }
                if (uninstall)
                {
                    Install(true, args);
                }
                if (install)
                {
                    Install(false, args);
                }
                if (console)
                {
                    Console.WriteLine("Starting...");
                    softGetawayWindowsService router = new softGetawayWindowsService();
                    router.startUp();
                    Console.WriteLine("System running; press any key to stop");
                    Console.ReadKey(true);
                    router.Stop();
                    Console.WriteLine("System stopped");
                }
                else if (!(install || uninstall))
                {
                    rethrow = true; // so that windows sees error...
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
            {
                new softGetawayWindowsService()
            };
                    ServiceBase.Run(ServicesToRun);

                    rethrow = false;
                }
                return 0;
            }
            catch (Exception ex)
            {
                if (rethrow) throw;
                Console.Error.WriteLine(ex.Message);
                return -1;
            }
        }
Пример #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            bool install = false, uninstall = false, console = false, rethrow = false;

            try
            {
                foreach (string arg in args)
                {
                    switch (arg)
                    {
                    case "-i":
                    case "-install":
                        install = true; break;

                    case "-u":
                    case "-uninstall":
                        uninstall = true; break;

                    case "-c":
                    case "-console":
                        console = true; break;

                    default:
                        Console.Error.WriteLine("Argument not expected: " + arg);
                        break;
                    }
                }
                if (uninstall)
                {
                    Install(true, args);
                }
                if (install)
                {
                    Install(false, args);
                }
                if (console)
                {
                    Console.WriteLine("Starting...");
                    softGetawayWindowsService router = new softGetawayWindowsService();
                    router.startUp();
                    Console.WriteLine("System running; press any key to stop");
                    Console.ReadKey(true);
                    router.Stop();
                    Console.WriteLine("System stopped");
                }
                else if (!(install || uninstall))
                {
                    rethrow = true; // so that windows sees error...
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[]
                    {
                        new softGetawayWindowsService()
                    };
                    ServiceBase.Run(ServicesToRun);

                    rethrow = false;
                }
                return(0);
            }
            catch (Exception ex)
            {
                if (rethrow)
                {
                    throw;
                }
                Console.Error.WriteLine(ex.Message);
                return(-1);
            }
        }