static void Main() { if (!Environment.UserInteractive) { // Startup as service. ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); } else { // Startup as application try { var options = System.Configuration.ConfigurationManager.GetSection("CrawlerOptions") as CrawlerOptions; logger.Info("Config is {0}", options); var crawler = new Crawler(options); crawler.Start(); } catch (Exception ex) { logger.Fatal(ex); } } }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { try { var options = System.Configuration.ConfigurationManager.GetSection("CrawlerOptions") as CrawlerOptions; logger.Info("Config is {0}", options); var crawler = new Crawler(options); crawler.Start(); } catch (Exception ex) { logger.Fatal(ex); } }
static void Main() { if (!Environment.UserInteractive) { // Startup as service. ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new CrawlerSerivce() }; ServiceBase.Run(ServicesToRun); } else { // Startup as application try { var cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var localSections = cfg.Sections.Cast<ConfigurationSection>() .Where(s => s.SectionInformation.IsDeclared); foreach (var i in localSections) { var options = System.Configuration.ConfigurationManager.GetSection(i.SectionInformation.SectionName) as CrawlerOptions; if (options.Run && i.SectionInformation.SectionName.Contains("CrawlerOptions")) { logger.Info(options.Name + " Config is {0}", options); var crawler = new Crawler(options); crawler.Start(); } } } catch (Exception ex) { logger.Fatal(ex); } } }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { var RepeatTime = ConfigurationManager.GetSection("TimeInterval") as TimeInterval; try { var cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var localSections = cfg.Sections.Cast<ConfigurationSection>() .Where(s => s.SectionInformation.IsDeclared); foreach (var i in localSections) { var options = ConfigurationManager.GetSection(i.SectionInformation.SectionName) as CrawlerOptions; if (options.Run && i.SectionInformation.SectionName.Contains("CrawlerOptions")) { logger.Info(options.Name + " Config is {0}", options); var crawler = new Crawler(options); crawler.Start(); } } RepeatTime = ConfigurationManager.GetSection("TimeInterval") as TimeInterval; logger.Info("[Report TimeR]" + RepeatTime.time); _timer.Stop(); _timer.Interval = RepeatTime.time; //Set your new interval here _timer.Start(); } catch (Exception ex) { logger.Fatal(ex); logger.Info("[Report TimeR]" + RepeatTime.time); _timer.Stop(); _timer.Interval = RepeatTime.time; //Set your new interval here _timer.Start(); } }