private async Task Filter()
        {
            TokenSource.Cancel();

            var query = from feed in await RSSDataService.GetFeedsDataAsync(0) select feed;

            if (FilterSelectedSource != null)
            {
                query = query.Where(x => x.PostSource.Id == FilterSelectedSource.Id);
            }
            if (!string.IsNullOrWhiteSpace(FilterTitle))
            {
                query = query.Where(x => x.PostTitle.ToLower().Contains(FilterTitle.ToLower()));
            }
            if (!string.IsNullOrWhiteSpace(FilterCreator))
            {
                query = query.Where(x => x.Authors.Any(x => x.Email.ToLower() == FilterCreator.ToLower()));
            }
            if (FilterIsUnreadOnly)
            {
                query = query.Where(x => x.IsRead == false);
            }

            Feeds.Clear();
            foreach (var item in query)
            {
                Feeds.Add(item);
            }
        }
Esempio n. 2
0
        public void EnterModelContext(NavigationContext oldContext, NavigationContext newContext)
        {
            // Load settings
            NewsSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <NewsSettings>();

            HasChanges      = false;
            NewFeedBookmark = new FeedBookmarkItem();
            Feeds.Clear();
            lock (settings.FeedsList)
            {
                if (settings.FeedsList.Count == 0)
                {
                    foreach (var feed in NewsSettings.GetDefaultRegionalFeeds())
                    {
                        Feeds.Add(new FeedBookmarkItem {
                            Name = feed.Name, Url = feed.Url
                        });
                    }
                }
                else
                {
                    foreach (var feed in settings.FeedsList)
                    {
                        Feeds.Add(new FeedBookmarkItem {
                            Name = feed.Name, Url = feed.Url
                        });
                    }
                }
            }
        }
Esempio n. 3
0
        public async Task LoadFeedsAsync()
        {
            IsLoading = true;

            Feeds.Clear();
            var results = await _feedService.GetFeeds();

            foreach (var feedDto in results)
            {
                Feed feed = AutoMapper.Mapper.Map <Feed>(feedDto);
                Feeds.Add(feed);
            }

            IsLoading = false;
        }
Esempio n. 4
0
        private async void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            searchingProgressRing.IsActive = true;
            Feeds.Clear();
            List <Uri> feedUrls = new List <Uri>();

            //Semaphore semaphore = new Semaphore(0, feedUrls.Count);
            try
            {
                if (((Button)sender).Content.ToString() == "Feedly")
                {
                    feedUrls = await FeedsFinder.SearchFromFeedly(websiteTextBox.Text);
                }
                else
                {
                    feedUrls = await FeedsFinder.GetFeedsFromUrl(new Uri(websiteTextBox.Text));
                }
                var client = new SyndicationClient();
                List <FeedViewModel> feeds = new List <FeedViewModel>();

                Parallel.ForEach(feedUrls, async(url, loopstat) =>
                {
                    try
                    {
                        var feed = await client.RetrieveFeedAsync(url);
                        lock (feeds)
                        {
                            Invoke(() =>
                            {
                                Feeds.Add(new FeedViewModel(feed, url.AbsoluteUri));
                            });
                            System.Diagnostics.Debug.WriteLine("循环内");
                        }
                    }
                    catch (Exception exception)
                    {
                        System.Diagnostics.Debug.WriteLine(exception.Message);
                    }
                });
            }
            catch (Exception)
            {
                Feeds.Add(new FeedViewModel("无结果或链接错误", "", "", "Nopic"));
            }
            System.Diagnostics.Debug.WriteLine("循环外");
            Invoke(() => searchingProgressRing.IsActive = false);
        }
