private void LoadConfigModbusMapper(IServiceCollection services) { string sqlite_conn_str = Configuration.GetConnectionString("sqlite"); SqliteAccessManager dam = new SqliteAccessManager(sqlite_conn_str); ModbusSystem modbusList = Configuration.GetSection("Modbus").Get <ModbusSystem>(); using (DataAccess da = new DataAccess(dam.SessionFactory)) { modbusList.GroupPoints = da.Select <GroupPoint>(); modbusList.GroupDigitalPoints = da.Select <EventGroupPoint>(); services.AddSingleton(modbusList); services.AddSingleton <IModbusFactory, ModbusConnectionFactory>(); EventMap map = new EventMap(); map.Load(); services.AddSingleton(map); AbsMqttBase.SetDefaultLoggerName("nlog.config", true); EventPublisherWorker worker = new EventPublisherWorker(); worker.Initialize(); services.AddSingleton(worker); services.AddSingleton <Microsoft.Extensions.Hosting.IHostedService, ModbusBackgroundService>(); services.AddSingleton <Microsoft.Extensions.Hosting.IHostedService, ModbusDigitalProcessingService>(); services.AddSingleton <Microsoft.Extensions.Hosting.IHostedService, ControlSubscribeWorker>(); //services.AddSingleton<Microsoft.Extensions.Hosting.IHostedService, ModbusDigitalProcessingService>(); } }
static void Main(string[] args) { AppSetting appconfig = new AppSetting("appsettings.json"); AbsMqttBase.SetDefaultLoggerName("nlog.config", true); string mysql_connectionString = appconfig.GetConnectionString("peiudb"); ISessionFactory sessionFactory = CreateSessionFactory(mysql_connectionString, appconfig.GetAssembly()); var redisConfiguration = appconfig.GetSection <RedisConfiguration>("redis"); ConnectionMultiplexer conn = ConnectionMultiplexer.Connect(redisConfiguration.ConfigurationOptions); // NLog: setup the logger first to catch all errors NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("nlog.config"); Console.CancelKeyPress += Console_CancelKeyPress; EventSubscribeWorker worker = new EventSubscribeWorker(sessionFactory, conn); CancellationToken token = cancellationTokenSource.Token; worker.Initialize(); while (true) { try { token.ThrowIfCancellationRequested(); Task workTask = worker.MqttSubscribeAsync(token); workTask.Wait(); Task.Delay(100); } catch (Exception ex) { } } }
public static void Main(string[] args) { //Services.HTMLGenerator gen = new Services.HTMLGenerator(); //gen.GenerateHtml("NotifyEmail.html", new { Company = "대건소프트", Name = "김기룡" }); // NLog: setup the logger first to catch all errors var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); AbsMqttBase.SetDefaultLoggerName("nlog.config", true); try { logger.Debug("init main"); CreateWebHostBuilder(args).Build().Run(); } catch (Exception ex) { //NLog: catch setup errors logger.Error(ex, "Stopped program because of exception"); throw; } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) NLog.LogManager.Shutdown(); } }
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); } }
public static void Main(string[] args) { //PythonEngine.Initialize(); var logger = LogManager.GetCurrentClassLogger(); ForceMode = args.Length > 0 && args[0] == "FORCEMODE"; AbsMqttBase.SetDefaultLoggerName("nlog.config", true); CreateHostBuilder(args).Build().Run(); //PythonEngine.Shutdown(); }
public static void Main(string[] args) { AbsMqttBase.SetDefaultLoggerName("nlog.config", true); var logger = NLog.LogManager.GetCurrentClassLogger(); try { CreateHostBuilder(args).Build().Run(); } catch (Exception ex) { logger.Error(ex); } finally { NLog.LogManager.Shutdown(); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); AbsMqttBase.SetDefaultLoggerName("nlog.config", true); EventPublisherWorker worker = new EventPublisherWorker(); worker.Initialize(); CancellationTokenSource tk = new CancellationTokenSource(); while (true) { Console.Write("Input the Event Code: "); string code = Console.ReadLine(); if (int.TryParse(code, out int EventCode)) { Task t = worker.PublishEvent(6, "PCS1", EventCode, Events.Alarm.EventStatus.New, tk.Token); t.Wait(); } } }
public static void Main(string[] args) { // NLog: setup the logger first to catch all errors AbsMqttBase.SetDefaultLoggerName("nlog.config", true); var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); try { logger.Error("DEBUG~ INIT"); //LogFactory = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config"); //var logger = LogFactory.GetCurrentClassLogger(); //logger.Info("start"); CreateWebHostBuilder(args).Build().Run(); } catch (Exception ex) { logger.Error(ex.Message + "\n" + ex.StackTrace); throw; } finally { NLog.LogManager.Shutdown(); } }
public MainWindow() { InitializeComponent(); AbsMqttBase.SetDefaultLoggerName("DefaultLogger"); }