Beispiel #1
0
        static void Main(string[] args)
        {
            QueryRequestEngine qre = new QueryRequestEngine();
            string             reply;
            DBEngine <string, DBElement <string, List <string> > > db = new DBEngine <string, DBElement <string, List <string> > >();
            DBElement <string, List <string> > elem = new DBElement <string, List <string> >();

            elem.name     = "name0";
            elem.descr    = "descr0";
            elem.children = new List <string>()
            {
                "key0", "key1", "key2"
            };
            elem.timeStamp = DateTime.Now;
            elem.payload   = new List <string>()
            {
                "item1", "item2", "item3"
            };
            db.insert("key0", elem);

            elem          = new DBElement <string, List <string> >();
            elem.name     = "name1";
            elem.descr    = "descr1";
            elem.children = new List <string>()
            {
                "key3", "key4", "key5"
            };
            elem.timeStamp = DateTime.Now;
            elem.payload   = new List <string>()
            {
                "item4", "item5", "item6"
            };
            db.insert("key1", elem);

            qre.parseRequest(db, "write,value,key0", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,value,key1", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,children,key0", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,children,key1", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,pattern,k", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,pattern,a", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,string,descr0", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,string,descr1", out reply);
            Console.WriteLine(reply);
            qre.parseRequest(db, "write,interval,10/7/1999 12:00:00 AM", out reply);
            Console.WriteLine(reply);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            RequestEngine      re  = new RequestEngine();
            QueryRequestEngine qre = new QueryRequestEngine();
            DBEngine <string, DBElement <string, List <string> > > db = new DBEngine <string, DBElement <string, List <string> > >();

            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);

            Console.Title = "Server";
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");

            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
            //Sender sndr = new Sender();
            Receiver rcvr = new Receiver(srvr.port, srvr.address);

            // - serviceAction defines what the server does with received messages
            // - This serviceAction just announces incoming messages and echos them
            //   back to the sender.
            // - Note that demonstrates sender routing works if you run more than
            //   one client.
            HiResTimer hrt           = new HiResTimer();
            PerfTest   pt            = new PerfTest();
            Action     serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    msg = rcvr.getMessage();                       // note use of non-service method to deQ messages
                    //insert();
                    int    length = msg.content.IndexOf(",") + 1;
                    string from   = "";
                    if (msg.content != "connection start message")
                    {
                        from = msg.content.Substring(0, length);                         //figure out where the request came from
                    }
                    string[] msgList = msg.content.Split(',');
                    Console.Write("\n  Received message:");
                    Console.Write("\n  Request type is: {0}", from);                     //denotes where the request came from
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    Console.Write("\n  content is {0}\n", msg.content);
                    string reply = "";
                    //------------< do processing based on the request type >------------
                    if (from == "write,")
                    {
                        hrt.Start();
                        re.parseRequest(msg.content, out reply);
                        hrt.Stop();
                        pt.add(msgList[1], hrt.ElapsedMicroseconds);
                        msg.content = reply;
                    }
                    else if (from == "read,")
                    {
                        hrt.Start();
                        db = re.getDB();
                        qre.parseRequest(db, msg.content, out reply);
                        hrt.Stop();
                        pt.add(msgList[1], hrt.ElapsedMicroseconds);
                        msg.content = reply;
                    }
                    else if (from == "perf,")
                    {
                        reply       = pt.printTimesWpf(msgList[1]);
                        msg.content = reply;
                    }
                    if (msg.content == "connection start message")
                    {
                        continue;                         // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n");
                        Console.WriteLine(pt.printTimes());
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    // swap urls for outgoing message
                    Util.swapUrls(ref msg);

#if (TEST_WPFCLIENT)
                    /////////////////////////////////////////////////
                    // The statements below support testing the
                    // WpfClient as it receives a stream of messages
                    // - for each message received the Server
                    //   sends back 1000 messages
                    // Use the code to test the server

                    /*int count = 0;
                     * for (int i = 0; i < 1000; ++i)
                     * {
                     *      Message testMsg = new Message();
                     *      testMsg.toUrl = msg.toUrl;
                     *      testMsg.fromUrl = msg.fromUrl;
                     *      testMsg.content = String.Format("test message #{0}", ++count);
                     *      Console.Write("\n  sending testMsg: {0}", testMsg.content);
                     *      sndr.sendMessage(testMsg);
                     * }*/
                    Message testMsg = new Message();
                    testMsg.toUrl   = msg.toUrl;
                    testMsg.fromUrl = msg.fromUrl;
                    testMsg.content = String.Format("test message");
                    Console.Write("\n  sending testMsg: {0}", testMsg.content);
                    sndr.sendMessage(testMsg);
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
                    sndr.sendMessage(msg);
                    //re.db.show<string, DBElement<string, List<string>>, List<string>, string>();
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction);           // This serviceAction is asynchronous,
            }                                            // so the call doesn't block.
            Util.waitForUser();
        }