如何在使用Microsoft.Azure.NotificationHubs.Installation class 时select 模板?

How to select templates when using the Microsoft.Azure.NotificationHubs.Installation class?

我正在设置一个使用 Azure 推送通知的 Web API 项目。我想使用新的 "Installation" 模型而不是旧的 "Registration" 模型。但是文档有点有限。

查看 MSDNMicrosoft.Azure.NotificationHubs.Installation 有一个 Tags 属性。

还有Templatesproperty. The template type is InstallationTemplate and surprisingly还有Tags.

模板不仅仅是一个列表,而是一个从 string 映射到 InstallationTemplate 的字典。

我理解标签背后的想法。但是我对这两个标签属性和字典的键感到困惑。

我看到了一个示例,其中 Installation.Tag 设置为 "foo",然后添加了两个模板,其中包含键 "template1" 和 "template2"。 InstallationTemplate.Tag 设置为 "tag-for-template1" 和 "tag-for-template2"。

经过一些测试,我聪明了一些。

两者,Microsoft.Azure.NotificationHubs.Installation 的标签 InstallationTemplate 内的标签将在使用 SendTemplateNotificationAsync() 时被评估。必须在字典中指定的键似乎未被使用。

示例:

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

使用标记表达式,您现在可以过滤 "install-a"、"install-b"、"subtemplate1" 和 "subtemplate2".

的任意组合

键 "someKey" 和 "someOtherKey" 不会被查询使用,我不明白为什么他们不使用 List<T> 而不是字典。