Stop() public method

public Stop ( ) : void
return void
        static void Main(string[] args)
        {
            // If port is zero socket will attach on the first available port between 1024 and 5000 (see https://goo.gl/t4MBUr)
            int port = int.Parse(ConfigurationManager.AppSettings.Get("Port"));
            // The socket's queue size for incoming connections (see https://goo.gl/IIFY20)
            int    queue = int.Parse(ConfigurationManager.AppSettings.Get("QueueSize"));
            int    convertersPoolSize = int.Parse(ConfigurationManager.AppSettings.Get("ConvertersPoolSize"));
            string restartCronExpr    = ConfigurationManager.AppSettings.Get("SystemRestartCron");

            // Greet the user and recap params
            Console.WriteLine("MateCAT WinConverter!");
            Console.WriteLine("Press ESC to stop the server and quit");
            Console.WriteLine();

            log.Info("MateCAT WinConverter is starting");

            // Set system restart timer, if configured
            if (!String.IsNullOrWhiteSpace(restartCronExpr))
            {
                CrontabSchedule restartCron = CrontabSchedule.Parse(restartCronExpr);
                DateTime        restartDate = restartCron.GetNextOccurrence(DateTime.Now);

                System.Timers.Timer restartTimer = new System.Timers.Timer();
                restartTimer.Elapsed  += new ElapsedEventHandler(SystemRestart);
                restartTimer.Interval  = (int)(restartDate - DateTime.Now).TotalMilliseconds;
                restartTimer.AutoReset = false;
                restartTimer.Enabled   = true;
                log.Info("Auto restart enabled: will restart at " + restartDate.ToShortTimeString() + " of " + restartDate.ToShortDateString());
            }

            // Create the main conversion class
            IConverter converter = new ConvertersRouter(convertersPoolSize);

            // Then create and start the conversion server
            server = new ConversionServer.ConversionServer(port, queue, converter);
            server.Start();

            // Press ESC to stop the server.
            // If others keys are pressed, remember to the user that only ESC works.
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Console.WriteLine("Press ESC to stop the server");
            }

            // ESC key pressed, shutdown everything and say goodbye
            log.Info("User pressed ESC: stopping the server");
            server.Stop();

            Console.WriteLine("Closing MateCAT WinConverter right now");
            // Let the user read the goodbye message
            Thread.Sleep(1000);
        }
        static void Main(string[] args)
        {
            // If port is zero socket will attach on the first available port between 1024 and 5000 (see https://goo.gl/t4MBUr)
            int port = int.Parse(ConfigurationManager.AppSettings.Get("Port"));
            // The socket's queue size for incoming connections (see https://goo.gl/IIFY20)
            int queue = int.Parse(ConfigurationManager.AppSettings.Get("QueueSize"));
            int convertersPoolSize = int.Parse(ConfigurationManager.AppSettings.Get("ConvertersPoolSize"));
            string restartCronExpr = ConfigurationManager.AppSettings.Get("SystemRestartCron");

            // Greet the user and recap params
            Console.WriteLine("MateCAT WinConverter!");
            Console.WriteLine("Press ESC to stop the server and quit");
            Console.WriteLine();

            log.Info("MateCAT WinConverter is starting");

            // Set system restart timer, if configured
            if (!String.IsNullOrWhiteSpace(restartCronExpr))
            {
                CrontabSchedule restartCron = CrontabSchedule.Parse(restartCronExpr);
                DateTime restartDate = restartCron.GetNextOccurrence(DateTime.Now);

                System.Timers.Timer restartTimer = new System.Timers.Timer();
                restartTimer.Elapsed += new ElapsedEventHandler(SystemRestart);
                restartTimer.Interval = (int)(restartDate - DateTime.Now).TotalMilliseconds;
                restartTimer.AutoReset = false;
                restartTimer.Enabled = true;
                log.Info("Auto restart enabled: will restart at "+ restartDate.ToShortTimeString() + " of "+ restartDate.ToShortDateString());
            }

            // Create the main conversion class
            IConverter converter = new ConvertersRouter(convertersPoolSize);

            // Then create and start the conversion server
            server = new ConversionServer.ConversionServer(port, queue, converter);
            server.Start();

            // Press ESC to stop the server.
            // If others keys are pressed, remember to the user that only ESC works.
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Console.WriteLine("Press ESC to stop the server");
            }

            // ESC key pressed, shutdown everything and say goodbye
            log.Info("User pressed ESC: stopping the server");
            server.Stop();

            Console.WriteLine("Closing MateCAT WinConverter right now");
            // Let the user read the goodbye message
            Thread.Sleep(1000);
        }
        private static void SystemRestart(object source, ElapsedEventArgs e)
        {
            log.Info("Restart timeout reached: stopping the server");
            server.Stop();

            System.Diagnostics.Process.Start("shutdown.exe", "-r -f -t " + secondsBeforeRestart);
            log.Info("System will restart in " + secondsBeforeRestart + " seconds; run \"shutdown -a\" to abort");

            int noticeDelay = 5;
            int i           = secondsBeforeRestart;

            while (i > 0)
            {
                Thread.Sleep(noticeDelay * 1000);
                i -= noticeDelay;
                Console.WriteLine(i + " seconds before system restart (if not aborted)");
            }
        }
        static void Main(string[] args)
        {
            // If port is zero socket will attach on the first available port between 1024 and 5000 (see https://goo.gl/t4MBUr)
            int port = int.Parse(ConfigurationManager.AppSettings.Get("Port"));
            // The socket's queue size for incoming connections (see https://goo.gl/IIFY20)
            int queue = int.Parse(ConfigurationManager.AppSettings.Get("QueueSize"));
            int convertersPoolSize = int.Parse(ConfigurationManager.AppSettings.Get("ConvertersPoolSize"));

            // Greet the user and recap params
            Console.WriteLine("MateCAT WinConverter!");
            Console.WriteLine("Guessed external IP is: " + GuessLocalIPv4().ToString());
            Console.WriteLine("Press ESC to stop the server and quit");
            Console.WriteLine();

            log.Info("MateCAT WinConverter is starting");

            // Create the main conversion class
            IConverter converter = new ConvertersRouter(convertersPoolSize);

            // Then create and start the conversion server
            ConversionServer.ConversionServer server = new ConversionServer.ConversionServer(port, queue, converter);
            server.Start();

            // Press ESC to stop the server. 
            // If others keys are pressed, remember to the user that only ESC works.
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Console.WriteLine("Press ESC to stop the server.");
            }

            // ESC key pressed, shutdown everything and say goodbye
            log.Info("User asked to stop");
            server.Stop();

            Console.WriteLine("Closing MateCAT WinConverter right now");
            // Let the user read the goodbye message
            Thread.Sleep(1000);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // If port is zero socket will attach on the first available port between 1024 and 5000 (see https://goo.gl/t4MBUr)
            int port = int.Parse(ConfigurationManager.AppSettings.Get("Port"));
            // The socket's queue size for incoming connections (see https://goo.gl/IIFY20)
            int queue = int.Parse(ConfigurationManager.AppSettings.Get("QueueSize"));
            int convertersPoolSize = int.Parse(ConfigurationManager.AppSettings.Get("ConvertersPoolSize"));

            // Greet the user and recap params
            Console.WriteLine("MateCAT WinConverter!");
            Console.WriteLine("Guessed external IP is: " + GuessLocalIPv4().ToString());
            Console.WriteLine("Press ESC to stop the server and quit");
            Console.WriteLine();

            log.Info("MateCAT WinConverter is starting");

            // Create the main conversion class
            IConverter converter = new ConvertersRouter(convertersPoolSize);

            // Then create and start the conversion server
            ConversionServer.ConversionServer server = new ConversionServer.ConversionServer(port, queue, converter);
            server.Start();

            // Press ESC to stop the server.
            // If others keys are pressed, remember to the user that only ESC works.
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Console.WriteLine("Press ESC to stop the server.");
            }

            // ESC key pressed, shutdown everything and say goodbye
            log.Info("User asked to stop");
            server.Stop();

            Console.WriteLine("Closing MateCAT WinConverter right now");
            // Let the user read the goodbye message
            Thread.Sleep(1000);
        }
 public static void ClassCleanup()
 {
     testServer.Stop();
 }