Esempio n. 1
0
        private async Task <ObservableCollection <EntitiesBase.YouTubeVideo> > LoadData(int pageNumber, bool forceRecaching = false)
        {
            var storedItems      = _storageService.Load <ObservableCollection <EntitiesBase.YouTubeVideo> >("Videos_s5");
            var storedCollection = storedItems != null?storedItems.ToList() : new List <EntitiesBase.YouTubeVideo>();

            var pageNotSaved = Math.Ceiling(storedCollection.Count() / (double)MaxResults) - 1 < pageNumber;

            if (_internetService.IsNetworkAvailable() && (pageNotSaved || forceRecaching))
            {
                var newItems = await _youtubeDataSource.LoadRemote <IEnumerable <EntitiesBase.YouTubeVideo> >(String.Format(YoutubeBaseUrl + YoutubePaginationParameters, HttpUtility.UrlEncode(YoutubeQuery), pageNumber *MaxResults + 1, MaxResults));

                if (forceRecaching)
                {
                    storedCollection = new List <EntitiesBase.YouTubeVideo>();
                }

                if (newItems != null && newItems.Any())
                {
                    storedCollection.AddRange(newItems);
                    _storageService.Save("Videos_s5", new ObservableCollection <EntitiesBase.YouTubeVideo>(storedCollection));
                }
            }

            return(new ObservableCollection <EntitiesBase.YouTubeVideo>(storedCollection.Skip(pageNumber * MaxResults).Take(MaxResults)));
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the data from a RSS data source (http://www.dandandin.it/Blog/RSS.aspx?p=1~2~-1&r=f3a58073-d9c8-496e-af7b-f4ee2ae8dd40), in an observable collection of RssSearchResult items.
        /// </summary>
        /// <returns>An observable collection of RssSearchResult items.</returns>
        public async Task <ObservableCollection <EntitiesBase.RssSearchResult> > Refresh()
        {
            SyndicationFeed feed;

            if (_internetService.IsNetworkAvailable())
            {
                feed = await _xmlDataSource.LoadRemote <System.ServiceModel.Syndication.SyndicationFeed>(RssUrl);

                var defaultImage = feed.ImageUrl != null ? feed.ImageUrl.AbsoluteUri : null;
                var items        = feed != null ? new ObservableCollection <EntitiesBase.RssSearchResult>(feed.Items.Select(i => new EntitiesBase.RssSearchResult(i, defaultImage))) : new ObservableCollection <EntitiesBase.RssSearchResult>();
                _storageService.Save("Web_RSS", items);

                return(items);
            }

            return(_storageService.Load <ObservableCollection <EntitiesBase.RssSearchResult> >("Web_RSS"));
        }