예제 #1
0
        public void upLoadFile(FileTransferMessage msg)
        {
            int totalBytes = 0;

            hrt.Start();
            filename = msg.filename;
            string rfilename = Path.Combine(savePath, filename);

            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            using (var outputStream = new FileStream(rfilename, FileMode.Create))
            {
                while (true)
                {
                    int bytesRead = msg.transferStream.Read(block, 0, BlockSize);
                    totalBytes += bytesRead;
                    if (bytesRead > 0)
                    {
                        outputStream.Write(block, 0, bytesRead);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            hrt.Stop();
            Console.Write(
                "\n Received file \"{0}\" of {1} bytes in {2} microsec.",
                filename, totalBytes, hrt.ElapsedMicroseconds
                );
        }
예제 #2
0
        //Repo Send button for sending dll files to the repository
        private void reposendbtn_Click(object sender, RoutedEventArgs e)
        {
            channel = CreateServiceChannel("http://localhost:8000/IRepo");
            string fqname = ToSendPath + "//TD//" + TDfilepaths[0];

            using (var inputStream = new FileStream(fqname, FileMode.Open))
            {
                FileTransferMessage msg2 = new FileTransferMessage();
                msg2.filename       = TDfilepaths[0];
                msg2.transferStream = inputStream;
                channel.upLoadFile(msg2);
            }
            string fqname1 = ToSendPath + "//TL//" + TLfilepaths[0];

            using (var inputStream = new FileStream(fqname, FileMode.Open))
            {
                FileTransferMessage msg2 = new FileTransferMessage();
                msg2.filename       = TLfilepaths[0];
                msg2.transferStream = inputStream;
                channel.upLoadFile(msg2);
            } ((IChannel)channel).Close();
        }
예제 #3
0
        //Uploading files to the Repository
        void uploadFile(string filename)
        {
            string fqname = Path.Combine(ToSendPath, filename);

            try
            {
                time.Start();
                using (var inputStream = new FileStream(fqname, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename       = filename;
                    msg.transferStream = inputStream;
                    channel.upLoadFile(msg);
                }
                time.Stop();
                Console.Write("\n  Uploaded file \"{0}\" in {1} microsec.", filename, time.ElapsedMicroseconds);
            }
            catch (Exception ex)
            {
                Console.Write("\n  can't find \"{0}\"", fqname);
                Console.Write("\n" + ex.Message);
            }
        }
예제 #4
0
        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;
                }
            }
        }