private HttpNotificationChannel CreateNewChannel() { var channel = HttpNotificationChannel.Find(AppContext.State.AppId); if (channel == null) { channel = new HttpNotificationChannel(AppContext.State.AppId); SubscribeToEvents(channel); // Open the channel channel.Open(); UpdateChannelUri(channel.ChannelUri); // Register for tile notifications var whitelistedDomains = AppContext.State.Settings.PushSettings.WhitelistedDomains; if (whitelistedDomains.Count == 0) channel.BindToShellTile(); else channel.BindToShellTile(new Collection<Uri>(whitelistedDomains)); // Register for shell notifications channel.BindToShellToast(); } else { SubscribeToEvents(channel); UpdateChannelUri(channel.ChannelUri); } return channel; }
private HttpNotificationChannel CreateNewChannel() { var channel = HttpNotificationChannel.Find(AppContext.State.AppId); if (channel == null) { channel = new HttpNotificationChannel(AppContext.State.AppId); SubscribeToEvents(channel); // Open the channel channel.Open(); UpdateChannelUri(channel.ChannelUri); // Register for tile notifications var whitelistedDomains = AppContext.State.Settings.PushSettings.WhitelistedDomains; if (whitelistedDomains.Count == 0) { channel.BindToShellTile(); } else { channel.BindToShellTile(new Collection <Uri>(whitelistedDomains)); } // Register for shell notifications channel.BindToShellToast(); } else { SubscribeToEvents(channel); UpdateChannelUri(channel.ChannelUri); } return(channel); }
public static HttpNotificationChannel Register(string channelName, Collection<Uri> baseUris, bool bindToShellTile, bool bindToShellToast, EventHandler<NotificationChannelErrorEventArgs> errorHandler, Action<HttpNotificationChannel, bool> completed) { try { var channel = HttpNotificationChannel.Find(channelName); if (channel == null) { channel = new HttpNotificationChannel(channelName); channel.ChannelUriUpdated += (s, e) => { if (!channel.IsShellTileBound && bindToShellTile) { if (baseUris != null) channel.BindToShellTile(baseUris); else channel.BindToShellTile(); } if (!channel.IsShellToastBound && bindToShellToast) channel.BindToShellToast(); completed(channel, true); }; channel.ErrorOccurred += (sender, args) => completed(null, false); if (errorHandler != null) channel.ErrorOccurred += errorHandler; channel.Open(); } else { if (errorHandler != null) { channel.ErrorOccurred -= errorHandler; channel.ErrorOccurred += errorHandler; } completed(channel, false); } return channel; } catch (Exception ex) { if (Debugger.IsAttached) Debugger.Break(); completed(null, false); return null; } }
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(); } }
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()); } }
public void OpenChannel() { HttpNotificationChannel notificationChannel1 = this.TryFindChannel(); if (notificationChannel1 != null && notificationChannel1.ChannelUri == null) { notificationChannel1.Close(); notificationChannel1 = null; } if (notificationChannel1 == null) { HttpNotificationChannel notificationChannel2 = new HttpNotificationChannel(VKConstants.HttpPushNotificationName, "push.vk.com"); notificationChannel2.ChannelUriUpdated += (new EventHandler <NotificationChannelUriEventArgs>(this.PushChannel_ChannelUriUpdated)); notificationChannel2.ErrorOccurred += (new EventHandler <NotificationChannelErrorEventArgs>(this.PushChannel_ErrorOccurred)); notificationChannel2.ShellToastNotificationReceived += (new EventHandler <NotificationEventArgs>(this.pushChannel_ShellToastNotificationReceived)); notificationChannel2.Open(); notificationChannel2.BindToShellToast(); notificationChannel2.BindToShellTile(); } else { notificationChannel1.ChannelUriUpdated += (new EventHandler <NotificationChannelUriEventArgs>(this.PushChannel_ChannelUriUpdated)); notificationChannel1.ErrorOccurred += (new EventHandler <NotificationChannelErrorEventArgs>(this.PushChannel_ErrorOccurred)); notificationChannel1.ShellToastNotificationReceived += (new EventHandler <NotificationEventArgs>(this.pushChannel_ShellToastNotificationReceived)); if (!(notificationChannel1.ChannelUri != null)) { return; } this.FireChannelUriUpdatedEvent(notificationChannel1.ChannelUri); } }
/// <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(); } }
/// <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(); } }
private void BindToShellTile() { if (_channel != null && !_channel.IsShellTileBound) { var c = new Collection <Uri> { new Uri("http://tiles.4thandmayor.com/", UriKind.Absolute), new Uri("https://www.4thandmayor.com/", UriKind.Absolute) }; try { _channel.BindToShellTile(c); } catch (InvalidOperationException) { // crash reported: /* * BindToShellTile or BindToShellToast failed because it is already bound to the channel. Check the IsShellToastBound or IsShellTileBound properties or UnbindToShellToast or UnbindToShellTile before binding again. * System.InvalidOperationException * at Microsoft.Phone.Notification.SafeNativeMethods.ThrowExceptionFromHResult(Int32 hr, Exception defaultException, NotificationType type) * at Microsoft.Phone.Notification.ShellObjectChannelInternals.Bind() * at Microsoft.Phone.Notification.HttpNotificationChannel.BindToShellTile(Collection`1 baseUri) * at JeffWilcox.FourthAndMayor.PushNotificationService.BindToShellTile() * at JeffWilcox.FourthAndMayor.PushNotificationService.OnChannelUriUpdated(Object sender, NotificationChannelUriEventArgs e) * at Microsoft.Phone.Notification.HttpNotificationChannel.OnDescriptorUpdated(IntPtr blob, UInt32 blobSize) * at Microsoft.Phone.Notification.HttpNotificationChannel.ChannelHandler(UInt32 eventType, IntPtr blob1, UInt32 int1, IntPtr blob2, UInt32 int2) * at Microsoft.Phone.Notification.HttpNotificationChannel.Dispatch(Object threadContext) * at System.Threading.ThreadPool.WorkItem.doWork(Object o) * at System.Threading.Timer.ring() * */ } } }
private void SubscribeToNotifications() { try { //Remote tiles - currently not working I think this is a MPNS issue //ShellEntryPoint shellEntryPoint = new ShellEntryPoint(); //shellEntryPoint.RemoteImageUri = new Uri("<A href="http://www.nickharris.net/wp-content/uploads/2010/06/Background1.png">http://www.nickharris.net/wp-content/uploads/2010/06/Background1.png</A>", UriKind.Absolute); � //_channel.BindToShellEntryPoint(shellEntryPoint); // tile - remote if (_supportsTile) { _channel.BindToShellTile(); // tile - local } } catch (Exception e) { } //do nothing - allready been subscribed to for current channel try { if (_supportsToast) { _channel.BindToShellToast(); // - toast } } catch (Exception e) { } //do nothing - allready been subscribed to for current channel }
private void SubscribeToNotifications() { try { //Registering to Toast Notifications if (httpChannel.IsShellToastBound == false) { httpChannel.BindToShellToast(); } } catch (Exception ex) { //Nothing to do - channel already exists and subscribed } try { if (httpChannel.IsShellTileBound == false) { httpChannel.BindToShellTile(); } } catch (Exception ex) { //Nothing to do - channel already exists and subscribed } }
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 void SubscribeToNotifications() { try { if (!_httpChannel.IsShellToastBound) { _httpChannel.BindToShellToast(); } } catch (InvalidOperationException iopEx) { //_errorHandler.WriteReport(string.Format("Channel error: {0}", iopEx)); } try { if (!_httpChannel.IsShellTileBound) { _httpChannel.BindToShellTile(); } } catch (InvalidOperationException iopEx) { //_errorHandler.WriteReport(string.Format("Channel error: {0}", iopEx)); } }
/// <summary> /// 初始化HttpNotify,创建绑定通道 /// </summary> public static void InitHttpNotify() { try { var _pushChannel = HttpNotificationChannel.Find(PursuitUtils.HttpNotifyChannelName); if (_pushChannel == null) { _pushChannel = new HttpNotificationChannel(PursuitUtils.HttpNotifyChannelName); _pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(_pushChannel_ChannelUriUpdated); _pushChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(_pushChannel_ErrorOccurred); _pushChannel.Open(); _pushChannel.BindToShellTile(); _pushChannel.BindToShellToast(); } else { _pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(_pushChannel_ChannelUriUpdated); _pushChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(_pushChannel_ErrorOccurred); } if (_pushChannel.ChannelUri != null) { JudgeUri(_pushChannel.ChannelUri.AbsoluteUri); } } catch (InvalidOperationException) { } }
/// <summary> /// Subscribe to Shell tile notifications /// </summary> /// <param name="channel">The active notification channel</param> private void SubscribeToTileNotifications(HttpNotificationChannel channel) { // // Bind to Tile Notification // if (channel.IsShellTileBound == true) { Trace("Already bound (registered) to Tile notification"); return; } try { Trace("Registering to Tile Notifications"); // // Remote Uri's must be explicitly allowed // Collection <Uri> uris = new Collection <Uri>(); uris.Add(new Uri("http://busstoplight.com/")); uris.Add(new Uri("http://api.busstoplight.com/")); uris.Add(new Uri("http://localhost/")); uris.Add(BaseAddress); channel.BindToShellTile(uris); } catch (Exception e) { UpdateStatus("BindToShellTile failed: " + e.Message); return; } }
public void RegisterPushNotifications() { if (pushChannel != null) return; 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, "PositiveSSL CA"); // Register for all the events before attempting to open the channel. pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated; pushChannel.ErrorOccurred += PushChannel_ErrorOccurred; pushChannel.HttpNotificationReceived += PushChannel_HttpNotificationReceived; pushChannel.Open(); pushChannel.BindToShellToast(); pushChannel.BindToShellTile(); } else { // The channel was already open, so just register for all the events. pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated; pushChannel.ErrorOccurred += PushChannel_ErrorOccurred; pushChannel.HttpNotificationReceived += PushChannel_HttpNotificationReceived; } if (UriUpdated != null && pushChannel.ChannelUri != null) { UriUpdated(pushChannel.ChannelUri.ToString()); } }
private static ZumoTest CreateRegisterChannelTest() { return(new ZumoTest("Register push channel", async delegate(ZumoTest test) { string channelName = "MyPushChannel"; var pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel == null) { pushChannel = new HttpNotificationChannel(channelName); test.AddLog("Created new channel"); } else { test.AddLog("Reusing existing channel"); } ZumoWP8PushTests.pushChannel = pushChannel; if (pushChannel.ConnectionStatus == ChannelConnectionStatus.Disconnected) { pushChannel.Open(); test.AddLog("Opened the push channel"); } else { test.AddLog("Channel already opened"); } if (pushChannel.IsShellToastBound) { test.AddLog("Channel is already bound to shell toast"); } else { var uris = new System.Collections.ObjectModel.Collection <Uri>(); uris.Add(new Uri(ImageUrlDomain)); pushChannel.BindToShellTile(uris); pushChannel.BindToShellToast(); test.AddLog("Bound the push channel to shell toast / tile"); } pushChannel.HttpNotificationReceived += pushChannel_HttpNotificationReceived; pushChannel.ShellToastNotificationReceived += pushChannel_ShellToastNotificationReceived; test.AddLog("Registered to raw / shell toast events"); TimeSpan maxWait = TimeSpan.FromSeconds(30); await WaitForChannelUriAssignment(test, pushChannel, maxWait); if (pushChannel.ConnectionStatus != ChannelConnectionStatus.Connected || pushChannel.ChannelUri == null) { test.AddLog("Error, push channel isn't connected or channel URI is null"); return false; } else { return true; } })); }
public XPushNotificationHelper() { /// Holds the push channel that is created or found. HttpNotificationChannel pushChannel; // The name of our push channel. string channelName = XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("ProductID").Value; // 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.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived); pushChannel.Open(); //Raw push only work on app running // Bind this new channel for toast events. //Toast push is work app is running or background! pushChannel.BindToShellToast(); // Bind this new channel for tile events. //Tile push is work background or died! 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); pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived); if (null == pushChannel.ChannelUri) return; // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point. XLog.WriteInfo("push channel URI is : " + pushChannel.ChannelUri.ToString()); //保存 Uri,由push扩展获取发送到js端 IsolatedStorageSettings userSettings = IsolatedStorageSettings.ApplicationSettings; userSettings[XConstant.PUSH_NOTIFICATION_URI] = pushChannel.ChannelUri.ToString(); userSettings.Save(); } }
private void BindTileNotification() { if (_notificationChannel.IsShellTileBound) { Debug.WriteLine("Already bounded (register) to Tile Notifications"); return; } Debug.WriteLine("Registering to Tile Notifications"); // you can register the phone application to receive tile images from remote servers [this is optional] if (_tileTrustedServers == null) { _notificationChannel.BindToShellTile(); } else { _notificationChannel.BindToShellTile(_tileTrustedServers); } }
/// <summary> /// The callback for a channel update. The event args contain the URI that points to the device. /// </summary> private void httpChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e) { // This URI is used to send notifications to the device and would need to be // sent to a game server or other web service any time the URI gets updated. console.AddLine("Channel updated. Got Uri:\n" + httpChannel.ChannelUri.ToString()); // Bind to the shell so the phone knows the app wants to receive notifications. console.AddLine("Binding to shell."); httpChannel.BindToShellToast(); httpChannel.BindToShellTile(); }
public void UpdateLiveTile(Uri liveTileUri, string liveTileTitle, int? liveTileCount, Action onComplete) { HttpNotificationChannel toastChannel = HttpNotificationChannel.Find("liveTileChannel"); if (toastChannel != null) { toastChannel.Close(); } toastChannel = new HttpNotificationChannel("liveTileChannel"); toastChannel.ChannelUriUpdated += (s, e) => { Debug.WriteLine(String.Format("Is image an absolute Uri: {0}", tileSchedule.RemoteImageUri.IsAbsoluteUri)); if (liveTileUri.IsAbsoluteUri) { toastChannel.BindToShellTile(new Collection<Uri> { liveTileUri }); } else { toastChannel.BindToShellTile(); } SendTileToPhone(e.ChannelUri, liveTileUri.ToString(), liveTileCount, liveTileTitle, () => { //Give it some time to let the update propagate Thread.Sleep(TimeSpan.FromSeconds(10)); toastChannel.UnbindToShellTile(); toastChannel.Close(); //Call the "complete" delegate if (onComplete != null) onComplete(); } ); }; toastChannel.Open(); }
private static void SetupNotificationChannel() { try { _channel = HttpNotificationChannel.Find(ChannelName); if (_channel == null) { try { _channel = new HttpNotificationChannel(ChannelName); _channel.ChannelUriUpdated += (s, e) => { _channel = HttpNotificationChannel.Find(ChannelName); if (!_channel.IsShellTileBound) { _channel.BindToShellTile(uris); } if (!_channel.IsShellToastBound) { _channel.BindToShellToast(); } RegisterForNotifications(); }; _channel.ErrorOccurred += (s, e) => LastError = e.Message; CurrentStatus = Status.Opening; _channel.Open(); } catch (Exception ex) { try { _channel.Close(); } catch (Exception) { } // MessageBox.Show("Failed to open Push Notification Channel: " + ex.Message); CurrentStatus = Status.Error; LastError = ex.Message; } } else { RegisterForNotifications(); } } catch (Exception exx) { CurrentStatus = Status.Error; LastError = exx.Message; } }
public void registerPushnotifications() { string pushToken; App.appSettings.TryGetValue <string>(App.LATEST_PUSH_TOKEN, out pushToken); _latestPushToken = pushToken; HttpNotificationChannel pushChannel; pollingTime = minPollingTime; // Try to find the push channel. pushChannel = HttpNotificationChannel.Find(HikeConstants.pushNotificationChannelName); try { // If the channel was not found, then create a new connection to the push service. if (pushChannel == null) { pushChannel = new HttpNotificationChannel(HikeConstants.pushNotificationChannelName, HikeConstants.PUSH_CHANNEL_CN); // 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); 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); pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); } if (pushChannel.ChannelUri != null) { LatestPushToken = pushChannel.ChannelUri.ToString(); } else { LatestPushToken = null; } } catch (InvalidOperationException ioe) { Debug.WriteLine("PUSH Exception :: " + ioe.StackTrace); } catch (Exception ee) { Debug.WriteLine("PUSH Exception :: " + ee.StackTrace); } }
private void SubscribeToNotifications() { ////////////////////////////////////////// // Bind to Toast Notification ////////////////////////////////////////// try { if (httpChannel.IsShellToastBound == true) { App.Trace("Already bound to Toast notification"); } else { App.Trace("Registering to Toast Notifications"); httpChannel.BindToShellToast(); } } catch (Exception ex) { // handle error here App.Trace("Bind to Toast Notification Exception : " + ex.Message); throw ex; } ////////////////////////////////////////// // Bind to Tile Notification ////////////////////////////////////////// try { if (httpChannel.IsShellTileBound == true) { App.Trace("Already bound to Tile Notifications"); } else { App.Trace("Registering to Tile Notifications"); // you can register the phone application to receive tile images from remote servers [this is optional] Collection <Uri> uris = new Collection <Uri>(); uris.Add(new Uri("http://www.larvalabs.com")); httpChannel.BindToShellTile(uris); } } catch (Exception ex) { //handle error here App.Trace("Bind to Tile Notification Exception : " + ex.Message); throw ex; } notificationsBound = true; }
private void BindTile(HttpNotificationChannel channel, List <string> allowedDomains) { // Check if the tile is bound, if not, bind it with the domain our image is coming from. if (!channel.IsShellTileBound) { Collection <Uri> ListOfAllowedDomains = new Collection <Uri>(); foreach (string url in allowedDomains) { ListOfAllowedDomains.Add(new Uri(url, UriKind.RelativeOrAbsolute)); } channel.BindToShellTile(ListOfAllowedDomains); } }
private void AcquirePushChannel() { CurrentChannel = HttpNotificationChannel.Find("MyPushChannel"); if (CurrentChannel == null) { CurrentChannel = new HttpNotificationChannel("MyPushChannel"); CurrentChannel.Open(); CurrentChannel.BindToShellTile(); CurrentChannel.BindToShellToast(); } }
public void init(string argsString) { Options options; try { options = JsonConvert.DeserializeObject<Options>(JsonConvert.DeserializeObject<string[]>(argsString)[0]); } catch (Exception) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return; } // Prevent double initialization. if (this.currentChannel != null) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.INVALID_ACTION, ALREADY_INITIALIZED_ERROR)); } // Create or retrieve the notification channel. var channel = HttpNotificationChannel.Find(options.WP8.ChannelName); if (channel == null) { channel = new HttpNotificationChannel(options.WP8.ChannelName); SubscribeChannelEvents(channel); try { channel.Open(); } catch (InvalidOperationException) { UnsubscribeChannelEvents(channel); this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, INVALID_REGISTRATION_ERROR)); return; } channel.BindToShellToast(); channel.BindToShellTile(); } else { SubscribeChannelEvents(channel); } this.currentChannel = channel; this.lastChannelUri = null; this.callbackId = CurrentCommandCallbackId; // First attempt at notifying the URL (most of the times it won't notify anything) NotifyRegitrationIfNeeded(); }
public void register(string options) { if (!TryDeserializeOptions(options, out this.pushOptions)) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return; } var pushChannel = HttpNotificationChannel.Find(this.pushOptions.ChannelName); if (pushChannel == null) { pushChannel = new HttpNotificationChannel(this.pushOptions.ChannelName); SubscribePushChannelEvents(pushChannel); try { pushChannel.Open(); } catch (InvalidOperationException) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, InvalidRegistrationError)); return; } pushChannel.BindToShellToast(); pushChannel.BindToShellTile(); } else { SubscribePushChannelEvents(pushChannel); } if (pushChannel.ChannelUri == null) { // Wait for the channel to become ready. // Need to respond with OK instead of NO_RESULT because of https://issues.apache.org/jira/browse/CB-8580 PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.KeepCallback = true; this.DispatchCommandResult(pluginResult, this.CurrentCommandCallbackId); } else { var result = new RegisterResult { ChannelName = this.pushOptions.ChannelName, Uri = pushChannel.ChannelUri.ToString() }; this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result)); } }
private void abrirCanalMPNS() { uriChannel = HttpNotificationChannel.Find(vNombreCanal); if (uriChannel == null) { uriChannel = new HttpNotificationChannel(vNombreCanal); uriChannel.Open(); uriChannel.BindToShellToast(); uriChannel.BindToShellTile(); } uriChannel.ChannelUriUpdated += uriChannel_ChannelUriUpdated; uriChannel.ErrorOccurred += uriChannel_ErrorOccurred; }
private static void BindToShell(HttpNotificationChannel httpChannel) { try { //toast notification binding httpChannel.BindToShellToast(); //tile notification binding httpChannel.BindToShellTile(); } catch (Exception ex) { Debug.WriteLine("An exception occurred binding to shell " + ex.ToString()); } }
private void LoadOrCreateChannelAsync(Action callback = null) { Execute.BeginOnThreadPool(() => { _pushChannel = HttpNotificationChannel.Find(Constants.ToastNotificationChannelName); if (_pushChannel == null) { _pushChannel = new HttpNotificationChannel(Constants.ToastNotificationChannelName); _pushChannel.HttpNotificationReceived += OnHttpNotificationReceived; _pushChannel.ChannelUriUpdated += OnChannelUriUpdated; _pushChannel.ErrorOccurred += OnErrorOccurred; _pushChannel.ShellToastNotificationReceived += OnShellToastNotificationReceived; try { _pushChannel.Open(); } catch (Exception e) { TLUtils.WriteException(e); } if (_pushChannel != null && _pushChannel.ChannelUri != null) { Debug.WriteLine(_pushChannel.ChannelUri.ToString()); } _pushChannel.BindToShellToast(); _pushChannel.BindToShellTile(); } else { _pushChannel.HttpNotificationReceived += OnHttpNotificationReceived; _pushChannel.ChannelUriUpdated += OnChannelUriUpdated; _pushChannel.ErrorOccurred += OnErrorOccurred; _pushChannel.ShellToastNotificationReceived += OnShellToastNotificationReceived; if (!_pushChannel.IsShellTileBound) { _pushChannel.BindToShellToast(); } if (!_pushChannel.IsShellTileBound) { _pushChannel.BindToShellTile(); } } callback.SafeInvoke(); }); }
private static HttpNotificationChannel OpenOrCreateChannel(string channelName) { HttpNotificationChannel channel; channel = HttpNotificationChannel.Find(channelName); if (channel == null) { channel = new HttpNotificationChannel(channelName); channel.Open(); channel.BindToShellTile(); channel.BindToShellToast(); } return(channel); }
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; } }
/// <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 BindToShell(HttpNotificationChannel channel) { if (channel == null) { return; } if (!channel.IsShellToastBound) { channel.BindToShellToast(); } if (!channel.IsShellTileBound) { channel.BindToShellTile(); } }
private static void SubscribeToService() { Guid deviceAppInstanceId = GetSettingValue <Guid>(DeviceAppIdKey, false); Context.Load(Context.Web, w => w.Title, w => w.Description); PushNotificationSubscriber pushSubscriber = Context.Web.RegisterPushNotificationSubscriber(deviceAppInstanceId, httpChannel.ChannelUri.AbsoluteUri); Context.Load(pushSubscriber); Context.ExecuteQueryAsync ( (object sender, ClientRequestSucceededEventArgs args) => { SetRegistrationStatus(true); // Indicate that tile and toast notifications can be // received by phone shell when phone app is not running. if (!httpChannel.IsShellTileBound) { httpChannel.BindToShellTile(); } if (!httpChannel.IsShellToastBound) { httpChannel.BindToShellToast(); } Context.Load(pushSubscriber.User); Context.ExecuteQueryAsync ( (object sender1, ClientRequestSucceededEventArgs args1) => { ShowMessage( string.Format("Subscriber successfully registered: {0}", pushSubscriber.User.LoginName), "Success"); }, (object sender1, ClientRequestFailedEventArgs args1) => { ShowMessage(args1.Exception.Message, "Error getting User details"); }); }, (object sender, ClientRequestFailedEventArgs args) => { ShowMessage(args.Exception.Message, "Error Subscribing"); }); }
public static async Task AcquirePushChannel() { // -- Channel CurrentChannel = HttpNotificationChannel.Find(ChannelName); if (CurrentChannel == null) { CurrentChannel = new HttpNotificationChannel(ChannelName); CurrentChannel.Open(); CurrentChannel.BindToShellTile(); CurrentChannel.BindToShellToast(); } CurrentChannel.ShellToastNotificationReceived += ShellToastNotificationReceived; // -- NotificationRegistration var registrationsTable = MobileService.GetTable <NotificationRegistration>(); var registration = new NotificationRegistration { ChannelUri = CurrentChannel.ChannelUri.AbsoluteUri, UserId = StaticData.UserData.UserId, }; var existingRegistrations = await registrationsTable .Where(nr => nr.ChannelUri == registration.ChannelUri || nr.UserId == registration.UserId) .ToListAsync(); if (existingRegistrations.Any()) // update { registration.Id = existingRegistrations[0].Id; await registrationsTable.UpdateAsync(registration); // If there are other records, those are out of date for (int i = 1; i < existingRegistrations.Count; i++) { await registrationsTable.DeleteAsync(existingRegistrations[i]); } } else // insert { await registrationsTable.InsertAsync(registration); } // -- NotificationData await ResetNotificationData(); }
private void SubscribeToNotifications() { ////////////////////////////////////////// // Bind to Toast Notification ////////////////////////////////////////// try { if (httpChannel.IsShellToastBound == true) { Trace("Already bounded (register) to to Toast notification"); } else { Trace("Registering to Toast Notifications"); httpChannel.BindToShellToast(); } } catch (Exception ex) { // handle error here } ////////////////////////////////////////// // Bind to Tile Notification ////////////////////////////////////////// try { if (httpChannel.IsShellTileBound == true) { Trace("Already bounded (register) to Tile Notifications"); } else { Trace("Registering to Tile Notifications"); // you can register the phone application to receive tile images from remote servers [this is optional] Collection <Uri> uris = new Collection <Uri>(); uris.Add(new Uri("http://jquery.andreaseberhard.de/pngFix/pngtest.png")); httpChannel.BindToShellTile(uris); } } catch (Exception ex) { //handle error here } }
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 void OpenNotificationChannel() { FindNotificationChannel(); if (!(bool)Settings.AllowPushNotifications) { if (Channel != null) Channel.Close(); return; } if (Channel == null) { Channel = new HttpNotificationChannel(ChannelName); Channel.Open(); Channel.BindToShellToast(); Channel.BindToShellTile(); } Channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(HttpChannelChannelUriUpdated); Channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(HttpChannelHttpNotificationReceived); Channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(HttpChannelErrorOccurred); Channel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(HttpChannelToastNotificationReceived); Channel.ConnectionStatusChanged += new EventHandler<NotificationChannelConnectionEventArgs>(HttpChannelConnectionStatusChanged); }
// Constructor public MainPage() { /// Holds the push channel that is created or found. HttpNotificationChannel pushChannel; // The name of our push channel. string channelName = "MyPushChannel"; InitializeComponent(); // 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); pushChannel.Open(); // Bind this new channel for Tile events. 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); // 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())); } }
/// <summary> /// /// </summary> /// <param name="channelName"></param> /// <param name="registrationCallBack">Registration Callback with parameter </param> /// <param name="messageCallback"></param> public void CreatePushChannel(String channelName, PushServiceRegistrationCallback registrationCallBack, PushServiceMessageCallback messageCallback) { /// Holds the push channel that is created or found. HttpNotificationChannel pushChannel; mRegistrationCallback = registrationCallBack; mMessageCallback = messageCallback; // 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); pushChannel.Open(); pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); 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); if (pushChannel.IsShellTileBound) { pushChannel.UnbindToShellTile(); } if (pushChannel.IsShellToastBound) { pushChannel.UnbindToShellToast(); } pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); pushChannel.BindToShellToast(); pushChannel.BindToShellTile(); } }
public void openChannel(string options) { try { HttpNotificationChannel currentChannel = HttpNotificationChannel.Find(ChannelName); if (currentChannel == null) { currentChannel = new HttpNotificationChannel(ChannelName); currentChannel.Open(); currentChannel.BindToShellTile(); currentChannel.BindToShellToast(); } this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, currentChannel.ChannelUri)); } catch { this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); } }
private void Subscribe(HttpNotificationChannel pushChannel) { // The channel was already open, so just register for all the events. pushChannel.ChannelUriUpdated += async (sender, e) => { await PushSubscribe(e.ChannelUri); }; pushChannel.ErrorOccurred += (sender, e) => System.Diagnostics.Debug.WriteLine("PushChannel Error: " + e.ErrorType.ToString() + " -> " + e.ErrorCode + " -> " + e.Message + " -> " + e.ErrorAdditionalData); // Bind this new channel for toast events. if (pushChannel.IsShellToastBound) System.Diagnostics.Debug.WriteLine("Already Bound to Toast"); else pushChannel.BindToShellToast(); if (pushChannel.IsShellTileBound) System.Diagnostics.Debug.WriteLine("Already Bound to Tile"); else pushChannel.BindToShellTile(); }
public void RegisterPushNotifications() { if (pushChannel != null) return; 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, "PositiveSSL CA"); // Register for all the events before attempting to open the channel. pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated; pushChannel.ErrorOccurred += PushChannel_ErrorOccurred; pushChannel.HttpNotificationReceived += PushChannel_HttpNotificationReceived; pushChannel.Open(); pushChannel.BindToShellToast(); pushChannel.BindToShellTile(); System.Diagnostics.Debug.WriteLine("Connetion: " + pushChannel.ConnectionStatus.ToString()); System.Diagnostics.Debug.WriteLine("Bound: " + pushChannel.IsShellTileBound.ToString()); } else { // The channel was already open, so just register for all the events. pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated; pushChannel.ErrorOccurred += PushChannel_ErrorOccurred; pushChannel.HttpNotificationReceived += PushChannel_HttpNotificationReceived; System.Diagnostics.Debug.WriteLine("Connetion2: " + pushChannel.ConnectionStatus.ToString()); System.Diagnostics.Debug.WriteLine("Bound2: " + pushChannel.IsShellTileBound.ToString()); } //if (UriUpdated != null && pushChannel.ChannelUri != null) //{ // UriUpdated(pushChannel.ChannelUri.ToString()); //} }
/// <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()); } }
public void enablePushNotifications() { try { string device_uuid = this.getDeviceUUID(); if (device_uuid == null) return; //check the push notifications user settings UserSettings settings = new UserSettings(); if (!this.pushNotificationsEnabled()) { this.disablePushNotifications(); return; } //check if there is a .COM or Jetpack blog in the app. List<Blog> blogs = DataService.Current.Blogs.ToList(); bool presence = false; foreach (Blog currentBlog in blogs) { if (currentBlog.isWPcom() || currentBlog.hasJetpack()) { presence = true; break; } } if (!presence) { System.Diagnostics.Debug.WriteLine("Not found a .COM or Jetpack blog"); this.disablePushNotifications(); return; } // 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); pushChannel.ConnectionStatusChanged += new EventHandler<NotificationChannelConnectionEventArgs>(PushChannel_ConnectionStatusChanged); // Register for this notification since we need to receive the notifications while the application is running. pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); try { pushChannel.Open(); } catch (InvalidOperationException _pushNotificationChannelOpenFailed) { Utils.Tools.LogException("Cannot open the channel, try it again...", _pushNotificationChannelOpenFailed); try { pushChannel.Open(); } catch (InvalidOperationException) { Utils.Tools.LogException("2nd tentative failed", _pushNotificationChannelOpenFailed); return; } } catch (ArgumentException) { return; } try { // Bind this new channel for toast events. pushChannel.BindToShellToast(); } catch (InvalidOperationException _pushNotificationChannelBindFailed) { Utils.Tools.LogException("BindToShellToast Failed", _pushNotificationChannelBindFailed); try { pushChannel.BindToShellToast(); } catch (InvalidOperationException) { } } try { // Bind this new channel for Tile events. pushChannel.BindToShellTile(); } catch (InvalidOperationException _pushNotificationChannelBindFailed) { Utils.Tools.LogException("BindToShellTile Failed", _pushNotificationChannelBindFailed); try { pushChannel.BindToShellTile(); } catch (InvalidOperationException) { } } } 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); pushChannel.ConnectionStatusChanged += new EventHandler<NotificationChannelConnectionEventArgs>(PushChannel_ConnectionStatusChanged); // Register for this notification since we need to receive the notifications while the application is running. pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived); System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); this.registerDevice(pushChannel.ChannelUri.ToString()); } } catch (Exception ex) { Utils.Tools.LogException("Unexpected Exception in enablePushnotification", ex); } }
private static HttpNotificationChannel OpenOrCreateChannel(string channelName) { HttpNotificationChannel channel; channel = HttpNotificationChannel.Find(channelName); if (channel == null) { channel = new HttpNotificationChannel(channelName); channel.Open(); channel.BindToShellTile(); channel.BindToShellToast(); } return channel; }
private void MainPageLoaded(object sender, RoutedEventArgs e) { HttpNotificationChannel pushChannel; string channelName = "NotificationSampleChannel"; pushChannel = HttpNotificationChannel .Find(channelName); if (pushChannel == null) { pushChannel = new HttpNotificationChannel (channelName); pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs> (PushChannelChannelUriUpdated); pushChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs> (PushChannelErrorOccurred); pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs> (pushChannel_ShellToastNotificationReceived); pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs> (pushChannel_HttpNotificationReceived); pushChannel.Open(); pushChannel.BindToShellTile(); pushChannel.BindToShellToast(); } else { pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs> (PushChannelChannelUriUpdated); pushChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs> (PushChannelErrorOccurred); pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs> (pushChannel_ShellToastNotificationReceived); pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs> (pushChannel_HttpNotificationReceived); Debug.WriteLine (pushChannel.ChannelUri .ToString()); MessageBox.Show (pushChannel.ChannelUri .ToString()); } }
private void BindTile(HttpNotificationChannel channel, List<string> allowedDomains) { // Check if the tile is bound, if not, bind it with the domain our image is coming from. if (!channel.IsShellTileBound) { Collection<Uri> ListOfAllowedDomains = new Collection<Uri>(); foreach (string url in allowedDomains) ListOfAllowedDomains.Add(new Uri(url, UriKind.RelativeOrAbsolute)); channel.BindToShellTile(ListOfAllowedDomains); } }
private void BindToShell(HttpNotificationChannel channel) { if (channel == null) return; if (!channel.IsShellToastBound) { channel.BindToShellToast(); } if (!channel.IsShellTileBound) { channel.BindToShellTile(); } }
/// <summary> /// 初始化HttpNotify,创建绑定通道 /// </summary> public static void InitHttpNotify() { try { var _pushChannel = HttpNotificationChannel.Find(PursuitUtils.HttpNotifyChannelName); if (_pushChannel == null) { _pushChannel = new HttpNotificationChannel(PursuitUtils.HttpNotifyChannelName); _pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(_pushChannel_ChannelUriUpdated); _pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(_pushChannel_ErrorOccurred); _pushChannel.Open(); _pushChannel.BindToShellTile(); _pushChannel.BindToShellToast(); } else { _pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(_pushChannel_ChannelUriUpdated); _pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(_pushChannel_ErrorOccurred); } if (_pushChannel.ChannelUri != null) JudgeUri(_pushChannel.ChannelUri.AbsoluteUri); } catch (InvalidOperationException) { } }
/// <summary> /// Init default values for newly opened push channel /// </summary> /// <param name="channel"></param> private static void Finish(HttpNotificationChannel channel) { string pushUri = channel.ChannelUri.ToString(); channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>((o, e) => { Deployment.Current.Dispatcher.BeginInvoke(() => { //not used.. //new ToastPrompt { Title = e.Notification.Channel.ChannelName }.Show(); }); }); if (!channel.IsShellToastBound) { channel.BindToShellToast(); } channel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>((o, e) => { Deployment.Current.Dispatcher.BeginInvoke(() => { string url = e.Collection["wp:Param"]; ToastPrompt tp = new ToastPrompt { Title = e.Collection["wp:Text1"], Message = e.Collection["wp:Text2"], TextOrientation = System.Windows.Controls.Orientation.Vertical}; tp.Tap += (o1, e1) => { try { ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri(url, UriKind.RelativeOrAbsolute)); } catch { }//ignore any error }; tp.Show(); }); }); if (!channel.IsShellTileBound) { channel.BindToShellTile(); } // handle error events channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>((o, e) => { RLog.E(typeof(PushHelper), e.Message); }); }
private void AcquirePushChannel() { CurrentChannel = HttpNotificationChannel.Find("MyPushChannel"); if (CurrentChannel == null) { CurrentChannel = new HttpNotificationChannel("MyPushChannel"); CurrentChannel.Open(); CurrentChannel.BindToShellTile(); } }
/// <summary> /// Subscribe to Shell tile notifications /// </summary> /// <param name="channel">The active notification channel</param> private void SubscribeToTileNotifications(HttpNotificationChannel channel) { // // Bind to Tile Notification // if (channel.IsShellTileBound == true) { Trace("Already bound (registered) to Tile notification"); return; } try { Trace("Registering to Tile Notifications"); // // Remote Uri's must be explicitly allowed // Collection<Uri> uris = new Collection<Uri>(); uris.Add(new Uri("http://busstoplight.com/")); uris.Add(new Uri("http://api.busstoplight.com/")); uris.Add(new Uri("http://localhost/")); uris.Add(BaseAddress); channel.BindToShellTile(uris); } catch (Exception e) { UpdateStatus("BindToShellTile failed: " + e.Message); return; } }
private static ZumoTest CreateRegisterChannelTest() { return new ZumoTest("Register push channel", async delegate(ZumoTest test) { string channelName = "MyPushChannel"; var pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel == null) { pushChannel = new HttpNotificationChannel(channelName); test.AddLog("Created new channel"); } else { test.AddLog("Reusing existing channel"); } ZumoWP8PushTests.pushChannel = pushChannel; if (pushChannel.ConnectionStatus == ChannelConnectionStatus.Disconnected) { pushChannel.Open(); test.AddLog("Opened the push channel"); } else { test.AddLog("Channel already opened"); } if (pushChannel.IsShellToastBound) { test.AddLog("Channel is already bound to shell toast"); } else { var uris = new System.Collections.ObjectModel.Collection<Uri>(); uris.Add(new Uri(ImageUrlDomain)); pushChannel.BindToShellTile(uris); pushChannel.BindToShellToast(); test.AddLog("Bound the push channel to shell toast / tile"); } pushChannel.HttpNotificationReceived += pushChannel_HttpNotificationReceived; pushChannel.ShellToastNotificationReceived += pushChannel_ShellToastNotificationReceived; test.AddLog("Registered to raw / shell toast events"); TimeSpan maxWait = TimeSpan.FromSeconds(30); await WaitForChannelUriAssignment(test, pushChannel, maxWait); if (pushChannel.ConnectionStatus != ChannelConnectionStatus.Connected || pushChannel.ChannelUri == null) { test.AddLog("Error, push channel isn't connected or channel URI is null"); return false; } else { return true; } }); }
public async void AcquirePushChannel() { CurrentChannel = HttpNotificationChannel.Find("MyPushChannel"); if (CurrentChannel == null) { CurrentChannel = new HttpNotificationChannel("MyPushChannel"); CurrentChannel.Open(); CurrentChannel.BindToShellTile(); } var uri = CurrentChannel.ChannelUri.ToString(); userTable = MobileService.GetTable<Users>(); if (settings.Contains("Pnumber")) { Users up = new Users(); up.uri = uri; up.Id = user_id; up.Name = user_name; up.Phone_no = pnumber; await userTable.UpdateAsync(up); } }
private static ZumoTest CreateRegisterChannelTest(bool registerTemplate = false, string templateType = null) { return new ZumoTest("Register push channel", async delegate(ZumoTest test) { string channelName = "MyPushChannel"; var pushChannel = HttpNotificationChannel.Find(channelName); if (pushChannel == null) { pushChannel = new HttpNotificationChannel(channelName); test.AddLog("Created new channel"); } else { test.AddLog("Reusing existing channel"); } ZumoWP8PushTests.pushChannel = pushChannel; if (pushChannel.ConnectionStatus == ChannelConnectionStatus.Disconnected || pushChannel.ChannelUri == null) { pushChannel.Open(); test.AddLog("Opened the push channel"); } else { test.AddLog("Channel already opened"); } if (pushChannel.IsShellToastBound) { test.AddLog("Channel is already bound to shell toast"); } else { var uris = new System.Collections.ObjectModel.Collection<Uri>(); uris.Add(new Uri(ImageUrlDomain)); pushChannel.BindToShellTile(uris); pushChannel.BindToShellToast(); test.AddLog("Bound the push channel to shell toast / tile"); } TimeSpan maxWait = TimeSpan.FromSeconds(30); await WaitForChannelUriAssignment(test, pushChannel, maxWait); if (ZumoTestGlobals.Instance.IsNHPushEnabled) { var zumoPush = ZumoTestGlobals.Instance.Client.GetPush(); MpnsTemplateRegistration reg = null; if (registerTemplate) { switch (templateType) { case "toast": reg = new MpnsTemplateRegistration(pushChannel.ChannelUri.ToString(), ZumoPushTestGlobals.NHWp8ToastTemplate, "wp8" + ZumoPushTestGlobals.NHToastTemplateName, "World English".Split()); break; case "tile": reg = new MpnsTemplateRegistration(pushChannel.ChannelUri.ToString(), ZumoPushTestGlobals.NHWp8TileTemplate, "wp8" + ZumoPushTestGlobals.NHTileTemplateName, "World Mandarin".Split()); break; case "raw": IDictionary<string, string> wp8Headers = new Dictionary<string, string>(); wp8Headers.Add("X-NotificationClass", "3"); reg = new MpnsTemplateRegistration(pushChannel.ChannelUri.ToString(), ZumoPushTestGlobals.NHWp8RawTemplate, "wp8" + ZumoPushTestGlobals.NHRawTemplateName, "World French".Split(), wp8Headers); break; } await zumoPush.RegisterAsync(reg); pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) => { await zumoPush.RegisterAsync(reg); }); test.AddLog("Registered to Notification hub"); } else { await zumoPush.RegisterNativeAsync(pushChannel.ChannelUri.ToString(), "tag1 tag2".Split()); pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) => { await zumoPush.RegisterNativeAsync(args.ChannelUri.ToString(), "tag1 tag2".Split()); }); test.AddLog("Registered with NH"); } } pushChannel.HttpNotificationReceived += pushChannel_HttpNotificationReceived; pushChannel.ShellToastNotificationReceived += pushChannel_ShellToastNotificationReceived; test.AddLog("Registered to raw / shell toast events"); if (pushChannel.ConnectionStatus != ChannelConnectionStatus.Connected || pushChannel.ChannelUri == null) { test.AddLog("Error, push channel isn't connected or channel URI is null"); return false; } else { return true; } }, registerTemplate ? ZumoTestGlobals.RuntimeFeatureNames.NH_PUSH_ENABLED : null); }
private void AcquirePushChannel() { CurrentChannel = HttpNotificationChannel.Find("MyPushChannel"); if (CurrentChannel == null) { CurrentChannel = new HttpNotificationChannel("MyPushChannel"); CurrentChannel.Open(); CurrentChannel.BindToShellTile(); } IMobileServiceTable<Channel> channelTable = App.MobileService.GetTable<Channel>(); var channel = new Channel { Uri = CurrentChannel.ChannelUri.ToString() }; channelTable.InsertAsync(channel); }