internal void ApplyTo( HttpNotificationChannel httpNotificationChannel )
    {
      if( IsBindedToShellTile != null )
        if( IsBindedToShellTile.Value )
        {
          if( !httpNotificationChannel.IsShellTileBound )
            httpNotificationChannel.BindToShellTile();
        }
        else
        {
          if( httpNotificationChannel.IsShellTileBound )
            httpNotificationChannel.UnbindToShellTile();
        }

      if( IsBindedToShellToast != null )
        if( IsBindedToShellToast.Value )
        {
          if( !httpNotificationChannel.IsShellToastBound )
            httpNotificationChannel.BindToShellToast();
        }
        else
        {
          if( httpNotificationChannel.IsShellToastBound )
            httpNotificationChannel.UnbindToShellToast();
        }

      if( OnHttpNotificationReceived != null )
        httpNotificationChannel.HttpNotificationReceived += OnHttpNotificationReceived;

      if( OnShellToastNotificationReceived != null )
        httpNotificationChannel.ShellToastNotificationReceived += OnShellToastNotificationReceived;
    }
Esempio n. 2
0
        public void unregister(string options)
        {
            Options unregisterOptions;

            if (!TryDeserializeOptions(options, out unregisterOptions))
            {
                SendError(JSONError);
                return;
            }

            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(unregisterOptions.WP8.ChannelName);

            if (pushChannel != null)
            {
                pushChannel.UnbindToShellTile();
                pushChannel.UnbindToShellToast();
                pushChannel.Close();
                pushChannel.Dispose();

                SendEvent("Channel " + unregisterOptions.WP8.ChannelName + " is closed!");
            }
            else
            {
                SendError(MissingChannelError);
            }
        }
