Ejemplo n.º 1
0
        void initializeDispatcher()
        {
            Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) =>
            {
                fileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = "http://localhost:" + clientport + "/IMessagePassingComm";
                reply.from      = "http://localhost:" + rcvrport + "/IMessagePassingComm";
                reply.command   = "getTopFiles";
                reply.arguments = fileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["getTopFiles"] = getTopFiles;
            Func <CommMessage, CommMessage> XML = (CommMessage msg) =>
            {
                tempList.Add(msg);
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = "http://localhost:" + clientport + "/IMessagePassingComm";
                reply.from    = "http://localhost:" + rcvrport + "/IMessagePassingComm";
                reply.command = "receive";
                reply.driver  = Path.GetFileName(msg.driver);
                return(reply);
            };

            messageDispatcher["XML"] = XML;

            Func <CommMessage, CommMessage> XMLend = (CommMessage msg) =>
            {
                fileMgr.doc     = new XDocument();
                fileMgr.msgList = tempList;
                fileMgr.makeRequest();
                if (fileMgr.saveXml())
                {
                    try{
                        CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                        reply.to      = "http://localhost:" + clientport + "/IMessagePassingComm";
                        reply.from    = "http://localhost:" + rcvrport + "/IMessagePassingComm";
                        reply.command = "XMLDone";
                        reply.show();
                        sndr.postMessage(reply);
                        if (transfer())
                        {
                            tempXML = fileMgr.tempXML;
                            CommMessage request = new CommMessage(CommMessage.MessageType.build);
                            request.to      = "http://localhost:" + motherport + "/IMessagePassingComm";
                            request.from    = "http://localhost:" + rcvrport + "/IMessagePassingComm";
                            request.command = tempList.Count().ToString();
                            request.XML     = tempXML;
                            tempList        = new List <CommMessage>();
                            return(request);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    catch (Exception ex) {
                        Console.Write("\n\n The error reason in XMLend is {0}\n\n", ex.Message);
                    }
                    return(null);
                }
                else
                {
                    return(null);
                }
            };

            messageDispatcher["XMLend"] = XMLend;
        }