private async Task <ShortUrlTableStorage> InsertOrMergeEntityAsync(CloudTable table, ShortUrlTableStorage entity) { if (entity == null) { throw new ArgumentNullException("ShortUrl"); } try { // Create the InsertOrReplace table operation TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity); // Execute the operation. TableResult result = await table.ExecuteAsync(insertOrMergeOperation); ShortUrlTableStorage insertedCustomer = result.Result as ShortUrlTableStorage; if (result.RequestCharge.HasValue) { logger.LogTrace("Request Charge of InsertOrMerge Operation: " + result.RequestCharge); } return(insertedCustomer); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
private async Task <ShortUrlTableStorage> RetrieveEntityUsingPointQueryAsync(CloudTable table, string partitionKey, string rowKey) { try { TableOperation retrieveOperation = TableOperation.Retrieve <ShortUrlTableStorage>(partitionKey, rowKey); TableResult result = await table.ExecuteAsync(retrieveOperation); ShortUrlTableStorage shortUrl = result.Result as ShortUrlTableStorage; if (shortUrl != null) { logger.LogDebug("\t{0}\t{1}\t{2}\t{3}", shortUrl.PartitionKey, shortUrl.RowKey, shortUrl.HashUrl, shortUrl.OriginalUrl); } if (result.RequestCharge.HasValue) { logger.LogDebug("Request Charge of Retrieve Operation: " + result.RequestCharge); } return(shortUrl); } catch (StorageException e) { logger.LogError(e, e.Message); throw; } }