public void OpenChannel(Action <string> channelCallback)
        {
            try
            {
                _channel = HttpNotificationChannel.Find(ChannelName);
            }
            catch { }

            if (_channel != null && _channel.ChannelUri != null)
            {
                channelCallback(_channel.ChannelUri.ToString());
            }
            else
            {
                try
                {
                    _channel = new HttpNotificationChannel(ChannelName);
                    _channel.ChannelUriUpdated += (o, e) => channelCallback(e.ChannelUri.ToString());
                    _channel.Open();
                    _channel.BindToShellToast();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
        }
Exemple #2
0
 public void Connect()
 {
     try
     {
         const string channelName = "ZabbkitNotifications";
         _httpChannel = HttpNotificationChannel.Find(channelName);
         if (null == _httpChannel)
         {
             _httpChannel = new HttpNotificationChannel(channelName);
             SubscribeToChannelEvents();
             _httpChannel.Open();
             SubscribeToNotifications();
         }
         else
         {
             SubscribeToChannelEvents();
             SubscribeToManagementServiceAsync();
         }
     }
     catch (Exception ex)
     {
         //_errorHandler.WriteReport(string.Format("Channel error: {0}",ex.Message));
         OnError();
     }
 }
Exemple #3
0
        public async Task AcquirePushChannelAsync(string stationId)
        {
            if (null != _pushChannel) return;

            try
            {
                _pushChannel = HttpNotificationChannel.Find(PushChannelName);

                if (_pushChannel == null)
                {
                    _pushChannel = new HttpNotificationChannel(PushChannelName);
                    _pushChannel.Open();
                    _pushChannel.BindToShellTile();
                }

                // ChannelUri can be null, don't forget to check (SIM-less dev phones)
                if (null != _pushChannel.ChannelUri)
                {
                    IMobileServiceTable<StationPush> channelTable =
                        CreateMobileServiceReference().GetTable<StationPush>();

                    var channel = new StationPush() {Uri = _pushChannel.ChannelUri.ToString(), StationId = stationId};

                    await channelTable.InsertAsync(channel);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemple #4
0
        /// <summary>
        /// Finds or creates the notification channel and binds the shell tile
        /// and toast notifications as well as events.
        /// </summary>
        private void BindChannel()
        {
            channel = HttpNotificationChannel.Find(channelName);

            if (channel == null || channel.ChannelUri == null)
            {
                if (channel != null)
                {
                    DisposeChannel();
                }

                channel = new HttpNotificationChannel(channelName);
                channel.ChannelUriUpdated += channel_ChannelUriUpdated;
                channel.Open();
            }
            else
            {
                ChannelUri = channel.ChannelUri.AbsoluteUri;
                System.Diagnostics.Debug.WriteLine(channel.ChannelUri.AbsoluteUri);
            }

            SubscribeToChannelEvents();

            if (!channel.IsShellTileBound)
            {
                channel.BindToShellTile();
            }
            if (!channel.IsShellToastBound)
            {
                channel.BindToShellToast();
            }
        }
Exemple #5
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();
            }
        }
        protected async override Task <string> ChannelUri()
        {
            HttpNotificationChannel channel;
            string channelName = "ToastChannel";

            channel = HttpNotificationChannel.Find(channelName);

            if (channel == null)
            {
                channel = new HttpNotificationChannel(channelName);
            }

            var tcs = new TaskCompletionSource <string>();

            channel.ChannelUriUpdated += (s, e) =>
            {
                tcs.TrySetResult(e.ChannelUri.ToString());
            };
            channel.ErrorOccurred += (s, e) =>
            {
                tcs.TrySetException(new Exception(e.Message));
            };

            channel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

            channel.Open();
            channel.BindToShellToast();
            return(await tcs.Task);
        }
Exemple #7
0
 private void DoConnect()
 {
     try
     {
         //首先查看现有的频道
         httpChannel = HttpNotificationChannel.Find(channelName);
         //如果频道存在
         if (httpChannel != null)
         {
             //注册Microsoft推送通知事件
             SubscribeToChannelEvents();
             //检测Microsoft通知服务注册状态
             SubscribeToService();
             //订阅Toast和Title通知
             SubscribeToNotifications();
         }
         else
         {
             //试图创建一个新的频道
             //创建频道
             httpChannel = new HttpNotificationChannel(channelName, "PuzzleService");
             //推送通知频道创建成功
             SubscribeToChannelEvents();
             //注册Microsoft推送通知事件
             httpChannel.Open();
         }
     }
     catch (Exception ex)
     {
         //创建或恢复频道时发生异常
     }
 }
Exemple #8
0
        private static void ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e, Action <Exception> callback)
        {
            Channel = HttpNotificationChannel.Find(Channel_Name);
            if (Channel != null)
            {
                //if (!channel.IsShellTileBound)
                //{
                //    // you can register the phone application to recieve tile images from remote servers [this is optional]
                //    var uris = new Collection<Uri>(Allowed_Domains);
                //    channel.BindToShellTile(uris);
                //    //channel.BindToShellTile();
                //}

                if (!Channel.IsShellToastBound)
                {
                    Channel.BindToShellToast();
                }

                RegisterForNotifications(callback);
                //RegisterWithNotificationService(callback);
            }
            else
            {
                if (callback != null)
                {
                    callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Channel URI update failed"));
                }
            }
        }
        private void CreateChannel()
        {
            // Try to find the push channel.
            _pushChannel = HttpNotificationChannel.Find(_channelName);

            // If the channel was not found, then create a new connection to the push service.
            if (_pushChannel == null)
            {
                _pushChannel = new HttpNotificationChannel(_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();
            }
            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);

                // 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());
                //MessageBox.Show(String.Format("Channel Uri is {0}", _pushChannel.ChannelUri.ToString()));
            }
        }
Exemple #10
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            HttpNotificationChannel pushChannel;
            string nomeCanal = "toastSampleChannel";

            pushChannel = HttpNotificationChannel.Find(nomeCanal);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(nomeCanal);
                pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(AtualizarUriCanal);
                pushChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                pushChannel.Open();
                pushChannel.BindToShellToast();
            }
            else
            {
                pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(AtualizarUriCanal);
                pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
                //  MessageBox.Show(String.Format("Canal Uri é {0}", pushChannel.ChannelUri.ToString()));
                // textBoxUri.Text = pushChannel.ChannelUri.ToString();
            }

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
Exemple #11
0
        /// <summary>
        /// Unregisters device from specified groups, if <seealso cref="NetmeraDeviceDetail"/> groups are set; otherwise unregisters from broadcast group
        /// </summary>
        /// <param name="channelName">Channel name to be unregistered</param>
        /// <param name="deviceDetail"><seealso cref="NetmeraDeviceDetail"/> object keeping device details</param>
        /// <param name="callback">>Method to be called just after unregister</param>
        public static void unregister(String channelName, NetmeraDeviceDetail deviceDetail, Action <Exception> callback)
        {
            Channel_Name = channelName;
            if (deviceDetail != null)
            {
                Groups          = deviceDetail.getDeviceGroups();
                Device_Location = deviceDetail.getDeviceLocation();
            }

            Channel = HttpNotificationChannel.Find(Channel_Name);
            if (Channel != null)
            {
                UnregisterFromNotificationService(ex =>
                {
                    if (callback != null)
                    {
                        callback(ex);
                    }
                    //if (ex != null)
                    //    callback(ex);
                    //else
                    //    Channel.Close();
                });
            }
            else
            {
                if (callback != null)
                {
                    callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Unregister failed since such a channel not found!"));
                }
            }
        }
