예제 #1
0
        private async Task CreateNotificationTiles(DateTime lastRefreshTime)
        {
            var notifications = await _client.GetNotifications();

            var newNotifications = notifications.Where(node => node.CreatedAt > lastRefreshTime);

            foreach (var notification in newNotifications)
            {
                NotifyStatusTile.CreateNotificationLiveTile(notification);
            }
        }
        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");
            }
        }