Esempio n. 5
0
        private async void ShowFeeds()
        {
            Feeds.Clear();
            if (FeedURLs != null)
            {
                foreach (string url in FeedURLs.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var puri      = new ParsedUri(url);
                    var parsedDoc = await _sessionScope.GetDocument(puri);

                    var feedViewModels = FeedViewModelFactory.GetFeedViewModels(parsedDoc);
                    foreach (var viewModel in feedViewModels)
                    {
                        Feeds.Add(viewModel);
                    }
                    this.NotifyPropertyChanged("Feeds");
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Populates the Feeds list and initializes the CurrentFeed and CurrentArticle properties.
 /// </summary>
 public async Task InitializeFeedsAsync()
 {
     Feeds.Clear();
     (await FeedDataSource.GetFeedsAsync()).ForEach(feed => Feeds.Add(feed));
     CurrentFeed    = Feeds[Feeds.Count == 1 ? 0 : 1];
     CurrentArticle = CurrentFeed.Articles.FirstOrDefault() ?? CurrentArticle;
     if (FavoritesFeed.Articles.Count == 0)
     {
         FavoritesFeed.ErrorMessage = NO_ARTICLES_MESSAGE;
     }
     FavoritesFeed.Articles.CollectionChanged += async(s, e) =>
     {
         // This handles list saving for both newly-starred items and for
         // reordering of the Favorites list (which causes a Remove followed by an Add).
         // List saving for removals due to an unstarring are handled in FeedView.xaml.cs.
         if (e.Action == NotifyCollectionChangedAction.Add)
         {
             await SaveFavoritesAsync();
         }
         FavoritesFeed.ErrorMessage = FavoritesFeed.Articles.Count > 0 ? null : NO_ARTICLES_MESSAGE;
     };
     Initialized?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 7
0
    public void LoadFeedsFromStorage()
    {
        Feeds.Clear();
        Bookmarks.Clear();
        if (Directory.Exists(FeedDirectory))
        {
            foreach (var feed_file in Directory.GetFiles(FeedDirectory, "*.feed"))
            {
                Feed feed;
                using (var file = new StreamReader(feed_file))
                    feed = Feed.Deserialize(Path.GetFileNameWithoutExtension(feed_file), file.ReadToEnd());

                foreach (var post_file in Directory.GetFiles(Path.Combine(FeedDirectory, feed.ID), "*.post"))
                {
                    Feed.Post post;
                    using (var file = new StreamReader(post_file))
                        post = Feed.Post.Deserialize(feed, Path.GetFileNameWithoutExtension(post_file), file.ReadToEnd());
                    feed.Posts.Add(post);
                }

                feed.Posts.Sort((x, y) => y.DatePublished.CompareTo(x.DatePublished));

                Feeds.Add(feed);
            }
            foreach (var bookmark_file in Directory.GetFiles(Path.Combine(FeedDirectory, "bookmarks"), "*.bookmark"))
            {
                Bookmark bookmark;
                using (var file = new StreamReader(bookmark_file))
                    bookmark = Bookmark.Deserialize(Path.GetFileNameWithoutExtension(bookmark_file), file.ReadToEnd());
                Bookmarks.Add(bookmark);
            }
        }
        else
        {
            Directory.CreateDirectory(Path.Combine(FeedDirectory, "bookmarks"));
        }
    }
        /// <summary>
        /// Gets all the feeds from database (with-in limits in settings)
        /// the try to gets all the new stuff from your sources
        /// add the new ones to the database if there is any
        /// then show the latest (with-in limits in settings)
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="token"></param>
        /// <returns>Task Type</returns>
        public async Task LoadDataAsync(IProgress <int> progress, CancellationToken token)
        {
            IsLoadingData = true;
            FilterSources.Clear();
            Feeds.Clear();
            ProgressCurrent = 0;
            bool hasLoadedFeedNewItems = false;

            // Shows the user what's new in this version
            await WhatsNewDisplayService.ShowIfAppropriateAsync();

            // Set Httpclient userAgent to the user selected one
            await RssRequest.SetCustomUserAgentAsync();

            foreach (var rss in await RSSDataService.GetFeedsDataAsync(await ApplicationData.Current.LocalSettings.ReadAsync <int>("FeedsLimit")))
            {
                Feeds.Add(rss);
            }

            SyndicationFeed feed = null;

            var sourcesDataList = await SourceDataService.GetSourcesDataAsync();

            ProgressMax = sourcesDataList.Count();
            int progressCount = 0;

            foreach (var source in sourcesDataList)
            {
                FilterSources.Add(source);

                if (token.IsCancellationRequested)
                {
                    IsLoadingData = false;
                    TokenSource   = new CancellationTokenSource();
                    MarkAsReadCommand.OnCanExecuteChanged();
                    return;
                }
            }
            // if there is no internet just cut our loses and get out of here we already loaded the local data
            if (!new NetworkInformationHelper().HasInternetAccess)
            {
                await new MessageDialog("CheckInternetMessageDialog".GetLocalized()).ShowAsync();
                return;
            }
            var WaitAfterLastCheckInMinutes = await ApplicationData.Current.LocalSettings.ReadAsync <int>("WaitAfterLastCheck");

            foreach (var sourceItem in FilterSources)
            {
                bool isFirstItemInFeed = true;

                if (token.IsCancellationRequested)
                {
                    IsLoadingData = false;
                    TokenSource   = new CancellationTokenSource();
                    MarkAsReadCommand.OnCanExecuteChanged();
                    return;
                }

                // don't get source feed if x number of minutes haven't passed since the last one - default is 2 hours
                var checkSourceAfter = sourceItem.LastBuildCheck.AddMinutes(WaitAfterLastCheckInMinutes);

                if (checkSourceAfter >= DateTimeOffset.Now)
                {
                    continue;
                }

                if (!new NetworkInformationHelper().HasInternetAccess)
                {
                    continue;
                }

                progress.Report(++progressCount);

                //if getting the feed crushed for (internet - not xml rss - other reasons)
                //move to the next source on the list to try it instead of stopping every thing
                try
                {
                    var feedString = await RssRequest.GetFeedAsStringAsync(sourceItem.RssUrl, token);

                    feed = new SyndicationFeed();

                    if (string.IsNullOrWhiteSpace(feedString))
                    {
                        continue;
                    }
                    else
                    {
                        feed.Load(feedString);

                        // Saves rss items count and last check time to source
                        sourceItem.CurrentRssItemsCount = feed.Items.Count;
                        sourceItem.LastBuildCheck       = DateTimeOffset.Now;
                        await SourceDataService.UpdateSourceAsync(sourceItem);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    continue;
                }

                // Iterate through each feed item.
                foreach (SyndicationItem syndicationItem in feed.Items)
                {
                    if (token.IsCancellationRequested)
                    {
                        IsLoadingData = false;
                        TokenSource   = new CancellationTokenSource();
                        MarkAsReadCommand.OnCanExecuteChanged();
                        return;
                    }

                    //handle edge cases like when they don't send that stuff or misplace them like freaking reddit r/worldnews
                    if (syndicationItem.Title == null)
                    {
                        syndicationItem.Title = new SyndicationText("MainViewModelNoTitleFound".GetLocalized());
                    }
                    if (syndicationItem.Summary == null)
                    {
                        syndicationItem.Summary = new SyndicationText("MainViewModelNoSummaryFound".GetLocalized());
                    }
                    if (syndicationItem.PublishedDate.Year < 2000)
                    {
                        syndicationItem.PublishedDate = syndicationItem.LastUpdatedTime.Year > 2000 ? syndicationItem.LastUpdatedTime : DateTimeOffset.Now;
                    }

                    Uri itemNewUri = syndicationItem.ItemUri;
                    if (itemNewUri == null)
                    {
                        if (syndicationItem.Links.Count > 0)
                        {
                            itemNewUri = syndicationItem.Links.FirstOrDefault().Uri;
                        }
                    }
                    if (string.IsNullOrWhiteSpace(syndicationItem.Id))
                    {
                        syndicationItem.Id = itemNewUri.ToString();
                    }

                    var rss = new RSS
                    {
                        PostTitle   = syndicationItem.Title.Text,
                        Description = syndicationItem.Summary.Text,
                        Authors     = new List <Author>(),
                        URL         = itemNewUri,
                        CreatedAt   = syndicationItem.PublishedDate.DateTime,
                        Guid        = syndicationItem.Id,
                        PostSource  = sourceItem
                    };

                    foreach (var author in syndicationItem.Authors)
                    {
                        rss.Authors.Add(new Author
                        {
                            Name  = author.Name,
                            Email = author.Email,
                            Uri   = author.Uri
                        });
                    }

                    if (!await RSSDataService.FeedExistAsync(rss))
                    {
                        var newRss = await RSSDataService.AddNewFeedAsync(rss);

                        Feeds.Add(newRss);
                        hasLoadedFeedNewItems = true;

                        // Add first item in each source feed to Windows Live Tiles
                        if (isFirstItemInFeed)
                        {
                            Singleton <LiveTileService> .Instance.SampleUpdate(newRss.PostSource.SiteTitle, ShortenText(newRss.PostTitle, 80), ShortenText(newRss.Description, 95));
                        }
                        isFirstItemInFeed = false;
                    }
                }
            }

            if (hasLoadedFeedNewItems)
            {
                Feeds.Clear();
                foreach (var rss in await RSSDataService.GetFeedsDataAsync(await ApplicationData.Current.LocalSettings.ReadAsync <int>("FeedsLimit")))
                {
                    Feeds.Add(rss);
                }
            }
            IsLoadingData = false;
            MarkAsReadCommand.OnCanExecuteChanged();
        }
Esempio n. 9
0
        /// <summary>
        /// Gets all the feeds from database (with-in limits in settings)
        /// the try to gets all the new stuff from your sources
        /// add the new ones to the database if there is any
        /// then show the latest (with-in limits in settings)
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="ct"></param>
        /// <returns>Task Type</returns>
        public async Task LoadDataAsync(IProgress <int> progress, CancellationToken token)
        {
            IsLoadingData = true;
            FilterSources.Clear();
            Feeds.Clear();
            bool hasLoadedFeedNewItems = false;

            foreach (var rss in await RSSDataService.GetFeedsDataAsync(await ApplicationData.Current.LocalSettings.ReadAsync <int>("FeedsLimit")))
            {
                Feeds.Add(rss);
            }

            SyndicationFeed feed = new SyndicationFeed();

            var sourcesDataList = await SourceDataService.GetSourcesDataAsync();

            ProgressMax     = sourcesDataList.Count();
            ProgressCurrent = 0;
            int progressCount = 0;

            foreach (var source in sourcesDataList)
            {
                FilterSources.Add(source);

                if (token.IsCancellationRequested)
                {
                    IsLoadingData = false;
                    return;
                }
            }
            // if there is no internet just cut our loses and get out of here we already loaded the local data
            if (!new NetworkInformationHelper().HasInternetAccess)
            {
                await new MessageDialog("CheckInternetMessageDialog".GetLocalized()).ShowAsync();
                return;
            }

            foreach (var sourceItem in FilterSources)
            {
                if (token.IsCancellationRequested)
                {
                    IsLoadingData = false;
                    return;
                }

                if (!new NetworkInformationHelper().HasInternetAccess)
                {
                    continue;
                }

                progress.Report(++progressCount);

                //if getting the feed crushed for (internet - not xml rss - other reasons)
                //move to the next source on the list to try it instead of stoping every thing
                try
                {
                    var feedString = await RssRequest.GetFeedAsStringAsync(sourceItem.RssUrl);

                    if (string.IsNullOrWhiteSpace(feedString))
                    {
                        continue;
                    }
                    else
                    {
                        var xmlFeed = feedString.TrimStart();
                        feed.Load(xmlFeed);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    continue;
                }

                // Iterate through each feed item.
                foreach (SyndicationItem syndicationItem in feed.Items)
                {
                    if (token.IsCancellationRequested)
                    {
                        IsLoadingData = false;
                        return;
                    }

                    //handle edge cases like when they don't send that stuff or misplace them like freaking reddit r/worldnews
                    if (syndicationItem.Title == null)
                    {
                        syndicationItem.Title = new SyndicationText("MainViewModelNoTitleFound".GetLocalized());
                    }
                    if (syndicationItem.Summary == null)
                    {
                        syndicationItem.Summary = new SyndicationText("MainViewModelNoSummaryFound".GetLocalized());
                    }
                    if (syndicationItem.PublishedDate.Year < 2000)
                    {
                        syndicationItem.PublishedDate = syndicationItem.LastUpdatedTime.Year > 2000 ? syndicationItem.LastUpdatedTime : DateTimeOffset.Now;
                    }

                    Uri itemNewUri = syndicationItem.ItemUri;
                    if (itemNewUri == null)
                    {
                        if (syndicationItem.Links.Count > 0)
                        {
                            itemNewUri = syndicationItem.Links.FirstOrDefault().Uri;
                        }
                    }

                    var rss = new RSS
                    {
                        PostTitle   = syndicationItem.Title.Text,
                        Description = syndicationItem.Summary.Text,
                        Authors     = new List <Author>(),
                        URL         = itemNewUri,
                        CreatedAt   = syndicationItem.PublishedDate.DateTime,
                        Guid        = syndicationItem.Id,
                        PostSource  = sourceItem
                    };

                    foreach (var author in syndicationItem.Authors)
                    {
                        rss.Authors.Add(new Author
                        {
                            Name  = author.Name,
                            Email = author.Email,
                            Uri   = author.Uri
                        });
                    }

                    if (!await RSSDataService.FeedExistAsync(rss))
                    {
                        var newRss = await RSSDataService.AddNewFeedAsync(rss);

                        Feeds.Add(newRss);
                        hasLoadedFeedNewItems = true;
                    }
                }

                //shorten the text for windows 10 Live Tile
                Singleton <LiveTileService> .Instance.SampleUpdate(feed.Title.Text, ShortenText(feed.Items.FirstOrDefault()?.Title.Text, 80), ShortenText(feed.Items.FirstOrDefault()?.Summary.Text, 95));
            }

            if (hasLoadedFeedNewItems)
            {
                Feeds.Clear();
                foreach (var rss in await RSSDataService.GetFeedsDataAsync(await ApplicationData.Current.LocalSettings.ReadAsync <int>("FeedsLimit")))
                {
                    Feeds.Add(rss);
                }
            }
            MarkAsReadCommand.OnCanExecuteChanged();
            IsLoadingData = false;
        }