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.Tag
is 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".
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With