Exemplo n.º 1
0
        public JsonResult RunScraper(int batchSize)
        {
            var scraper = UFOScraper.GetSingletonScraper();

            scraper.BatchSize = 100;

            // turn on the scraper if its not already on
            if (scraper.IsRunning)
            {
                return(new JsonResult("{ \"success\":false, msg:\"Scraper is already running!\" }"));
            }

            var currentIds = _context.Reports.Select(r => r.ReportId).ToHashSet();

            new TaskFactory()
            .StartNew(() =>
            {
                try { return(scraper.GetReports(currentIds)); }
                catch (Exception) { }
                return(new List <Report>());
            }).ContinueWith((result) =>
            {
                if (result.IsCompletedSuccessfully)
                {
                    var newReports = result.Result;
                    try
                    {
                        _context.Reports.AddRange(newReports);
                        _context.SaveChanges();
                    }
                    catch (Exception) { }
                }
            });

            return(new JsonResult(new { success = true }));
        }
Exemplo n.º 2
0
        public JsonResult HaltScraper()
        {
            UFOScraper.GetSingletonScraper().Halt = true;

            return(new JsonResult("{ \"success\":true }"));
        }