我正在设置一个使用 Azure 推送通知的 Web API 项目。我想使用新的“安装”模型而不是旧的“注册”模型。然而,该文档有点有限。
查看MSDN ,Microsoft.Azure.NotificationHubs.Installation
具有 Tags
属性。
还有一个模板
property 。模板类型为 InstallationTemplate
和 surprisingly还有标签
。
模板不仅仅是一个列表,而是一个从string
映射到InstallationTemplate
的字典。
我理解标签背后的想法。但我对这两个标签属性和字典的键感到困惑。
我看到一个示例,其中Installation.Tag
设置为“foo”,然后使用键“template1”和“template2”添加两个模板。 InstallationTemplate.Tag
设置为“tag-for-template1”和“tag-for-template2”。
- 两个标签值必须匹配吗?
- 它们各自的用途是什么?
- 模板字典的键应该是什么?
- 如果我使用该方法通过NotificationHubClient发送通知,我可以指定一个标签 - 它与什么匹配以及将选择哪个模板?
最佳答案
经过一些测试,我变得更明智了。
两者,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>
而不是字典。
关于c# - 使用 Microsoft.Azure.NotificationHubs.Installation 类时如何选择模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107932/