void UploadFile(string filename)
        {
            //string srcPath = "..\\..\\..\\TestDriver2\\bin\\Debug\\";
            string     fqname = System.IO.Path.Combine(srcPath, filename);
            HiResTimer hrt    = new HiResTimer();

            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.WriteLine("\n------------------------Requirement 2 and 6 -- Line 248 Client_1.xaml.cs---------------");
                Console.Write("\n  Uploaded file to Repository \"{0}\" in {1} microsec.", filename, hrt.ElapsedMicroseconds);
            }
            catch (Exception e)
            {
                Console.Write("\n  can't find \"{0}\"", fqname);
            }
        }
Exemple #2
0
        public void upLoadFile(FileTransferMessage msg)
        {
            int totalBytes = 0;

            block = new byte[BlockSize];
            HiResTimer hrt1 = new HiResTimer();

            hrt1.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;
                    }
                }
            }
            hrt1.Stop();
            Console.Write(
                "\n  Received file \"{0}\" of {1} bytes in {2} microsec.",
                filename, totalBytes, hrt1.ElapsedMicroseconds
                );
        }