Exemplo n.º 1
0
        private void SaveToDatabase(List <Item> newItems)
        {
            foreach (Item item in newItems)
            {
                BasicRepository.SaveItem(item);
            }

            Logger.Info("Saved {0} new items to the database", newItems.Count);
        }
Exemplo n.º 2
0
        private void FetchNewFeeds()
        {
            // Get all the items from the database
            List <Item>  currentItems = BasicRepository.AllItems();
            IList <Feed> feeds        = BasicRepository.AllFeeds();
            FeedFetcher  fetcher      = new FeedFetcher(_settings, currentItems);

            // Fetch each one
            List <Item> newItems = new List <Item>();

            foreach (Feed feed in feeds)
            {
                newItems.AddRange(fetcher.Parse(feed));
                Console.WriteLine("Finished {0}", feed.Url);
            }

            if (newItems.Count > 0)
            {
                SaveToDatabase(newItems);
            }
        }
Exemplo n.º 3
0
        public void Update()
        {
            try
            {
                BasicRepository.ConnectionString = _settings.ConnectionString;
                FetchNewFeeds();

                // Last 3 hours
                List <Item> items = BasicRepository.ItemsForPast(3);
                if (_settings.EnableFtp)
                {
                    SaveToDisk(items, "3.bin.gz");
                }
                else
                {
                    SaveToDisk(items, Path.Combine(_settings.LocalFolder, "3.bin.gz"));
                }

                // Last 6 hours
                items = BasicRepository.ItemsForPast(6);
                if (_settings.EnableFtp)
                {
                    SaveToDisk(items, "6.bin.gz");
                }
                else
                {
                    SaveToDisk(items, Path.Combine(_settings.LocalFolder, "6.bin.gz"));
                }

                // Last 12 hours
                items = BasicRepository.ItemsForPast(12);
                if (_settings.EnableFtp)
                {
                    SaveToDisk(items, "12.bin.gz");
                }
                else
                {
                    SaveToDisk(items, Path.Combine(_settings.LocalFolder, "12.bin.gz"));
                }

                // Last 24 hours.
                // Saturdays and sundays have very low postings so if the application is used on these days the user will get no news -
                // account for this by simply giving them Friday's.
                int hours = 24;
                if (DateTime.UtcNow.DayOfWeek == DayOfWeek.Saturday)
                {
                    hours = 48;
                }
                else if (DateTime.UtcNow.DayOfWeek == DayOfWeek.Sunday)
                {
                    hours = 72;
                }

                items = BasicRepository.ItemsForPast(hours);
                if (_settings.EnableFtp)
                {
                    SaveToDisk(items, "24.bin.gz");
                }
                else
                {
                    SaveToDisk(items, Path.Combine(_settings.LocalFolder, "24.bin.gz"));
                }

                // FTP
                if (_settings.EnableFtp)
                {
                    FtpFile("3.bin.gz");
                    FtpFile("6.bin.gz");
                    FtpFile("12.bin.gz");
                    FtpFile("24.bin.gz");
                }
            }
            catch (Exception e)
            {
                Logger.Fatal("Exception occured in Update: \n{0}", e);
            }
        }
Exemplo n.º 4
0
 public void ClearOldItems()
 {
     BasicRepository.ConnectionString = _settings.ConnectionString;
     BasicRepository.ClearOldItems();
 }