Exemple #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            if (args.Length >= 1)
            {
                if (args[0] == "-cfg")
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new ClusterConfig());
                }
                else if (args[0] == "-install")
                {
                    Native.Kernel32.AttachConsole(Native.Ntdll.GetParentProcessID(Process.GetCurrentProcess().Id));

                    ProjectInstaller installer = new ProjectInstaller();

                    installer.Context = new InstallContext();
                    installer.Context.Parameters["assemblypath"] = Application.ExecutablePath;
                    Hashtable state = new Hashtable();

                    try
                    {
                        installer.Install(state);
                    }
                    catch (Exception ex)
                    {
                        installer.Rollback(state);
                        LogManager.GetCurrentClassLogger().FatalException(Resources.ServerRunningError, ex);
                    }
                }
                else if (args[0] == "-uninstall")
                {
                    Native.Kernel32.AttachConsole(Native.Ntdll.GetParentProcessID(Process.GetCurrentProcess().Id));

                    ProjectInstaller installer = new ProjectInstaller();

                    try
                    {
                        installer.Context = new InstallContext();
                        installer.Uninstall(null);
                    }
                    catch (Exception ex)
                    {
                        LogManager.GetCurrentClassLogger().FatalException(Resources.ServerRunningError, ex);
                        Console.WriteLine(Resources.ServerRunningError + ": " + ex.Message);
                    }
                }
                else if (args[0] == "-console")
                {
                    Native.Kernel32.AttachConsole(Native.Ntdll.GetParentProcessID(Process.GetCurrentProcess().Id));

                    ClusterSrv.RunAsProcess(args);
                }
            }
            else
            {
                System.IO.Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
                ClusterSrv.RunAsServer(args);
            }
        }
Exemple #2
0
        public static void RunAsProcess(string[] args)
        {
            ClusterSrv Server = new ClusterSrv();

            try
            {
                Native.Kernel32.SetConsoleTitle(" CLUSTER SRV (" + Settings.Default.NodeId + ") ");

                Console.WriteLine(Resources.ConsoleMenu.Replace("\\n", Environment.NewLine), Settings.Default.NodeId);

                Server.OnStart(args);
                //_Cluster = new Cluster(GetClusterSettings());
                //_Cluster.Run();

                // Asegurar que libera la IP virtual antes de entrar.
                // Puede ser que ambos servidores, hayan cogido la IP virtual porque estén incomunicados
                //_Cluster.Deactivate();

                ConsoleKeyInfo cki = new ConsoleKeyInfo();

                do
                {
                    while (Console.KeyAvailable == false)
                    {
                        System.Threading.Thread.Sleep(500);
                    }

                    cki = Console.ReadKey(true);

                    try
                    {
                        switch (cki.Key)
                        {
                        case ConsoleKey.M:
                            Console.WriteLine(Resources.ConsoleMenu.Replace("\\n", Environment.NewLine), Settings.Default.NodeId);
                            break;

                        case ConsoleKey.A:
                            _Cluster?.Activate();
                            break;

                        case ConsoleKey.C:
                            if (_Cluster?.State.LocalNode.State == NodeState.NoActive)
                            {
                                _Cluster?.Activate();
                            }
                            else
                            {
                                _Cluster?.Deactivate();
                            }
                            break;

                        case ConsoleKey.I:
                            Console.WriteLine(_Cluster?.State);
                            break;

                        case ConsoleKey.Q:
                            break;

                        case ConsoleKey.H:
                            Console.WriteLine(Resources.ConsoleMenu.Replace("\n", Environment.NewLine), Settings.Default.NodeId);
                            break;

#if DEBUG
                        case ConsoleKey.N:
                            _Cluster.WorkingNetworkSimulOff = !_Cluster.WorkingNetworkSimulOff;
                            break;
#endif
                        }
                    }
                    catch (Exception ex)
                    {
                        _Logger.Error(ex, Resources.ConsoleCommandError);
                    }
                } while (cki.Key != ConsoleKey.Q);

                //_Cluster.Dispose();
                Server.OnStop();
            }
            catch (Exception ex)
            {
                _Logger.Fatal(ex, Resources.ServerRunningError);
            }
        }