本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteQuerySegmentedAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudTable.ExecuteQuerySegmentedAsync方法的具体用法?C# CloudTable.ExecuteQuerySegmentedAsync怎么用?C# CloudTable.ExecuteQuerySegmentedAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Table.CloudTable
的用法示例。
在下文中一共展示了CloudTable.ExecuteQuerySegmentedAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteAllEntities
private static async Task DeleteAllEntities(CloudTable table)
{
TableQuerySegment<DynamicTableEntity> segment = null;
while (segment == null || segment.ContinuationToken != null)
{
segment = await table.ExecuteQuerySegmentedAsync(new TableQuery().Take(100), segment?.ContinuationToken);
foreach (var entity in segment.Results)
{
await table.ExecuteAsync(TableOperation.Delete(entity));
}
}
}
示例2: ExecuteQuery
private static List<DynamicTableEntity> ExecuteQuery(CloudTable table, TableQuery query)
{
List<DynamicTableEntity> retList = new List<DynamicTableEntity>();
TableQuerySegment<DynamicTableEntity> currSeg = null;
while (currSeg == null || currSeg.ContinuationToken != null)
{
Task<TableQuerySegment<DynamicTableEntity>> task = Task.Run(() => table.ExecuteQuerySegmentedAsync(query, currSeg != null ? currSeg.ContinuationToken : null));
task.Wait();
currSeg = task.Result;
retList.AddRange(currSeg.Results);
}
return retList;
}
示例3: PartitionScanAsync
/// <summary>
/// Demonstrate a partition scan whereby we are searching for all the entities within a partition. Note this is not as efficient
/// as a range scan - but definitely more efficient than a full table scan. The async API's require the user to implement
/// paging themselves using continuation tokens.
/// </summary>
/// <param name="table">Sample table name</param>
/// <param name="partitionKey">The partition within which to search</param>
private static async Task PartitionScanAsync(CloudTable table, string partitionKey)
{
TableQuery<CustomerEntity> partitionScanQuery = new TableQuery<CustomerEntity>().Where
(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey));
TableContinuationToken token = null;
// Page through the results
do
{
TableQuerySegment<CustomerEntity> segment = await table.ExecuteQuerySegmentedAsync(partitionScanQuery, token);
token = segment.ContinuationToken;
foreach (CustomerEntity entity in segment)
{
Console.WriteLine("Customer: {0},{1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, entity.Email, entity.PhoneNumber);
}
}
while (token != null);
}
示例4: PartitionRangeQueryAsync
/// <summary>
/// Demonstrate a partition range query whereby we are searching within a partition for a set of entities that are within a
/// specific range. The async API's require the user to implement paging themselves using continuation tokens.
/// </summary>
/// <param name="table">Sample table name</param>
/// <param name="partitionKey">The partition within which to search</param>
/// <param name="startRowKey">The lowest bound of the row key range within which to search</param>
/// <param name="endRowKey">The highest bound of the row key range within which to search</param>
private static async Task PartitionRangeQueryAsync(CloudTable table, string partitionKey, string startRowKey, string endRowKey)
{
// Create the range query using the fluid API
TableQuery<CustomerEntity> rangeQuery = new TableQuery<CustomerEntity>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
TableOperators.And,
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, startRowKey),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, endRowKey))));
// Page through the results - requesting 50 results at a time from the server.
TableContinuationToken token = null;
rangeQuery.TakeCount = 50;
do
{
TableQuerySegment<CustomerEntity> segment = await table.ExecuteQuerySegmentedAsync(rangeQuery, token);
token = segment.ContinuationToken;
foreach (CustomerEntity entity in segment)
{
Console.WriteLine("Customer: {0},{1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, entity.Email, entity.PhoneNumber);
}
}
while (token != null);
}
示例5: TableSASConstructorsAsync
public async Task TableSASConstructorsAsync()
{
CloudTableClient tableClient = GenerateCloudTableClient();
CloudTable table = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));
try
{
await table.CreateAsync();
await table.ExecuteAsync(TableOperation.Insert(new BaseEntity("PK", "RK")));
// Prepare SAS authentication with full permissions
string sasToken = table.GetSharedAccessSignature(
new SharedAccessTablePolicy
{
Permissions = SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Delete | SharedAccessTablePermissions.Query,
SharedAccessExpiryTime = DateTimeOffset.Now.AddMinutes(30)
},
null /* accessPolicyIdentifier */,
null /* startPk */,
null /* startRk */,
null /* endPk */,
null /* endRk */);
CloudStorageAccount sasAccount;
StorageCredentials sasCreds;
CloudTableClient sasClient;
CloudTable sasTable;
Uri baseUri = new Uri(TestBase.TargetTenantConfig.TableServiceEndpoint);
// SAS via connection string parse
sasAccount = CloudStorageAccount.Parse(string.Format("TableEndpoint={0};SharedAccessSignature={1}", baseUri.AbsoluteUri, sasToken));
sasClient = sasAccount.CreateCloudTableClient();
sasTable = sasClient.GetTableReference(table.Name);
Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());
// SAS via account constructor
sasCreds = new StorageCredentials(sasToken);
sasAccount = new CloudStorageAccount(sasCreds, null, null, baseUri, null);
sasClient = sasAccount.CreateCloudTableClient();
sasTable = sasClient.GetTableReference(table.Name);
Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());
// SAS via client constructor URI + Creds
sasCreds = new StorageCredentials(sasToken);
sasClient = new CloudTableClient(baseUri, sasCreds);
Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());
// SAS via CloudTable constructor Uri + Client
sasCreds = new StorageCredentials(sasToken);
sasTable = new CloudTable(table.Uri, tableClient.Credentials);
sasClient = sasTable.ServiceClient;
Assert.AreEqual(1, (await sasTable.ExecuteQuerySegmentedAsync(new TableQuery<BaseEntity>(), null)).Results.Count());
}
finally
{
table.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例6: ExecuteQueryAsync
/// <inheritdoc />
public async Task<IEnumerable<DynamicTableEntity>> ExecuteQueryAsync(CloudTable table, TableQuery query)
{
if (table == null)
{
throw new ArgumentNullException(nameof(table));
}
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
try
{
List<DynamicTableEntity> result = new List<DynamicTableEntity>();
TableQuerySegment<DynamicTableEntity> segment;
TableContinuationToken continuationToken = null;
do
{
segment = await table.ExecuteQuerySegmentedAsync(query, continuationToken);
if (segment == null)
{
break;
}
result.AddRange(segment);
continuationToken = segment.ContinuationToken;
}
while (continuationToken != null);
return result;
}
catch (Exception ex)
{
string errorMessage = GetStorageErrorMessage(ex);
string msg = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.StorageManager_QueryFailed, errorMessage);
_logger.Error(msg, ex);
throw new InvalidOperationException(msg, ex);
}
}
示例7: PartitionScanAsync
/// <summary>
/// Demonstrate a partition scan whereby we are searching for all the entities within a partition. Note this is not as efficient
/// as a range scan - but definitely more efficient than a full table scan. The async APIs require that the user handle the segment
/// size and return the next segment using continuation tokens.
/// </summary>
/// <param name="table">Sample table name</param>
/// <param name="partitionKey">The partition within which to search</param>
/// <returns>A Task object</returns>
private static async Task PartitionScanAsync(CloudTable table, string partitionKey)
{
try
{
TableQuery<CustomerEntity> partitionScanQuery =
new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey));
TableContinuationToken token = null;
// Read entities from each query segment.
do
{
TableQuerySegment<CustomerEntity> segment = await table.ExecuteQuerySegmentedAsync(partitionScanQuery, token);
token = segment.ContinuationToken;
foreach (CustomerEntity entity in segment)
{
Console.WriteLine("Customer: {0},{1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, entity.Email, entity.PhoneNumber);
}
}
while (token != null);
}
catch (StorageException e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
throw;
}
}
示例8: PartitionRangeQueryAsync
/// <summary>
/// Demonstrate a partition range query that searches within a partition for a set of entities that are within a
/// specific range. The async APIs require that the user handle the segment size and return the next segment
/// using continuation tokens.
/// </summary>
/// <param name="table">Sample table name</param>
/// <param name="partitionKey">The partition within which to search</param>
/// <param name="startRowKey">The lowest bound of the row key range within which to search</param>
/// <param name="endRowKey">The highest bound of the row key range within which to search</param>
/// <returns>A Task object</returns>
private static async Task PartitionRangeQueryAsync(CloudTable table, string partitionKey, string startRowKey, string endRowKey)
{
try
{
// Create the range query using the fluid API
TableQuery<CustomerEntity> rangeQuery = new TableQuery<CustomerEntity>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
TableOperators.And,
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, startRowKey),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, endRowKey))));
// Request 50 results at a time from the server.
TableContinuationToken token = null;
rangeQuery.TakeCount = 50;
int segmentNumber = 0;
do
{
// Execute the query, passing in the continuation token.
// The first time this method is called, the continuation token is null. If there are more results, the call
// populates the continuation token for use in the next call.
TableQuerySegment<CustomerEntity> segment = await table.ExecuteQuerySegmentedAsync(rangeQuery, token);
// Indicate which segment is being displayed
if (segment.Results.Count > 0)
{
segmentNumber++;
Console.WriteLine();
Console.WriteLine("Segment {0}", segmentNumber);
}
// Save the continuation token for the next call to ExecuteQuerySegmentedAsync
token = segment.ContinuationToken;
// Write out the properties for each entity returned.
foreach (CustomerEntity entity in segment)
{
Console.WriteLine("\t Customer: {0},{1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, entity.Email, entity.PhoneNumber);
}
Console.WriteLine();
}
while (token != null);
}
catch (StorageException e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
throw;
}
}
示例9: PartitionRangeQueryAsync
private async Task PartitionRangeQueryAsync(CloudTable table, string partitionKey, string startRowKey, string endRowKey)
{
TableQuery<PersonEntity> rangeQuery = new TableQuery<PersonEntity>().Where(
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
TableOperators.And,
TableQuery.CombineFilters(
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, startRowKey),
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, endRowKey))));
TableContinuationToken token = null;
rangeQuery.TakeCount = 50;
do
{
TableQuerySegment<PersonEntity> segment = await table.ExecuteQuerySegmentedAsync(rangeQuery, token);
token = segment.ContinuationToken;
foreach (PersonEntity entity in segment)
{
Console.WriteLine("Customer: {0},{1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, entity.Email, entity.PhoneNumber);
}
}
while (token != null);
}