//----< run client demo >---------------------------------------- static void Main(string[] args) { Console.WriteLine("/////////////////////////////////////////////////////////////////"); Console.WriteLine(" CSE681 - Software Modeling & Analysis "); Console.WriteLine(" Project 4 - Remote Test Harness "); Console.WriteLine(" Yadav Narayana Murthy - SUID: 990783888 "); Console.WriteLine("//////////////////////////////////////////////////////////////////\n"); Console.Title = "Client 2"; Console.Write("\n Client 2"); Console.Write("\n =========\n"); Console.Write(" REQ 1 - Shall be implemented in C# using the facilities of the .Net Framework Class Library and Visual Studio 2015"); Console.Write("\n REQ 10 - Creating a WCF channel"); Client client = new Client(); Console.WriteLine(" \n File stream service starting:"); Console.Write("=================================\n"); Console.Write(" REQ 2 - Each test driver and the code it will be testing is implemented as a dynamic link library (DLL) and" + " sent by the client to the Repository server before sending the Test Request to the Test Harness.\n"); client.channel = CreateServiceChannel("http://localhost:8000/StreamService"); HRTimer.HiResTimer hrt = new HRTimer.HiResTimer(); // sending the DLLs to Repository Console.Write("\n REQ 6 - File Transfer using streams"); hrt.Start(); client.uploadFile("TestDriver2.dll"); client.uploadFile("TestedCode2.dll"); hrt.Stop(); Console.Write( "\n\n total elapsed time for uploading = {0} microsec.\n", hrt.ElapsedMicroseconds ); // sending the Test Request to Test Harness Console.Write(" REQ 2 - Sending Test Request to Test Harness"); Message msg = client.makeMessage("John", client.endPoint, client.endPoint); string remoteEndPoint = Comm <Client> .makeEndPoint("http://localhost", 8080); msg = msg.copy(); msg.to = remoteEndPoint; client.comm.sndr.PostMessage(msg); // sending the query message to Repository string repoEndPoint = Comm <Client> .makeEndPoint("http://localhost", 8095); Message repoQuery = client.makeRepoMessage("John", "Client2", client.endPoint, repoEndPoint, "John"); client.comm.sndr.PostMessage(repoQuery); Console.Write("\n press key to exit: "); Console.ReadKey(); msg.to = client.endPoint; msg.body = "quit"; client.comm.sndr.PostMessage(msg); client.wait(); Console.Write("\n\n"); }
//----< initialize receiver >------------------------------------ public Client(string url, int port) { endPoint = Comm <Client> .makeEndPoint(url, port); Console.Write("\n Creating instance of Client"); comm.rcvr.CreateRecvChannel(endPoint); //Console.Title = "Client: " + endPoint; rcvThread = comm.rcvr.start(rcvThreadProc); }
// host the service public void initiateServer() { string rcvrEndPoint1 = Comm <T> .makeEndPoint("http://localhost", THport); objComm.rcvr.CreateRecvChannel(rcvrEndPoint1); Thread rcvThread1 = objComm.rcvr.start(rcvThreadProc); Console.Write("\n rcvr thread id = {0}", rcvThread1.ManagedThreadId); Console.WriteLine(); }
//create a channle to communicate with repository public ICommunicator createRepoChannel() { string senderEndPoint1 = Comm <Server> .makeEndPoint("http://localhost", repoPort); EndpointAddress baseAddress = new EndpointAddress(senderEndPoint1); WSHttpBinding binding = new WSHttpBinding(); ChannelFactory <ICommunicator> factory = new ChannelFactory <ICommunicator>(binding, senderEndPoint1); ICommunicator channel = factory.CreateChannel(); return(channel); }
static void Main(string[] args) { Comm<Cat> comm = new Comm<Cat>(); string endPoint = Comm<Cat>.makeEndPoint("http://localhost", 8080); comm.rcvr.CreateRecvChannel(endPoint); comm.rcvr.start(comm.thrdProc); comm.sndr = new Sender(); comm.sndr.CreateSendChannel(endPoint); Message msg1 = new Message(); msg1.body = "Message #1"; comm.sndr.PostMessage(msg1); Message msg2 = new Message(); msg2.body = "quit"; comm.sndr.PostMessage(msg2); Console.Write("\n Comm Service Running:"); Console.Write("\n Press key to quit"); Console.ReadKey(); Console.Write("\n\n"); }
/*----------------------------------< Sends a communication message to Repository with msg.body = test log file name >--------------------------------*/ void sendTestLogto_Repo(string filename, string file_storage_path, string testresult) { try { CommMessage msg = new CommMessage(CommMessage.MessageType.TestLog); string remoteEndPoint = Comm <TestHarness> .makeEndPoint("http://localhost", 8081, "Repository"); msg.to = remoteEndPoint; msg.from = endPoint; msg.command = "SendTestLog"; msg.body = filename + "," + file_storage_path + "," + testresult; //sends test log file name with it's storage path comm.sndr.PostMessage(msg); Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Gray; Console.Write("\n Requirement 9 [Part 2]\n"); Console.ResetColor(); Console.WriteLine("It shall submit the results of testing to the Repository.\n"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nMessage Sent from TestHarness to Repository. Purpose - Sending {0} to Repository stored at{1}", filename, file_storage_path); Console.ResetColor(); msg.show(); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { int length = 0; Client client = new Client(); Console.Write("\n Testing Client Demo"); string url = "http://localhost:8080/FileService"; Console.Write("\n Client of File Transfer Service"); Console.Write("\n =================================\n"); IFileService fs = null; while (true) { try { fs = CreateChannel(url); break; } catch { Console.Write("\n connection to service failed {0} times - trying again", ++length); Thread.Sleep(500); continue; } } Console.Write("\n Connected to {0}\n", url); string storedlocation = "Sending"; string location = Path.GetFullPath(storedlocation); Console.Write("\n retrieving files from\n {0}\n", location); string[] files = Directory.GetFiles(location); foreach (string file in files) { string filename = Path.GetFileName(file); Console.Write("\n sending file {0}", filename); if (!sending(fs, file)) { Console.Write("\n could not send file"); } } Console.Write("\n\n"); Message msg = client.makeMessage("Manjunath", client.endPoint, client.endPoint); msg = client.makeMessage("Manjunath", client.endPoint, client.endPoint); msg.body = MessageTest.makeTestRequest(); client.comm.sndr.PostMessage(msg); string remoteEndPoint = Comm <Client> .makeEndPoint("http://localhost", 8080); msg = msg.copy_(); msg.to = remoteEndPoint; client.comm.sndr.PostMessage(msg); Console.ReadKey(); Message msg1 = client.results(); client.showMsg(msg1); Console.Write("\n received query: \"{0}\"", client.messge()); msg.time = DateTime.Now; client.m += "\n " + client.comm.name + " sent message:"; client.m += msg.showMsg(); Console.WriteLine("{0}", client.m); client.wait(); }
static void Main(string[] args) { Console.Write("\n Demonstrating Project #4 Channel Prototype"); Console.Write("\n ============================================\n"); ChannelDemo <Client> demo1 = new ChannelDemo <Client>(); string sndrEndPoint1 = Comm <Client> .makeEndPoint("http://localhost", 8080); string rcvrEndPoint1 = Comm <Server> .makeEndPoint("http://localhost", 8080); demo1.comm.rcvr.CreateRecvChannel(rcvrEndPoint1); Thread rcvThread1 = demo1.comm.rcvr.start(demo1.rcvThreadProc); Console.Write("\n rcvr thread id = {0}", rcvThread1.ManagedThreadId); Console.WriteLine(); ChannelDemo <Server> demo2 = new ChannelDemo <Server>(); string sndrEndPoint2 = Comm <Client> .makeEndPoint("http://localhost", 8081); string rcvrEndPoint2 = Comm <Server> .makeEndPoint("http://localhost", 8081); demo2.comm.rcvr.CreateRecvChannel(rcvrEndPoint2); Thread rcvThread2 = demo2.comm.rcvr.start(demo2.rcvThreadProc); Console.Write("\n rcvr thread id = {0}", rcvThread2.ManagedThreadId); Console.WriteLine(); // make a TestRequest message and send five times to two different endpoints Message msg = null; string rcvrEndPoint; for (int i = 0; i < 5; ++i) { msg = new Message(demo1.makeTestRequest()); msg.type = "TestRequest"; msg.from = sndrEndPoint1; if (i < 3) { msg.to = rcvrEndPoint = rcvrEndPoint1; } else { msg.to = rcvrEndPoint = rcvrEndPoint2; } msg.author = "Fawcett"; msg.time = DateTime.Now; demo1.comm.sndr.PostMessage(msg); Console.Write("\n {0}\n posting message with body:\n{1}", msg.from, msg.body.shift()); Thread.Sleep(20); } msg = new Message(); msg.from = sndrEndPoint1; msg.to = rcvrEndPoint2; msg.body = "quit"; demo1.comm.sndr.PostMessage(msg); rcvThread2.Join(); Console.Write("\n rcvThread1.state = {0}", rcvThread1.ThreadState.ToString()); Console.Write("\n rcvThread2.state = {0}", rcvThread2.ThreadState.ToString()); msg = new Message(); msg.from = sndrEndPoint2; msg.to = rcvrEndPoint1; msg.body = "quit"; demo2.comm.sndr.PostMessage(msg); Thread.Sleep(500); Console.Write("\n rcvThread1.state = {0}", rcvThread1.ThreadState.ToString()); rcvThread1.Join(); Console.Write("\n passed 2nd Join"); Console.Write("\n\n"); }