Ejemplo n.º 1
0
 public CrsController(
     ILogger <CrsController> logger,
     ICrsService crsService
     )
 {
     _logger     = logger;
     _crsService = crsService;
 }
Ejemplo n.º 2
0
        public async void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            ILogger <Startup> logger,
            ICrsService crsService,
            IStationService stationService,
            IUpdateCheckService updateCheckService)
        {
            logger.LogInformation("Configuring Huxley 2 web API application");

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            // UseResponseCaching doesn't appear to be necessary to enable the ResponseCache attribute
            // but it is required to use VaryByQueryKeys in the future so enable middleware to be safe
            app.UseResponseCaching();

            // CORS must be called after UseRouting and before UseEndpoints to function correctly
            // The `Access-Control-Allow-Origin` header will not be added to normal GET responses
            // An `Origin` header must be on the request (for a different domain) for CORS to run
            // https://docs.microsoft.com/en-us/aspnet/core/security/cors
            app.UseCors(config => config.AllowAnyOrigin());

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapRazorPages();
            });

            logger.LogInformation("Huxley 2 web API application configured");

            try
            {
                logger.LogInformation("Loading CRS station codes from remote source");
                await crsService.LoadCrsCodes();

                await stationService.LoadStations();

                if (_enableUpdateCheck)
                {
                    logger.LogInformation("Checking for any available updates to Huxley");
                    await updateCheckService.CheckForUpdates();
                }
            }
            catch (Exception e) when(
                e is CrsServiceException ||
                e is UpdateCheckServiceException
                )
            {
                logger.LogError(e, "Non-fatal startup failure");
            }

            logger.LogInformation("Huxley 2 web API application ready");
        }
Ejemplo n.º 3
0
 public MapperService(
     ILogger <MapperService> logger,
     IAccessTokenService accessTokenService,
     ICrsService crsService,
     IDateTimeService dateTimeService
     )
 {
     _logger             = logger;
     _accessTokenService = accessTokenService;
     _crsService         = crsService;
     _dateTimeService    = dateTimeService;
 }
Ejemplo n.º 4
0
        public DelaysService(
            ILogger <DelaysService> logger,
            IStationBoardService stationBoardService,
            ICrsService crsService,
            IConfiguration config,
            IDateTimeService dateTimeService
            )
        {
            _logger = logger;
            _stationBoardService = stationBoardService;
            _crsService          = crsService;
            _config          = config;
            _dateTimeService = dateTimeService;

            _logger.LogInformation("Loading Delay Minutes Threshold from settings");
            if (!int.TryParse(_config["DelayMinutesThreshold"], out _delayMinutesThreshold))
            {
                _delayMinutesThreshold = 5; // default 5 minutes if can't read configuration
            }
            _logger.LogInformation($"Threshold: {_delayMinutesThreshold} minutes");
        }