// sources => target news sources
        // returns news from the target sources
        public async Task <List <News> > GetNews(NewsSource sources)
        {
            List <News> news    = new List <News>();
            List <News> badGuys = new List <News>(); // TODO @ mario -- remove list after debugging

            // delete all existing rows
            //db.News.RemoveRange(db.News);

            // get newest news from each source
            foreach (var newsSource in sources.Sources)
            {
                // request for news
                string newsResponse = await service.MakeRequest("https://newsapi.org/v1/articles?source=" + newsSource.ID + "&sortBy=latest&apiKey=" + API_KEY);

                // parse json to news object and add to list if no error occured
                News targetnews = JsonConvert.DeserializeObject <News>(newsResponse);
                // work arround
                targetnews.Source = newsSource.Name;
                if (targetnews.Status.Equals("error"))
                {
                    badGuys.Add(targetnews);
                    continue;
                }
                ;
                targetnews.LastUpdate = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);

                news.Add(targetnews);
                //db.News.Add(targetnews);
            }

            //db.SaveChanges();

            return(news.OrderBy(x => x.Source).ToList());
        }
        public void EqualsTestEquality()
        {
            NewsSource o1 = new NewsSource("foo", new Uri("http://www.foo.bar"));
            NewsSource o2 = new NewsSource("foo", new Uri("http://www.foo.bar"));

            Assert.IsTrue(o1.Equals(o2));
        }
Exemple #3
0
        /// <summary>
        /// Delete a news source given a source ID
        /// And a user setting object.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="user"></param>
        public void DeleteNewsSource(int id, UserSetting user)
        {
            // Search for the user, and eager load the associations
            var        userAssoc       = Read(user.Id);
            NewsSource connectedSource = null;
            UserSettingNewsCategory connectedCategory = null;

            // Iterate over each category
            foreach (var category in userAssoc.UserSettingNewsCategories)
            {
                // Find the news category
                connectedCategory = category;
                var firstNewsSource = category.NewsSources.Where(s => s.Id == id);

                // When the news source is found
                if (firstNewsSource != null && firstNewsSource.Count() >= 1)
                {
                    // Add it to the list of sources that have been found connected to the user's category
                    connectedSource = firstNewsSource.First();
                }
            }

            // When the user, source, and category are identified to exist
            if (connectedSource != null && connectedCategory != null && userAssoc != null)
            {
                // Delete the news source
                _db.NewsSources.Remove(connectedSource);
                connectedCategory.NewsSources.Remove(connectedSource);
                _db.SaveChanges();
            }
        }
        public List <NewsArticle> Read(NewsSource newsSource)
        {
            XmlReader       reader = XmlReader.Create(newsSource.Link);
            SyndicationFeed feed   = SyndicationFeed.Load(reader);

            reader.Close();

            List <NewsArticle> articles = new List <NewsArticle>();

            foreach (SyndicationItem item in feed.Items)
            {
                articles.Add(new NewsArticle {
                    Title      = item.Title.Text,
                    CreateDate = DateTime.Today,
                    Group      = 0,
                    SimHash    = SimHash.SimHashOfString(item.Title.Text),
                    Source     = feed.Links.Count >= 1 ? feed.Links[0].Uri.ToString():"",
                    Link       = item.Links.Count >= 1 ? item.Links[0].Uri.ToString(): "",
                    Content    = item.Summary.Text,
                    ImageUrl   = item.Links.Count >= 2 ? item.Links[1].Uri.ToString():"",
                    NewsSource = newsSource
                });
            }
            return(articles);
        }
Exemple #5
0
 /// <summary>
 /// Adds a <c>NewsSource</c> to the <c>Archivist</c>.
 /// </summary>
 /// <param name="source">
 /// The <c>NewsSource</c> to add.
 /// </param>
 public static void AddNewsSource(NewsSource source)
 {
     if (source != null)
     {
         Archivist.AddNewsSource(source);
     }
 }
Exemple #6
0
        private NewsSource convertApiSource2Source(NewsApiSource source, int index)
        {
            ContentCategory category = ds.GetContentCategoryByName(source.Category);
            Language        language = ds.GetLanguageByCode(source.Language);
            Country         country  = ds.GetCountryByCode(source.Country);

            NewsSource result = new NewsSource();

            result.Id                      = index;
            result.NewsProviderId          = ProviderDef.Id;
            result.NewsProvider            = ProviderDef.Name;
            result.NewsSourceId            = source.Id;
            result.NewsSourceDescription   = source.Description;
            result.NewsSourceUrl           = source.Url;
            result.NewsSourceSmallLogoUrl  = source.UrlsToLogos.Small;
            result.NewsSourceMediumLogoUrl = source.UrlsToLogos.Medium;
            result.NewsSourceLargeLogoUrl  = source.UrlsToLogos.Large;
            result.ContentCategoryId       = category.Id;
            result.ContentCategory         = category.Name;

            result.CountryId   = country != null ? country.Id : null;
            result.CountryCode = source.Country;
            result.CountryName = country != null ? country.Name : null;

            result.LanguageId   = language != null ? language.Id : null;
            result.LanguageCode = source.Language;
            result.LanguageName = language != null ? language.Name : null;

            return(result);
        }
