/// <summary>Creates multiple <see cref="ListItem"/>s.</summary> /// <param name="createManyRequest">The create many request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The created <see cref="ListItem"/>s.</returns> /// <exception cref="ApiException">A server side error occurred.</exception> /// <exception cref="PictureparkException">The business process has not been completed.</exception> public async Task <IEnumerable <ListItem> > CreateManyAsync(ListItemCreateManyRequest createManyRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (!createManyRequest.Requests.Any()) { return(new List <ListItem>()); } var businessProcess = await CreateManyCoreAsync(createManyRequest, cancellationToken).ConfigureAwait(false); var waitResult = await _businessProcessClient.WaitForCompletionAsync(businessProcess.Id, null, cancellationToken).ConfigureAwait(false); if (waitResult.HasLifeCycleHit) { var details = await _businessProcessClient.GetDetailsAsync(businessProcess.Id, cancellationToken).ConfigureAwait(false); if (details.LifeCycle == BusinessProcessLifeCycle.Failed) { // TODO: ListItemClient.CreateManyAsync: Should we check for Succeeded here? throw new Exception("The business process failed to execute."); } var bulkResult = (BusinessProcessDetailsDataBulkResponse)details.Details; if (bulkResult.Response.Rows.Any(i => i.Succeeded == false)) { // TODO: ListItemClient.CreateManyAsync: Use better exception classes in this method. throw new Exception("Could not save all objects."); } // Fetch created objects var searchRequest = new ListItemSearchRequest { Start = 0, Limit = 1000, Filter = new TermsFilter { Field = "id", Terms = bulkResult.Response.Rows.Select(i => i.Id).ToList() } }; var searchResult = await SearchAsync(searchRequest, cancellationToken).ConfigureAwait(false); return(searchResult.Results); } else { throw new Exception("The business process has not been completed."); } }
/// <inheritdoc /> public async Task <SchemaBatchOperationResult> WaitForBusinessProcessAndReturnResult(string businessProcessId, TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken)) { var result = await _businessProcessClient.WaitForCompletionAsync(businessProcessId, timeout, cancellationToken).ConfigureAwait(false); return(new SchemaBatchOperationResult(this, businessProcessId, result.LifeCycleHit, _businessProcessClient)); }