public void HandleSay(string args_str) { Debug.Log("Got say command with message: " + args_str); //ClientAPI.Network.SendCommMessage(args_str); CommMessage commMessage = new CommMessage(); commMessage.ChannelId = 1; // CommChannel.Say commMessage.Message = args_str; commMessage.SenderName = ClientAPI.GetPlayerObject().Name; NetworkHelper.Instance.SendMessage(commMessage); Debug.Log("Sent chat message: " + commMessage); }
public static void SendCommMessage(string text) { CommMessage message = new CommMessage(); message.ChannelId = 1; // CommChannel.Say message.Message = text; message.SenderName = ClientAPI.GetPlayerObject().Name; Client.Instance.NetworkHelper.SendMessage(message); }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> analyzeFiles = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "analyzeFiles"; TypeAnalysis typeana = new TypeAnalysis(); DepAnalys depana = new DepAnalys(); StrongComp strongcomp = new StrongComp(); List <Elem> table = new List <Elem>(); foreach (string file in msg.arguments) { ITokenCollection semi = Factory.create(); if (!semi.open(file as string)) { Console.Write("\n Can't open {0}\n\n", file); return(null); } BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi); Parser parser = builder.build(); try { while (semi.get().Count > 0) { parser.parse(semi); } } catch (Exception ex) { Console.Write("\n\n {0}\n", ex.Message); } Repository rep = Repository.getInstance(); table = rep.locations; File f = file.Substring(file.LastIndexOf('\\') + 1); string namesp = ""; foreach (Elem ele in table) { if (ele.type == "namespace") { namesp = ele.name; } typeana.add(f, ele, namesp); } semi.close(); } depana.BuildGraph(msg.arguments); foreach (string f in msg.arguments) { depana.ConnectNode(typeana, f); } //move to reply.arguments[0]; foreach (CsNode <string, string> node in depana.csgraph.adjList) { StringBuilder temp = new StringBuilder(); temp.Append(node.name.Substring(node.name.LastIndexOf('/') + 1)); temp.Append(" \n Dependency : ["); foreach (CsEdge <string, string> edge in node.children) { temp.Append(edge.targetNode.name.Substring(edge.targetNode.name.LastIndexOf('/') + 1)); temp.Append(" "); } temp.Append(" ] \n"); reply.arguments.Add(temp.ToString()); } strongcomp.FindConnect(depana.csgraph); //move to reply.arguments[1]; int i = 1; foreach (List <CsNode <string, string> > nodes in strongcomp.result) { StringBuilder temp = new StringBuilder(); temp.Append("Components " + i.ToString() + ": "); foreach (CsNode <string, string> node in nodes) { temp.Append(node.name.Substring(node.name.LastIndexOf('/') + 1) + " "); } temp.Append("\n"); i++; reply.arguments.Add(temp.ToString()); } return(reply); }; messageDispatcher["analyzeFiles"] = analyzeFiles; Func <CommMessage, CommMessage> demo456 = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "demo456"; reply.arguments.Add(""); return(reply); }; messageDispatcher["demo456"] = demo456; }
/*----< define how each message will be processed >------------*/ private void initializeDispatcher() { Func <CommMessage, CommMessage> getUpFiles = msg => { localFileMgr.currentPath = ""; var temp = string.Empty; var send_path = string.Empty; var count = 0; if (localFileMgr.pathStack.Count == 1 && localFileMgr.pathStack.Peek().Equals(ServerEnvironment.root)) { localFileMgr.currentPath = ""; if (localFileMgr.pathStack.Count != 0) { localFileMgr.pathStack.Clear(); localFileMgr.pathStack.Push(ServerEnvironment.root); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpFiles"; reply.arguments = localFileMgr.getFiles().ToList(); return(reply); } else { temp = localFileMgr.pathStack.Pop(); send_path = localFileMgr.pathStack.Peek(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpFiles"; reply.arguments = localFileMgr.getFiles(send_path).ToList(); return(reply); } }; messageDispatcher["getUpFiles"] = getUpFiles; Func <CommMessage, CommMessage> getUpDirs = msg => { localFileMgr.currentPath = ""; var send_path = string.Empty; var count = 0; if (localFileMgr.pathStack.Count == 1 && localFileMgr.pathStack.Peek().Equals(ServerEnvironment.root)) { localFileMgr.currentPath = ""; var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpDirs"; reply.arguments = localFileMgr.getDirs().ToList(); return(reply); } else { send_path = localFileMgr.pathStack.Peek(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getUpDirs"; reply.arguments = localFileMgr.getDirs(send_path).ToList(); return(reply); } }; messageDispatcher["getUpDirs"] = getUpDirs; Func <CommMessage, CommMessage> connect = msg => { localFileMgr.currentPath = ""; if (localFileMgr.pathStack.Count != 0) { localFileMgr.pathStack.Clear(); localFileMgr.pathStack.Push(ServerEnvironment.root); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "connect"; reply.arguments.Add("Connected"); return(reply); }; messageDispatcher["connect"] = connect; Func <CommMessage, CommMessage> getTopFiles = msg => { localFileMgr.currentPath = ""; if (localFileMgr.pathStack.Count != 0) { localFileMgr.pathStack.Clear(); localFileMgr.pathStack.Push(ServerEnvironment.root); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = msg => { localFileMgr.currentPath = ""; var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = msg => { var temp = string.Empty; if (msg.arguments.Count() == 1) { //temp_path = localFileMgr.pathStack.Peek(); temp = localFileMgr.pathStack.Peek() + "/" + msg.arguments[0]; localFileMgr.pathStack.Push(temp); localFileMgr.currentPath = msg.arguments[0]; } //string temp = localFileMgr.pathStack.Peek(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles(temp).ToList(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = msg => { var temp = string.Empty; if (msg.arguments.Count() == 1) { temp = localFileMgr.pathStack.Peek(); } var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs(temp).ToList(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> Close = msg => { var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Close"; reply.arguments.Add("Close"); return(reply); }; messageDispatcher["Close"] = Close; Func <CommMessage, CommMessage> DepAnalysis = msg => { localFileMgr.currentPath = ""; var temp = string.Empty; var send_path = string.Empty; var count = 0; try { var ex = new Executive(); FileStream ostrm; StreamWriter writer; var oldOut = Console.Out; var directory = Directory.GetParent(Directory.GetParent(ServerEnvironment.root).ToString()) .ToString(); var listOfSelectedFiles = msg.arguments; if (File.Exists(directory + "/Analysis.txt")) { File.Delete(directory + "/Analysis.txt"); } ostrm = new FileStream(directory + "/Analysis.txt", FileMode.Create, FileAccess.Write); writer = new StreamWriter(ostrm); writer.AutoFlush = true; Console.SetOut(writer); send_path = localFileMgr.pathStack.Peek(); var temp_list = new List <string> { "/Analysis.txt" }; var nav = new Navigate(); nav.Add("*.cs"); List <string> files; if (listOfSelectedFiles.Count > 0) { nav.go(send_path, listOfSelectedFiles); files = nav.allFiles; ex.getResult(files); } else { nav.go(send_path); files = nav.allFiles; ex.getResult(files); } Console.SetOut(oldOut); writer.Flush(); ostrm.Flush(); writer.Close(); ostrm.Close(); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "DepAnalysis"; reply.arguments = temp_list; return(reply); } catch (Exception e) { var temp_list = new List <string> { "/Analysis.txt" }; Console.WriteLine(e); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "DepAnalysis"; reply.arguments = temp_list; return(reply); } }; messageDispatcher["DepAnalysis"] = DepAnalysis; Func <CommMessage, CommMessage> OpenFile = msg => { var send_path = string.Empty; var count = 0; try { var FileToOpen = msg.arguments[0]; send_path = localFileMgr.pathStack.Peek(); comm.postFile(send_path, FileToOpen); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "OpenFile"; reply.arguments.Add(FileToOpen); return(reply); } catch (Exception e) { var temp_list = new List <string> { "" }; Console.WriteLine(e); var reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "OpenFile"; reply.arguments = temp_list; return(reply); } }; messageDispatcher["OpenFile"] = OpenFile; }
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; }
public abstract void ExecuteCommCommand(CommMessage msg);
/*-------------extract port number from the ready message from the child process--------------*/ public void getReadyThread(CommMessage msg) { trdQ.enQ(msg.from.Substring(17, 4)); //get the sub string of the port number }
public LoaderProxy() { treply = new CommMessage(CommMessage.MessageType.TestResult); }
static void listen_test_thread() { Console.WriteLine(); Console.WriteLine("**************************************************************"); Console.WriteLine("***************Test Harness Listening*************************"); Console.WriteLine("**************************************************************"); if (comm != null) { while (true) { CommMessage recv_msg = new CommMessage(CommMessage.MessageType.request); recv_msg = comm.getMessage(); if (recv_msg.port_number != 0 && recv_msg.msg_body.Contains("test")) { //recv_msg.show(); string[] files = Directory.GetFiles(recv_msg.msg_body.Replace("test", ""), "*.dll"); List <String> l_files = new List <String>(); foreach (String str in files) { l_files.Add(Path.GetFileName(str)); } string source_path = recv_msg.msg_body.Replace("test", ""); string dest_path = @"../../../Test_Harness/Local_Storage"; string source_file_name = ""; string source_file = ""; string destination_file = ""; foreach (String file in l_files) { destination_file = ""; source_file_name = "" + file; source_file = System.IO.Path.Combine(source_path, source_file_name); destination_file = System.IO.Path.Combine(dest_path, source_file_name); System.IO.File.Copy(source_file, destination_file, true); } Console.WriteLine(" * *****************************************************"); Console.WriteLine("------------Required .dll Files are stored in the Testers path:{0}----------", System.IO.Path.GetFullPath(dest_path)); Console.WriteLine("******************************************************"); call_harness(recv_msg.msg_body.Replace("test", "")); //send message to repo CommMessage test_result_msg = new CommMessage(CommMessage.MessageType.request); test_result_msg.command = "from_harness"; test_result_msg.author = "Salim Zhulkhrni"; test_result_msg.to = "http://*****:*****@"../../../Repo_Files/Test_log_For_" + file.Split(':')[0] + ".txt", file.Split(':')[0] + ":" + file.Split(':')[1]); } /////////////// test_result = ""; //send test notification to client } } } }
public void MessageIn(CommMessage msg) { testQ.enQ(msg); }
public CommMessage MessageOut() { CommMessage msg = testQ.deQ(); return(msg); }
//------< helps in spawning number of child builders >---------- public void processMessage(CommMessage msg) { creatProcess(msg.numberProcess); return; }
//this function invokes the helper function so as to populate the listbox with xml build request files obtained from repo. private void populateXmlFileListBoxFromRepo(CommMessage msgFromRepo) { Console.WriteLine("populateXmlFileListBoxFromRepo entered"); Dispatcher.Invoke(new Action <CommMessage>(populateXMlFileListBoxHelper), System.Windows.Threading.DispatcherPriority.Background, new CommMessage[] { msgFromRepo }); }
static void Main(string[] args) { try { Console.Title = "AUTO TEST"; Console.Write("Auto Test start"); int threadNum = 3; string motherName = "..\\..\\..\\MotherBuild\\bin\\Debug\\MotherBuild.exe"; Process.Start(motherName, threadNum.ToString()); string repoName = "..\\..\\..\\Repo\\bin\\Debug\\Repo.exe"; Process.Start(repoName); string thName = "..\\..\\..\\TestHarness\\bin\\Debug\\TestHarness.exe"; Process.Start(thName); Thread.Sleep(600); Sender testSndr = new Sender("http://localhost", 9999); CommMessage testmsg = new CommMessage(CommMessage.MessageType.request); testmsg.author = "test"; testmsg.command = "XML"; testmsg.from = "test"; testmsg.to = "http://localhost:8082/IMessagePassingComm"; testmsg.driver = "TestDriver.cs"; testmsg.arguments.Add("TestedOne.cs"); testmsg.arguments.Add("TestedTwo.cs"); testmsg.show(); testSndr.postMessage(testmsg); Thread.Sleep(500); CommMessage testmsg_1 = new CommMessage(CommMessage.MessageType.request); testmsg_1.author = "test_1"; testmsg_1.command = "XML"; testmsg_1.from = "test"; testmsg_1.to = "http://localhost:8082/IMessagePassingComm"; testmsg_1.driver = "TestDriver_1.cs"; testmsg_1.arguments.Add("TestedOne_1.cs"); testmsg_1.arguments.Add("TestedTwo_1.cs"); testmsg_1.show(); testSndr.postMessage(testmsg_1); Thread.Sleep(500); CommMessage testmsg_2 = new CommMessage(CommMessage.MessageType.request); testmsg_2.author = "test_2"; testmsg_2.command = "XML"; testmsg_2.from = "test"; testmsg_2.to = "http://localhost:8082/IMessagePassingComm"; testmsg_2.driver = "TestDriver_2.cs"; testmsg_2.arguments.Add("TestedOne_2.cs"); testmsg_2.arguments.Add("TestedTwo_2.cs"); testmsg_2.show(); testSndr.postMessage(testmsg_2); Thread.Sleep(500); CommMessage testmsg_end = new CommMessage(CommMessage.MessageType.build); testmsg_end.command = "XMLend"; testmsg_end.to = "http://localhost:8082/IMessagePassingComm"; testmsg_end.show(); testSndr.postMessage(testmsg_end); } catch (Exception ex) { Console.Write("\n\n The error reason in auto test is {0}\n\n", ex.Message); } }
public override void update(Robot r) { bool finished = false; //////////////////////////////////////////////////////////////////////////////////////// // Initialize variables if necessary when first enter state //////////////////////////////////////////////////////////////////////////////////////// if (!initialized) { initialized = true; resume = true; state = ForagingState.REQUEST_RESOURCE; } //////////////////////////////////////////////////////////////////////////////////////// // Reset variables if robot is returning from another state //////////////////////////////////////////////////////////////////////////////////////// if (resume) { resume = false; Log.d(LogTag.ROBOT, "Robot " + r.id + " is returning to foraging"); switch (state) { case ForagingState.REQUEST_RESOURCE: { Log.d(LogTag.ROBOT, "ROBOT " + r.id + " has requested a resource."); Comm.directMessage(r.id, Comm.SATELLITE, "resource_request"); break; } case ForagingState.PICK_UP_RESOURCE: { testMove = new Vector2(10f, 10f); r.pushState(new RobotStateMove(testMove)); state = ForagingState.GO_TO_DROP_OFF; break; } case ForagingState.GO_TO_RESOURCE_HOME: { state = ForagingState.GO_TO_DROP_OFF; break; } case ForagingState.GO_TO_DROP_OFF: { //request a position where to drop off the resource in the resource home Comm.directMessage(r.id, Comm.SATELLITE, "resource_home_request"); break; } case ForagingState.DROP_OFF_RESOURCE: { //drop off the resource Comm.directMessage(r.id, Comm.SATELLITE, "resource_delivered"); break; } case ForagingState.RETURN_TO_BASE: { state = ForagingState.REQUEST_RESOURCE; break; } case ForagingState.FINISHED: { finished = true; break; } default: { break; } } } //////////////////////////////////////////////////////////////////////////////////////// // Update: check if robot has reached its destination (within specified tolerance) //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// // Process messages: no, should be handled in other states //////////////////////////////////////////////////////////////////////////////////////// int count = r.unhandledMessages.Count; for (int i = 0; i < count; ++i) { CommMessage msg = r.unhandledMessages.Dequeue(); if (msg.senderId == Comm.SATELLITE) { switch (state) { case ForagingState.REQUEST_RESOURCE: { if (msg.text.StartsWith("resource_location")) { string[] lines = msg.text.Split('\t'); //parse the messgae sent back from the satellite //will be sent the location of the resource StringToVector2(lines[1], out result); r.pushState(new RobotStateRetrieveResource(result)); state = ForagingState.PICK_UP_RESOURCE; } else if (msg.text.StartsWith("go_to_base")) { string[] lines = msg.text.Split('\t'); StringToVector3(lines[1], out resultBase); r.pushState(new RobotStateMove(resultBase)); state = ForagingState.FINISHED; } break; } case ForagingState.GO_TO_DROP_OFF: { if (msg.text.StartsWith("resource_home")) { string[] lines = msg.text.Split('\t'); StringToVector2(lines[1], out resultRH); } testMove = new Vector2(10f, 15f); r.pushState(new RobotStateMove(testMove)); r.pushState(new RobotStatePlaceResource(resultRH)); state = ForagingState.DROP_OFF_RESOURCE; break; } case ForagingState.DROP_OFF_RESOURCE: { if (msg.text.StartsWith("resource_location")) { string[] lines = msg.text.Split('\t'); //parse the messgae sent back from the satellite //will be sent the location of the resource StringToVector2(lines[1], out result); r.pushState(new RobotStateRetrieveResource(result)); state = ForagingState.PICK_UP_RESOURCE; } else if (msg.text.StartsWith("go_to_base")) { string[] lines = msg.text.Split('\t'); StringToVector3(lines[1], out resultBase); r.pushState(new RobotStateMove(resultBase)); state = ForagingState.FINISHED; } break; } } } else { Log.w(LogTag.ROBOT, "Robot " + r.id + " processed unknown message " + msg.text + " from " + msg.senderId); } } //////////////////////////////////////////////////////////////////////////////////////// // "Clean up" robot state //////////////////////////////////////////////////////////////////////////////////////// if (finished) { Log.d(LogTag.ROBOT, "Robot " + r.id + " has finished foraging"); // Pop state off the stack r.popState(); } }
/// <summary> /// On receiving a message, raises the event. /// </summary> /// <param name="msg"></param> protected override void HandleCommunicationMessage(CommMessage msg) { this.MessageReceived(msg); }
/*----< called by remote Comm to upload fileName >-----------------*/ public bool postFile(CommMessage msg) { return(sndr.postFile(msg)); }
private void processFileReceivedMsg(CommMessage msg) { receivedFiles.Add(msg.arguments[0]); }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { if (localFileMgr.pathStack.Count != 1) { localFileMgr.pathStack.Clear(); } Console.WriteLine(localFileMgr.currentPath); localFileMgr.currentPath = ""; localFileMgr.pathStack.Push(localFileMgr.currentPath); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { if (msg.arguments.Count() == 1) { localFileMgr.currentPath = msg.arguments[0]; } localFileMgr.pathStack.Push(localFileMgr.currentPath); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; Func <CommMessage, CommMessage> moveUpDirs = (CommMessage msg) => { if (localFileMgr.pathStack.Count != 1) { localFileMgr.pathStack.Pop(); localFileMgr.currentPath = localFileMgr.pathStack.Peek(); } else { localFileMgr.pathStack.Pop(); localFileMgr.currentPath = Environment.root; localFileMgr.pathStack.Push(localFileMgr.currentPath); localFileMgr.currentPath = localFileMgr.pathStack.Peek(); } Console.WriteLine(localFileMgr.currentPath); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveUpDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); //Console.WriteLine(localFileMgr.pathStack.Count); return(reply); }; messageDispatcher["moveUpDirs"] = moveUpDirs; Func <CommMessage, CommMessage> moveUpDirsFile = (CommMessage msg) => { if (localFileMgr.pathStack.Count != 0) { localFileMgr.currentPath = localFileMgr.pathStack.Peek(); } else { localFileMgr.currentPath = Environment.root; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveUpDirsFile"; reply.arguments = localFileMgr.getFiles().ToList <string>(); Console.WriteLine(localFileMgr.pathStack.Count); return(reply); }; messageDispatcher["moveUpDirsFile"] = moveUpDirsFile; Func <CommMessage, CommMessage> moveSelectedFiles = (CommMessage msg) => { int temp = 0; foreach (var item in selected) { if (item == msg.arguments[0]) { temp = 1; } } if (temp == 0 && Path.GetExtension(msg.arguments[0]) == ".cs") { selected.Add(msg.arguments[0]); } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveSelectedFiles"; foreach (var i in selected) { reply.arguments.Add(i); } return(reply); }; messageDispatcher["moveSelectedFiles"] = moveSelectedFiles; Func <CommMessage, CommMessage> Add_all = (CommMessage msg) => { foreach (var item in msg.arguments) { int temp = 0; foreach (var elem in selected) { if (elem == item) { temp = 1; } } if (temp == 0 && Path.GetExtension(item) == ".cs") { selected.Add(item); } } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Add_all"; foreach (var i in selected) { reply.arguments.Add(i); } // reply.arguments = selected; return(reply); }; messageDispatcher["Add_all"] = Add_all; Func <CommMessage, CommMessage> removeSelectedFiles = (CommMessage msg) => { for (var i = 0; i < selected.Count; i++) { Console.WriteLine(selected[i]); if (selected[i] == msg.arguments[0]) { selected.Remove(selected[i]); } } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "removeSelectedFiles"; foreach (var i in selected) { reply.arguments.Add(i); } // reply.arguments = selected; return(reply); }; messageDispatcher["removeSelectedFiles"] = removeSelectedFiles; Func <CommMessage, CommMessage> clearSelectedFiles = (CommMessage msg) => { selected.Clear(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "clearSelectedFiles"; reply.arguments = selected; return(reply); }; messageDispatcher["clearSelectedFiles"] = clearSelectedFiles; Func <CommMessage, CommMessage> Generate_TT = (CommMessage msg) => { List <string> file_list = new List <string>(); string ttt = Path.GetFullPath(ServerEnvironment.root); for (var i = 0; i < msg.arguments.Count; i++) { file_list.Add(ttt + msg.arguments[i]); } TypeTable tt = new TypeTable(); tt = tt.GetTable(file_list.ToArray()); for (var i = 0; i < file_list.Count; i++) { string temp = Path.GetFileNameWithoutExtension(file_list[i]); file_list[i] = temp; Console.WriteLine(file_list[i]); } //List<string> type_table = tt.print(); string type_table = tt.tt_to_string(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Generate_TT"; List <string> tt_t = new List <string>(); tt_t.Add(""); if (type_table.Length > 1024) { string pp = ""; for (int i = 0; i < type_table.Length; i++) { pp += type_table[i]; if (pp.Length >= 1024) { reply.arguments.Add(pp); pp = ""; } } reply.arguments.Add(pp); pp = ""; } else { reply.arguments.Add(type_table); } return(reply); }; messageDispatcher["Generate_TT"] = Generate_TT; Func <CommMessage, CommMessage> Generate_DT = (CommMessage msg) => { List <string> file_list = new List <string>(); string ttt = Path.GetFullPath(ServerEnvironment.root); for (var i = 0; i < msg.arguments.Count; i++) { file_list.Add(ttt + msg.arguments[i]); } DepenAnalysis dp = new DepenAnalysis(); dp = dp.DepenAnalysises(file_list.ToArray()); for (var i = 0; i < file_list.Count; i++) { string temp = Path.GetFileNameWithoutExtension(file_list[i]); file_list[i] = temp; Console.WriteLine(file_list[i]); } //List<string> dep_table = dp.asign_table(); string dep_table = dp.dep_tostring(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Generate_DT"; if (dep_table.Length > 1024) { string pp = ""; for (int i = 0; i < dep_table.Length; i++) { pp += dep_table[i]; if (pp.Length >= 1024) { reply.arguments.Add(pp); pp = ""; } } reply.arguments.Add(pp); pp = ""; } else { reply.arguments.Add(dep_table); } return(reply); }; messageDispatcher["Generate_DT"] = Generate_DT; Func <CommMessage, CommMessage> Generate_SC = (CommMessage msg) => { List <string> file_list = new List <string>(); string ttt = Path.GetFullPath(ServerEnvironment.root); for (var i = 0; i < msg.arguments.Count; i++) { file_list.Add(ttt + msg.arguments[i]); } CsGraph <string, string> csGraph = new CsGraph <string, string>("Dep_Table"); csGraph = csGraph.Creat_Graph(file_list.ToArray()); csGraph.sc_finder(); for (var i = 0; i < file_list.Count; i++) { string temp = Path.GetFileNameWithoutExtension(file_list[i]); file_list[i] = temp; Console.WriteLine(file_list[i]); } string SC = csGraph.SC_tostring(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Generate_SC"; if (SC.Length > 1024) { string pp = ""; for (int i = 0; i < SC.Length; i++) { pp += SC[i]; if (pp.Length >= 1024) { reply.arguments.Add(pp); pp = ""; } } reply.arguments.Add(pp); pp = ""; } else { reply.arguments.Add(SC); } return(reply); }; messageDispatcher["Generate_SC"] = Generate_SC; Func <CommMessage, CommMessage> importone = (CommMessage msg) => { string path = Path.GetFullPath(ServerEnvironment.root); List <string> dirs_list = new List <string>(); string ttt = Path.GetFullPath(ServerEnvironment.root) + msg.arguments[0]; Console.WriteLine(msg.arguments[0] + "debuggogogo"); string judge = msg.arguments[0] + "debuggogogo"; List <string> file_list = new List <string>(); file_list.AddRange(Directory.GetFiles(ttt).ToList <string>()); dirs_list.AddRange(Directory.GetDirectories(ttt).ToList <string>()); int temp1 = path.Length; foreach (var i in dirs_list) { file_list.AddRange(Directory.GetFiles(i).ToList <string>()); } for (var i = 0; i < file_list.Count; i++) { if (judge == "debuggogogo") { file_list[i] = file_list[i].Remove(temp1); Console.WriteLine(file_list[i]); file_list[i] = Path.GetFileName(file_list[i]); } else { file_list[i] = file_list[i].Remove(0, temp1); } } if (msg.arguments.Count == 0) { selected = selected; } else { foreach (var item in file_list) { int temp = 0; foreach (var elem in selected) { if (elem == item) { temp = 1; } } if (temp == 0 && Path.GetExtension(item) == ".cs") { selected.Add(item); } } } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "importone"; foreach (var i in selected) { reply.arguments.Add(i); } return(reply); }; messageDispatcher["importone"] = importone; Func <CommMessage, CommMessage> importall = (CommMessage msg) => { localFileMgr.all_files.Clear(); if (localFileMgr.pathStack.Count == 1) { localFileMgr.currentPath = ServerEnvironment.root; } else { localFileMgr.currentPath = ServerEnvironment.root + localFileMgr.pathStack.Peek(); } Console.WriteLine(localFileMgr.currentPath); string temp = Path.GetFullPath(ServerEnvironment.root); int temp2 = temp.Length; string dirPath = Path.GetFullPath(localFileMgr.currentPath); List <string> file_sets = new List <string>(); localFileMgr.FindFile(dirPath); file_sets = localFileMgr.all_files; for (var i = 0; i < file_sets.Count; i++) { file_sets[i] = file_sets[i].Remove(0, temp2); } selected = file_sets; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "importall"; reply.arguments = file_sets; return(reply); }; messageDispatcher["importall"] = importall; }
private void builderProc() { while (open) { try { CommMessage request = buildRequests.deQ( ); if (request.command == "SelfClosing") { return; } receivedFiles.Clear( ); CommMessage reqMsg = new CommMessage(CommMessage.MessageType.request); reqMsg.from = address; reqMsg.to = addresses["Repository"]; reqMsg.command = "GetFiles"; reqMsg.arguments = request.arguments; comm.postMessage(reqMsg); while (receivedFiles.Count != request.arguments.Count) { Thread.Sleep(100); } // perform the build string dllname = request.author; DllBuilder builder = new DllBuilder(receivedFiles, dllname); builder.Build( ); string log = builder.Log; // PREPARE message to repository about the log CommMessage logMsg = new CommMessage(CommMessage.MessageType.reply); logMsg.command = "logMsg"; logMsg.author = "ChildBuilder : " + address; logMsg.to = addresses["Repository"]; logMsg.from = address; logMsg.argument = log; comm.postMessage(logMsg); // SEND THE DLL TO TEST HARNESS TO GET TESTED CommMessage dllFile = new CommMessage(CommMessage.MessageType.reply); logMsg.command = "dllFileBild"; logMsg.author = "ChildBuilder : " + address; logMsg.to = ServerEnvironment.endPoint; logMsg.from = address; logMsg.argument = log; comm.postMessage(logMsg); // DELETE ALL FILES IN WORKING DIRECTORY TO ALLOW FUTURE REQUESTS TO PROCESS // WITHOUT PROBLEMS. DeleteFolder(workingDirectory); } catch { } } }
/// <summary> /// Handle communication message. /// </summary> /// <param name="msg"></param> protected override void HandleCommunicationMessage(CommMessage msg) { requestQueue.EnQ(msg); }
public void communication() { Console.WriteLine("BuilderStarted"); while (true) { CommMessage a = comm.getMessage(); if (a.type == CommMessage.MessageType.request) { a.show(); CommMessage comMsg = new CommMessage(CommMessage.MessageType.reply); comMsg.from = "http://localhost:" + port + "/IMessagePassingComm"; comMsg.to = "http://localhost:8081/IPluggableComm"; comMsg.author = "Nitsh Kumar"; comm.postMessage(comMsg); } if (a.type == CommMessage.MessageType.test) { string path = a.command; string readText = File.ReadAllText(RepoEnvironment.fileStorage + "\\" + path); TestRequest test = readText.FromXml <TestRequest>(); Console.WriteLine("test xml" + test.ToString()); } if (a.type == CommMessage.MessageType.reply) { string path = ""; a.show(); try { path = File.ReadAllText(Path.Combine(RepoEnvironment.fileStorage, a.command)); } catch (Exception E) { Console.WriteLine("Exception " + E.Message); } TestRequest tr = path.FromXml <TestRequest>(); fileList.Clear(); foreach (TestElement test in tr.tests) { fileList.Add(test.testDriver); foreach (string testfile in test.testCodes) { Console.WriteLine(test); fileList.Add(testfile); } } CommMessage comMsg = new CommMessage(CommMessage.MessageType.file); comMsg.from = "http://localhost:" + port + "/IMessagePassingComm"; comMsg.to = "http://localhost:8081/IPluggableComm"; comMsg.author = "Nitsh Kumar"; comMsg.arguments.AddRange(fileList); comm.postMessage(comMsg); Console.WriteLine("Request to Repo"); connectRepo(); } if (a.type == CommMessage.MessageType.file) { Console.WriteLine("Files received from Repo\n"); a.show(); try { createdll(fileList); } catch (Exception e) { Console.WriteLine("Exception " + e.Message); } } } }
public void fortest(CommMessage msg) { msg.show(); sndr.postMessage(msg); }
/*----< define how each message will be processed >------------*/ void initializeDispatcher() { // process the message and reply the new files address Func <CommMessage, CommMessage> Start_Browse_Files = (CommMessage msg) => { Environment.Environment.root = msg.arguments[0]; Console.WriteLine(Environment.Environment.root); localFileMgr.pathStack.Clear(); msg.arguments.Clear(); localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Start_Browse_Files"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["Start_Browse_Files"] = Start_Browse_Files; // process the message and reply the new dirs address Func <CommMessage, CommMessage> Start_Browse_Dirs = (CommMessage msg) => { Environment.Environment.root = msg.arguments[0]; localFileMgr.pathStack.Clear(); msg.arguments.Clear(); localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Start_Browse_Dirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["Start_Browse_Dirs"] = Start_Browse_Dirs; // process the message and reply the new message to get top files Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) => { localFileMgr.pathStack.Clear(); msg.arguments.Clear(); localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["getTopFiles"] = getTopFiles; // process the message and reply the new message to get top dirs Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) => { localFileMgr.pathStack.Clear(); msg.arguments.Clear(); localFileMgr.currentPath = ""; CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "getTopDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["getTopDirs"] = getTopDirs; // process the message and reply the new message to move into next files Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles; // process the message and reply the new message to move into next dirs Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) => { string dirName = msg.arguments.Last().ToString(); localFileMgr.pathStack.Push(localFileMgr.currentPath); localFileMgr.currentPath = dirName; Console.WriteLine("now add ress : --------------{0}", dirName); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "moveIntoFolderDirs"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs; // process the message and reply the new message to double click files Func <CommMessage, CommMessage> DoubleClickFiles = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "DoubleClickFiles"; reply.arguments = msg.arguments; return(reply); }; messageDispatcher["DoubleClickFiles"] = DoubleClickFiles; // process the message and reply the new message to go back upper dirs Func <CommMessage, CommMessage> GoToUpDir = (CommMessage msg) => { if (localFileMgr.currentPath != "") { localFileMgr.currentPath = localFileMgr.pathStack.Peek(); localFileMgr.pathStack.Pop(); } else { localFileMgr.currentPath = ""; } CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "GoToUpDir"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["GoToUpDir"] = GoToUpDir; // process the message and reply the new message to go back upper files Func <CommMessage, CommMessage> GoToUpFiles = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "GoToUpFiles"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["GoToUpFiles"] = GoToUpFiles; // process the message and reply the new message to typetable analysis Func <CommMessage, CommMessage> Rq_Analysis_Ttable = (CommMessage msg) => { List <string> files = new List <string>(); string path = Path.Combine(Environment.Environment.root, localFileMgr.currentPath); Console.WriteLine(" string path = Path.Combine(Environment.Environment.root,localFileMgr.currentPath) --- list: {0}", path); string absPath = Path.GetFullPath(path); Console.WriteLine(" string absPath = Path.GetFullPath(path); --- list: {0}", absPath); localFileMgr.FindFile(absPath); files = localFileMgr.all_files; string[] xx = files.ToArray(); TypeTable t_table = new TypeTable(); foreach (var aa in xx) { Console.WriteLine(aa); } t_table = t_table.getTypeTable(files.ToArray()); string result = t_table.tt_to_string(); Console.WriteLine("----------------------------------- {0}", result.Length); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Rq_Analysis_Ttable"; reply.arguments.Clear(); if (result.Length > 1024) { string pp = ""; for (int i = 0; i < result.Length; i++) { pp += result[i]; if (pp.Length >= 1024) { reply.arguments.Add(pp); pp = ""; } } reply.arguments.Add(pp); pp = ""; } else { reply.arguments.Add(result); } localFileMgr.all_files.Clear(); return(reply); }; messageDispatcher["Rq_Analysis_Ttable"] = Rq_Analysis_Ttable; // process the message and reply the new message to Dependency analysis Func <CommMessage, CommMessage> Rq_Analysis_Depend = (CommMessage msg) => { List <string> files = new List <string>(); string path = Path.Combine(Environment.Environment.root, localFileMgr.currentPath); Console.WriteLine(" string path = Path.Combine(Environment.Environment.root,localFileMgr.currentPath) --- list: {0}", path); string absPath = Path.GetFullPath(path); Console.WriteLine(" string absPath = Path.GetFullPath(path); --- list: {0}", absPath); localFileMgr.FindFile(absPath); files = localFileMgr.all_files; DepAnalysis depend_analysis = new DepAnalysis(); depend_analysis.match(files.ToArray()); string result = depend_analysis.dep_tostring(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Rq_Analysis_Depend"; reply.arguments.Clear(); if (result.Length > 1024) { string pp = ""; for (int i = 0; i < result.Length; i++) { pp += result[i]; if (pp.Length >= 1024) { reply.arguments.Add(pp); pp = ""; } } reply.arguments.Add(pp); pp = ""; } else { reply.arguments.Add(result); } localFileMgr.all_files.Clear(); return(reply); }; messageDispatcher["Rq_Analysis_Depend"] = Rq_Analysis_Depend; // process the message and reply the new message to Strong componenet analysis Func <CommMessage, CommMessage> Rq_Analysis_SCC = (CommMessage msg) => { List <string> files = new List <string>(); string path = Path.Combine(Environment.Environment.root, localFileMgr.currentPath); Console.WriteLine(" string path = Path.Combine(Environment.Environment.root,localFileMgr.currentPath) --- list: {0}", path); string absPath = Path.GetFullPath(path); Console.WriteLine(" string absPath = Path.GetFullPath(path); --- list: {0}", absPath); localFileMgr.FindFile(absPath); files = localFileMgr.all_files; CsGraph <string, string> scc = new CsGraph <string, string>("scc"); string result = scc.show_strong(files.ToArray()).SC_tostring(); CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "Rq_Analysis_SCC"; reply.arguments.Clear(); if (result.Length > 1024) { string pp = ""; for (int i = 0; i < result.Length; i++) { pp += result[i]; if (pp.Length >= 1024) { reply.arguments.Add(pp); pp = ""; } } reply.arguments.Add(pp); pp = ""; } else { reply.arguments.Add(result); } localFileMgr.all_files.Clear(); return(reply); }; messageDispatcher["Rq_Analysis_SCC"] = Rq_Analysis_SCC; // process the message and reply the new message to connect to server and obtain files Func <CommMessage, CommMessage> ConnectToServerFile = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "ConnectToServerFile"; reply.arguments = localFileMgr.getFiles().ToList <string>(); return(reply); }; messageDispatcher["ConnectToServerFile"] = ConnectToServerFile; // process the message and reply the new message to connect to server and obtain dirs Func <CommMessage, CommMessage> ConnectToServerDir = (CommMessage msg) => { CommMessage reply = new CommMessage(CommMessage.MessageType.reply); reply.to = msg.from; reply.from = msg.to; reply.command = "ConnectToServerDir"; reply.arguments = localFileMgr.getDirs().ToList <string>(); return(reply); }; messageDispatcher["ConnectToServerDir"] = ConnectToServerDir; }
/*----< listen thread of Client which listens to the incoming message >-----------------------------------------*/ void listen() { while (true) { ClientEnvironment.verbose = true; CommMessage crcvMsg = comm.getMessage(); if (crcvMsg.body != null) { if (ClientEnvironment.verbose) { crcvMsg.show(); } if (crcvMsg.command.Equals("csFileListFromRepo")) { Console.WriteLine(crcvMsg.body); csFileListFromRepo(crcvMsg.body); } if (crcvMsg.command.Equals("xmlsaved")) { refreshXmlList(); } if (crcvMsg.command.Equals("deleterequest")) { if (crcvMsg.body.Equals("success")) { refreshXmlList(); } else { MessageBox.Show(String.Format(crcvMsg.body)); } } if (crcvMsg.command.Equals("deletefiles")) { if (crcvMsg.body.Equals("success")) { refreshCsList(); } else { MessageBox.Show(String.Format(crcvMsg.body)); } } if (crcvMsg.command.Equals("xmlFileListFromRepo")) { xmlFileListFromRepo(crcvMsg.body); } if (crcvMsg.command.Equals("notification")) { Action act = () => { AddInNotificationList(crcvMsg.body); }; string[] args = new string[] { }; Dispatcher.Invoke(act, args); } if (crcvMsg.command.Equals("fileContents")) { showcontents(crcvMsg.body); } } Thread.Sleep(1000); } }
// 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; } } }
public void communication() { Console.WriteLine("Receiver started on Repo"); string port = ""; while (true) { CommMessage a = c.getMessage(); //if(a.type == CommMessage.MessageType.connect) //{ // Console.WriteLine("Connected to child"); //} if (a.type == CommMessage.MessageType.request) { fileList = a.arguments; port = a.command; Console.WriteLine("File Transfer Request received from child :" + port + "\n"); a.show(); string targetpath = @"..//..//..//ChildProc//" + port; string sourcepath = @"..//..//..//MockRepo//RepoStorage"; string[] files = System.IO.Directory.GetFiles(sourcepath, "*.cs"); foreach (string s in files) { string fileName = System.IO.Path.GetFileName(s); string destFile = System.IO.Path.Combine(targetpath, fileName); System.IO.File.Copy(s, destFile, true); } Console.WriteLine("File successfully transferred to: " + targetpath + "\n"); CommMessage comMsg = new CommMessage(CommMessage.MessageType.file); comMsg.from = "http://*****:*****@"..//..//..//MockRepo//RepoStorage//BuildLog" + System.DateTime.Now.Millisecond + ".txt"; var myFile = File.Create(path); myFile.Close(); StreamWriter SW = new StreamWriter(path); SW.WriteLine(a.command); SW.Close(); Console.WriteLine("\n\n===============Build log received @ : " + path + "\n\n"); Console.WriteLine("Build Log : " + a.command + "\n\n"); } catch (Exception e) { Console.WriteLine(e.Message); } } if (a.type == CommMessage.MessageType.file) { a.show(); string path = @"..//..//..//MockRepo//RepoStorage//TestLog" + System.DateTime.Now.Millisecond + ".txt"; var myFile = File.Create(path); myFile.Close(); StreamWriter SW = new StreamWriter(path); SW.WriteLine(a.command); SW.Close(); Console.WriteLine("\n\n===============Test log received @ : " + path + "\n\n"); Console.WriteLine("Test Log : " + a.command + "\n\n"); } } }
/*----< enqueue a message for transmission to a Receiver >-----*/ public void postMessage(CommMessage msg) { rcvQ.enQ(msg); }
public RobotStateBuildSatellite(Robot r, CommMessage msg) { initialCommand = msg; }
/*----< main thread enqueues message for sending >-------------*/ public void postMessage(CommMessage msg) { sndQ.enQ(msg); }
/*----< post message to remote Comm >--------------------------*/ public void postMessage(CommMessage msg) { sndr.postMessage(msg); }
/// <summary> /// Dispatches request to comm object. /// </summary> /// <param name="message"></param> public void DispatchMessage(CommMessage message) { this.commObject.PostMessage(message); }