Exemple #7
0
        public IList <NewsSourceView> GetSourceViewList(MobileParam mobileParams, int cver, out int sver)
        {
            #region instance
            var source = new NewsSource()
            {
                Id             = 1,
                Name           = "今日头条",
                NameLowCase    = "toutiao",
                PackageName    = "com.ss.android.article.news",
                Status         = 1,
                CreateDateTime = DateTime.Now
            };

            var source2 = new NewsSource()
            {
                Id             = 2,
                Name           = "腾讯新闻",
                NameLowCase    = "tentcent",
                PackageName    = "com.tencent.news",
                Status         = 1,
                CreateDateTime = DateTime.Now
            };
            #endregion

            var sourcelist = new List <NewsSource>()
            {
                source, source2
            };
            sver = 1;
            var result = sourcelist.To <IList <NewsSourceView> >();

            return(result);
        }
Exemple #8
0
        public IEnumerable <Link> GetLinks(string newsSourceId)
        {
            List <Link> result = new List <Link>();

            if (string.IsNullOrEmpty(newsSourceId))
            {
                return(result);
            }

            NewsSource source = db.NewsSources.AsNoTracking().FirstOrDefault(x => x.NewsSourceId == newsSourceId);

            if (source == null)
            {
                return(result);
            }


            string          url    = source.NewsSourceUrl;
            XmlReader       reader = XmlReader.Create(url);
            SyndicationFeed feed   = SyndicationFeed.Load(reader);

            reader.Close();
            int i = 0;

            foreach (SyndicationItem item in feed.Items)
            {
                i++;
                result.Add(convertXml2Link(item, i));
            }

            return(result);
        }
        public ActionResult Create(NewsSource newssource)
        {
            if (ModelState.IsValid)
            {
                _newsSourceRepo.InsertOrUpdate(newssource);
                try
                {
                    _newsSourceRepo.Save();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        var temp2 = string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                  eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        //Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        //    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            var temp = string.Format("- Property: {0}, Error: {1}", ve.PropertyName, ve.ErrorMessage);
                            //Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            //    ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                return(RedirectToAction("Details", new { id = newssource.Id }));
            }
            var entity = new NewsSource();

            return(View(entity));
        }
        private Article GetTestArticle(int guid, NewsSource source)
        {
            var keywords = new string[] { "test" };

            return(new Article {
                Guid = guid, KeywordsList = keywords, Source = source
            });
        }
Exemple #11
0
        public NewsProducer(NewsSource newsSource, ILogger <NewsProducer> logger, IHttpClientFactory httpClientFactory)
        {
            _logger            = logger;
            _source            = newsSource;
            _httpClientFactory = httpClientFactory;

            nextId = 1;
        }
        public void ContentExpirationTimeTestProperty()
        {
            NewsSource source =
                new NewsSource("test", new Uri("http://www.test.com"));
            source.ContentExpirationTime = DateTime.MaxValue;

            Assert.AreEqual(source.ContentExpirationTime, DateTime.MaxValue);
        }
Exemple #13
0
        public RSSSPortalBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "Формула 1";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_8.xml";
            nSource.DefCategory = "8";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Волейбол";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_5.xml";
            nSource.DefCategory = "5";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "БГ Футбол";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_1.xml";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Европейски футбол";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_2.xml";
            nSource.DefCategory = "2";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Световен футбол";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_120.xml";
            nSource.DefCategory = "120";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Баскетбол";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_3.xml";
            nSource.DefCategory = "3";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Тенис";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_6.xml";
            nSource.DefCategory = "6";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Моторни спортове";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_73.xml";
            nSource.DefCategory = "73";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Булевард";
            nSource.URL         = "http://www.sportal.bg/uploads/rss_category_35.xml";
            nSource.DefCategory = "35";
            _NSource.Add(nSource);
        }
