static void UserProgrammingGetFinchCommands(List <Command> commands) { Command command = Command.NONE; DisplayScreenHeader("Finch Robot Commands"); int CommandCount = 1; Console.WriteLine("\tList of availble commands"); Console.WriteLine(); Console.WriteLine("\t="); foreach (string CommandName in Enum.GetNames(typeof(Command))) { Console.WriteLine($"- {CommandName.ToLower()}"); if (CommandCount % 5 == 0) { Console.Write("-\n\t-"); } CommandCount++; } Console.WriteLine(); while (command != Command.DONE) { Console.WriteLine("\tEnter command:"); if (Enum.TryParse(Console.ReadLine().ToUpper(), out command)) { commands.Add(command); } else { Console.WriteLine("\t******************************************"); Console.WriteLine("\tPlease enter a command from the list above"); Console.WriteLine("\t******************************************"); } } DisplayMenuPrompt("User Programming"); }
/// <summary> /// 获取命令用法介绍信息 /// </summary> public void Load() { //不获取信息的排除字符串 List <string> exceptString = new List <string> (new string[] { "wmic", "eventquery", "pagefileconfig", "sc", "schtasks" }); const string exceptMessage = "【本程序暂无法显示该命令的用法提示 请自行运行命令行获取该命令的帮助】"; if (IsInternal) { if (exceptString.Contains(CommandName.ToLower())) { Usege = exceptMessage; return; } #region 内部命令用help获取 Process p = new Process { StartInfo = { FileName = "cmd.exe", // 设定程序名 Arguments = String.Format("/A /c help {0}", CommandName), UseShellExecute = false, // 关闭Shell的使用 RedirectStandardInput = true, // 重定向标准输入 RedirectStandardOutput = true, // 重定向标准输出 RedirectStandardError = true, //重定向错误输出 CreateNoWindow = true // 设置不显示窗口 } }; p.Start(); p.StandardInput.WriteLine("\r\n"); string result = p.StandardOutput.ReadToEnd(); p.Close(); string[] tmp = result.Split(new[] { "\r\n" }, StringSplitOptions.None); StringBuilder sb = new StringBuilder(); for (int i = 0; i < tmp.Length - 1; i++) { sb.Append(tmp[i]); sb.Append("\r\n"); } IsLoaded = true; Usege = sb.ToString(); #endregion } else { //外部命令用 /? 参数获取 } }
public bool ValidCommand() { var tmp = GlobalSettings.AvailableCmd.Where(a => a.ModuleName.ToLower() == ModuleName?.ToLower()).Select(a => a.ModuleName).ToList(); if (tmp.Count > 0) { ModuleName = tmp[0]; _moduleisvalid = true; var tmp2 = GlobalSettings.AvailableCmd.Where(a => a.ModuleName == ModuleName && a.CommandName.ToLower() == CommandName?.ToLower()).Select(a => a).ToList(); if (tmp2.Count > 0) { CommandName = tmp2[0].CommandName; _commandisvalid = true; Assembly = tmp2[0].Assembly; Attr = tmp2[0].Attr; } } return(_moduleisvalid && _commandisvalid); }