Exemple #12
0
        public void Connect(Action <HttpNotificationChannel> callback)
        {
            callback = callback ?? (r => { });

            if (this.IsConnected)
            {
                callback(this.NotificationChannel);
            }
            else
            {
                try
                {
                    // First, try to pick up an existing channel.
                    this.NotificationChannel = HttpNotificationChannel.Find(this.config.ChannelName);

                    if (this.NotificationChannel == null)
                    {
                        this.CreateChannel(callback);
                    }
                    else
                    {
                        this.PrepareChannel(callback);
                    }

                    this.UpdateNotificationBindings();
                    this.IsConnected = true;
                }
                catch (Exception ex)
                {
                    this.OnError(ex);
                }
            }
        }
        /// <summary>
        /// Creates push channel and regestrite it at pushwoosh server
        /// <param name="serviceName">
        /// The name that the web service uses to associate itself with the Push Notification Service.
        /// </param>
        /// </summary>
        public void SubscribeToPushService(string serviceName)
        {
            //First, try to pick up existing channel
            _notificationChannel = HttpNotificationChannel.Find(Constants.ChannelName);

            if (_notificationChannel != null)
            {
                Debug.WriteLine("Channel Exists - no need to create a new one");
                SubscribeToChannelEvents();

                Debug.WriteLine("Register the URI with 3rd party web service. URI is:" + _notificationChannel.ChannelUri);
                SubscribeToService(AppID);

                Debug.WriteLine("Subscribe to the channel to Tile and Toast notifications");
                SubscribeToNotifications();
            }
            else
            {
                Debug.WriteLine("Trying to create a new channel...");
                _notificationChannel = string.IsNullOrEmpty(serviceName)
                                           ? new HttpNotificationChannel(Constants.ChannelName)
                                           : new HttpNotificationChannel(Constants.ChannelName, serviceName);

                Debug.WriteLine("New Push Notification channel created successfully");

                SubscribeToChannelEvents();

                Debug.WriteLine("Trying to open the channel");
                _notificationChannel.Open();
            }
            if (_notificationChannel.ChannelUri != null)
            {
                PushToken = _notificationChannel.ChannelUri.ToString();
            }
        }