Exemple #14
0
    private IEnumerator CauseFailure(IRepairable victim, FailureType fail)
    {
        Transform effect = GetFailureParticleSystemFromPool(fail);
        AudioClip failClip = null, announcementClip = null;

        gremlindMap.Add(victim, new Gremlind()
        {
            FailType    = fail,
            Effect      = effect,
            PreviousTag = victim.transform.root.tag
        });

        victim.transform.root.tag = GremlindTag;

        //if we've loaded a pre-existing fault percentage, don't undo the repair
        if (victim.FaultedPercentage == 0f)
        {
            victim.FaultedPercentage = 1f;
        }

        if (fail == FailureType.Electrical)
        {
            effect.SetParent(victim.FailureEffectAnchors.Electrical);
            //alert the powergrid script
            FlowManager.Instance.PowerGrids.HandleElectricalFailureChange(victim, true);
            announcementClip = this.ElectricalFailureComputerTalk;
            failClip         = this.ElectricalFailureSound;
        }
        else if (fail == FailureType.Pressure && victim is GasStorage)
        {
            effect.SetParent(victim.FailureEffectAnchors.Pressure);
            announcementClip = this.PressureFailureComputerTalk;
            failClip         = this.PressureFailureSound;
            (victim as GasStorage).ToggleLeak(true);
        }
        else if (fail == FailureType.HabitatPressure && victim is IHabitatModule)
        {
            effect.SetParent(victim.FailureEffectAnchors.HabitatPressure);
            announcementClip = this.PressureFailureComputerTalk;
            failClip         = this.PressureFailureSound;
            (victim as IHabitatModule).LinkedHabitat.ToggleOxygenLeak(true);
        }

        effect.transform.localPosition = Vector3.zero;
        effect.transform.localRotation = Quaternion.identity;

        GremlinAudio.transform.position = effect.transform.position;

        SunOrbit.Instance.CheckEmergencyReset();
        GremlinAudio.PlayOneShot(failClip);

        yield return(new WaitForSeconds(failClip.length));

        SunOrbit.Instance.CheckEmergencyReset();
        GuiBridge.Instance.ComputerAudioSource.PlayOneShot(announcementClip);
        GuiBridge.Instance.ShowNews(NewsSource.GetFailureNews(victim, fail));
        PlayerInput.Instance.ToggleRepairMode(true);
    }
Exemple #15
0
        public RSSSPortalBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "Формула 1";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_8.xml";
            nSource.DefCategory = "8";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Волейбол";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_5.xml";
            nSource.DefCategory = "5";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "БГ Футбол";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_1.xml";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Европейски футбол";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_2.xml";
            nSource.DefCategory = "2";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Световен футбол";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_120.xml";
            nSource.DefCategory = "120";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Баскетбол";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_3.xml";
            nSource.DefCategory = "3";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Тенис";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_6.xml";
            nSource.DefCategory = "6";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Моторни спортове";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_73.xml";
            nSource.DefCategory = "73";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Булевард";
            nSource.URL = "http://www.sportal.bg/uploads/rss_category_35.xml";
            nSource.DefCategory = "35";
            _NSource.Add(nSource);
        }
        public void ReadAllAndStore()
        {
            List <NewsSource> newsSources = context.NewsSources.ToList();
            //databaseCtx.NewsArticles.RemoveRange(databaseCtx.NewsArticles);
            List <NewsArticle> newsArticles = new List <NewsArticle>();

            // read from all sources
            for (int i = 0; i < newsSources.Count; i++)
            {
                try
                {
                    NewsSource         source   = newsSources[i];
                    List <NewsArticle> articles = Read(source);
                    newsArticles.AddRange(articles);
                }
                catch (Exception)
                {
                    Console.WriteLine("Cannot read from source" + newsSources[i].Name);
                }
            }

            // last group number
            int lastGroup = context.NewsArticles.Select(x => (int?)x.Group).Max() ?? 0;

            for (int rep = 0; rep < 31; rep++) // 32 is number of bits of the SimHash fingerprint
            {
                // sort
                newsArticles.Sort((x, y) => x.SimHash.CompareTo(y.SimHash));
                // search for possible groups
                for (int i = 1; i < newsArticles.Count; i++)
                {
                    var previous = newsArticles[i - 1];
                    var current  = newsArticles[i];
                    if (HammingDistance(previous.SimHash, current.SimHash) <= 3)
                    {
                        if (previous.Group == 0)
                        {
                            previous.Group = current.Group = ++lastGroup;
                        }
                        else
                        {
                            current.Group = previous.Group;
                        }
                    }
                }

                // rotate
                foreach (var article in newsArticles)
                {
                    article.SimHash = RotateLeft(article.SimHash, 1);
                }
            }

            context.AddRange(newsArticles);
            context.SaveChanges();
            Console.WriteLine("News read from " + newsSources.Count.ToString() + " sources");
        }
 public ActionResult Edit(NewsSource newssource)
 {
     if (ModelState.IsValid)
     {
         _newsSourceRepo.InsertOrUpdate(newssource);
         _newsSourceRepo.Save();
         return(RedirectToAction("Details", new { id = newssource.Id }));
     }
     return(View());
 }