Esempio n. 3
0
        private void Connect(Action actionIfNotFound)
        {
            try
            {
                _channel = HttpNotificationChannel.Find(_channelName);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            if (_channel != null)
            {
                if (_channel.ChannelUri != null)
                {
                    SubscribeToChannelEvents();
                    RegisterChannel(_channel.ChannelUri);
                    SubscribeToNotifications();
                }
                else
                {
                    _channel.UnbindToShellTile();
                    _channel.UnbindToShellToast();
                    _channel.Close();
                    RetryChannelConnect();
                }
            }
            else
            {
                actionIfNotFound();
            }
        }
 /// <summary>
 /// Unsubscribe from pushes at pushwoosh server
 /// </summary>
 public void UnsubscribeFromPushes()
 {
     if (_registrationService == null)
     {
         return;
     }
     _notificationChannel.UnbindToShellTile();
     _notificationChannel.UnbindToShellToast();
     _registrationService.Unregister();
 }
 public void DisableToastNotification()
 {
     channel = HttpNotificationChannel.Find(Constants.Settings.WeeklyThaiRecipeChannelName);
     if (channel != null)
     {
         if (channel.IsShellToastBound)
         {
             channel.UnbindToShellToast();
         }
     }
 }
Esempio n. 6
0
        private void Push_Unchecked(object sender, RoutedEventArgs e)
        {
            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(ToastChannelName);

            appSettings["pushenabled"] = 0;
            appSettings.Save();
            if (pushChannel != null)
            {
                pushChannel.UnbindToShellToast();
                pushChannel.Close();
            }
        }
        /// <summary>
        /// Unsubscribe to Shell toast notifications
        /// </summary>
        /// <param name="channel">The active notification channel</param>
        private void UnSubscribeToToastNotifications(HttpNotificationChannel channel)
        {
            //
            // UnBind to Toast Notification
            //

            if (channel.IsShellToastBound == false)
            {
                Trace("Already unbound to to Toast notification");
                return;
            }

            Trace("Unbinding to Toast Notifications");
            channel.UnbindToShellToast();
        }
Esempio n. 8
0
        /// <summary>
        /// This subscribes this phone for push notification with MPNS and saves the push notification url in Yapper services
        /// </summary>
        public void Subscribe()
        {
            // Try to find the push channel.
            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(PushNotification.ChannelName);

            // If the channel was not found, then create a new connection to the push service.
            if (pushChannel == null || pushChannel.ChannelUri == null)
            {
                if (pushChannel != null)
                {
                    pushChannel.UnbindToShellToast();
                    pushChannel.Close();
                    pushChannel.Dispose();
                }

                pushChannel = new HttpNotificationChannel(PushNotification.ChannelName);

                // Register for all the events before attempting to open the channel.
                pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

                // Register for this notification only if you need to receive the notifications while your application is running.
                pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

                pushChannel.Open();

                // Bind this new channel for toast events.
                pushChannel.BindToShellToast();
                pushChannel.BindToShellTile();
            }
            else
            {
                // The channel was already open, so just register for all the events.
                pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

                // Register for this notification only if you need to receive the notifications while your application is running.
                pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

                if (UserSettingsModel.Instance.PushNotificationSubscriptionStatus == PushNotificationSubscriptionStatus.EnabledNotSubscribed)
                {
                    this.SubscribePushNotificationUrlInService();
                }

                // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
                //System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
            }
        }
Esempio n. 9
0
        internal void ApplyTo(HttpNotificationChannel httpNotificationChannel)
        {
            if (IsBindedToShellTile != null)
            {
                if (IsBindedToShellTile.Value)
                {
                    if (!httpNotificationChannel.IsShellTileBound)
                    {
                        httpNotificationChannel.BindToShellTile();
                    }
                }
                else
                {
                    if (httpNotificationChannel.IsShellTileBound)
                    {
                        httpNotificationChannel.UnbindToShellTile();
                    }
                }
            }

            if (IsBindedToShellToast != null)
            {
                if (IsBindedToShellToast.Value)
                {
                    if (!httpNotificationChannel.IsShellToastBound)
                    {
                        httpNotificationChannel.BindToShellToast();
                    }
                }
                else
                {
                    if (httpNotificationChannel.IsShellToastBound)
                    {
                        httpNotificationChannel.UnbindToShellToast();
                    }
                }
            }

            if (OnHttpNotificationReceived != null)
            {
                httpNotificationChannel.HttpNotificationReceived += OnHttpNotificationReceived;
            }

            if (OnShellToastNotificationReceived != null)
            {
                httpNotificationChannel.ShellToastNotificationReceived += OnShellToastNotificationReceived;
            }
        }
 private static void CloseChannel()
 {
     if (httpChannel == null)
     {
         return;
     }
     try
     {
         httpChannel.UnbindToShellTile();
         httpChannel.UnbindToShellToast();
         httpChannel.Close();
     }
     catch (Exception ex)
     {
         ShowMessage(ex.Message, "Error Closing Channel");
     }
 }
Esempio n. 11
0
        internal static void BindNotifications()
        {
            if (null != _channel)
            {
                RegisterDevice();

                if (_channel.IsShellTileBound && !DataContextManager.Settings.EnableTileNotifications)
                {
                    _channel.UnbindToShellTile();
                }
                else if (!_channel.IsShellTileBound && DataContextManager.Settings.EnableTileNotifications)
                {
                    var uris = new Collection <Uri>
                    {
                        new Uri("http://mobilesrc.com")
                    };

                    _channel.BindToShellTile(uris);
                }

                if (_channel.IsShellToastBound && !DataContextManager.Settings.EnableToastNotifications)
                {
                    _channel.UnbindToShellToast();
                }
                else if (!_channel.IsShellToastBound && DataContextManager.Settings.EnableToastNotifications)
                {
                    bool shouldSet = true;
                    if (!DataContextManager.Settings.HasNotifiedToast)
                    {
                        if (MessageBoxResult.OK != MessageBox.Show("Are you sure you want to enable toast notifications?", "Enable Toasts", MessageBoxButton.OKCancel))
                        {
                            DataContextManager.Settings.EnableToastNotifications = false;
                            shouldSet = false;
                        }
                        DataContextManager.Settings.HasNotifiedToast = true;
                        DataContextManager.Save();
                    }

                    if (shouldSet)
                    {
                        _channel.BindToShellToast();
                    }
                }
            }
        }
Esempio n. 12
0
        public void Stop()
        {
            FSLog.Debug();

            if (NotificationChannel != null)
            {
                NotificationChannel.UnbindToShellTile();
                NotificationChannel.UnbindToShellToast();
                NotificationChannel.Close();

                NotificationChannel.ChannelUriUpdated -= NotificationService_ChannelUriUpdated;
                NotificationChannel.ErrorOccurred     -= NotificationService_ErrorOccurred;
                NotificationChannel.ShellToastNotificationReceived -= NotificationService_ShellToastNotificationReceived;

                Dispose();
                NotificationChannel = null;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// This unsubscribes the phone from push notification and removes the url from the yapper service
        /// </summary>
        public void UnSubscribe()
        {
            // Try to find the push channel.
            using (HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(PushNotification.ChannelName))
            {
                // If the channel was not found, then create a new connection to the push service.
                if (pushChannel != null)
                {
                    // If the channel is not null, close the channel
                    pushChannel.UnbindToShellToast();
                    pushChannel.Close();
                }

                UserSettingsModel.Instance.PushNotificationSubscriptionStatus = PushNotificationSubscriptionStatus.Disabled;

                this.UnSubscribePushNotificationUrlInService();
            }
        }
Esempio n. 14
0
        public void CloseChannel()
        {
            HttpNotificationChannel channel = this.TryFindChannel();

            if (channel == null)
            {
                return;
            }
            try
            {
                channel.UnbindToShellToast();
                channel.UnbindToShellTile();
                channel.Close();
            }
            catch (Exception)
            {
                Logger.Instance.Error("Failed to close channel");
            }
        }
Esempio n. 15
0
        private void SetupChannel()
        {
            HttpNotificationChannel httpChannel = null;
            string channelName = "DemoChannel";

            try
            {
                //if channel exists, retrieve existing channel
                httpChannel = HttpNotificationChannel.Find(channelName);
                if (httpChannel != null)
                {
                    //If we can't get it, then close and reopen it.
                    if (httpChannel.ChannelUri == null)
                    {
                        httpChannel.UnbindToShellToast();
                        httpChannel.Close();
                        SetupChannel();
                        return;
                    }
                    else
                    {
                        ChannelUri  = httpChannel.ChannelUri;
                        txtURI.Text = "Channel retrieved: " + httpChannel.ChannelUri;
                        //wiring up the raw notifications event handler
                        httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);
                    }
                }
                else
                {
                    httpChannel = new HttpNotificationChannel(channelName);
                    httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
                    httpChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred);

                    //wiring up the raw notifications event handler
                    httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);

                    httpChannel.Open();
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void SetupChannel()
        {
            HttpNotificationChannel httpChannel = null;
            string channelName = "DemoChannel";

            try
            {
                //if channel exists, retrieve existing channel
                httpChannel = HttpNotificationChannel.Find(channelName);
                if (httpChannel != null)
                {
                    //If we can't get it, then close and reopen it.
                    if (httpChannel.ChannelUri == null)
                    {
                        httpChannel.UnbindToShellToast();
                        httpChannel.Close();
                        SetupChannel();
                        return;
                    }
                    else
                    {
                        ChannelUri = httpChannel.ChannelUri;
                    }
                    BindToShell(httpChannel);
                }
                else
                {
                    httpChannel = new HttpNotificationChannel(channelName);
                    httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
                    httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);
                    httpChannel.HttpNotificationReceived       += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);
                    httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ExceptionOccurred);

                    httpChannel.Open();
                    BindToShell(httpChannel);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("An exception setting up channel " + ex.ToString());
            }
        }
Esempio n. 17
0
        private void DeleteLocalStorage()
        {
            NetworkManager.turnOffNetworkManager = true;
            App.MqttManagerInstance.disconnectFromBroker(false);
            App.ClearAppSettings();
            App.WriteToIsoStorageSettings(App.IS_DB_CREATED, true);
            MiscDBUtil.clearDatabase();

            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName);

            if (pushChannel != null)
            {
                if (pushChannel.IsShellTileBound)
                {
                    pushChannel.UnbindToShellTile();
                }
                if (pushChannel.IsShellToastBound)
                {
                    pushChannel.UnbindToShellToast();
                }
                pushChannel.Close();
            }


            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                App.ViewModel.ClearViewModel();
                try
                {
                    progress.Hide(LayoutRoot);
                    progress = null;
                }
                catch
                {
                }
                try
                {
                    NavigationService.Navigate(new Uri("/View/WelcomePage.xaml", UriKind.Relative));
                }
                catch { }
            });
        }
