public async Task<List<IPhotoModel>> GetLatestFromTableStorageAsync()
{
var client = _account.CreateCloudTableClient();
var table = client.GetTableReference(StorageConfig.TableName);
//Scan all partitions looking for entities with a DateAdded property
// equal to today. This is inefficient, and one of the reasons
// we introduce Redis as a cache.
TableQuery<PhotoEntity> tableScanQuery = new TableQuery<PhotoEntity>().Where
(TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("YearAdded", QueryComparisons.Equal, System.DateTime.Now.Year.ToString()),
TableOperators.And,
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("MonthAdded", QueryComparisons.Equal, System.DateTime.Now.Month.ToString()),
TableOperators.And,
TableQuery.GenerateFilterCondition("DayAdded", QueryComparisons.Equal, System.DateTime.Now.Day.ToString()))));
TableContinuationToken token = null;
List<IPhotoModel> ret = new List<IPhotoModel>();
// Page through the results
do
{
TableQuerySegment<PhotoEntity> segment = await table.ExecuteQuerySegmentedAsync(
tableScanQuery,
token);
token = segment.ContinuationToken;
foreach (PhotoEntity entity in segment)
{
ret.Add(new PhotoModel(entity));
}
}
while (token != null);
return ret;
}