void initializeDispatcher() { Func <CommMessage, CommMessage> testRequest = (CommMessage msg) => { msg.show(); //create the temp dir string TestTempFileDir = "../../../TestStorage/" + msg.arguments[0] + "/"; if (!System.IO.Directory.Exists(TestTempFileDir)) { System.IO.Directory.CreateDirectory(TestTempFileDir); } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = "http://localhost:5270/IPluggableComm"; reply.from = msg.to; reply.command = "getTestFiles"; reply.arguments.Add(msg.arguments[0]); return(reply); }; messageDispatcher["testRequest"] = testRequest; Func <CommMessage, CommMessage> testFileOK = (CommMessage msg) => { msg.show(); //do Test string TestTempFileDir = "../../../TestStorage/" + msg.arguments[0] + "/"; TestRequest.TestRequest TR = new TestRequest.TestRequest(); TR.unwrap(TestTempFileDir + "TestRequest" + msg.arguments[0] + ".xml", false); Tester tstr = new Tester(); Thread t = tstr.SelectConfigAndRun(TestTempFileDir); t.Join(); bool Testresult = tstr.ShowTestResults(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = "http://localhost:5261/IPluggableComm"; reply.from = msg.to; reply.command = "testResult"; reply.arguments.Add(msg.arguments[0]); reply.arguments.Add(Testresult?"Success":"Fail"); return(reply); }; messageDispatcher["testFileOK"] = testFileOK; }
// Main entrance static void Main(string[] args) { Builder ChildBuilder = new Builder(); if (ChildBuilder.ProcessCommandLineArgs(args)) { Console.Write("\n ChildBuildProcess Start Up. Address: {0}\n", ChildBuilder.address); } else { Console.Write("\n No Command Line Arguments..\n"); } Comm comm = new Comm("http://localhost", int.Parse(args[0])); CommMessage crcvMessage = comm.getMessage(); crcvMessage.show(); //ChildBuilder.address = crcvMessage.to; while (true) { crcvMessage = comm.getMessage(); // TODO: Change switch-case to Fun() switch (crcvMessage.command) { case "show": crcvMessage.show(); break; case "test": crcvMessage.show(); "Connection from MotherBuilder to this ChildBuilder is OK.".green(); "Sending testback...".yellow(); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "testback"; csndMsg.author = "Jing Qi"; csndMsg.to = crcvMessage.from; csndMsg.from = crcvMessage.to; comm.postMessage(csndMsg); break; case "testdone": "Connection test success. ChildBuilder is Ready.".green(); CommMessage csndMsg_ready = new CommMessage(CommMessage.MessageType.request); csndMsg_ready.command = "ready"; csndMsg_ready.author = "Jing Qi"; csndMsg_ready.to = crcvMessage.from; csndMsg_ready.from = crcvMessage.to; comm.postMessage(csndMsg_ready); break; case "build": // TODO: NOW YOU GET THE BUILD REQUEST, NOW BUILD "Build Request Received.".yellow(); crcvMessage.show(); //Thread.Sleep(3000); // pretend to be building string BuildTempFileDir = "../../../BuilderStorage/"; BuildTempFileDir += System.IO.Path.GetFileNameWithoutExtension(crcvMessage.arguments[0]); if (!System.IO.Directory.Exists(BuildTempFileDir)) { System.IO.Directory.CreateDirectory(BuildTempFileDir); } // gatherFiles CommMessage needFileRequest = new CommMessage(CommMessage.MessageType.request); needFileRequest.command = "needXML"; needFileRequest.author = "Jing Qi"; needFileRequest.to = "http://localhost:5260/IPluggableComm"; needFileRequest.from = crcvMessage.to; needFileRequest.arguments.Add(crcvMessage.arguments[0]); needFileRequest.arguments.Add(BuildTempFileDir); comm.postMessage(needFileRequest); Thread.Sleep(1000); " --xml files gathered.".green(); List <string> files = new List <string>(); files = Directory.GetFiles(BuildTempFileDir, "*.xml").ToList <string>(); string BuildRequestName = files[0]; BuildRequest.BuildRequest br = new BuildRequest.BuildRequest(); br.unwrap(BuildTempFileDir + "/" + System.IO.Path.GetFileName(BuildRequestName), false); List <string> testfiles = br.testedFiles; foreach (string testfile in testfiles) { CommMessage needTestFileRequest = new CommMessage(CommMessage.MessageType.request); needTestFileRequest.command = "needXML"; needTestFileRequest.author = "Jing Qi"; needTestFileRequest.to = "http://localhost:5260/IPluggableComm"; needTestFileRequest.from = crcvMessage.to; needTestFileRequest.arguments.Add(testfile); needTestFileRequest.arguments.Add(BuildTempFileDir); comm.postMessage(needTestFileRequest); } Thread.Sleep(1000); " --all files gathered.".green(); CoreBuilder_ICC Builder = new CoreBuilder_ICC(br); bool buildResult = Builder.build(); if (buildResult) { "Build success!...".green(); // send log to repo comm.postFile(BuildTempFileDir, "../../../ServerFiles/BuildLog/", "BuildLog" + crcvMessage.arguments[0]); // send a message to client CommMessage message2Client = new CommMessage(CommMessage.MessageType.request); message2Client.command = "buildResult"; message2Client.author = "Jing Qi"; message2Client.to = "http://localhost:5261/IPluggableComm"; message2Client.from = crcvMessage.to; message2Client.arguments.Add(br.requestID); message2Client.arguments.Add("Success"); comm.postMessage(message2Client); // make a test request TestRequest.TestRequest tr = new TestRequest.TestRequest(); tr.requestID = br.requestID; tr.testDir = BuildTempFileDir; tr.testedFiles.Add("Out.dll"); tr.wrap(); tr.saveXML(BuildTempFileDir + "/TestRequest" + br.requestID + ".xml"); // send test request CommMessage message2TH = new CommMessage(CommMessage.MessageType.request); message2TH.command = "testRequest"; message2TH.author = "Jing Qi"; message2TH.to = "http://localhost:5262/IPluggableComm"; message2TH.from = crcvMessage.to; message2TH.arguments.Add(br.requestID); message2TH.arguments.Add(BuildTempFileDir); comm.postMessage(message2TH); } else { "Build fail!...".red(); // send log to repo comm.postFile(BuildTempFileDir, "../../../ServerFiles/BuildLog/", "BuildLog" + crcvMessage.arguments[0]); // send a message to client CommMessage message2Client = new CommMessage(CommMessage.MessageType.request); message2Client.command = "buildResult"; message2Client.author = "Jing Qi"; message2Client.to = "http://localhost:5261/IPluggableComm"; message2Client.from = crcvMessage.to; message2Client.arguments.Add(br.requestID); message2Client.arguments.Add("Fail"); comm.postMessage(message2Client); } //for (int i = 0; i < 10; i++) //{ // Console.Write("\nbuild process:{0}", i * 10); // Thread.Sleep(300); //} //"BUILT SUCCESS!".green(); CommMessage csndMsg_Buildready = new CommMessage(CommMessage.MessageType.request); csndMsg_Buildready.command = "ready"; csndMsg_Buildready.author = "Jing Qi"; csndMsg_Buildready.to = crcvMessage.from; csndMsg_Buildready.from = crcvMessage.to; comm.postMessage(csndMsg_Buildready); break; case "quit": crcvMessage.show(); comm.close(); "Closed.".red(); return; } } }