private async Task <string> cosmosWrite2(string runtime) { Uri collectionLink = UriFactory.CreateDocumentCollectionUri("TestDB", "TestCollection"); var data = new CosmosEntity(); data.Id = Guid.NewGuid().ToString(); data.PKey = data.Id.Substring(data.Id.Length - 3, 2); data.RunTime = runtime; ResourceResponse <Document> result = await clientCosmos.CreateDocumentAsync(collectionLink, data); return(data.Id); }
protected internal virtual async Task Replace(CosmosEntity document) { document.EnforceInvariants(); // last write wins var response = await _client.ReplaceDocumentAsync( UriFactory.CreateDocumentUri(_databaseName, _collectionName, document.Id), document, options : new RequestOptions { PartitionKey = new PartitionKey(document.PartitionKey) }); _logger.LogDebug($"Replace: Type = {document.Type} id = \"{document.Id}\" PK = \"{document.PartitionKey}\""); TrackEvent("RingoBotNet/CosmosData/Replace", response.RequestCharge, document.Id, document.PartitionKey, document.Type); }
protected async Task Create(CosmosEntity document) //where T : CosmosEntity { document.EnforceInvariants(); var response = await _client.CreateDocumentAsync( _collectionUri, document, options : new RequestOptions { PartitionKey = new PartitionKey(document.PartitionKey) }, disableAutomaticIdGeneration : true); _logger.LogDebug($"Create: Type = {document.Type} id = \"{document.Id}\" PK = \"{document.PartitionKey}\""); TrackEvent("RingoBotNet/CosmosData/Create", response.RequestCharge, document.Id, document.PartitionKey, document.Type); }
protected async Task Upsert(CosmosEntity document) { document.EnforceInvariants(); // last write wins var response = await _client.UpsertDocumentAsync( _collectionUri, document, options : new RequestOptions { PartitionKey = new PartitionKey(document.PartitionKey) }, disableAutomaticIdGeneration : true); _logger.LogDebug($"Upsert: Type = {document.Type} id = \"{document.Id}\" PK = \"{document.PartitionKey}\""); TrackEvent("RingoBotNet/CosmosData/Upsert", response.RequestCharge, document.Id, document.PartitionKey, document.Type); }
private async Task <string> cosmosWrite(string runtime) { using (DocumentClient client = new DocumentClient(CosmosDBUri, CosmosDBKey, connPolicy)) { await client.OpenAsync(); Uri collectionLink = UriFactory.CreateDocumentCollectionUri("TestDB", "TestCollection"); var data = new CosmosEntity(); data.Id = Guid.NewGuid().ToString(); data.PKey = data.Id.Substring(data.Id.Length - 3, 2); data.RunTime = runtime; ResourceResponse <Document> result = await client.CreateDocumentAsync(collectionLink, data); return(data.Id); } }