//-------------< test stub >----------- static void Main(string[] args) { HiResTimer hrt = new HiResTimer(); PerfTest pt = new PerfTest(); for (int j = 0; j < 10; j++) { hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("add", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("edit", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("delete", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("persist", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("restore", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("value", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("children", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("pattern", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("string", hrt.ElapsedMicroseconds); } hrt.Start(); for (int i = 0; i < 10; i++) { hrt.Stop(); pt.add("interval", hrt.ElapsedMicroseconds); } } pt.printTimes(); }
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(); }