예제 #1
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;
		}
예제 #2
0
        public void unregister(string options)
        {
            Options unregisterOptions;

            if (!TryDeserializeOptions(options, out unregisterOptions))
            {
                SendError(JSONError);
                return;
            }

            HttpNotificationChannel pushChannel = HttpNotificationChannel.Find(unregisterOptions.WP8.ChannelName);

            if (pushChannel != null)
            {
                pushChannel.UnbindToShellTile();
                pushChannel.UnbindToShellToast();
                pushChannel.Close();
                pushChannel.Dispose();

                SendEvent("Channel " + unregisterOptions.WP8.ChannelName + " is closed!");
            }
            else
            {
                SendError(MissingChannelError);
            }
        }
        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");
                });
        }
예제 #4
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
             });
         }
     }
 }
예제 #5
0
        public void RegisterTilePushChannel(string channelName = "TilePushChannel")
        {
            // Holds the push channel that is created or found.
            HttpNotificationChannel _tilePushChannel;

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

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

                // Register for all the events before attempting to open the channel.
                _tilePushChannel.ChannelUriUpdated += TileChannelUriUpdated;
                _tilePushChannel.ErrorOccurred += TileErrorOccurred;

                _tilePushChannel.Open();

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

            }
            else
            {
                // The channel was already open, so just register for all the events.
                _tilePushChannel.ChannelUriUpdated += TileChannelUriUpdated;
                _tilePushChannel.ErrorOccurred += TileErrorOccurred;

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

            }
        }
    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;
    }
예제 #7
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);
            }
        }
예제 #8
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)
     {
         //创建或恢复频道时发生异常
     }
 }
예제 #9
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());
            }
        }
예제 #10
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)
     {
         //创建或恢复频道时发生异常
     }
 }
예제 #11
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;
        }
        protected async override Task <string> ChannelUri()
        {
            HttpNotificationChannel channel;
            string channelName = "ToastChannel";

            channel = HttpNotificationChannel.Find(channelName);

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

            var tcs = new TaskCompletionSource <string>();

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

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

            channel.Open();
            channel.BindToShellToast();
            return(await tcs.Task);
        }
예제 #13
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();
     }
 }
예제 #14
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));
            }
        }
예제 #15
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());
                }
            }
        }
예제 #16
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);
            }
        }
예제 #17
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();
        }
예제 #18
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());
            }
        }
예제 #19
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
            {

            }
        }
예제 #20
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();
        }
예제 #21
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()));
            }

        }
예제 #22
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());
            }
        }
예제 #23
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;
                }
            }
        }
예제 #24
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));
            }
        }
예제 #25
0
        /// <summary>
        /// Unregisters device from specified groups, if <seealso cref="NetmeraDeviceDetail"/> groups are set; otherwise unregisters from broadcast group
        /// </summary>
        /// <param name="channelName">Channel name to be unregistered</param>
        /// <param name="deviceDetail"><seealso cref="NetmeraDeviceDetail"/> object keeping device details</param>
        /// <param name="callback">>Method to be called just after unregister</param>
        public static void unregister(String channelName, NetmeraDeviceDetail deviceDetail, Action <Exception> callback)
        {
            Channel_Name = channelName;
            if (deviceDetail != null)
            {
                Groups          = deviceDetail.getDeviceGroups();
                Device_Location = deviceDetail.getDeviceLocation();
            }

            Channel = HttpNotificationChannel.Find(Channel_Name);
            if (Channel != null)
            {
                UnregisterFromNotificationService(ex =>
                {
                    if (callback != null)
                    {
                        callback(ex);
                    }
                    //if (ex != null)
                    //    callback(ex);
                    //else
                    //    Channel.Close();
                });
            }
            else
            {
                if (callback != null)
                {
                    callback(new NetmeraException(NetmeraException.ErrorCode.EC_PUSH_DEVICE_NOT_REGISTERED, "Unregister failed since such a channel not found!"));
                }
            }
        }
예제 #26
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());
            }
        }
예제 #27
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 RegisterDevice(object state)
		{
			IsRegistering = true;

			HttpNotificationChannel pushChannel;
			pushChannel = HttpNotificationChannel.Find("RegistrationChannel");

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

			RegistrationRequest req = new RegistrationRequest()
			{
				ChannelUri = pushChannel.ChannelUri.ToString(),
				DeviceType = (short)Common.Data.DeviceType.WindowsPhone7
			};

			string json = null;

			using (MemoryStream ms = new MemoryStream())
			{
				DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RegistrationRequest));
				serializer.WriteObject(ms, req);
				json = Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length);
			}

			WebClient registrationClient = new WebClient();
			registrationClient.Headers["content-type"] = "application/json";
			registrationClient.UploadStringCompleted += registrationClient_UploadStringCompleted;
			string url = string.Format("http://{0}/Services/RegisterDevice", App.ServiceHostName);
			registrationClient.UploadStringAsync(new Uri(url), json);
		}
예제 #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
        private void Connect(Action actionIfNotFound)
        {
            try
            {
                _channel = HttpNotificationChannel.Find(_channelName);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            if (_channel != null)
            {
                if (_channel.ChannelUri != null)
                {
                    SubscribeToChannelEvents();
                    RegisterChannel(_channel.ChannelUri);
                    SubscribeToNotifications();
                }
                else
                {
                    _channel.UnbindToShellTile();
                    _channel.UnbindToShellToast();
                    _channel.Close();
                    RetryChannelConnect();
                }
            }
            else
            {
                actionIfNotFound();
            }
        }
예제 #31
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()));
            }
        }
