使用 Azure 通知中心安装模型时如何获取所有安装?
How to get all installations when using Azure Notification Hubs installation model?
使用 NotificationHubClient
我可以获得所有 registered devices using GetAllRegistrationsAsync()
. But if I do not use the registration model but the installation model instead, how can I get all installations? There are methods to retrieve a specific installation 但 none 可以获得所有。
您是对的,截至 2016 年 7 月,无法获取集线器的所有安装。未来,产品团队计划将此功能添加到安装模型中,但它将以不同的方式工作。您将提供存储连接字符串,而不是使其成为运行时操作,您将获得一个 blob,其中包含与 hub 关联的所有内容。
抱歉访问旧线程...但理论上您可以使用 GetAllRegistrationsAsyc 获取所有安装。我想这也会 return 所有没有安装 ID 的东西,但如果你愿意,你可以忽略它们。
可能看起来像这样
var allRegistrations = await _hub.GetAllRegistrationsAsync(0);
var continuationToken = allRegistrations.ContinuationToken;
var registrationDescriptionsList = new List<RegistrationDescription>(allRegistrations);
while (!string.IsNullOrWhiteSpace(continuationToken))
{
var otherRegistrations = await _hub.GetAllRegistrationsAsync(continuationToken, 0);
registrationDescriptionsList.AddRange(otherRegistrations);
continuationToken = otherRegistrations.ContinuationToken;
}
// Put into DeviceInstallation object
var deviceInstallationList = new List<DeviceInstallation>();
foreach (var registration in registrationDescriptionsList)
{
var deviceInstallation = new DeviceInstallation();
var tags = registration.Tags;
foreach(var tag in tags)
{
if (tag.Contains("InstallationId:"))
{
deviceInstallation.InstallationId = new Guid(tag.Substring(tag.IndexOf(":")+1));
}
}
deviceInstallation.PushHandle = registration.PnsHandle;
deviceInstallation.Tags = new List<string>(registration.Tags);
deviceInstallationList.Add(deviceInstallation);
}
我并不是说这是编写的最干净的代码块,但它为我们提供了窍门。无论如何,我们只将其用于调试类型目的
使用 NotificationHubClient
我可以获得所有 registered devices using GetAllRegistrationsAsync()
. But if I do not use the registration model but the installation model instead, how can I get all installations? There are methods to retrieve a specific installation 但 none 可以获得所有。
您是对的,截至 2016 年 7 月,无法获取集线器的所有安装。未来,产品团队计划将此功能添加到安装模型中,但它将以不同的方式工作。您将提供存储连接字符串,而不是使其成为运行时操作,您将获得一个 blob,其中包含与 hub 关联的所有内容。
抱歉访问旧线程...但理论上您可以使用 GetAllRegistrationsAsyc 获取所有安装。我想这也会 return 所有没有安装 ID 的东西,但如果你愿意,你可以忽略它们。
可能看起来像这样
var allRegistrations = await _hub.GetAllRegistrationsAsync(0);
var continuationToken = allRegistrations.ContinuationToken;
var registrationDescriptionsList = new List<RegistrationDescription>(allRegistrations);
while (!string.IsNullOrWhiteSpace(continuationToken))
{
var otherRegistrations = await _hub.GetAllRegistrationsAsync(continuationToken, 0);
registrationDescriptionsList.AddRange(otherRegistrations);
continuationToken = otherRegistrations.ContinuationToken;
}
// Put into DeviceInstallation object
var deviceInstallationList = new List<DeviceInstallation>();
foreach (var registration in registrationDescriptionsList)
{
var deviceInstallation = new DeviceInstallation();
var tags = registration.Tags;
foreach(var tag in tags)
{
if (tag.Contains("InstallationId:"))
{
deviceInstallation.InstallationId = new Guid(tag.Substring(tag.IndexOf(":")+1));
}
}
deviceInstallation.PushHandle = registration.PnsHandle;
deviceInstallation.Tags = new List<string>(registration.Tags);
deviceInstallationList.Add(deviceInstallation);
}
我并不是说这是编写的最干净的代码块,但它为我们提供了窍门。无论如何,我们只将其用于调试类型目的