public static ConsoleMessage ProcessShowMessage(ConsoleMessage consoleMessage) { ConsoleMessage consoleResponse = new ConsoleMessage(); consoleResponse.AgentId = consoleMessage.AgentId; consoleResponse.UserId = 1; consoleResponse.Type = "ShowMessage"; consoleResponse.Received = DateTime.UtcNow; List <string> availableShowCommands = new List <string>(); availableShowCommands.Add("MODULES"); availableShowCommands.Add("COMMANDS"); string showCommand = ""; string[] commandParts = consoleMessage.Content.Split(' '); if (commandParts.Length > 1) { if (availableShowCommands.Contains(commandParts[1].ToUpper())) { showCommand = commandParts[1].ToUpper(); } else { consoleResponse.Display = $"Unknown SHOW option {commandParts[1]}. Valid options are: {availableShowCommands.ToString()}"; } } else { consoleResponse.Display = $"Available SHOW commands are:"; foreach (string availableShowCommand in availableShowCommands) { consoleResponse.Display += $"\n * show {availableShowCommand.ToLower()}"; } } if (String.IsNullOrEmpty(showCommand)) { return(consoleResponse); } if (showCommand == "MODULES") { List <ShowModule> showModules = new List <ShowModule>(); foreach (Module module in AgentDetails.AvailableModules) { showModules.Add(new ShowModule(module, AgentDetails.IsModuleLoaded(module))); } consoleResponse.Display = JsonConvert.SerializeObject(showModules); } else if (showCommand == "COMMANDS") { List <ShowCommand> showCommands = new List <ShowCommand>(); List <Command> agentTypeCommands = _taskRepository.GetAgentTypeCommands(AgentDetails.AgentType.Id); foreach (Command command in agentTypeCommands) { showCommands.Add(new ShowCommand(command, AgentDetails.IsCommandAvailable(command))); } foreach (Module module in AgentDetails.AvailableModules) { List <Command> commands = _taskRepository.GetCommands(module.Id); foreach (Command command in commands) { showCommands.Add(new ShowCommand(command, AgentDetails.IsCommandAvailable(command))); } } consoleResponse.Display = JsonConvert.SerializeObject(showCommands); } return(consoleResponse); }