public void CreatingANotificationChannel()
        {
            // 既存のチャンネルを探す
            myChannel = HttpNotificationChannel.Find(ChannelName);

            if (myChannel == null)
            {
                // チャンネルがなければ作成する
                myChannel = new HttpNotificationChannel(ChannelName);
                SetUpDelegates();

                // Openすると、ChannelUriUpdated が発行される
                myChannel.Open();

                myChannel.BindToShellToast();
            }
            else
            {
                SetUpDelegates();
            }

            // サービスを登録する
            if (myChannel.ChannelUri != null)
            {
                RegistToService(myChannel.ChannelUri.ToString());
            }
        }
        private void AcquirePushChannel()
        {
            CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");

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

            CurrentChannel.ChannelUriUpdated +=
                new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
                {
                    MobileServiceClient client = todoItemManager.GetClient;

                    // Register for notifications using the new channel
                    const string template =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification " +
                    "xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>$(message)</wp:Text1></wp:Toast></wp:Notification>";

                    await client.GetPush()
                        .RegisterTemplateAsync(CurrentChannel.ChannelUri.ToString(), template, "mytemplate");
                });
        }
	    private async void AcquireToken()
	    {
	        var currentChannel = HttpNotificationChannel.Find(ChannelName);
		    if (currentChannel == null)
		    {
			    currentChannel = new HttpNotificationChannel(ChannelName);
				currentChannel.Open();
				currentChannel.BindToShellToast();
				currentChannel.ChannelUriUpdated += (sender, args) =>
				{
					RegisterToken(currentChannel.ChannelUri.AbsoluteUri);
				};

			    if (currentChannel.ChannelUri == null)
			    {
				    await Task.Delay(200);
					if(currentChannel.ChannelUri == null)
						return;
			    }

			    RegisterToken(currentChannel.ChannelUri.AbsoluteUri);
		    }
		    else
		    {
				currentChannel.ChannelUriUpdated += (sender, args) =>
				{
					RegisterToken(currentChannel.ChannelUri.AbsoluteUri);
				};
			}

			currentChannel.ShellToastNotificationReceived += OnNotificationReceived;
		}
        public override void OnInit()
        {
            configHandler.LoadAppPackageConfig();

            string channelName = "UAPush";

            // 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 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);

                this.RegisterDevice(pushChannel.ChannelUri);
            }
        }
        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()));
            }
        }
        // Constructor
        public MainPage()
        {
            HttpNotificationChannel pushChannel;
            String channelName = "ToastSampleChannel";

            InitializeComponent();
            pushChannel = HttpNotificationChannel.Find(channelName);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);
                pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                pushChannel.Open();
                pushChannel.BindToShellToast();
            }
            else
            {
                pushChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
                MessageBox.Show(String.Format("Channel uri is {0}", pushChannel.ChannelUri.ToString()));
            }
        }
Exemple #7
0
        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
        }
Exemple #8
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);
        }
    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;
    }
Exemple #10
0
 private void BindToast(HttpNotificationChannel channel)
 {
     if (!channel.IsShellToastBound)
     {
         channel.BindToShellToast();
     }
 }
Exemple #11
0
 /// <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>
        /// <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 #13
0
        public PainelPage()
        {
            InitializeComponent();
            lblUsuario.Text = "@" + usuario.Nome;
            ListarGrupos();
            ListarUsuarios();

            // Iniciar canal
            HttpNotificationChannel pushChannel;
            string channelName = "MeNotaChannel";
            pushChannel = HttpNotificationChannel.Find(channelName);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                pushChannel.Open();
                pushChannel.BindToShellToast();
            }
            else
            {
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                (Application.Current as App).Usuario.Url = pushChannel.ChannelUri.ToString();
                AtualizarUsuario((Application.Current as App).Usuario);
            }
        }
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);
        }
 private void BindToShellToast()
 {
     if (_channel != null && !_channel.IsShellToastBound)
     {
         try
         {
             _channel.BindToShellToast();
         }
         catch (InvalidOperationException)
         {
             /*
              * 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()
              * */
         }
     }
 }
Exemple #16
0
        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));
            }
        }
Exemple #17
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 #18
0
        // ===========================这个是推送发的信息



        //====================下面是推送 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();
        }
        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);
        }
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 AcquirePushChannel()
        {
            CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");

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

            CurrentChannel.ChannelUriUpdated +=
                new EventHandler <NotificationChannelUriEventArgs>(async(o, args) =>
            {
                MobileServiceClient client = todoItemManager.GetClient;

                // Register for notifications using the new channel
                const string template =
                    "<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification " +
                    "xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>$(message)</wp:Text1></wp:Toast></wp:Notification>";

                await client.GetPush()
                .RegisterTemplateAsync(CurrentChannel.ChannelUri.ToString(), template, "mytemplate");
            });
        }
