Skip to content

Instantly share code, notes, and snippets.

Matias Quaranta ealsur

Block or report user

Report or block ealsur

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ealsur
ealsur / transactionalbatch-error.cs
Created Jan 6, 2020
TransactionalBatch - Error view
View transactionalbatch-error.cs
// Parent's birthday!
parent.Age = 31;
// Naming two childs with the same name, should abort the transaction
ChildClass anotherChild = new ChildClass(){ Id = "The Child", ParentId = parent.Id, PartitionKey = partitionKey };
TransactionalBatchResponse failedBatchResponse = await container.CreateTransactionalBatch(new PartitionKey(partitionKey))
.ReplaceItem<ParentClass>(parent.Id, parent)
.CreateItem<ChildClass>(anotherChild)
.ExecuteAsync();
using (failedBatchResponse)
@ealsur
ealsur / transactionalbatch-view.cs
Created Jan 6, 2020
TransactionalBatch - View response
View transactionalbatch-view.cs
using (batchResponse)
{
if (batchResponse.IsSuccessStatusCode)
{
TransactionalBatchOperationResult<ParentClass> parentResult = batchResponse.GetOperationResultAtIndex<ParentClass>(0);
ParentClass parentClassResult = parentResult.Resource;
TransactionalBatchOperationResult<ChildClass> childResult = batchResponse.GetOperationResultAtIndex<ChildClass>(1);
ChildClass childClassResult = childResult.Resource;
}
}
@ealsur
ealsur / transactionalbatch-execute.cs
Created Jan 6, 2020
TransactionalBatch - Execute Batch
View transactionalbatch-execute.cs
TransactionalBatchResponse batchResponse = await batch.ExecuteAsync();
@ealsur
ealsur / transactionalbatch-create.cs
Created Jan 6, 2020
TransactionalBatch - Creating Batch
View transactionalbatch-create.cs
string partitionKey = "The Family";
ParentClass parent = new ParentClass(){ Id = "The Parent", PartitionKey = partitionKey, Name = "John", Age = 30 };
ChildClass child = new ChildClass(){ Id = "The Child", ParentId = parent.Id, PartitionKey = partitionKey };
TransactionalBatch batch = container.CreateTransactionalBatch(new PartitionKey(parent.PartitionKey))
.CreateItem<ParentClass>(parent)
.CreateItem<ChildClass>(child);
@ealsur
ealsur / BulkCreateTasks.cs
Created Oct 12, 2019
Azure Cosmos DB V3 SDK - Bulk tasks
View BulkCreateTasks.cs
Container container = cosmosClient.GetContainer("myDb", "myCollection");
// Assuming your have your data available to be inserted or read
List<Task> concurrentTasks = new List<Task>();
foreach(Item itemToInsert in ReadYourData())
{
concurrentTasks.Add(container.CreateItemAsync(itemToInsert, new PartitionKey(itemToInsert.MyPk)));
}
await Task.WhenAll(concurrentTasks);
@ealsur
ealsur / BulkCreateClient.cs
Last active Oct 12, 2019
Azure Cosmos DB V3 Bulk
View BulkCreateClient.cs
CosmosClientOptions options = new CosmosClientOptions() {
AllowBulkExecution = true };
CosmosClient cosmosclient = new CosmosClient(connectionString, options);
@ealsur
ealsur / profiles.json
Last active Nov 5, 2019
Windows Terminal profiles
View profiles.json
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles":
@ealsur
ealsur / Trigger.cs
Last active Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring - trigger
View Trigger.cs
[FunctionName("Trigger")]
public static void Trigger([CosmosDBTrigger(
databaseName: "%MonitoredDatabase%",
collectionName: "%MonitoredCollection%",
ConnectionStringSetting = "CosmosDB",
LeaseCollectionPrefix = "%MonitoredDatabaseLeasePrefix%",
LeaseCollectionName = "leases",
CreateLeaseCollectionIfNotExists = true)] IReadOnlyList<Document> documents,
ILogger log)
{
@ealsur
ealsur / CosmosDBConnectionString.cs
Created Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring - helper
View CosmosDBConnectionString.cs
private class CosmosDBConnectionString
{
public CosmosDBConnectionString(string connectionString)
{
// Use this generic builder to parse the connection string
DbConnectionStringBuilder builder = new DbConnectionStringBuilder
{
ConnectionString = connectionString
};
@ealsur
ealsur / Estimator.cs
Created Feb 15, 2019
Azure Cosmos DB + Functions Cookbook - monitoring - estimator
View Estimator.cs
private static Lazy<IRemainingWorkEstimator> remainingWorkEstimator;
public static IRemainingWorkEstimator GetRemainingWorkEstimator(
DocumentClient monitoredCollectionClient,
DocumentClient leaseCollectionClient)
{
if (remainingWorkEstimator == null)
{
// Pull the Connection string from the environment, Environment.GetEnvironmentVariable will read the local.settings.json file or the deployed Function App configuration
CosmosDBConnectionString cosmosDBConnectionString = new CosmosDBConnectionString(Environment.GetEnvironmentVariable("CosmosDB"));
You can’t perform that action at this time.