private FileUploadParameters CreateFileUploadParameters(EntityUploadParameters parameters) { CreateWorkingDirectoryIfNeeded(); var fileName = Path.Combine(WorkingDirectory, Guid.NewGuid() + ".csv"); using (var writer = new BulkFileWriter(fileName)) { foreach (var entity in parameters.Entities) { writer.WriteEntity(entity); } } var fileUploadParameters = new FileUploadParameters { UploadFilePath = fileName, ResponseMode = parameters.ResponseMode, ResultFileDirectory = parameters.ResultFileDirectory, ResultFileName = parameters.ResultFileName, OverwriteResultFile = parameters.OverwriteResultFile, RenameUploadFileToMatchRequestId = true }; return(fileUploadParameters); }
/// <summary> /// Uploads the specified Bulk file. /// </summary> /// <param name="parameters">Determines various upload parameters, for example what file to upload. Please see <see cref="FileUploadParameters"/> for more information about available parameters.</param> /// <param name="progress">A class implementing <see cref="IProgress{T}"/> for tracking the percent complete progress information for the bulk operation.</param> /// <param name="cancellationToken">Cancellation token that can be used to cancel the tracking of the bulk operation on the client. Doesn't cancel the actual bulk operation on the server.</param> /// <returns>A task that represents the asynchronous operation. The task result will be an enumerable list of <see cref="BulkEntity"/> objects.</returns> /// <exception cref="FaultException{TDetail}">Thrown if a fault is returned from the Bing Ads service.</exception> /// <exception cref="OAuthTokenRequestException">Thrown if tokens can't be refreshed due to an error received from the Microsoft Account authorization server.</exception> /// <exception cref="BulkOperationCouldNotBeCompletedException{TStatus}">Thrown if the bulk operation has failed.</exception> public Task <string> UploadFileAsync(FileUploadParameters parameters, IProgress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken) { ValidateSubmitUploadParameters(parameters.SubmitUploadParameters); ValidateUserData(); return(UploadFileAsyncImpl(parameters, progress, cancellationToken)); }
private async Task <string> UploadFileAsyncImpl(FileUploadParameters parameters, IProgress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken) { using (var operation = await SubmitUploadAsync(parameters.SubmitUploadParameters).ConfigureAwait(false)) { await operation.TrackAsync(progress, cancellationToken).ConfigureAwait(false); return(await DownloadBulkFile(parameters.ResultFileDirectory, parameters.ResultFileName, parameters.OverwriteResultFile, operation).ConfigureAwait(false)); } }
private async Task <IEnumerable <BulkEntity> > UploadEntitiesAsyncImpl(IProgress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken, FileUploadParameters fileUploadParameters) { var resultFile = await UploadFileAsyncImpl(fileUploadParameters, progress, cancellationToken).ConfigureAwait(false); return(new BulkFileReaderEnumerable(BulkFileReaderFactory.CreateBulkFileReader(resultFile, ResultFileType.Upload, DownloadFileType.Csv))); }
/// <summary> /// Uploads the specified Bulk file. /// </summary> /// <param name="parameters">Determines various upload parameters, for example what file to upload. Please see <see cref="FileUploadParameters"/> for more information about available parameters.</param> /// <returns>A task that represents the asynchronous operation. The task result will be an enumerable list of <see cref="BulkEntity"/> objects.</returns> /// <exception cref="FaultException{TDetail}">Thrown if a fault is returned from the Bing Ads service.</exception> /// <exception cref="OAuthTokenRequestException">Thrown if tokens can't be refreshed due to an error received from the Microsoft Account authorization server.</exception> /// <exception cref="BulkOperationCouldNotBeCompletedException{TStatus}">Thrown if the bulk operation has failed.</exception> public Task <string> UploadFileAsync(FileUploadParameters parameters) { return(UploadFileAsync(parameters, null, CancellationToken.None)); }