public string AddFeed(string newFeed) { if (_ctx.Feeds.Any(f => f.Url == newFeed)) { return("This feed is already in DB!"); } _ctx.Feeds.Add(new Feed { Url = newFeed, Active = true }); _ctx.SaveChanges(); RssLogic.UpdateServerConnection(); return("Success !"); }
private void PerformDownload(object state) { //DataLayer.LogMessage(LogLevel.Service, "Download Invoked"); using (var context = new Db()) { Feed f = RssLogic.GetNextFeed(context); if (f != null) { //DataLayer.LogMessage(LogLevel.Feed, $"N Next feed {f.ID} {f.Url}"); RssLogic.ProcessFeed(f, context); //DataLayer.LogMessage(LogLevel.Feed, $"Completed feed {f.ID} {f.Url}"); context.SaveChanges(); } } thDownload.timer.Start(); }
protected override void OnStart(string[] args) { thDownload = new SynThread("Download", 5000, PerformDownload); thProcessArticles = new SynThread("ProcessingArticles", 1001, PerformArticleProcessing); thProcessShingles = new SynThread("ProcessingShingles", 1111, PerformShingleProcessing); //thIntrinio = new SynThread("Intrinio", 24000 * 3600 / 450, PerformIntrinio); //thIntrinio = new SynThread("Intrinio", 24000 * 3600 / 45, PerformIntrinio); RssLogic.UpdateServerConnection(); using (var ctx = new Db()) { RssLogic.AddNewFeedsFromResource(ctx); } StartThread(thDownload); //StartThread(thProcessShingles); StartThread(thProcessArticles); //StartThread(thIntrinio); }
private void PerformArticleProcessing(object state) { try { using (var ctx = new Db()) { ctx.Database.CommandTimeout = 120; ArticlesToProcess = ShingleLogic.GetNextArticles(ctx); if (ArticlesToProcess == null || ArticlesToProcess.Count == 0) { System.Threading.Tasks.Task.Delay(20000); } // Thread.Sleep(20000); else { foreach (var a in ArticlesToProcess) { var sw = Stopwatch.StartNew(); ShingleLogic.ProcessArticle(a); RssLogic.ScoreArticle(a); var ea = ctx.Articles.Include("Feed").Single(x => x.ID == a); string ticker = string.IsNullOrEmpty(ea.Ticker) ? "" : "Ticker:" + ea.Ticker + " "; DataLayer.LogMessage(LogLevel.Article, $"A {sw.ElapsedMilliseconds}ms ID:{a} Score:{100 * (ea.ScoreMin + ea.ScoreMax)} {ticker}{ea.Title}"); } } } } catch (Exception e) { DataLayer.LogException(e); } finally { thProcessArticles.timer.Start(); } }