예제 #1
0
        /// <summary>
        /// Creates (or re-opens) the push channel, and subscribes to push notification events.
        /// </summary>
        private void CreateNotificationChannel()
        {
            //Try to find an existing channel.
            console.AddLine("Looking for notification channel");

            httpChannel = HttpNotificationChannel.Find(channelName);

            // If no existing channel is found, create a new one.  The device's URI will be in the
            // event args of the HttpNotificationChannel.ChannelUriUpdated event.
            if (null == httpChannel)
            {
                console.AddLine("Creating new channel");

                httpChannel = new HttpNotificationChannel(channelName, serviceName);
                httpChannel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
                httpChannel.Open();
            }
            else
            {
                console.AddLine("Got existing channel Uri:\n" + httpChannel.ChannelUri.ToString());
            }

            console.AddLine("Subscribing to channel events.");

            // Add an event handler for raw push messages.
            httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(httpChannel_HttpNotificationReceived);

            // Add an event handler for toast push messages.
            httpChannel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);

            // Tile notifications cannot be handled in-game.

            // Add an event handler for channel errors.
            httpChannel.ErrorOccurred += new EventHandler <NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred);
        }
예제 #2
0
	    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;
		}
예제 #3
0
        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()));
            }
        }
        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");
                });
        }
예제 #5
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();
            }
        }
        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);
            }
        }
        /// <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();
            }
        }
예제 #8
0
        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());
                }
            }
        }
예제 #9
0
파일: Manager.cs 프로젝트: SamirHafez/Bantu
        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());
            }
        }
예제 #10
0
        public void SwitchOn()
        {
            _channel = HttpNotificationChannel.Find(CHANNEL_NAME);
            if (_channel == null)
            {
                _channel = new HttpNotificationChannel(CHANNEL_NAME);
                _channel.Open();

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

                _Register(channelUri);
            }

            _channel.ShellToastNotificationReceived += _ChannelToastNotificationReceived;
            _channel.HttpNotificationReceived       += _ChannelNotificationReceived;
            _channel.ChannelUriUpdated += _ChannelUriUpdated;
            _channel.ErrorOccurred     += _ChannelErrorOccurred;
        }
예제 #11
0
        private void InitPushChannel()
        {
            // Try to find the push channel.
            HttpNotificationChannel httpChannel = HttpNotificationChannel.Find(App.pushChannelName);

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

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

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

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

            // Register for all the events.
            httpChannel.ChannelUriUpdated        += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            httpChannel.ErrorOccurred            += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
            httpChannel.HttpNotificationReceived += new EventHandler <HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
        }
예제 #12
0
        public async Task AcquirePushChannelAsync(string stationId)
        {
            if (null != _pushChannel) return;

            try
            {
                _pushChannel = HttpNotificationChannel.Find(PushChannelName);

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

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

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

                    await channelTable.InsertAsync(channel);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #13
0
        // LIVE TILE CODE ADDED HERE !!!!!!!!------------------------!!!!!!!!!!!!!!!!

        private void CreatePushChannel()
        {
            // 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.
   // hereeee uncommnt      //       System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
                //MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
            }
        }
예제 #14
0
        public EntryPage()
        {
            InitializeComponent();
            StandardTileData sd = new StandardTileData
            {
                Title = "Property Viewer",
                BackgroundImage = new Uri("Background.png", UriKind.Relative),
                Count = 0
            };

            ShellTile st = ShellTile.ActiveTiles.ElementAt(0);
            st.Update(sd);
            client = new ImageServiceClient();

            string channelName = "ChannelName";
            httpChannel = HttpNotificationChannel.Find(channelName);
            if (httpChannel != null)
            {
                channelUri = httpChannel.ChannelUri;
                client.SetUrlAsync(channelUri);
            }
            else
            {
                httpChannel = new HttpNotificationChannel(channelName);
                httpChannel.ErrorOccurred += OnErrorOccurred;
                httpChannel.Open();
                channelUri = httpChannel.ChannelUri;

            }
            httpChannel.ChannelUriUpdated += OnChannelUriUpdated;
            client.resetCompleted += OnResetCompleted;
        }
예제 #15
0
 private void DoConnect()
 {
     try
     {
         //首先查看现有的频道
         httpChannel = HttpNotificationChannel.Find(channelName);
         //如果频道存在
         if (httpChannel != null)
         {
             //注册Microsoft推送通知事件
             SubscribeToChannelEvents();
             //检测Microsoft通知服务注册状态
             SubscribeToService();
             //订阅Toast和Title通知
             SubscribeToNotifications();
         }
         else
         {
             //试图创建一个新的频道
             //创建频道
             httpChannel = new HttpNotificationChannel(channelName, "PuzzleService");
             //推送通知频道创建成功
             SubscribeToChannelEvents();
             //注册Microsoft推送通知事件
             httpChannel.Open();
         }
     }
     catch (Exception ex)
     {
         //创建或恢复频道时发生异常
     }
 }
예제 #16
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);
        }
