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));
        }
        public static Task <TableQuerySegment <T> > ExecuteQueryAsync <T>(this CloudTable table, TableQuery <T> query,
                                                                          TableContinuationToken token, CancellationToken ct = default(CancellationToken))
            where T : ITableEntity, new()
        {
            var ar = table.BeginExecuteQuerySegmented(query, token, null, null);

            ct.Register(ar.Cancel);

            return(Task.Factory.FromAsync(ar, table.EndExecuteQuerySegmented <T>));
        }
示例#4
0
        // 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);
            }));
        }
示例#5
0
        // 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);
            }));
        }
示例#6
0
        // asynchronously get first 1000 entities in a given partition, pass in continuation token
        // to retreive next 1000 entities and cancellation token to be able to signal to stop processing
        // externally.  Cancellation token is optional.
        public async Task <TableQuerySegment <UserMedia> > GetPartitionAsync(string partitionKey, TableContinuationToken token = null, CancellationToken ct = default(CancellationToken))
        {
            var tableQuery = new TableQuery <UserMedia>();

            // Create and Set PartitionKey filter
            var filter = CreatePartitionKeyFilter(partitionKey);

            tableQuery = tableQuery.Where(filter);

            ICancellableAsyncResult ar = _cloudTable.BeginExecuteQuerySegmented(tableQuery, token, null, null);

            ct.Register(ar.Cancel);

            return(await Task.Factory.FromAsync <TableQuerySegment <UserMedia> >(ar, _cloudTable.EndExecuteQuerySegmented <UserMedia>).ConfigureAwait(false));
        }
        private void ExecuteQuerySegment(CloudTable table,
                                         CloudTable targetTable)
        {
            var reqOptions = new TableRequestOptions();

            var ctx = new OperationContext {
                ClientRequestID = "StorageMigrator"
            };

            queries.Add(table.BeginExecuteQuerySegmented(query,
                                                         null,
                                                         reqOptions,
                                                         ctx,
                                                         HandleCompletedQuery(targetTable),
                                                         table));
        }
示例#8
0
 public ICancellableAsyncResult BeginExecuteQuerySegmented(TableQuery query, TableContinuationToken token,
                                                           AsyncCallback callback, object state)
 {
     return(_cloudTable.BeginExecuteQuerySegmented(query, token, r =>
     {
         var t = new AdapterAsyncResult <ITableQuerySegment <DynamicTableEntity> >(r,
                                                                                   new TableQuerySegmentAdapter <DynamicTableEntity>(
                                                                                       r.AsyncState as TableQuerySegment <DynamicTableEntity>));
         callback(t);
     }, state));
 }
示例#9
0
        /// <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);
            }));
        }
示例#10
0
        /// <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);
            }));
        }
示例#11
0
        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);
        }
        private void CopyData(CloudTable table)
        {
            TableContinuationToken token      = null;
            TableRequestOptions    reqOptions = new TableRequestOptions();
            var ctx = new OperationContext {
                ClientRequestID = "StorageMigrator"
            };

            while (true)
            {
                ManualResetEvent evt = new ManualResetEvent(false);
                var result           = table.BeginExecuteQuerySegmented(query, token, reqOptions, ctx, (o) =>
                {
                    var cloudTable = o.AsyncState as CloudTable;
                    var response   = cloudTable.EndExecuteQuerySegmented <DynamicTableEntity>(o);
                    token          = response.ContinuationToken;
                    var retrieved  = response.Count();
                    if (retrieved > 0)
                    {
                        WriteToTarget(cloudTable, response);
                    }
                    UpdateCount(cloudTable, retrieved);
                    Console.WriteLine("Table " +
                                      cloudTable.Name +
                                      " |> Records = " +
                                      retrieved +
                                      " | Total Records = " +
                                      this.retrieved[cloudTable.Name]);
                    evt.Set();
                }, table);
                evt.WaitOne();
                if (token == null)
                {
                    break;
                }
            }
        }
示例#13
0
 private void ExecuteQuerySegment(CloudTable table, TableContinuationToken token)
 {
     table.BeginExecuteQuerySegmented(_query, token, new TableRequestOptions(), new OperationContext {
         ClientRequestID = "StorageMigrator"
     }, HandleCompletedQuery(), table);
 }