void OneNewBRMessageHandler(CommMessage msg) { try { if (msg.type == CommMessage.MessageType.build) { msg.show(); templist = new List <string>(); parseXML(msg); foreach (var a in ReadyList) { if (a.Value == true) { tempport = sndrport + a.Key; if (transfer()) { msg.to = "http://localhost:" + tempport + "/IMessagePassingComm"; msg.from = motherAddress; Console.Write("\n ================== Msg goes to: " + msg.to + "\n================="); msg.show(); sndr.postMessage(msg); } break; } } } } catch (Exception ex) { Console.Write("\n\n The error reason in OneNewBRMessageHandler is {0}\n\n", ex.Message); } }
/*-------------builder loop: process the request from the parent process--------------*/ public void ChildLoop() { while (true) { CommMessage msg = ChdComm.getMessage(); msg.show(); if (msg.type == CommMessage.MessageType.close) { Process pro = Process.GetCurrentProcess(); pro.Kill(); } else if (msg.command == "build" && msg.type != CommMessage.MessageType.connect) { msg.command = "send xml"; msg.to = msg.from; msg.from = localAddress; msg.show(); ChdComm.postMessage(msg); checkXml(msg); } else if (msg.command == "start build") { tryToBuild(msg.fileStorage, msg.size); } else if (msg.command == "send dll") { postDllFile(msg); } else if (msg.command == "tester ready") { ready(); } } }
//<--------------function that handles incoming messages to Mock Repository---------------------> public void handleincomingmessages() { while (true) { CommMessage msg = comm.getMessage(); if (msg.command == "Please send the specified file in the Message") { Console.WriteLine("\n"); Console.WriteLine("Mock Repository recieved message from " + msg.from); msg.show(); Console.WriteLine("\n"); Console.WriteLine("Mock repository processing the Request"); Console.WriteLine("\n"); bool val = this.comm.sendfile(msg.filename, msg.from); Console.WriteLine("File Transfer status " + val); Console.WriteLine("\n"); sendbuildermessage(msg); } if (msg.command == "BuildRequestFileName") { Console.WriteLine("Mock repo recived request from Mock client"); Console.WriteLine("\n"); msg.show(); Console.WriteLine("forwarding the request to Build server"); CommMessage csndMsg = msg; csndMsg.to = serveraddress; csndMsg.from = repoaddress; this.comm.postMessage(csndMsg); csndMsg.show(); } } }
//Receive the messege from other components and perform required actions public void getMessege() { while (true) { CommMessage csndMsg1 = c.getMessage(); Console.WriteLine("Messege received"); csndMsg1.show(); if (csndMsg1.type.ToString() == "request") { csndMsg1.show(); string testRequest = csndMsg1.body; Console.WriteLine("Body is::" + testRequest); XMLHandler x = new XMLHandler(); string testRequestContent = File.ReadAllText("../../../THStorage/" + testRequest); x.loadXml(testRequestContent); List <string> testDrivers = x.parseList("tested"); foreach (string temp in testDrivers) { Console.WriteLine("TEMP:" + temp); requestFile(temp); } Thread.Sleep(2000); DllLoader d = new DllLoader(log.getFileName()); d.loadDlls(testDrivers); sendFile("../../../RepoStorage", "THLog.txt"); } } }
public override void messageHandler(CommMessage msg) { if (msg.type == CommMessage.MessageType.connect) { Console.WriteLine("\nConnection with Mother Builder established\n"); } else if (msg.type == CommMessage.MessageType.closeReceiver) { } else { switch (msg.command) { case "ready": Console.WriteLine("\n In Mother Builder message handler with \"ready\" \n"); //readyStatusQ.enQ(msg.from); msg.show(); Console.WriteLine("\n In Mother Builder message handler with \"ready\" - Enqueue done\n"); break; case "buildRequest": Console.WriteLine("\n In Mother Builder message handler with \"buildRequest\" \n"); //buildRequestQ.enQ(msg); msg.show(); Console.WriteLine("\n In Mother Builder message handler with \"buildRequest\" - Enqueue done\n"); break; } } }
//<--------------function that handles incoming messages to Mock Repository---------------------> public void handleincomingmessages() { while (true) { CommMessage msg = comm.getMessage(); if (msg.command == "Please send the specified file in the Message") { Console.WriteLine("\n"); Console.WriteLine("Mock Repository recieved message from " + msg.from); msg.show(); Console.WriteLine("\n"); Console.WriteLine("Mock repository processing the Request"); Console.WriteLine("\n"); bool val = this.comm.sendfile(msg.filename, msg.from, msg.builderId); Console.WriteLine("File Transfer status " + val); Console.WriteLine("\n"); sendbuildermessage(msg); } if (msg.command == "BuildRequestFileName") { sendmessagetobuildserver(msg); } if (msg.command == "filelist") { Console.WriteLine("\n"); Console.WriteLine("Mock Repository recieved message from " + msg.from); msg.show(); Console.WriteLine("\n"); handlefilelistrequest(msg); } if (msg.command == "Repocontents") { handlerepocontentlist(msg); } if (msg.command == "sendxmlfilelist") { handlexmlfilelist(msg); } if (msg.command == "filexmlrequest") { validatebuildrequest(msg); } if (msg.command == "buildlog") { savesbuildlog(msg); } if (msg.command == "Testlog") { savestestlog(msg); } if (msg.command == "logs") { sendlogstoclient(msg); } if (msg.command == "logfilelist") { sendlogfilelist(msg); } } }
/*Process incoming messages and take suitable action*/ private static void processMessage(string portN) { switch (rcv.command) { case "Parse": { Parse_method(portN); Console.WriteLine("\nRequirement: 6"); rcv.show(); break; } case "BuildCodes": { BuildCodes_method(portN); rcv.show(); break; } case "XmlConnect": { XmlConnect_method(portN); rcv.show(); break; } case "ParseXml": { ParseXml_method(portN); rcv.show(); break; } } }
///////////////////// Receiver listning for any incoming file static void listen() { while (true) { rcMsg = rc.getMessage(); switch (rcMsg.command) { case "m_ready": { rcMsg.show(); readyQ.enQ(Int32.Parse(rcMsg.from)); break; } case "sendR2MP": { rcMsg.show(); brQ.enQ(rcMsg.arguments[0]); break; } case "KillMP": { rcMsg.show(); killMother(); break; } default: break; } } }
/*----------------------------< receivers' thread that extracts messages from Repository's receiver blocking queue >-------------------------*/ void rcvThreadProc() { while (true) { try{ CommMessage msg = comm.rcvr.GetMessage(); //dequeues a comm message from Repositorys' blocking queue switch (msg.command) //switch statement that gets operated based on command given in the comm message { case "SendFilestoRepo": string[] files = msg.body.Split(','); //gets file names that user wants to transfer from his local storage to Repository Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received at Repository from GUI. Purpose - List of file names that user wants to transfer from local storage to Reposiotry Storage"); Console.ResetColor(); msg.show(); foreach (var item in files) { postFile(item, @"../../../Local_storage/"); //Repository copies those files using Push model } break; case "AskRepotoSendFilestoBuilder": sendfileToBuilder(msg.body); //gets comm message from GUI where GUI asks repository to send selected build requests to mother builder Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received at Repository from GUI. Purpose - Gets request & file names of selected build request to send to MotherBuilder"); Console.ResetColor(); msg.show(); break; case "SendBuildLog": //gets comm message from child builder containing build log file name string[] transfer_data = msg.body.Split(','); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received at Repository from ChildBuilder. Purpose - Gets BuildLog file name/s after building build request"); Console.ResetColor(); msg.show(); postFile(transfer_data[0], transfer_data[1]); //Repository copies that build log file using Push model break; case "SendTestLog": //gets comm message from Test Harness containing test log file name string[] file_data = msg.body.Split(','); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received at Repository from TestHarness. Purpose - Gets TestLog file name/s after testing build request"); Console.ResetColor(); msg.show(); if (postFile(file_data[0], file_data[1])) //Repository copies that test log file using Push model { if (file_data[2] == "true") { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Testing Successful! Deleting Temporary Directory"); Console.ResetColor(); try { Directory.Delete(file_data[1], true); } catch (Exception e) { Console.WriteLine(e.Message); } } } break; case "RequestToGetFiles": Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received at Repository from GUI. Purpose - Request from GUI to get List of file names of currently present files in the Repository"); Console.ResetColor(); msg.show(); show_file(); //calling show_file() function which will send present file names to GUI break; case "quit": break; //if command is to quit then break default: break; } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public void communication() { Console.WriteLine("Receiver started on mother builder"); while (true) { CommMessage a = c.getMessage(); if (a.type == CommMessage.MessageType.kill) { a.show(); killProcesses(); DeleteFolder(); Console.WriteLine("================All the child processes killed================"); } if (a.type == CommMessage.MessageType.request) { a.show(); string child = a.command; Console.WriteLine("===============Communication from GUI to mother Process started & " + child + " child processes created================"); createChild(child); } if (a.type == CommMessage.MessageType.reply) { a.show(); } if (a.type == CommMessage.MessageType.test) { a.show(); int port = list.First(); Console.WriteLine("" + port); string testPath = a.command; CommMessage comMsg = new CommMessage(CommMessage.MessageType.reply); comMsg.from = "http://localhost:8081/IMessagePassingComm"; comMsg.to = "http://localhost:" + port + "/IPluggableComm"; comMsg.author = "Nitsh Kumar"; comMsg.command = testPath; c.postMessage(comMsg); list.Remove(port); list.Add(port); } if (a.type == CommMessage.MessageType.file) { a.show(); fileList.Clear(); fileList.AddRange(a.arguments); Thread t = new Thread(new ThreadStart(sendFiles)); t.Start(); } } }
/*-------------------------< receivers' thread that extracts messages from childBuilder's receiver blocking queue >---------------------------*/ void rcvThreadProc() { while (true) { try{ CommMessage msg = comm.rcvr.GetMessage(); //dequeues a comm message from ChildBuilders' blocking queue if (msg.body == null) { Console.WriteLine("Waiting for Build Request.........."); break; } postFile(msg.body, @"../../../Repository/Repo_storage/", temp_directory_path); //copies the build request file at temp directory through Push model Dictionary <string, List <string> > testfiles = new Dictionary <string, List <string> >(); int count = 1; testfiles = XMLParser.xmlparser(temp_directory_path + @"/" + msg.body); //gets buildrequest stored in the temp directory and parses it testelement_count = testfiles.Count; Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Gray; Console.Write("\n Requirement 3 [Part 1]\n"); Console.ResetColor(); Console.WriteLine("The Communication Service shall support accessing build requests by Pool Processes from the mother Builder process, receiving build requests, sending and receiving files.\n"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received from from MotherBuilder at ChildBuilder. Purpose - buildrequest to build"); Console.ResetColor(); msg.show(); string xmlString = null; if (msg.body != "quit") //if the msg is not quit but it's a build request then it prints it's content on the console { xmlString = File.ReadAllText(temp_directory_path + @"/" + msg.body); } Console.WriteLine(xmlString); foreach (string key in testfiles.Keys) { string[] filenames = testfiles[key].ToArray(); for (int i = 0; i < filenames.Length; i++) { postFile(filenames[i], @"../../../Repository/Repo_storage/", temp_directory_path); } if (buildFiles(filenames, count)) //builds the dll file for given build request { Console.WriteLine("Stroing generated dll file at : {0}", temp_directory_path); } count++; } if (msg.command == "quit") { break; } if (msg.command == "SendFreemsg") { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received from TestHarness at ChildBuilder. Purpose - relasing child builder from current build request so that it can send ready msg to mother builder to accept next buildrequest"); Console.ResetColor(); msg.show(); sendReadymsg(true); } } catch (Exception e) { Console.WriteLine(e.Message); } } }
/*--------< runs as a background thread to check any kind of messages including TestRequest and DLLFIleSent message >----*/ private void checkMessage() { while (true) { Console.WriteLine("TestHarness is checking an incoming message via MessagePassingComm service on thread {0}", Thread.CurrentThread.ManagedThreadId); CommMessage crcvMsg = comm.getMessage(); if (crcvMsg.command == "TestRequest") { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("TestHarness has received a TestRequest" + " message from child via MessagePassingComm service on thread {0}", Thread.CurrentThread.ManagedThreadId); Console.ResetColor(); crcvMsg.show(); _childPort = crcvMsg.arguments[0]; if (_childPort != null) { crcvMsg.arguments.RemoveAt(0); } if (crcvMsg.from == "http://localhost:" + _childPort + "/IPluggableComm") { _testRequestFileName = crcvMsg.arguments[0]; Thread.Sleep(300); xmlDeserialization <string>(_testHarnessStoragePath, _testRequestFileName); replyRequestedDllFilesToChildProc(_files); } } else if (crcvMsg.command == "DllFilesSent") { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("TestHarness has received dllfiles" + " message from child via MessagePassingComm service on thread {0}", Thread.CurrentThread.ManagedThreadId); Console.ResetColor(); crcvMsg.show(); _childPort = crcvMsg.arguments[0]; if (_childPort != null) { crcvMsg.arguments.RemoveAt(0); } if (crcvMsg.from == "http://localhost:" + _childPort + "/IPluggableComm") { Thread.Sleep(1500); TestAllFiles(); } } else { TestUtilities.putLine(string.Format("There's no incoming message on thread {0}\r\n", Thread.CurrentThread.ManagedThreadId)); } } }
/*-------------------------< receivers' thread that extracts messages from MotherBuilder's receiver blocking queue >--------------------------*/ void rcvThreadProc() { while (true) { try { CommMessage msg = comm.rcvr.GetMessage(); //dequeues a comm message from MotherBuilders' blocking queue switch (msg.command) //switch statement that gets operated based on command given in the comm message { case "processCountfromGUI": process_count = Convert.ToInt32(msg.body); //gets a number for how many child builder processes to spawn Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received from GUI at MotherBuilder. Purpose - gets count from GUI for number of child builder processes to spawn"); Console.ResetColor(); msg.show(); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Gray; Console.Write("\n Requirement 5\n"); Console.ResetColor(); Console.WriteLine("Shall provide a Process Pool component that creates a specified number of processes on command. \n"); for (int i = 0; i < process_count; i++) { if (createProcess(i, Convert.ToString(9000 + i))) //spawns child builder processes of count given by GUI { Console.WriteLine("Status - Successful"); } else { Console.WriteLine("Status - Failed"); } } break; case "ready": Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received from ChildBuilder at MotherBuilder. Purpose - gets ready msg from spawned child builder/s so that it can decide where to send the build request"); Console.ResetColor(); msg.show(); sendfilesto_childBuilder(msg.body); //send build request file/s to child builder/s only after getting ready message from them break; case "SendBRstoBuilder": string file_names = msg.body; //receives build request/s file name/s from Repository [sent on command from GUI] string[] files = file_names.Split(','); build_request_filenames = files.ToList(); //saves those file names into a list Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nMessage Received from Repository at MotherBuilder. Purpose - accepts the buildrequest file name/s from repository on which user wants to perform build operation"); Console.ResetColor(); msg.show(); break; case "quit": break; //if command is to quit then break default: break; } } catch (Exception e) { Console.WriteLine(e.Message); } } }
/*process incoming message and take suitable action*/ private static void processmessage() { //Process the received messages switch (rmsg.command) { case "Xml": { Xml_method(); //If message command is xml start a connection break; } case "sendXml": //If message command is sendXml, send the xml file { rmsg.show(); sendxml_method(); break; } case "sendFiles": { //If message command is sendFiles, send the source files rmsg.show(); sendFiles_method(); break; } case "GetSourceFiles": { GetSourceFiles_method(); break; } case "GetXmlFiles": { GetXmlFiles_method(); break; } case "ConnectHarness": { ConnectHarness(); break; } case "spawnchilds": { spawnchilds_method(); break; } } }
//<------------- sends Test request and dll files to Mock test harness----------------------> private void sendfilestoharness(List<string> driverlist, string filename) { Console.WriteLine("\nSending the Test Request and dll files to the Mock Test harness DLLRepository Folder \n"); string source = "../../../CoreBuilder/Builderstorage/" + builderId; string temp = builderId; temp = temp.Replace("Builder", ""); temp = temp + "Files"; string destination = "../../../MockTestHarness/DLLRepository/" + temp; this.comm.transferfile(filename, source, destination, harnessaddress); foreach (string str in driverlist) { this.comm.transferfile(str, source, destination, harnessaddress); } Console.WriteLine("\nDll Files and Test Request sent to " + destination); Console.WriteLine("\n"); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "executedll"; csndMsg.author = "RamaTejaRepaka"; csndMsg.to = harnessaddress; csndMsg.from = myAddress; csndMsg.filename = filename; csndMsg.builderId = temp; csndMsg.arguments = driverlist; Console.WriteLine("Sending the request to Mock Test Harness"); Console.WriteLine("\n"); this.comm.postMessage(csndMsg); csndMsg.show(); Console.WriteLine("\n"); }
//----------------< A thread that deques the messages from the reciever queue >-------------- void rcvThreadProc() { Console.WriteLine("\n Starting Recive Thread of Mother Build Server"); while (true) { CommMessage msg = comm.getMessage(); msg.show(); Console.WriteLine("\nReady size {0}", readyQueue.size()); Console.WriteLine("\nRequest size {0}", requestQueue.size()); if (msg.type == CommMessage.MessageType.connect) { continue; } initializeMessageDispatcher(msg); initializechildBuilder(msg); if (msg.command == null) { continue; } if ((msg.command).Equals("SpawnProcess")) { Console.ForegroundColor = ConsoleColor.DarkBlue; Console.Write("\n==========================================\nRequirement # 5 Process Pool\n==========================================\n"); Console.ResetColor(); spawnProcessPool(msg.numProcess); } } }
/*--------------------------<thread which receives messages from repository and child continuously>------------------------*/ public void receiveMessages() { Thread threadreceive = new Thread(() => { while (true) { CommMessage m = receiver.getMessage(); m.show(); if (m.from == "Repo" && m.command == "Post_XML") { insertIntoBlockQueue(m); } if (m.from == "Child" && m.command == "Ready") { foreach (string s in m.arguments) { readyqueue.enQ(Int32.Parse(s)); } } if (m.command == "Quit" && m.from == "GUI") { sendQuit(); //flag = false; //break; } } }); threadreceive.Start(); }
//---------------------------------< Get filelist from repo make build test libraries send logs to repo >-------- void messageFileListHelper(CommMessage msg) { msg.show(); requestRepoForFilesBuildDll(Data, ChildBuildServer.root, ChildBuildServer.root); this.comm.postMessage(this.readymsg); CommMessage log = msg.clone(); log.type = CommMessage.MessageType.BuildLog; log.to = Repository.endPoint; log.from = EnvironmentSet.endPoint; log.body = doc; Console.Write("\n========================================================\n Requirement #7 : Build Logs Sending to RepoStorage\n======================================================="); Console.Write("\nBuild Log:\n{0}", log.body); this.comm.postMessage(log); this.comm.postMessage(blib.rply); if (this.toolChain.Equals("C#")) { if (tRmsg.body != null) { Console.WriteLine("\n===========================================\n Requirement #8 :Sending Test Request To Test Harness \n==========================================="); Console.WriteLine("\nTest Request::{0}\n", tRmsg.body); this.comm.postMessage(this.tRmsg); } } return; }
/*-----------------------< Sends communication message to Repository asking repository to send the build request file/s to Mother builder >--------------------*/ public void send_BR_toBuilder(object sender, RoutedEventArgs e) { try { CommMessage msg = new CommMessage(CommMessage.MessageType.SendBuildRequest); msg.from = endPoint; msg.to = Comm <MainWindow> .makeEndPoint("http://localhost", 8081, "Repository"); //Repository receiving end point at port address 8081 msg.command = "AskRepotoSendFilestoBuilder"; string files = ""; foreach (var item in listBox3.SelectedItems) { string str = item.ToString(); //gets selected build request file names from list box 3 if (str.Length > 18) { str = str.Remove(0, 37); } files += str + ","; } msg.body = files; //send these build request file names to Repository comm.sndr.PostMessage(msg); brSent.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green); brSent.Text = "Build Request/s Sent!"; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nMessage Sent from GUI to Repository. Purpose - Request to repository to send selected build request/s in its storage to the Build Server"); Console.ResetColor(); msg.show(); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Gray; Console.Write("Requirement 13 \n"); Console.ResetColor(); Console.WriteLine("The client shall be able to request the repository to send a build request in its storage to the Build Server for build processing. \n"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { try { int port_addr = Int32.Parse(args[0]); Console.Title = "Child Builder " + port_addr.ToString(); ChildBuilder cBuilder = new ChildBuilder(port_addr); //starts child builder at port address given by mother builder if (cBuilder.comm.sndr.getReadyblockingQ_size() <= 0) { CommMessage msg = new CommMessage(CommMessage.MessageType.BuildRequest); string remoteEndPoint = Comm <ChildBuilder> .makeEndPoint("http://localhost", 8082, "MotherBuilder"); msg.to = remoteEndPoint; msg.from = cBuilder.endPoint; msg.command = "ready"; msg.body = port_addr.ToString(); cBuilder.comm.sndr.PostMessage(msg); //sends ready message to mother builder cBuilder.comm.sndr.PostReadyMessage(msg); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nMessage Sent from ChildBuilder to MotherBuilder. Purpose - At start after spawning, sends ready msg to mother builder to accept next buildrequest"); Console.ResetColor(); msg.show(); } } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadKey(); }
/*---------------check whether the Xml file has been sent or not, * if yes, ask for files in the Xml---------------*/ private void checkXml(CommMessage msg) { int tryCount = 0; while (!getFileNames(chdXmlPath).Contains(msg.xmlName)) { List <string> files = getFileNames(chdXmlPath); if (tryCount++ == maxCount) { Console.Write("\n Time out, please try to debug again \n"); return; } Console.Write("\n tried {0} times \n", tryCount); Thread.Sleep(500); } try { parseXml(msg.xmlName); } catch (Exception e) { Console.Write("\n {0} \n", e.Message); } string dirPath = Path.Combine(fileStorage, msg.xmlName); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } currentDirPath = dirPath; msg.type = CommMessage.MessageType.reply; msg.command = "send file"; msg.to = "http://localhost:8080/IPluggableComm"; msg.from = localAddress; msg.dirName = dir; msg.size = size; msg.arguments = files; msg.fileStorage = Path.GetFullPath(dirPath); msg.show(); ChdComm.postMessage(msg); }
/*-------------thread for continuously receiving messages from the other modules ------------*/ public void rcvProcThread() { Thread thr = new Thread(() => { Console.Write("\n starting client's receive thread"); while (true) { CommMessage msg = receiver.getMessage(); msg.show(); if (msg.command == "Create_Request" && msg.from == "Repo") { } if (msg.command == "Append_Request" && msg.from == "Repo") { openFile(System.IO.Path.Combine(path, msg.arguments.ElementAt(0))); } if ((msg.command == "Display_Build_Log" || msg.command == "Display_Test_Log") && msg.from == "Repo") { openFile(System.IO.Path.Combine(generated_path, msg.arguments.ElementAt(0))); } } }); thr.Start(); }
//---------------------< Recieve thread of the reciever >----------------------- void rcvThreadProc() { Console.Write("\n Starting client's receive thread"); try { while (true) { CommMessage msg = comm.getMessage(); msg.show(); if (msg.type == CommMessage.MessageType.TestResult) { Console.WriteLine("\n===========================================\n Requirement #7 & #9 : Showing Build or Test Status \n==========================================="); Dispatcher.Invoke( new Action <String>(showPath), System.Windows.Threading.DispatcherPriority.Background, new String[] { msg.body } ); } if (msg.command == null) { continue; } // pass the Dispatcher's action value to the main thread for execution Dispatcher.Invoke(messageDispatcher[msg.command], new object[] { msg }); } } catch (Exception e) { Console.WriteLine("Caught a exception{0}", e.Message); } }
/*----< receive thread processing >----------------------------*/ void threadProc() { while (true) { try { CommMessage msg = comm_.getMessage(); Console.Write("\n Received {0} message : {1}", msg.type.ToString(), msg.command.ToString()); CommMessage reply = dispatcher_.doCommand(msg.command, msg); if (reply.command == Msg.Command.show) { reply.show(); Console.Write(" -- no reply sent"); } if (doReply(msg, reply)) { comm_.postMessage(reply); } } catch { break; } } }
static void Main(String[] args) { Console.Title = "Child:" + args[0].ToString(); int ini_port = 8095; int port = ini_port + Int32.Parse(args[0]); proc_num = proc_num + Int32.Parse(args[0]); Console.WriteLine(); Console.WriteLine("**************************************************************"); Console.WriteLine("*********** Inside Child: {0} With Port Number :{1}***********", proc_num, port); Console.WriteLine("**************************************************************"); // send msg from child process to mother builder for connection// comm = new Comm("http://localhost", port); Thread child_thread = null; child_thread = new Thread(listen_child_thread); child_thread.Start(); str_port = port; CommMessage send_msg = new CommMessage(CommMessage.MessageType.request); send_msg.command = "from child:" + Int32.Parse(args[0]); send_msg.author = "Salim Zhulkhrni"; send_msg.to = "http://localhost:8091/IPluggableComm"; send_msg.from = "http://localhost:" + port + "/IMessagePassingComm"; send_msg.msg_body = "child"; send_msg.port_number = port; comm.postMessage(send_msg); Console.WriteLine(); Console.WriteLine("**************************************************************"); Console.WriteLine(" Sending Message From Child:{0} To Mother Builder", proc_num); Console.WriteLine("**************************************************************"); send_msg.show(); Console.WriteLine(); }
//----< loop to get message and execute the corresponding operation >----------------- private void testerLoop() { Console.Write("The test path is: {0}", pathToTestLibs_); while (true) { CommMessage msg = testerComm.getMessage(); msg.show(); if (msg.command == "test") { string dirName = "TestLog" + (logCount++); currentFileStorage = Path.Combine(fileStorage, dirName); if (!Directory.Exists(currentFileStorage)) { Directory.CreateDirectory(currentFileStorage); } logName = dirName + ".txt"; msg.fileStorage = currentFileStorage; msg.to = msg.from; msg.from = localAddress; msg.command = "send dll"; testerComm.postMessage(msg); checkDll(); postLog(); postReadyMsg(msg); } else if (msg.command == "close") { Process pro = Process.GetCurrentProcess(); pro.Kill(); } } }
/*----< Server processing >------------------------------------*/ /* * - all server processing is implemented with the simple loop, below, * and the message dispatcher lambdas defined above. */ static void Main(string[] args) { TestUtilities.title("Starting Navigation Server", '='); try { NavigatorServer server = new NavigatorServer(); server.initializeDispatcher(); server.comm = new MessagePassingComm.Comm(ServerEnvironment.address, ServerEnvironment.port); while (true) { CommMessage msg = server.comm.getMessage(); if (msg.type == CommMessage.MessageType.closeReceiver) { break; } msg.show(); if (msg.command == null) { continue; } CommMessage reply = server.messageDispatcher[msg.command](msg); reply.show(); server.comm.postMessage(reply); } } catch (Exception ex) { Console.Write("\n exception thrown:\n{0}\n\n", ex.Message); } }
/*----< Server processing >------------------------------------*/ /* * - all server processing is implemented with the simple loop, below, * and the message dispatcher lambdas defined above. */ static void Main(string[] args) { TestUtilities.title("Starting Test Harness", '='); try { TestHarness server = new TestHarness(); server.initializeDispatcher(); server.comm = new Comm(TestHarnessEnvironment.address, TestHarnessEnvironment.port); server.comm1 = new Comm(TestHarnessEnvironment.address, TestHarnessEnvironment.port - 500); server.comm1addr = "http://localhost:7579/IMessagePassingComm"; while (true) { CommMessage msg = server.comm.getMessage(); if (msg.type == CommMessage.MessageType.closeReceiver) { break; } msg.show(); if (msg.command == null) { continue; } CommMessage reply = server.messageDispatcher[msg.command](msg); reply.show(); server.comm.postMessage(reply); } } catch (Exception ex) { Console.Write("\n exception thrown:\n{0}\n\n", ex.Message); } }
/*--------------< Sends a communication message to GUI with msg.body = name of files present in teh Repository storage directory >------------*/ public void show_file() { string sendendPoint = Comm <Repository> .makeEndPoint("http://localhost", 8080, "GUI"); //creates senders' endpoint at port addr - 8080 try { CommMessage msg = new CommMessage(CommMessage.MessageType.FileList); //new comm message of type FileTransfer msg.from = endPoint; msg.to = sendendPoint; msg.command = "SendFilestoRepo"; string path = @"../../../Repository/Repo_storage/"; string[] files = Directory.GetFiles(path, "*.cs"); string file_names = ""; foreach (string file in files) { file_names += Path.GetFileName(file) + ","; } msg.body = file_names; //sends all file names of extension .cs to GUI as a string comm.sndr.PostMessage(msg); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nMessage Sent from Repository to GUI. Purpose - List of file names of currently present files in the Repository"); Console.ResetColor(); msg.show(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//---------------Thread to check messages in the receiver queue------------------------------------------------------------ void receiverThreadProc() { Console.Write("\n Started receiver thread for Client"); while (true) { CommMessage msg1 = comm.getMessage(); msg1.show(); switch (msg1.type) { case CommMessage.MessageType.Drivers: addDriversLBox(msg1.fileNames); break; case CommMessage.MessageType.TestCodes: addTestCodes(msg1.fileNames); break; case CommMessage.MessageType.TestLogs: addTestLogs(msg1.fileNames); break; case CommMessage.MessageType.BuildRequests: addBuildRequests(msg1.fileNames); break; case CommMessage.MessageType.BuildLogs: showBuildlogs(msg1.fileNames); break; } } }