private async Task <IEnumerable <BulkInsertItemState> > FlushCurrentBufferAsync() { IEnumerable <BulkInsertItemState> response = null; try { response = await Client.ExecuteStoredProcedureAsync <IEnumerable <BulkInsertItemState> >( storedProcedureLink, surrogate, Configuration.DisableIdGeneration? 1 : 0); } catch (DocumentSizeExceedsScriptSizeLimitException documentTooLarge) { // This error is thrown by the capped serializer if very first document got capped by the // size limit and prevents it from sending an empty request. // In this case - remove the first document from the buffer and report an error. var firstDocument = buffer.FirstOrDefault(); if (firstDocument != null) { response = new BulkInsertItemState[] { new BulkInsertItemState { DocumentIndex = firstDocument.DocumentIndex, ErrorMessage = documentTooLarge.Message } }; } } catch (Exception exception) { // Obtain last serialized document indexes, and report exception on their tasks // ConcurrentDictionary<,>.Keys will actually clone the collection, so we are good var lastIndexes = activeBulkItems.Keys; var responseIndex = -1; var responseArray = new BulkInsertItemState[surrogate.LastSerializedCount]; foreach (var index in lastIndexes) { if (++responseIndex >= surrogate.LastSerializedCount) { break; } responseArray[responseIndex] = new BulkInsertItemState { DocumentIndex = index, ErrorMessage = exception.Message }; } response = responseArray; } return(response ?? Enumerable.Empty <BulkInsertItemState>()); }
private async Task <IEnumerable <BulkInsertItemState> > FlushCurrentBufferAsync() { IEnumerable <BulkInsertItemState> result = null; try { var response = await Client.ExecuteStoredProcedureAsync <IEnumerable <BulkInsertItemState> >( storedProcedureLink, surrogate, Configuration.UpdateExisting? 1 : 0, Configuration.DisableIdGeneration? 1 : 0); result = response.Data; // Append global ActivityId to all error messages foreach (var item in result) { if (!String.IsNullOrEmpty(item.ErrorMessage)) { item.ErrorMessage += String.Format(CultureInfo.InvariantCulture, Resources.ImportErrorActivityIdFormat, Environment.NewLine, response.ActivityId); } } } catch (DocumentSizeExceedsScriptSizeLimitException documentTooLarge) { // This error is thrown by the capped serializer if very first document got capped by the // size limit and prevents it from sending an empty request. // In this case - remove the first document from the buffer and report an error. var firstDocument = buffer.FirstOrDefault(); if (firstDocument != null) { result = new BulkInsertItemState[] { new BulkInsertItemState { DocumentIndex = firstDocument.DocumentIndex, ErrorMessage = documentTooLarge.Message } }; } } catch (Exception exception) { // Obtain last serialized document indexes, and report exception on their tasks // ConcurrentDictionary<,>.Keys will actually clone the collection, so we are good var lastIndexes = activeBulkItems.Keys; var responseIndex = -1; var responseArray = new BulkInsertItemState[surrogate.LastSerializedCount]; foreach (var index in lastIndexes) { if (++responseIndex >= surrogate.LastSerializedCount) { break; } responseArray[responseIndex] = new BulkInsertItemState { DocumentIndex = index, ErrorMessage = exception.Message }; } result = responseArray; } return(result ?? Enumerable.Empty <BulkInsertItemState>()); }