问题描述

在Notification Hub中注册了设备后,从Azure门户上没有找到相应的入口来删除已注册设备 (Active Devices)

如果使用C# SDK是否有办法删除呢?

问题解答

可以的,查看Notification Hub的文档,可以通过注册ID来删除一个注册设备:https://docs.azure.cn/zh-cn/notification-hubs/notification-hubs-push-notification-registration-management#example-code-to-register-with-a-notification-hub-from-a-backend-using-a-registration-id

示例代码

MainPage.xaml.cs

using Microsoft.Azure.NotificationHubs;
using Microsoft.WindowsAzure.Messaging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Networking.PushNotifications;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 namespace NoteHubApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
//Connection String & Notification Hub Name
const string nhName = "NH Name";
const string managementConnectionString = "NH Connection String"; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(managementConnectionString, nhName); List<string> registrationIds = new List<string>();
public MainPage()
{
this.InitializeComponent();
} private void MyButton_Click(object sender, RoutedEventArgs e)
{
RegisterDevices(); RefreshAllRegistration();
}
private async void RegisterDevices()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
// create a registration description object of the correct type, e.g.
var reg = new WindowsRegistrationDescription(channel.Uri);
// Create
var result = await hub.CreateRegistrationAsync(reg);
// Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
registrationIds.Add(result.RegistrationId); var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
RefreshAllRegistration();
} private async void RefreshAllRegistration()
{
registrationIds.Clear(); var allRegistrations = await hub.GetAllRegistrationsAsync(100); showresult.Text = "Registrations Total is " + allRegistrations.Count().ToString() + "\n"; foreach (var registration in allRegistrations)
{
registrationIds.Add(registration.RegistrationId); showresult.Text += registration.RegistrationId + "\n";
} //var dialogs = new MessageDialog("Get Registrations Number " + allRegistrations.Count().ToString());
//dialogs.Commands.Add(new UICommand("OK"));
//await dialogs.ShowAsync();
} private void Delete_Click(object sender, RoutedEventArgs e)
{
DeleteDevices();
} private async void DeleteDevices()
{
if (registrationIds.Count > 0)
{
var rid = registrationIds[registrationIds.Count - 1];
// Get by ID
var r = await hub.GetRegistrationAsync<RegistrationDescription>(rid);
try
{
// delete
await hub.DeleteRegistrationAsync(r);
registrationIds.Remove(rid);
var dialog = new MessageDialog("Delete Registration: " + rid);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
catch
{
} RefreshAllRegistration();
}
}
}
}

MainPage.xaml

<Page
x:Class="NoteHubApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NoteHubApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Height="1027" Width="1623">
<Grid Margin="0,0,66,30">
<Button x:Name="MyButton" Content="Register One!" Click="MyButton_Click" Height="244" Width="243" Margin="48,610,0,0" VerticalAlignment="Top" RenderTransformOrigin="2.758,-2.919" Background="#33228919"/>
<Button x:Name="MyButton_Copy" Content="Refresh All Register!" Click="Refresh_Click" Height="809" Width="198" Margin="723,36,0,0" VerticalAlignment="Top" Background="#33D26136"/>
<Button x:Name="MyButton_Copy1" Content="Delete Old One!" Click="Delete_Click" Height="238" Width="374" Margin="315,613,0,0" VerticalAlignment="Top" Background="#33172D5D"/>
<TextBox x:Name="showresult" HorizontalAlignment="Left" Margin="30,28,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Height="556" Width="664" Background="#667B857A"/>
</Grid>
</Page>

UI 展示如下:

参考资料

注册管理 (DeleteRegistrationAsync)  : https://docs.azure.cn/zh-cn/notification-hubs/notification-hubs-push-notification-registration-management#example-code-to-register-with-a-notification-hub-from-a-backend-using-a-registration-id

 

