4

I'm setting up a Web API project that uses Azure Push Notifications. I'd like to use the new "Installation" model instead of the older "Registration" model. The documentation is a bit limited however.

Looking at MSDN, Microsoft.Azure.NotificationHubs.Installation has a Tags property.

There is also has a Templates property. The template type is InstallationTemplate and surprisingly also has Tags.

The templates are not just a list but a dictionary that maps from string to InstallationTemplate.

I understand the idea behind tags. But I'm confused about the two tag properties and the key of the dictionary.

I saw an example where the Installation.Tagis set to "foo" and then two templates are added with the keys "template1" and "template2". The InstallationTemplate.Tag was set to "tag-for-template1" and "tag-for-template2".

  • Do the two tag values have to match?
  • What is each of them used for?
  • What should the key of the template dictionary be?
  • If I use the method to send a notification via the NotificationHubClient, I can specify a tag - what is it matched against and which template will be picked?
Nikita R.
  • 7,245
  • 3
  • 51
  • 62
Krumelur
  • 32,180
  • 27
  • 124
  • 263

1 Answers1

3

After some testing I'm a bit wiser.

Both, the Microsoft.Azure.NotificationHubs.Installation's tags and the tags inside of the InstallationTemplate will be evaluated when using SendTemplateNotificationAsync(). The key that has to be specified in the dictionary seems to be unused.

Example:

var installationA = new Installation();
installationA.Tags = new List<string> { $"install-a" };
installationA.Templates.Add("someKey", new InstallationTemplate
{
    Body = "JSON-FOR-TEMPLATE"
    Tags = new List<string> { $"subtemplate1" }
});
installationA.Templates.Add("someOtherKey", new InstallationTemplate
{
    Body = "JSON-FOR-TEMPLATE"
    Tags = new List<string> { $"subtemplate2" }
});


var installationB = new Installation();
installationB.Tags = new List<string> { $"install-b" };
installationB.Templates.Add("someKey", new InstallationTemplate
{
    Body = "JSON-FOR-TEMPLATE"
    Tags = new List<string> { $"subtemplate1" }
});
installationB.Templates.Add("someOtherKey", new InstallationTemplate
{
    Body = "JSON-FOR-TEMPLATE"
    Tags = new List<string> { $"subtemplate2" }
});

Using tag expressions you can now filter for any combination of "install-a", "install-b", "subtemplate1" and "subtemplate2".

The keys "someKey" and "someOtherKey" will not be used by the query and I don't understand why they did not use a List<T> instead of the dictionary.

Krumelur
  • 32,180
  • 27
  • 124
  • 263