Exemple #14
0
        public async Task <Registration> SubscribeToCategories()
        {
            registrationTask = new TaskCompletionSource <Registration>();

            var channel = HttpNotificationChannel.Find("MyPushChannel");

            if (channel == null)
            {
                channel = new HttpNotificationChannel("MyPushChannel");
                channel.Open();
                channel.BindToShellToast();
                channel.ChannelUriUpdated += channel_ChannelUriUpdated;

                // This is optional, used to receive notifications while the app is running.
                channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;
            }

            // If channel.ChannelUri is not null, we will complete the registrationTask here.
            // If it is null, the registrationTask will be completed in the ChannelUriUpdated event handler.
            if (channel.ChannelUri != null)
            {
                await RegisterTemplate(channel.ChannelUri);
            }

            return(await registrationTask.Task);
        }
 /// <summary>
 /// Initialize the notification channel used to receive data from the game server.
 /// </summary>
 /// <param name="channelName">The name the application uses to identify the notification channel
 /// instance used to communicate with the game server.</param>
 /// <param name="serviceName">The name that the game's server uses to associate itself with the Push
 /// Notification Service.</param>
 private void InitializePushNotification(string channelName, string serviceName)
 {
     try
     {
         // Look for an already existing channel
         channel = HttpNotificationChannel.Find(channelName);
         if (channel == null)
         {
             // Create a new channel and open it
             channel = new HttpNotificationChannel(channelName, serviceName);
             channel.ChannelUriUpdated        += channel_ChannelUriUpdated;
             channel.HttpNotificationReceived += channel_HttpNotificationReceived;
             channel.Open();
         }
         else
         {
             // Register the client using the existing channel
             channel.ChannelUriUpdated        += channel_ChannelUriUpdated;
             channel.HttpNotificationReceived += channel_HttpNotificationReceived;
             RegisterForPushNotifications();
         }
     }
     catch (Exception e)
     {
         if (ServiceError != null)
         {
             ServiceError(this, new ExceptionEventArgs()
             {
                 Error = e
             });
         }
     }
 }
