static void Main(string[] args)
        {
            Console.Write("\n Test ExtractFile");
            Console.Write("\n===================\n\n");
            ExtractFile ef       = new ExtractFile();
            string      filename = "../../Repository\\XmlCreation.cs.xml";
            string      content1 = ef.TextFile(filename);
            string      content2 = ef.XmlFile(filename);

            Console.Write("{0}\n\n{1}", content1, content2);
        }
Exemplo n.º 2
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;
                }
            }
        }