예제 #18
0
        void getSubscription()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains("DeviceId"))
            {
                deviceID = (Guid)IsolatedStorageSettings.ApplicationSettings["DeviceId"];
            }
            else
            {
                deviceID = Guid.NewGuid();
                IsolatedStorageSettings.ApplicationSettings["DeviceId"] = deviceID;
            }
            pushChannel = HttpNotificationChannel.Find("myChannel");

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

                pushClient.SubscribeMyPhoneAsync(deviceID, pushChannel.ChannelUri.ToString());
            }
        }
예제 #19
0
        // Constructor
        public MainPage()
        {
            // the push channel that is created or used
            // rawdata is the name of the push channel
            var pushNotification = HttpNotificationChannel.Find("rawdata");

            InitializeComponent();

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

                // register the events

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

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

            // get the location data
            GetLocation();

            Forms.Init();
            LoadApplication(new GPSPush.App());
        }
예제 #20
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();
            }
        }
예제 #21
0
 private void RegisterNewChannel()
 {
     _channel = new HttpNotificationChannel(_channelName, _serviceName);
     SubscribeToChannelEvents();
     _channel.Open();
     SubscribeToNotifications();
 }
예제 #22
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);
            }
        }
        /// <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());
            }
        }
예제 #24
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");
            });
        }
예제 #25
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();
            }
        }
예제 #26
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)
     {
     }
 }
예제 #27
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);
            }
        }
예제 #28
0
        private void DoConnect()
        {
            try
            {

                httpChannel = HttpNotificationChannel.Find(channelName);

                if (null != httpChannel)
                {

                    SubscribeToChannelEvents();

                    SubscribeToService();

                    SubscribeToNotifications();

                    Dispatcher.BeginInvoke(() => UpdateStatus("Channel recovered"));
                }
                else
                {

                    httpChannel = new HttpNotificationChannel(channelName, "HOLWeatherService");

                    SubscribeToChannelEvents();

                    httpChannel.Open();
                    Dispatcher.BeginInvoke(() => UpdateStatus("Channel open requested"));
                }
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() => UpdateStatus("Channel error: " + ex.Message));
            }
        }
예제 #29
0
        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());
            }
        }
예제 #30
0
        public void SetupNotificationChannel()
        {
            if (!InternetIsAvailable()) return;
            channel = HttpNotificationChannel.Find(channelName);

            if (channel == null)
            {
                channel = new HttpNotificationChannel(channelName);
                HookupHandlers();
                channel.Open();
            }
            else
            {
                HookupHandlers();
                try
                {
                    channelUri = channel.ChannelUri.ToString();
                    apiMethodRequest.SendRequest(VkApi.Authorization.AccessToken, "account.registerDevice", new Dictionary<string, string>() { { "token", channelUri } });
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
예제 #31
0
        private void DoConnect()
        {
            try
            {
                //First, try to pick up existing channel
                httpChannel = HttpNotificationChannel.Find(Constant.CHANNELNAME);

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

                    SubscribeToService();
                    SubscribeToNotifications();
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #32
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);
        }
예제 #33
0
        private void SetupChannel()
        {
            string channelName = "Demo notification channel";

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

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

                notificationChannel.Open();
                BindToShell();
            }
        }
예제 #34
0
        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());
                }
            }
        }
