private void StartAlerting(IAlertChecker alertChecker, CancellationToken cancellationToken)
        {
            alertChecker.OnTemperatureTooLowAlert += AlertCheckingScheduler_OnTemperatureTooLowAlert;

            new Task(() =>
            {
                Logger.LogInformation("Starting alert detection.");
                while (!cancellationToken.IsCancellationRequested)
                {
                    alertChecker.CheckAndRaiseAlertIfNeeded(cancellationToken);
                    WaitForNextCycle(cancellationToken, 360);
                }
            }, TaskCreationOptions.LongRunning).Start();
        }
        public void Configure(IApplicationBuilder app, IHostApplicationLifetime hostApplicationLifetime, IWebHostEnvironment env, ILoggerFactory loggerFactory, IAlertChecker alertChecker)
        {
            loggerFactory.AddFile("Logs/weatherapi-{Date}.txt");
            Logger = loggerFactory.CreateLogger <Startup>();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            hostApplicationLifetime.ApplicationStarted.Register(
                () => StartAlerting(alertChecker, hostApplicationLifetime.ApplicationStopping));

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
 public Worker(ILogger <Worker> logger, IAlertChecker alertChecker)
 {
     _logger           = logger;
     this.alertChecker = alertChecker;
     alertChecker.OnTemperatureTooLowAlert += AlertCheckingScheduler_OnTemperatureTooLowAlert;
 }