Esempio n. 18
0
        public void onFailure(Exception value)
        {
            if ((value is ConnectionException) && ((ConnectionException)value).getCode().Equals(finalmqtt.Msg.ConnAckMessage.ConnectionStatus.BAD_USERNAME_OR_PASSWORD))
            {
                bool isPresent = false;
                if (App.appSettings.Contains(App.IS_DB_CREATED))
                {
                    isPresent = true;
                }
                App.ClearAppSettings();
                if (isPresent)
                {
                    App.WriteToIsoStorageSettings(App.IS_DB_CREATED, true);
                }
                NetworkManager.turnOffNetworkManager = true; // stop network manager
                App.MqttManagerInstance.disconnectFromBroker(false);
                MiscDBUtil.clearDatabase();

                HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName);
                if (pushChannel != null)
                {
                    if (pushChannel.IsShellTileBound)
                    {
                        pushChannel.UnbindToShellTile();
                    }
                    if (pushChannel.IsShellToastBound)
                    {
                        pushChannel.UnbindToShellToast();
                    }
                    pushChannel.Close();
                }
                App.HikePubSubInstance.publish(HikePubSub.BAD_USER_PASS, null);
            }
            else if (hikeMqttManager.connectionStatus != HikeMqttManager.MQTTConnectionStatus.NOTCONNECTED_WAITINGFORINTERNET)
            {
                scheduler.Schedule(hikeMqttManager.connect, TimeSpan.FromSeconds(5));
            }
            hikeMqttManager.setConnectionStatus(windows_client.Mqtt.HikeMqttManager.MQTTConnectionStatus.NOTCONNECTED_UNKNOWNREASON);
        }
        public void unregisterForPush(string options)
        {
            PushOptions unregisterOptions;

            if (!TryDeserializeOptions(options, out unregisterOptions))
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));

                return;
            }

            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(unregisterOptions.ChannelName);

            if (pushChannel != null)
            {
                ChannelListener channelListener;

                if (channelListeners.TryGetValue(unregisterOptions.ChannelName, out channelListener))
                {
                    channelListener.Unsubscribe(pushChannel);
                    channelListeners.Remove(unregisterOptions.ChannelName);
                }

                pushChannel.UnbindToShellTile();
                pushChannel.UnbindToShellToast();
                pushChannel.Close();

#if DEBUG
                Debug.WriteLine("Unregistered for push on channel " + pushChannel.ChannelName);
#endif

                DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
            }
            else
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, MissingChannelError));
            }
        }
Esempio n. 20
0
        public void Disconnect()
        {
            if (_channel != null)
            {
                if (_channel.IsShellToastBound)
                {
                    _channel.UnbindToShellToast();
                }

                if (_channel.IsShellTileBound)
                {
                    _channel.UnbindToShellTile();
                }

                try
                {
                    _channel.Close();
                }
                finally
                {
                    _channel.Dispose();
                }
            }
        }
        /// <summary>
        /// Unsubscribe to Shell toast notifications
        /// </summary>
        /// <param name="channel">The active notification channel</param>
        private void UnSubscribeToToastNotifications(HttpNotificationChannel channel)
        {
            //
            // UnBind to Toast Notification 
            //

            if (channel.IsShellToastBound == false)
            {
                Trace("Already unbound to to Toast notification");
                return;
            }

            Trace("Unbinding to Toast Notifications");
            channel.UnbindToShellToast();
        }