static void Main(string[] args)
        {
            Loader load = new Loader();

            load.setpath(Directory.GetCurrentDirectory());
            XMLProp xl = null;

            load.loadTests(xl);
        }
        public bool parse(FileStream xml)
        {
            xdoc = XDocument.Load(xml);
            XElement[] xlibs      = xdoc.Descendants("Test").ToArray();
            int        libsLength = xlibs.Count();
            XMLProp    test       = null;

            for (int i = 0; i < libsLength; i++)
            {
                test             = new XMLProp();
                test.TestLibrary = new List <string>();
                test.TestDriver  = xlibs[i].Element("testDriver").Value;
                IEnumerable <XElement> xtestcode = xlibs[i].Elements("Library");
                foreach (var xlibrary in xtestcode)
                {
                    test.TestLibrary.Add(xlibrary.Value);
                }
                testList.Add(test);
            }
            return(true);
        }
        public void loadTests(XMLProp testRequest)
        {
            Logger lg = new Logger();

            lg.add("Received Test Request : " + testRequest.TestDriver).displaycurrent();
            XMLProp lib = testRequest;

            lg.add("\nSetting Up Domain for test request").displaycurrent();
            AppDomainSetup domainsetup = new AppDomainSetup();
            Assembly       assem       = null;

            domainsetup.ApplicationBase = System.Environment.CurrentDirectory;
            //domainsetup.ApplicationBase=System.Environment.CurrentDirectory;
            string driverPath = System.Environment.CurrentDirectory + "\\TestHarnessCS\\Server_Received\\" + lib.TestDriver;

            //Creating Evidence
            Evidence appEvidence = AppDomain.CurrentDomain.Evidence;

            lg.add("\nCreating child App Domain: ").displaycurrent();

            //Using Domain setup and evidence to create the Child application Domain
            AppDomain domain = AppDomain.CreateDomain(testRequest.TestDriver.Replace(".dll", "-AppDomain"));//, appEvidence, domainsetup);

            assem = Assembly.LoadFrom(driverPath);
            lg.add("\nApp Domain created: " + domain.FriendlyName);
            domain.Load(Path.GetFileNameWithoutExtension(lib.TestDriver));

            //domain.Load(assem.FullName + ".dll");
            Console.WriteLine("\nDisplaying Assemblies: ");
            showAssemblies(domain);
            Console.WriteLine("\n------------------------");
            string name = assem.GetName().Name;

            Console.WriteLine("\nRequirement 5 - Checking if Derived from ITest Interface");
            ITest tdr = null;

            Type[] types = assem.GetExportedTypes();
            foreach (Type t in types)
            {
                if (t.IsClass && typeof(ITest).IsAssignableFrom(t))
                {
                    try
                    {
                        tdr = (ITest)Activator.CreateInstance(t);
                        Console.WriteLine("Passed, This Test driver is derived from ITest Interface \n");
                    }
                    catch
                    {
                        Console.WriteLine("\n This test driver is not derived from ITest Interface \n");
                        continue;
                    }
                }
            }

            Console.Write("\n Child Domain name :" + domain.FriendlyName + "\n");
            Console.WriteLine("---------------------------------------------------------");
            time.Start();
            //ObjectHandle ohandle = domain.CreateInstance(lib.TestDriver.Replace(".dll", ""), "" + lib.TestDriver.Replace(".dll", ""));
            ObjectHandle ohandle = domain.CreateInstance(lib.TestDriver.Replace(".dll", ""), "TestHarnessCS." + name);
            Object       obj     = ohandle.Unwrap();
            ITest        TI      = (ITest)obj;
            bool         result  = TI.test();

            time.Stop();
            lg.add("\nThe result of the test is " + result + "\n  Executed in " + time.ElapsedMicroseconds + " ms");
            Console.Write("\n The result of the test is {0} , \n Executed in {1}  ms", result, time.ElapsedMicroseconds);
            AppDomain.Unload(domain);
            lg.add("\n");
            lg.add("Unloading Domain");
            lg.savetofile(driverPath + ".log");
            Console.WriteLine("\n ---------------------------Ending Test-------------------------------------------");
        }
        void rcvThreadProc()
        {
            while (true)
            {
                Message msg = comm.rcv.GetMessage();
                if (msg.body != "quit")
                {
                    rcvdFile.Clear();
                    string clientAdd = msg.from;
                    msg.time = DateTime.Now;
                    Console.Write("\n  {0} received message:", comm.name);
                    msg.showMsg();
                    string testKey  = Path.Combine("..\\", msg.author);
                    string filename = msg.time.ToString().Replace(" ", "_").Replace(":", "_").Replace("/", "_") + ".xml";
                    Directory.CreateDirectory(testKey);
                    string       path = Path.Combine(testKey, filename);
                    StreamWriter sw   = new StreamWriter(path);
                    sw.WriteLine(msg.body);
                    sw.Close();
                    FileStream xml = new FileStream(path, FileMode.Open);
                    xi.parse(xml);
                    foreach (XMLProp tl in xi.testList)
                    {
                        rcvdFile.Add(tl.TestDriver.ToString());
                        foreach (var tl2 in tl.TestLibrary)
                        {
                            rcvdFile.Add(tl2.ToString());
                        }
                        Queue.enQ(tl);
                    }

                    string request = msg.body.ToString();
                    Console.WriteLine("\n Requirement 4: - DeQueued Message request: " + request + " \n ");
                    channel = CreateServiceChannel("http://localhost:8000/IRepo");
                    try
                    {
                        foreach (string files in rcvdFile)
                        {
                            download(files);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("\n Requirement 3: - Can't find dll file for testing in repository \n");
                        Message failedmsg = new Message();
                        failedmsg      = makeMessage("Server", endPoint, "http://localhost:8080");
                        failedmsg.time = DateTime.Now;
                        failedmsg.body = "Requirement 3 - Can't find dll file in repository - terminating request";
                        comm.snd.PostMessage(failedmsg);
                        Message quitmsg = new Message();
                        quitmsg      = makeMessage("Server", endPoint, endPoint);
                        quitmsg.time = DateTime.Now;
                        quitmsg.body = "quit";
                        comm.snd.PostMessage(quitmsg);
                    }
                    ((System.ServiceModel.Channels.IChannel)channel).Close();
                    while (Queue.size() != 0)
                    {
                        XMLProp XMLrequest = Queue.deQ();
                        Console.WriteLine("\n ------------------------- Starting Test -----------------------\n");
                        load.loadTests(XMLrequest);
                    }

                    xi.testList.Clear();
                    Console.WriteLine("\n Requirement 6 - Sending Log files to Repository: ");
                    channel = CreateServiceChannel("http://localhost:8000/IRepo");
                    string fqname = receivePath + "\\" + rcvdFile[0] + ".log";
                    using (var inputStream = new FileStream(fqname, FileMode.Open))
                    {
                        FileTransferMessage msg2 = new FileTransferMessage();
                        msg2.filename       = rcvdFile[0] + ".log";
                        msg2.transferStream = inputStream;
                        channel.upLoadFile(msg2);
                    }
                    ((System.ServiceModel.Channels.IChannel)channel).Close();
                }
                else
                {
                    break;
                }
            }
        }