// Insert a new drawer in the table static public void InsertUrlDrawer(UrlDrawer urlDrawer) { CloudTable table = tableClient.GetTableReference("AzureTable"); TableOperation insertOperation = TableOperation.Insert(urlDrawer); table.Execute(insertOperation); // Increment the indice TableOperation retrieveOperation = TableOperation.Retrieve <UrlDrawer>("indice", "indice"); TableResult retrievedResult = table.Execute(retrieveOperation); UrlDrawer updateEntity = retrievedResult.Result as UrlDrawer; if (updateEntity != null) { updateEntity.Hits += 1; TableOperation updateOperation = TableOperation.Replace(updateEntity); table.Execute(updateOperation); } }
public AzureTable(IConfiguration configuration) { var connectionString = configuration.GetConnectionString("TableStorage"); // Retrieve the storage account from the connection string. storageAccount = CloudStorageAccount.Parse(connectionString); tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("AzureTable"); table.CreateIfNotExistsAsync(); // other option CreateNewTable(cloudTable); TableOperation retrieveOperation = TableOperation.Retrieve <UrlDrawer>("indice", "indice"); TableResult retrievedResult = table.Execute(retrieveOperation); if (retrievedResult.Result == null) { UrlDrawer indice = new UrlDrawer("indice", "indice"); InsertUrlDrawer(indice); } }