src/Picturepark.SDK.V1/Partial/TransferClient.cs
/// <summary>Uploads multiple files from the filesystem.</summary>
/// <param name="transfer">The existing transfer object.</param>
/// <param name="files">The file paths on the filesystem with optional overrides.</param>
/// <param name="uploadOptions">The file upload options.</param>
/// <param name="timeout">The timeout to wait for completion.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The created transfer object.</returns>
Uploads multiple files from the filesystem.
Uploads multiple files from the filesystem .
public async Task UploadFilesAsync(Transfer transfer, IEnumerable<FileLocations> files, UploadOptions uploadOptions, TimeSpan? timeout = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            uploadOptions = uploadOptions ?? new UploadOptions();
            var exceptions = new List<Exception>();
            var throttler = new SemaphoreSlim(uploadOptions.ConcurrentUploads);
            var filteredFileNames = await FilterFilesByBlacklist(files).ConfigureAwait(false);
            var tasks = filteredFileNames
                .Select(file => Task.Run(async () =>
                {
                    try
                    {
                        await UploadFileAsync(throttler, transfer.Id, file.Identifier, file, uploadOptions.ChunkSize, cancellationToken).ConfigureAwait(false);
                        uploadOptions.SuccessDelegate?.Invoke(file);
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                        uploadOptions.ErrorDelegate?.Invoke(ex);
                    }
                }));
            await Task.WhenAll(tasks).ConfigureAwait(false);
            if (exceptions.Any())
            {
                throw new AggregateException(exceptions);
            }
            if (uploadOptions.WaitForTransferCompletion)
            {
                await _businessProcessClient.WaitForCompletionAsync(transfer.BusinessProcessId, timeout, cancellationToken).ConfigureAwait(false);
            }
        }
public async Task UploadFilesAsync ( Transfer transfer , IEnumerable < FileLocations > files , UploadOptions uploadOptions , TimeSpan ? timeout = null , CancellationToken cancellationToken = default ( CancellationToken ) ) { uploadOptions = uploadOptions ?? new UploadOptions ( ) ; var exceptions = new List < Exception > ( ) ; var throttler = new SemaphoreSlim ( uploadOptions . ConcurrentUploads ) ; var filteredFileNames = await FilterFilesByBlacklist ( files ) . ConfigureAwait ( false ) ; var tasks = filteredFileNames . Select ( file => Task . Run ( async ( ) => { try { await UploadFileAsync ( throttler , transfer . Id , file . Identifier , file , uploadOptions . ChunkSize , cancellationToken ) . ConfigureAwait ( false ) ; uploadOptions . SuccessDelegate ? . Invoke ( file ) ; } catch ( Exception ex ) { exceptions . Add ( ex ) ; uploadOptions . ErrorDelegate ? . Invoke ( ex ) ; } } ) ) ; await Task . WhenAll ( tasks ) . ConfigureAwait ( false ) ; if ( exceptions . Any ( ) ) { throw new AggregateException ( exceptions ) ; } if ( uploadOptions . WaitForTransferCompletion ) { await _businessProcessClient . WaitForCompletionAsync ( transfer . BusinessProcessId , timeout , cancellationToken ) . ConfigureAwait ( false ) ; } }
Uploads multiple files from the filesystem.
Uploads multiple files from the filesystem .
// Limits concurrent uploads
The created transfer object.
The created transfer object .
transfer
Transfer
The existing transfer object.
The existing transfer object .
files
IEnumerable<FileLocations>
The file paths on the filesystem with optional overrides.
The file paths on the filesystem with optional overrides .
uploadOptions
UploadOptions
The file upload options.
The file upload options .
timeout
TimeSpan?
The timeout to wait for completion.
The timeout to wait for completion .
cancellationToken
CancellationToken
The cancellation token.
The cancellation token .