protected override async Task <UploadResponse> InternalUploadAsync(CancellationToken cancellationToken)
        {
            try
            {
                var offset = activeUploadState == null ? 0 : activeUploadState.BytesUploaded;
                await
                partUploader.Upload(
                    FileStream,
                    UploadSpecificationRequest.FileName,
                    HashProvider,
                    UploadSpecification.ChunkUri.AbsoluteUri,
                    UploadSpecificationRequest.Raw,
                    offset,
                    cancellationToken).ConfigureAwait(false);

                return(await FinishUploadAsync().ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                // if the upload id was invalid, then the partial upload probably expired, so restart from the beginning
                var uploadException = ex as UploadException;
                var invalid         = uploadException == null ? false : uploadException.IsInvalidUploadId;
                if (!canRestart || !invalid)
                {
                    throw;
                }
            }

            progressReporter.ResetProgress();
            activeUploadState   = null;
            UploadSpecification = null;
            Prepared            = false;
            canRestart          = false;
            return(await UploadAsync(null, cancellationToken).ConfigureAwait(false));
        }
 public AsyncScalingFileUploader(
     ShareFileClient client,
     ActiveUploadState activeUploadState,
     UploadSpecificationRequest uploadSpecificationRequest,
     Stream stream,
     FileUploaderConfig config = null)
     : this(client, uploadSpecificationRequest, stream, config)
 {
     this.activeUploadState = activeUploadState;
     UploadSpecification    = activeUploadState.UploadSpecification;
 }
 public AsyncMemoryMappedFileUploader(
     ShareFileClient client,
     UploadSpecificationRequest uploadSpecificationRequest,
     FileStream stream,
     FileUploaderConfig config           = null,
     ActiveUploadState activeUploadState = null,
     int?expirationDays = default(int?))
     : base(client, uploadSpecificationRequest, stream, config, expirationDays)
 {
     hasher = new FileChunkHasher(HashProvider);
     if (activeUploadState != null)
     {
         initialPosition     = activeUploadState.BytesUploaded;
         UploadSpecification = activeUploadState.UploadSpecification; // what happens if the new UploadSpecRequest disagrees with this?
     }
 }
Beispiel #4
0
 protected override UploadResponse InternalUpload(CancellationToken cancellationToken)
 {
     try
     {
         var offset = activeUploadState == null ? 0 : activeUploadState.BytesUploaded;
         SetUploadSpecification();
         partUploader.NumberOfThreads = Math.Min(
             partUploader.NumberOfThreads,
             UploadSpecification.MaxNumberOfThreads.GetValueOrDefault(1));
         partUploader.UploadSpecification = UploadSpecification;
         var uploads = partUploader.Upload(
             FileStream,
             UploadSpecificationRequest.FileName,
             HashProvider,
             UploadSpecification.ChunkUri.AbsoluteUri,
             UploadSpecificationRequest.Raw,
             offset,
             cancellationToken);
         uploads.Wait();
         return(FinishUpload());
     }
     catch (Exception ex)
     {
         var agg = ex as AggregateException;
         if (agg != null)
         {
             ex = agg.Unwrap();
         }
         //if (canRestart && ((ex as UploadException)?.IsInvalidUploadId).GetValueOrDefault())
         if (canRestart && ((ex is UploadException) && ((UploadException)ex).IsInvalidUploadId))
         {
             activeUploadState   = null;
             UploadSpecification = null;
             Prepared            = false;
             canRestart          = false;
             return(Upload());
         }
         throw;
     }
 }
        public SyncUploaderBase GetFileUploader(
            ActiveUploadState activeUploadState,
            UploadSpecificationRequest uploadSpecificationRequest,
            Stream stream,
            FileUploaderConfig config = null)
        {
            UploadMethod?method = activeUploadState.UploadSpecification.Method;

            if (!method.HasValue)
            {
                throw new ArgumentNullException("UploadSpecification.Method");
            }
            switch (method.Value)
            {
            case UploadMethod.Standard:
                return(new StandardFileUploader(this, activeUploadState.UploadSpecification, uploadSpecificationRequest, stream, config));

            case UploadMethod.Threaded:
                return(new ScalingFileUploader(this, activeUploadState, uploadSpecificationRequest, stream, config));

            default:
                throw new NotSupportedException($"{method} is not supported");
            }
        }
        public AsyncUploaderBase GetAsyncFileUploader(
            ActiveUploadState activeUploadState,
            UploadSpecificationRequest uploadSpecificationRequest,
            Stream stream,
            FileUploaderConfig config = null)
        {
            this.PreprocessUploadSpecRequest(uploadSpecificationRequest);

            switch (uploadSpecificationRequest.Method)
            {
            case UploadMethod.Standard:
                return(new AsyncStandardFileUploader(this, uploadSpecificationRequest, stream, config));

            case UploadMethod.Threaded:
                return(new AsyncScalingFileUploader(
                           this,
                           activeUploadState,
                           uploadSpecificationRequest,
                           stream,
                           config));
            }

            throw new NotSupportedException(uploadSpecificationRequest.Method + " is not supported.");
        }
Beispiel #7
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;
 }