How to get all installations when using Azure Notification Hubs installation model?

穿精又带淫゛_ 提交于 2019-12-12 11:40:30

问题


Using NotificationHubClient I can get all 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 but none to get everything.


回答1:


You're correct, as of July 2016 there's no way to get all installations for a hub. In the future, the product team is planning to add this feature to the installations model, but it will work in a different way. Instead of making it a runtime operation, you'll provide your storage connection string and you'll get a blob with everything associated with the hub.




回答2:


Sorry for visiting an old thread... but in theory you could use the GetAllRegistrationsAsyc to get all the installations. I guess this will return everything without an installation id as well, but you could just ignore those if you choose.

Could look something like this

        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);
        }

I am not suggesting this to be the cleanest chunk of code written, but it does the trick for us. We only use this for debugging type purposes anyways



来源:https://stackoverflow.com/questions/38108730/how-to-get-all-installations-when-using-azure-notification-hubs-installation-mod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!