Exemple #1
0
        private void sendTile()
        {
            string     weatherType = cmbWeather.SelectedValue as string;
            int        temperature = (int)(sld.Value + 0.5);
            string     location    = cmbLocation.SelectedValue as string;
            List <Uri> subscribers = RegistrationService.GetSubscribers();

            tilePushNotificationMessage.BackgroundImageUri = new Uri("/Images/" + weatherType + ".png", UriKind.Relative);
            tilePushNotificationMessage.Count         = temperature;
            tilePushNotificationMessage.Title         = location;
            tilePushNotificationMessage.SecondaryTile = MakeTileUri(location).ToString();

            subscribers.ForEach(uri => tilePushNotificationMessage.SendAsync(uri,
                                                                             (result) => OnMessageSent(NotificationType.Token, result),
                                                                             (result) => { }));
        }
Exemple #2
0
        private void OnRawSent(string userName, MessageSendResult result)
        {
            // In case that the device is disconnected, no need to send a tile message.
            if (result.DeviceConnectionStatus == DeviceConnectionStatus.TempDisconnected)
            {
                return;
            }

            // Checking these three flags we can know what's the state of both the device and apllication.
            bool isApplicationRunning =
                result.SubscriptionStatus == SubscriptionStatus.Active &&
                result.NotificationStatus == NotificationStatus.Received &&
                result.DeviceConnectionStatus == DeviceConnectionStatus.Connected;

            // In case that the application is not running, send a tile update with counter increase.
            if (!isApplicationRunning)
            {
                var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High)
                {
                    Count = IncreaseCounter(userName),
                    BackgroundImageUri = BackgroundImageUri,
                    Title = Title
                };

                tileMsg.SendAsync(result.ChannelUri, Log, Log);
            }
        }
        public void SendLiveTile(string uri, string backgroundImageUrl, string title, int count)
        {
            if (count > 99 || !SendRealMessages)
            {//counter for live tile must be 1-99 number (http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/01/14/windows-push-notification-server-side-helper-library.aspx)
                return;
            }
            var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High)
            {
                Count = count,
                Title = title
            };

            tileMsg.SendAsync(new Uri(uri), delegate(MessageSendResult res)
            {
                Log.WriteInfo("DeviceConnectionStatus:" + res.DeviceConnectionStatus);
                Log.WriteInfo("StatusCode:" + res.StatusCode);
                Log.WriteInfo("NotificationStatus:" + res.NotificationStatus);
                Log.WriteInfo("SubscriptionStatus:" + res.SubscriptionStatus);
            },
                              delegate(MessageSendResult res)
            {
                Log.WriteInfo("DeviceConnectionStatus:" + res.DeviceConnectionStatus);
                Log.WriteInfo("StatusCode:" + res.StatusCode);
                Log.WriteInfo("NotificationStatus:" + res.NotificationStatus);
                Log.WriteInfo("SubscriptionStatus:" + res.SubscriptionStatus);
            });
        }
Exemple #4
0
        private void PushService_TileUpdateRequest(object sender, TileUpdateRequestEventArgs e)
        {
            // Send a tile notification message to the relevant device.
            var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High)
            {
                BackgroundImageUri = new Uri(string.Format(ImageService.GetTileImageService, e.Parameter))
            };

            tileMsg.SendAsync(e.ChannelUri, Log, Log);
        }
Exemple #5
0
        /// <summary>
        /// On subscription change, reset the subscriber tile counter if exist.
        /// </summary>
        protected override void OnSubscribed(SubscriptionEventArgs e)
        {
            // Create a tile message to reset tile count.
            var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High)
            {
                Count = 0,
                BackgroundImageUri = BackgroundImageUri,
                Title = Title
            };

            tileMsg.SendAsync(e.Subscription.ChannelUri, Log, Log);

            ResetCounter(e.Subscription.UserName);
        }
        protected override void OnSend()
        {
            // Starts by sending a tile notification to all relvant subscribers.
            // This tile notification updates the tile with custom image.
            var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High)
            {
                Count = Count,
                Title = Title
            };

            foreach (var subscriber in PushService.Subscribers)
            {
                // Set the tile background image uri with the address of the ImageService.GetTileImage,
                // REST service, using current subscriber channel uri as a parameter to bo sent to the service.
                tileMsg.BackgroundImageUri = new Uri(string.Format(ImageService.GetTileImageService, string.Empty));
                tileMsg.SendAsync(subscriber.ChannelUri, Log, Log);
            }
        }