예제 #32
0
 void SubscribePushChannelEvents(HttpNotificationChannel channel)
 {
     channel.ChannelUriUpdated += new EventHandler <NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
     channel.ErrorOccurred     += new EventHandler <NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
     channel.ShellToastNotificationReceived += new EventHandler <NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
     channel.HttpNotificationReceived       += new EventHandler <HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
 }
예제 #33
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)
            {
            }
        }
        protected async override Task<string> ChannelUri()
        {
            HttpNotificationChannel channel;
            string channelName = "ToastChannel";

            channel = HttpNotificationChannel.Find(channelName);

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

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

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

            channel.Open();
            channel.BindToShellToast();
            return await tcs.Task;
        }
예제 #35
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();
            }
        }
예제 #36
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());
            }
        }
        private static ZumoTest CreateUnregisterChannelTest(bool unRegisterTemplate = false, string templateName = null)
        {
            return(new ZumoTest("Unregister push channel", async delegate(ZumoTest test)
            {
                if (ZumoTestGlobals.Instance.IsNHPushEnabled)
                {
                    var client = ZumoTestGlobals.Instance.Client;
                    var push = client.GetPush();
                    if (unRegisterTemplate)
                    {
                        await push.UnregisterTemplateAsync(templateName);
                    }
                    else
                    {
                        await push.UnregisterNativeAsync();
                    }
                }

                if (ZumoWP8PushTests.pushChannel != null)
                {
                    ZumoWP8PushTests.pushChannel.HttpNotificationReceived -= pushChannel_HttpNotificationReceived;
                    ZumoWP8PushTests.pushChannel.ShellToastNotificationReceived -= pushChannel_ShellToastNotificationReceived;
                    ZumoWP8PushTests.pushChannel.UnbindToShellTile();
                    ZumoWP8PushTests.pushChannel.UnbindToShellToast();
                    test.AddLog("Unbound from shell tile/toast");
                    ZumoWP8PushTests.pushChannel.Close();
                    test.AddLog("Closed the push channel");
                    ZumoWP8PushTests.pushChannel = null;
                }

                TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
                tcs.SetResult(true);
                return await tcs.Task;
            }, unRegisterTemplate ? ZumoTestGlobals.RuntimeFeatureNames.NH_PUSH_ENABLED : null));
        }
        /// <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());
            }
        }
예제 #39
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();
            }
        }
예제 #40
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);
        }
예제 #41
0
        public void register(string options)
        {
            try
            {
                var args = JSON.JsonHelper.Deserialize<string[]>(options);
                var pushOptions = JSON.JsonHelper.Deserialize<Options>(args[0]);
                this.channelName = pushOptions.ChannelName;
                this.toastCallback = pushOptions.NotificationCallback;
            }
            catch (Exception)
            {
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            this.pushChannel = HttpNotificationChannel.Find(this.channelName);
            if (this.pushChannel == null)
            {
                this.pushChannel = new HttpNotificationChannel(this.channelName);
                this.PushChannel_HookEvents();
                this.pushChannel.Open();
                this.pushChannel.BindToShellToast();
                this.pushChannel.BindToShellTile();
            }
            else
            {
                this.PushChannel_HookEvents();

                var result = new RegisterResult();
                result.ChannelName = this.channelName;
                result.Uri = this.pushChannel.ChannelUri.ToString();
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result));
            }
        }
예제 #42
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();
            }
        }
예제 #43
0
        private void LoadOrCreateChannelAsync(Action callback = null)
        {
            Execute.BeginOnThreadPool(async() =>
            {
                try
                {
                    var pushChannel = HttpNotificationChannel.Find(Constants.ToastNotificationChannelName);

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

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

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

                callback.SafeInvoke();
            });
        }
예제 #44
0
        public static void DisableNotification()
        {
            _channel = null;
            var ns = new NotificationServiceClient();

            ns.UnregisterEndpointAsync(_username);
        }
예제 #45
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);
        }
예제 #46
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;
                }
            }
        }
예제 #47
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());
        }
        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);
            }
        }
예제 #50
0
 private void RegisterNewChannel()
 {
     _channel = new HttpNotificationChannel(_channelName, _serviceName);
     SubscribeToChannelEvents();
     _channel.Open();
     SubscribeToNotifications();
 }
예제 #51
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;
        }
        /// <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();
            }
        }
예제 #53
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()));
            }
        }
예제 #54
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();
            }
        }
 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;
 }
        // 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 IHttpNotificationChannel GetNotificationChannel(string channelName)
 {
     var channel = HttpNotificationChannel.Find(channelName);
     if (channel == null)
     {
         channel = new HttpNotificationChannel(channelName);
     }
     return new HttpNotificationChannelAdapter(channel);
 }
예제 #58
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();
            }
        }
예제 #60
0
 public RegistrationDecorator( HttpNotificationChannel channel, string registrationId,
                               DateTime registrationExpiration )
 {
   _registrationInfo = new RegistrationInfo
     {
       Channel = channel,
       RegistrationId = registrationId,
       RegistrationExpiration = registrationExpiration
     };
 }