Beispiel #1
0
        //todo to private
        private IEnumerable <News> GetNewsFromUrls(IEnumerable <string> urls)

        {
            try
            {
                //split urls for different parsers or use fabric urlsFromRss
                var urlFromRss = GetUrlsFromRss();

                var onlinerUrls = urlFromRss.Where(si =>
                                                   si.ToLowerInvariant().Contains("onliner")).ToList();

                /*var tuByUrls = urlFromRss.Where(si =>
                 *  si.ToLowerInvariant().Contains("tutby")).ToList();
                 *
                 * var s13Urls = urlFromRss.Where(si =>
                 *  si.ToLowerInvariant().Contains("s13")).ToList();*/

                var news = new ConcurrentBag <News>();

                Parallel.ForEach(onlinerUrls, url =>
                {
                    news.Add(_onlinerParser.Parse(url));
                });

                /*Parallel.ForEach(tuByUrls, url =>
                 * {
                 *  news.Add(_tutByParser.Parse(url));
                 * });
                 *
                 * Parallel.ForEach(s13Urls, url =>
                 * {
                 *  news.Add(_s13Parser.Parse(url));
                 * });*/

                return(news.ToList());
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                throw e;
            }
        }