예제 #1
0
        public async Task <IList <TableResult> > InsertBatchAsync(IEnumerable <UserMedia> entities, CancellationToken ct = default(CancellationToken))
        {
            var tasks = new List <IList <TableResult> >();

            var entityBatches = entities.GroupAndSlice <UserMedia, string>(
                _maxBatchEntityCount,
                um => um.PartitionKey,
                KeyGroupPredicate
                );


            foreach (var entityBatch in entityBatches)
            {
                var tbo = new TableBatchOperation();

                foreach (var entity in entityBatch)
                {
                    tbo.Add(TableOperation.Insert(entity));
                }

                ICancellableAsyncResult ar = _cloudTable.BeginExecuteBatch(tbo, null, null);
                ct.Register(ar.Cancel);

                var batchTask = await Task.Factory.FromAsync <IList <TableResult> >(ar, _cloudTable.EndExecuteBatch).ConfigureAwait(false);

                tasks.Add(batchTask);
            }

            return(tasks.SelectMany(t => t).ToList());
        }
예제 #2
0
        public static Task <IList <TableResult> > ExecuteBatchAsync(
            this CloudTable table,
            TableBatchOperation operation,
            CancellationToken ct = default(CancellationToken))
        {
            ICancellableAsyncResult ar = table.BeginExecuteBatch(operation, null, null);

            ct.Register(ar.Cancel);

            return(Task.Factory.FromAsync <IList <TableResult> >(ar, table.EndExecuteBatch));
        }
예제 #3
0
        public static Task <IList <TableResult> > ExecuteBatchAsync(this CloudTable tbl, TableBatchOperation operation, TableRequestOptions opt, OperationContext ctx, CancellationToken token)
        {
            ICancellableAsyncResult result = null;

            if (opt == null && ctx == null)
            {
                result = tbl.BeginExecuteBatch(operation, null, null);
            }
            else
            {
                result = tbl.BeginExecuteBatch(operation, opt, ctx, null, null);
            }

            var cancellationRegistration = token.Register(result.Cancel);

            return(Task.Factory.FromAsync(result, ar =>
            {
                cancellationRegistration.Dispose();
                return tbl.EndExecuteBatch(ar);
            }));
        }
예제 #4
0
        /// <summary>
        ///     Executes a batch of operations on a table asynchronously.
        /// </summary>
        /// <param name="cloudTable">Cloud table.</param>
        /// <param name="tableBatchOperation">
        ///     The <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableBatchOperation" /> object representing the operations to execute on the table.
        /// </param>
        /// <param name="cancellationToken">Cancalltion token.</param>
        /// <returns>
        ///     An enumerable collection of <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableResult" /> objects that contains the results, in order, of each operation in the
        ///     <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableBatchOperation" />
        ///     on the table.
        /// </returns>
        public static Task <IList <TableResult> > ExecuteBatchAsync(
            this CloudTable cloudTable,
            TableBatchOperation tableBatchOperation,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ICancellableAsyncResult       asyncResult  = cloudTable.BeginExecuteBatch(tableBatchOperation, null, null);
            CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);

            return(Task <IList <TableResult> > .Factory.FromAsync(
                       asyncResult,
                       result =>
            {
                registration.Dispose();
                return cloudTable.EndExecuteBatch(result);
            }));
        }
예제 #5
0
 public ICancellableAsyncResult BeginExecuteBatch(TableBatchOperation batch, AsyncCallback callback, object state)
 {
     return(_cloudTable.BeginExecuteBatch(batch, callback, state));
 }