public void TableGenericWithResolverAPM() { TableQuery <TableEntity> query = new TableQuery <TableEntity>().Select(new List <string>() { "A", "C" }); using (AutoResetEvent waitHandle = new AutoResetEvent(false)) { TableContinuationToken token = null; List <string> list = new List <string>(); do { IAsyncResult result = currentTable.BeginExecuteQuerySegmented(query, (pk, rk, ts, prop, etag) => prop["A"].StringValue + prop["C"].StringValue, token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); TableQuerySegment <string> segment = currentTable.EndExecuteQuerySegmented <TableEntity, string>(result); list.AddRange(segment.Results); token = segment.ContinuationToken; } while (token != null); foreach (string ent in list) { Assert.AreEqual("ac", ent); } List <BaseEntity> list1 = new List <BaseEntity>(); do { IAsyncResult result = currentTable.BeginExecuteQuerySegmented(query, (pk, rk, ts, prop, etag) => new BaseEntity() { PartitionKey = pk, RowKey = rk, Timestamp = ts, A = prop["A"].StringValue, C = prop["C"].StringValue, ETag = etag }, token, ar => waitHandle.Set(), null); waitHandle.WaitOne(); TableQuerySegment <BaseEntity> segment = currentTable.EndExecuteQuerySegmented <TableEntity, BaseEntity>(result); list1.AddRange(segment.Results); token = segment.ContinuationToken; } while (token != null); foreach (BaseEntity ent in list1) { Assert.IsNotNull(ent.PartitionKey); Assert.IsNotNull(ent.RowKey); Assert.IsNotNull(ent.Timestamp); Assert.IsNotNull(ent.ETag); Assert.AreEqual("a", ent.A); Assert.IsNull(ent.B); Assert.AreEqual("c", ent.C); Assert.IsNull(ent.D); } } }
public static async Task <ReadOnlyCollection <T> > ExecuteQuerySegmentedAsync <T>(this CloudTable table, TableQuery <T> query, IProgress <List <DynamicTableEntity> > progress = null) where T : ITableEntity, new() { TableQuerySegment <DynamicTableEntity> resultSegment; TableContinuationToken continuation = null; var results = new List <T>(); do { resultSegment = await Task.Factory.FromAsync( (cb, state) => (IAsyncResult)table.BeginExecuteQuerySegmented(query, continuation, cb, state), ar => table.EndExecuteQuerySegmented(ar), null); results.AddRange(resultSegment.Results.Cast <T>()); if (progress != null) { progress.Report(resultSegment.Results); } continuation = resultSegment.ContinuationToken; } while (continuation != null); return(new ReadOnlyCollection <T>(results)); }
/// <summary> /// Executes an operation to query a table in segmented mode asynchronously. /// </summary> /// <param name="cloudTable">Cloud table.</param> /// <param name="tableQuery"> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableQuery" /> instance specifying the table to query and the query parameters to use, specialized for a type <c>TElement</c>. /// </param> /// <param name="continuationToken"> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableContinuationToken" /> object representing a continuation token from the server when the operation returns a partial result. /// </param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableQuerySegment`1" /> containing the projection into type <c>R</c> of the results of executing the query. /// </returns> public static Task <TableQuerySegment <DynamicTableEntity> > ExecuteQuerySegmentedAsync( this CloudTable cloudTable, TableQuery tableQuery, TableContinuationToken continuationToken, CancellationToken cancellationToken = default(CancellationToken)) { ICancellableAsyncResult asyncResult = cloudTable.BeginExecuteQuerySegmented( tableQuery, continuationToken, null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task <TableQuerySegment <DynamicTableEntity> > .Factory.FromAsync( asyncResult, result => { registration.Dispose(); return cloudTable.EndExecuteQuerySegmented(result); })); }
/// <summary> /// Executes an operation to query a table in segmented mode asynchronously. /// </summary> /// <typeparam name="TElement">The entity type of the query.</typeparam> /// <typeparam name="TR"> /// The type into which the <see cref="T:Microsoft.WindowsAzure.Storage.Table.EntityResolver" /> will project the query results. /// </typeparam> /// <param name="cloudTable">Cloud table.</param> /// <param name="tableQuery"> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableQuery" /> instance specifying the table to query and the query parameters to use, specialized for a type <c>TElement</c>. /// </param> /// <param name="entityResolver"> /// An <see cref="T:Microsoft.WindowsAzure.Storage.Table.EntityResolver" /> instance which creates a projection of the table query result entities into the specified type <c>R</c>. /// </param> /// <param name="continuationToken"> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableContinuationToken" /> object representing a continuation token from the server when the operation returns a partial result. /// </param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableQuerySegment`1" /> containing the projection into type <c>R</c> of the results of executing the query. /// </returns> public static Task <TableQuerySegment <TR> > ExecuteQuerySegmentedAsync <TElement, TR>( this CloudTable cloudTable, TableQuery <TElement> tableQuery, EntityResolver <TR> entityResolver, TableContinuationToken continuationToken, CancellationToken cancellationToken = default(CancellationToken)) where TElement : ITableEntity, new() { ICancellableAsyncResult asyncResult = cloudTable.BeginExecuteQuerySegmented( tableQuery, entityResolver, continuationToken, null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task <TableQuerySegment <TR> > .Factory.FromAsync( asyncResult, result => { registration.Dispose(); return cloudTable.EndExecuteQuerySegmented <TElement, TR>(result); })); }
// Overload 6 public static Task <TableQuerySegment <R> > ExecuteQuerySegmentedAsync2 <TElement, R>(this CloudTable tbl, TableQuery <TElement> query, EntityResolver <R> resolver, TableContinuationToken continuationToken, TableRequestOptions opt, OperationContext ctx, CancellationToken token) where TElement : ITableEntity, new() { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginExecuteQuerySegmented <TElement, R>(query, resolver, continuationToken, null, null); } else { result = tbl.BeginExecuteQuerySegmented <TElement, R>(query, resolver, continuationToken, opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); return tbl.EndExecuteQuerySegmented <R>(ar); })); }
// Overload #4 public static Task <TableQuerySegment <DynamicTableEntity> > ExecuteQuerySegmentedAsync(this CloudTable tbl, TableQuery query, TableContinuationToken continuationToken, TableRequestOptions opt, OperationContext ctx, CancellationToken token) { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginExecuteQuerySegmented(query, continuationToken, null, null); } else { result = tbl.BeginExecuteQuerySegmented(query, continuationToken, opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); return tbl.EndExecuteQuerySegmented(ar); })); }
public static async Task ExecuteQuerySegmentedAsync <T>(this CloudTable table, TableQuery <T> query, IProgress <List <DynamicTableEntity> > progress) where T : ITableEntity, new() { TableQuerySegment <DynamicTableEntity> resultSegment; TableContinuationToken continuation = null; do { resultSegment = await Task.Factory.FromAsync( (cb, state) => (IAsyncResult)table.BeginExecuteQuerySegmented(query, continuation, cb, state), ar => table.EndExecuteQuerySegmented(ar), null); if (progress != null) { progress.Report(resultSegment.Results); } continuation = resultSegment.ContinuationToken; } while (continuation != null); }
public ITableQuerySegment <DynamicTableEntity> EndExecuteQuerySegmented(IAsyncResult asyncResult) { var result = _cloudTable.EndExecuteQuerySegmented(asyncResult); return(new TableQuerySegmentAdapter <DynamicTableEntity>(result)); }