コード例 #1
0
        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))));
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public static bool ValidateShortUrl(GetConnectionStringDelegate connectionString, string hash)
 {
     return(RetrieveShortUrl(connectionString, hash) != null);
 }
コード例 #5
0
 internal static CloudStorageAccount GenerateStorageAccount(GetConnectionStringDelegate connectionString)
 {
     return(CloudStorageAccount
            .Parse(connectionString()));
 }