Exemple #16
0
        private void DoConnect()
        {
            try
            {
                //First, try to pick up existing channel
                httpChannel = HttpNotificationChannel.Find(Constant.CHANNELNAME);

                if (httpChannel == null)
                {
                    httpChannel = new HttpNotificationChannel(Constant.CHANNELNAME);
                    SubscribeToChannelEvents();
                    httpChannel.Open();
                    (App.Current as App).MPNSUrl = httpChannel.ChannelUri.ToString();
                }
                else
                {
                    (App.Current as App).MPNSUrl = httpChannel.ChannelUri.ToString();
                    SubscribeToChannelEvents();

                    SubscribeToService();
                    SubscribeToNotifications();
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void SwitchOn()
        {
            _channel = HttpNotificationChannel.Find(CHANNEL_NAME);
            if (_channel == null)
            {
                _channel = new HttpNotificationChannel(CHANNEL_NAME);
                _channel.Open();

                if (App.Current.IsToastOn)
                {
                    TurnOnToasts();
                }
            }
            else
            {
                string channelUri = _channel.ChannelUri.ToString();

                _Register(channelUri);
            }

            _channel.ShellToastNotificationReceived += _ChannelToastNotificationReceived;
            _channel.HttpNotificationReceived       += _ChannelNotificationReceived;
            _channel.ChannelUriUpdated += _ChannelUriUpdated;
            _channel.ErrorOccurred     += _ChannelErrorOccurred;
        }
        private void SetupChannel()
        {
            string channelName = "Demo notification channel";

            notificationChannel = HttpNotificationChannel.Find(channelName);
            if (notificationChannel != null)
            {
                notificationChannel.ChannelUriUpdated              += notificationChannel_ChannelUriUpdated;
                notificationChannel.ErrorOccurred                  += notificationChannel_ErrorOccurred;
                notificationChannel.HttpNotificationReceived       += notificationChannel_HttpNotificationReceived;
                notificationChannel.ShellToastNotificationReceived += notificationChannel_ShellToastNotificationReceived;
                notificationChannel.ConnectionStatusChanged        += notificationChannel_ConnectionStatusChanged;
                Debug.WriteLine(notificationChannel.ChannelUri.ToString());
            }
            else
            {
                notificationChannel = new HttpNotificationChannel(channelName);

                notificationChannel.ChannelUriUpdated              += notificationChannel_ChannelUriUpdated;
                notificationChannel.ErrorOccurred                  += notificationChannel_ErrorOccurred;
                notificationChannel.HttpNotificationReceived       += notificationChannel_HttpNotificationReceived;
                notificationChannel.ShellToastNotificationReceived += notificationChannel_ShellToastNotificationReceived;
                notificationChannel.ConnectionStatusChanged        += notificationChannel_ConnectionStatusChanged;

                notificationChannel.Open();
                BindToShell();
            }
        }
        /// <summary>
        /// Creates the or update notifications asynchronous.
        /// </summary>
        public void CreateOrUpdateNotificationsAsync()
        {
            var channel = HttpNotificationChannel.Find("MyPushChannel");

            if (channel == null)
            {
                channel = new HttpNotificationChannel("MyPushChannel");
                channel.Open();
                channel.BindToShellToast();

                channel.ErrorOccurred                  += Channel_ErrorOccurred;
                channel.HttpNotificationReceived       += Channel_HttpNotificationReceived;
                channel.ShellToastNotificationReceived += Channel_ShellToastNotificationReceived;
                channel.ChannelUriUpdated              += Channel_ChannelUriUpdated;
            }
            else
            {
                channel.ErrorOccurred                  += Channel_ErrorOccurred;
                channel.HttpNotificationReceived       += Channel_HttpNotificationReceived;
                channel.ShellToastNotificationReceived += Channel_ShellToastNotificationReceived;
                channel.ChannelUriUpdated              += Channel_ChannelUriUpdated;

                Debug.WriteLine(channel.ChannelUri.ToString());
            }
        }
Exemple #20
0
        void SetupChannel()
        {
            bool newChannel = false;

            channel = HttpNotificationChannel.Find(CHANNEL_NAME);
            if (channel == null)
            {
                channel    = new HttpNotificationChannel(CHANNEL_NAME);
                newChannel = true;
            }

            channel.ConnectionStatusChanged        += channel_ConnectionStatusChanged;
            channel.ChannelUriUpdated              += channel_ChannelUriUpdated;
            channel.ErrorOccurred                  += channel_ErrorOccurred;
            channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;

            if (newChannel)
            {
                channel.Open();
                channel.BindToShellTile();
                channel.BindToShellToast();
            }

            channelStatus.Text = channel.ConnectionStatus.ToString();

            if (channel.ChannelUri != null)
            {
                channelUri.Text = channel.ChannelUri.ToString();
            }
        }
Exemple #21
0
        private void InitPushChannel()
        {
            // Try to find the push channel.
            HttpNotificationChannel httpChannel = HttpNotificationChannel.Find(App.pushChannelName);

            // If the channel was not found, then create a new connection to the push service.
            if (httpChannel == null)
            {
                // We need to create a new channel.
                httpChannel = new HttpNotificationChannel(App.pushChannelName);
                httpChannel.Open();
            }
            else
            {
                // This is an existing channel.
                this.PushChannelUri = httpChannel.ChannelUri;

                Debug.WriteLine("[App] Existing Push channel URI is {0}", this.PushChannelUri);

                //  Let listeners know that we have a push channel URI
                if (this.PushChannelUriChanged != null)
                {
                    this.PushChannelUriChanged(this, this.PushChannelUri);
                }

                // TODO: Let your cloud server know that the push channel to this device is this.PushChannelUri.
            }

            // Register for all the events.
            httpChannel.ChannelUriUpdated        += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            httpChannel.ErrorOccurred            += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
            httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
        }
Exemple #22
0
        private void LoadOrCreateChannelAsync(Action callback = null)
        {
            Execute.BeginOnThreadPool(async() =>
            {
                try
                {
                    var pushChannel = HttpNotificationChannel.Find(Constants.ToastNotificationChannelName);

                    if (pushChannel != null)
                    {
                        pushChannel.UnbindToShellTile();
                        pushChannel.UnbindToShellToast();
                    }
                }
                catch (Exception ex)
                {
                    Telegram.Logs.Log.Write("WNSPushService start creating channel ex " + ex);

                    Execute.ShowDebugMessage("WNSPushService.LoadOrCreateChannelAsync ex " + ex);
                }

                Telegram.Logs.Log.Write("WNSPushService start creating channel");
                _pushChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
                _pushChannel.PushNotificationReceived += OnPushNotificationReceived;
                Telegram.Logs.Log.Write("WNSPushService stop creating channel");

                callback.SafeInvoke();
            });
        }
Exemple #23
0
        public static void EnableNotifications(string username)
        {
            _username = username;
            if (_channel != null)
            {
                return;
            }

            _channel = HttpNotificationChannel.Find(CHANNEL);

            if (_channel == null)
            {
                _channel = new HttpNotificationChannel(CHANNEL);
                WireChannel(_channel);
                _channel.Open();
            }
            else
            {
                WireChannel(_channel);
            }

            if (!_channel.IsShellToastBound)
            {
                _channel.BindToShellToast();
            }

            if (_channel.ChannelUri != null)
            {
                var ns = new NotificationServiceClient();
                ns.RegisterEndpointAsync(username, _channel.ChannelUri.ToString());
            }
        }
Exemple #24
0
        private void InitPushChannel()
        {
            // Try to find the push channel.
            HttpNotificationChannel httpChannel = HttpNotificationChannel.Find(pushChannelName);

            // If the channel was not found, then create a new connection to the push service.
            if (httpChannel == null)
            {
                // We need to create a new channel.
                httpChannel = new HttpNotificationChannel(App.pushChannelName);
                httpChannel.Open();

                // Bind this new channel for toast events.
                httpChannel.BindToShellToast();
                PushChannelUri = httpChannel.ChannelUri;
            }
            else
            {
                // This is an existing channel.
                PushChannelUri = httpChannel.ChannelUri;

                Logger.Dbg("[Linphone] Existing Push channel URI is {0}", PushChannelUri);

                //  Let listeners know that we have a push channel URI
                if (PushChannelUriChanged != null)
                {
                    PushChannelUriChanged(this, PushChannelUri);
                }
            }

            httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            httpChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
        }
        /// <summary>
        /// <see cref="MyCompany.Expenses.Client.WP.Services.Notification.INotificationService"/>
        /// </summary>
        public void Subscribe()
        {
            // Try to find the push channel.
            notificationChannel = HttpNotificationChannel.Find(channelName);

            // If the channel was not found, then create a new connection to the push service.
            if (notificationChannel == null)
            {
                notificationChannel = new HttpNotificationChannel(channelName);
            }
            else
            {
                // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
                ChannelUriUpdated();
            }

            // The channel was already open, so just register for all the events.
            notificationChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(NotificationChannel_ChannelUriUpdated);
            notificationChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(NotificationChannel_ErrorOccurred);

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

            if (notificationChannel.ConnectionStatus != ChannelConnectionStatus.Connected || notificationChannel.ChannelUri == null)
            {
                notificationChannel.Open();
            }

            if (!notificationChannel.IsShellToastBound)
            {
                notificationChannel.BindToShellToast();
            }
        }
Exemple #26
0
        // Constructor
        public MainPage()
        {
            // the push channel that is created or used
            // rawdata is the name of the push channel
            var pushNotification = HttpNotificationChannel.Find("rawdata");

            InitializeComponent();

            // channel not found, so create one
            if (pushNotification == null)
            {
                pushNotification = new HttpNotificationChannel("rawdata");

                // register the events

                pushNotification.ChannelUriUpdated        += new EventHandler <NotificationChannelUriEventArgs>(ChannelUriUpdated);
                pushNotification.ErrorOccurred            += new EventHandler <NotificationChannelErrorEventArgs>(ErrorOccurred);
                pushNotification.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(NewNotification);
                pushNotification.Open();
            }
            else
            {
                // channel exists, so just register the events

                pushNotification.ChannelUriUpdated        += new EventHandler <NotificationChannelUriEventArgs>(ChannelUriUpdated);
                pushNotification.ErrorOccurred            += new EventHandler <NotificationChannelErrorEventArgs>(ErrorOccurred);
                pushNotification.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(NewNotification);
            }

            // get the location data
            GetLocation();

            Forms.Init();
            LoadApplication(new GPSPush.App());
        }
Exemple #27
0
        /// <summary>
        /// authorized:
        ///  ID_CAP_PUSH_NOTIFICATION
        ///  ID_CAP_IDENTITY_DEVICE
        /// </summary>
        public void rebind()
        {
            HttpNotificationChannel channel = HttpNotificationChannel.Find(BmobWindowsPhone.PushChannel);

            //如果用户通过更改应用程序中的设置关闭了通知,如应用程序策略的第 2.9 节中所述,则您应该确保使用 Close()()()() 方法来关闭推送通道。

            if (channel == null)
            {
                // 感谢赵越大哥无私的贡献!
                channel = new HttpNotificationChannel(BmobWindowsPhone.PushChannel, "urn:wp-ac-hash-2:bchdqmkdpwamzk1umxagzovixy2mwp8-b9vfeea9l2c");
                registerPushChannelEvent(channel);

                channel.Open();

                /// 如果您想接收 Toast 通知,则应该调用 BindToShellToast()方法将通道绑定到 Toast 通知。
                channel.BindToShellToast();
                // 如果您想接收磁贴通知,则将通道绑定到磁贴通知,方法是:调用 BindToShellTile()方法以访问设备上的本地资源或调用
                // BindToShellTile(Collection<(Of <<'(Uri>)>>)) 方法以访问远程资源。若要访问远程资源,您必须提供从中访问远程图像的所允许域的集合。集合中的每个 URI 都限制为 256 个字符。
                channel.BindToShellTile();
            }
            else
            {
                registerPushChannelEvent(channel);
                NotificationUri = channel.ChannelUri.ToString();
                BmobDebug.Log("NotificationUri: " + NotificationUri);

                fetchAndUpdateNotifactionUri();
            }
        }
Exemple #28
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);
            }
        }
Exemple #29
0
        void getSubscription()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("DeviceId"))
            {
                deviceID = (Guid)IsolatedStorageSettings.ApplicationSettings["DeviceId"];
            }
            else
            {
                deviceID = Guid.NewGuid();
                IsolatedStorageSettings.ApplicationSettings["DeviceId"] = deviceID;
            }
            pushChannel = HttpNotificationChannel.Find("myChannel");

            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel("myChannel");
                attachHandlerFunctions();
                pushChannel.Open();
            }
            else
            {
                attachHandlerFunctions();

                pushClient.SubscribeMyPhoneAsync(deviceID, pushChannel.ChannelUri.ToString());
            }
        }
Exemple #30
0
        void RegisterPush()
        {
            // Try to find the push channel.
            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(ToastChannelName);

            // If the channel was not found, then create a new connection to the push service.
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(ToastChannelName);

                // 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 Tile events.
                pushChannel.BindToShellToast();
            }
            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);
            }

            // Send Channel Uri to OpenXLive Hosting Server
            RegisterNotificationUri(pushChannel.ChannelUri);
        }