Exemplo n.º 1
0
 /// <summary>
 /// Instantiates the controller taking a logger.
 /// </summary>
 /// <param name="logger">The logger to use for logging.</param>
 /// <param name="configuration">The configuration settings.</param>
 /// <param name="dbContext">The databse context to use for retrieving the values to return.</param>
 /// <param name="retryFeasibleHandler">The handler to check whether retry is feasible.</param>
 public BgpController(ILogger <RestController> logger, IConfiguration configuration, QueryResultDatabaseContext dbContext, IFailureRetryFilteringDataHandler retryFeasibleHandler)
 {
     this.logger               = logger ?? throw new ArgumentNullException(nameof(logger), "The logger to use is null");
     this.configuration        = configuration ?? throw new ArgumentNullException(nameof(configuration), "The configuration to use is null");
     this.dbContext            = dbContext ?? throw new ArgumentNullException(nameof(dbContext), "The database context to take the data from is null");
     this.retryFeasibleHandler = retryFeasibleHandler ?? throw new ArgumentNullException(nameof(retryFeasibleHandler), "The retry feasible handler singleton has not been provided by DI engine");
 }
        /// <summary>
        /// Constructs taking the logger.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="configuration">The service configuration.</param>
        /// <param name="hamnetDbAccess">The singleton instance of the HamnetDB access handler.</param>
        /// <param name="retryFeasibleHandler">The handler to check whether retry is feasible.</param>
        public BgpAquisitionService(ILogger <BgpAquisitionService> logger, IConfiguration configuration, IHamnetDbAccess hamnetDbAccess, IFailureRetryFilteringDataHandler retryFeasibleHandler)
        {
            this.logger               = logger ?? throw new ArgumentNullException(nameof(logger), "The logger has not been provided by DI engine");
            this.configuration        = configuration ?? throw new ArgumentNullException(nameof(configuration), "The configuration has not been provided by DI engine");
            this.retryFeasibleHandler = retryFeasibleHandler ?? throw new ArgumentNullException(nameof(retryFeasibleHandler), "The retry feasible handler singleton has not been provided by DI engine");

            this.hamnetDbPoller = new HamnetDbPoller(this.configuration, hamnetDbAccess ?? throw new ArgumentNullException(nameof(hamnetDbAccess), "The HamnetDB accessor singleton has not been provided by DI engine"));

            this.dataHandlers.Add(this.retryFeasibleHandler);
            this.dataHandlers.Add(new ResultDatabaseDataHandler(configuration, this.retryFeasibleHandler));
            this.dataHandlers.Add(new InfluxDatabaseDataHandler(configuration, this.hamnetDbPoller));
            this.dataHandlers = this.dataHandlers.OrderBy(h => h.Name).ToList();
        }
        /// <summary>
        /// Constructs taking the logger.
        /// </summary>
        /// <param name="logger">The logger to use.</param>
        /// <param name="configuration">The service configuration.</param>
        /// <param name="hamnetDbAccess">The singleton instance of the HamnetDB access handler.</param>
        /// <param name="retryFeasibleHandler">The handler to check whether retry is feasible.</param>
        public RssiAquisitionService(ILogger<RssiAquisitionService> logger, IConfiguration configuration, IHamnetDbAccess hamnetDbAccess, IFailureRetryFilteringDataHandler retryFeasibleHandler)
        {
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger), "The logger has not been provided by DI engine");
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration), "The configuration has not been provided by DI engine");
            this.retryFeasibleHandler = retryFeasibleHandler ?? throw new ArgumentNullException(nameof(retryFeasibleHandler), "The retry feasible handler singleton has not been provided by DI engine");

            this.dataHandlers.Add(this.retryFeasibleHandler);
            this.dataHandlers.Add(new ResultDatabaseDataHandler(configuration, this.retryFeasibleHandler));

            this.hamnetDbPoller = new HamnetDbPoller(this.configuration, hamnetDbAccess ?? throw new ArgumentNullException(nameof(hamnetDbAccess), "The HamnetDB accessor singleton has not been provided by DI engine"));

            IConfigurationSection influxSection = configuration.GetSection(Program.InfluxSectionKey);
            if ((influxSection != null) && influxSection.GetChildren().Any())
            {
                this.dataHandlers.Add(new InfluxDatabaseDataHandler(configuration, this.hamnetDbPoller));
            }
            else
            {
                this.logger.LogInformation($"Influx database disabled: No or empty '{Program.InfluxSectionKey}' section in configuration");
            }

            this.dataHandlers = this.dataHandlers.OrderBy(h => h.Name).ToList();
        }
 /// <summary>
 /// Construct for the given configuration.
 /// </summary>
 /// <param name="configuration">The configuration to construct for.</param>
 /// <param name="failureRetryFilteringDataHandler">The data handler to add retry information to the database set.</param>
 public ResultDatabaseDataHandler(IConfiguration configuration, IFailureRetryFilteringDataHandler failureRetryFilteringDataHandler)
 {
     this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration), "configuration is null when creating a ResultDatabaseDataHandler");
     this.failureRetryFilteringDataHandler = failureRetryFilteringDataHandler; // null allowed here in which case the penalty information is simply omitted
     this.hamnetDbConfig = this.configuration.GetSection(Program.RssiAquisitionServiceSectionKey);
 }