static void Main(string[] args)
        {
            Console.Write("{0}{1}",
                          "\n  Time Parsing Operations ",
                          "\n =========================\n"
                          );

            OpTimer ot = new OpTimer();

            ot.Verbose = false;
            string fileName = "../../Test.cs";

            ot.ParseFile(fileName);

            HiResTimer hrt = new HiResTimer();

            hrt.Start();
            int N = 1000;

            for (int i = 0; i < N; ++i)
            {
                ot.HashLookUp("class");
            }
            hrt.Stop();
            ulong lookUpTime = hrt.ElapsedMicroseconds;

            Console.Write("\n   {0} lookups took {1} microseconds", N, lookUpTime);
            Console.Write("\n\n");
            ot.showTable();
            Console.Write("\n\n");
        }
        //
        //----< parse file into identifiers and store in Hashtable >-------

        public void ParseFile(string fileName)
        {
            HiResTimer total = new HiResTimer();
            HiResTimer open  = new HiResTimer();
            HiResTimer parse = new HiResTimer();

            try      {
                total.Start();
                open.Start();
                StreamReader fs = new StreamReader(fileName);
                open.Stop();
                openTime = open.ElapsedMicroseconds;
                parse.Start();
                int    size = 0;
                string line;
                while ((line = fs.ReadLine()) != null)
                {
                    string[] tokens = line.Split();
                    foreach (string token in tokens)
                    {
                        if (token == "\n" | token.Length == 0)
                        {
                            continue;
                        }
                        if (Verbose)
                        {
                            Console.Write("\n    {0}", token);
                        }
                        string tok, compositeToken = token;
                        while (compositeToken != "")
                        {
                            tok = extractIdent(ref compositeToken);
                            if (tok == "")
                            {
                                continue;
                            }
                            if (Verbose)
                            {
                                Console.Write("\n      {0}", tok);
                            }
                            if (table.Contains(tok))
                            {
                                table[tok] = 1 + (int)table[tok];
                            }
                            else
                            {
                                table[tok] = 1;
                                size      += tok.Length;
                            }
                        }
                    }
                }
                parse.Stop();
                parseTime = parse.ElapsedMicroseconds;
                total.Stop();
                totalTime = total.ElapsedMicroseconds;
                Console.Write("\n   Open time: {0} microsec", openTime);
                Console.Write("\n  Parse time: {0} microsec", parseTime);
                Console.Write("\n  total time: {0} microsec", totalTime);
                Console.Write("\n   Hash size: {0} bytes", size);
            }
            catch      {
                Console.Write("\n  Could not open file \"{0}\"\n\n", fileName);
            }
        }
Esempio n. 3
0
        //Main function parses and sends the messages to server//
        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);
            Action   serviceAction = () => {
                Message msg = null;
                DBEngine <int, DBElement <int, string> > dbserver = new DBEngine <int, DBElement <int, string> >(); //new DBEngine
                QueryEngine QE    = new QueryEngine();
                HiResTimer  timer = new HiResTimer();                                                               //new object for timer
                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;
                    }
                    timer.Start();                  //start timer
                    XElement  insertelem = XElement.Parse(msg.content);
                    XElement  res        = new XElement("result", "not found");
                    processor rdbserver  = new processor();
                    Console.WriteLine("\n----------write client operations----------");
                    Console.WriteLine("\n");
                    //----------select the required method to perform operations------------//
                    if (insertelem.Element("Type").Value.Equals("Insert"))
                    {
                        res = rdbserver.insert(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("Delete"))
                    {
                        res = rdbserver.Delete(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("EditName"))
                    {
                        res = rdbserver.EditName(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("getvalue"))
                    {
                        res = rdbserver.getvalue(insertelem, dbserver, QE);
                    }
                    else if (insertelem.Element("Type").Value.Equals("EditDescr"))
                    {
                        res = rdbserver.editdescr(insertelem, dbserver);
                    }
                    else if (insertelem.Element("Type").Value.Equals("getchildren"))
                    {
                        res = rdbserver.getchildren(insertelem, dbserver, QE);
                    }
                    else if (insertelem.Element("Type").Value.Equals("Persist"))
                    {
                        res = rdbserver.persistdb(insertelem, dbserver);
                    }
                    else
                    {
                        Console.Write("   operation failed   ");
                    }
                    Console.WriteLine("\n-------------server response----------");
                    XElement response = new XElement("resonse");
                    response.Add(res);
                    timer.Stop();              //stop timer
                    Console.WriteLine("the time taken for operation is {0}", timer.ElapsedMicroseconds + " MicroSeconds ");
                    srvr.send_wpf_msg(timer.ElapsedMicroseconds, sndr);
                    Util.swapUrls(ref msg);
                    msg.content = response.ToString();
                    sndr.sendMessage(msg);             //sending message
                }
            };

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