【Azure Notification Hub】如何手动删除 Notification Hub 中已注册的设备的更多相关文章

  1. 如何删除docker镜像中已配置的volume

    场景: 有个同学不知道因为啥,将容器内部的 /sys/fs/cgroup 挂载到了外面的某个目录: 但是这个目录是很有用的,不想随便被挂载,如何从image中去掉呢? docker没有给出一个方便的方 ...

  2. Azure IoT 技术研究系列4-Azure IoT Hub的配额及缩放级别

    上两篇博文中,我们介绍了将设备注册到Azure IoT Hub,设备到云.云到设备之间的通信: Azure IoT 技术研究系列2-设备注册到Azure IoT Hub Azure IoT 技术研究系 ...

  3. Azure IoT 技术研究系列5-Azure IoT Hub与Event Hub比较

    上篇博文中,我们介绍了Azure IoT Hub的使用配额和缩放级别: Azure IoT 技术研究系列4-Azure IoT Hub的配额及缩放级别 本文中,我们比较一下Azure IoT Hub和 ...

  4. Azure Event Hub 技术研究系列3-Event Hub接收事件

    上篇博文中,我们通过编程的方式介绍了如何将事件消息发送到Azure Event Hub: Azure Event Hub 技术研究系列2-发送事件到Event Hub 本篇文章中,我们继续:从Even ...

  5. Android中使用Notification实现进度通知栏(Notification示例三)

    我们在使用APP的过程中,软件会偶尔提示我们进行版本更新,我们点击确认更新后,会在通知栏显示下载更新进度(已知长度的进度条)以及安装情况(不确定进度条),这就是我们今天要实现的功能.实现效果如下: 在 ...

  6. Android中使用Notification实现普通通知栏(Notification示例一)

    Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer) ...

  7. Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式

    前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...

  8. 手动删除portal中托管服务。

    在portal中将server作为托管联合服务器,然后发布了托管服务.若中间取消了托管联合服务器,再重新连接,那么会出现之前的托管服务无法删除的现象. 下文为怎样手动删除这些服务的方法,(不过貌似之后 ...

  9. 用于svn添加当前目录下所有未追踪的文件,和删除所有手动删除的文件的脚本

    由于要经常用到类似与 git 中的 git add --all 这种操作,但是发现svn中并不支持类似的操作. 虽然可以使用 wildcard 进行匹配,但是 wildcard是在shell中进行匹配 ...

  10. Azure Automation (2) 定期删除存储账号中的文件

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文是对笔者之前的文档Azure Backup (1) 将SQL ...

随机推荐

  1. [官网]Apache Log4j2 最新版安全提示 2.17.0

    https://logging.apache.org/log4j/2.x/ 最近一个周的时间 log4j2 从 2.14 跃升到了2.17 还在不停的升级 安全问题正是焦头烂额 free softwa ...

  2. 分布式日志追踪ID实战 | 京东物流技术团队

    本文通过介绍分布式应用下各个场景的全局日志ID透传思路,以及介绍分布式日志追踪ID简单实现原理和实战效果,从而达到通过提高日志查询排查问题的效率. 背景 开发排查系统问题用得最多的手段就是查看系统日志 ...

  3. String 中的Trim

    Trim 切除首尾指定字符 var newStr=""; char[] trimChars={'@','#','$',' '}; string strC="@Hello# ...

  4. 深度学习实践篇[17]:模型压缩技术、模型蒸馏算法:Patient-KD、DistilBERT、DynaBERT、TinyBERT

    深度学习实践篇[17]:模型压缩技术.模型蒸馏算法:Patient-KD.DistilBERT.DynaBERT.TinyBERT 1.模型压缩概述 1.2模型压缩原有 理论上来说,深度神经网络模型越 ...

  5. 数据挖掘[一]---汽车车交易价格预测(测评指标;EDA)

    题目出自阿里天池赛题链接:零基础入门数据挖掘 - 二手车交易价格预测-天池大赛-阿里云天池 相关文章: 特征工程详解及实战项目[参考] 数据挖掘---汽车车交易价格预测[一](测评指标:EDA) 数据 ...

  6. Python 提取图片中的GPS信息

    JPG图片中默认存在敏感数据,例如位置,相机类型等,可以使用Python脚本提取出来,加以利用,自己手动拍摄一张照片,然后就能解析出这些敏感数据了,对于渗透测试信息搜索有一定帮助,但有些相机默认会抹除 ...

  7. 散片便宜300元!但还是劝你买盒装CPU

    喜欢DIY的小伙伴在选购产品时会纠结于散片和盒装,以13代酷睿i5-13600KF为例,散片一般是1899元左右,而盒装2199元,两者相差300元,AMD的锐龙5 7600也差不多,盒装和散片相差也 ...

  8. 优化利器In-Memory开启和效果

    本文主要介绍Oracle In-Memory 选件,Oracle在12.1.0.2就已经推出了In-Memory这个选件,现在通常会建议所有使用19.8及之后版本的用户,有条件都要留给In-memor ...

  9. mysql 索引优化 explain,复合索引,联合索引,优化 user_base 和 log_login 实战

    本节是关于MySQL的复合索引相关的知识,两个或更多个列上的索引被称作复合索引,本文主要介绍了mysql 联合索引生效的条件及失效的条件 对于复合索引:Mysql从左到右的使用索引中的字段,一个查询可 ...

  10. .NET 云原生架构师训练营(模块二 基础巩固 EF Core 介绍)--学习笔记

    2.4.2 EF Core -- 介绍 ORM Repository 仓储 UnitOfWork 工作单元 DB Context 与 DB Set EF Core快速开始示例 ORM ORM:obje ...