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); } }
// ===========================这个是推送发的信息 //====================下面是推送 Uri private void getUri() { httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
/// <summary> /// Performs necessary cleanup. /// </summary> public void Dispose() { if (channel != null) { // Dispose the push notification channel channel.Dispose(); } }
public void release() { HttpNotificationChannel channel = HttpNotificationChannel.Find(BmobWindowsPhone.PushChannel); if (channel != null) { channel.Close(); channel.Dispose(); } }
/// <summary> /// Dispose the class' resources /// </summary> /// <param name="disposing">Indicates it's called by the Dispose method or by the finalizer</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (notificationChannel != null) { notificationChannel.Dispose(); notificationChannel = null; } } }
private void DisableNotifications() { if (channel == null) { return; } channel.Close(); channel.Dispose(); channel = null; }
public void Dispose() { if (_notificationChannel == null) { return; } _notificationChannel.HttpNotificationReceived -= RawNotificationReceived; _notificationChannel.ShellToastNotificationReceived -= ToastNotificationReceived; _notificationChannel.ErrorOccurred -= ErrorOccurred; _notificationChannel.ChannelUriUpdated -= ChannelUriUpdated; _notificationChannel.Dispose(); }
/// <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()); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { httpChannel = HttpNotificationChannel.Find(channelName); //如果存在就删除 if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); httpChannel.ChannelUriUpdated += httpChannel_ChannelUriUpdated; httpChannel.ShellToastNotificationReceived += httpChannel_ShellToastNotificationReceived; httpChannel.HttpNotificationReceived += httpChannel_HttpNotificationReceived; httpChannel.ErrorOccurred += httpChannel_ErrorOccurred; httpChannel.Open(); httpChannel.BindToShellToast(); httpChannel.BindToShellTile(); }
//============================= 推送通知相关变量 public totalArrangement() { InitializeComponent(); if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("No network connection available!"); return; } showCurrentlist(); sendPosition(); //新添加的接收 推送信息的 httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
private void button1_Click(object sender, RoutedEventArgs e) { HttpNotificationChannel httpChannel = null; string channelName = "NotificationTest"; httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName); httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived); httpChannel.Open(); httpChannel.BindToShellToast(); httpChannel.BindToShellTile(); }
//============================= 推送通知相关变量 public totalArrangement() { InitializeComponent(); if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("No network connection available!"); return; } showCurrentlist(); sendPosition(); //新添加的接收 推送信息的 httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
public void disablePushNotifications() { try { // Try to find the push channel. pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel != null) { pushChannel.Close(); pushChannel.Dispose(); pushChannel = null; } } catch (InvalidOperationException ioException) { Utils.Tools.LogException("Cannot close the channel", ioException); } catch (ArgumentException argEcxeption) { Utils.Tools.LogException("Cannot close the channel", argEcxeption); } this.UnregisterDevice(); }
public void Disconnect() { if (_channel != null) { if (_channel.IsShellToastBound) { _channel.UnbindToShellToast(); } if (_channel.IsShellTileBound) { _channel.UnbindToShellTile(); } try { _channel.Close(); } finally { _channel.Dispose(); } } }
/// <summary> /// Closes the channel and disposes it. /// </summary> private void DisposeChannel() { channel.Close(); channel.Dispose(); channel = null; }
/// <summary> /// Event handler for when a push notification error occurs. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) { Utils.Tools.LogException((String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)), null); if (processingError) return; processingError = true; switch (e.ErrorType) { case ChannelErrorType.ChannelOpenFailed: case ChannelErrorType.PayloadFormatError: //ChannelErrorType.ChannelOpenFailed //This error is returned when the Push Client and the Push Notification Service are unable to establish a connection //ChannelErrorType.PayloadFormatError: //This error is returned when the XML payload format or the HTTP header of the push notification is syntactically invalid. pushChannel = HttpNotificationChannel.Find(channelName); try { if (pushChannel != null) { pushChannel.Close(); pushChannel.Dispose(); pushChannel = null; } } catch (InvalidOperationException ioException) { Utils.Tools.LogException("Cannot close the channel", ioException); } catch (ArgumentException argEcxeption) { Utils.Tools.LogException("Cannot close the channel", argEcxeption); } /* UIThread.Invoke(() => { this.enablePushNotifications(); });*/ break; case ChannelErrorType.NotificationRateTooHigh: //This error is returned when the Push Client is unable to receive messages because the web service is sending too many messages at too quick a rate to a certain device. //Slow down the notifications //@TODO: send the server a signal? break; case ChannelErrorType.MessageBadContent: //This error is returned when the image reference is pointing to an HTTP image, even though the notification channel is not currently bound to a list of URIs. //This should never happen to us break; case ChannelErrorType.PowerLevelChanged: //This has been deprecated because push client no longer takes any action based on any power states break; case ChannelErrorType.Unknown: //An internal error has occurred and could not be recovered. A device reboot may be necessary. break; default: break; } processingError = false; }
// ===========================这个是推送发的信息 //====================下面是推送 Uri private void getUri() { httpChannel = HttpNotificationChannel.Find(channelName); if (httpChannel != null) { httpChannel.Close(); httpChannel.Dispose(); } httpChannel = new HttpNotificationChannel(channelName, "NotificationServer"); //注册URI httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated); //发生错误的事件 httpChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred); //toast 推送通知服务事件 httpChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived); //打开连接 httpChannel.Open(); //绑定toast 推送服务 httpChannel.BindToShellToast(); }
/// <summary> /// Event handler for when a push notification error occurs. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) { Utils.Tools.LogException((String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)), null); if (processingError) { return; } processingError = true; switch (e.ErrorType) { case ChannelErrorType.ChannelOpenFailed: case ChannelErrorType.PayloadFormatError: //ChannelErrorType.ChannelOpenFailed //This error is returned when the Push Client and the Push Notification Service are unable to establish a connection //ChannelErrorType.PayloadFormatError: //This error is returned when the XML payload format or the HTTP header of the push notification is syntactically invalid. pushChannel = HttpNotificationChannel.Find(channelName); try { if (pushChannel != null) { pushChannel.Close(); pushChannel.Dispose(); pushChannel = null; } } catch (InvalidOperationException ioException) { Utils.Tools.LogException("Cannot close the channel", ioException); } catch (ArgumentException argEcxeption) { Utils.Tools.LogException("Cannot close the channel", argEcxeption); } /* UIThread.Invoke(() => * { * this.enablePushNotifications(); * });*/ break; case ChannelErrorType.NotificationRateTooHigh: //This error is returned when the Push Client is unable to receive messages because the web service is sending too many messages at too quick a rate to a certain device. //Slow down the notifications //@TODO: send the server a signal? break; case ChannelErrorType.MessageBadContent: //This error is returned when the image reference is pointing to an HTTP image, even though the notification channel is not currently bound to a list of URIs. //This should never happen to us break; case ChannelErrorType.PowerLevelChanged: //This has been deprecated because push client no longer takes any action based on any power states break; case ChannelErrorType.Unknown: //An internal error has occurred and could not be recovered. A device reboot may be necessary. break; default: break; } processingError = false; }
public void Dispose() { _pushChannel.Dispose(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { _channel.Dispose(); GC.SuppressFinalize(this); }