コード例 #1
0
ファイル: Program.cs プロジェクト: iamlos/Seo.Crawler.Service
        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);
                }

            }


        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        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);
                }

            }


        }
コード例 #4
0
        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();
            }
           

        
        }