//----< message creator >----------------------------------------

        /*
         * This is a placeholder using types defined in CommChannelDemo.MessageTest
         * You need a more efficient mechanism for creating messages.
         * Here's a suggestion:
         * - create MessageBody class for each message body type.
         * - use serializer, as demoed in TestDeserializer, to generate the
         *   body XML.
         * - On the other end deserialize, using the MessageBody type.
         */
        public string makeTestRequest()
        {
            TestElement te1 = new TestElement("test1");

            te1.addDriver("td1.dll");
            te1.addCode("t1.dll");
            te1.addCode("t2.dll");
            TestElement te2 = new TestElement("test2");

            te2.addDriver("td2.dll");
            te2.addCode("tc3.dll");
            te2.addCode("tc4.dll");
            TestRequest tr = new TestRequest();

            tr.author = "Jim Fawcett";
            tr.tests.Add(te1);
            tr.tests.Add(te2);
            return(tr.ToXml());
        }
        static void Main(string[] args)
        {
            Message msg = new Message();

            msg.to     = "http://localhost:8080/ICommunicator";
            msg.from   = "http://localhost:8081/ICommunicator";
            msg.author = "Bangera";
            msg.type   = "TestRequest";

            Console.Write("\n  Testing Message with Serialized TestRequest");
            Console.Write("\n ---------------------------------------------\n");
            TestElement te1 = new TestElement("test1");

            te1.addDriver("td1.dll");
            te1.addCode("tc1.dll");
            te1.addCode("tc2.dll");
            TestElement te2 = new TestElement("test2");

            te2.addDriver("td2.dll");
            te2.addCode("tc3.dll");
            te2.addCode("tc4.dll");
            TestRequest tr = new TestRequest();

            tr.author = "Karthik Bangera";
            tr.tests.Add(te1);
            tr.tests.Add(te2);
            msg.body = tr.ToXml();

            Console.Write("\n  Serialized TestRequest:");
            Console.Write("\n -------------------------\n");
            Console.Write(msg.body.shift());

            Console.Write("\n  TestRequest Message:");
            Console.Write("\n ----------------------");
            msg.showMsg();

            Console.Write("\n  Testing Deserialized TestRequest");
            Console.Write("\n ----------------------------------\n");
            TestRequest trDS = msg.body.FromXml <TestRequest>();

            Console.Write(trDS.showThis());
        }
