/// <summary> /// Creates an interactive user menu for logged users. /// </summary> public static void Menu() { char menuChoice = '0'; bool exit = false; while (!exit) { Console.ForegroundColor = ConsoleColor.Cyan; string menu = "*********************************************************************************************************************" + "\r\n" + "Menu:" + "\r\n" + "*********************************************************************************************************************" + "\r\n" + "a. Login/Logout." + "\r\n" + "b. Retrieve last 10 messages from server." + "\r\n" + "c. Display last 20 retrieved messages (without retrieving new ones from the server)." + "\r\n" + "d. Display all retrieved messages (without retrieving new ones from the server)" + "\r\n" + "e. Write (and send) a new message (max. Length 150 characters)." + "\r\n" + "f. Delete local message cache (previous message history)." + "\r\n" + "g. Exit (logout first)." + "\r\n" + "*********************************************************************************************************************" + "\r\n" + "Please choose your action: "; Console.Write(menu); menuChoice = Console.ReadKey().KeyChar; Console.ResetColor(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); switch (menuChoice) { case ('A'): case ('a'): NewScreen(); if (!ChatRoom._loggedInUser.logged) { Login(!ChatRoom._loggedInUser.logged); } else { Logout(); } break; case ('B'): case 'b': NewScreen(); string checkError = ChatRoom.RetrieveTenMessages(); if (!(checkError.Length < 6)) { ErrorMessage(1, "\r\nWhile trying to retrieve messages from server the following error occured:"); ErrorMessage(3, "\r\n" + checkError + "\r\n\r\n"); } else { MarkerMessage(1, "\r\nRetrieved " + checkError + " new messages from server.\r\n\r\n"); } break; case ('C'): case 'c': { NewScreen(); const int messagesToDisplay = 20; int availableMessages = ChatRoom._messages.messages.Count; if (availableMessages >= 20) { MarkerMessage(1, "\r\nDisplaying " + messagesToDisplay + " messages:\r\n\r\n"); } else { MarkerMessage(1, "\r\nDisplaying " + availableMessages + " messages:\r\n\r\n"); } string messages = DisplayMessages(ChatRoom.DisplayMessages(messagesToDisplay)); if (messages == System.String.Empty) { ErrorMessage(1, "No Messages to display at the moment.\r\nTry to retrieve new messages from server.\r\n\r\n"); } } break; case ('D'): case 'd': { NewScreen(); MarkerMessage(1, "\r\nDisplaying " + ChatRoom._messages.messages.Count + " messages:\r\n\r\n"); string messages = DisplayMessages(ChatRoom.DisplayAllMessages()); if (messages == System.String.Empty) { ErrorMessage(1, "No Messages to display at the moment.\r\nTry to retrieve new messages from server.\r\n\r\n"); } break; } case ('E'): case 'e': NewScreen(); Console.Write("\r\nEnter your message:"); WriteAndSend(); break; case ('F'): case 'f': NewScreen(); ClearMessages(); break; case 'g': case ('G'): NewScreen(); if (Exit()) { exit = true; } break; default: NewScreen(); ErrorMessage(2, "\r\nPlease enter a valid menu selection.\r\n\r\n"); break; } } Console.ResetColor(); }