コード例 #1
0
        static void upload(string filename)
        {
            // byte[] block;
            string ToSendPath = "../../../Repository";

            channel = CreateServiceChannel("http://localhost:8000/StreamService");
            byte[] block = new byte[1024];
            //int totalBytes = 0;
            string fqname = System.IO.Path.Combine(ToSendPath, filename);

            try
            {
                //hrt.Start();
                using (var inputStream = new FileStream(filename, FileMode.Open))
                {
                    FileTransferMessage msg = new FileTransferMessage();
                    msg.filename       = filename;
                    msg.transferStream = inputStream;
                    channel.upLoadFile(msg);
                }
                // hrt.Stop();
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }
        }
コード例 #2
0
        void download(string filename)
        {
            channel = CreateServiceChannel("http://localhost:8000/StreamService");
            block   = new byte[BlockSize];
            int totalBytes = 0;

            try
            {
                // hrt.Start();
                Stream strm      = channel.downLoadFile(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 = strm.Read(block, 0, BlockSize);
                        totalBytes += bytesRead;
                        if (bytesRead > 0)
                        {
                            outputStream.Write(block, 0, bytesRead);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                // hrt.Stop();
                //ulong time = hrt.ElapsedMicroseconds;
                Console.Write("\n  Recieved file ");
            }
            catch (Exception ex)
            {
                Console.Write("\n  {0}", ex.Message);
            }
        }