public ActionResult BDItalia()
        {
            var model = db.TinTucs.ToList().Where(x => x.idCM == 6);

            ViewBag.RSS = RssReader.GetRssFeed("https://bongda24h.vn/RSS/176.rss");
            return(View(model));
        }
        public void TestMethod1()
        {
            var rssReader = new RssReader("http://k.img.com.ua/rss/ru/all_news2.0.xml");
            var feed = rssReader.GetFeed();

     
        }
        public void CanGetImagesFromRssFeed()
        {
            string description = string.Format(@"<p><a href=""{0}""><img src=""http://thepaperwall.com/wallpapers/people/small/small_584778739bace9b64fb91975340190ed2f64a51d.jpg?x=130&y=89&q=85&sig=SVA2qhNVOsYltxwW7ULPyQ--"" align=""left"" height=""150"" width=""240""/>", expectedImageUrl);
            var rssChannelItem = new rssChannelItem
            {
                description =
                    description
            };
            var rssChannelItem2 = new rssChannelItem
            {
                description =
                    description
            };

            RssReader reader = new RssReader();

            var rss = new rss
            {
                channel = new rssChannel
                {
                    item = new rssChannelItem[] { rssChannelItem, rssChannelItem2 }
                }
            };
            List<PWImage> imageUrls = reader.GetImageUrls(rss);

            Assert.AreEqual(2, imageUrls.Count);

            foreach (var image in imageUrls)
            {
                Assert.AreEqual(expectedImageUrl, image.imageUrl);
            }
        }
 /// <DeleteRssReader>
 /// Delete RssReader
 /// </summary>
 /// <param name="rss">Set rssid in a RssReader Class Property and Pass the Object of RssReader Class.(Domein.RssReader)</param>
 /// <returns>Return 1 for true and 0 for false.(int)</returns>
 public int DeleteRssReader(RssReader rss)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action to delete RssReader by id.
                 NHibernate.IQuery query = session.CreateQuery("delete from RssReader where Id = :adsid")
                                 .SetParameter("adsid", rss.Id);
                 int isUpdated = query.ExecuteUpdate();
                 transaction.Commit();
                 return isUpdated;
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return 0;
             }
         }//End Transaction
     }//End Session
 }
        public ActionResult DuaXe()
        {
            var model = db.TinTucs.ToList().Where(x => x.idCM == 8);

            ViewBag.RSS = RssReader.GetRssFeed2("https://thethao247.vn/dua-xe-c96.rss");
            return(View(model));
        }
        public ActionResult Tennis()
        {
            var model = db.TinTucs.ToList().Where(x => x.idCM == 7);

            ViewBag.RSS = RssReader.GetRssFeed2("https://thethao247.vn/quan-vot-tennis-c4.rss");
            return(View(model));
        }
Esempio n. 7
0
        // GET: RssNews from nt and calls nt view
        public ActionResult nt()
        {
            string url2 = "https://www.nt.se/rss/lokalt/norrkoping";
            var    s    = RssReader.Read(url2, "nt");

            s.Sort((x, y) => DateTime.Compare(y.PublicationDate, x.PublicationDate)); //descending order
            return(View(s));
        }
 public static RssReader GetInstance()
 {
     if (_inst == null)
     {
         _inst = new RssReader();
     }
     return(_inst);
 }
Esempio n. 9
0
        // GET: RssNews from expressen and calls expressen view
        public ActionResult expressen()
        {
            string url2 = "https://feeds.expressen.se/nyheter/";
            var    s    = RssReader.Read(url2, "expressen");

            s.Sort((x, y) => DateTime.Compare(y.PublicationDate, x.PublicationDate)); //descending order
            return(View(s));
        }
Esempio n. 10
0
 public Form1()
 {
     RssReader = new RssReader();
     CCP       = new ShoppingCartLogic();
     GetItemsFromDb();
     InitializeComponent();
     Load += Initialize;
 }
Esempio n. 11
0
        // GETs: RssNews from svd and calls svd view
        public ActionResult Svd()
        {
            string url2 = "https://www.svd.se/?service=rss";
            var    s    = RssReader.Read(url2, "svd");

            s.Sort((x, y) => DateTime.Compare(y.PublicationDate, x.PublicationDate)); //descending order
            return(View(s));
        }
Esempio n. 12
0
        public async Task TestDownloadRss()
        {
            var rssReader = new RssReader();
            var result    = await rssReader.DownloadRssString();

            Assert.IsNotNull(result);
            Assert.AreNotEqual <string>(string.Empty, result);
        }
        private void SendDownloadQuery()
        {
            while (ThreadStopCheck)
            {
                RssReader rss = new RssReader();
                rss.FeedUrl = "https://www.tokyotosho.info/rss.php?filter=1,10,7";

                foreach (RssItem item in rss.Execute())
                {
                    int i = 0;

                    for (int j = 0; j < Ani.Count; j++)
                    {
                        item.Title.Replace('_', ' ');

                        if (item.Title.Contains("1280x720") || item.Title.Contains("1920x1080") ||
                            item.Title.Contains("1080p") || item.Title.Contains("720p"))
                        {
                            item.Title.Replace("1280x720", "");
                            item.Title.Replace("1920x1080", "");
                            item.Title.Replace("1080p", "");
                            item.Title.Replace("720p", "");

                            if (item.Title.Contains(Ani[j].name) && item.Title.Contains(Ani[j].Ep))
                            {
                                WebClient webClient = new WebClient();
                                webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(fake2);
                                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(fake);
                                webClient.DownloadFileAsync(new Uri(item.Link), item.Title + ".torrent");

                                int Ep = Convert.ToInt32(Ani[j].Ep);
                                ++Ep;
                                AniName Variable = Ani[j];
                                Variable.Ep = Convert.ToString(Ep);
                                Ani[i]      = Variable;
                                TweetToPerson(Ani[j], list_TweetUser);
                            }

                            i++;
                        }
                    }
                }
                int timerCheck = 0;
                while (ThreadStopCheck && timerCheck < 10000)
                {
                    Thread.Sleep(1);
                    timerCheck++;
                }
            }

            this.Invoke(new MethodInvoker(delegate()
            {
                bt_Refresh.Enabled = true;
            }));
            Thread.CurrentThread.Abort();
        }
        public static void AutoGetAndPublish()
        {
            //查找所有有url的OverView类型的发布
            IContentType    type = ApplicationContext.Current.Services.ContentTypeService.GetContentType("Overview");
            List <IContent> needPublishContents =
                ApplicationContext.Current.Services.ContentService.GetContentOfContentType(type.Id).Where(c => c.ParentId.Equals(1075))
                .Where(c => c.GetValue("url").ToString().Trim() != string.Empty)
                .ToList();

            //比较是否有新的新闻要发布
            foreach (IContent newsContent in needPublishContents)
            {
                if (newsContent.GetValue <bool>("StartGettingNews").Equals(true))
                {
                    IContent lastPublishNews =
                        newsContent.Children().OrderByDescending(c => c.CreateDate).FirstOrDefault();

                    string catchNewsInfo = string.Empty;

                    List <RssNews> rssNews = RssReader.GetNewsFromRss(newsContent.GetValue("url").ToString().Trim(),
                                                                      1, out catchNewsInfo);
                    string oldPublishStatus = newsContent.GetValue("publishStatus").ToString().Trim();
                    if (rssNews != null && rssNews.Count() > 0)
                    {
                        if (rssNews[0].Title.Trim() !=
                            lastPublishNews.GetValue("pageTitle").ToString().Trim())
                        {
                            string newPublishStatus = string.Empty;
                            bool   isSuccess        = PublishNew(newsContent.GetValue("AddressPrefix").ToString().Trim(),
                                                                 newsContent.Id, rssNews[0], out newPublishStatus); //执行发布
                            newsContent.SetValue("publishStatus", oldPublishStatus + catchNewsInfo + newPublishStatus);
                            if (isSuccess == false)
                            {
                                //发布失败,设置为停止发布
                                // newsContent.SetValue("StartGettingNews", false);
                                ApplicationContext.Current.Services.ContentService.Publish(newsContent, 0);
                            }
                        }
                        else //一样的新闻不再发布
                        {
                            string newPublishStatus = DateTime.Now.ToString("yyyy-M-d dddd HH:mm:ss") +
                                                      ":已执行抓取新闻,但没有新的新闻。\r\n---------------------------\r\n";
                            newsContent.SetValue("publishStatus", oldPublishStatus + newPublishStatus);
                            ApplicationContext.Current.Services.ContentService.Publish(newsContent, 0);
                            break;
                        }
                    }
                    else//抓取新闻失败
                    {
                        //newsContent.SetValue("StartGettingNews", false);
                        newsContent.SetValue("publishStatus", catchNewsInfo);
                        ApplicationContext.Current.Services.ContentService.Publish(newsContent, 0);
                    }
                }
            }
        }
