private async void InitNotificationsAsync() { Exception exception = null; try { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub(ConfigSecrets.AzureNotificationHubName, ConfigSecrets.AzureNotificationHubCnxString); var result = await hub.RegisterNativeAsync(channel.Uri); // Displays the registration ID so you know it was successful if (result.RegistrationId != null) { //var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); //dialog.Commands.Add(new UICommand("OK")); //await dialog.ShowAsync(); UpdateStatus("Chat channel is ready.", false); PushChannel = channel; PushChannel.PushNotificationReceived += OnPushNotification; } } catch (Exception ex) { exception = ex; } if(exception != null) { UpdateStatus("Could not initialize cloud services to receive messages.", true); string msg1 = "An error has occurred while initializing cloud notifications." + Environment.NewLine + Environment.NewLine; // TO DO: Dissect the various potential errors and provide a more appropriate // error message in msg2 for each of them. string msg2 = "Make sure that you have an active Internet connection and try again."; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { new MessageDialog(msg1 + msg2, "Initialization Error").ShowAsync(); }); } }
/// <summary> /// 通知の初期化。 /// </summary> /// <returns></returns> /// <seealso cref="http://azure.microsoft.com/ja-jp/documentation/articles/notification-hubs-windows-store-dotnet-get-started/"/> private async Task InitNotificationsAsync() { // OS の通知機構とやり取りするオブジェクト var channel = await PushNotificationChannelManager .CreatePushNotificationChannelForApplicationAsync(); // ハブ名 // 接続文字列(DefaultListenSharedAccessSignature) var hub = new NotificationHub( "<hub name>", "Endpoint=sb://<hub name>.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=<key>"); // 通知の対象を制限する際の購読例 var tags = new HashSet<string>(); #if WINDOWS_APP tags.Add("group1"); #else tags.Add("group2"); #endif // ハブと接続 //var result = await hub.RegisterNativeAsync(channel.Uri); var result = await hub.RegisterNativeAsync(channel.Uri, tags); // Displays the registration ID so you know it was successful if (result.RegistrationId != null) { var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }
private async Task<RegisterResult> RegisterNativeAsyncInternal(string notificationHubPath, string connectionString, string channelUri, string tags) { // Create the notification hub var hub = new Microsoft.WindowsAzure.Messaging.NotificationHub(notificationHubPath, connectionString); List<string> tagCollection = new List<string>(); if (tags.Contains(",")) { foreach (string tag in tags.Split(',')) { tagCollection.Add(tag); } } else { tagCollection.Add(tags); } // Register with the Notification Hub, passing the push channel uri and the string array of tags var registration = await hub.RegisterNativeAsync(channelUri, tagCollection); var regInfo = new RegisterResult(); regInfo.RegistrationId = registration.RegistrationId; regInfo.ChannelUri = registration.ChannelUri; regInfo.NotificationHubPath = registration.NotificationHubPath; regInfo.Tags = string.Join(",", registration.Tags); return regInfo; }
public PushNotificationHandler() { WindowsAzureConfig windowsAzureConfig = this.GetWindowsAzureConfigInfo(); if (windowsAzureConfig != null) { hub = new NotificationHub(windowsAzureConfig.DevHubName, windowsAzureConfig.DevListenAccessConnectionString); } }
public GeofenceRegistrationManager(string hubName, string hubConnectionString, string pushChannel) { this.tags = new List<string>(); this.hub = new NotificationHub(hubName, hubConnectionString); this.pushChannel = pushChannel; this.monitor = GeofenceMonitor.Current; this.monitor.GeofenceStateChanged += OnGeofenceStateChangedHandler; }
public async void UnregisterFromAzurePushNotification() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub(PushNotificationCredentials.AzureNotificationHubName, PushNotificationCredentials.AzureListenConnectionString); await hub.UnregisterNativeAsync(); }
public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; hub = new NotificationHub("alarms", "Endpoint=sb://[namespace].servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=[key]"); InitNotificationSync(); }
/// <summary> /// Initializes the singleton Application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; var connectionString = ConnectionString.CreateUsingSharedAccessSecretWithListenAccess("sb://ciserversb.servicebus.windows.net", "RVNwaVtIPTBPKW5dazhVMQ=="); notificationHub = new NotificationHub("myhub", connectionString); }
public async static Task RegisterForPush() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); NotificationHub hub = new NotificationHub( "banddemonotificationhub", "Endpoint=sb://banddemonotificationhub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=f+Z7H8h+qauNbeck/QJUe6dAinbLZztCvu+3usaD/Fk="); await hub.RegisterNativeAsync(channel.Uri); }
private async void OnRegisterForNotificationsClicked(object sender, RoutedEventArgs e) { PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); if (channel != null) { string result = $"Registration successfull: the channel url is {channel.Uri}"; Result.Text = result; NotificationHub hub = new NotificationHub("uwpsample", ConnectionString); await hub.RegisterNativeAsync(channel.Uri); } }
private async void btnRegisterForNotificationsWithTemplate_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub(_nothubName, _endPoint); var res = await hub.RegisterTemplateAsync(channel.Uri, txtTemplate.Text, "template1"); if (res.RegistrationId != null) { var dlg = new MessageDialog("Success: " + res.RegistrationId); await dlg.ShowAsync(); } }
private async void InitNotificationAsync() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("myNotificationHub", "Endpoint=sb://mengnan.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=oxxphyduxPkHN4Csuf9WHV9YjjaFESF0M+AkewjunwM="); var result = await hub.RegisterNativeAsync(channel.Uri); if(result.RegistrationId!=null) { var dialog = new MessageDialog("Registeration successful:" + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }
private async void btnRegisterForNotificationsWithTag_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { //parse the tags var tags = txtTags.Text.Split(new char[] { ' ', ',' }); var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub(_nothubName, _endPoint); var res = await hub.RegisterNativeAsync(channel.Uri, tags); if (res.RegistrationId != null) { var dlg = new MessageDialog("Success: " + res.RegistrationId); await dlg.ShowAsync(); } }
private async void InitNotificationsAsync() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("SmartEnglishNotifHub", "Endpoint=sb://notifhubns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=mK6q4lHdY7RSteCVBLKDxDa1IGNWIkxHrY2sd+MptXw="); var result = await hub.RegisterNativeAsync(channel.Uri); // Displays the registration ID so you know it was successful if (result.RegistrationId != null) { /* var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync();*/ } }
private async void InitNotificationsAsync() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("<hub name>", "<connection string with listen access>"); var result = await hub.RegisterNativeAsync(channel.Uri); // Displays the registration ID so you know it was successful if (result.RegistrationId != null) { var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }
private async void InitNotificationsAsync() { CHANNEL = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); HUB = new NotificationHub("HubName", "ListenConnectionString"); //var result = await hub.RegisterNativeAsync(channel.Uri); // Displays the registration ID so you know it was successful //if (result.RegistrationId != null) //{ // var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); // dialog.Commands.Add(new UICommand("OK")); // await dialog.ShowAsync(); //} }
private async void InitNotificationsAsync() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("notification", "Endpoint=sb://smartwardrobe.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=MlHoVfn1Ub/c2ThUha+Crn7hHSGmqofrW3cJ6IK89Ok="); var result = await hub.RegisterNativeAsync(channel.Uri); //// Displays the registration ID so you know it was successful //if (result.RegistrationId != null) //{ // var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); // dialog.Commands.Add(new UICommand("OK")); // await dialog.ShowAsync(); //} }
public async void RegisterNotificationHubs(string channel) { var connectionString = ConnectionString.CreateUsingSharedAccessKey( MobileServiceConfig.NotificationHubUri, MobileServiceConfig.NotificationHubKey, MobileServiceConfig.NotificationHubSecret); NotificationHub notificationHub = new NotificationHub( MobileServiceConfig.NotificationHubName, connectionString); await notificationHub.UnregisterAllAsync(channel); await notificationHub.RegisterTemplateAsync(channel, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>" + "SlapChat" + "</wp:Text1>" + "<wp:Text2>" + "$(msg)" + "</wp:Text2>" + "</wp:Toast> " + "</wp:Notification>", "toast"); }
public void RegisterForAzurePushNotification() { var channel = HttpNotificationChannel.Find("MyPushChannel"); if (channel == null) { channel = new HttpNotificationChannel("MyPushChannel"); channel.Open(); channel.BindToShellToast(); } channel.ChannelUriUpdated += async (o, args) => { var hub = new NotificationHub(PushNotificationCredentials.AzureNotificationHubName, PushNotificationCredentials.AzureListenConnectionString); await hub.RegisterNativeAsync(args.ChannelUri.ToString(), PushNotificationCredentials.Tags); }; }
private async void InitNotificationsAsync() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); //var hub = new NotificationHub("sks-notification", "Endpoint=sb://skshub.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=hqP02VpOdrJhbvVB3vi/avkG1nTZhkS4pYxgQQkviRk="); var hub = new NotificationHub("wistron-demo", "Endpoint=sb://wistron-demo.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=TCdvkg7GKaIATkBIGXeca9BnOfkhaDvEHUDiACCR4Sk="); var result = await hub.RegisterNativeAsync(channel.Uri);//, new string[] { "IT","IT Manager", "Regional IT Direcotor" }); // Displays the registration ID so you know it was successful if (result.RegistrationId != null) { var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }
private void RegisterPushChannel() { try { var channel = HttpNotificationChannel.Find(PUSH_CHANNEL_NAME); if (channel == null) { channel = new HttpNotificationChannel(PUSH_CHANNEL_NAME); channel.Open(); channel.BindToShellToast(); } channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) => { var hub = new NotificationHub(PUSH_HUB_NAME, PUSH_HUB_CONNECTION); try { var result = await hub.RegisterNativeAsync(args.ChannelUri.ToString()); Debug.WriteLine(result.NotificationHubPath); if (result.RegistrationId != null) { Debug.WriteLine("Registration successful; Id of device:" + result.RegistrationId); } else { Debug.WriteLine("Registration failed! No registrationId recieved"); } } catch (RegistrationAuthorizationException e) { Debug.WriteLine("Registration failed;"+ e.Message); App.ViewModel.PushStatus = "Registration failed!"; } }); } catch(Exception e){ MessageBox.Show("Registration of push channel failed!" + e.ToString()); } }
private async void registerButton_Click(object sender, RoutedEventArgs e) { // Get the current push notification channel var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("myhub", "Endpoint=sb://sabbour.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=GgJk6ED18JfKc4Ch3dmAtoXcmbZXxUdl4fzefq5XyLU="); // Get the selected cityname var cityName = citiesCombobox.SelectedValue as string; // Construct the template the app is expecting var temperatureProperty = celsiusSwitch.IsOn ? "tempC" : "tempF"; var temperatureString = celsiusSwitch.IsOn ? "Celsius" : "Fahrenheit"; var message = "Temperature in " + cityName + " is $(" + temperatureProperty + ") " + temperatureString; // Append the message into the toast template string toastTemplate = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + message + "</text></binding></visual></toast>"; // Register with the notification hub, and pass the cityname as a tag you are interested in as well as the template await hub.RegisterTemplateAsync(channel.Uri, toastTemplate, "TemperatureToastTemplate", new string[] { cityName }); }
private async void SetupNotifiations() { channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("nmct", "Endpoint=sb://nmct-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=Pe69t2KOt+lKmT1mH84Uexyr91582r27MFwa7kqoUfI="); var result = await hub.RegisterNativeAsync(channel.Uri); if (result != null) { channel.PushNotificationReceived += Channel_PushNotificationReceived; } else { var dialog = new MessageDialog("Registratie failed"); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }
private async Task SubscribeInternalAsync(string topic) { #if WINDOWS_PHONE_APP || WINDOWS_APP try { var channel = await PushNotificationChannelManager .CreatePushNotificationChannelForApplicationAsync(); channel.PushNotificationReceived += channel_PushNotificationReceived; var hub = new NotificationHub(_notificationHubPath, _connectionString); await hub.RegisterNativeAsync(channel.Uri, new string[] { topic }); } catch (Exception ex) { // Ignore. Continue without push notifications. } #else throw new NotImplementedException(); #endif }
/// <summary> /// http://www.windowsazure.com/en-us/documentation/articles/notification-hubs-windows-store-dotnet-get-started/ /// </summary> private async void InitNotificationsAsync() { try { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("ferrarimagazine", "Endpoint=sb://ferrarifans.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=Y2GhUIPcgEh/uIpv10H2ImF7/p+fkkWYskS8GoUdBV0="); await hub.RegisterNativeAsync(channel.Uri); //// Displays the registration ID so you know it was successful //if (result.RegistrationId != null) //{ // var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); // dialog.Commands.Add(new UICommand("OK")); // await dialog.ShowAsync(); //} } catch (Exception) { // skip.. } }
private async void Register() { PushNotificationChannel channel = null; try { channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); return; } List<string> tags = new List<string>(); tags.Add("tester"); NotificationHub hub = new NotificationHub(NOTIFICATION_HUB_NAME, CONNECTION_STRING); //await hub.RegisterNativeAsync(channel.Uri); await hub.RegisterNativeAsync(channel.Uri, tags); ShowPushChannel(); }
private async void InitNotificationsAsync() { Channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var hub = new NotificationHub("OfficeTicTacToeNotificationHub", "Endpoint=sb://tictactoenotifications.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=iojKHPCa3oXRAL7WBK8o+ulDGx8SV0QM6CwiGP8pgv0="); Registration result = null; try { result = await hub.RegisterNativeAsync(Channel.Uri); } catch (RegistrationException ex) { Debug.WriteLine(ex.Message); } // Displays the registration ID so you know it was successful if (result?.RegistrationId != null) { Debug.WriteLine("Channel Registered: " + result.RegistrationId); } }
public NotificationService(ISettingsService settings) { hub = new NotificationHub("podcastr", "Endpoint=sb://podcastr-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=ink/oq3X+ZMDTu29EWjRHp+U2AtmgNP4IQP+DiXQhOY="); username = settings.Username; }
public void RegisterForRemoteHubNotifications(string notificationHubName, string connectionString, string channelName, string[] tags) { var channel = HttpNotificationChannel.Find(channelName); if (channel == null) { channel = new HttpNotificationChannel(channelName); channel.Open(); channel.BindToShellToast(); } channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) => { Hub = new NotificationHub(notificationHubName, connectionString); Microsoft.WindowsAzure.Messaging.Registration registration = await Hub.RegisterNativeAsync(args.ChannelUri.ToString(), tags); if (this.NotificationRegistered!=null) this.NotificationRegistered(this, new AzureNotificationEventArgs("Success", registration.RegistrationId)); Console.WriteLine("RegisterForRemoteHubNotifications completed"); }); }
public NotificationManager(AppSettings appSettings) { this.notificationHub = new NotificationHub(notificationHubName, notificationHubConnectionString); this.appSettings = appSettings; }