c# - 使用 Microsoft.Azure.NotificationHubs.Installation 类时如何选择模板?

标签 c# azure push-notification azure-notificationhub

我正在设置一个使用 Azure 推送通知的 Web API 项目。我想使用新的“安装”模型而不是旧的“注册”模型。然而,该文档有点有限。

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

还有一个模板 property 。模板类型为 InstallationTemplatesurprisingly还有标签

模板不仅仅是一个列表,而是一个从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/

相关文章:

c# - 如何防止XDocument添加XML版本和编码信息

azure - 创建 Azure 表存储

ios - 在 iOS 上重置通知标志的问题 - Swift

c# - 如何在 C# 中使用任何可靠的 XMPP 库连接 FCM 服务器?

c# - 将选项模式与 Azure Key Vault 结合使用?

c# - UWP 用户控件 + 内容控件

c# - 记录异常并重新抛出的 Polly 策略

Azure WebAPI,它需要 id token 还是访问 token 作为承载?

c# - 在 Microsoft Azure Web 应用程序中以编程方式访问性能计数器

react-native - Expo 推送通知 - 当应用程序处于前台时,它会导致 iOS 崩溃