Exemplo n.º 1
0
        public void StartNotificationListener()
        {
            this.contentCard.Children.Clear();
            notificationList = new NotificationList(SentNotifications);

            if (VRController._IsRunning)
            {
                VRDummyOverlay = new WPFOverlay("PushVR", "", notificationList, Dispatcher);
                VRController.RegisterNewItem(VRDummyOverlay);
            }

            this.contentCard.Children.Add(notificationList);

            PushClient = new PushbulletNetworkManager(Properties.Settings.Default["PushToken"].ToString());
            PushClient.OnMessageReceived += PushClient_OnMessageReceived;
            //Tries to connect to Pushbullet Realtime-Events WebSocket
            PushClient.StartListeningForRealtimeEvents(new Action(() =>
            {
                //On Success
                Dispatcher.Invoke(new Action(() =>
                {
                    txtStatus.Foreground = Brushes.Green;
                    txtStatus.Text       = "Status: Listening...";
                }));
            }), new Action <object>((object ex) =>
            {
                //On Fail
                Dispatcher.Invoke(new Action(() =>
                {
                    if (ex is HttpWebResponse)
                    {
                        if (((HttpWebResponse)ex).StatusCode == HttpStatusCode.Unauthorized)
                        {
                            Properties.Settings.Default["PushToken"] = null;
                            Properties.Settings.Default.Save();
                            MessageBox.Show("Failed to login to Pushbullet, please log-in again!");
                            TryLogin();
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }));
            }));
        }