Ejemplo n.º 1
0
        public PVBackgroundService(NLog.ILogger loggerFactory,
                                   MqttClientProxyCollection mqttClientProxies, RedisConnectionFactory redisFactory,
                                   IConfiguration configuration)
        {
            logger       = loggerFactory;
            config       = configuration;
            mqtt_clients = mqttClientProxies;
            mqtt_config  = configuration.GetSection("MQTTBrokers").Get <MqttConfig>();
            SiteId       = configuration.GetSection("SiteId").Get <int>();
            string mssql_conn = configuration.GetConnectionString("mssql");
            string etri_conn  = configuration.GetConnectionString("etridb");

            PollInterval        = configuration.GetSection("PollInterval").Get <TimeSpan>();
            redis               = redisFactory.Connection().GetDatabase(1);
            DeviceName          = configuration.GetSection("DeviceName").Get <string>();
            redisDeviceName     = configuration.GetSection("RedisKeyName").Get <string>();
            sessionFactory      = new MsSqlAccessManager().CreateSessionFactory(mssql_conn);
            mysqlSessionFactory = new MySqlAccessManager(etri_conn, Assembly.GetExecutingAssembly()).SessionFactory;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            // NLog: setup the logger first to catch all errors
            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("nlog.config");
            logger = NLog.LogManager.Configuration.LogFactory.GetLogger("");
            var redisConfiguration = config.GetSection("redis").Get <RedisConfiguration>();
            var mqtt_informations  = config.GetSection("MQTTBrokers").Get <MqttConfig>();
            RedisConnectionFactory redisConnectionFactory = new RedisConnectionFactory(redisConfiguration);
            string mssql_conn = config.GetConnectionString("mssql");
            //ISessionFactory sessionFactory = new MsSqlAccessManager().CreateSessionFactory(mssql_conn);
            var proxy = TryInitializeMqtt(mqtt_informations);

            source = new CancellationTokenSource();
            PVBackgroundService service = new PVBackgroundService(logger, proxy, redisConnectionFactory, config);
            Task worker = service.RunWorkerAsync(source.Token);

            worker.Wait();
        }