Exemple #22
0
        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);
            }
        }
        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 #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);
        }
 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;
 }
Exemple #26
0
        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
            }
        }
        /// <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 #28
0
        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());
            }
        }
Exemple #29
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 #30
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"));
                }
            }
        }
        public void RegisterRawPushChannel(string channelName = "RawPushChannel")
        {
            // Holds the push channel that is created or found.
            HttpNotificationChannel _rawPushChannel;

            // Try to find the push channel.
            _rawPushChannel = HttpNotificationChannel.Find(channelName);

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

                // Register for all the events before attempting to open the channel.
                _rawPushChannel.ChannelUriUpdated += RawChannelUriUpdated;
                _rawPushChannel.ErrorOccurred += RawErrorOccurred;
                _rawPushChannel.HttpNotificationReceived += RawHttpNotificationReceived;

                _rawPushChannel.Open();

                // Bind this new channel for toast events.
                _rawPushChannel.BindToShellToast();

            }
            else
            {
                // The channel was already open, so just register for all the events.
                _rawPushChannel.ChannelUriUpdated += RawChannelUriUpdated;
                _rawPushChannel.ErrorOccurred += RawErrorOccurred;
                _rawPushChannel.HttpNotificationReceived += RawHttpNotificationReceived;

                // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.

            }
        }
Exemple #32
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 #33
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();
        }
        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());
                }
            }
        }
        // Constructor
        public MainPage()
        {
            HttpNotificationChannel pushChannel;
            String channelName = "ToastSampleChannel";
            InitializeComponent();
            pushChannel = HttpNotificationChannel.Find(channelName);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                pushChannel.Open();
                pushChannel.BindToShellToast();
            }
            else
            {
                pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
                pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
                pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
                MessageBox.Show(String.Format("Channel uri is {0}", pushChannel.ChannelUri.ToString()));
            }

        }
Exemple #36
0
        public static void Init(string appId, NotificationReceived inNotificationDelegate = null)
        {
            if (initDone)
            {
                return;
            }

            mAppId = appId;
            notificationDelegate = inNotificationDelegate;
            mPlayerId            = settings.Contains("GameThrivePlayerId") ? (string)settings["GameThrivePlayerId"] : null;
            mChannelUri          = settings.Contains("GameThriveChannelUri") ? (string)settings["GameThriveChannelUri"] : null;

            string channelName = "GameThriveApp" + appId;

            var pushChannel = HttpNotificationChannel.Find(channelName);

            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);

                SubscribeToChannelEvents(pushChannel);

                pushChannel.Open();
                pushChannel.BindToShellToast();
                fallBackOneSignalSession = new Timer((o) => Deployment.Current.Dispatcher.BeginInvoke(() => SendSession(null)), null, 20000, Timeout.Infinite);
            }
            else   // Else gets run on the 2nd open of the app and after. This happens on WP8.0 but not WP8.1
            {
                SubscribeToChannelEvents(pushChannel);

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

                // Since the channel was found ChannelUriUpdated does not fire so send an on session event.
                SendSession(null);
            }

            lastPingTime = DateTime.Now.Ticks;
            PhoneApplicationService.Current.Closing     += (s, e) => SaveActiveTime();
            PhoneApplicationService.Current.Deactivated += (s, e) => SaveActiveTime();
            PhoneApplicationService.Current.Activated   += AppResumed;

            // Using Disatcher due to Unity threading issues with Application.Current.RootVisual.
            // Works fine with normal native apps too.
            Deployment.Current.Dispatcher.BeginInvoke(() => {
                var startingPage = ((PhoneApplicationFrame)Application.Current.RootVisual).Content as PhoneApplicationPage;

                if (startingPage.NavigationContext.QueryString.ContainsKey("GameThriveParams"))
                {
                    NotificationOpened(null, startingPage.NavigationContext.QueryString["GameThriveParams"]);
                }

                SendPing(GetSavedActiveTime());

                initDone = true;
            });
        }
