public Worker(ILogger <Worker> logger, IConnectionMultiplexer connex, AlarmConfig alarmConfig)
        {
            _logger           = logger;
            _redis            = connex;
            _alarmConfig      = alarmConfig;
            zone_descriptions = _alarmConfig.Zones;

            _redis_db  = _redis.GetDatabase();
            _botClient = new TelegramBotClient(_alarmConfig.BotAPIKey);
            var me = _botClient.GetMeAsync().Result;

            _logger.LogInformation("Telegram bot initialised: " + me.FirstName);
            _botClient.OnMessage += _botClient_OnMessage;
        }
Beispiel #2
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((hostContext, config) => {
            if (configurationPath != null && configurationPath.Length > 0)
            {
                config.AddJsonFile(configurationPath, false, false);
            }
        })
        .ConfigureServices((hostContext, services) =>
        {
            IConfiguration configuration = hostContext.Configuration;
            AlarmConfig alarmConfig      = configuration.GetSection("Alarm").Get <AlarmConfig>();
            RedisConfig redisConfig      = configuration.GetSection("Redis").Get <RedisConfig>();

            services.AddSingleton(alarmConfig);
            services.AddSingleton(redisConfig);
            services.AddSingleton <IConnectionMultiplexer>(ConnectionMultiplexer.Connect(String.Format("{0}:{1}, password={2}", redisConfig.ip, redisConfig.port, redisConfig.password)));

            // services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect(alarmConfig.RedisConnection));
            services.AddHostedService <Worker>();
        });