コード例 #1
0
        //Todo: Comments needed:
        public IRespondStrategy GetStrategy(string received)
        {
            IRespondStrategy strategy = null;

            string[] splitter = new string[] { "\r\n" };
            string[] StrArr = received.Split(splitter, StringSplitOptions.None);
            string order = StrArr[0];

            if (TCPDebug.DEBUG)
            {
                Console.WriteLine("Order: " + order);
                Console.WriteLine(received);
            }

            string[] eq = order.Split(' ');

            //Todo: Should handle subscribe.
            //Todo: Also, its a problem that startegy is not set at invalid input
            switch (eq[0])
            {
                case "GET":
                    strategy = new GETResponder(eq[1]);
                    break;
                case "POST":
                    strategy = new POSTResponder(received);
                    break;
                case "SUBSCRIBE":
                    Console.WriteLine("Someone subscribed");
                    break;
                default:
                    Console.WriteLine("Error in Switch-case:");
                    Console.WriteLine(order);
                    break;
            }

            return strategy;
        }
コード例 #2
0
        /// <summary>
        /// Function returning the strategy, based on order type.
        /// </summary>
        /// <param name="received">The entire HTTP message sent with the request</param>
        /// <param name="BasePath">Path to directory containing the desc.xml files for descriptions</param>
        /// <param name="pub">The instance of publisher containing all subscribers, used for eventing</param>
        /// <returns></returns>
        public IRespondStrategy GetStrategy(string received, string BasePath, Publisher pub)
        {
            IRespondStrategy strategy = null;

            string[] splitter = new string[] { "\r\n" };
            string[] StrArr = received.Split(splitter, StringSplitOptions.None);
            string order = StrArr[0];

            if (TCPDebug.DEBUG)
            {
                Console.WriteLine("Order: " + order);
                Console.WriteLine(received);
            }

            string[] eq = order.Split(' ');

            switch (eq[0])
            {
                case "GET":
                    strategy = new GETResponder(BasePath + eq[1]);
                    break;
                case "POST":
                    strategy = new POSTResponder(received);
                    break;
                case "SUBSCRIBE":

                    strategy = new SubscribeResponder(pub,received);
                    break;
                default:
                    Console.WriteLine("Error in Switch-case:");
                    Console.WriteLine (eq[0]);
                    Console.WriteLine(order);
                    break;
            }

            return strategy;
        }