Exemple #37
0
        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;
                }
            }));
        }
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            DataContext = App.ViewModel;

            // 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()));
            }


            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();

            httpClient = new HttpClient();

            // Add a user-agent header
            var headers = httpClient.DefaultRequestHeaders;

            // HttpProductInfoHeaderValueCollection is a collection of 
            // HttpProductInfoHeaderValue items used for the user-agent header

            headers.UserAgent.ParseAdd("ie");
            headers.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");

        }
Exemple #39
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            //Create soap client for the GovBids service
            client = new AvailBidsSoapClient();

            //Connect the Get Bids Completed event (Async)
            client.GetBidsCompleted += client_GetBidsCompleted;

            var progressIndicator = new ProgressIndicator();
            SystemTray.SetProgressIndicator(this, progressIndicator);

            /// Holds the push channel that is created or found.
            HttpNotificationChannel pushChannel;

            // The name of our push channel.
            string channelName = "ToastUpdateChannel";

            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);

                // 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 #40
0
        private async void buttonEntrar_Click(object sender, RoutedEventArgs e)
        {
            (App.Current as App).NomeUsuarioLogado = textBoxNomeUsuario.Text;
            NavigationService.Navigate(new Uri("/Usuario/Inicial.xaml", UriKind.Relative));
            (App.Current as App).IdUsuarioLogado = 1;
            HttpNotificationChannel canalPush = HttpNotificationChannel.Find(nomeCanal);

            try
            {
                if (canalPush == null)
                {
                    //canal não existe
                    if (await Modelo.Usuario.ConsultarPorNome(textBoxNomeUsuario.Text) == "")
                    {
                        //Usuario existe
                        canalPush = new HttpNotificationChannel(nomeCanal);
                        canalPush.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(AtualizarUriCanal);
                        canalPush.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(CanalPush_ErrorOccurred);
                        canalPush.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                        canalPush.Open();
                        canalPush.BindToShellToast();
                    }
                    else
                    {
                        //Usuario não existe
                        canalPush = new HttpNotificationChannel(nomeCanal);
                        canalPush.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(CriarUriCanal);
                        canalPush.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(CanalPush_ErrorOccurred);
                        canalPush.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                        canalPush.Open();
                        canalPush.BindToShellToast();
                    }
                }
                else
                {
                    //Canal existe
                    if (await Modelo.Usuario.ConsultarPorNome(textBoxNomeUsuario.Text) != "")
                    {
                        //Usuario existe
                        canalPush.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(AtualizarUriCanal);
                        canalPush.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(CanalPush_ErrorOccurred);
                        canalPush.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                    }
                    else
                    {
                        //Usuario não existe
                        canalPush.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(CriarUriCanal);
                        canalPush.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(CanalPush_ErrorOccurred);
                        canalPush.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Olha o errro ai!");
            }
        }
        public async Task RegisterPushNotifications()
        {
            try {
                await TelegramSession.Instance.Established;

                var pushChannel = HttpNotificationChannel.Find(ChannelName);

                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>(HttpNotificationReceived);

                    pushChannel.Open();

                    // Bind this new channel for toast events.
                    pushChannel.BindToShellToast();

                    bool register = await
                                    TelegramSession.Instance.Api.account_registerDevice(3, pushChannel.ChannelUri.ToString(), DeviceStatus.DeviceName,
                                                                                        Environment.OSVersion.ToString(), AppVersion, true, "ru");

                    logger.debug("Registering GCM result {0}", register.ToString());
                }
                else
                {
                    bool register = await TelegramSession.Instance.Api.account_registerDevice(3, pushChannel.ChannelUri.ToString(), DeviceStatus.DeviceName,
                                                                                              Environment.OSVersion.ToString(), AppVersion, true, "ru");

                    logger.debug("Registering GCM result {0}", register.ToString());

                    // 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>(HttpNotificationReceived);

                    // 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());
                    logger.debug(String.Format("Channel Uri is {0}",
                                               pushChannel.ChannelUri.ToString()));
                }
            }
            catch (Exception ex) {
                logger.error("exception {0}", ex);
            }
        }
Exemple #42
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            //Create soap client for the GovBids service
            client = new AvailBidsSoapClient();

            //Connect the Get Bids Completed event (Async)
            client.GetBidsCompleted += client_GetBidsCompleted;

            var progressIndicator = new ProgressIndicator();

            SystemTray.SetProgressIndicator(this, progressIndicator);

            /// Holds the push channel that is created or found.
            HttpNotificationChannel pushChannel;

            // The name of our push channel.
            string channelName = "ToastUpdateChannel";

            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);

                // 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()));
            }
        }
        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();
            }
        }
