private async Task <CosmosOperationResponse> ReplaceDocumentAsync(string oldDocumentId, object newDocument, int retryCount, CosmosOperationResponse result) { try { var docUri = UriFactory.CreateDocumentUri(_databaseName, _collectionName, oldDocumentId); await _client.ReplaceDocumentAsync(docUri, newDocument); result.Success = true; result.TotalRetries = retryCount; return(result); } catch (Exception e) { if (e.Message.Contains("Request rate is large")) { if (retryCount > _maximumRetryCount) { result.Success = false; result.TotalRetries = retryCount; return(result); } else { var op = ScaleLogic.ScaleUpCollectionAsync(_client, _metaDataOperator, _databaseName, _collectionName, _minRu, _maxRu); result.ScaleOperations.Add(op); return(await ReplaceDocumentAsync(oldDocumentId, newDocument, retryCount ++, result)); } } else { throw; } } }
private async Task <CosmosOperationResponse> DeleteDocumentAsync(string id, int retryCount, CosmosOperationResponse result, object partitionKey = null) { try { var docUri = UriFactory.CreateDocumentUri(_databaseName, _collectionName, id); if (partitionKey == null) { await _client.DeleteDocumentAsync(docUri, new RequestOptions() { PartitionKey = new PartitionKey(id) }); } else { await _client.DeleteDocumentAsync(docUri, new RequestOptions() { PartitionKey = new PartitionKey(partitionKey) }); } result.Success = true; result.TotalRetries = retryCount; return(result); } catch (Exception e) { if (e.Message.Contains("Request rate is large")) { if (retryCount > _maximumRetryCount) { result.Success = false; result.TotalRetries = retryCount; return(result); } else { var op = ScaleLogic.ScaleUpCollectionAsync(_client, _metaDataOperator, _databaseName, _collectionName, _minRu, _maxRu); result.ScaleOperations.Add(op); return(await DeleteDocumentAsync(id, retryCount ++, result, partitionKey)); } } else { throw; } } }