因此,Microsoft决定将诊断数据发送到Azure表存储。我正在尝试查询此存储并将其发送到另一个位置以通过C#SDK进行分析。我可以很好地查询数十万条记录,但看起来它们发送的最后一个延续令牌将始终收到空响应。即使将更多数据发送到表存储,我的延续令牌也不起作用,仍然会获得空的延续令牌和空数据。
有人做过这样的事吗?如果他们发送的延续令牌被破坏,如何继续“同步”azure表数据?
public static List<PerfMonEntity> GetEventData(ref TableContinuationToken contToken)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable eventLogsTable = tableClient.GetTableReference("WADPerformanceCountersTable");
TableQuery<PerfMonEntity> query = new TableQuery<PerfMonEntity>();
var l = new List<PerfMonEntity>();
var segment = eventLogsTable.ExecuteQuerySegmented(query, contToken ?? new TableContinuationToken());
foreach (PerfMonEntity wadCounter in segment)
{
l.Add(wadCounter);
}
contToken = segment.ContinuationToken;
if (contToken == null)
{
Console.WriteLine("contToken is NULL!");
return null;
}
Console.WriteLine("partkey: {0}", contToken.NextPartitionKey ?? "");
Console.WriteLine("rowkey: {0}", contToken.NextRowKey ?? "");
return l;
}
- = - = - = - = - = -
while (num < loop)
{
List<PerfMonEntity> eleList = AzurePerfTable.GetEventData(ref contToken);
if (eleList != null)
returnedList.AddRange(eleList);
else
num = loop;
num += 1;
if (contToken != null)
AZContinuationToken.SetContToken(contToken);
Console.WriteLine("returnedlistsize: {0}", returnedList.Count<PerfMonEntity>());
}
答案 0 :(得分:0)
当没有更多数据要返回时,continuation标记为null。如果它为非null,则表示在下一页中还有其他实体要返回。您可以检查null以确定何时检索到最后一页然后退出循环。
尝试按以下方式编写逻辑:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable eventLogsTable = tableClient.GetTableReference("WADPerformanceCountersTable");
TableQuery query = new TableQuery();
Console.WriteLine("List perf counter results in pages:");
TableContinuationToken token = null;
do
{
var segment = eventLogsTable.ExecuteQuerySegmented(query, token, null, null);
foreach (var wadCounter in segment)
{
Console.WriteLine(wadCounter.PartitionKey);
Console.WriteLine(wadCounter.RowKey);
Console.WriteLine(wadCounter.Timestamp);
}
token = segment.ContinuationToken;
}
while (token != null);