Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Lib.Network.PingIP1;
- using Lib.System.Command;
- namespace Brendan
- {
- class Program
- {
- private const string prefixBeforeLogon = ">";
- private const string prefixAfterLogon = "(BT):>>";
- private const string uname = "Brendan";
- private const string pwd = "password";
- private enum EnumCommand
- {
- Invalid,
- Exit,
- Login,
- Logout,
- Username,
- Ping,
- CLS,
- RDP
- }
- /// <summary>
- /// Main program
- /// </summary>
- /// <param name="args">The args as string array.</param>
- static void Main(string[] args)
- {
- var loggedIn = false;
- Console.WriteLine("Welcome! Use #Exit to close this program.");
- // Initial input
- Console.Write(prefixBeforeLogon);
- var cCommand = GetCommand(Console.ReadLine());
- // Keep this program running untill user exits
- while (cCommand != EnumCommand.Exit)
- {
- switch (cCommand)
- {
- case EnumCommand.Invalid:
- UserCommand.Invalid();
- Console.WriteLine("Invalid command. Use #Exit to quit!");
- break;
- case EnumCommand.Login:
- UserCommand.Login();
- Console.Write("Username: ");
- if (Console.ReadLine() == uname)
- {
- Console.Write("Password: ");
- }
- else
- {
- Console.WriteLine("Invalid Username!");
- }
- if (Console.ReadLine() == pwd)
- {
- loggedIn = true;
- }
- else
- {
- Console.WriteLine("Incorrect Password!");
- }
- break;
- case EnumCommand.Logout:
- UserCommand.Logout();
- Console.WriteLine("You are logged out!");
- loggedIn = false;
- break;
- case EnumCommand.Username:
- UserCommand.Username();
- Console.WriteLine(loggedIn ? "Brendan" : "Please login first");
- break;
- default:
- Console.WriteLine("Program error!");
- break;
- case EnumCommand.Ping:
- UserCommand.Ping();
- // Console.Write("Enter IP/Hostname: ");
- PingExample.PingIP(Console.ReadLine());
- break;
- case EnumCommand.RDP:
- UserCommand.RDP();
- System.Diagnostics.Process.Start("C:\\Windows\\System32\\mstsc.exe");
- Console.WriteLine("Microsoft Remote Desktop Services Started!");
- break;
- case EnumCommand.CLS:
- UserCommand.CLS();
- Console.Clear();
- break;
- }
- // Use of immidiate if - "statement ? if_true : if_false"
- Console.Write(loggedIn ? prefixAfterLogon : prefixBeforeLogon);
- // Get next command
- cCommand = GetCommand(Console.ReadLine());
- }
- }
- /// <summary>
- /// Returns the enum value of the user command.
- /// </summary>
- /// <param name="userInput">The user input as string.</param>
- /// <returns></returns>
- private static EnumCommand GetCommand(string userInput)
- {
- switch (userInput.ToUpperInvariant())
- {
- case "#EXIT":
- return EnumCommand.Exit;
- case "#LOGIN":
- return EnumCommand.Login;
- case "#LOGOUT":
- return EnumCommand.Logout;
- case "$USERNAME":
- return EnumCommand.Username;
- case "$PING":
- return EnumCommand.Ping;
- case "$CLS":
- return EnumCommand.CLS;
- case "$RDP":
- return EnumCommand.RDP;
- default:
- return EnumCommand.Invalid;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement