UploadFile() public method

Uploads the file. Resumes an upload if the given localFileStream.Position is larger than zero.
/// Contains the last successful remote document state. This is needed for continue a failed upload. ///
public UploadFile ( IDocument remoteDocument, Stream localFileStream, Transmission transmission, HashAlgorithm hashAlg, bool overwrite = true, UpdateChecksum update = null ) : IDocument
remoteDocument IDocument /// Remote document where the local content should be uploaded to. ///
localFileStream Stream /// Local file stream. ///
transmission Transmission /// Transmission status where the uploader should report its uploading status. ///
hashAlg System.Security.Cryptography.HashAlgorithm /// Hash alg which should be used to calculate a checksum over the uploaded content. ///
overwrite bool /// If true, the local content will overwrite the existing content. ///
update UpdateChecksum Is called on every new chunk, if not null.
return IDocument
        public void NormalUploadReplacesRemoteStreamIfRemoteStreamExists() {
            this.mockedDocument.Setup(doc => doc.ContentStreamId).Returns("StreamId");
            this.mockedDocument.Setup(doc => doc.DeleteContentStream(It.IsAny<bool>())).Callback(() => {
                if (this.remoteStream != null) {
                    this.remoteStream.Dispose();
                }

                this.remoteStream = new MemoryStream();
            }).Returns(this.mockedDocument.Object);

            this.remoteStream.WriteByte(1);

            using (IFileUploader uploader = new ChunkedUploader(this.chunkSize)) {
                uploader.UploadFile(this.mockedDocument.Object, this.localFileStream, this.transmission, this.hashAlg);
            }

            this.mockedDocument.Verify(doc => doc.DeleteContentStream(It.IsAny<bool>()), Times.Once());
            this.AssertThatLocalAndRemoteContentAreEqualToHash();
            Assert.AreEqual(1, this.lastChunk);
        }
 public void IOExceptionOnUploadTest() {
     this.mockedDocument.Setup(doc => doc.AppendContentStream(It.IsAny<IContentStream>(), It.IsAny<bool>(), It.Is<bool>(b => b == true)))
         .Throws(new IOException());
     using (IFileUploader uploader = new ChunkedUploader(this.chunkSize)) {
         var e = Assert.Throws<UploadFailedException>(() => uploader.UploadFile(this.mockedDocument.Object, this.localFileStream, this.transmission, this.hashAlg));
         Assert.IsInstanceOf(typeof(UploadFailedException), e);
         Assert.IsInstanceOf(typeof(IOException), e.InnerException);
         Assert.AreEqual(this.mockedDocument.Object, ((UploadFailedException)e).LastSuccessfulDocument);
     }
 }
        public void ResumeUpload() {
            double successfulUploadPart = 0.5;
            int successfulUploaded = (int)(this.fileLength * successfulUploadPart);
            double minPercent = 100 * successfulUploadPart;
            this.transmission.AddLengthConstraint(Is.Null.Or.GreaterThanOrEqualTo(successfulUploaded));
            this.transmission.AddPercentConstraint(Is.Null.Or.GreaterThanOrEqualTo(minPercent));
            this.transmission.AddPositionConstraint(Is.Null.Or.GreaterThanOrEqualTo(successfulUploaded));

            // Copy half of data before start uploading
            this.InitRemoteChunkWithSize(successfulUploaded);
            this.hashAlg.TransformBlock(this.localContent, 0, successfulUploaded, this.localContent, 0);
            this.localFileStream.Seek(successfulUploaded, SeekOrigin.Begin);

            using (IFileUploader uploader = new ChunkedUploader(this.chunkSize)) {
                uploader.UploadFile(this.mockedDocument.Object, this.localFileStream, this.transmission, this.hashAlg);
            }

            this.AssertThatLocalAndRemoteContentAreEqualToHash();
            Assert.AreEqual(1, this.lastChunk);
        }
        public void ResumeUploadWithUtils() {
            double successfulUploadPart = 0.2;
            int successfulUploaded = (int)(this.fileLength * successfulUploadPart);
            double minPercent = 100 * successfulUploadPart;
            this.InitRemoteChunkWithSize(successfulUploaded);
            this.transmission.AddLengthConstraint(Is.GreaterThanOrEqualTo(successfulUploaded));
            this.transmission.AddPercentConstraint(Is.GreaterThanOrEqualTo(minPercent));
            this.transmission.AddPositionConstraint(Is.GreaterThanOrEqualTo(successfulUploaded));

            using (IFileUploader uploader = new ChunkedUploader(this.chunkSize)) {
                ContentTaskUtils.PrepareResume(successfulUploaded, this.localFileStream, this.hashAlg);
                uploader.UploadFile(this.mockedDocument.Object, this.localFileStream, this.transmission, this.hashAlg);
            }

            this.AssertThatLocalAndRemoteContentAreEqualToHash();
            Assert.AreEqual(1, this.lastChunk);
        }
        public void NormalUpload() {
            using (IFileUploader uploader = new ChunkedUploader(this.chunkSize)) {
                uploader.UploadFile(this.mockedDocument.Object, this.localFileStream, this.transmission, this.hashAlg);
            }

            this.AssertThatLocalAndRemoteContentAreEqualToHash();
            Assert.AreEqual(1, this.lastChunk);
        }