Beispiel #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  Echo processing completed\n");
         if (msg.Contents == "quit")
         {
             break;
         }
         else if (msg.ResourceName == "catagories")
         {
             Category       c     = new Category();
             List <string>  cat   = c.getCat();
             ServiceMessage reply = ServiceMessage.MakeCategoryMessage("client-echo", "echo", cat, "reply from categories");
             reply.TargetUrl = msg.SourceUrl;
             reply.SourceUrl = msg.TargetUrl;
             AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
             dispatcher.PostMessage(reply);
             break;
         }
     }
 }
        //----< get and process message from Server>----------------
        protected override void ProcessMessages()
        {
            while (true)
            {
                ServiceMessage msg = bq.deQ();

                if (msg.Contents == "quit")
                {
                    msg.TargetCommunicator = "dispatcher";
                    AbstractMessageDispatcher.GetInstance().PostMessage(msg);
                    break;
                }
                //////////////////////////////////////////////////////////////
                // show message that server finished the mapping process
                if (msg.ResourceName == "mapping finished")
                {
                    MessageBox.Show("Mapping fishined!");
                }
                //////////////////////////////////////////////////////////////
                // receive message that contains the parents of current file
                if (msg.ResourceName == "found parents")
                {
                    mainWin.dispatcher.Invoke(
                        new Action <string>(mainWin.showParents),
                        System.Windows.Threading.DispatcherPriority.Background,
                        new string[] { msg.Contents }
                        );
                }
            }
        }
Beispiel #3
0
            //initiates the FileContentRtr to get all info of a text file
            protected override void ProcessMessages()
            {
                while (true)
                {
                    ServiceMessage msg = bq.deQ();

                    FileContentRtr filecontent = new FileContentRtr();
                    //string message =
                    List <List <string> > result = filecontent.getContent(msg.filename);

                    /*  var appDomain = AppDomain.CurrentDomain;
                     * string temp1 = appDomain.BaseDirectory;
                     * Directory.SetCurrentDirectory(temp1);*/
                    //Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                    //msg.ShowMessage();
                    //Console.Write("\n  Query processing is an exercise for students\n");
                    if (msg.Contents == "quit")
                    {
                        break;
                    }
                    ServiceMessage reply = ServiceMessage.MakeQueryMessage("client-echo", "filecontent", result, "reply from filecontent");
                    reply.TargetUrl = msg.SourceUrl;
                    reply.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply);
                }
            }
Beispiel #4
0
        //----< get and process message from client>----------------
        // find text files and xml files which contain tags or strings
        // send xml file content back
        protected override void ProcessMessages()
        {
            while (true)
            {
                List <string>  foundFiles = new List <string>();
                ServiceMessage msg        = bq.deQ();
                Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                QueryProcessing qpro = new QueryProcessing();
                foundFiles = qpro.queryProcessing(msg);

                //Console.Write("\n  Query processing is an exercise for students\n");
                if (msg.Contents == "quit")
                {
                    break;
                }
                foreach (string file in foundFiles)
                {
                    XDocument doc = XDocument.Load(file);

                    string fileContent = doc.ToString();

                    ServiceMessage reply = ServiceMessage.MakeMessage("client-query", "ServiceServer", fileContent);
                    reply.TargetUrl = msg.SourceUrl;
                    reply.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply);
                }
            }
        }
        //----< Create service and get reference to dispatcher >---------

        public CommService()
        {
            Name       = "CommService";
            dispatcher = AbstractMessageDispatcher.GetInstance();

            /*
             *  A class that derives from AbstractMessageDispatcher must
             *  be created before calling GetInstance().  The service
             *  Host must do that.
             */
        }
Beispiel #6
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  Navigation processing is an exercise for students\n");
         if (msg.Contents == "quit")
         {
             break;
         }
         ServiceMessage reply = ServiceMessage.MakeMessage("client-echo", "nav", "reply from nav");
         reply.TargetUrl = msg.SourceUrl;
         reply.SourceUrl = msg.TargetUrl;
         AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
         dispatcher.PostMessage(reply);
     }
 }
Beispiel #7
0
            //initiates the TextQueryHandler to get the text files that belong to a category
            protected override void ProcessMessages()
            {
                while (true)
                {
                    ServiceMessage msg = bq.deQ();
                    Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                    msg.ShowMessage();
                    TextQueryHandler textqueryhandler = new TextQueryHandler();

                    /*List<List<string>> dummy = new List<List<string>>();
                     * dummy.Add(msg.category);*/
                    List <string>  textfiles = textqueryhandler.getTextFiles(msg.category);
                    ServiceMessage reply     = ServiceMessage.MakeTextFilesMessage("client-echo", "textfiles", textfiles, "reply from textfiles");
                    reply.TargetUrl = msg.SourceUrl;
                    reply.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply);
                    //break;
                }
            }
Beispiel #8
0
        //initiates the QueryHandler for metadata query processing and text query processing
        protected override void ProcessMessages()
        {
            while (true)
            {
                ServiceMessage msg = bq.deQ();

                if (!msg.ResourceName.Equals("textquery"))
                {
                    QueryHandler          queryhandler = new QueryHandler();
                    List <List <string> > results      = queryhandler.MetaQuery(msg.nlist);

                    Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                    msg.ShowMessage();
                    //Console.Write("\n  Query processing is an exercise for students\n");
                    if (msg.Contents == "quit")
                    {
                        break;
                    }
                    ServiceMessage reply = ServiceMessage.MakeQueryMessage("client-echo", "query", results, "reply from query");
                    reply.TargetUrl = msg.SourceUrl;
                    reply.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply);
                }

                else
                {
                    TextQueryHandler      textqueryhandler = new TextQueryHandler();
                    List <List <string> > results          = textqueryhandler.textQuery(msg.nlist);
                    if (msg.Contents == "quit")
                    {
                        break;
                    }
                    ServiceMessage reply = ServiceMessage.MakeQueryMessage("client-echo", "query", results, "reply from tquery");
                    reply.TargetUrl = msg.SourceUrl;
                    reply.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply);
                }
            }
        }
Beispiel #9
0
        //----< get and process message from client>----------------
        protected override void ProcessMessages()
        {
            MappingTool mt = new MappingTool();

            while (true)
            {
                ServiceMessage msg = bq.deQ();
                Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                //msg.ShowMessage();
                //Console.Write("\n  Navigation processing is an exercise for students\n");
                if (msg.Contents == "quit")
                {
                    break;
                }
                ///////////////////////////////////////////////////////////////////////////////////////
                // find files relationship and construct parents and child map when client
                // connect with server
                if (msg.Contents == "mapping")
                {
                    mt.Mapping();
                    ServiceMessage reply1 = ServiceMessage.MakeMessage("client-nav", "nav", "mapping finished", "mapping finished");
                    reply1.TargetUrl = msg.SourceUrl;
                    reply1.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply1);
                }
                //////////////////////////////////////////////////////////////////////////////////////
                // client send current file name to server, server find the parents and children
                // then reply
                if (msg.ResourceName == "file relationship")
                {
                    string parents = null;
                    parents = mt.findParents(msg.Contents);
                    ServiceMessage reply2 = ServiceMessage.MakeMessage("client-nav", "nav", parents, "found parents");
                    reply2.TargetUrl = msg.SourceUrl;
                    reply2.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply2);
                }
            }
        }
        //----< get and process message from server>----------------
        protected override void ProcessMessages()
        {
            while (true)
            {
                ServiceMessage msg = bq.deQ();
                /////////////////////////////////////////////////////////////////
                // receive query results and show in UI
                mainWin.dispatcher.Invoke(
                    new Action <string>(mainWin.AddQueryResult),
                    System.Windows.Threading.DispatcherPriority.Background,
                    new string[] { msg.Contents }
                    );

                if (msg.Contents == "quit")
                {
                    msg.TargetCommunicator = "dispatcher";
                    AbstractMessageDispatcher.GetInstance().PostMessage(msg);
                    break;
                }
            }
        }