예제 #35
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);
        }
예제 #36
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);
        }
예제 #37
0
 /// <summary>
 /// Initialize the notification channel used to receive data from the game server.
 /// </summary>
 /// <param name="channelName">The name the application uses to identify the notification channel
 /// instance used to communicate with the game server.</param>
 /// <param name="serviceName">The name that the game's server uses to associate itself with the Push
 /// Notification Service.</param>
 private void InitializePushNotification(string channelName, string serviceName)
 {
     try
     {
         // Look for an already existing channel
         channel = HttpNotificationChannel.Find(channelName);
         if (channel == null)
         {
             // Create a new channel and open it
             channel = new HttpNotificationChannel(channelName, serviceName);
             channel.ChannelUriUpdated        += channel_ChannelUriUpdated;
             channel.HttpNotificationReceived += channel_HttpNotificationReceived;
             channel.Open();
         }
         else
         {
             // Register the client using the existing channel
             channel.ChannelUriUpdated        += channel_ChannelUriUpdated;
             channel.HttpNotificationReceived += channel_HttpNotificationReceived;
             RegisterForPushNotifications();
         }
     }
     catch (Exception e)
     {
         if (ServiceError != null)
         {
             ServiceError(this, new ExceptionEventArgs()
             {
                 Error = e
             });
         }
     }
 }
        /// <summary>
        /// Creates push channel and regestrite it at pushwoosh server
        /// <param name="serviceName">
        /// The name that the web service uses to associate itself with the Push Notification Service.
        /// </param>
        /// </summary>
        public void SubscribeToPushService(string serviceName)
        {
            //First, try to pick up existing channel
            _notificationChannel = HttpNotificationChannel.Find(Constants.ChannelName);

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

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

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

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

                SubscribeToChannelEvents();

                Debug.WriteLine("Trying to open the channel");
                _notificationChannel.Open();
            }
            if (_notificationChannel.ChannelUri != null)
            {
                PushToken = _notificationChannel.ChannelUri.ToString();
            }
        }
 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;
 }
예제 #40
0
        // 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()));
            }

        }
예제 #41
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());
            }
        }
예제 #42
0
        public void Init()
        {
            try
            {
                //First, try to pick up existing channel
                httpChannel = HttpNotificationChannel.Find(channelName);

                if (null != httpChannel)
                {
                    SubscribeToChannelEvents();

                    SubscribeToService();

                    SubscribeToNotifications();
                }
                else
                {
                    httpChannel = new HttpNotificationChannel(channelName, "BlandCAPITAL.Shared.FinanceService");

                    SubscribeToChannelEvents();

                    httpChannel.Open();
                }
            }
            catch
            {

            }
        }
예제 #43
0
 private void DoConnect()
 {
     try
     {
         //首先查看现有的频道
         httpChannel = HttpNotificationChannel.Find(channelName);
         //如果频道存在
         if (httpChannel != null)
         {
             //注册Microsoft推送通知事件
             SubscribeToChannelEvents();
             //检测Microsoft通知服务注册状态
             SubscribeToService();
             //订阅Toast和Title通知
             SubscribeToNotifications();
         }
         else
         {
             //试图创建一个新的频道
             //创建频道
             httpChannel = new HttpNotificationChannel(channelName, "PuzzleService");
             //推送通知频道创建成功
             SubscribeToChannelEvents();
             //注册Microsoft推送通知事件
             httpChannel.Open();
         }
     }
     catch (Exception ex)
     {
         //创建或恢复频道时发生异常
     }
 }
