//----< 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(); } } }
/*--------< 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)); } } }
/** * This function is to run check the messages received and * act accordingly. */ private void checkRequests() { CommMessage msg; while (true) { msg = channel.getMessage(); if (msg.command == "xml") { Console.WriteLine("Received an test request from {0}", msg.timestamp.Clone()); Directory.CreateDirectory("TestHarness/files/" + (string)msg.timestamp.Clone()); files = parse((string)msg.timestamp.Clone(), (string)msg.content.Clone()); postMessage(fetchPort(msg.from), (string)msg.timestamp.Clone(), "testFiles", files, ""); } else if (msg.command == "file") { runTestHarness(msg.timestamp, files); } else if (msg.command == "Quit") { Console.WriteLine("quit received"); CommMessage quitMsgGui = new CommMessage(CommMessage.MessageType.closeReceiver); quitMsgGui.to = "http://localhost:5000/MessagePassingComm.Receiver"; quitMsgGui.from = "http://localhost:5500/MessagePassingComm.Receiver"; quitMsgGui.command = "Quit"; quitMsgGui.author = "testHarness"; channel.postMessage(quitMsgGui); Thread.Sleep(3000); CommMessage quit = new CommMessage(CommMessage.MessageType.closeSender); quit.to = "http://localhost:5500/MessagePassingComm.Receiver"; quit.from = "http://localhost:5500/MessagePassingComm.Receiver"; quit.author = "testHarness"; channel.postMessage(quit); break; } } }