Esempio n. 15
0
        public async Task TestParseRssXml()
        {
            var rssReader = new RssReader();
            var result    = await rssReader.DownloadRssString();

            var rssNode = rssReader.GetRssNode(result);
            var items   = rssReader.ParseRss(rssNode);

            Assert.IsTrue(items.Count > 0);
        }
Esempio n. 16
0
        public async Task TestSaveFile()
        {
            var fileStoreHelper = new FileStoreHelper();
            var rssReader       = new RssReader();
            var result          = await rssReader.DownloadRssString();

            var isSuccess = await fileStoreHelper.SaveRssFileAsync(result);

            Assert.IsTrue(isSuccess);
        }
 public static void ReadRss()
 {
     using (var newsRssSourcesRepo = AutofacService.Instance.Resolve <INewsRssSourceRepository>())
     {
         var sources   = newsRssSourcesRepo.GetAll();
         var rssReader = new RssReader();
         rssReader.NewRssItemsEvent += RssReaderOnNewRssItemsEvent;
         rssReader.Read(sources, null, null);
     }
 }
 public static void AddPodcast(string url, string cat, int freq)
 {
     if (Validator.CheckUrl(url))
     {
         RssReader.RssFeed(url, cat, freq);
     }
     else
     {
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Retrieves the remote RSS feed and inserts it into the cache
 /// when it has expired.
 /// </summary>
 private static void RefreshCache(string key, object item, CacheItemRemovedReason reason)
 {
     if (reason != CacheItemRemovedReason.Removed)
     {
         string    feedUrl = key.Replace("RssReader_", String.Empty);
         RssReader reader  = new RssReader(feedUrl);
         reader.Execute();
         reader._UpdateFrequenzy = ((RssReader)item).UpdateFrequenzy;
         HttpRuntime.Cache.Add("RssReader_" + feedUrl, reader, null, DateTime.Now.Add(reader.UpdateFrequenzy), Cache.NoSlidingExpiration, CacheItemPriority.Normal, RefreshCache);
     }
 }
Esempio n. 20
0
        public async Task <ActionResult> Edit([Bind(Include = "UserFeedID,UserID,Url")] UserFeedModel userfeedmodel)
        {
            if (ModelState.IsValid)
            {
                userfeedmodel.Title           = RssReader.GetRssTitle(userfeedmodel.Url);
                db.Entry(userfeedmodel).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(userfeedmodel));
        }
Esempio n. 21
0
    /// <summary>
    /// Creates an RssReader instance from the specified URL
    /// and inserts it into the cache. When it expires from the cache,
    /// it automatically retrieves the remote RSS feed and inserts it
    /// to the cache again.
    /// </summary>
    /// <param name="feedUrl">The URI of the RSS feed.</param>
    /// <param name="updateFrequenzy">The time before it should update it self.</param>
    /// <returns>An instance of the RssReader class.</returns>
    public static RssReader CreateAndCache(string feedUrl, TimeSpan updateFrequenzy)
    {
        if (HttpRuntime.Cache["RssReader_" + feedUrl] == null)
        {
            RssReader reader = new RssReader(feedUrl);
            reader.Execute();
            reader._UpdateFrequenzy = updateFrequenzy;
            HttpRuntime.Cache.Add("RssReader_" + feedUrl, reader, null, DateTime.Now.Add(updateFrequenzy), Cache.NoSlidingExpiration, CacheItemPriority.Normal, RefreshCache);
        }

        return((RssReader)HttpContext.Current.Cache["RssReader_" + feedUrl]);
    }
Esempio n. 22
0
        public async Task TestReadFile()
        {
            var fileStoreHelper = new FileStoreHelper();
            var rssReader       = new RssReader();
            var result          = await rssReader.DownloadRssString();

            await fileStoreHelper.SaveRssFileAsync(result);

            var content = await fileStoreHelper.ReadRssFileAsync();

            Assert.AreEqual <string>(result, content);
        }
Esempio n. 23
0
 public PartialViewResult MvcForumLatestNews()
 {
     if (Request.IsAjaxRequest())
     {
         var reader    = new RssReader();
         var viewModel = new LatestNewsViewModel {
             RssFeed = reader.GetRssFeed("http://www.mvcforum.com/rss").Take(AmountToShow).ToList()
         };
         return(PartialView(viewModel));
     }
     return(null);
 }
        public void ProcessFeed()
        {
            try
            {
                _logger.Log("ProcessFeed() called...", LogCategory.Information);

                using (var rss = new RssReader(ConfigurationManager.AppSettings["FeedUrl"]))
                {
                    var items         = rss.Execute().ToList();
                    var newNofication = new List <RssItem>();

                    if (items.Count <= 0)
                    {
                        return;
                    }

                    try
                    {
                        using (IDataContext dataContext = _dataContextFactory.Create(ConnectionType.Ip))
                        {
                            var notifications = dataContext.Query <NotificationMessage>().ToList();

                            newNofication.AddRange(notifications.Any()
                                ? items.Where(rssItem => notifications.All(n => n.StartDate != rssItem.Date))
                                : items);

                            foreach (var rssNotification in newNofication)
                            {
                                var notification = new NotificationMessage
                                {
                                    Text           = rssNotification.Title,
                                    Link           = rssNotification.Link,
                                    StartDate      = rssNotification.Date,
                                    EndDate        = rssNotification.ExpireOn,
                                    NotificationId = Guid.NewGuid()
                                };

                                dataContext.Add(notification);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }
Esempio n. 25
0
        private void GetNewDataFromSite()
        {
            var tagReader = new TagReader();

            tagReader.ReadTags();
            List <itemTag> items = new List <itemTag>();

            items = mongoCRUD.returnAllSources <itemTag>("Sources");
            var sources    = GetXRandomItemsFromList(5, items);
            var itemReader = new RssReader();

            itemReader.ReadItemsFromMultipleSources(sources);
        }
Esempio n. 26
0
        public static ICollection <string> GetFeeds()
        {
            var titles = new List <string>();

            using (var reader = new RssReader("http://idnes.cz.feedsportal.com/c/34387/f/625936/index.rss"))
            {
                titles.AddRange(reader.Execute().Select(i => i.Title));
            }
            using (var reader = new RssReader("http://idnes.cz.feedsportal.com/c/34387/f/625937/index.rss"))
            {
                titles.AddRange(reader.Execute().Select(i => i.Title));
            }
            return(titles);
        }
Esempio n. 27
0
 public PartialViewResult MvcForumLatestNews()
 {
     if (Request.IsAjaxRequest())
     {
         var reader    = new RssReader();
         var viewModel = new LatestNewsViewModel
         {
             RssFeed = reader.GetRssFeed(_settingsService.GetSettings().ForumUrl.TrimEnd('/') + "/home/LatestRss").Take(AmountToShow).ToList()
                       //RssFeed = reader.GetRssFeed("http://www.mvcforum.com/rss").Take(AmountToShow).ToList();
         };
         return(PartialView(viewModel));
     }
     return(null);
 }
Esempio n. 28
0
        private void FetchFeeds(object sender, DoWorkEventArgs args)
        {
            controller.Items.Clear();

            foreach (string feed in controller.Feeds)
            {
                RssReader rssReader = new RssReader(feed);

                foreach (RssItem item in rssReader.Items)
                {
                    controller.Items.Add(item);
                }
            }
        }
Esempio n. 29
0
        public async Task <ActionResult> Create([Bind(Include = "UserFeedID,UserID,Url")] UserFeedModel userfeedmodel)
        {
            if (ModelState.IsValid)
            {
                userfeedmodel.Title  = RssReader.GetRssTitle(userfeedmodel.Url);
                userfeedmodel.UserID = User.Identity.GetUserId();
                db.UserFeedModel.Add(userfeedmodel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(userfeedmodel));
        }
Esempio n. 30
0
        public ActionResult GetView(int tileId)
        {
            var tile = db.Tile.Find(tileId);

            // which tile is it?

            if (tile.TileType == 1)
            {
                // this is a noticeboard tile.
                var noticeBoard = tile as Noticeboard;
                // get Noticeboard Items ViewModel.
                var noticeboardItem = NoticeboardReader.GetNoticeboardItem(noticeBoard, db);
                if (noticeboardItem == null)
                {
                    return(PartialView("_ErrorPartialView", "Cannot find noticeboard item, check your configuration"));
                }
                // pass ViewModel to the view.
                return(PartialView("_NoticeBoardTilePartialView", noticeboardItem));
            }
            if (tile.TileType == 2)
            {
                // this is a calendar tile.
                var calender = tile as Calender;
                // get Calendar Items ViewModel.
                var calendarItems = CalendarReader.GetCalendarItems(calender, db);
                // pass ViewModel to the view.
                return(PartialView("_CalendarTilePartialView", calendarItems));
            }
            if (tile.TileType == 3)
            {
                // this is a newsfeed tile.
                var newstile = tile as Newsfeed;
                // get Newsfeed Items ViewModel.
                var newsItems = RssReader.Read(newstile.RssUrl);
                // pass ViewModel to the view.
                return(PartialView("_NewsFeedTilePartialView", newsItems));
            }
            if (tile.TileType == 4)
            {
                // this is the a Twitter tile.
                var twitterTile = tile as Twitter;
                // get Twitter Items ViewModel.
                var tweets = TwitterReader.GetTweets(twitterTile.SearchCriteria);
                // pass ViewModel to the view.
                return(PartialView("_TwitterTilePartialView", tweets));
            }

            return(PartialView("_TilePartialView"));
        }
Esempio n. 31
0
        public MainWindow()
        {
            InitializeComponent();

            _rssReader = new RssReader(
                Settings.Default.UpdateInterval,
                GetFeedSources()
                );
            SettingsExtensions.OnSettingsSaved += SettingsUpdated;
            DataContext = _rssReader;

            ICollectionView view = CollectionViewSource.GetDefaultView(_rssReader.Entries);

            view.Filter = entry => (entry as RssEntry).Feed.Source?.IsEnabled ?? false;
        }
Esempio n. 32
0
        /// <summary>
        /// Starts loading the feed and initializing the reader for the feed type.
        /// </summary>
        /// <returns></returns>
        public async Task<ObservableCollection<RssSchema>> Load()
        {
            string xmlContent = await DownloadAsync();

            var doc = XDocument.Parse(xmlContent);
            var type = BaseRssReader.GetFeedType(doc);

            BaseRssReader rssReader;
            if (type == RssType.Rss)
                rssReader = new RssReader();
            else
                rssReader = new AtomReader();

            return rssReader.LoadFeed(doc);
        }
Esempio n. 33
0
        public ActionResult Index(string search)
        {
            ViewBag.RSS = RssReader.GetRssFeed("https://bongda24h.vn/RSS/279.rss");
            DBServices.DBServicesSoapClient client = new DBServices.DBServicesSoapClient();
            int s = client.Search(search);

            if (s == 1)
            {
                var result = ConvertToOBJ.Convert2(client.GetTT(search));
                return(View("SearchResult", result));
            }
            else
            {
                return(View(db.TinTucs.ToList()));
            }
        }
Esempio n. 34
0
        // GET: /UserFeed/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserFeedModel userfeedmodel = await db.UserFeedModel.FindAsync(id);

            if (userfeedmodel == null)
            {
                return(HttpNotFound());
            }
            System.Diagnostics.Debug.WriteLine("title = " + RssReader.GetRssTitle(userfeedmodel.Url));

            return(View(userfeedmodel));
        }
Esempio n. 35
0
        public static void Run ()
        {
            // Get keywords. Read Frisim. Parse. Store.

            string[] keywords = MediaEntries.GetOldMediaKeywords();

            foreach (string keyword in keywords)
            {
                // string rssUrl = String.Format("http://sesam.se/search/?c=m&q={0}&&output=rss", keyword.ToLower());

                string rssUrl = String.Format("http://www.frisim.com/rss/?q={0}&k=nyheter", keyword.ToLower());

                // Read the RSS URL into memory, then feed RssReader from a MemoryStream

                HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(rssUrl);
                request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5";

                HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
                RssReader reader = new RssReader(resp.GetResponseStream());

                try
                {
                    Rss rss = reader.Read();

                    foreach (RssChannelItem item in rss.Channel.Items)
                    {
                        // We want the title, media name, link and pubdate.

                        string url = item.Link;
                        DateTime dateTime = item.PubDate;
                        string title = item.Title;
                        string mediaName = item.Categories[0].Name;

                        MediaEntry.CreateFromKeyword(keyword, mediaName, false, url, title, dateTime);
                    }
                }
                catch (Exception e)
                {
                    throw new ReaderException("feed:" + rssUrl + "Status=" + resp.StatusCode, e);
                }

                finally
                {
                    request.GetResponse().GetResponseStream().Close();
                }
            }
        }
 /// <AddRssReader>
 /// Add new RssReader
 /// </summary>
 /// <param name="rss">Set Values in a RssReader Class Property and Pass the Object of RssReader Class.(Domein.RssReader)</param>
 public void AddRssReader(RssReader rss)
 {
     try
     {
         //Creates a database connection and opens up a session
         using (NHibernate.ISession session = SessionFactory.GetNewSession())
         {
             //After Session creation, start Transaction.
             using (NHibernate.ITransaction transaction = session.BeginTransaction())
             {
                 //Proceed action, to save new data.
                 session.Save(rss);
                 transaction.Commit();
             }//End Transaction
         }//End Session
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
     }
 }
Esempio n. 37
0
    /// <summary>
    /// Get News Feeds from the assigned RSS Aggregator.
    /// </summary>
    /// <param name="alreadySelectedStocks">The Symbols of User selected Stocks, in CSV format.</param>
    /// <returns>A string containing (News Title, News Link)</returns>
    public string LoadPerStockNews(string alreadySelectedStocks)
    {
        string newsFeeds = "";

        if (isShowNews)
        {
            GUIVariables gui = new GUIVariables();

            //    //    You can use the class with Caching.
            //    RssReader reader = RssReader.CreateAndCache("http://feeds.feedburner.com/netslave", new TimeSpan(2, 0, 0));
            //    foreach (RssItem item in reader.Items)
            //    {
            //        Response.Write(item.Title +"<br />");
            //    }

            //  You can also use the class directly without caching.
            using (RssReader rss = new RssReader())
            {
                //  Show personalized News for all Users, Don't Cache.
                rss.FeedUrl = yahooNewsFeedRSSFinanceURL + alreadySelectedStocks;

                foreach (RssItem item in rss.Execute())
                {
                    //  string makeLink = item.Title + "    " + "[" + "<a href='" + item.Link + "' target='_blank'>" + "link" + "</a>" + "]";
                    //  newsFeeds = newsFeeds + makeLink + "    " + gui.LineBreak;

                    string makeLink = gui.RedFontStart + ">>" + gui.RedFontEnd
                        + "<a href='" + item.Link + "' style=\"text-decoration:none; font-family:Verdana;\" target='_blank'>" + item.Title + "</a>";
                    newsFeeds = newsFeeds + makeLink + "    " + gui.LineBreak;
                }
            }
        }
        return newsFeeds;
    }
Esempio n. 38
0
    /// <summary>
    /// Get News Feeds from the assigned RSS Aggregator.
    /// </summary>
    /// <param name="feedURL">URL to fetch the news feed.</param>
    /// <param name="alreadySelectedStocks">The Symbols of User selected Stocks, in CSV format.</param>
    /// <returns>A string containing (News Title, News Link)</returns>
    public string LoadPerStockNews(string feedURL, string alreadySelectedStocks)
    {
        string newsFeeds = "";

        if (isShowNews)
        {
            GUIVariables gui = new GUIVariables();
            using (RssReader rss = new RssReader())
            {
                rss.FeedUrl = feedURL + alreadySelectedStocks;

                foreach (RssItem item in rss.Execute())
                {
                    //  string makeLink = item.Title + "    " + "[" + "<a href='" + item.Link + "' target='_blank'>" + "link" + "</a>" + "]";
                    //  newsFeeds = newsFeeds + makeLink + "    " + gui.LineBreak;

                    string makeLink = gui.RedFontStart + ">>" + gui.RedFontEnd
                        + "<a href='" + item.Link + "' style=\"text-decoration:none; font-family:Verdana;\" target='_blank'>" + item.Title + "</a>";
                    newsFeeds = newsFeeds + makeLink + "    " + gui.LineBreak;
                }
            }
        }
        return newsFeeds;
    }
Esempio n. 39
0
 /// <summary>
 /// Retrieves the remote RSS feed and inserts it into the cache
 /// when it has expired.
 /// </summary>
 private static void RefreshCache(string key, object item, CacheItemRemovedReason reason)
 {
     if (reason != CacheItemRemovedReason.Removed)
     {
         string feedUrl = key.Replace("RssReader_", String.Empty);
         RssReader reader = new RssReader(feedUrl);
         reader.Execute();
         reader._UpdateFrequency = ((RssReader)item).UpdateFrequency;
         HttpRuntime.Cache.Add("RssReader_" + feedUrl, reader, null, DateTime.Now.Add(reader.UpdateFrequency), Cache.NoSlidingExpiration, CacheItemPriority.Normal, RefreshCache);
     }
 }
Esempio n. 40
0
    protected void Page_Load(object sender, EventArgs e)
    {
        dbOps = (DBOperations)Application["dbOps"];
        rssReader = (RssReader)Application["rssReader"];
        gui = (GUIVariables)Application["gui"];
        stockService = (StockService)Application["stockService"];
        links = (Links)Application["links"];
        general = (General)Application["general"];
        engine = (ProcessingEngine)Application["engine"];

        //  username = Convert.ToString(Session["username"]);
        //  username = "******";

        if (Request.Cookies["stoockerCookie"] != null)
        {
            HttpCookie stoockerCookie = Request.Cookies["stoockerCookie"];
            username = dbOps.Decrypt(stoockerCookie["username"].ToString().Trim());
        }

        if (string.IsNullOrEmpty(username))
        {
            Response.Redirect(links.SessionExpiredPageLink);
        }
        else
        {
            upPredict = (int)ProcessingEngine.Movement.Up;
            downPredict = (int)ProcessingEngine.Movement.Down;

            yesterday = DateTime.Now.AddDays(-1).ToString(dateFormatString);
            today = DateTime.Now.ToString(dateFormatString);
            tomorrow = DateTime.Now.AddDays(+1).ToString(dateFormatString);

            //  If Today=Friday Then Tomorrow=Monday. Why? Because Stock Markets are closed on Weekends.
            if (DateTime.Now.DayOfWeek == DayOfWeek.Friday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                if (DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                    tomorrow = DateTime.Now.AddDays(+3).ToString(dateFormatString);
                if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                    tomorrow = DateTime.Now.AddDays(+2).ToString(dateFormatString);
                if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                    tomorrow = DateTime.Now.AddDays(+1).ToString(dateFormatString);
            }

            string welcomeMessage = gui.BoldFontStart + "Welcome to" + gui.StoocksFont + gui.BoldFontEnd;
            WelcomeLabel.Text = welcomeMessage;

            //  Trace.Write("Enter LoadCommonIndicesData");
            LoadCommonIndicesData();
            //  Trace.Write("Exit LoadCommonIndicesData");

            Trace.Write("Enter ShowAlreadySelectedStocks");
            interestedStocks = ShowAlreadySelectedStocks(username);
            Trace.Write("Exit ShowAlreadySelectedStocks");

            if (!string.IsNullOrEmpty(alreadySelectedStocks))
            {
                Trace.Write("Enter LoadYahooFinanceBadgeIFrame");
                LoadYahooFinanceBadgeIFrame(alreadySelectedStocks);
                Trace.Write("Exit LoadYahooFinanceBadgeIFrame");
            }

            //  if (!Page.IsPostBack)
            {
                Trace.Write("Enter LoadUserData");
                UserDetailsLabel.Text = LoadUserData(username);
                Trace.Write("Exit LoadUserData");

                if (isShowUserStockData)
                {
                    Trace.Write("Enter LoadCurrentData");
                    LoadCurrentData();
                    Trace.Write("Exit LoadCurrentData");
                }

                MessageLabel.Text = "";

                Trace.Write("Enter LoadNews");
                string newsFeeds = "";
                if (isGenericNews)      //  Show the same News for all Users, Do Cache, Update every 30 minutes.
                {
                    newsFeeds = rssReader.LoadPerStockNews(alreadySelectedStocks);
                }
                else
                {
                    newsFeeds = rssReader.LoadGenericNews("", false);
                }
                Trace.Write("Exit LoadNews");

                if (!string.IsNullOrEmpty(newsFeeds))
                {
                    NewsMessageLabel.Text = gui.BoldFontStart + "Latest News & Recommended Readings from " + gui.StoocksFont + gui.BoldFontEnd;
                    NewsLabel.Text = newsFeeds;
                }
            }
        }
    }
Esempio n. 41
0
        public static void Run ()
        {
            // Get keywords. Read Knuff. Parse. Store.

            string[] keywords = MediaEntries.GetBlogKeywords();

            foreach (string keyword in keywords)
            {
                string rssUrl = "http://knuff.se/rss/q/" + keyword;

                // Read the RSS URL into memory, then feed RssReader from a MemoryStream

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(rssUrl);
                request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5";
                HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
                RssReader reader = new RssReader(resp.GetResponseStream());

                try
                {
                    Rss rss = reader.Read();

                    foreach (RssChannelItem item in rss.Channel.Items)
                    {
                        // We want the title, link and pubdate.

                        string url = item.Link;
                        DateTime dateTime = item.PubDate;

                        int dividerIndex = item.Title.LastIndexOf('(');

                        if (item.Title.EndsWith("))"))
                        {
                            dividerIndex = item.Title.Substring(0, item.Title.Length - 7).LastIndexOf('(');
                        }

                        string title = item.Title.Substring(0, dividerIndex).Trim();
                        string blogName = item.Title.Substring(dividerIndex + 1, item.Title.Length - dividerIndex - 2);

                        bool newEntry = MediaEntry.CreateFromKeyword(keyword, blogName, true, url, title, dateTime);

                        if (newEntry)
                        {
                            try
                            {
                                PingCreeper(url);
                            }
                            catch (Exception)
                            {
                                // Ignore exceptions here, move on to the next entry
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new ReaderException("feed:" + rssUrl + ", Status=" + resp.StatusCode, e);
                }

                finally
                {
                    request.GetResponse().GetResponseStream().Close();
                }
            }
        }
 public static RssReader Create(string feedUrl)
 {
     RssReader reader = new RssReader(feedUrl);
     reader.Execute();
     return reader;
 }
Esempio n. 43
0
    public string LoadGenericNews(string url, bool isByPassCache)
    {
        string newsFeeds = "";

        if (isShowNews)
        {
            GUIVariables gui = new GUIVariables();
            if (!isByPassCache && HttpRuntime.Cache["genericNews"] != null)
            {
                newsFeeds = Convert.ToString(HttpRuntime.Cache["genericNews"]);
            }
            else
            {
                using (RssReader rss = new RssReader())
                {
                    if (string.IsNullOrEmpty(url))
                    {
                        rss.FeedUrl = yahooGenericNewsFeedRSSFinanceURL;
                    }
                    else
                    {
                        rss.FeedUrl = url;
                    }

                    foreach (RssItem item in rss.Execute())
                    {
                        //  string makeLink = item.Title + "    " + "[" + "<a href='" + item.Link + "' target='_blank'>" + "link" + "</a>" + "]";
                        //  newsFeeds = newsFeeds + makeLink + "    " + gui.LineBreak;

                        string makeLink = gui.RedFontStart + ">>" + gui.RedFontEnd
                            + "<a href='" + item.Link + "' style=\"text-decoration:none; font-family:Verdana;\" target='_blank'>" + item.Title + "</a>";
                        newsFeeds = newsFeeds + makeLink + "    " + gui.LineBreak;

                    }
                    //  HttpRuntime.Cache.Insert("genericNews", newsFeeds, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(newsRefreshRate));
                    HttpRuntime.Cache.Insert("genericNews", newsFeeds, null, DateTime.Now.AddMinutes(newsRefreshRate), System.Web.Caching.Cache.NoSlidingExpiration);
                }
            }
        }
        return newsFeeds;
    }
Esempio n. 44
0
    protected void Page_Load(object sender, EventArgs e)
    {
        dbOps = (DBOperations)Application["dbOps"];
        rssReader = (RssReader)Application["rssReader"];
        gui = (GUIVariables)Application["gui"];
        stockService = (StockService)Application["stockService"];
        links = (Links)Application["links"];
        log = (Logger)Application["log"];

        NewsSearchLabel.Text = gui.GreenFontStart + "Enter a Stock Symbol: " + gui.GreenFontEnd;

        if (Request.Cookies["stoockerCookie"] != null)
        {
            HttpCookie stoockerCookie = Request.Cookies["stoockerCookie"];
            username = dbOps.Decrypt(stoockerCookie["username"].ToString().Trim());

            GoBackLink.Text = "Home Page";
            LogoutLink.Visible = true;
        }
        else
        {
            GoBackLink.Text = "Login";
            LogoutLink.Visible = false;
        }

        //  if (!Page.IsPostBack)
        {
            GetNews(newsFeedsTable);
            RenderNews();

            StockTable.Visible = false;
        }
    }
 public void DownloadRssFeed()
 {
     var reader = new RssReader();
     var feed =  reader.GetFeed("http://www.thepaperwall.com/category_rss.php?feed=people").Result;
     Assert.AreEqual("ThePaperWall.com", feed.channel.title);
 }
Esempio n. 46
0
        private static void CheckOneFeed (string readerUrl, string persistAsKey, int orgIdForTemplate)
        {
            string persistenceKey = String.Format("Pressrelease-Highwater-{0}", persistAsKey);

            DateTime highWaterMark = DateTime.MinValue;

            RssReader reader = null;

            try
            {
                string highWaterMarkString = Persistence.Key[persistenceKey];

                if (string.IsNullOrEmpty(highWaterMarkString))
                {
                    //Initialize highwatermark if never used
                    highWaterMark = DateTime.Now;
                    Persistence.Key[persistenceKey] = DateTime.Now.ToString();
                }
                else
                {

                    try
                    {
                        highWaterMark = DateTime.Parse(highWaterMarkString);
                    }
                    catch (Exception ex)
                    {
                        HeartBeater.Instance.SuggestRestart();
                        throw new Exception(
                            "Triggered restart. Unable to read/parse old highwater mark from database in PressReleaseChecker.Run(), from key:" + persistenceKey + ", loaded string was '" + highWaterMarkString + "' expected format is " + DateTime.Now.ToString(), ex);
                    }
                }
                DateTime storedHighWaterMark = highWaterMark;
                reader = new RssReader(readerUrl);
                Rss rss = reader.Read();

                foreach (RssChannelItem item in rss.Channel.Items)
                {
                    // Ignore any items older than the highwater mark.
                    // Also ignore if older than two days

                    if (item.PubDate < highWaterMark || item.PubDate < DateTime.Now.AddDays(-2))
                    {
                        continue;
                    }

                    // This is an item we should publish.

                    // Set highwater datetime mark. We do this first, BEFORE processing, as a defense against mail floods,
                    // if should something go wrong and unexpected exceptions happen.

                    // We used to add 70 minutes as a defense against mistakes on DST switch in spring and fall (yes, it has happened), but have reduced to two.

                    if (item.PubDate > storedHighWaterMark)
                    {
                        Persistence.Key[persistenceKey] = item.PubDate.AddMinutes(2).ToString();
                        storedHighWaterMark = item.PubDate.AddMinutes(2);

                        // Verify that it was written correctly to database. This is defensive programming to avoid a mail flood,
                        // in case we can't write to the database for some reason.
                        string newStoredHighWaterString = "";
                        try
                        {
                            newStoredHighWaterString = Persistence.Key[persistenceKey];
                            DateTime temp = DateTime.Parse(newStoredHighWaterString);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(
                                "Unable to commit/parse new highwater mark to database in PressReleaseChecker.Run(), loaded string was '" + newStoredHighWaterString + "'", ex);
                        }

                        if (DateTime.Parse(Persistence.Key[persistenceKey]) < item.PubDate)
                        {
                            throw new Exception(
                                "Unable to commit new highwater mark to database in PressReleaseChecker.Run()");
                        }
                    }

                    bool allReporters = false;
                    bool international = false;
                    MediaCategories categories = new MediaCategories();

                    foreach (RssCategory category in item.Categories)
                    {
                        if (category.Name == "Alla")
                        {
                            allReporters = true;
                        }
                        else if (category.Name == "Uncategorized")
                        {
                            continue;
                        }
                        else 
                        {
                            try
                            {
                                MediaCategory mediaCategory = MediaCategory.FromName(category.Name);
                                categories.Add(mediaCategory);

                                if (category.Name.StartsWith("International"))
                                {
                                    international = true;
                                }
                            }
                            catch (Exception)
                            {
                                ExceptionMail.Send(new Exception("Unrecognized media category in press release: " + category.Name));
                            }
                        }
                    }

                    string mailText = Blog2Mail(item.Content);

                    // Create recipient list of relevant reporters

                    Reporters reporters = null;

                    if (allReporters)
                    {
                        reporters = Reporters.GetAll();
                    }
                    else
                    {
                        reporters = Reporters.FromMediaCategories(categories);
                    }

                    // Add officers if not int'l

                    People officers = new People();
                    Dictionary<int, bool> officerLookup = new Dictionary<int, bool>();

                    if (!international)
                    {
                        int[] officerIds = Roles.GetAllDownwardRoles(1, 1);
                        foreach (int officerId in officerIds)
                        {
                            officerLookup[officerId] = true;
                        }
                    }
                    else
                    {
                        officerLookup[1] = true;
                    }



                    // Send press release

                    //TODO: hardcoded  geo ... using  World
                    Organization org = Organization.FromIdentity(orgIdForTemplate);
                    Geography geo = Geography.Root;
                    PressReleaseMail pressreleasemail = new PressReleaseMail();

                    pressreleasemail.pSubject = item.Title;
                    pressreleasemail.pDate = DateTime.Now;
                    pressreleasemail.pBodyContent = Blog2Mail(item.Content);
                    pressreleasemail.pOrgName = org.MailPrefixInherited;
                    if (allReporters)
                    {
                        pressreleasemail.pPostedToCategories = "Alla";  // TODO: TRANSLATE
                    }
                    else if (international)
                    {
                        pressreleasemail.pPostedToCategories = "International/English"; // TODO: THIS IS HARDCODED
                    }
                    else
                    {
                        pressreleasemail.pPostedToCategories = PressReleaseMail.GetConcatenatedCategoryString(categories);
                    }

                    OutboundMail newMail = pressreleasemail.CreateFunctionalOutboundMail(MailAuthorType.PressService, OutboundMail.PriorityHighest, org, geo);

                    int recipientCount = 0;
                    foreach (Reporter recipient in reporters)
                    {
                        if (!Formatting.ValidateEmailFormat(recipient.Email))
                        {
                            continue;
                        }
                        ++recipientCount;
                        newMail.AddRecipient(recipient);
                    }
                    foreach (int key in officerLookup.Keys)
                    {
                        Person recipient = Person.FromIdentity(key);
                        if (!Formatting.ValidateEmailFormat(recipient.Mail))
                        {
                            continue;
                        }
                        ++recipientCount;
                        newMail.AddRecipient(recipient, true);
                    }

                    newMail.SetRecipientCount(recipientCount);
                    newMail.SetResolved();
                    newMail.SetReadyForPickup();
                }
            }
            catch (Exception ex)
            {
                ExceptionMail.Send(new Exception("PressReleaseChecker failed:" + ex.Message + "\r\nwhen checking " + readerUrl, ex));
            }
            finally
            {
                reader.Close();
            }
        }
 public void UpdateRssReader(RssReader rss)
 {
     throw new NotImplementedException();
 }
Esempio n. 48
0
    protected void Page_Load(object sender, EventArgs e)
    {
        dbOps = (DBOperations)Application["dbOps"];
        rssReader = (RssReader)Application["rssReader"];
        gui = (GUIVariables)Application["gui"];
        links = (Links)Application["links"];
        engine = (ProcessingEngine)Application["engine"];

        //  username = Convert.ToString(Session["username"]);

        if (Request.Cookies["stoockerCookie"] != null)
        {
            HttpCookie stoockerCookie = Request.Cookies["stoockerCookie"];
            username = dbOps.Decrypt(stoockerCookie["username"].ToString().Trim());
        }

        if (string.IsNullOrEmpty(username))
        {
            Response.Redirect(links.SessionExpiredPageLink);
        }
        else
        {
            upPredict = (int)ProcessingEngine.Movement.Up;
            downPredict = (int)ProcessingEngine.Movement.Down;

            yesterday = DateTime.Now.AddDays(-1).ToString(dateFormatString);
            today = DateTime.Now.ToString(dateFormatString);
            tomorrow = DateTime.Now.AddDays(+1).ToString(dateFormatString);

            //  If Today=Friday Then Tomorrow=Monday. Why? Because Stock Markets are closed on Weekends.
            if (DateTime.Now.DayOfWeek == DayOfWeek.Friday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
            {
                if (DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                    tomorrow = DateTime.Now.AddDays(+3).ToString(dateFormatString);
                if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                    tomorrow = DateTime.Now.AddDays(+2).ToString(dateFormatString);
                if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                    tomorrow = DateTime.Now.AddDays(+1).ToString(dateFormatString);
            }

            symbol = Convert.ToString(Request.QueryString["stock"]);
            if (string.IsNullOrEmpty(symbol))
            {
                Response.Redirect(links.HomePageLink);
            }
            else
            {
                StockDetailsLabel.Text = LoadStockDetails(symbol);
                LoadYahooFinanceBadgeIFrame(symbol);

                string newsFeeds = rssReader.LoadPerStockNews(symbol);
                if (!string.IsNullOrEmpty(newsFeeds))
                {
                    NewsMessageLabel.Text = gui.BoldFontStart + "Latest News & Recommended Readings from " + gui.StoocksFont + gui.BoldFontEnd;
                    NewsLabel.Text = newsFeeds;
                }
            }
        }
    }
Esempio n. 49
0
    /// <summary>
    /// Creates an RssReader instance from the specified URL and inserts it into the cache. 
    /// When it expires from the cache, it automatically retrieves the remote RSS feed and inserts it to the cache again.
    /// </summary>
    /// <param name="feedUrl">The URI of the RSS feed.</param>
    /// <param name="updateFrequency">The time before it should update it self.</param>
    /// <returns>An instance of the RssReader class.</returns>
    public static RssReader CreateAndCache(string feedUrl, TimeSpan updateFrequency)
    {
        if (HttpRuntime.Cache["RssReader_" + feedUrl] == null)
        {
          RssReader reader = new RssReader(feedUrl);
          reader.Execute();
          reader._UpdateFrequency = updateFrequency;
          HttpRuntime.Cache.Add("RssReader_" + feedUrl, reader, null, DateTime.Now.Add(updateFrequency), Cache.NoSlidingExpiration, CacheItemPriority.Normal, RefreshCache);
        }

        return (RssReader)HttpContext.Current.Cache["RssReader_" + feedUrl];
    }
Esempio n. 50
0
        private void FetchFeeds(object sender, DoWorkEventArgs args)
        {
            controller.Items.Clear();

            foreach(string feed in controller.Feeds){
                RssReader rssReader = new RssReader(feed);

                foreach(RssItem item in rssReader.Items){
                    controller.Items.Add(item);
                }
            }
        }
Esempio n. 51
0
        private static void CheckOneBlog (string readerFeedUrl, int personId)
        {
            try
            {

                Person sender = Person.FromIdentity(personId);

                string senderName = sender.Name + " (Piratpartiet)";
                string senderAddress = sender.PartyEmail;


                if (personId == 5)
                {
                    senderName = "=?utf-8?Q?Christian_Engstr=C3=B6m_(Piratpartiet)?="; // compensate for Mono bug
                }
                if (personId == 1)
                {
                    senderAddress = "*****@*****.**";
                }

                RssReader reader = new RssReader(readerFeedUrl);
                People recipients = null;

                DateTime highWaterMark = DateTime.MinValue;
                string persistenceKey = "Newsletter-Highwater-" + personId.ToString();

                string highWaterMarkString = Persistence.Key[persistenceKey];

                try
                {
                    highWaterMark = DateTime.Parse(highWaterMarkString);
                }
                catch (FormatException)
                {
                    highWaterMark = DateTime.MinValue;
                }
                catch (Exception e)
                {
                    throw new ReaderException("feed:" + readerFeedUrl, e);
                }

                try
                {
                    Rss rss = reader.Read();

                    // TODO: Read the high water mark from db

                    foreach (RssChannelItem item in rss.Channel.Items)
                    {
                        // Ignore any items older than the highwater mark.

                        if (item.PubDate < highWaterMark)
                        {
                            continue;
                        }

                        // For each item, look for the "Nyhetsbrev" category.

                        bool publish = false;

                        foreach (RssCategory category in item.Categories)
                        {
                            if (category.Name.ToLowerInvariant() == "nyhetsbrev")
                            {
                                publish = true;
                            }
                        }


                        if (publish)
                        {
                            // Set highwater datetime mark. We do this first as a defense against mail floods, should something go wrong.

                            Persistence.Key[persistenceKey] = item.PubDate.AddMinutes(5).ToString();

                            // Verify that it was written correctly to database. This is defensive programming to avoid a mail flood.

                            if (DateTime.Parse(Persistence.Key[persistenceKey]) < item.PubDate)
                            {
                                throw new Exception(
                                    "Unable to commit new highwater mark to database in NewsletterChecker.Run()");
                            }

                            bool testMode = false;

                            if (item.Title.ToLower().Contains("test"))
                            {
                                // Newsletter blog entry contains "test" in title -> testmode
                                testMode = true;
                            }

                            // Post to forum

                            string forumText = Blog2Forum(item.Content);
                            string mailText = Blog2Mail(item.Content);
                            int forumPostId = 0;
                            try
                            {
                                forumPostId = SwedishForumDatabase.GetDatabase().CreateNewPost(
                                                                testMode ? ForumIdTestPost : ForumIdNewsletter, sender,
                                                                "Nyhetsbrev " + DateTime.Today.ToString("yyyy-MM-dd"),
                                                                item.Title, forumText);
                            }
                            catch (Exception ex)
                            {
                                if (!System.Diagnostics.Debugger.IsAttached)
                                {   // ignore when debugging
                                    throw ex;
                                }
                            }


                            // Establish people to send to, if not already done.

                            if (recipients == null || recipients.Count == 1)
                            {
                                recipients = People.FromNewsletterFeed(NewsletterFeed.TypeID.ChairmanBlog);
                            }

                            /*                            
                             *  Disabled sending to activists -- this was done leading up to the election in 2009
                             */
                            // Add activists (HACK)
                            // Should probably be better to select by organization, not geography.

                            /*
                            People activists = Activists.FromGeography(Country.FromCode("SE").Geography).People;

                            recipients = recipients.LogicalOr(activists);*/


                            // OVERRIDE: If this is a TEST newsletter, send ONLY to the originator

                            if (testMode)
                            {
                                recipients = People.FromSingle(sender);
                                item.Title += " [TEST MODE]";
                            }

                            //TODO: hardcoded Org & geo ... using PP & World
                            Organization org = Organization.PPSE;
                            Geography geo = Geography.Root;


                            NewsletterMail newslettermail = new NewsletterMail();

                            newslettermail.pSubject = item.Title;
                            newslettermail.pDate = DateTime.Now;
                            newslettermail.pForumPostUrl =
                                String.Format("http://vbulletin.piratpartiet.se/showthread.php?t={0}", forumPostId);
                            newslettermail.pBodyContent = Blog2Mail(item.Content);
                            newslettermail.pOrgName = org.MailPrefixInherited;


                            OutboundMail newMail = newslettermail.CreateOutboundMail(sender, OutboundMail.PriorityLow, org, geo);

                            int recipientCount = 0;
                            foreach (Person recipient in recipients)
                            {
                                if (!Formatting.ValidateEmailFormat(recipient.Mail)
                                    || recipient.MailUnreachable
                                    || recipient.NeverMail)
                                {
                                    continue;
                                }
                                ++recipientCount;
                                newMail.AddRecipient(recipient, false);
                            }

                            newMail.SetRecipientCount(recipientCount);
                            newMail.SetResolved();
                            newMail.SetReadyForPickup();
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                lock (feedErrorSignaled)
                {
                    if (!feedErrorSignaled.ContainsKey(readerFeedUrl) || feedErrorSignaled[readerFeedUrl].AddMinutes(60) < DateTime.Now)
                    {
                        feedErrorSignaled[readerFeedUrl] = DateTime.Now;
                        throw new ReaderException("NewsletterChecker got error " + ex.Message + "\n when checking feed:" + readerFeedUrl + "\n(feed will be continually checked, bu will not signal error again for an hour)", ex);
                    }
                }
            }
        }
Esempio n. 52
0
        private static RssFeed read(string url, HttpWebRequest request, RssFeed oldFeed)
        {
            // ***** Marked for substantial improvement
            RssFeed feed = new RssFeed();
            RssElement element;
            Stream stream = null;
            Uri uri = new Uri(url);
            feed.url = url;

            switch (uri.Scheme)
            {
                case "file":
                    feed.lastModified = File.GetLastWriteTime(url);
                    if ((oldFeed != null) && (feed.LastModified == oldFeed.LastModified))
                    {
                        oldFeed.cached = true;
                        return oldFeed;
                    }
                    stream = new FileStream(url, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    break;
                case "https":
                    goto case "http";
                case "http":
                    if (request == null)
                        request = (HttpWebRequest) WebRequest.Create(uri);
                    if (oldFeed != null)
                    {
                        request.IfModifiedSince = oldFeed.LastModified;
                        request.Headers.Add("If-None-Match", oldFeed.ETag);
                    }
                    try
                    {
                        HttpWebResponse response = (HttpWebResponse) request.GetResponse();
                        feed.lastModified = response.LastModified;
                        feed.etag = response.Headers["ETag"];
                        try
                        {
                            if (response.ContentEncoding != "")
                                feed.encoding = Encoding.GetEncoding(response.ContentEncoding);
                        }
                        catch
                        {
                        }
                        stream = response.GetResponseStream();
                    }
                    catch (WebException we)
                    {
                        if (oldFeed != null)
                        {
                            oldFeed.cached = true;
                            return oldFeed;
                        }
                        else throw we; // bad
                    }
                    break;
            }

            if (stream != null)
            {
                RssReader reader = null;
                try
                {
                    reader = new RssReader(stream);
                    do
                    {
                        element = reader.Read();
                        if (element is DSD.Site.UtilityClasses.RSS.NET.RssChannel.RssChannel)
                            feed.Channels.Add((DSD.Site.UtilityClasses.RSS.NET.RssChannel.RssChannel) element);
                    } while (element != null);
                    feed.rssVersion = reader.Version;
                }
                finally
                {
                    feed.exceptions = reader.Exceptions;
                    reader.Close();
                }
            }
            else
                throw new ApplicationException("Not a valid Url");

            return feed;
        }