Example #1
0
        /// <summary>
        /// Read a single table entry from the storage table.
        /// </summary>
        /// <param name="partitionKey">The partition key for the entry.</param>
        /// <param name="rowKey">The row key for the entry.</param>
        /// <returns>Value promise for tuple containing the data entry and its corresponding etag.</returns>
        public async Task <Tuple <T, string> > ReadSingleTableEntryAsync(string partitionKey, string rowKey)
        {
            const string operation = "ReadSingleTableEntryAsync";
            var          startTime = DateTime.UtcNow;

            if (Logger.IsVerbose2)
            {
                Logger.Verbose2("{0} table {1} partitionKey {2} rowKey = {3}", operation, TableName, partitionKey, rowKey);
            }

            try
            {
                TableResult retrievedResult = await Task <TableResult> .Factory.FromAsync(
                    tableReference.BeginExecute,
                    tableReference.EndExecute,
                    TableOperation.Retrieve <T>(partitionKey, rowKey),
                    null);

                if (retrievedResult == null || retrievedResult.Result == null || AzureStorageUtils.IsNotFoundError((HttpStatusCode)retrievedResult.HttpStatusCode))
                {
                    if (Logger.IsVerbose)
                    {
                        Logger.Verbose("Could not find table entry for PartitionKey={0} RowKey={1}", partitionKey, rowKey);
                    }
                    return(null);  // No data
                }
                //The ETag of data is needed in further operations.
                return(new Tuple <T, string>(retrievedResult.Result as T, retrievedResult.Etag));
            }
            finally
            {
                CheckAlertSlowAccess(startTime, operation);
            }
        }
        /// <summary>
        /// Inspect an exception returned from Azure storage libraries to check whether it means that attempt was made to read some data that does not exist in storage table.
        /// </summary>
        /// <param name="exc">Exception that was returned by Azure storage library operation</param>
        /// <returns><c>True</c> if this exception means the data being read was not present in Azure table storage</returns>
        public static bool TableStorageDataNotFound(Exception exc)
        {
            HttpStatusCode httpStatusCode;
            string         restStatus;

            if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus, true))
            {
                if (AzureStorageUtils.IsNotFoundError(httpStatusCode)
                    /* New table: Azure table schema not yet initialized, so need to do first create */)
                {
                    return(true);
                }
                return(StorageErrorCodeStrings.ResourceNotFound.Equals(restStatus));
            }
            return(false);
        }