예제 #44
0
 public void Connect()
 {
     try
     {
         const string channelName = "ZabbkitNotifications";
         _httpChannel = HttpNotificationChannel.Find(channelName);
         if (null == _httpChannel)
         {
             _httpChannel = new HttpNotificationChannel(channelName);
             SubscribeToChannelEvents();
             _httpChannel.Open();
             SubscribeToNotifications();
         }
         else
         {
             SubscribeToChannelEvents();
             SubscribeToManagementServiceAsync();
         }
     }
     catch (Exception ex)
     {
         //_errorHandler.WriteReport(string.Format("Channel error: {0}",ex.Message));
         OnError();
     }
 }
예제 #45
0
        public void Connect()
        {
            try
            {
                httpChannel = HttpNotificationChannel.Find(channelName);

                if (null != httpChannel)
                {
                    SubscribeToChannelEvents();
                    SubscribeToNotifications();
                    Deployment.Current.Dispatcher.BeginInvoke(() => this.UpdateStatus("Channel recovered"));
                }
                else
                {
                    httpChannel = new HttpNotificationChannel(channelName, "GeoScavChannel");
                    SubscribeToChannelEvents();
                    httpChannel.Open();
                    Deployment.Current.Dispatcher.BeginInvoke(() => this.UpdateStatus("Channel open requested"));
                }
            }
            catch (Exception ex)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => UpdateStatus("Channel error: " + ex.Message));
            }
        }
예제 #46
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();
        }
예제 #47
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());
            }
        }
예제 #48
0
        private void open_Click(object sender, RoutedEventArgs e)
        {
            var channel = HttpNotificationChannel.Find("TestChannel");

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

                channel = new HttpNotificationChannel("TestChannel");
                channel.ChannelUriUpdated += channel_ChannelUriUpdated;
                channel.ErrorOccurred += channel_ErrorOccurred;
                channel.Open();
            }
            else
            {
                channel.ErrorOccurred += channel_ErrorOccurred;
                Debug.WriteLine(channel.ChannelUri.AbsoluteUri);
            }

            channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;

            if(!channel.IsShellToastBound) channel.BindToShellToast();
        }
예제 #49
0
        public void SetupNotificationChannel()
        {
            if (!InternetIsAvailable()) return;
            channel = HttpNotificationChannel.Find(channelName);

            if (channel == null)
            {
                channel = new HttpNotificationChannel(channelName);
                HookupHandlers();
                channel.Open();
            }
            else
            {
                HookupHandlers();
                try
                {
                    pushClient.RegisterPhoneAsync(WP7App1.Bootstrapper.phoneId, channel.ChannelUri.ToString(), username);
                }
                catch (Exception ex)
                {

                    throw ex;
                }
            }
        }
예제 #50
0
        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.

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

        }
예제 #52
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();
            }
        }
예제 #54
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; 
			}
		}
예제 #55
0
 public static HttpNotificationChannel GetNotificationChannel(string channelName)
 {
     var currentChannel = HttpNotificationChannel.Find(channelName);
     if (currentChannel == null)
     {
         currentChannel = new HttpNotificationChannel(channelName);
         currentChannel.Open();     
         //currentChannel.BindToShellTile();
         //currentChannel.BindToShellToast();
     }
     return currentChannel;
 }
예제 #56
0
        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);
            }
        }
 private Task<string> GetPushUri()
 {
     var taskSource = new TaskCompletionSource<string>();
     var httpChannel = HttpNotificationChannel.Find(AppPushChannel);
     if (httpChannel == null)
     {
         httpChannel = new HttpNotificationChannel(AppPushChannel);
         httpChannel.Open();
     }
     httpChannel.ChannelUriUpdated += (s, e) => taskSource.TrySetResult(e.ChannelUri.ToString());
     httpChannel.ErrorOccurred += (s, e) => taskSource.TrySetResult(string.Empty);
     return taskSource.Task;
 }
예제 #58
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);
        }
예제 #59
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());

            }
        }
예제 #60
0
        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();
        }