Exemple #44
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            DataContext = App.ViewModel;

            // 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()));
            }


            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();

            httpClient = new HttpClient();

            // Add a user-agent header
            var headers = httpClient.DefaultRequestHeaders;

            // HttpProductInfoHeaderValueCollection is a collection of
            // HttpProductInfoHeaderValue items used for the user-agent header

            headers.UserAgent.ParseAdd("ie");
            headers.UserAgent.ParseAdd("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
        }
		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; 
			}
		}
 public void EnableToadNotification()
 {
     channel = HttpNotificationChannel.Find(Constants.Settings.WeeklyThaiRecipeChannelName);
     if (channel != null)
     {
         if (channel.IsShellToastBound)
         {
             channel.UnbindToShellToast();
         }
         channel.BindToShellToast();
     }
 }
        public async Task RegisterPushNotifications() {
            try {
                await TelegramSession.Instance.Established;

                var pushChannel = HttpNotificationChannel.Find(ChannelName);

                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>(HttpNotificationReceived);

                    pushChannel.Open();

                    // Bind this new channel for toast events.
                    pushChannel.BindToShellToast();
                    
                    bool register = await
    TelegramSession.Instance.Api.account_registerDevice(3, pushChannel.ChannelUri.ToString(), DeviceStatus.DeviceName,
        Environment.OSVersion.ToString(), AppVersion, true, "ru");
                    logger.debug("Registering GCM result {0}", register.ToString());
                } else {
                    bool register = await TelegramSession.Instance.Api.account_registerDevice(3, pushChannel.ChannelUri.ToString(), DeviceStatus.DeviceName,
    Environment.OSVersion.ToString(), AppVersion, true, "ru");
                    logger.debug("Registering GCM result {0}", register.ToString());

                    // 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>(HttpNotificationReceived);
                    
                    // 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());
                    logger.debug(String.Format("Channel Uri is {0}",
                        pushChannel.ChannelUri.ToString()));

                }

            }
            catch (Exception ex) {
                logger.error("exception {0}", ex);
            }
        }
Exemple #48
0
        private async Task AcquirePushChannel()
        {
            CurrentChannel = HttpNotificationChannel.Find("ApartmentPushChannel");
            if (CurrentChannel == null)
            {
                CurrentChannel = new HttpNotificationChannel("ApartmentPushChannel");
                CurrentChannel.Open();
                CurrentChannel.BindToShellToast();
            }

            Channel channel = new Channel { Uri = CurrentChannel.ChannelUri.ToString(), Type = "Windows Phone 8" };
            await App.MobileService.GetTable<Channel>().InsertAsync(channel);
        }
        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();
        }
Exemple #50
0
        // Конструктор
        public MainPage()
        {
            /// Holds the push channel that is created or found.
            HttpNotificationChannel pushChannel;

            // The name of our push channel.
            string channelName = "ToastSampleChannel";

            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);

                // 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());

            }
        }
