|
| 1 | +using Microsoft.Extensions.Options; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +namespace CLARiNET |
| 9 | +{ |
| 10 | + public static class CommandLineCommand |
| 11 | + { |
| 12 | + public static string CommandGet(string command) |
| 13 | + { |
| 14 | + if (String.IsNullOrEmpty(command)) |
| 15 | + { |
| 16 | + string[] commands = Commands.COMMAND_LIST.Split("\n"); |
| 17 | + PrintCommand(commands); |
| 18 | + Console.WriteLine("Enter the number that identifies the CLARiNET Command (1 - " + commands.Length + "):\n"); |
| 19 | + command = Console.ReadLine().Trim().ToUpper(); |
| 20 | + Console.WriteLine(""); |
| 21 | + } |
| 22 | + return command; |
| 23 | + } |
| 24 | + |
| 25 | + public static string CommandValidate(string command) |
| 26 | + { |
| 27 | + // Ensure Command is uppercase. |
| 28 | + if (command != null) |
| 29 | + { |
| 30 | + command = command.Trim().ToUpper(); |
| 31 | + } |
| 32 | + |
| 33 | + int ndx = 0; |
| 34 | + if (int.TryParse(command, out ndx)) |
| 35 | + { |
| 36 | + string[] commands = Commands.COMMAND_LIST.Split("\n"); |
| 37 | + command = commands[ndx - 1]; |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + // Check for valid commands |
| 42 | + switch (command.ToEnum<Command>()) |
| 43 | + { |
| 44 | + case Command.CLAR_UPLOAD: |
| 45 | + case Command.CLAR_DOWNLOAD: |
| 46 | + case Command.DRIVE_UPLOAD: |
| 47 | + case Command.DRIVE_TRASH: |
| 48 | + case Command.PHOTO_DOWNLOAD: |
| 49 | + case Command.PHOTO_UPLOAD: |
| 50 | + case Command.DOCUMENT_UPLOAD: |
| 51 | + case Command.CANDIDATE_ATTACHMENT_UPLOAD: |
| 52 | + break; |
| 53 | + default: |
| 54 | + throw new Exception("Invalid command. Please use --help for a list of valid commands."); |
| 55 | + } |
| 56 | + Console.WriteLine("\n\nCommand: " + command + "\n"); |
| 57 | + |
| 58 | + return command; |
| 59 | + } |
| 60 | + |
| 61 | + public static void PrintCommand(string[] commands) |
| 62 | + { |
| 63 | + string[] commandName = new string[3]; |
| 64 | + string colFormat = "{0,-35} {1,-35} {2,-35}\n"; |
| 65 | + |
| 66 | + Console.WriteLine("-- Commands --\n"); |
| 67 | + for (int ndx = 0; ndx < commands.Length; ndx++) |
| 68 | + { |
| 69 | + if (ndx > 0 && ndx % 3 == 0) |
| 70 | + { |
| 71 | + Console.Write(colFormat, commandName[0], commandName[1], commandName[2]); |
| 72 | + commandName = new string[3]; |
| 73 | + } |
| 74 | + if (commandName[0] == null) |
| 75 | + { |
| 76 | + commandName[0] = ndx + 1 + ") " + commands[ndx]; |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + if (commandName[1] == null) |
| 81 | + { |
| 82 | + commandName[1] = ndx + 1 + ") " + commands[ndx]; |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + commandName[2] = ndx + 1 + ") " + commands[ndx]; |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + if (commandName[0] != null) |
| 91 | + { |
| 92 | + Console.Write(colFormat, commandName[0], commandName[1], commandName[2]); |
| 93 | + } |
| 94 | + Console.WriteLine("\n"); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments