//----< set current file and show its information and relationship in each view >----------------
        public void SetCurrentFile(string filename)
        {
            Text_File.Text     = null;
            Metadata_FIle.Text = null;
            ParentsList.Items.Clear();
            ChildrenList.Items.Clear();

            if (!filename.Contains(".xml"))
            {
                filename = filename + ".xml";
            }
            ServiceMessage msg3 =
                ServiceMessage.MakeMessage("echo", "ServiceClient", filename, "extract file");

            msg3.SourceUrl = ClientUrl;
            msg3.TargetUrl = ServerUrl;
            sender.PostMessage(msg3);

            ServiceMessage msg4 =
                ServiceMessage.MakeMessage("nav", "ServiceClient", filename, "file relationship");

            msg4.SourceUrl = ClientUrl;
            msg4.TargetUrl = ServerUrl;
            sender.PostMessage(msg4);
        }
        //----< register with Server>----------------
        public void ClientStart()
        {
            ServerUrl = "http://localhost:8000/CommService";
            sender    = null;
            sender    = new Sender();
            sender.Connect(ServerUrl);
            sender.Start();

            reference.dispatcher.BeginInvoke(new invoker(GetClientUrl),
                                             System.Windows.Threading.DispatcherPriority.Send);
            receiver = new Receiver(ClientUrl);

            EchoCommunicator echo = new EchoCommunicator(reference);

            echo.Name = "client-echo";
            receiver.Register(echo);
            echo.Start();

            NaviCommnuicator nav = new NaviCommnuicator(reference);

            nav.Name = "client-nav";
            receiver.Register(nav);
            nav.Start();
            ServiceMessage msg =
                ServiceMessage.MakeMessage("echo", "ServiceClient", "connect to server", ClientUrl);

            msg.SourceUrl = ClientUrl;
            msg.TargetUrl = ServerUrl;
            sender.PostMessage(msg);
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        public void Close()
        {
            ServiceMessage msg = ServiceMessage.MakeMessage(this.Name, this.Name, "quit");

            this.PostMessage(msg);
            t.Join();
            ((IClientChannel)svc).Close();
        }
        public void Stop()
        {
            ServiceMessage msg = ServiceMessage.MakeMessage(this.Name, this.Name, "quit");

            msg.TargetUrl = "http://localhost:8001/CommService";
            msg.SourceUrl = msg.TargetUrl;
            this.PostMessage(msg);
        }
        //----< refresh button >----------------
        private void Refresh_Click(object sender_, RoutedEventArgs e)
        {
            ServiceMessage msg3 =
                ServiceMessage.MakeMessage("nav", "ServiceClient", "mapping", "refresh pc relationship");

            msg3.SourceUrl = ClientUrl;
            msg3.TargetUrl = ServerUrl;

            sender.PostMessage(msg3);
        }
        //----< show files in specified category when category change >----------------
        private void Cate_SelectionChanged(object sender_, SelectionChangedEventArgs e)
        {
            Files.Items.Clear();
            string         CateName = Cate.SelectedItem.ToString();
            ServiceMessage msg2     =
                ServiceMessage.MakeMessage("echo", "ServiceClient", CateName, "files in this category");

            msg2.SourceUrl = ClientUrl;
            msg2.TargetUrl = ServerUrl;
            sender.PostMessage(msg2);
        }
        static void Main(string[] args)
        {
            "Testing AbstractCommunicator".Title();

            TestCommunicator tc1 = new TestCommunicator();

            tc1.Name = "tc1";
            tc1.Start();

            TestCommunicator tc2 = new TestCommunicator();

            tc2.Name = "tc2";
            tc2.Start();

            TestDispatcher td = new TestDispatcher();

            td.Name    = "td";
            td.Verbose = true;
            td.Start();
            td.Register(tc1);

            // show that GetInstance works

            AbstractMessageDispatcher tdi = TestDispatcher.GetInstance();

            tdi.Register(tc2);

            ServiceMessage msg0 = ServiceMessage.MakeMessage("foobar", "Main", "going nowhere");

            td.PostMessage(msg0);
            ServiceMessage msg1 = ServiceMessage.MakeMessage(tc1.Name, "Main", "some boring contents");

            td.PostMessage(msg1);
            ServiceMessage msg2 = ServiceMessage.MakeMessage(tc2.Name, "Main", "more boring contents");

            td.PostMessage(msg2);
            ServiceMessage msg3 = ServiceMessage.MakeMessage(tc1.Name, "Main", "quit");

            td.PostMessage(msg3);
            ServiceMessage msg4 = ServiceMessage.MakeMessage(tc2.Name, "Main", "quit");

            td.PostMessage(msg4);
            ServiceMessage msg5 = ServiceMessage.MakeMessage(td.Name, "Main", "quit");

            td.PostMessage(msg5);

            tc1.Wait();
            tc2.Wait();
            td.Wait();

            Console.Write("\n\n");
        }
        //----< get categories and files in Server>----------------
        public void GetContent()
        {
            ServiceMessage msg1 =
                ServiceMessage.MakeMessage("echo", "ServiceClient", "get category", "category");

            msg1.SourceUrl = ClientUrl;
            msg1.TargetUrl = ServerUrl;
            sender.PostMessage(msg1);

            ServiceMessage msg2 =
                ServiceMessage.MakeMessage("nav", "ServiceClient", "mapping", "get pc relationship");

            msg2.SourceUrl = ClientUrl;
            msg2.TargetUrl = ServerUrl;
            sender.PostMessage(msg2);
        }
        //----< query button to send query message with query requirement >----------------
        private void Query1_Click(object sender_, RoutedEventArgs e)
        {
            if (ServerUrl == null)
            {
                MessageBox.Show("Please register with Server first!");
            }
            else
            {
                QueryCommunicator query = new QueryCommunicator(reference);
                query.Name = "client-query";
                receiver.Register(query);
                query.Start();

                Result.Items.Clear();
                Categories1.Items.Clear();
                show_elements.Items.Clear();
                string         queryContents = Categories2.Text + "&" + QueryContent.Text;
                ServiceMessage msg2          = null;

                if (Text.IsChecked == true && all_strings.IsChecked == true)
                {
                    msg2           = ServiceMessage.MakeMessage("query", "ServiceClient", queryContents, "textqueryA");
                    msg2.SourceUrl = ClientUrl;
                    msg2.TargetUrl = ServerUrl;
                    sender.PostMessage(msg2);
                }
                else if (Text.IsChecked == true && all_strings.IsChecked != true)
                {
                    msg2           = ServiceMessage.MakeMessage("query", "ServiceClient", queryContents, "textqueryO");
                    msg2.SourceUrl = ClientUrl;
                    msg2.TargetUrl = ServerUrl;
                    sender.PostMessage(msg2);
                }
                else if (Metadata.IsChecked == true)
                {
                    msg2           = ServiceMessage.MakeMessage("query", "ServiceClient", queryContents, "metadataquery");
                    msg2.SourceUrl = ClientUrl;
                    msg2.TargetUrl = ServerUrl;
                    sender.PostMessage(msg2);
                }
                else
                {
                    MessageBox.Show("Choose file pattern!");
                }
            }
        }
Esempio n. 11
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);
     }
 }
Esempio n. 12
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);
                }
            }
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
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);
                }
            }
Esempio n. 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;
                }
            }
        }
Esempio n. 16
0
        public void Stop()
        {
            ServiceMessage msg = ServiceMessage.MakeMessage(this.Name, this.Name, "quit");

            this.PostMessage(msg);
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Console.Write("\n  Starting CommService Client");
            Console.Write("\n =============================\n");

            string ServerUrl = "http://localhost:8000/CommService";
            Sender sender    = null;

            Console.Write("\n  Press key to start client: ");
            Console.ReadKey();

            sender = new Sender();
            sender.Connect(ServerUrl);
            sender.Start();

            string   ClientUrl = "http://localhost:8001/CommService";
            Receiver receiver  = new Receiver(ClientUrl);

            // Don't need to start receiver unless you want
            // to send it messages, which we won't as all
            // our messages go to the server
            //receiver.Start();

            EchoCommunicator echo = new EchoCommunicator();

            echo.Name = "client-echo";
            receiver.Register(echo);
            echo.Start();

            ServiceMessage msg1 =
                ServiceMessage.MakeMessage("echo", "ServiceClient", "<root>some echo stuff</root>", "no name");

            msg1.SourceUrl = ClientUrl;
            msg1.TargetUrl = ServerUrl;
            Console.Write("\n  Posting message to \"{0}\" component", msg1.TargetCommunicator);
            sender.PostMessage(msg1);

            ServiceMessage msg2 =
                ServiceMessage.MakeMessage("query", "ServiceClient", "<root>some query stuff</root>", "no name");

            msg2.SourceUrl = ClientUrl;
            msg2.TargetUrl = ServerUrl;
            Console.Write("\n  Posting message to \"{0}\" component", msg2.TargetCommunicator);
            sender.PostMessage(msg2);

            ServiceMessage msg3 =
                ServiceMessage.MakeMessage("nav", "ServiceClient", "<root>some nav stuff</root>", "no name");

            msg3.SourceUrl = ClientUrl;
            msg3.TargetUrl = ServerUrl;
            Console.Write("\n  Posting message to \"{0}\" component", msg3.TargetCommunicator);
            sender.PostMessage(msg3);

            // wait for all server replies to be sent back

            Console.Write("\n  Wait for Server replies, then press a key to exit: ");
            Console.ReadKey();

            sender.Stop(); // this function sends a quit message to client-echo
            sender.Wait();
            echo.Stop();
            echo.Wait();
            receiver.Close();
            Console.Write("\n\n");
        }