Esempio n. 1
0
        public async Task Upload(
            Stream fileStream,
            string fileName,
            IMD5HashProvider hashProvider,
            string chunkUploadUrl,
            bool raw,
            long offset = 0,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            this.raw = raw;
            // We block this after setting 'started', so make sure this statement is first
            NumberOfThreads = (int)Math.Min(NumberOfThreads, (fileStream.Length / partConfig.MinFileSizeForMultithreaded) + 1);
            started         = true;
            if (offset != 0)
            {
                updateProgress(offset);
                completedBytes.Add(0, offset);
            }
            try
            {
                var filePartSource = new FilePartSource(fileStream, hashProvider, partConfig.BufferAllocator, offset);
                var workers        = await Dispatch(filePartSource, chunkUploadUrl, fileName, cancellationToken).ConfigureAwait(false);

                await Task.WhenAll(workers).ConfigureAwait(false);

                logger.Info("[Scaling Uploader] All upload parts succeeded");
            }
            catch (Exception innerException)
            {
                logger.Info("[Scaling Uploader] Upload failed. Bytes uploaded: " + LastConsecutiveByteUploaded);
                var uploadException         = innerException as UploadException;
                UploadStatusCode statusCode = uploadException == null ? UploadStatusCode.Unknown : uploadException.StatusCode;
                throw new UploadException(
                          "FilePart upload failed",
                          statusCode,
                          new ActiveUploadState(UploadSpecification, LastConsecutiveByteUploaded),
                          innerException);
            }
        }
Esempio n. 2
0
 public UploadException(string errorMessage, UploadStatusCode errorCode, ActiveUploadState activeUploadState, Exception baseException = null)
     : base(string.Format("ErrorCode: {0}" + Environment.NewLine + "Message: {1}", errorCode, errorMessage), baseException)
 {
     StatusCode        = errorCode;
     ActiveUploadState = activeUploadState;
 }