//Function: Main //The main method, contains an input loop for console interactivity static void Main(string[] args) { bool active = true; //This bool keeps the loop going until the user chooses to exit controller = new ThreadController(); //This class will handle all of the functionality of the Application while (active) { var input = Console.ReadLine(); string command; string parameter; if (input.Contains(" "))//this code block seperates commands with multiple qords into a command and a parameter { command = input.Substring(0, input.IndexOf(" ")).Trim(); parameter = input.Substring(input.IndexOf(" "), input.Length - command.Length).Trim(); } else { command = input; parameter = ""; } Console.WriteLine("COMMAND----------> " + input); if (command.Equals("Add-Channel")) { controller.addClient(parameter); } else if (command.Equals("Drop-Channel")) { controller.dropClient(parameter); } else if (command.Equals("List-Channels")) { Console.WriteLine("The active threads are:"); controller.listThreads(); } else if (command.Equals("Count")) { Console.WriteLine("The message queue has " + controller.queueSize() + " messages in it right now"); } else if (command.Equals("Exit")) { controller.exit(); active = false; } else if (command.Equals("Blacklist")) { controller.listBlacklist(); } } }
static void Main(string[] args) { bool active = true; controller = new ThreadController(); while (active) { var input = Console.ReadLine(); string command; string parameter; if (input.Contains(" ")) { command = input.Substring(0, input.IndexOf(" ")).Trim(); parameter = input.Substring(input.IndexOf(" "), input.Length - command.Length).Trim(); } else { command = input; parameter = ""; } Console.WriteLine("COMMAND----------> " + input); if (command.Equals("Add-Channel")) { controller.addThread(parameter); } else if (command.Equals("Drop-Channel")) { controller.dropThread(parameter); } else if (command.Equals("List-Channels")) { Console.WriteLine("The active threads are:"); controller.listThreads(); } else if (command.Equals("Count")) { Console.WriteLine("The message queue has " + controller.queueSize() + " messages in it right now"); } else if (command.Equals("Exit")) { controller.exit(); active = false; } else if (command.Equals("Blacklist")) { controller.listBlacklist(); } } }
public CommandConsumer(ThreadController controller, ref HashSet <string> blacklist) { this.blacklist = blacklist; this.controller = controller; config = new ConsumerConfig { BootstrapServers = server, GroupId = Guid.NewGuid().ToString(), EnableAutoCommit = true, StatisticsIntervalMs = 5000, SessionTimeoutMs = 6000, AutoOffsetReset = AutoOffsetReset.Latest, EnablePartitionEof = true }; source = new CancellationTokenSource(); canceltoken = source.Token; }