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));
        }
Esempio n. 2
0
 public override UploadResponse Upload(Dictionary <string, object> transferMetadata = null)
 {
     try
     {
         SetUploadSpecification();
         var uploads = partUploader.Upload(File, HashProvider, UploadSpecification.ChunkUri.AbsoluteUri);
         uploads.Wait();
         return(FinishUpload());
     }
     catch (AggregateException aggEx)
     {
         throw aggEx.Unwrap();
     }
 }
Esempio n. 3
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;
     }
 }
Esempio n. 4
0
        protected override async Task <UploadResponse> InternalUploadAsync()
        {
            await partUploader.Upload(File, HashProvider, UploadSpecification.ChunkUri.AbsoluteUri);

            return(await FinishUploadAsync());
        }