Exemple #51
0
        private void AcquirePushChannel()
        {
            CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");


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


        }
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            HttpNotificationChannel pushChannel;
            pushChannel = HttpNotificationChannel.Find("RegistrationChannel");

            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel("RegistrationChannel");
                pushChannel.Open();
                pushChannel.BindToShellToast();
            }

            pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(pushChannel_ShellToastNotificationReceived);
        }
        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;
        }
        /// <summary>
        /// Asynchronously registers the device for native notifications.
        /// </summary>
        /// <param name="options"></param>
        public void registerApplication(string options)
        {
            try
            {
                var args = JsonHelper.Deserialize<List<string>>(options);

                var notificationHubPath = args[0];
                var connectionString = args[1];
                this.pushNotificationCallback = args[2];
                var tags = args[3];

                if (string.IsNullOrEmpty(notificationHubPath))
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "notificationHubPath can't be null or empty"));
                    return;
                }

                if (string.IsNullOrEmpty(connectionString))
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "connectionString can't be null or empty"));
                    return;
                }

                if (string.IsNullOrEmpty(pushNotificationCallback))
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "pushNotificationCallback can't be null or empty"));
                    return;
                }

                var channel = HttpNotificationChannel.Find(PluginChannelId);
                if (channel == null)
                {
                    channel = new HttpNotificationChannel(PluginChannelId);
                    channel.ChannelUriUpdated += (o, res) => CompleteApplicationRegistration(res.ChannelUri.ToString(), notificationHubPath, connectionString, tags);
                    channel.Open();
                    channel.BindToShellToast();
                }
                else
                {
                    CompleteApplicationRegistration(channel.ChannelUri.ToString(), notificationHubPath, connectionString, tags);
                }

                channel.ShellToastNotificationReceived += PushChannel_ShellToastNotificationReceived;
                
            }
            catch (Exception ex)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
            }
        }
        public async Task SubscribeToPushes(IEnumerable<string> deviceIds) 
        {
            try
            {
                var channel = HttpNotificationChannel.Find("MlpPushChannel");
                if (channel == null)
                {
                    channel = new HttpNotificationChannel("MlpPushChannel");
                    channel.Open();
                    channel.BindToShellToast();
                }
                channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;

                if (channel.ChannelUri != null)
                {
                    try
                    {
                        if (!(string.IsNullOrEmpty(App.LoginEmailId) || string.IsNullOrWhiteSpace(App.LoginEmailId)))
                        {
                            await this.Register(deviceIds, channel.ChannelUri.ToString());

                        }
                    }
                    catch (Exception)
                    {

                    }
                }
                channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
                {
                    try
                    {
                        await this.Register(deviceIds, args.ChannelUri.ToString());
                    }
                    catch (Exception)
                    {

                    }
                    
                });
            }            
            catch(Exception)
            {
               
            }           

           
        }
        public static void GetToastUri(Action<Uri> callback)
        {
            var channel = HttpNotificationChannel.Find(ChannelName);
            if (channel == null) {
                channel = new HttpNotificationChannel(ChannelName);

                channel.RegisterEvents(callback);

                channel.Open();
                channel.BindToShellToast();
            } else {
                channel.RegisterEvents(callback);
            }

            callback(channel.ChannelUri);
        }
        /// <summary>
        /// Register method
        /// </summary>
        /// <param name="options"></param>
        public void register(string options)
        {
            Options pushOptions;

            try
            {
                string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
                pushOptions = JSON.JsonHelper.Deserialize<Options>(args[0]);
                this.channelName = pushOptions.ChannelName;
                this.toastCallback = pushOptions.NotificationCallback;
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            pushChannel = HttpNotificationChannel.Find(channelName);
            if (pushChannel == null)
            {
                pushChannel = new HttpNotificationChannel(channelName);

                pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated;
                pushChannel.ErrorOccurred += PushChannel_ErrorOccurred;
                pushChannel.ShellToastNotificationReceived += PushChannel_ShellToastNotificationReceived;

                pushChannel.Open();
                pushChannel.BindToShellToast();
            }
            else
            {
                pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated;
                pushChannel.ErrorOccurred += PushChannel_ErrorOccurred;
                pushChannel.ShellToastNotificationReceived += PushChannel_ShellToastNotificationReceived;

                RegisterResult result = new RegisterResult();
                result.ChannelName = this.channelName;
                result.Uri = pushChannel.ChannelUri.ToString();
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result));
            }

            PhoneApplicationService service = PhoneApplicationService.Current;
            service.RunningInBackground += service_RunningInBackground;
            service.Activated += service_Activated;
            service.Deactivated += service_Deactivated;
        }
        public void RegisterForAzurePushNotification()
        {
            var channel = HttpNotificationChannel.Find("MyPushChannel");
            if (channel == null)
            {
                channel = new HttpNotificationChannel("MyPushChannel");
                channel.Open();
                channel.BindToShellToast();
            }

            channel.ChannelUriUpdated += async (o, args) =>
            {
                var hub = new NotificationHub(PushNotificationCredentials.AzureNotificationHubName, PushNotificationCredentials.AzureListenConnectionString);

                await hub.RegisterNativeAsync(args.ChannelUri.ToString(), PushNotificationCredentials.Tags);
            };
        }
 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();
 }
Exemple #60
0
 /// <summary>
 /// Constructor
 /// </summary>
 private CMClient()
 {
     HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(PushChannelName);
     if(pushChannel == null)
     {
         pushChannel = new HttpNotificationChannel(PushChannelName);
         pushChannel.ChannelUriUpdated += (sender, e) => Token = (e.ChannelUri.ToString());
         pushChannel.ShellToastNotificationReceived += ((sender,e) => HandleHttpNotification(e));
         pushChannel.Open();
         pushChannel.BindToShellToast();
     }
     else
     {
         Token = pushChannel.ChannelUri != null ? pushChannel.ChannelUri.ToString() : null;
         pushChannel.ChannelUriUpdated += (sender, e) => Token = (e.ChannelUri.ToString());
         pushChannel.ShellToastNotificationReceived += ((sender, e) => HandleHttpNotification(e));
     }
 }