本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteBatchAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudTable.ExecuteBatchAsync方法的具体用法?C# CloudTable.ExecuteBatchAsync怎么用?C# CloudTable.ExecuteBatchAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Table.CloudTable
的用法示例。
在下文中一共展示了CloudTable.ExecuteBatchAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
public static async Task Insert(CloudTable table)
{
CustomerEntity customer1 = new CustomerEntity("Harp", "Walters")
{
Email = "[email protected]",
PhoneNumber = "425-555-0101"
};
CustomerEntity customer2 = new CustomerEntity("Harp", "Ben")
{
Email = "[email protected]",
PhoneNumber = "425-555-0102"
};
TableBatchOperation batchOperation = new TableBatchOperation();
// Create the TableOperation object that inserts the customer entity.
TableOperation insertOperation = TableOperation.Insert(customer1);
batchOperation.Insert(customer1);
batchOperation.Insert(customer2);
// Execute the insert operation.
Incremental retryStrategy = new Incremental(5, TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2));
ExponentialBackoff retryStrategy2=new ExponentialBackoff(5,TimeSpan.FromSeconds(1),TimeSpan.FromSeconds(5),TimeSpan.FromSeconds(2));
TimeSpan back = TimeSpan.FromSeconds(31);
// Define your retry policy using the retry strategy and the Azure storage
// transient fault detection strategy.
RetryPolicy<StorageTransientErrorDetectionStrategy> retryPolicy =
new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy);
RetryPolicy<StorageTransientErrorDetectionStrategy> r =
new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy2);
// Receive notifications about retries.
retryPolicy.Retrying += (sender, args) =>
{
Console.WriteLine("Information");
// Log details of the retry.
var msg = String.Format("Retry - Count:{0}, Delay:{1}, Exception:{2}",
args.CurrentRetryCount, args.Delay, args.LastException);
Console.WriteLine(msg, "Information");
};
try
{
// Do some work that may result in a transient fault.
await retryPolicy.ExecuteAsync(
() => table.ExecuteBatchAsync(batchOperation));
}
catch (Exception e)
{
var z = e;
}
Console.ReadLine();
/* // Create a new customer entity.
CustomerEntity customer1 = new CustomerEntity("Harp", "Walters")
{
Email = "[email protected]",
PhoneNumber = "425-555-0101"
};
CustomerEntity customer2 = new CustomerEntity("Harp", "Ben")
{
Email = "[email protected]",
PhoneNumber = "425-555-0102"
};
TableBatchOperation batchOperation = new TableBatchOperation();
// Create the TableOperation object that inserts the customer entity.
TableOperation insertOperation = TableOperation.Insert(customer1);
batchOperation.Insert(customer1);
batchOperation.Insert(customer2);
// Execute the insert operation.
try
{
IList<TableResult> z = await table.ExecuteBatchAsync(batchOperation);
foreach (var i in z)
{
CustomerEntity y = (CustomerEntity)i.Result;
Console.WriteLine(y.PartitionKey);
}
var x = z;
}
catch (StorageException e)
{
var z = e.RequestInformation.HttpStatusCode;
var zz = 3;
}*/
}
示例2: DoInsert
async Task<CommandResult> DoInsert(CloudTable table, long n, Func<long, EntityNk[]> entityFactory)
{
var batchOperation = new TableBatchOperation();
foreach (var e in entityFactory(n))
{
batchOperation.Insert(e);
}
var cresult = new CommandResult { Start = DateTime.UtcNow.Ticks };
var cbt = 0L;
var context = GetOperationContext((t) => cbt = t);
try
{
var results = await table.ExecuteBatchAsync(batchOperation, operationContext: context);
cresult.Elapsed = cbt;
}
catch (Exception ex)
{
cresult.Elapsed = -1;
Console.Error.WriteLine("Error DoInsert {0} {1}", n, ex.ToString());
}
return cresult;
}
示例3: MyClassInitialize
public static async Task MyClassInitialize(TestContext testContext)
{
tableClient = GenerateCloudTableClient();
currentTable = tableClient.GetTableReference(GenerateRandomTableName());
await currentTable.CreateIfNotExistsAsync();
for (int i = 0; i < 15; i++)
{
TableBatchOperation batch = new TableBatchOperation();
for (int j = 0; j < 100; j++)
{
DynamicTableEntity ent = GenerateRandomEntity("tables_batch_" + i.ToString());
ent.RowKey = string.Format("{0:0000}", j);
batch.Insert(ent);
}
await currentTable.ExecuteBatchAsync(batch);
}
}
示例4: BatchInsertOfCustomerEntitiesAsync
/// <summary>
/// Demonstrate inserting of a large batch of entities. Some considerations for batch operations:
/// 1. You can perform updates, deletes, and inserts in the same single batch operation.
/// 2. A single batch operation can include up to 100 entities.
/// 3. All entities in a single batch operation must have the same partition key.
/// 4. While it is possible to perform a query as a batch operation, it must be the only operation in the batch.
/// 5. Batch size must be <= 4MB
/// </summary>
/// <param name="table">Sample table name</param>
private static async Task BatchInsertOfCustomerEntitiesAsync(CloudTable table)
{
// Create the batch operation.
TableBatchOperation batchOperation = new TableBatchOperation();
// The following code generates test data for use during the query samples.
for (int i = 0; i < 100; i++)
{
batchOperation.InsertOrMerge(new CustomerEntity("Smith", string.Format("{0}", i.ToString("D4")))
{
Email = string.Format("{0}@contoso.com", i.ToString("D4")),
PhoneNumber = string.Format("425-555-{0}", i.ToString("D4"))
});
}
// Execute the batch operation.
IList<TableResult> results = await table.ExecuteBatchAsync(batchOperation);
foreach (var res in results)
{
var customerInserted = res.Result as CustomerEntity;
Console.WriteLine("Inserted entity with\t Etag = {0} and PartitionKey = {1}, RowKey = {2}", customerInserted.ETag, customerInserted.PartitionKey, customerInserted.RowKey);
}
}
示例5: ExecuteBatchAsync
/// <inheritdoc />
public async Task<IList<TableResult>> ExecuteBatchAsync(CloudTable table, TableBatchOperation batch)
{
if (table == null)
{
throw new ArgumentNullException(nameof(table));
}
if (batch == null)
{
throw new ArgumentNullException(nameof(batch));
}
try
{
IList<TableResult> results = await table.ExecuteBatchAsync(batch);
return results;
}
catch (Exception ex)
{
string errorMessage = GetStorageErrorMessage(ex);
int statusCode = GetStorageStatusCode(ex);
string msg = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.StorageManager_OperationFailed, statusCode, errorMessage);
_logger.Error(msg, ex);
return new List<TableResult>();
}
}
示例6: MyClassInitialize
public static async Task MyClassInitialize(TestContext testContext)
{
CloudTableClient tableClient = GenerateCloudTableClient();
currentTable = tableClient.GetTableReference(GenerateRandomTableName());
await currentTable.CreateIfNotExistsAsync();
// Bulk Query Entities
for (int i = 0; i < 15; i++)
{
TableBatchOperation batch = new TableBatchOperation();
for (int j = 0; j < 100; j++)
{
var ent = GenerateRandomEnitity("tables_batch_" + i.ToString());
ent.RowKey = string.Format("{0:0000}", j);
batch.Insert(ent);
}
await currentTable.ExecuteBatchAsync(batch);
}
complexEntityTable = tableClient.GetTableReference(GenerateRandomTableName());
await complexEntityTable.CreateAsync();
// Setup
TableBatchOperation complexBatch = new TableBatchOperation();
string pk = Guid.NewGuid().ToString();
for (int m = 0; m < 100; m++)
{
ComplexEntity complexEntity = new ComplexEntity(pk, string.Format("{0:0000}", m));
complexEntity.String = string.Format("{0:0000}", m);
complexEntity.Binary = new byte[] { 0x01, 0x02, (byte)m };
complexEntity.BinaryPrimitive = new byte[] { 0x01, 0x02, (byte)m };
complexEntity.Bool = m % 2 == 0 ? true : false;
complexEntity.BoolPrimitive = m % 2 == 0 ? true : false;
complexEntity.Double = m + ((double)m / 100);
complexEntity.DoublePrimitive = m + ((double)m / 100);
complexEntity.Int32 = m;
complexEntity.Int32N = m;
complexEntity.IntegerPrimitive = m;
complexEntity.IntegerPrimitiveN = m;
complexEntity.Int64 = (long)int.MaxValue + m;
complexEntity.LongPrimitive = (long)int.MaxValue + m;
complexEntity.LongPrimitiveN = (long)int.MaxValue + m;
complexEntity.Guid = Guid.NewGuid();
complexBatch.Insert(complexEntity);
if (m == 50)
{
middleRef = complexEntity;
}
// Add delay to make times unique
Thread.Sleep(100);
}
await complexEntityTable.ExecuteBatchAsync(complexBatch);
}
示例7: BatchInsertOfCustomerEntitiesAsync
private async Task BatchInsertOfCustomerEntitiesAsync(CloudTable table)
{
TableBatchOperation batchOperation = new TableBatchOperation();
for (int i = 0; i < 100; i++)
{
batchOperation.InsertOrMerge(new PersonEntity("Smith", string.Format("{0}", i.ToString("D4")))
{
Email = string.Format("{0}@contoso.com", i.ToString("D4")),
PhoneNumber = string.Format("425-555-{0}", i.ToString("D4"))
});
}
IList<TableResult> results = await table.ExecuteBatchAsync(batchOperation);
foreach (var res in results)
{
var customerInserted = res.Result as PersonEntity;
Console.WriteLine("Inserted entity with\t Etag = {0} and PartitionKey = {1}, RowKey = {2}", customerInserted.ETag, customerInserted.PartitionKey, customerInserted.RowKey);
}
}