Exemplo n.º 1
0
        static void Main(string[] args)
        {
            token = new CancellationTokenSource();
            System.Console.CancelKeyPress += Console_CancelKeyPress;
            NLog.LogManager.Configuration  = new NLog.Config.XmlLoggingConfiguration("nlog.config");
            AbsMqttBase.SetDefaultLoggerName("nlog.config", true);
            logger = NLog.LogManager.Configuration.LogFactory.GetLogger("");

            AppSetting            setting               = new AppSetting("appsettings.json");
            ModbusConfig          pvmodbusConfig        = setting.GetSection <ModbusConfig>("PVModbus");
            ModbusConfig          essmodbusConfig       = setting.GetSection <ModbusConfig>("ESSModbus");
            var                   redisConfiguration    = setting.GetSection <RedisConfiguration>("redis");
            ConnectionMultiplexer connectionMultiplexer = ConnectionMultiplexer.Connect(redisConfiguration.ConfigurationOptions);
            MysqlDataAccess       access = new MysqlDataAccess(setting.GetConnectionString("etridb"));
            RelayDataInformation  relayDataInformation = setting.GetSection <RelayDataInformation>("Information");

            try
            {
                using (RelayDevicePublisher publisher = new RelayDevicePublisher(relayDataInformation, pvmodbusConfig, essmodbusConfig, access, connectionMultiplexer, logger))
                {
                    publisher.Initialize();
                    Task t = publisher.RunningAsync(token.Token);
                    t.Wait();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Exemplo n.º 2
0
 public RelayDevicePublisher(RelayDataInformation dataInformation, ModbusConfig pvmodbusConfig, ModbusConfig essmodbusConfig, MysqlDataAccess dataAccess, ConnectionMultiplexer connectionMultiplexer, ILogger logger)
 {
     this.relayDataInformation = dataInformation;
     this.pvmodbusConfig       = pvmodbusConfig;
     this.essmodbusConfig      = essmodbusConfig;
     this.logger          = logger;
     this.mysqlDataAccess = dataAccess;
     redisDb = connectionMultiplexer.GetDatabase(1);
 }