public static void CreateToastNotification(NotificationEntity.Notification notification)
        {
            XmlDocument notificationXml =
                ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText01);
            XmlNodeList toastElements = notificationXml.GetElementsByTagName("text");

            toastElements[0].AppendChild(
                notificationXml.CreateTextNode(notification.Message));
            XmlNodeList imageElement = notificationXml.GetElementsByTagName("image");
            string      imageName    = string.Empty;

            if (string.IsNullOrEmpty(imageName))
            {
                imageName = @"Assets/Logo.scale-100.png";
            }
            imageElement[0].Attributes[1].NodeValue = imageName;
            IXmlNode toastNode  = notificationXml.SelectSingleNode("/toast");
            string   test       = "{" + string.Format("type:'toast'") + "}";
            var      xmlElement = (XmlElement)toastNode;

            if (xmlElement != null)
            {
                xmlElement.SetAttribute("launch", test);
            }
            var toastNotification = new ToastNotification(notificationXml);

            ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
        }
Exemple #2
0
        public static async Task <bool> ClearNotification(NotificationEntity.Notification notification,
                                                          UserAccountEntity userAccountEntity)
        {
            try
            {
                var authenticationManager = new AuthenticationManager();
                var user = userAccountEntity.GetUserEntity();
                if (userAccountEntity.GetAccessToken().Equals("refresh"))
                {
                    await authenticationManager.RefreshAccessToken(userAccountEntity);
                }
                string url           = string.Format("https://{0}-ntl.np.community.playstation.net/notificationList/v1/users/{1}/notifications/{2}/{3}", user.Region, user.OnlineId, notification.NotificationGroup, notification.NotificationId);
                var    theAuthClient = new HttpClient();
                var    request       = new HttpRequestMessage(HttpMethod.Put, url)
                {
                    Content = new StringContent("{\"seenFlag\":true}", Encoding.UTF8, "application/json")
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
                request.Headers.CacheControl  = new CacheControlHeaderValue {
                    NoCache = true
                };
                HttpResponseMessage response = await theAuthClient.SendAsync(request);

                return(response.IsSuccessStatusCode);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public static void CreateNotificationLiveTile(NotificationEntity.Notification notification)
        {
            XmlDocument tileXml        = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text03);
            XmlNodeList tileAttributes = tileXml.GetElementsByTagName("text");

            tileAttributes[0].AppendChild(tileXml.CreateTextNode(notification.Message));
            var tileNotification = new TileNotification(tileXml);

            TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
        }
        protected async override void OnInvoke(Microsoft.Phone.Scheduler.ScheduledTask task)
        {
            var  userAccountEntity = new UserAccountEntity();
            var  authManager       = new AuthenticationManager();
            bool loginTest         = await authManager.RefreshAccessToken(userAccountEntity);

            if (loginTest)
            {
                UserAccountEntity.User user = await authManager.GetUserEntity(userAccountEntity);

                if (user == null)
                {
                    return;
                }
                userAccountEntity.SetUserEntity(user);
                NotificationEntity notificationEntity = await GetNotifications(userAccountEntity);

                if (notificationEntity == null)
                {
                    return;
                }
                if (notificationEntity.Notifications == null)
                {
                    return;
                }
                var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false);
                NotificationEntity.Notification firstNotification = notificationList.FirstOrDefault();
                ShellTile appTile = ShellTile.ActiveTiles.First();
                if (firstNotification != null)
                {
                    var toastMessage = firstNotification.Message;
                    var toast        = new ShellToast {
                        Title = "FoulPlay", Content = toastMessage
                    };
                    toast.Show();
                    if (appTile != null)
                    {
                        var tileData = new FlipTileData
                        {
                            Title           = "FoulPlay",
                            BackTitle       = "FoulPlay",
                            BackContent     = firstNotification.Message,
                            WideBackContent = firstNotification.Message,
                            Count           = notificationList.Count()
                        };
                        appTile.Update(tileData);
                    }
                    await NotificationManager.ClearNotification(firstNotification, userAccountEntity);
                }
            }
#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif
            NotifyComplete();
        }
Exemple #5
0
        public async Task <bool> ClearNotification(NotificationEntity.Notification notification,
                                                   UserAccountEntity userAccountEntity)
        {
            try
            {
                var user   = userAccountEntity.GetUserEntity();
                var url    = string.Format(EndPoints.ClearNotification, user.Region, user.OnlineId, notification.NotificationGroup, notification.NotificationId);
                var json   = new StringContent("{\"seenFlag\":true}", Encoding.UTF8, "application/json");
                var result = await _webManager.PostData(new Uri(url), null, json, userAccountEntity);

                return(result.IsSuccess);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to clear notification", ex);
            }
        }