Exemple #1
0
        static void RunAsAConsole(int port, bool debug)
        {
            //Console.WriteLine("Current culture: " + CultureInfo.CurrentCulture.DisplayName);
            if (Type.GetType("Mono.Runtime") == null)
            {
                _ = new exitHandler();
            }

            cumulus = new Cumulus(port, debug, "");

            Console.WriteLine(DateTime.Now.ToString("G"));

            Console.WriteLine("Type Ctrl-C to terminate");
        }
Exemple #2
0
        //private exitHandler ctrlchandler;

        private static void Main(string[] args)
        {
            //var ci = new CultureInfo("en-GB");
            //System.Threading.Thread.CurrentThread.CurrentCulture = ci;


            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                // Use reflection, so no attempt to load Mono dll on Windows
                Assembly   _posixAsm;
                Type       _unixSignalType, _signumType;
                MethodInfo _unixSignalWaitAny;

                _posixAsm          = Assembly.Load("Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
                _unixSignalType    = _posixAsm.GetType("Mono.Unix.UnixSignal");
                _unixSignalWaitAny = _unixSignalType.GetMethod("WaitAny", new[] { _unixSignalType.MakeArrayType() });
                _signumType        = _posixAsm.GetType("Mono.Unix.Native.Signum");

                Array _signals = Array.CreateInstance(_unixSignalType, 2);
                _signals.SetValue(Activator.CreateInstance(_unixSignalType, _signumType.GetField("SIGINT").GetValue(null)), 0);
                _signals.SetValue(Activator.CreateInstance(_unixSignalType, _signumType.GetField("SIGTERM").GetValue(null)), 1);


                Thread signal_thread = new Thread(delegate()
                {
                    while (true)
                    {
                        // Wait for a signal to be delivered
                        var id = (int)_unixSignalWaitAny.Invoke(null, new object[] { _signals });

                        // Notify the main thread that a signal was received,
                        // you can use things like:
                        //    Application.Invoke () for Gtk#
                        //    Control.Invoke on Windows.Forms
                        //    Write to a pipe created with UnixPipes for server apps.
                        //    Use an AutoResetEvent



                        exitSystem = true;

                        //AppDomain.CurrentDomain.UnhandledException -= UnhandledExceptionTrapper;
                    }
                });

                signal_thread.Start();
            }
            else
            {
                var exithandler = new exitHandler();
            }

            int httpport = 8998;
            int wsport   = 8002;

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-lang" && args.Length >= i)
                {
                    var lang = args[i + 1];

                    System.Globalization.CultureInfo.DefaultThreadCurrentCulture   = new System.Globalization.CultureInfo(lang);
                    System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo(lang);
                }

                if (args[i] == "-port" && args.Length >= i)
                {
                    httpport = Convert.ToInt32(args[i + 1]);
                }

                if (args[i] == "-wsport" && args.Length >= i)
                {
                    wsport = Convert.ToInt32(args[i + 1]);
                }
            }

            //System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-GB");
            //System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo("en-GB");
            Console.WriteLine("Localizacion actual: " + CultureInfo.CurrentCulture.DisplayName);

            cumulus = new Cumulus(httpport, wsport);

            DateTime now = DateTime.Now;

            Console.WriteLine(DateTime.Now.ToString("G"));


            Console.WriteLine("Teclea Ctrl-C para terminar");
            while (!exitSystem)
            {
                Thread.Sleep(500);
            }

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                Console.WriteLine("\nTerminando Cumulus-MX");
                cumulus.Stop();
                Console.WriteLine("Cierre del programa");
                Environment.Exit(0);
            }
        }