예제 #1
0
        static void Main(string[] args)
        {
            Console.Write("\n  Testing Monitor-Based Blocking Queue");
            Console.Write("\n ======================================");

            SWTools.BlockingQueue <string> q = new SWTools.BlockingQueue <string>();
            Thread t = new Thread(() =>
            {
                string msg;
                while (true)
                {
                    msg = q.deQ(); Console.Write("\n  child thread received {0}", msg);
                    if (msg == "quit")
                    {
                        break;
                    }
                }
            });

            t.Start();
            string sendMsg = "msg #";

            for (int i = 0; i < 20; ++i)
            {
                string temp = sendMsg + i.ToString();
                Console.Write("\n  main thread sending {0}", temp);
                q.enQ(temp);
            }
            q.enQ("quit");
            t.Join();
            Console.Write("\n\n");
        }
예제 #2
0
        private void createProcessPool(CommMessage msg)
        {
            if (allProcessinPool.Count == 0)
            {
                string childBuilderExePath = "..\\..\\..\\ChildBuilder\\bin\\Debug\\ChildBuilder.exe";
                string absFileSpec         = Path.GetFullPath(childBuilderExePath);

                int processNum = 0;
                if (int.TryParse(msg.argument, out processNum))
                {
                    if (processNum <= 0 || processNum > maxProcessNum)
                    {
                        processNum = maxProcessNum;
                    }
                }

                for (int i = 0; i < processNum; i++)
                {
                    try
                    {
                        int               processUID  = i + 1 + 8090;
                        Process           proc        = Process.Start(absFileSpec, processUID.ToString( ));
                        SingleProcessInfo processInfo = new SingleProcessInfo(proc, processUID);

                        allProcessinPool.Add(processInfo);
                        readQ.enQ(i);

                        Console.Write("\n  create ChildBuilder Process : {0} on id {1}", processUID, proc.Id);
                    }
                    catch (Exception ex)
                    {
                        Console.Write("\n  {0}", ex.Message);
                    }
                }


                //return message to client
                CommMessage returnMsg = new CommMessage(CommMessage.MessageType.reply);
                returnMsg.to       = msg.from;
                returnMsg.from     = msg.to;
                returnMsg.author   = "BuildServer";
                returnMsg.command  = msg.command;
                returnMsg.argument = "Succeed create process pool . ";
                comm.postMessage(returnMsg);
            }
            else
            {
                Console.Write("\n process pool has exited , please shutdown first.");
            }
        }
