Example #1
0
        void ConnectServer(MonitorClient monitor)
        {
            monitor.ConnectServer();
            ServerHandle server = new ServerHandle(monitor.monitorSocket);

            servers.Add(server);
        }
Example #2
0
        public void StartMonitoring(string host, string port)
        {
            string command = null;

            while (true)
            {
                switch (state)
                {
                // Initialize Redis
                case CommandState.Idle:
                    state = CommandState.Main;
                    break;

                // Main Screen - Monitor with or without Server //
                case CommandState.Main:
                    DivideSection();
                    Console.WriteLine("-------Monitoring Command-------\n" +
                                      "|      0 : Exit                |\n" +
                                      "|      1 : Only Redis          |\n" +
                                      "|      2 : Connect Server      |\n" +
                                      "--------------------------------");
                    command = GetCommand();

                    if ("0" == command)
                    {
                        state = CommandState.Finish;
                    }
                    else if ("1" == command)
                    {
                        state = CommandState.Redis;
                    }
                    else if ("2" == command)
                    {
                        state = CommandState.Connect;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Command...");
                    }

                    break;

                // Monitor without Server, Show data from only Redis //
                case CommandState.Redis:
                    DivideSection();
                    Console.WriteLine("-------Monitoring Command-------\n" +
                                      "|     0 : Exit                 |\n" +
                                      "|     1 : Back to Main         |\n" +
                                      "|     2 : Show User LIst       |\n" +
                                      "|     3 : Show User Info       |\n" +
                                      "|     4 : Show Room List       |\n" +
                                      "|     5 : Show Chat Ranking    |\n" +
                                      "--------------------------------");
                    command = GetCommand();
                    RedisCommand(command);
                    break;

                // Begin Server Connection Sequence //
                case CommandState.Connect:
                    DivideSection();
                    Console.WriteLine("-------Monitoring Command-------\n" +
                                      "|      0 : Exit                |\n" +
                                      "|      1 : Back to Main        |\n" +
                                      "|      2 : Connect Server      |\n" +
                                      "|      3 : Start Monitoring    |\n" +
                                      "--------------------------------");
                    command = GetCommand();

                    switch (command)
                    {
                    case "0":
                        state = CommandState.Finish;
                        CloseAllServer();
                        break;

                    case "1":
                        state = CommandState.Main;
                        CloseAllServer();
                        break;

                    case "2":
                        Console.Write("\nIP Address: " + ((host == null) ? "LoopBack" : host) + "\nPORT: ");
                        port   = Console.ReadLine();
                        server = new MonitorClient(host, port);
                        try
                        {
                            ConnectServer(server);
                        }
                        catch (SocketException se)
                        {
                            Console.WriteLine("\nFAIL to connect...");
                            server = null;
                            break;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                            server = null;
                            break;
                        }
                        break;

                    case "3":
                        if (0 != servers.Count)
                        {
                            state = CommandState.Server;
                        }
                        else
                        {
                            Console.WriteLine("\nNot Connected to Server...");
                        }
                        break;

                    default:
                        Console.WriteLine("Invalid Command...");
                        break;
                    }

                    break;

                // Monitor with Server Connection //
                case CommandState.Server:
                    DivideSection();

                    // Monitoring Thread
                    Thread mThread = new Thread(RealTimeMonitor);
                    mThread.Start();

                    command = GetCommand();
                    switch (command)
                    {
                    case "0":
                        state = CommandState.Finish;
                        mThread.Abort();
                        CloseAllServer();
                        break;

                    case "1":
                        state = CommandState.Main;
                        mThread.Abort();
                        CloseAllServer();
                        break;

                    default:
                        Console.WriteLine("Invalid Command...");
                        DivideSection();
                        break;
                    }

                    break;

                case CommandState.Finish:
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Wrong State!!");
                    break;
                }
            }
        }