コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
        public void CommandThread()
        {
            Console.WriteLine("CommandThread Start");
            Active = true;
            var consumer = new ConsumerBuilder <string, string>(config).Build();
            var topicp   = new TopicPartition(topic, 0);

            consumer.Assign(topicp);

            while (Active)
            {
                try
                {
                    var consumeresult = consumer.Consume(canceltoken);

                    if (!consumeresult.IsPartitionEOF)
                    {
                        var    input = consumeresult.Value;
                        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("SCPList-Channels"))
                        {
                            Console.WriteLine("The active threads are:");
                            controller.listThreads();
                        }
                        else if (command.Equals("SCPCount"))
                        {
                            Console.WriteLine("The message queue has " + controller.queueSize() + " messages in it right now");
                        }
                        else if (command.Equals("SCPExit") || command.Equals("System-Shutdown"))
                        {
                            controller.exit();
                            Active = false;
                            source.Cancel();
                        }
                        else if (command.Equals("SCPBlacklist"))
                        {
                            blacklist.Add(parameter);
                        }
                        else if (command.Equals("SCPUnblacklist"))
                        {
                            blacklist.Remove(parameter);
                        }
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                }
                catch (System.OperationCanceledException e)
                {
                }
            }
        }