コード例 #1
0
        //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();
                }
            }
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
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)
                {
                }
            }
        }
コード例 #4
0
        /**
         * The main loop to be run as a thread. Generates a Kafka client that checks
         * for new messages COMMANDS and then calls the appropriete function from <THreadController>
         */
        public void CommandThread()
        {
            Console.WriteLine("CommandThread Start");
            Active = true;
            //Objs: Kafka Client
            //
            //consumer - the Kafka consumer that will connect to the Kafka server
            //topicp - what partition to start looking for messages in.
            var consumer = new ConsumerBuilder <string, string>(config).Build();
            var topicp   = new TopicPartition(topic, 0);

            consumer.Assign(topicp);

            while (Active)
            {
                try
                {
                    /**
                     * the result of <consumer> checking for nes messages
                     */
                    var consumeresult = consumer.Consume(canceltoken);

                    if (!consumeresult.IsPartitionEOF)
                    {
                        /*
                         * This section breaks down the message and then exicutes the appropriete command
                         */

                        //Vars: Commad Strings
                        //
                        //input - the raw message
                        //command - the part of the message that specifies what function to exicute
                        //parameter - the part of a message that may be passed into a function at exicution
                        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.addClient(parameter);
                        }
                        else if (command.Equals("Drop-Channel"))
                        {
                            controller.dropClient(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)
                {
                }
            }
        }