Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Write("\n Test ShowFiles");
            Console.Write("\n===================\n\n");

            List <string> a1 = new List <string>();
            List <string> a2 = new List <string>();
            ShowFiles     sf = new ShowFiles();

            a1 = sf.FindCategories();
            a2 = sf.FindFiles("code");
            foreach (string a in a1)
            {
                Console.Write(a1);
                Console.Write("\n");
            }
            foreach (string a in a2)
            {
                Console.Write(a1);
                Console.Write("\n");
            }
        }
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;
                }
            }
        }