Esempio n. 1
0
 protected override void ProcessMessages()
 {
     while (true)
     {
         ServiceMessage msg = bq.deQ();
         Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
         msg.ShowMessage();
         Console.Write("\n  {0} Resource data:\n", msg.ResourceName);
         string[] tokens = msg.Contents.Split(';');
         string keywords = "";
         string[] tempstring = tokens[1].Split(',');
         foreach (string str in tempstring)
         {
             if (tokens[0] == "/T")
             {
                 if(tempstring.Length==1)
                     keywords = keywords + str;
                 else
                     keywords = keywords + str+"/T";
             }
             else
             {
                 if(tempstring.Length==1)
                     keywords = keywords + str;
                 else
                 keywords = keywords + str + "/M";
             }
         }
         string queryString = tokens[0] + keywords + tokens[2];
         List<string> filepattern = new List<string>();
         filepattern.Add("*.*");
         List<string> resultfilelist = new List<string>();
         if (msg.ResourceName == "search_text")
         {
             QueryProcessor QP = new QueryProcessor();    //calling the QueryProcessor module to process the tokens
             resultfilelist = QP.tokenAnalyzer(filepattern, @"..\..\DocumentVault\", queryString, tokens[3]);
         }
         string filestring = "";
         foreach (string str in resultfilelist)
         {
             filestring = filestring + str + ",";
         }
         ServiceMessage reply = ServiceMessage.MakeMessage("client-echo", "echo", filestring, "search_text");
         reply.TargetUrl = msg.SourceUrl;
         reply.SourceUrl = msg.TargetUrl;
         AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
         dispatcher.PostMessage(reply);
     }
 }
        //test stub function for testing the individual class
#if TESTING_QUERY_PROCESSOR

        public static void Main(string[] args)
        {
            List<string> pattern = new List<string>();
            pattern.Add("*.txt");
            string path = "../../testfiles";
            string querystring = "/Tvoid";
            QueryProcessor QP = new QueryProcessor();
            Console.Write("\nI m testing Query Processor");
            QP.tokenAnalyzer(pattern,path,querystring);
            //Console.Write("n  path = {0}\n  file pattern = {1}\n query string = {2}", path, pattern, queryString);
        }