Exemple #18
0
        public RSSSignalBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "SignalBG";
            nSource.URL = "http://signal.bg/rss.php";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);
        }
Exemple #19
0
        public RSSCapitalBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "www.capital.bg";
            nSource.URL = "http://www.capital.bg/rss/";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);
        }
Exemple #20
0
        public RSSDoctorOnlineBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "DoctorOnline.bg: сайт за здраве";
            nSource.URL         = "http://doctoronline.bg/rss.php";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);
        }
Exemple #21
0
        public RSSHiCommBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "HiCommBG";
            nSource.URL         = "http://hicomm.bg/bg/rss/";
            nSource.DefCategory = "HiCommBG";
            _NSource.Add(nSource);
        }
Exemple #22
0
        public RSSZarBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "ZarBG";
            nSource.URL         = "http://zar.bg/rss.php";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);
        }
        public RSSDoctorOnlineBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "DoctorOnline.bg: сайт за здраве";
            nSource.URL = "http://doctoronline.bg/rss.php";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);
        }
Exemple #24
0
        public RSSSignalBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "SignalBG";
            nSource.URL         = "http://signal.bg/rss.php";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);
        }
Exemple #25
0
        public RSSZarBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "ZarBG";
            nSource.URL = "http://zar.bg/rss.php";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);
        }
Exemple #26
0
        /// <summary>
        /// Fetch News from a specific source.
        /// </summary>
        /// <param name="source">The source you want to request news for.</param>
        /// <returns><see cref="NewsResult"/> The result of the search with an IEnumerable collection of articles.</returns>
        public async Task <NewsResult> FetchNewsFromSource(NewsSource source)
        {
            var baseUrl       = Constants.BaseUrl;
            var requestSource = NewsSourceFormatter.FormatNewsSource(source);
            var query         = NewsSourceFormatter.FormatRequestSourceUrl(requestSource, baseUrl);

            var response = await SendRequestAsync(query);

            return(GetResult(response));
        }
Exemple #27
0
        public RSSGongBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "Спорт";
            nSource.URL         = "http://www.gong.bg/rss.php";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);
        }
Exemple #28
0
        public RSSCapitalBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "www.capital.bg";
            nSource.URL         = "http://www.capital.bg/rss/";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);
        }
Exemple #29
0
        public RSSHiCommBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "HiCommBG";
            nSource.URL = "http://hicomm.bg/bg/rss/";
            nSource.DefCategory = "HiCommBG";
            _NSource.Add(nSource);
        }
        public static string DisplayName(this NewsSource newsSource)
        {
            return(newsSource switch
            {
                NewsSource.Unknown => "Nepoznato",
                NewsSource.IndexHr => "Index",
                NewsSource.KonzervaHr => "Konzerva",
                NewsSource.PriznajemHr => "Priznajem",

                _ => throw new ArgumentException(message: "invalid enum value", paramName: "newsSource")
            });
        void source_ItemsUpdatedEvent(NewsSource source, IEnumerable <NewsItem> items)
        {
            List <RssNewsItem> rssItems = new List <RssNewsItem>();

            foreach (RssNewsItem item in items)
            {
                rssItems.Add(item);
            }

            _persistenceHelper.UpdateToDB <RssNewsItem>(rssItems, null);
        }
        [InlineData(2, NewsSource.IndexHr, true)]  // Different source, different guid
        void AddArticle_ContainsGuidAndSource_DoesNotAddArticle(int guid, NewsSource source, bool articleGetsAdded)
        {
            var repo = new InMemoryPostedArticlesRepository();

            repo.PostedArticles.Add(GetTestArticle(guid));
            var article = GetTestArticle(1, source);

            repo.AddArticle(article);

            Assert.Equal(articleGetsAdded, repo.PostedArticles.Contains(article));
        }
Exemple #33
0
        public void UpdataSource(NewsSourceDTO newsSourceDTO)
        {
            if (newsSourceDTO == null)
            {
                throw new ValidationException("Пустой источник новости", "");
            }
            Mapper.Initialize(cfr => cfr.CreateMap <NewsSourceDTO, NewsSource>());
            NewsSource newsSource = Mapper.Map <NewsSourceDTO, NewsSource>(newsSourceDTO);

            Database.NewsSource.Update(newsSource);
        }
        void PlatformNewsManager_SourceRemovedEvent(NewsManager manager, NewsSource source)
        {
            SystemMonitor.CheckError(_persistenceHelper.Delete <NewsSource>(new NewsSource[] { (source) }), "Failed to delete source from DB.");

            source.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate <IDBPersistent>(source_PersistenceDataUpdatedEvent);
            source.ItemsAddedEvent             -= new NewsSource.ItemsUpdateDelegate(source_ItemsAddingAcceptEvent);
            source.ItemsUpdatedEvent           -= new NewsSource.ItemsUpdateDelegate(source_ItemsUpdatedEvent);

            _persistenceHelper.Delete <NewsSource>(source);

            _persistenceHelper.Delete <RssNewsItem>(new MatchExpression("NewsSourceId", source.Id));
        }
        // get all possible sources
        public async Task <NewsSource> GetSources(string language = "de")
        {
            // request
            string sourcesResponse = await service.MakeRequest("https://newsapi.org/v1/sources?language=" + language + "&apiKey=" + API_KEY);

            // parse json to source object and add to list
            NewsSource sources = JsonConvert.DeserializeObject <NewsSource>(sourcesResponse);

            sources.LastUpdate = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);

            return(sources);
        }
