Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 686
Krumelur Avatar asked Jun 29 '16 19:06

Krumelur


2 Answers

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.

like image 91
Nikita R. Avatar answered Oct 17 '22 23:10

Nikita R.


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

like image 1
AndySousa Avatar answered Oct 17 '22 21:10

AndySousa