Beispiel #1
0
        static void CallApm(object n)
        {
            Message msg = (Message)n;

            Console.Write("\nThreadname is:" + Thread.CurrentThread.ManagedThreadId + "-----Req 4\n");
            msg.showMsg();

            // stwr.WriteLine(msg.body);
            // stwr.Close();
            XmlCreator.TestRequest tr = msg.body.FromXml <XmlCreator.TestRequest>();

            if (tr != null)
            {
                foreach (XmlCreator.TestElement t in tr.tests)
                {
                    AppDomainManager1 apm             = new AppDomainManager1();
                    string            x               = apm.LoadTests(t, tr.author);
                    string            testreqfilename = msg.author + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Year + ".log";
                    StreamWriter      stwr            = new StreamWriter("../../../ServerMemory/" + testreqfilename);
                    stwr.WriteLine(x);
                    msg.body = x;
                    stwr.Close();
                    string remoteEndPoint = null;
                    if (msg.author == "Client2")
                    {
                        remoteEndPoint = Comm <Server> .makeEndPoint("http://localhost", 8085);
                    }
                    else if (msg.author == "Client1")
                    {
                        remoteEndPoint = Comm <Server> .makeEndPoint("http://localhost", 8081);
                    }
                    Sender s = new Sender();
                    s.CreateSendChannel(msg.from);
                    msg.from = msg.to;
                    msg.to   = remoteEndPoint;
                    Console.Write("\n\nSending test results to Client ---req 8\n\n");
                    s.PostMessage(msg);
                    Console.Write("\n\nSending log file to repository----Req 8\n\n");
                    upload("../../../ServerMemory/" + testreqfilename);
                }
            }
        }
Beispiel #2
0
        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");
        }