コード例 #1
0
        public void UploadFile(string localFilepath, string remoteFilepath)
        {
            remoteFilepath = Path.IsPathRooted(remoteFilepath) ? remoteFilepath : Path.Combine(CurrentFolder, remoteFilepath);

            FileInfo localFileInfo = new FileInfo(localFilepath);
            long     localFileSize = localFileInfo.Length;

            Stopwatch sw = Stopwatch.StartNew();

            using (ConsoleStatusWriter statusWriter = new ConsoleStatusWriter("Uploading...", localFileSize))
            {
                try
                {
                    int count  = 512 * 1024;
                    int offset = 0;

                    byte[] buffer;

                    using (FileStream fs = File.OpenRead(localFilepath))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            do
                            {
                                buffer = br.ReadBytes(count);

                                AcknowledgementResponse response = remoteExecutor.Execute(new UploadFileRequest
                                {
                                    Path   = remoteFilepath,
                                    Data   = buffer,
                                    Offset = offset
                                });

                                offset += buffer.Length;
                                statusWriter.Update(buffer.Length);

                                if (!response.IsSuccessful)
                                {
                                    throw new CustomException("Error while uploading.");
                                }
                            }while (buffer.Length == count);
                        }
                }
                catch (IOException e)
                {
                    throw new CustomException(e.Message);
                }
            }
            sw.Stop();
            WriteStatistics(sw.ElapsedMilliseconds, localFileSize);
        }
コード例 #2
0
 private void ParallelFileDownloader_FilePartDownloadedEvent(ParallelFileWriter writer, ConsoleStatusWriter statusWriter, int partNumber, byte[] data)
 {
     writer.WritePart(partNumber, data);
     statusWriter.Update(data.Length);
 }