Example #3
0
        //----------- Parses the xml string -----------
        public TestRequest parse(String xml)
        {
            try
            {
                //parses the xml string.
                doc_ = XDocument.Parse(xml);
                if (doc_ != null)
                {
                    string author = doc_.Descendants("author").First().Value;
                    tr.author = author;

                    // Console.WriteLine("\n--> Inside Parser. Current Domain : {0}", AppDomain.CurrentDomain.FriendlyName);
                    XElement[] xtests   = doc_.Descendants("TestElement").ToArray();
                    int        numTests = xtests.Count();
                    foreach (var xtest in xtests)
                    {
                        TestElement test = new TestElement();
                        test.testName   = xtest.Element("testName").Value;
                        test.testDriver = xtest.Element("testDriver").Value;
                        XElement xtestCodes = xtest.Element("testCodes");
                        IEnumerable <XElement> xLibraries = xtestCodes.Elements("string");
                        foreach (var lib in xLibraries)
                        {
                            test.testCodes.Add(lib.Value);
                        }
                        tr.tests.Add(test);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n\n-->##### Exception caught in Parser: {0}", ex.Message);
                tr = null;       //Passes null to the test list (List<Test>) if any error encountered while parsing.
                Console.WriteLine("\n\n-->Assigned NULL to test case List");
                Console.WriteLine("\n\n-->*** XML FILE needs to be fixed!!");
            }


            // Console.WriteLine("\n--> Exiting Parser & returning <Test List>. Current Domain : {0}", AppDomain.CurrentDomain.FriendlyName);
            return(tr);
        }
 public void TestRequestProcessing(Message msg)
 {
     lock (obj)
     {
         Console.WriteLine("\nChild Thread Created for Test Request (Message number {0}) ------->Requirement 4(Reference: TestHarnessServer.cs Line number 61, 66 and 75)", recvmsgcount);
         Console.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------------------------------");
         Parser      parser = new Parser();
         TestRequest tr     = parser.parse(msg.body);
         Console.WriteLine("\nTest Request Parsed: \n");
         Console.WriteLine("{0}", tr.ToString());
         if (tr != null)
         {
             List <object> ob        = RequestingRepoForDlls(msg, tr);
             DirectoryInfo d         = (DirectoryInfo)ob.ElementAt(0);
             int           filecount = (int)ob.ElementAt(1);
             Thread.Sleep(1000);
             while (true)
             {
                 if (checkFiles)
                 {
                     break;
                 }
             }
             if (d.GetFiles().Count() != filecount)
             {
                 Message errorMsgToClient = makeMessage("TestHarnessServer", msg.to, msg.from, "DLLsNotFound");
                 Console.WriteLine("Sending Error Message back to Client about the DLLs that were no found ------> Requirement 3(Reference: TestHarnessServer.cs Line Number 118-121");
                 errorMsgToClient.body = errorFromRepo;
                 comm.sndr.PostMessage(errorMsgToClient);
             }
             if (d != null)
             {   //Creating Child AppDomains
                 AppDomainManager adm      = new AppDomainManager();
                 List <Logger>    testLogs = adm.CreateChildDomains(d, tr);
                 TestResultReplyToClient(msg, testLogs);
             }
         }
     }
 }
Example #5
0
        public void SendingDllsToRepository(Message msg)
        {
            Parser p = new Parser();

            TestRequest       tr   = p.parse(msg.body);
            ClientFileManager cfm  = new ClientFileManager();
            List <string>     dlls = cfm.RetrieveFilesFromRepo(tr);

            int          count = 0;
            IFileService fs    = null;

            while (true)
            {
                try
                {
                    fs = CreateChannelForFileTransfer("http://localhost:8080/RepositoryServer");
                    break;
                }
                catch
                {
                    Console.Write("\n  connection to Test Harness service failed {0} times - trying again", ++count);
                    Thread.Sleep(500);
                    continue;
                }
            }

            Console.WriteLine("Sending the Following dlls to the Repository ------> Requirement 6(Reference: Client.cs line number 68-92,141)");
            foreach (string file in dlls)
            {
                string filename = System.IO.Path.GetFileName(file);
                Console.Write("\n\t  sending file {0} from Client's Local Repository to Main Repository", filename);

                if (!SendFile(fs, file))
                {
                    Console.Write("\n  could not send file");
                }
            }
        }
Example #6
0
        public static string makeTestRequest(string author)
        {
            TestElement te1 = new TestElement("test1");

            te1.addDriver("TestDriver1.dll");
            te1.addCode("CodeToTest1.dll");
            TestElement te2 = new TestElement("test2");

            te2.addDriver("TestDriver2.dll");
            te2.addCode("CodeToTest2.dll");
            TestElement te3 = new TestElement("test3");

            te3.addDriver("TestDriver4.dll");
            te3.addCode("CodeToTest4.dll");

            TestRequest tr = new TestRequest();

            tr.author = author;
            tr.tests.Add(te1);
            tr.tests.Add(te2);
            tr.tests.Add(te3);
            return(tr.ToXml());
        }
        public static string makeTestRequest(string testDriver, string testCode)
        {
            //TestElement te1 = new TestElement("test1");
            //te1.addDriver("TestDriver1.dll");
            //te1.addCode("CodeToTest1.dll");
            //TestElement te2 = new TestElement("test2");
            //te2.addDriver("TestDriver2.dll");
            //te2.addCode("CodeToTest2.dll");
            //TestRequest tr = new TestRequest();
            //tr.author = "Karthik Bangera";
            //tr.tests.Add(te1);
            //tr.tests.Add(te2);
            //return tr.ToXml();
            count++;
            TestElement te = new TestElement("test" + count);

            te.addDriver(testDriver);
            te.addCode(testCode);
            TestRequest tr = new TestRequest();

            tr.author = "Karthik Bangera";
            tr.tests.Add(te);
            return(tr.ToXml());
        }
Example #8
0
 // ------ Default Constructor --------------
 public Parser()
 {
     doc_ = new XDocument();
     tr   = new TestRequest();
 }
Example #9
0
 //Constructor for AppDomainLoader()
 public AppDomainLoader()
 {
     tr            = (TestRequest)AppDomain.CurrentDomain.GetData("TestRequest");
     tempDirectory = (DirectoryInfo)AppDomain.CurrentDomain.GetData("Directory");
 }
Example #10
0
        void rcvThreadProc()
        {
            while (true)
            {
                Message msg = comm.rcvr.GetMessage();
                msg.time = DateTime.Now;
                Console.Write("\n  {0} received message:", comm.name);
                msg.showMsg();
                if (msg.body == "quit")
                {
                    break;
                }
                else
                {
                    string        xml  = msg.body;
                    TestHarness   test = new TestHarness();
                    Logger.Logger log  = new Logger.Logger();
                    test.channel = TestHarness.CreateServiceChannel("http://localhost:8002/StreamService");
                    THTimer.HiResTimer hrt = new THTimer.HiResTimer();

                    hrt.Start();
                    string        driverName = null;                //test driver name
                    List <string> codeName   = new List <String>(); //List type for test code names
                    string        testCode;
                    string        testName;
                    string        author      = msg.author;
                    TestHarness   filePath    = new TestHarness();
                    string        testPath    = filePath.SavePath;
                    TestRequest   testRequest = xml.FromXml <TestRequest>();
                    Console.Write("\n  Tests to be run in the test harness");
                    Console.Write("\n ==========================================\n");
                    foreach (var requests in testRequest.tests)
                    {
                        testName = requests.testName;
                        Console.Write("\n Test Name: " + testName);
                        driverName = requests.testDriver;
                        Console.Write("\n Test Driver required: " + driverName);
                        codeName = requests.testCodes;

                        test.download(driverName);
                        //test.download("driverName");
                        foreach (string cname in codeName)
                        {
                            testCode = cname;
                            Console.Write("\n Test Code required: " + testCode);

                            test.download(cname);
                        }
                        Console.Write("\n");
                        Console.Write("\n  Required files received from the repository");
                        Console.Write("\n ==========================================\n");
                        log.setLogName(author + "_" + DateTime.Now.ToString("MMdd_hhss"));
                        string logFileName = log.getLogName();
                        log.writeLog("*****************************************************************");
                        log.writeLog("In App Domain......");
                        AppDomain main = AppDomain.CurrentDomain;
                        log.writeLog("\n Starting in AppDomain " + main.FriendlyName);
                        AppDomainSetup domaininfo = new AppDomainSetup();
                        domaininfo.ApplicationBase = System.Environment.CurrentDirectory;//need to change path
                        //Create evidence for the new AppDomain from evidence of current
                        Evidence adevidence = AppDomain.CurrentDomain.Evidence;
                        // Create Child AppDomain
                        AppDomain ad = AppDomain.CreateDomain("ChildDomain", adevidence, domaininfo);
                        ad.Load("ChildAppDomain");
                        log.writeLog("\n Child App Domain Created......");
                        //Console.Write("\n Child App Domain Created......");
                        ObjectHandle oh = ad.CreateInstance("ChildAppDomain", "ChildAppDomain.Loader");
                        object       ob = oh.Unwrap(); // unwrap creates proxy to ChildDomain
                                                       // using object in ChildDomain through IHello interface
                        ChildAppDomain.Loader h = (ChildAppDomain.Loader)ob;

                        h.run(testPath, driverName, codeName, logFileName);
                        //h.run(testPath, driverName, codeName);
                        AppDomain.Unload(ad);
                        test.uploadFile(logFileName);
                        hrt.Stop();

                        Console.Write("\n\n  total elapsed time for uploading = {0} microsec.\n", hrt.ElapsedMicroseconds);
                        ClientTransfer clnt = new ClientTransfer();
                        test.channel = TestHarness.CreateServiceChannel("http://localhost:8003/StreamService");
                        test.uploadFile(logFileName);
                        Console.Write("\n\n  total elapsed time for uploading = {0} microsec.\n", hrt.ElapsedMicroseconds);
                    }
                }
            }
        }