示例#1
0
        public async Task <CosmosOperationResponse> ReplaceSignleDocumentAsync(string oldDocumentId, object newDocument)
        {
            await _metaDataOperator.AddActivity(_databaseName, _collectionName, DateTimeOffset.Now, ActivityStrength.Cold);

            CosmosOperationResponse result = new CosmosOperationResponse();

            return(await ReplaceDocumentAsync(oldDocumentId, newDocument, 0, result));
        }
示例#2
0
        public async Task <CosmosOperationResponse> DeleteSingleDocumentAsync(string id, object partitionKey = null)
        {
            await _metaDataOperator.AddActivity(_databaseName, _collectionName, DateTimeOffset.Now, ActivityStrength.Cold);

            CosmosOperationResponse result = new CosmosOperationResponse();

            return(await DeleteDocumentAsync(id, 0, result, partitionKey));
        }
示例#3
0
        public async Task <CosmosOperationResponse> InsertSingleDocumentAsync(object document)
        {
            await _metaDataOperator.AddActivity(_databaseName, _collectionName, DateTimeOffset.Now, ActivityStrength.Cold);

            CosmosOperationResponse result = new CosmosOperationResponse();

            return(await InsertDocumentAsync(document, 0, result));
        }
示例#4
0
        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;
                }
            }
        }
示例#5
0
 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;
         }
     }
 }