Пример #1
0
        /// <summary>Uploads multiple files from the filesystem.</summary>
        /// <param name="transfer">The existing transfer object.</param>
        /// <param name="filePaths">The file paths on the filesystem.</param>
        /// <param name="uploadOptions">The file upload options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The created transfer object.</returns>
        public async Task UploadFilesAsync(Transfer transfer, IEnumerable <string> filePaths, UploadOptions uploadOptions, CancellationToken cancellationToken = default(CancellationToken))
        {
            uploadOptions = uploadOptions ?? new UploadOptions();

            var exceptions = new List <Exception>();

            // Limits concurrent downloads
            var throttler         = new SemaphoreSlim(uploadOptions.ConcurrentUploads);
            var filteredFileNames = FilterFilesByBlacklist(filePaths.ToList());

            // TODO: File by file uploads
            var tasks = filteredFileNames
                        .Select(file => Task.Run(async() =>
            {
                try
                {
                    await UploadFileAsync(throttler, transfer.Id, 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, cancellationToken : cancellationToken).ConfigureAwait(false);
            }
        }
Пример #2
0
        /// <summary>Creates the given <see cref="SchemaDetail"/>.</summary>
        /// <param name="schemaDetail">The schema detail.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task.</returns>
        /// <exception cref="ApiException">A server side error occurred.</exception>
        public async Task CreateAndWaitForCompletionAsync(SchemaDetail schemaDetail, CancellationToken cancellationToken = default(CancellationToken))
        {
            var createRequest = new SchemaCreateRequest
            {
                Aggregations    = schemaDetail.Aggregations,
                Descriptions    = schemaDetail.Descriptions,
                DisplayPatterns = schemaDetail.DisplayPatterns,
                Fields          = schemaDetail.Fields,
                Id = schemaDetail.Id,
                SchemaPermissionSetIds = schemaDetail.SchemaPermissionSetIds,
                Names          = schemaDetail.Names,
                ParentSchemaId = schemaDetail.ParentSchemaId,
                Public         = schemaDetail.Public,
                ReferencedInContentSchemaIds = schemaDetail.ReferencedInContentSchemaIds,
                Sort           = schemaDetail.Sort,
                SortOrder      = schemaDetail.SortOrder,
                Types          = schemaDetail.Types,
                LayerSchemaIds = schemaDetail.LayerSchemaIds
            };

            var businessProcess = await CreateAsync(createRequest, cancellationToken).ConfigureAwait(false);

            await _businessProcessClient.WaitForCompletionAsync(businessProcess.Id, cancellationToken : cancellationToken).ConfigureAwait(false);
        }