public static async Task <TableResult> RecordShortUrlHit(GetConnectionStringDelegate connectionString, string hash) { var table = GenerateCloudTable(GenerateStorageAccount(connectionString), "ShortUrlHit"); await table.CreateIfNotExistsAsync(); return(await table.ExecuteAsync(TableOperation.InsertOrReplace(new ShortUrlHit(hash)))); }
public static async Task <string> RetrieveShortUrl(GetConnectionStringDelegate connectionString, string hash) { var res = await GenerateCloudTable(GenerateStorageAccount(connectionString), "ShortUrl") .ExecuteAsync(TableOperation.Retrieve <ShortUrl>("ShortUrl", hash)); if (res.Result == null) { return(null); } else { return(((ShortUrl)res.Result).OriginalUrl); } }
public static async Task <bool> SaveShortUrl(GetConnectionStringDelegate getConnectionString, ShortUrl url) { CloudStorageAccount storageAccount = CloudStorageAccount .Parse(getConnectionString()); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("ShortUrl"); await table.CreateIfNotExistsAsync(); // Create the TableOperation that inserts the customer entity. TableOperation insertOperation = TableOperation.Insert(url); // Execute the insert operation. var tableOperationResult = await table.ExecuteAsync(insertOperation); return(tableOperationResult.HttpStatusCode == (int)HttpStatusCode.OK); }
public static bool ValidateShortUrl(GetConnectionStringDelegate connectionString, string hash) { return(RetrieveShortUrl(connectionString, hash) != null); }
internal static CloudStorageAccount GenerateStorageAccount(GetConnectionStringDelegate connectionString) { return(CloudStorageAccount .Parse(connectionString())); }