Exemple #36
0
        public RSSInvestorBG()
        {
            NewsSource nSource;

            nSource             = new NewsSource();
            nSource.Title       = "България";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564912/index.rss";
            nSource.DefCategory = "България";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Свят";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564913/index.rss";
            nSource.DefCategory = "World";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Имоти";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564914/index.rss";
            nSource.DefCategory = "RealEstate";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Борса";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564915/index.rss";
            nSource.DefCategory = "Exchange";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Forex";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564916/index.rss";
            nSource.DefCategory = "Forex";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Комуникации";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564917/index.rss";
            nSource.DefCategory = "Communications";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Обучение";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564918/index.rss";
            nSource.DefCategory = "Training";
            _NSource.Add(nSource);

            nSource             = new NewsSource();
            nSource.Title       = "Style";
            nSource.URL         = "http://rss.investor.bg/c/33288/f/564919/index.rss";
            nSource.DefCategory = "Style";
            _NSource.Add(nSource);
        }
Exemple #37
0
        public RSSInvestorBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "България";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564912/index.rss";
            nSource.DefCategory = "България";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Свят";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564913/index.rss";
            nSource.DefCategory = "World";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Имоти";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564914/index.rss";
            nSource.DefCategory = "RealEstate";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Борса";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564915/index.rss";
            nSource.DefCategory = "Exchange";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Forex";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564916/index.rss";
            nSource.DefCategory = "Forex";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Комуникации";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564917/index.rss";
            nSource.DefCategory = "Communications";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Обучение";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564918/index.rss";
            nSource.DefCategory = "Training";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Style";
            nSource.URL = "http://rss.investor.bg/c/33288/f/564919/index.rss";
            nSource.DefCategory = "Style";
            _NSource.Add(nSource);
        }
        public IActionResult ModifySource([FromBody] NewsSource source)
        {
            var s = database.NewsSources.Find(source.Id);

            if (s == null)
            {
                return(NotFound("Source not found"));
            }

            database.Entry(s).CurrentValues.SetValues(source);
            database.SaveChanges();
            return(Ok(source));
        }
Exemple #39
0
        public IActionResult GetLinksBySource([FromBody] NewsSource source)
        {
            return(es.Execute(() =>
            {
                if (source == null)
                {
                    return new JsonResult(new GenericResult());
                }

                IEnumerable <Link> result = newsService.GetArticles(source.NewsProviderId, source.NewsSourceId);
                return new JsonResult(new GenericResult(result));
            }, false));
        }
Exemple #40
0
 public void InsertOrUpdate(NewsSource newsSource)
 {
     if (newsSource.Id == default(int))
     {
         // New entity
         _ctx.NewsSources.Add(newsSource);
     }
     else
     {
         // Existing entity
         _ctx.Entry(newsSource).State = EntityState.Modified;
     }
 }
Exemple #41
0
        public RSSDirBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "life.dir.bg";
            nSource.URL = "http://life.dir.bg/rss20.xml";
            nSource.DefCategory = "life";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "dnes.dir.bg";
            nSource.URL = "http://dnes.dir.bg/rss20.xml";
            nSource.DefCategory = "dnes";
            _NSource.Add(nSource);
        }
        public RSSMobileBulgariaCOM()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "Mobile Bulgaria News";
            nSource.URL = "http://www.mobilebulgaria.com/rss.php";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Mobile Bulgaria Reviews";
            nSource.URL = "http://www.mobilebulgaria.com/rss_reviews.php";
            nSource.DefCategory = "Reviews";
            _NSource.Add(nSource);
        }
Exemple #43
0
        public RSSDnesBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "България";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=1";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Бизнес";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=3";
            nSource.DefCategory = "3";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Свят";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=2";
            nSource.DefCategory = "2";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Крими";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=6";
            nSource.DefCategory = "6";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Спорт";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=9";
            nSource.DefCategory = "9";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Наука и технологии";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=4";
            nSource.DefCategory = "4";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Миш-маш";
            nSource.URL = "http://www.dnes.bg/rss.php?cat=7";
            nSource.DefCategory = "7";
            _NSource.Add(nSource);
        }
