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();
        }
示例#2
0
        //----< 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 1";
            Console.Write("\n  Client ");
            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("AnotherTestDriver.dll");
            client.uploadFile("AnotherTestedCode.dll");
            client.uploadFile("TestDriver.dll");
            client.uploadFile("TestedCode.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("Mark Dwayne", 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("Mark Dwayne", "Client1", client.endPoint, repoEndPoint, "Mark Dwayne");

            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");
        }
        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");
        }