Example #1
0
        private UploadFileInformation GetFileInfo()
        {
            UploadFileInformation fileInfo = new UploadFileInformation();

            fileInfo.SourceFilePath   = _file;
            fileInfo.TargetFileName   = Path.GetFileName(_file);
            fileInfo.ChunkSizeInBytes = _bufferLength;
            fileInfo.StartingIndex    = _startingIndex;

            return(fileInfo);
        }
        public void UploadFile(UploadFileInformation fileInfo, IUploadProgressCommunicator progessCommunicator)
        {
            _fileInfo = fileInfo;

            Init();

            var uploadFileName = Path.GetFileName(_fileInfo.SourceFilePath);

            try
            {
                using (FileStream stream = new FileStream(_fileInfo.SourceFilePath, FileMode.Open))
                {
                    byte[] buffer = new byte[_fileInfo.ChunkSizeInBytes];

                    int count;

                    stream.Seek(fileInfo.StartingIndex, SeekOrigin.Begin);

                    while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        CopyBytes(buffer, count);

                        progessCommunicator.FileUploadSoFar(stream.Position);

                        if (progessCommunicator.Pause)
                        {
                            return;
                        }
                    }
                }

                progessCommunicator.UploadCompleted();
            }
            finally
            {
                CleanUp();
            }
        }