Advertisement
Guest User

Untitled

a guest
May 14th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Lib.Network.PingIP1;
  6. using Lib.System.Command;
  7.  
  8.  
  9. namespace Brendan
  10. {
  11.     class Program
  12.     {
  13.         private const string prefixBeforeLogon = ">";
  14.         private const string prefixAfterLogon = "(BT):>>";
  15.         private const string uname = "Brendan";
  16.         private const string pwd = "password";
  17.  
  18.        
  19.         private enum EnumCommand
  20.         {
  21.             Invalid,
  22.             Exit,
  23.             Login,
  24.             Logout,
  25.             Username,
  26.             Ping,
  27.             CLS,
  28.             RDP
  29.         }
  30.  
  31.         /// <summary>
  32.         /// Main program
  33.         /// </summary>
  34.         /// <param name="args">The args as string array.</param>
  35.         static void Main(string[] args)
  36.         {
  37.             var loggedIn = false;
  38.  
  39.                                  
  40.             Console.WriteLine("Welcome! Use #Exit to close this program.");
  41.  
  42.             // Initial input
  43.             Console.Write(prefixBeforeLogon);
  44.             var cCommand = GetCommand(Console.ReadLine());
  45.  
  46.             // Keep this program running untill user exits
  47.             while (cCommand != EnumCommand.Exit)
  48.             {
  49.                 switch (cCommand)
  50.                 {
  51.                        
  52.                     case EnumCommand.Invalid:
  53.                         UserCommand.Invalid();
  54.                         Console.WriteLine("Invalid command. Use #Exit to quit!");
  55.                         break;
  56.                     case EnumCommand.Login:
  57.                         UserCommand.Login();
  58.                         Console.Write("Username: ");
  59.                         if (Console.ReadLine() == uname)
  60.                         {
  61.                             Console.Write("Password: ");
  62.                         }
  63.                         else
  64.                         {
  65.                             Console.WriteLine("Invalid Username!");
  66.                         }
  67.                         if (Console.ReadLine() == pwd)
  68.                         {
  69.                             loggedIn = true;
  70.                            
  71.                            
  72.                         }
  73.                         else
  74.                         {
  75.                             Console.WriteLine("Incorrect Password!");
  76.                         }
  77.                         break;
  78.                     case EnumCommand.Logout:
  79.                         UserCommand.Logout();
  80.                         Console.WriteLine("You are logged out!");
  81.                         loggedIn = false;
  82.                         break;
  83.                     case EnumCommand.Username:
  84.                         UserCommand.Username();
  85.                         Console.WriteLine(loggedIn ? "Brendan" : "Please login first");
  86.                         break;
  87.                     default:
  88.                         Console.WriteLine("Program error!");
  89.                         break;
  90.                     case EnumCommand.Ping:
  91.                         UserCommand.Ping();
  92.                        // Console.Write("Enter IP/Hostname: ");
  93.                         PingExample.PingIP(Console.ReadLine());
  94.                         break;
  95.                     case EnumCommand.RDP:
  96.                         UserCommand.RDP();
  97.                         System.Diagnostics.Process.Start("C:\\Windows\\System32\\mstsc.exe");
  98.                         Console.WriteLine("Microsoft Remote Desktop Services Started!");
  99.                         break;
  100.  
  101.                     case EnumCommand.CLS:
  102.                         UserCommand.CLS();
  103.                         Console.Clear();
  104.                         break;
  105.  
  106.                 }
  107.                        
  108.  
  109.                 // Use of immidiate if - "statement ? if_true : if_false"
  110.                 Console.Write(loggedIn ? prefixAfterLogon : prefixBeforeLogon);
  111.  
  112.                 // Get next command
  113.                 cCommand = GetCommand(Console.ReadLine());
  114.             }
  115.         }
  116.  
  117.         /// <summary>
  118.         /// Returns the enum value of the user command.
  119.         /// </summary>
  120.         /// <param name="userInput">The user input as string.</param>
  121.         /// <returns></returns>
  122.         private static EnumCommand GetCommand(string userInput)
  123.         {
  124.             switch (userInput.ToUpperInvariant())
  125.             {
  126.                 case "#EXIT":
  127.                     return EnumCommand.Exit;
  128.                 case "#LOGIN":
  129.                     return EnumCommand.Login;
  130.                 case "#LOGOUT":
  131.                     return EnumCommand.Logout;
  132.                 case "$USERNAME":
  133.                     return EnumCommand.Username;
  134.                 case "$PING":
  135.                     return EnumCommand.Ping;
  136.                 case "$CLS":
  137.                     return EnumCommand.CLS;
  138.                 case "$RDP":
  139.                     return EnumCommand.RDP;
  140.                 default:
  141.                     return EnumCommand.Invalid;
  142.             }
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement