public static async Task <T[]> LookupAsync <T>(this ITableLookupStorage <T> table, string partitionKey, string rowKeyStart = null, string rowKeyEnd = null) where T : TableEntity { List <T> list = null; string continuationToken = null; while (true) { var segment = await table.LookupAsync(partitionKey, rowKeyStart, rowKeyEnd, continuationToken); if (list == null) { if (segment.ContinuationToken == null) { return(segment.Results); // optimization, skip allocating the list } list = new List <T>(); } if (segment.Results != null) { list.AddRange(segment.Results); } continuationToken = segment.ContinuationToken; if (continuationToken == null) { // Done return(list.ToArray()); } } }
public static async Task <T[]> QueryAllAsync <T>( this ITableLookupStorage <T> table, TableQuery <T> query) where T : TableEntity { int? takeN = query.TakeCount; List <T> list = null; string continuationToken = null; while (true) { var segment = await table.QueryAsync(query, continuationToken); if (list == null) { if (segment.ContinuationToken == null) { if (takeN.HasValue) { // Truncate if (segment.Results.Length > takeN.Value) { return(segment.Results.Take(takeN.Value).ToArray()); } } return(segment.Results); // optimization, skip allocating the list } list = new List <T>(); } if (segment.Results != null) { list.AddRange(segment.Results); } if (takeN.HasValue) { if (list.Count > takeN.Value) { // Truncate list.RemoveRange(takeN.Value, list.Count - takeN.Value); } // If we continue querying, we'll grab more than TakeN. // So check and return now. if (list.Count == takeN.Value) { return(list.ToArray()); } } continuationToken = segment.ContinuationToken; if (continuationToken == null) { // Done return(list.ToArray()); } } }
public static Task <T[]> GetRowsWithPrefixAsync <T>( this ITableLookupStorage <T> table, string partitionKey, string rowKeyPrefix) where T : TableEntity { string rowKeyEnd = NextRowKey(rowKeyPrefix); return(table.LookupAsync(partitionKey, rowKeyPrefix, rowKeyEnd)); }
public static async Task <T[]> LookupAsync <T>(this ITableLookupStorage <T> table, string partitionKey, string rowKeyStart = null, string rowKeyEnd = null) where T : TableEntity { TableQuery <T> query = new TableQuery <T>(); if (partitionKey != null) { query.WhereRowRange(partitionKey, rowKeyStart, rowKeyEnd); } return(await table.QueryAllAsync(query)); }