/// <inheritdoc /> public Task <IList <TableResult> > ExecuteBatchAsync(IStorageTableBatchOperation batch, CancellationToken cancellationToken) { TableBatchOperation sdkBatch = ((StorageTableBatchOperation)batch).SdkObject; return(_sdk.ExecuteBatchAsync(sdkBatch, cancellationToken)); }
public IList <TableResult> ExecuteBatch(IStorageTableBatchOperation batch) { IStorageTableOperation[] operations = batch.ToArray(); if (operations.Length == 0) { return(new List <TableResult>()); } // Ensure all operations are for the same partition. string firstPartitionKey = operations[0].Entity.PartitionKey; if (operations.Any(o => o.Entity.PartitionKey != firstPartitionKey)) { throw new InvalidOperationException("All operations in a batch must have the same partition key."); } // Ensure each row key is only present once. if (operations.GroupBy(o => o.Entity.RowKey).Any(g => g.Count() > 1)) { throw new InvalidOperationException("All operations in a batch must have distinct row keys."); } List <TableResult> results = new List <TableResult>(); foreach (IStorageTableOperation operation in operations) { // For test purposes, use an easier (non-atomic) implementation. TableResult result = Execute(operation); results.Add(result); } return(results); }
/// <inheritdoc /> public Task <IList <TableResult> > ExecuteBatchAsync(IStorageTableBatchOperation batch, CancellationToken cancellationToken) { TableBatchOperation sdkBatch = ((StorageTableBatchOperation)batch).SdkObject; return(_sdk.ExecuteBatchAsync(sdkBatch, requestOptions: null, operationContext: null, cancellationToken: cancellationToken)); }
public IList <TableResult> ExecuteBatch(string tableName, IStorageTableBatchOperation batch) { if (!_items.ContainsKey(tableName)) { throw StorageExceptionFactory.Create(404, "TableNotFound"); } return(_items[tableName].ExecuteBatch(batch)); }
internal virtual async Task ExecuteBatchAndCreateTableIfNotExistsAsync( Dictionary <string, IStorageTableOperation> partition, CancellationToken cancellationToken) { IStorageTableBatchOperation batch = _table.CreateBatch(); foreach (var operation in partition.Values) { batch.Add(operation); } if (batch.Count > 0) { StorageException exception = null; try { // Commit the batch await _table.ExecuteBatchAsync(batch, cancellationToken); } catch (StorageException e) { if (!e.IsNotFoundTableNotFound()) { throw new StorageException(e.GetDetailedErrorMessage(), e); } exception = e; } if (exception != null) { // Make sure the table exists await _table.CreateIfNotExistsAsync(cancellationToken); // Commit the batch try { await _table.ExecuteBatchAsync(batch, cancellationToken); } catch (StorageException e) { throw new StorageException(e.GetDetailedErrorMessage(), e); } } } }
public Task <IList <TableResult> > ExecuteBatchAsync(IStorageTableBatchOperation batch, CancellationToken cancellationToken) { return(Task.FromResult(_store.ExecuteBatch(_tableName, batch))); }