Exemple #1
0
        static void Main(string[] args)
        {
            DB = DataBase.GetInstance();

            while (true)
            {
                foreach (var f in DB.Feeds.Where(i => i.LastChecked.AddMinutes(15) < DateTime.Now).AsParallel())
                {
                    try
                    {
                        foreach (var fi in FeedParser.Parse(new Uri(f.Url)))
                        {
                            try
                            {
                                FeedReader.Models.FeedItem nFeedItem = new FeedReader.Models.FeedItem
                                {
                                    FeedID = f.ID,
                                    Created = fi.PublicationDate,
                                    Description = PrepareString(fi.Description),
                                    Title = PrepareString(fi.Title),
                                    Url = fi.Link.ToString()
                                };

                                if (!DB.FeedItems.Any(i => i.Url == nFeedItem.Url && i.FeedID == f.ID))
                                {
                                    DB.FeedItems.InsertOnSubmit(nFeedItem);
                                    Console.WriteLine("{0}: {1}", f.Title, nFeedItem.Title);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Error occurred inserting {0}.", fi.Title.TrimEnd('.'));
                                Console.WriteLine(e);
                            }
                        }

                        f.LastChecked = DateTime.Now;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to download or parse {0}.", f.Title);
                        Console.WriteLine(e);
                    }
                }

                try
                {
                    DB.SubmitChanges();
                    Thread.Sleep(30 * 1000);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error inserting feeds:");
                    Console.WriteLine(e.Message);
                    Thread.Sleep(10 * 1000);
                }

                DB.ClearInternalCache();
            }
        }
Exemple #2
0
        public async Task<FeedData> GetFeedAsync(string link) {
            Windows.Web.Syndication.SyndicationClient client = new SyndicationClient();
            Uri feedUri = new Uri(link);

            try {
                SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);

                // This code is executed after RetrieveFeedAsync returns the SyndicationFeed.
                // Process the feed and copy the data you want into the FeedData and FeedItem classes.
                FeedData feedData = new FeedData();

                if (feed.Title != null && feed.Title.Text != null) {
                    feedData.Title = feed.Title.Text;
                }
                if (feed.Subtitle != null && feed.Subtitle.Text != null) {
                    feedData.Description = feed.Subtitle.Text;
                }
                if (feed.Items != null && feed.Items.Count > 0) {
                    // Use the date of the latest post as the last updated date.
                    feedData.PubDate = feed.Items[0].PublishedDate.DateTime;

                    foreach (SyndicationItem item in feed.Items) {
                        FeedItem feedItem = new FeedItem();
                        if (item.Title != null && item.Title.Text != null) {
                            feedItem.Title = item.Title.Text;
                        }
                        if (item.PublishedDate != null) {
                            feedItem.PubDate = item.PublishedDate.DateTime;
                        }
                        if (item.Authors != null && item.Authors.Count > 0) {
                            feedItem.Author = item.Authors[0].Name.ToString();
                        }
                        // Handle the differences between RSS and Atom feeds.
                        if (feed.SourceFormat == SyndicationFormat.Atom10) {
                            if (item.Content != null && item.Content.Text != null) {
                                feedItem.Content = item.Content.Text;
                            }
                            if (item.Id != null) {
                                feedItem.Link = new Uri(item.Id);
                            }
                        }
                        else if (feed.SourceFormat == SyndicationFormat.Rss20) {
                            if (item.Summary != null && item.Summary.Text != null) {
                                feedItem.Content = item.Summary.Text;
                            }
                            if (item.Links != null && item.Links.Count > 0) {
                                feedItem.Link = item.Links[0].Uri;
                            }
                        }
                        feedData.Items.Add(feedItem);
                    }
                }
                return feedData;
            }
            catch (Exception) {
                return null;
            }
        }
Exemple #3
0
 partial void DeleteFeedItem(FeedItem instance);
Exemple #4
0
 partial void UpdateFeedItem(FeedItem instance);
Exemple #5
0
 partial void InsertFeedItem(FeedItem instance);
Exemple #6
0
 private void detach_FeedItems(FeedItem entity)
 {
     this.SendPropertyChanging();
     entity.Feed = null;
 }
Exemple #7
0
 private void attach_FeedItems(FeedItem entity)
 {
     this.SendPropertyChanging();
     entity.Feed = this;
 }
Exemple #8
0
        static void Main(string[] args)
        {
            DB = DataBase.GetInstance();

            while (true)
            {
                foreach (var f in DB.Feeds.Where(i => i.LastChecked.AddMinutes(15) < DateTime.Now).AsParallel())
                {
                    try
                    {
                        foreach (var fi in FeedParser.Parse(new Uri(f.Url)))
                        {
                            try
                            {
                                FeedReader.Models.FeedItem nFeedItem = new FeedReader.Models.FeedItem
                                {
                                    FeedID      = f.ID,
                                    Created     = fi.PublicationDate,
                                    Description = PrepareString(fi.Description),
                                    Title       = PrepareString(fi.Title),
                                    Url         = fi.Link.ToString()
                                };

                                if (!DB.FeedItems.Any(i => i.Url == nFeedItem.Url && i.FeedID == f.ID))
                                {
                                    DB.FeedItems.InsertOnSubmit(nFeedItem);
                                    Console.WriteLine("{0}: {1}", f.Title, nFeedItem.Title);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Error occurred inserting {0}.", fi.Title.TrimEnd('.'));
                                Console.WriteLine(e);
                            }
                        }

                        f.LastChecked = DateTime.Now;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to download or parse {0}.", f.Title);
                        Console.WriteLine(e);
                    }
                }


                try
                {
                    DB.SubmitChanges();
                    Thread.Sleep(30 * 1000);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error inserting feeds:");
                    Console.WriteLine(e.Message);
                    Thread.Sleep(10 * 1000);
                }

                DB.ClearInternalCache();
            }
        }
Exemple #9
0
 partial void DeleteFeedItem(FeedItem instance);
Exemple #10
0
 partial void UpdateFeedItem(FeedItem instance);
Exemple #11
0
 partial void InsertFeedItem(FeedItem instance);
Exemple #12
0
		private void detach_FeedItems(FeedItem entity)
		{
			this.SendPropertyChanging();
			entity.Feed = null;
		}
Exemple #13
0
		private void attach_FeedItems(FeedItem entity)
		{
			this.SendPropertyChanging();
			entity.Feed = this;
		}