예제 #1
0
파일: Program.cs 프로젝트: olegall/pbl
        public static void Main(string[] args)
        {
            var isService = args.Contains(RunAsServiceArg);
            var builder   = CreateWebHostBuilder(args.Where(a => a != RunAsServiceArg).ToArray());

            if (isService)
            {
                var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
                var pathToContentRoot = Path.GetDirectoryName(pathToExe);
                builder.UseContentRoot(pathToContentRoot);
            }

            _context = new ApplicationContext();
            InitControllers();
            LightsService.Init();
            ModbusControllerAdapter.InvokePollingFinished();
            var host = builder.Build();

            if (isService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: olegall/pbl
        private static void InitControllers()
        {
            if (!_context.Database.CanConnect())
            {
                return;
            }

            _controllers = new ConcurrentDictionary <long, IControllerAdapter>();
            foreach (var c in _context.Controllers)
            {
                try
                {
                    var controller = new ModbusControllerAdapter(c.Id, c.SlaveAddress, c.Address, c.Port);
                    controller.Init(receiveTimeout, sendTimeout);
                    if (!_controllers.TryAdd(c.Id, controller))
                    {
                        throw new Exception("Could not add controller to collection");
                    }
                }
                catch
                {
                }
            }
        }