예제 #3
0
        public void parse(System.IO.Stream xml, SWTools.BlockingQueue <TestData> q)//decode a xml file and put all test data into a blocking queue
        {
            TestData test;

            doc_ = XDocument.Load(xml);
            if (doc_ == null)
            {
                test           = new TestData();
                test.success   = false;
                test.author    = "unknown";
                test.timeStamp = DateTime.Now;
                test.testName  = "END";
                q.enQ(test);
                return;
            }
            string datetime = doc_.Descendants("datetime").First().Value;
            string author   = doc_.Descendants("author").First().Value;
            string repo     = doc_.Descendants("reposetory").First().Value;

            XElement[] xtests   = doc_.Descendants("test").ToArray();
            int        numTests = xtests.Count();

            try {
                for (int i = 0; i < numTests; ++i)
                {
                    test            = new TestData();
                    test.success    = true;
                    test.testCode   = new List <string>();
                    test.author     = author;
                    test.datetime   = datetime;
                    test.timeStamp  = DateTime.Now;
                    test.repo       = repo;
                    test.testName   = xtests[i].Attribute("name").Value;
                    test.testDriver = xtests[i].Element("testDriver").Value;
                    IEnumerable <XElement> xtestCode = xtests[i].Elements("library");
                    foreach (var xlibrary in xtestCode)
                    {
                        test.testCode.Add(xlibrary.Value);
                    }
                    q.enQ(test);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n\n  {0}", ex.Message);
            }
            return;
        }
예제 #4
0
 /*To get messages from client and child builder and store them in respective queues*/
 private static void CreateQueues()
 {
     try
     {
         rcvr.start("http://localhost", 8080);                              // Starts the receiver object
     }
     catch (Exception)
     {
         Console.WriteLine("\nUnable to start Mother builder receiver port or port already in use...");
     }
     while (true)
     {
         rcvMsg = rcvr.getMessage();
         if (rcvMsg.from != null)
         {
             rcvMsg.show();
             if (rcvMsg.from == "GUI")
             {
                 if (rcvMsg.type == CommMessage.MessageType.closeReceiver)
                 {                                                        //if closeReceiver message type is received then break from loop
                     break;
                 }
                 else
                 {
                     processGUI();
                 }
             }
             else
             {
                 readyQ.enQ(rcvMsg.from);
                 Console.WriteLine("\nEnqueing message to Ready Queue");
             }
         }
     }
 }
예제 #5
0
        // messageHandler function overridden by mother builder
        public override void messageHandler(CommMessage msg)
        {
            // To close the child builders
            if (msg.type == CommMessage.MessageType.closeReceiver)
            {
                for (int i = 0; i < numProcess; i++)
                {
                    CommMessage sendMsg = new CommMessage(CommMessage.MessageType.closeReceiver);
                    sendMsg.from    = "http://localhost:8081/IMessagePassingComm";
                    sendMsg.to      = childProcessAddr[i] + "/IMessagePassingComm";
                    sendMsg.command = "killProc";
                    sendMsg.author  = "Sachin";
                    //sendMsg.type = CommMessage.MessageType.closeReceiver;
                    commObj.postMessage(sendMsg);
                    Thread.Sleep(1000);
                }
                Thread.Sleep(10000);
                Process.GetCurrentProcess().Kill();
            }
            else
            {
                switch (msg.command)
                {
                // Enqueues the address of the child builder that sent the ready status
                case "ready":
                    readyStatusQ.enQ(msg.from);
                    break;

                // Enqueues the build request sent by the repo
                case "buildRequest":
                    buildRequestQ.enQ(msg);
                    break;
                }
            }
        }
예제 #6
0
        //----< enqueue string for writing >-----------------------------

        public void write(string msg)
        {
            if (threadRunning_)
            {
                Q_.enQ(msg);
            }
        }
예제 #7
0
        /*Process messages received grom gui*/
        private static void processGUI()
        {
            if (rcvMsg.command == "DeleteSenders")
            {
                while (readyQ.size() != 0)
                {
                    readyQ.deQ();
                }
                CloseServers();
            }

            /*Spawn pool processes depending on the input received*/
            else if (rcvMsg.command == "spawnchilds")
            {
                childCount = Int32.Parse(rcvMsg.arguments[0]);
                Console.WriteLine("\nRequirement: 5");
                Console.WriteLine("\nCreating " + childCount + " child builder processes");
                bs = new Sender[childCount];
                for (int p = 1; p <= childCount; p++)
                {
                    createProcess(8081 + p, "ChildBuilder\\bin\\debug\\ChildBuilder.exe");      // Spawn all the child builders
                    bs[p - 1] = new Sender("http://localhost", 8081 + p);                       //bs[p - 1] = new Sender("http://localhost", 8081 + p);
                }
            }
            else
            {
                requestQ.enQ(rcvMsg.arguments[0]);
                Console.WriteLine("\nEnqueing message to TestRequest Queue");
            }
        }
예제 #8
0
        private void requestAction(CommMessage msg)
        {
            RequestInfo request = new RequestInfo(msg);

            requestedQ.enQ(request);

            //Console.Write ( "\n  Inserted request in Requested Queue , Index : {0}" ,  requestedQ.size() );
            Console.Write("\n  Inserted request in Requested Queue. ");
        }
        /*----< enqueue test request to a queue >----------------------*/

        void processTestRequest(Msg msg)
        {
            Console.Write("\n" + msg.argument);
            // parse test request
            TestRequest request = msg.argument.FromXml <TestRequest>();

            requestQ_.enQ(request);

            Console.Write("\n  Inserted into request queue");
        }
        /*----< create a child process with index number >------------*/

        bool createProcess(int i)
        {
            string fileName    = "..\\..\\..\\ChildBuilder\\bin\\Debug\\ChildBuilder.exe";
            string absFileSpec = Path.GetFullPath(fileName);

            Console.Write("\n  attempting to start {0}", absFileSpec);
            string commandline = i.ToString();

            try
            {
                Process   proc  = Process.Start(fileName, commandline);
                ChildNode child = new ChildNode(proc, i);
                childs_.Add(child);
                readyQ_.enQ(i);
            }
            catch (Exception ex)
            {
                Console.Write("\n  {0}", ex.Message);
                return(false);
            }
            return(true);
        }
예제 #11
0
        public void Test1()
        {
            Console.Write("\n  Testing Monitor-Based Blocking Queue");
            Console.Write("\n ======================================");

            SWTools.BlockingQueue <string> q = new SWTools.BlockingQueue <string>();
            int  count = 0;
            Task t     = new Task(() =>
            {
                string msg;
                while (true)
                {
                    msg = q.deQ(); Console.Write("\n  child thread received {0}", msg);
                    // Assert.True(msg == "msg #" + count.ToString());
                    count++;
                    if (msg == "quit")
                    {
                        break;
                    }
                }

                //Assert.True(count == 21);
            });

            t.Start();

            string sendMsg = "msg #";

            for (int i = 0; i < 20; ++i)
            {
                string temp = sendMsg + i.ToString();
                Console.Write("\n  main thread sending {0}", temp);
                q.enQ(temp);
            }
            q.enQ("quit");
            t.Wait();
            Console.Write("\n\n");
        }
예제 #12
0
 //Recieve Messages using WCF
 void recieveMessages(int count)
 {
     while (true)
     {
         CommMessage msg = c.rcvr.getMessage();
         Console.WriteLine("==================================");
         msg.show();
         if (msg.type == CommMessage.MessageType.testRequest)
         {
             testQueue.enQ(msg.body);
         }
         else if (msg.type == CommMessage.MessageType.ready)
         {
             Console.WriteLine(" Child Builder with port number = " + msg.body + " is ready");
             ready.enQ(msg.body);
         }
         else if (msg.type == CommMessage.MessageType.quit)
         {
             msg.from = fromAddr;
             for (int i = 1; i <= count; i++)
             {
                 int         portNum  = portNumber + i;
                 CommMessage csndMsg3 = new CommMessage(CommMessage.MessageType.quit);
                 csndMsg3.command = "show";
                 csndMsg3.author  = "Jim Fawcett";
                 csndMsg3.to      = "http://localhost:" + portNum + "/IPluggableComm";
                 csndMsg3.from    = fromAddr;
                 csndMsg3.body    = "Quitting Child Builder";
                 c.postMessage(csndMsg3);
             }
             foreach (int pid in processID)
             {
                 KillProcess(pid);
             }
             Process.GetCurrentProcess().Kill();
         }
     }
 }
예제 #13
0
        void caseRunTest(CommandData cmdData)
        {
            string path = "../../../THtemp/" + cmdData.testAuthor + "_" + cmdData.dateTime + "_" + cmdData.xmlFile;

            System.IO.FileStream xml = new System.IO.FileStream(path, System.IO.FileMode.Open);
            q.enQ(xml);
            if (startlocal() == true)//now the log file is prepared and we should send it to the repository now
            {
                IFileService fs = null; IFileService fs2 = null;
                int          count = 0;
                while (true)
                {
                    try
                    {
                        fs  = TestHarness.fileSender.CreateChannel(RepoFRcvr);
                        fs2 = TestHarness.fileSender.CreateChannel(cmdData.url + "/CFRcvr");
                        break;
                    }
                    catch
                    {
                        Console.Write("\n  connection to service failed {0} times - trying again", ++count);
                        Thread.Sleep(500);
                        continue;
                    }
                }
                Console.Write("\n  Connected to {0}\n", RepoFRcvr);
                string relativeFilePath = "../../../THtemp/";
                string filepath         = Path.GetFullPath(relativeFilePath);
                string file             = filepath + cmdData.testAuthor + "_" + cmdData.dateTime + ".txt";
                Console.Write("----------this is for requirement 7 and 8------------------\n  sending file {0} to the client({1}) and reposetory", file, cmdData.url); timer.Start();
                if (!fileSender.SendFile(fs, file))
                {
                    Console.Write("\n  could not send file"); timer.Stop();
                }
                else
                {
                    timer.Stop();
                    Console.WriteLine("\nsend file {0} success in {1} ", file, timer.ElapsedTimeSpan);
                }
                if (!fileSender.SendFile(fs2, file))
                {
                    Console.Write("\n  could not send file"); timer.Stop();
                }
                else
                {
                    timer.Stop();
                    Console.WriteLine("\nsend file {0} success in {1} ", file, timer.ElapsedTimeSpan);
                }
            }
        }
예제 #14
0
        public void Log(/*string errorLogId,*/ string applicationId /*, string userId,*/, string errorMessage, string errorCategory, Exception ex = null)
        {
            Console.WriteLine(errorMessage);
            startQueue();
            startThread();
            PostError post = new PostError();

            //post.ErrorLogID = errorLogId;
            post.ApplicationID = applicationId;
            //post.UserId = userId;
            post.ErrorMessage  = errorMessage;
            post.ErrorCategory = errorCategory;
            //post.TimeStamp = Convert.ToString(DateTime.Now);
            queue.enQ(post);
        }
예제 #15
0
 void listen_builder_thread()
 {
     Console.WriteLine("MB thread running: ");
     while (true)
     {
         CommMessage recv_msg = null;
         recv_msg = comm.getMessage();
         Console.WriteLine("In MB:");
         recv_msg.show();
         // send reply message to child process
         if (recv_msg.port_number != 0 && recv_msg.msg_body.Equals("child"))
         {
             rd_q.enQ(recv_msg.port_number.ToString()); // enque the child's port number in the queue
         }
     }
 }
예제 #16
0
        void generate_xml()
        {
            List <String> xml_string_list = new List <String>();
            string        temp_str        = "";

            String[] xml_files_list = Directory.GetFiles(@"../../../Client_Files/", "*.xml");
            for (int i = 0; i < xml_files_list.Count(); i++)
            {
                temp_str = File.ReadAllText("" + xml_files_list[i]);
                xml_string_list.Add(temp_str);
                temp_str = "";
            }
            foreach (String str in xml_string_list)
            {
                br_q.enQ(str);
            }
        }
예제 #17
0
 // < thread for builder > //
 void listen_builder_thread()
 {
     Console.WriteLine("***********************************************************");
     Console.WriteLine("************* Mother Builder Thread Running*****************");
     Console.WriteLine("***********************************************************");
     while (true)
     {
         CommMessage recv_msg = null;
         recv_msg = comm.getMessage();
         Console.WriteLine("***********************************************************");
         Console.WriteLine("********Inside Mother Builder Thread:Received The Message***");
         Console.WriteLine("***********************************************************");
         recv_msg.show();
         // send reply message to child process
         if (recv_msg.port_number != 0 && recv_msg.msg_body.Contains("child"))
         {
             rd_q.enQ(recv_msg.port_number.ToString()); // enque the child's port number in the queue
         }
     }
 }
예제 #18
0
        //thread function to get messages from the receiver queue
        public static void getMessage()
        {
            while (true)
            {
                rcvMsg = rcvr.getMessage();
                lock (ConsoleWriterLock)
                {
                    rcvMsg.show();
                }
                if (rcvMsg.from == baseAddress + ":" + "8079" + "/IpluggableComm")
                {
                    if (rcvMsg.type == CommMessage.MessageType.request)
                    {
                        foreach (string file in rcvMsg.arguments)
                        {
                            buildRequestQ.enQ(file);
                        }
                    }
                }
                else if (rcvMsg.command == "ready")
                {
                    if (rcvMsg.from != null)
                    {
                        Console.Write("\nEnqueing msg {0} into the ready queue", rcvMsg.arguments[0]);
                        readyQ.enQ(Int32.Parse(rcvMsg.arguments[0]));
                    }
                }
                if (rcvMsg.command == "quit")
                {
                    Console.Write("\nQuitting Mother Builder");

                    for (int i = 1; i <= childProcNum; i++)
                    {
                        QuitMsg(i);
                    }
                    Thread.Sleep(2000);
                    Process.GetCurrentProcess().Kill();
                }
            }
        }
        //----< send a message to remote Receiver >--------------------------

        public bool sendMessage(Message msg)
        {
            sendQ.enQ(msg);
            return(true);
        }
예제 #20
0
 public void PostMessage(string msg)
 {
     rcvQueue.enQ(msg);
 }
        /*----< main thread enqueues message for sending >-------------*/

        public void postMessage(CommMessage msg)
        {
            sndQ.enQ(msg);
        }
예제 #22
0
        //----< called by clients >--------------------------------------

        public void sendTestRequest(Message testRequest)
        {
            Console.Write("\n  TestHarness received a testRequest - REQUIREMENT #2");
            inQ_.enQ(testRequest);
        }