Пример #1
0
    static void Main(string[] args)
    {
      Util.verbose = false;
      Server srvr = new Server();
      srvr.ProcessCommandLine(args);
      
      Console.Title = "Server: " + srvr.port.ToString();
      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.
      
      if (rcvr.StartService())
      {
        rcvr.doService(doserviceAction(sndr, rcvr, srvr)); // This serviceAction is asynchronous,
      }
      // so the call doesn't block.
      Util.waitForUser(); 
    }
Пример #2
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);

            bool log_messages = true;

            string srv_win = "Server - " + srvr.port;

            Console.Title = srv_win;
            Console.Write(String.Format("\n  Starting CommService server listening on port {0}", srvr.port));
            Console.Write("\n ====================================================\n");
            //Console.WriteLine("Going to create a DB and add a single element to it:");


            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.


            Action serviceAction = srvr.define_server_receiveaction(rcvr, sndr, log_messages);

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

            Thread.Sleep(10000);
            Util.waitForUser();
        }
Пример #3
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();
            DBEngine <string, DBElement <string, List <string> > > testDict = new DBEngine <string, DBElement <string, List <string> > >();

            srvr.ProcessCommandLine(args);
            double timeTaken = 0, totalTime = 0, insCount = 0;

            srvr.printMessage(srvr);
            Sender        sndr          = new Sender(Util.makeUrl(srvr.address, srvr.port));
            Receiver      rcvr          = new Receiver(srvr.port, srvr.address);
            StringBuilder sb            = new StringBuilder();
            Action        serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    HiResTimer hiResTimer = new HiResTimer();
                    hiResTimer.Start();
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    srvr.printMessage(msg);
                    if (msg.content == "connection start message")
                    {
                        continue;                                            // don't send back start message
                    }
                    if (msg.fromUrl == "http://localhost:8080/CommService")
                    {
                        continue;
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has {0} finished\n", msg.fromUrl); continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer"); break;
                    }
                    msg.content = srvr.readOperations(testDict, msg);
                    Util.swapUrls(ref msg);                     // swap urls for outgoing message
#if (TEST_WPFCLIENT)
                    Message testMsg = new Message();
                    testMsg.toUrl   = msg.toUrl;
                    testMsg.fromUrl = msg.fromUrl;
                    testMsg.content = msg.content;
                    sndr.sendMessage(testMsg);
                    hiResTimer.Stop();
                    double diffTime = hiResTimer.ElapsedTimeSpan.TotalSeconds;
                    totalTime     = totalTime + diffTime;
                    timeTaken     = totalTime / (++insCount);
                    Console.Title = "Server client handling " + (insCount) + " requests";
                    srvr.printServerThroughput(timeTaken);
                    sndr.sendServerThroughput((1 / timeTaken));
#else
                    sndr.sendMessage(msg);
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }
            Util.waitForUser();                // so the call doesn't block.
        }
Пример #4
0
        /// <summary>
        /// Mains the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            DatabaseController dbController = new DatabaseController();

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

            srvr.ProcessCommandLine(args);
            double totalTime = 0;
            int    count     = 0;

            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));
            Receiver rcvr          = new Receiver(srvr.port, srvr.address);
            Action   serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    HiResTimer timer = new HiResTimer();
                    timer.Start();
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    srvr.displayReceivedMsg(msg);
                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client {0} has finished\n", msg.fromUrl);
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    if (msg.fromUrl == "http://localhost:8080/CommService")
                    {
                        continue;
                    }
                    var result = dbController.QueryDatabase(msg.content);
                    msg.content = "received " + msg.content + " from " + msg.fromUrl;
                    Util.swapUrls(ref msg);
                    Message testMsg = new Message {
                        content = result, fromUrl = msg.fromUrl, toUrl = msg.toUrl
                    };
                    srvr.displaySentMsg(msg, result);
                    sndr.sendMessage(testMsg);
                    timer.Stop();
                    sndr.SendServerThroughput(srvr.calculateThroughput(timer, ref totalTime, ++count));
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // so the call doesn't block.
            }
            Util.waitForUser();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Util.verbose = false;
            Server srvr = new Server();
            DBEngine<string, DBElement<string, List<string>>> testDict = new DBEngine<string, DBElement<string, List<string>>>();
            srvr.ProcessCommandLine(args);
            double timeTaken = 0, totalTime = 0, insCount = 0;
            srvr.printMessage(srvr);
            Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
            Receiver rcvr = new Receiver(srvr.port, srvr.address);
            StringBuilder sb = new StringBuilder();
            Action serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    HiResTimer hiResTimer = new HiResTimer();
                    hiResTimer.Start();
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages            
                    srvr.printMessage(msg);
                    if (msg.content == "connection start message") continue; // don't send back start message
                    if (msg.fromUrl == "http://localhost:8080/CommService") continue;
                    if (msg.content == "done")
                    { Console.Write("\n  client has {0} finished\n",msg.fromUrl); continue; }
                    if (msg.content == "closeServer")
                    { Console.Write("received closeServer"); break; }
                    msg.content = srvr.readOperations(testDict, msg);
                    Util.swapUrls(ref msg);                     // swap urls for outgoing message
