Пример #1
0
        static void Main(string[] args)
        {
            var monitors = new List <EndpointMonitor>();

            foreach (var endpoint in endpointRepo.GetAll())
            {
                var monitor = new EndpointMonitor(endpoint.Url, endpoint.CheckInterval);
                monitor.EndpointChecked += Monitor_EndpointChecked;
                monitor.Start();
                monitors.Add(monitor);
            }

            Console.WriteLine("Press the Enter key to exit.");
            Console.ReadLine();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IEndpointRepository repository)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            var timerPeriod = Int32.Parse(Configuration.GetSection("AppSettings").GetSection("TimerPeriod").Value);

            _timer = new Timer(new TimerCallback(s =>
            {
                var heartbeats = repository.GetAll();

                var httpClient = new HttpClient();
                foreach (var heartbeat in heartbeats)
                {
                    try
                    {
                        httpClient.GetAsync(heartbeat.Url);
                    }
                    catch (Exception) { }
                }
            }),
                               null,
                               1000,
                               timerPeriod);
        }
Пример #3
0
 public IActionResult Index()
 {
     return(View(_repository.GetAll()));
 }
        public async Task <IActionResult> GetAll()
        {
            var result = await _endpointRepository.GetAll();

            return(new OkObjectResult(ToJson(result)));
        }
 public IEnumerable <Endpoint> Get([FromServices] IEndpointRepository repository)
 {
     return(repository.GetAll());
 }