/*--------------------------------------------------------*/ /// <summary> /// Parses the input from the user into a command string and a path string /// </summary> /// <param name="consoleInput">Input from user</param> private static void parseCommand(String consoleInput) { string[] inputArray = consoleInput.Split(' '); StatusText.setCommandInput(inputArray[0]); if (inputArray.Length > 1) { StatusText.setPathInput(inputArray[1]); } }
/*--------------------------------------------------------------------------------------*/ #endregion /// <summary> /// Core of the program, automatically executed /// </summary> /// <param name="args"></param> static void Main(string[] args) { NetworkConfig.startUDPServer(); Thread thread = new Thread(Server.startTCPlisteners); thread.Start(); StatusText.showWelcomeMessage(); while (EXIT_STATUS == false) { parseCommand(typeInRequest()); //Erases the IP list in order to avoid disconnected guests. NetworkConfig.refreshIPList(); //Pause in order for all other hosts to have time to send their IP again. Thread.Sleep(50); Client.executeRequest(); } }
/*---------------------------------------------------------------------------*/ /// <summary> /// Executes the command typed in by user. /// </summary> public static void executeRequest() { int commandIndex = 0; //Compares the command input to the list of possible commands. for (int i = 0; i < StatusText.getcommandInputValueArrayLength() + 1; ++i) { //A correcte instruction was entered if (i < StatusText.getcommandInputValueArrayLength() && StatusText.getCommandValue(i) == StatusText.getCommandInput()) { commandIndex = i; break; } //A non existing instruction was entered else { commandIndex = i; } } //End of for //Calls the correct method depending on the command input switch (commandIndex) { case 0: upload(StatusText.getPathInput()); break; case 1: update(StatusText.getPathInput()); break; case 2: delete(StatusText.getPathInput()); break; case 3: open(StatusText.getPathInput()); break; case 4: case 5: quit(); break; case 6: case 7: case 10: showHelpScreen(); break; case 8: create(StatusText.getPathInput()); break; case 9: showIPs(); break; } //End of switch //Erases the command just executed to prevent any misbehaviours for future requests. StatusText.setCommandInput(""); StatusText.setPathInput(""); }