#if (TEST_WPFCLIENT)
                    Message testMsg = new Message();
                    testMsg.toUrl = msg.toUrl;
                    testMsg.fromUrl = msg.fromUrl;
                    testMsg.content = msg.content;
                    sndr.sendMessage(testMsg);
                    hiResTimer.Stop();
                    double diffTime = hiResTimer.ElapsedTimeSpan.TotalSeconds;
                    totalTime = totalTime + diffTime;
                    timeTaken = totalTime / (++insCount);
                    Console.Title = "Server client handling " + (insCount) + " requests";
                    srvr.printServerThroughput(timeTaken);
                    sndr.sendServerThroughput((1 / timeTaken));
#else
                              sndr.sendMessage(msg);
#endif
                }
            };
            if (rcvr.StartService())
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            Util.waitForUser(); // so the call doesn't block.
        }
Пример #6
0
        //----< Main method. >-----
        static void Main(string[] args)
        {
            Util.verbose    = false;
            Util.verboseApp = true;
            Server srvr = new Server();

            srvr.ProcessCommandLine(args);
            srvr.preLoadData();

            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.

            Action serviceAction = () =>
            {
                Message    msg = null;
                HiResTimer hrt = new HiResTimer();
                while (true)
                {
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    if (Util.verbose)
                    {
                        Console.Write("\n  Received message:");
                        Console.Write("\n  sender is {0}", msg.fromUrl);
                        Console.Write("\n  content is {0}\n", msg.content);
                    }
                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    try
                    {
                        XDocument xdoc = XDocument.Parse(msg.content);

                        string operationCalled = identifyOperation(xdoc);
                        // swap urls for outgoing message
                        if (operationCalled == "add")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("add Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processAddMessage(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "delete")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("delete Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processDeleteMessage(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }

                        else if (operationCalled == "edit")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("Edit Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processEditMessage(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }

                        else if (operationCalled == "query1")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query1 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery1Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query2")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query2 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery2Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query3")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query3 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery3Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query4")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query4 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery4Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query5")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("query5 Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processQuery5Message(xdoc);
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "persist")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("persist Operation Called");
                            }
                            hrt.Start();
                            srvr.persistDatatToFile();
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            msg.content = "Persist operation performed.";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "restore")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("Restore Operation Called");
                            }
                            hrt.Start();
                            msg.content = srvr.processDataRestoreMessageRequest();
                            hrt.Stop();
                            Server.numMessages++;
                            Server.totalTime += hrt.ElapsedMicroseconds;
                            Server.avgTime    = srvr.getAvgTime(Server.totalTime, Server.numMessages);
                            Util.swapUrls(ref msg);
                            sndr.sendMessage(msg);
                            continue;
                        }
                        else if (operationCalled == "performance")
                        {
                            if (Util.verboseApp)
                            {
                                Console.WriteLine("performance Operation Called");
                            }
                            Message msgToWpf1 = new Message();
                            msgToWpf1.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                            msgToWpf1.toUrl   = "http://localhost:8089/CommService";
                            msgToWpf1.content = srvr.createPerformanceMessageForWPF(xdoc, avgTime.ToString());
                            sndr.sendMessage(msgToWpf1);
                            continue;
                        }
                    }

                    catch (Exception e)
                    {
                        Console.WriteLine("Catch " + e.StackTrace + "\n");
                    }


#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
                    //
                    int count = 0;
                    for (int i = 0; i < 2; ++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);
                    }
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
                    // sndr.sendMessage(msg);
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.
            Util.waitForUser();
        }
Пример #7
0
        static void Main(string[] args)
        {
            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.

            Action serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    msg = rcvr.getMessage(); // note use of non-service method to deQ messages
                    Console.Write("\n  Received message:");
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    Console.Write("\n  content is {0}\n", msg.content);

                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n");
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    msg.content = "received " + msg.content + " from " + msg.fromUrl;

                    // 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
                    //
                    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);
                    }
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
                    sndr.sendMessage(msg);
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.
            Util.waitForUser();
        }