Beispiel #11
0
        //not using this
        public void getFileContent(ServiceMessage msg)
        {
            Server s = new Server();
            //s.GetFileContent(msg);
            string file      = msg.Contents;
            long   blockSize = 512;

            string filename = @"..\\DocumentVault\\" + file;

            try
            {
                FileStream fs;
                fs = File.Open(filename, FileMode.Open, FileAccess.Read);
                int bytesRead = 0;
                while (true)
                {
                    long remainder = (int)(fs.Length - fs.Position);
                    if (remainder == 0)
                    {
                        break;
                    }
                    long   size  = Math.Min(blockSize, remainder);
                    byte[] block = new byte[size];
                    bytesRead = fs.Read(block, 0, block.Length);
                    ServiceMessage msg4 =
                        ServiceMessage.MakeMessage("client-echo", "file_Comm", System.Text.Encoding.Default.GetString(block), "FileContent");
                    msg4.TargetUrl = msg.SourceUrl;
                    msg4.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher1 = AbstractMessageDispatcher.GetInstance();
                    dispatcher1.PostMessage(msg4);
                }
                fs.Flush();
                fs.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #12
0
        protected override void ProcessMessages()
        {
            while (true)
            {
                ServiceMessage msg = bq.deQ();
                Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                msg.ShowMessage();
                if (msg.Contents == "quit")
                {
                    if (Verbose)
                    {
                        Console.Write("\n  Echo shutting down");
                    }

                    // shut down dispatcher

                    msg.TargetCommunicator = "dispatcher";
                    AbstractMessageDispatcher.GetInstance().PostMessage(msg);
                    break;
                }
            }
        }
Beispiel #13
0
            //initiates the EditMetadataHandler for editing metadata
            protected override void ProcessMessages()
            {
                while (true)
                {
                    ServiceMessage msg = bq.deQ();

                    EditMetadataHandler queryhandler = new EditMetadataHandler();
                    //string message =
                    queryhandler.editMetadata(msg.tag);

                    //Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                    //msg.ShowMessage();
                    //Console.Write("\n  Query processing is an exercise for students\n");
                    if (msg.Contents == "quit")
                    {
                        break;
                    }
                    ServiceMessage reply = ServiceMessage.MakeMessage("client-echo", "query", " ", "reply from editmetadata");
                    reply.TargetUrl = msg.SourceUrl;
                    reply.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                    dispatcher.PostMessage(reply);
                }
            }
 //----< get and process message from server>----------------
 protected override void ProcessMessages()
 {
     while (true)
     {
         ServiceMessage msg = bq.deQ();
         //////////////////////////////////////////////////////////////////////////////////
         // receive message which contains category information
         // then show in UI
         if (msg.ResourceName == "Categories")
         {
             mainWin.dispatcher.Invoke(
                 new Action <string>(mainWin.AddCategory),
                 System.Windows.Threading.DispatcherPriority.Background,
                 new string[] { msg.Contents }
                 );
             string message = "Connection successful!";
             mainWin.dispatcher.Invoke(
                 new Action <string>(mainWin.connected),
                 System.Windows.Threading.DispatcherPriority.Background,
                 new string[] { message }
                 );
         }
         ///////////////////////////////////////////////////////////////////////////////////
         // receive message which contains files information in specified category
         // then show in UI
         if (msg.ResourceName == "files found in category")
         {
             mainWin.dispatcher.Invoke(
                 new Action <string>(mainWin.AddFile),
                 System.Windows.Threading.DispatcherPriority.Background,
                 new string[] { msg.Contents }
                 );
         }
         ////////////////////////////////////////////////////////////////////////////////////
         // receive message which contains textfile content
         // then show in UI
         if (msg.ResourceName == "textfile")
         {
             mainWin.dispatcher.Invoke(
                 new Action <string>(mainWin.showText),
                 System.Windows.Threading.DispatcherPriority.Background,
                 new string[] { msg.Contents }
                 );
         }
         ////////////////////////////////////////////////////////////////////////////////////
         // receive message which contains xmlfile content
         // then show in UI
         if (msg.ResourceName == "xmlfile")
         {
             mainWin.dispatcher.Invoke(
                 new Action <string>(mainWin.showXml),
                 System.Windows.Threading.DispatcherPriority.Background,
                 new string[] { msg.Contents }
                 );
             mainWin.dispatcher.Invoke(
                 new Action <string>(mainWin.showChildren),
                 System.Windows.Threading.DispatcherPriority.Background,
                 new string[] { msg.Contents }
                 );
         }
         ////////////////////////////////////////////////////////////////////////////////////
         if (msg.Contents == "quit")
         {
             msg.TargetCommunicator = "dispatcher";
             AbstractMessageDispatcher.GetInstance().PostMessage(msg);
             break;
         }
         ////////////////////////////////////////////////////////////////////////////////////
     }
 }
Beispiel #15
0
        //----< get and process message from client>----------------
        protected override void ProcessMessages()
        {
            while (true)
            {
                ShowFiles      sf  = new ShowFiles();
                ServiceMessage msg = bq.deQ();
                Console.Write("\n  {0} Recieved Message:\n", msg.TargetCommunicator);
                Console.Write("\n  Echo processing completed\n");
                if (msg.Contents == "connect to server")
                {
                    ClientURL = msg.ResourceName;
                }
                ////////////////////////////////////////////////////////////////////////////////////////////
                // client ask for category root in repositpry, find categories repository files belong to
                // and send the msg back to client, msg contain categories
                if (msg.ResourceName == "category")
                {
                    List <string> Categories = new List <string>();
                    Categories = sf.FindCategories();
                    foreach (string cate in Categories)
                    {
                        ServiceMessage reply = ServiceMessage.MakeMessage("client-echo", "ServiceServer", cate, "Categories");
                        reply.TargetUrl = msg.SourceUrl;
                        reply.SourceUrl = msg.TargetUrl;
                        AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                        dispatcher.PostMessage(reply);
                    }
                }
                ///////////////////////////////////////////////////////////////////////////////////////////
                // client require for files in the specified category
                // server find files and send back
                if (msg.ResourceName == "files in this category")
                {
                    List <string> filesInCate = new List <string>();
                    filesInCate = sf.FindFiles(msg.Contents);
                    foreach (string file in filesInCate)
                    {
                        ServiceMessage reply = ServiceMessage.MakeMessage("client-echo", "ServiceServer", file, "files found in category");
                        reply.TargetUrl = msg.SourceUrl;
                        reply.SourceUrl = msg.TargetUrl;
                        AbstractMessageDispatcher dispatcher = AbstractMessageDispatcher.GetInstance();
                        dispatcher.PostMessage(reply);
                    }
                }
                ///////////////////////////////////////////////////////////////////////////////////////////
                //send the xml and text file content back
                if (msg.ResourceName == "extract file")
                {
                    ExtractFile ef       = new ExtractFile();
                    string      textfile = ef.TextFile(msg.Contents);
                    string      xmlfile  = ef.XmlFile(msg.Contents);

                    ServiceMessage reply1 = ServiceMessage.MakeMessage("client-echo", "ServiceServer", textfile, "textfile");
                    reply1.TargetUrl = msg.SourceUrl;
                    reply1.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher1 = AbstractMessageDispatcher.GetInstance();
                    dispatcher1.PostMessage(reply1);

                    ServiceMessage reply2 = ServiceMessage.MakeMessage("client-echo", "ServiceServer", xmlfile, "xmlfile");
                    reply2.TargetUrl = msg.SourceUrl;
                    reply2.SourceUrl = msg.TargetUrl;
                    AbstractMessageDispatcher dispatcher2 = AbstractMessageDispatcher.GetInstance();
                    dispatcher2.PostMessage(reply2);
                }
                if (msg.Contents == "quit")
                {
                    break;
                }
            }
        }