예제 #1
0
        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();
        }
예제 #2
0
        public async Task <UserAccountEntity> LoginTest(UserAccountEntity userAccountEntity)
        {
            var authManager = new AuthenticationManager();

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

            if (user == null)
            {
                return(null);
            }
            userAccountEntity.SetUserEntity(user);
            return(userAccountEntity);
        }
        private async Task Update(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                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;
                    }

                    // Debug
                    //NotifyStatusTile.CreateNotificationLiveTile(notificationEntity.Notifications.First());
                    //NotifyStatusTile.CreateToastNotification(notificationEntity.Notifications.First());

                    var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false);
                    foreach (var notification in notificationList)
                    {
                        NotifyStatusTile.CreateNotificationLiveTile(notification);
                        NotifyStatusTile.CreateToastNotification(notification);
                        await NotificationManager.ClearNotification(notification, userAccountEntity);
                    }
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("Failed to show toast/live tile notification");
            }
        }