Exemple #44
0
        public RSSBtvBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "btv.bg/action";
            nSource.URL = "http://www.btv.bg/rss__action";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "ladyzone.bg";
            nSource.URL = "http://www.ladyzone.bg/rss_all";
            nSource.DefCategory = "ladyzone";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "btv.bg";
            nSource.URL = "http://www.btv.bg/rss_all";
            nSource.DefCategory = "News";
            _NSource.Add(nSource);
        }
Exemple #45
0
        public RSSBGFactorORG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "Водещите материали";
            nSource.URL = "http://www.bgfactor.org/rss/leading.xml";
            nSource.DefCategory = "leading";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Наука и техника";
            nSource.URL = "http://www.bgfactor.org/rss/sci_tech.xml";
            nSource.DefCategory = "sci_tech";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Любопитно";
            nSource.URL = "http://www.bgfactor.org/rss/znaete_li.xml";
            nSource.DefCategory = "znaete_li";
            _NSource.Add(nSource);
        }
Exemple #46
0
 /// <summary>
 /// Removes a <c>NewsSource/c> from the <c>Archivist</c>.
 /// </summary>
 /// <param name="source">
 /// The <c>NewsSource</c> to remove.
 /// </param>
 public static void RemoveNewsSource(NewsSource source)
 {
     if (source != null)
     {
         Archivist.RemoveNewsSource(source);
     }
 }
        /// <summary>
        /// Adds a new <c>NewsSource</c> to the visible list. The 
        /// <c>NewsSource</c> is not yet added to the database.
        /// </summary>
        /// <param name="sender">
        /// A reference to the calling object.
        /// </param>
        /// <param name="e">
        /// Arguments of this event.
        /// </param>
        private void AddNewNewsSourceButton_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(NewsSourceNameTextBox.Text) &&
                !string.IsNullOrWhiteSpace(NewsSourceUrlTextBox.Text))
            {
                NewsSourceNameTextBox.Text = NewsSourceNameTextBox.Text.Trim();
                NewsSourceUrlTextBox.Text = NewsSourceUrlTextBox.Text.Trim();

                string rawUri = NewsSourceUrlTextBox.Text.Replace("http", "").
                    Replace("https", "").Replace("://", "").Replace("www.", "");

                if (NewsSources.Where(source =>
                {
                    return source.Source.
                        AbsoluteUri.Contains(rawUri);
                })
                .Count() == 0)
                {

                    Uri url;
                    if ((Uri.TryCreate(NewsSourceUrlTextBox.Text,
                        UriKind.Absolute, out url)
                        && url.Scheme == Uri.UriSchemeHttp))
                    {
                        NewsSource newSource =
                            new NewsSource(NewsSourceNameTextBox.Text, url);

                        NewsSources.Add(newSource);
                        AddedSources.Add(newSource);
                        // Empty the TextBoxs.
                        NewsSourceNameTextBox.Text = "";
                        NewsSourceUrlTextBox.Text = "";
                    }
                    else
                    {
                        // Present a MessageBox popup to the user,
                        // indicating an error.
                        MessageBoxButton buttons = MessageBoxButton.OK;
                        MessageBoxImage icon = MessageBoxImage.Error;
                        MessageBox.Show("Feed url is not valid", "Error",
                            buttons, icon);
                    }
                }
                else
                {
                    // Present a MessageBox popup to the user,
                    // indicating an error.
                    MessageBoxButton buttons = MessageBoxButton.OK;
                    MessageBoxImage icon = MessageBoxImage.Error;
                    MessageBox.Show("A feed with this URL allready exists",
                        "Error", buttons, icon);
                }
            }
            else
            {
                // Present a MessageBox popup to the user, indicating an error.
                MessageBoxButton buttons = MessageBoxButton.OK;
                MessageBoxImage icon = MessageBoxImage.Error;
                MessageBox.Show("Publisher name and Feed url cannot be empty",
                    "Error", buttons, icon);
            }
        }
