Esempio n. 1
1
        private async void InitNotificationsAsync()
        {
            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
            var rul = channel.Uri;



        //    Debugger.Break();
            var hub = new NotificationHub("uwptest", "Endpoint=sb://todolisthub2-ns.servicebus.chinacloudapi.cn/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=CtIr3BF/MRRzWO8SA12GZ3bfpERLyBnAUhcONm3W70E=");
            var tags = new string[2];
            tags[0] = "MSDN";
            tags[1] = "movies";
            var result = await hub.RegisterNativeAsync(channel.Uri, tags);

            if (result.RegistrationId != null)
            {
                Debug.WriteLine("Registration successful!");
            }

            channel.PushNotificationReceived += Channel_PushNotificationReceived;
        }
        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 async void RegisterForAzurePushNotification()
        {
            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            var hub = new NotificationHub(PushNotificationCredentials.AzureNotificationHubName,
                PushNotificationCredentials.AzureListenConnectionString);

            await hub.RegisterNativeAsync(channel.Uri, PushNotificationCredentials.Tags);
        }
Esempio n. 6
0
        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);
     }
 }
Esempio n. 8
0
        private async void btnRegisterForNotifications_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
            var hub = new NotificationHub(_nothubName, _endPoint);
            var res = await hub.RegisterNativeAsync(channel.Uri);

            if (res.RegistrationId != null)
            {
                var dlg = new MessageDialog("Success: " + res.RegistrationId);
                await dlg.ShowAsync();
            }
        }
Esempio n. 9
0
        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();
            }
        }
Esempio n. 10
0
        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();*/
            }
        }
Esempio n. 11
0
        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();
            }

        }
Esempio n. 12
0
        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 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);
            };
        }
Esempio n. 14
0
        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();
            }

        }
Esempio n. 15
0
        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 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
        }
        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();
        }
Esempio n. 18
0
		/// <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..				
			}
		}
Esempio n. 19
0
        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);
            }

            
        }
Esempio n. 20
0
 /// <summary>
 /// Obtains a push notification channel from the Windows Notification Service (WNS)
 /// Then registers it with the Service Bus Notification Hub
 /// </summary>
 /// <returns></returns>
 private async Task InitNotificationAsync()
 {
     hub = new NotificationHub("myhub", "Endpoint=sb://sabbour.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=GgJk6ED18JfKc4Ch3dmAtoXcmbZXxUdl4fzefq5XyLU=");
     var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
     await hub.RegisterNativeAsync(channel.Uri);
 }
        private async void RegisterChannel()
        {
            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
            var result = await hub.RegisterNativeAsync(channel.Uri);
        }
Esempio n. 22
0
      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");
          });
      }
Esempio n. 23
0
        private async Task InitNotificationsAsync()
        {
            App.Channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            var hub = new NotificationHub("notificationapp", "Endpoint=sb://KAIT-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=Qy+U8BBbQOpjUAX8v2FfhoNInn3CygnIfrjDh2F3xR4=");
            var result = await hub.RegisterNativeAsync(App.Channel.Uri,new string[] {"demo"});

            // Displays the registration ID so you know it was successful
            if (result.RegistrationId == null)
            {
                var dialog = new MessageDialog("Registration not successful: " + result.RegistrationId);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
            else
            {
                Debug.WriteLine("Successful Notification Registration");
            }

            App.Notifier = new Notifier();


        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            String geocoords = myLocation.Latitude + ", " + myLocation.Longitude;
            
            Bing.Maps.Search.GeocodeRequestOptions requestOptions = new Bing.Maps.Search.GeocodeRequestOptions(geocoords);
            
            Bing.Maps.Search.SearchManager searchManager = BingMap.SearchManager;
            Bing.Maps.Search.LocationDataResponse response = await searchManager.GeocodeAsync(requestOptions);
          
            string city = response.LocationData[0].Address.Locality;
            MessageDialog dialog = new MessageDialog("City is " + city);
            
            await dialog.ShowAsync();

            var hub = new NotificationHub("HubName", "ListenConnectionString");
            
            var result = await hub.RegisterNativeAsync(App.ChannelUri, new[] { city });

            // Displays the registration ID so you know it was successful
            if (result.RegistrationId != null)
            {
                dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
        }
Esempio n. 25
0
        private async void InitNotificationsAsync()
        {
            PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
            NotificationHub hub = new NotificationHub(
                "chinesenotificationhub",
                "Endpoint=sb://chinesenotificationhub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=On/QfPHG2GnuNrMfq2QvyBSxmvbNDMF/54NTNft1ts0=");
            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 SetupNotificationsHub()
        {
            try
            {
                channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
                var hub = new NotificationHub("notific", "Endpoint=sb://gardenrnotif.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=8bPfKiz9h4jY/e0JtAUqN/tCybd+dOtj3X/tA6zndxM=");
                channel.PushNotificationReceived += Channel_PushNotificationReceived;
                var result = await hub.RegisterNativeAsync(channel.Uri);
                if (result.RegistrationId != null)
                {
                    // var dialog = new MessageDialog("Registratie ok");
                    //  dialog.Commands.Add(new UICommand("Ok"));
                    //   await dialog.ShowAsync();
                    //  await sendPush("wns", App.FacebookId, "troll");
                    LoginAndRegisterClick();
                }
                else
                {
                    //  var dialog = new MessageDialog("Failed");
                    // dialog.Commands.Add(new UICommand("Ok"));
                    //await dialog.ShowAsync();
                }
            }
            catch (Exception e) {

                Exception j = e;
            }
        }
Esempio n. 27
0
        private async void InitNotificationsAsync()
        {
          var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

          var hub = new NotificationHub("MyFirstNotifyHub", hubListen);
          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("It was a notification popup!");
            dialog.Commands.Add(new UICommand("OK"));
            await dialog.ShowAsync();
          }

        }
Esempio n. 28
0
 /// <summary>
 /// Initializes the pushnotification.  This is the first line of authored code
 /// executed, and as such is the logical equivalent of main() or WinMain().
 /// </summary>
 private async void InitNotificationsAsync()
 {
     var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
     var hub = new NotificationHub(Core.Constants.NotificationHubPath, Core.Constants.ConnectionString); var result = await hub.RegisterNativeAsync(channel.Uri);
 }
        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();
            }
        }
Esempio n. 30
0
        private async void InitNotificationsAsync()
        {
            var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();


            var hub = new NotificationHub("mva-pushnotificationdemo", "Endpoint=sb://mva-pushnotificationdemo-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=BMOWfUiiOTFxT3hareNVXDV/uNDpQdg0g190af7jF0M=");
            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();
            }


        }