private static async Task <IEnumerable <PageStatus> > HitPages() { var listPageStatus = new List <PageStatus>(); try { using (var repoPages = new PagesRepository()) { using (var repoPageStatus = new PageStatusRepository()) { //Get page with Monitor bit on. var pages = repoPages.GetAllMonitor(); //var pages = repoPages.GetAllProdMonitor(); //var pages = repoPages.GetAllStgMonitor(); var pageGetter = new PageGetter(); foreach (var page in pages) { var pageStats = new PageStats { Url = page.Url }; var stats = await pageGetter.HTTP_GET(pageStats); var pageStatus = new PageStatus { Url = stats.Url, ResponseTime = stats.ResponseTime, ContentLength = stats.ContentLength, ExceptionMessage = stats.ExceptionMessage, Status = stats.Status.ToString(), Created = DateTime.Now }; repoPageStatus.Add(pageStatus); repoPageStatus.SaveChanges(); listPageStatus.Add(pageStatus); } } } } catch (Exception ex) { // ReSharper disable once UnusedVariable var msg = ex.Message; } return(listPageStatus); }
static void Main() { //DirectAccess(); //const string url = "http://pagehitterweb.azurewebsites.net/api/Values"; //const string url = "http://localhost:9476/api/Values/?html=false&page=https://www.findlay.edu"; //const string url = "http://localhost:9476/api/Values/?html=false&page="; const string url = "http://pagehitterweb.azurewebsites.net/api/Values?html=false&page="; //const string url = "http://localhost:9476/api/Values/?json=true"; while (true) { using (var pagesRepository = new PagesRepository()) { using (var delayRepository = new DelayRepository()) { var delay = delayRepository.GetDelay(); var pages = pagesRepository.GetAllMonitor(); var interPageSleepTime = new TimeSpan(0, delay.PageHour, delay.PageMinute, delay.PageSecond); //Hit each page from web job. foreach (var page in pages) { var msg = WebServiceAccess(url + page.Url, interPageSleepTime).Result; //Console.WriteLine(msg); } //Sleep before hitting collection of pages again //Console.WriteLine($"Sleeping {delay.IterationMinute} minutes {delay.IterationSecond} seconds pageDelay: {delay.PageSecond}"); var sleepTime = new TimeSpan(0, delay.IterationHour, delay.IterationMinute, delay.IterationSecond); //1 min Thread.Sleep(sleepTime); } } } //Console.WriteLine("complete"); //Console.ReadLine(); }
private static async Task<IEnumerable<PageStatus>> HitPages() { var listPageStatus = new List<PageStatus>(); try { using (var repoPages = new PagesRepository()) { using (var repoPageStatus = new PageStatusRepository()) { //Get page with Monitor bit on. var pages = repoPages.GetAllMonitor(); //var pages = repoPages.GetAllProdMonitor(); //var pages = repoPages.GetAllStgMonitor(); var pageGetter = new PageGetter(); foreach (var page in pages) { var pageStats = new PageStats { Url = page.Url }; var stats = await pageGetter.HTTP_GET(pageStats); var pageStatus = new PageStatus { Url = stats.Url, ResponseTime = stats.ResponseTime, ContentLength = stats.ContentLength, ExceptionMessage = stats.ExceptionMessage, Status = stats.Status.ToString(), Created = DateTime.Now }; repoPageStatus.Add(pageStatus); repoPageStatus.SaveChanges(); listPageStatus.Add(pageStatus); } } } } catch (Exception ex) { // ReSharper disable once UnusedVariable var msg = ex.Message; } return listPageStatus; }