Пример #8
0
        static void Main(string[] args)
        {
            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));

            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.

            Action serviceAction = () =>
            {
                Message msg = null;
                while (true)
                {
                    msg = rcvr.getMessage();   // note use of non-service method to deQ messages
                    Console.Write("\n  Received message:");
                    Console.Write("\n  sender is {0}", msg.fromUrl);
                    //Console.Write("\n  content is {0}\n", msg.content);

                    if (msg.content == "connection start message")
                    {
                        continue; // don't send back start message
                    }
                    if (msg.content == "done")
                    {
                        Console.Write("\n  client has finished\n");
                        continue;
                    }
                    if (msg.content == "closeServer")
                    {
                        Console.Write("received closeServer");
                        break;
                    }
                    if (msg.content.Contains("Writer"))
                    {
                        int     avg      = srvr.Ttime.Sum() / srvr.Ttime.Count();
                        string  lat      = string.Join(null, System.Text.RegularExpressions.Regex.Split(msg.content, "[^\\d]"));
                        Message msgToWpf = new Message();
                        msgToWpf.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf.content = msg.content + " microseconds for Client: " + msg.fromUrl.ToString();
                        sndr.sendMessage(msgToWpf);
                        Message msgToWpf1 = new Message();
                        msgToWpf1.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf1.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf1.content = "Server ThroughPut(Avg Time) for " + srvr.Ttime.Count().ToString() + " Write Operations = " + avg.ToString() + " microseconds";
                        sndr.sendMessage(msgToWpf1);
                        continue;
                    }
                    if (msg.content.Contains("Reader"))
                    {
                        int     avg1     = srvr.Ttime1.Sum() / srvr.Ttime1.Count();
                        string  lat      = string.Join(null, System.Text.RegularExpressions.Regex.Split(msg.content, "[^\\d]"));
                        Message msgToWpf = new Message();
                        msgToWpf.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf.content = msg.content + " microseconds for Client: " + msg.fromUrl.ToString();
                        sndr.sendMessage(msgToWpf);
                        Message msgToWpf1 = new Message();
                        msgToWpf1.fromUrl = Util.makeUrl(srvr.address, srvr.port);
                        msgToWpf1.toUrl   = Util.makeUrl("localhost", "8089");
                        msgToWpf1.content = "Server ThroughPut(Avg Time) for " + srvr.Ttime1.Count().ToString() + " Read Operations = " + avg1.ToString() + " microseconds";
                        sndr.sendMessage(msgToWpf1);
                        continue;
                    }
                    try
                    {
                        XDocument xdoc            = XDocument.Parse(msg.content);
                        string    operationCalled = getOperationType(xdoc);
                        if (operationCalled == "add")
                        {
                            Console.WriteLine("\nAdd Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processAddMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "delete")
                        {
                            Console.WriteLine("\nDelete Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processDelMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }

                        else if (operationCalled == "edit")
                        {
                            Console.WriteLine("\nEdit Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processEditMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }

                        else if (operationCalled == "query1")
                        {
                            Console.WriteLine("\nQuery1 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery1(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "query2")
                        {
                            Console.WriteLine("\nQuery2 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery2(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                            Util.swapUrls(ref msg);
                            msg.content = "-----Query2 operation performed-----";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query3")
                        {
                            Console.WriteLine("\nQuery3 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery3(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                            Util.swapUrls(ref msg);
                            msg.content = "-----Query3 operation performed-----";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "query4")
                        {
                            Console.WriteLine("\nQuery4 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery4(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "query5")
                        {
                            Console.WriteLine("\nQuery5 Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processQuery5(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime1.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                            Util.swapUrls(ref msg);
                            msg.content = "-----Query5 operation performed-----";
                            sndr.sendMessage(msg);
                        }
                        else if (operationCalled == "persist")
                        {
                            Console.WriteLine("\nPersist Operation Called");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processPersistMsg(xdoc, sndr, msg);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                        else if (operationCalled == "augment")
                        {
                            Console.WriteLine("\nAugment Operation Called\n");
                            HiResTimer hrt = new HiResTimer();
                            hrt.Start();
                            srvr.processAugmentedMsg(xdoc, sndr, msg, srvr);
                            hrt.Stop();
                            srvr.Ttime.Add(Convert.ToInt32(hrt.ElapsedMicroseconds));
                        }
                    }

                    catch { }



#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
                    //
                    int count = 0;
                    for (int i = 0; i < 2; ++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);
                    }
#else
                    /////////////////////////////////////////////////
                    // Use the statement below for normal operation
#endif
                }
            };

            if (rcvr.StartService())
            {
                rcvr.doService(serviceAction); // This serviceAction is asynchronous,
            }                                  // so the call doesn't block.
            Util.waitForUser();
        }
Пример #9
0
 static void Main(string[] args)
 {
  try
     {
         Util.verbose = false;
         Server srvr = new Server();
         srvr.ProcessCommandLine(args);
         Console.Title = "Server";
         Console.Write(String.Format("\nStarting CommService server listening on port {0}", srvr.port));
         Console.WriteLine("\nServer Address is {0}", Util.makeUrl(srvr.address, srvr.port));
         Console.Write("\n ====================================================\n");
         Sender sndr = new Sender(Util.makeUrl(srvr.address, srvr.port));
         Receiver rcvr = new Receiver(srvr.port, srvr.address);
         Action serviceAction = DefineServiceAction(srvr, sndr, rcvr);
         if (rcvr.StartService())
         {
             rcvr.doService(serviceAction); // This serviceAction is asynchronous, // so the call doesn't block.
         }
         Util.waitForUser();
     }
     catch (CustomException ex)
     {
         Console.WriteLine("Error occured in Server.cs{0}", ex);
     }
 }