Exemple #1
0
        /// <summary>
        /// Check console input
        /// TODO: Move this into <see cref="ConsoleThread"/>
        /// </summary>
        private static void CheckConsoleInput()
        {
            // Get input from console output.
            string input = Console.ReadLine();

            // Switch from cases of the input.
            switch (input)
            {
            case "quit":
            case "exit":
            case "stop":
                // Close the application.
                logger.Log("Bye!");
                toStop = false;
                // Try to close the GUI (even if it's closed already).
                try
                {
                    gui.Invoke((MethodInvoker) delegate { gui.exit = true; gui.Close(); });
                }
                catch (Exception ex)
                {
                    logger.Log("Error: GUI Already Closed. | " + ex.Message);
                    logger.Log(ex.StackTrace);
                }
                // Finally close the application.
                Application.Exit();
                break;

            case "update":
                // Try to update the RPC.
                UpdateRPC();
                break;

            case "gui":
                // Try to launch the GUI (without autoHide, because it's not necessary).
                try
                {
                    logger.Log("Launching GUI");
                    StartGUI(false);
                }
                catch (Exception ex)
                {
                    logger.Log("Error: When attempting to launch GUI. | " + ex.Message);
                    logger.Log(ex.StackTrace);
                }
                break;

            case var loadFileCommand when new Regex(@"^load\s[a-z0-9]+$").IsMatch(loadFileCommand):
                try
                {
                    string arguments = loadFileCommand.Substring(5, loadFileCommand.Length - 5);
                    ConfigHandler.ReadConfig(arguments, false);
                }
                catch (Exception ex)
                {
                    logger.Log("Failed to parse arguments and read config from file. | " + ex.Message);
                    logger.Log(ex.StackTrace);
                }
                break;

            case var loadCommand when new Regex(@"^load$").IsMatch(loadCommand):
                try
                {
                    ConfigHandler.ReadConfig();
                }
                catch (Exception ex)
                {
                    logger.Log("Failed to parse arguments and read config from file. | " + ex.Message);
                    logger.Log(ex.StackTrace);
                }
                break;

            case var saveFileCommand when new Regex(@"^save\s[a-z0-9]+$").IsMatch(saveFileCommand):
                try
                {
                    string arguments = saveFileCommand.Substring(5, saveFileCommand.Length - 5);
                    ConfigHandler.WriteConfig(arguments, false);
                }
                catch (Exception ex)
                {
                    logger.Log("Failed to parse arguments and write config to file. | " + ex.Message);
                    logger.Log(ex.StackTrace);
                }
                break;

            case var saveCommand when new Regex(@"^save$").IsMatch(saveCommand):
                try
                {
                    ConfigHandler.WriteConfig();
                }
                catch (Exception ex)
                {
                    logger.Log("Failed to parse arguments and write config to file. | " + ex.Message);
                    logger.Log(ex.StackTrace);
                }
                break;

            default:
                // Output the possible command line arguments if no recognized case is used.
                logger.Log("Commands are as follows: [ quit/exit/stop | update | gui ]");
                break;
            }
        }
Exemple #2
0
 /// <summary>
 /// Forces the <see cref="ConfigHandler"/> to save the <see cref="Config"/> to file.
 /// </summary>
 /// <param name="sender">The sending object (Typically a <see cref="Button"/>).</param>
 /// <param name="e">The event arguments.</param>
 private void SaveConfig_Button_Click(object sender, EventArgs e) => Invoke((MethodInvoker) delegate
 {
     ConfigHandler.WriteConfig();
 });