Esempio n. 1
0
        public void uploadFile(string filename, string Uri, string dir)
        {
            string   fqname  = Path.Combine(dir, filename);
            IService Channel = null;

            Channel = createSendChannel(Uri);
            if (Channel == null)
            {
                Console.WriteLine("Failed to establish connection with {0}", Uri);
                return;
            }

            try
            {
                using (var inputStream = new FileStream(fqname, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename       = filename;
                    msg.transferStream = inputStream;
                    Channel.upLoadFile(msg);
                }
                Console.Write("\n  Uploaded file \"{0}\" .", filename);
            }
            catch
            {
                Console.Write("\n  can't find \"{0}\"", fqname);
            }
        }
        public void upLoadFile(FileTransferMessage msg)
        {
            string dir        = TestHarness.returnCurTempDir();
            int    totalBytes = 0;
            int    BlockSize  = 1024;

            byte[] block     = new byte[BlockSize];
            string filename  = msg.filename;
            string rfilename = Path.Combine(dir, filename);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            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;
                    }
                }
            }
            string str = "Received file " + filename + " of " + totalBytes + "bytes .";

            str.title();
            return;
        }
Esempio n. 3
0
        public void upLoadFile(FileTransferMessage msg) //uploadfiles
        {
            HRTimer.HiResTimer hrt = new HRTimer.HiResTimer();
            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);
                    if (bytesRead > 0)
                    {
                        outputStream.Write(block, 0, bytesRead);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            hrt.Stop();
            Console.Write("\n  Received file \"{0}\"", filename);
        }
        public void upLoadFile(FileTransferMessage msg)
        {
            int    totalBytes = 0;
            string 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;
                    }
                }
            }
            string str = "Received file " + filename + "of " + totalBytes + " bytes .";

            str.title();
        }
Esempio n. 5
0
        //----< downLoadFile function >---------------------------------------

        /*
         *   function to read the uploaded file from clients
         */
        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
                );
        }
Esempio n. 6
0
        public void uploadFile(string filename, string Uri)
        {
            string   fqname  = System.IO.Path.Combine(ToSendPath, filename);
            IService Channel = null;

            Channel = CreateSendChannel(Uri);
            if (Channel == null)
            {
                string toPrint = "Failed to establish connection with " + Uri;
                toPrint.title();
                return;
            }
            try
            {
                using (var inputStream = new FileStream(fqname, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename       = filename;
                    msg.transferStream = inputStream;
                    Channel.upLoadFile(msg);
                }
                string printfile = "Uploaded the file " + filename + "to Repository";
                printfile.title();
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n  can't find \"{0}\" Exception: {1}", fqname, ex.Message);
            }
        }
 // uploads logs and test results to repo
 public void uploadFileToRepo(string filePath, string filename, ICommunicator repoChannel)
 {
     try
     {
         hrt.Start();
         using (var inputStream = new FileStream(filePath, FileMode.Open))
         {
             FileTransferMessage msg = new FileTransferMessage();
             msg.filename = filename;
             msg.transferStream = inputStream;
             repoChannel.upLoadFile(msg);
         }
         hrt.Stop();
         Console.Write("\n  Uploaded file \"{0}\" in {1} microsec.", filename, hrt.ElapsedMicroseconds);
     }
     catch (Exception e)
     {
         Console.Write("\n  can't find \"{0}\" exception {1}", filePath, e);
     }
 }
Esempio n. 8
0
        public bool uploadFile(string filename)
        {
            Console.Write("\n  sending file \"{0}\"", filename);
            string fqname = Path.Combine(ToSendPath, filename);

            try
            {
                using (var inputStream = new FileStream(fqname, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename       = filename;
                    msg.transferStream = inputStream;
                    channel.upLoadFile(msg);
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
        // function used to upload a file to the channel by file streaming
        void uploadFile(string filename)
        {
            string fqname = Path.Combine(ToSendPath, filename);

            try
            {
                hrt.Start();
                using (var inputStream = new FileStream(fqname, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename       = filename;
                    msg.transferStream = inputStream;
                    channel.upLoadFile(msg);
                }
                hrt.Stop();
                Console.Write("\n  Uploaded file \"{0}\" in {1} microsec.", filename, hrt.ElapsedMicroseconds);
            }
            catch
            {
                Console.Write("\n  can't find \"{0}\"", fqname);
            }
        }