Exemple #48
0
        /// <summary>
        /// Reads a JSON file with news sources and saves in archivist.
        /// </summary>
        /// <param name="archivist">
        /// The <c>Archivist</c> instance with database access.
        /// </param>
        /// <param name="file">
        /// The path to the JSON-file containing <c>NewsSource</c>s.
        /// </param>
        public static void SeedNewsSources(Archivist archivist, string file)
        {
            List<NewsSource> newsSources = new List<NewsSource>();

            string json = File.ReadAllText(file, UTF8Encoding.UTF8);
            try
            {
                // Parse JSON and assign various values.
                var values = JArray.Parse(json);

                for (int i = 0; i < values.Count; i++)
                {
                    // Parse and add news source to list.
                    string name = values[i]["name"].ToString();
                    string url = values[i]["url"].ToString();
                    try
                    {
                        Uri uri = new Uri(url);
                        NewsSource newsSource = new NewsSource(name, uri);
                        newsSources.Add(newsSource);
                    }
                    catch (UriFormatException)
                    {
                        Console.WriteLine("Could not parse news item URL.");
                    }
                }

            }
            catch (Newtonsoft.Json.JsonReaderException)
            {
                Console.WriteLine("Error parsing news source");
            }

            // Add to database.
            archivist.AddNewsSources(newsSources);
        }
        void PlatformNewsManager_SourceRemovedEvent(NewsManager manager, NewsSource source)
        {
            SystemMonitor.CheckError(_persistenceHelper.Delete<NewsSource>(new NewsSource[] { (source) }), "Failed to delete source from DB.");

            source.PersistenceDataUpdatedEvent -= new GeneralHelper.GenericDelegate<IDBPersistent>(source_PersistenceDataUpdatedEvent);
            source.ItemsAddedEvent -= new NewsSource.ItemsUpdateDelegate(source_ItemsAddingAcceptEvent);
            source.ItemsUpdatedEvent -= new NewsSource.ItemsUpdateDelegate(source_ItemsUpdatedEvent);

            _persistenceHelper.Delete<NewsSource>(source);

            _persistenceHelper.Delete<RssNewsItem>(new MatchExpression("NewsSourceId", source.Id));
        }
        void source_ItemsAddingAcceptEvent(NewsSource source, IEnumerable<NewsItem> items)
        {
            List<RssNewsItem> rssItems = new List<RssNewsItem>();
            foreach (RssNewsItem item in items)
            {
                if (item.IsPersistedToDB == false)
                {
                    rssItems.Add(item);
                }
            }

            if (rssItems.Count > 0)
            {
                _persistenceHelper.Insert<RssNewsItem>(rssItems, new KeyValuePair<string, object>("NewsSourceId", source.Id));
            }
        }
Exemple #51
0
        public RSSHotNewsBG()
        {
            NewsSource nSource;

            nSource = new NewsSource();
            nSource.Title = "Звездите";
            nSource.URL = "http://hotnews.bg/rss.php?type=1";
            nSource.DefCategory = "1";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "На микрофона";
            nSource.URL = "http://hotnews.bg/rss.php?type=11";
            nSource.DefCategory = "11";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Hollywood";
            nSource.URL = "http://hotnews.bg/rss.php?type=7";
            nSource.DefCategory = "7";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Фолк";
            nSource.URL = "http://hotnews.bg/rss.php?type=6";
            nSource.DefCategory = "6";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Риалити";
            nSource.URL = "http://hotnews.bg/rss.php?type=13";
            nSource.DefCategory = "13";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Събития";
            nSource.URL = "http://hotnews.bg/rss.php?type=14";
            nSource.DefCategory = "14";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Издънки";
            nSource.URL = "http://hotnews.bg/rss.php?type=15";
            nSource.DefCategory = "15";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Top stories";
            nSource.URL = "http://hotnews.bg/rss.php?type=8";
            nSource.DefCategory = "8";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Fashionista";
            nSource.URL = "http://hotnews.bg/rss.php?type=16";
            nSource.DefCategory = "16";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Любопитно";
            nSource.URL = "http://hotnews.bg/rss.php?type=2";
            nSource.DefCategory = "2";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Hot";
            nSource.URL = "http://hotnews.bg/rss.php?type=18";
            nSource.DefCategory = "18";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Спорт";
            nSource.URL = "http://hotnews.bg/rss.php?type=19";
            nSource.DefCategory = "19";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Криминално";
            nSource.URL = "http://hotnews.bg/rss.php?type=20";
            nSource.DefCategory = "20";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Интимно";
            nSource.URL = "http://hotnews.bg/rss.php?type=4";
            nSource.DefCategory = "4";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Съдби";
            nSource.URL = "http://hotnews.bg/rss.php?type=5";
            nSource.DefCategory = "5";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Красота";
            nSource.URL = "http://hotnews.bg/rss.php?type=10";
            nSource.DefCategory = "10";
            _NSource.Add(nSource);

            nSource = new NewsSource();
            nSource.Title = "Култура";
            nSource.URL = "http://hotnews.bg/rss.php?type=12";
            nSource.DefCategory = "12";
            _NSource.Add(nSource);
        }
        void source_ItemsUpdatedEvent(NewsSource source, IEnumerable<NewsItem> items)
        {
            List<RssNewsItem> rssItems = new List<RssNewsItem>();
            foreach (RssNewsItem item in items)
            {
                rssItems.Add(item);
            }

            _persistenceHelper.UpdateToDB<RssNewsItem>(rssItems, null);
        }
