Example #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public void Menu()
        {
            Console.WriteLine("Server Manager Client");
            Console.WriteLine(string.Format("version {0}\n", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version));

            Console.WriteLine("type help for available commands.");


            bool goOn      = true;
            bool connected = false;

            while (goOn)
            {
                Console.Write("> ");
                string   command = Console.ReadLine();
                string[] cArr    = command.Split(new char[] { ' ' });
                string   result  = "";

                try
                {
                    if (connected)
                    {
                        switch (cArr[0].ToLower())
                        {
                        case "help":
                            Console.WriteLine(Help());
                            break;

                        case "ps":
                            result = remoteInterface.Ps();
                            Console.WriteLine(AdjustPsList(result));
                            break;

                        case "startall":
                            result = remoteInterface.StartAll();
                            Console.WriteLine(result);
                            break;

                        case "stopall":
                            result = remoteInterface.StopAll();
                            Console.WriteLine(result);
                            break;

                        case "start":
                            if (cArr.Length >= 2)
                            {
                                foreach (string jb in cArr)
                                {
                                    if (jb != "start")
                                    {
                                        result = remoteInterface.StartJob(jb);
                                        Console.WriteLine(string.Format("Start of {0} {1}", jb, result));
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("{0} is an illegal command. Correct syntax is {1} <jobname>.", command, cArr[0]);
                            }
                            break;

                        case "stop":
                            if (cArr.Length >= 2)
                            {
                                foreach (string jb in cArr)
                                {
                                    if (jb != "stop")
                                    {
                                        result = remoteInterface.StopJob(jb);
                                        Console.WriteLine(string.Format("Stop of {0} {1}", jb, result));
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("{0} is an illegal command. Correct syntax is {1} <jobname>.", command, cArr[0]);
                            }
                            break;

                        case "connect":
                            if (cArr.Length == 3)
                            {
                                int port;
                                try
                                {
                                    port = Convert.ToInt32(cArr[2]);
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine("Port number must be numeric.");
                                    break;
                                }

                                if (!Connect(cArr[1], port))
                                {
                                    break;
                                }
                                connected = true;
                                Console.WriteLine("ok, connected");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("{0} is an illegal command. Correct syntax is {1} <hostname> <port>.", command, cArr[0]);
                            }
                            break;

                        case "exit":
                            goOn = false;
                            break;

                        case "":
                            break;

                        default:
                            Console.WriteLine("{0} is an illegal command", command);
                            break;
                        }
                    }
                    else
                    {
                        switch (cArr[0].ToLower())
                        {
                        case "connect":
                            if (cArr.Length == 3)
                            {
                                int port;

                                try
                                {
                                    port = Convert.ToInt32(cArr[2]);
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine("Port number must be numeric.");
                                    break;
                                }

                                if (!Connect(cArr[1], port))
                                {
                                    break;
                                }
                                connected = true;
                                Console.WriteLine("ok, connected");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("{0} is an illegal command. Correct syntax is {1} <hostname> <port>.", command, cArr[0]);
                            }
                            break;

                        case "help":
                            Console.WriteLine(Help());
                            break;

                        case "exit":
                            goOn = false;
                            break;

                        default:
                            Console.WriteLine("You must connect before issuing any commands except help and exit.", command);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error when issuing command to server\n{0}", e.Message);
                }
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Example #2
0
 public string StopAll()
 {
     return(remoteInterface.StopAll());
 }