Ejemplo n.º 1
0
        private static MqttClientProxyCollection TryInitializeMqtt(MqttConfig config)
        {
            MqttClientProxyCollection result = new MqttClientProxyCollection();

            foreach (MqttAddress addr in config.DataBrokerAddress)
            {
                IMqttClient client = CreateMqttClient(addr);
                if (client != null)
                {
                    result.Add(new MqttClientProxy(client, addr));
                }
            }
            return(result);
        }
Ejemplo n.º 2
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;
        }