Exemple #53
0
        public ActionResult CreateNewsSource(NewsSource type)
        {
            type.LanguageId = Int16.Parse(this.Request.Form.Get("LanguageList"));
            type.NewsSourceTypeId = Int16.Parse(this.Request.Form.Get("NewsSourceTypeList"));
            if (ModelState.IsValid)
            {
                if (type.NewsSourceId == 0)
                {
                    db.NewsSources.Add(type);
                }
                else
                {
                    db.Entry(type).State = EntityState.Modified;
                }
                db.SaveChanges();
                return RedirectToAction("Details", new { id = type.CompanyId });
            }

            ViewBag.LanguageList = new SelectList(db.Language.ToList(), "Culture", "Title");
            ViewBag.NewsSourceTypeList = new SelectList(db.NewsSourceTypes.ToList(), "NewsSourceTypeId", "Title", type.NewsSourceTypeId);
            return View(type);
        }
        void PlatformNewsManager_SourceAddedEvent(NewsManager manager, NewsSource source)
        {
            if (source.IsPersistedToDB == false)
            {// Already persisted to DB.
                SystemMonitor.CheckError(_persistenceHelper.InsertDynamicType<NewsSource>(source, "Type"), "Failed to add source to DB.");
            }

            source.PersistenceDataUpdatedEvent += new GeneralHelper.GenericDelegate<IDBPersistent>(source_PersistenceDataUpdatedEvent);
            source.ItemsAddedEvent += new NewsSource.ItemsUpdateDelegate(source_ItemsAddingAcceptEvent);
            source.ItemsUpdatedEvent += new NewsSource.ItemsUpdateDelegate(source_ItemsUpdatedEvent);

            // AddElement the items already in the source.
            foreach (string channelName in source.ChannelsNames)
            {
                source_ItemsAddingAcceptEvent(source, source.GetAllItemsFlat < NewsItem > ().AsReadOnly());
            }
        }
Exemple #55
0
 public ActionResult CreateNewsSource(int companyid = 0, int id = 0)
 {
     Company company = db.Companies.Find(companyid);
     if (company == null)
         HttpNotFound();
     NewsSource newsSource = new NewsSource();
     if (id == 0)
         newsSource.CompanyId = companyid;
     else
         newsSource = db.NewsSources.Find(id);
     ViewBag.NewsSourceTypeList = new SelectList(db.NewsSourceTypes.ToList(), "NewsSourceTypeId", "Title", newsSource.NewsSourceTypeId);
     ViewBag.LanguageList = new SelectList(db.Language.ToList(), "LanguageId", "Title", newsSource.LanguageId);
     return View(newsSource);
 }
Exemple #56
0
 /// <summary>
 /// Removes the specified <c>NewsSource</c> from the storage device.
 /// </summary>
 /// <param name="newsSource">
 /// The <c>NewsSource</c> to remove from the storage device.
 /// </param>
 public abstract void RemoveNewsSource(NewsSource newsSource);
Exemple #57
0
 /// <summary>
 /// Updates a <c>NewsSource</c> in the storage device.
 /// </summary>
 /// <param name="newsSource">
 /// The <c>NewsSource</c> to update.
 /// </param>
 public abstract void UpdateNewsSource(NewsSource newsSource);
        /// <summary>
        /// Handle enable changed, to load items from DB for source (since it may not have any loaded;
        /// implementing an load "On demand" mechanism"); also store change of Enabled to DB.
        /// </summary>
        /// <param name="source"></param>
        protected override void source_EnabledChangedEvent(NewsSource source)
        {
            if (source.Enabled)
            {// Extract items from DB, since it may have none at this point.
                List<RssNewsItem> items =
                    _persistenceHelper.Select<RssNewsItem>(new MatchExpression("NewsSourceId", source.Id), null);
                foreach (RssNewsItem item in items)
                {
                    item.Source = source;
                }

                // Handle the relation to persistence.
                source.AddItems(items.ToArray());

            }

            // Update source to DB.
            source_PersistenceDataUpdatedEvent(source);

            base.source_EnabledChangedEvent(source);
        }
        public NewsSourceSettingsControl(NewsSource source)
        {
            InitializeComponent();

            _source = source;
        }
Exemple #60
0
 /// <summary>
 /// Adds a <c>NewsSource</c> to the storage device.
 /// </summary>
 /// <param name="newsSource">
 /// The <c>NewsSource</c> to add to the storage device.
 /// </param>
 public abstract void AddNewsSource(NewsSource newsSource);