private Task UploadAllSingleFiles( IEnumerable <FileUploadInfo> singleFileUploadInfos, Guid requestId, CancellationToken cancellationToken) { var singleFileUploadInfosBag = new ConcurrentBag <FileUploadInfo>(singleFileUploadInfos); var concurrentOperationsRunner = new ConcurrentOperationsRunner <FileUploadInfo>( uploadInfo => this.UploadSingleFile( File.ReadAllBytes(uploadInfo.FileInfo.FullName), uploadInfo.FilePathInImageStore, requestId.ToString(), cancellationToken), singleFileUploadInfosBag.TryTake, MaxConcurrentUpload); return(concurrentOperationsRunner.RunAll()); }
private Task UploadDirectoryCompletionMarkerFiles( IEnumerable <string> dirPathsInImageStore, Guid requestId, CancellationToken cancellationToken) { var dirPaths = new ConcurrentBag <string>(dirPathsInImageStore); var concurrentOperationsRunner = new ConcurrentOperationsRunner <string>( dirPathInImageStore => this.UploadSingleFile( new byte[0], $"{dirPathInImageStore}{Path.DirectorySeparatorChar}_.dir", requestId.ToString(), cancellationToken), dirPaths.TryTake, MaxConcurrentUpload); return(concurrentOperationsRunner.RunAll()); }
private async Task UploadAllChunksAsync( ICollection <ChunkInfo> chunkInfos, Guid requestId, long?serverTimeout, CancellationToken cancellationToken) { if (chunkInfos.Count > 0) { var chunkInfosBag = new ConcurrentBag <ChunkInfo>(chunkInfos); var concurrentOperationsRunner = new ConcurrentOperationsRunner <ChunkInfo>( chunkInfo => this.UploadChunkAsync( chunkInfo, requestId.ToString(), serverTimeout, cancellationToken), chunkInfosBag.TryTake, MaxConcurrentUpload); await concurrentOperationsRunner.RunAll(); var sessiodIds = new ConcurrentBag <Guid>(); foreach (var sessionId in chunkInfos.Select(x => x.SessionId).Distinct()) { sessiodIds.Add(sessionId); } // TODO: Before commiting check for missing chunlks and upload them again. // commit all chunkuploads with up to MaxConcurrentUpload in parallel. var sessionIdCommits = new ConcurrentOperationsRunner <Guid>( sessionId => this.httpClient.ImageStore.CommitImageStoreUploadSessionAsync( sessionId, cancellationToken: cancellationToken), sessiodIds.TryTake, MaxConcurrentUpload); await sessionIdCommits.RunAll(); } }