protected override void Update() { INewsCollector newsCollector = ServiceRegistration.Get <INewsCollector>(false); if (newsCollector != null) { NewsItem newNewsItem = newsCollector.GetRandomNewsItem(); if (newNewsItem != null) { newNewsItem.CopyTo(CurrentNewsItem); // Decrease interval once we have the first item ChangeInterval(NEWSITEM_UPDATE_INTERVAL); } } }
public void Refresh() { INewsCollector newsCollector = ServiceRegistration.Get <INewsCollector>(false); if (newsCollector != null) { NewsItem newNewsItem = newsCollector.GetRandomNewsItem(); if (newNewsItem != null) { newNewsItem.CopyTo(CurrentNewsItem); var feeds = newsCollector.GetAllFeeds().OrderByDescending(f => f.LastUpdated); //Only update if changed if (!feeds.Select(f => f.LastUpdated).SequenceEqual(_currentFeedItems.Select(f => (f as NewsFeed)?.LastUpdated ?? DateTime.Now))) { _currentFeedItems.Clear(); foreach (var feed in feeds) { feed.Command = new AsyncMethodDelegateCommand(() => ShowNews(feed)); _currentFeedItems.Add(feed); } _currentFeedItems.FireChange(); } var items = newsCollector.GetAllNewsItems().OrderByDescending(i => i.PublishDate); //Only update if changed if (!items.Select(i => i.PublishDate).SequenceEqual(_currentNewsItems.Select(i => (i as NewsItem)?.PublishDate ?? DateTime.Now))) { _currentNewsItems.Clear(); _currentTopNewsItems.Clear(); foreach (var newsItem in items) { newsItem.Command = new AsyncMethodDelegateCommand(() => ShowNews(newsItem)); _currentNewsItems.Add(newsItem); if (_currentTopNewsItems.Count < NEWSITEM_TOP_COUNT) { _currentTopNewsItems.Add(newsItem); } } _currentNewsItems.FireChange(); _currentTopNewsItems.FireChange(); } } } }