public MainForm() { log4net.Config.XmlConfigurator.Configure(); log.Info("Starting application."); string comPortString = ConfigurationManager.AppSettings["comPort"]; if (!string.IsNullOrEmpty(comPortString)) _serialPort = comPortString; InitializeComponent(); _handler = new InsteonHandler(_serialPort, false); foreach (string key in _handler.AllDevices.Keys) { _allDevices.Add(_handler.AllDevices[key]); } _handler.InsteonTrafficDetected += new InsteonHandler.InsteonTrafficHandler(InsteonTrafficDetected); }
public InsteonWebService(InsteonHandler handler) { _handler = handler; }
protected override void OnStart(string[] args) { log.Info("Starting Insteon Service."); try { string serialPort = ConfigurationManager.AppSettings["SerialPort"]; if (!string.IsNullOrEmpty(serialPort)) _serialPort = serialPort; string latString = ConfigurationManager.AppSettings["Latitude"]; if (!double.TryParse(latString, out _latitude)) _latitude =35.773; string longitudeString = ConfigurationManager.AppSettings["Longitude"]; if (!double.TryParse(longitudeString, out _longitude)) _longitude = -78.888893; SetServiceState(State.SERVICE_START_PENDING); _handler = new InsteonHandler(serialPort, true); _handler.InsteonTrafficDetected += new InsteonHandler.InsteonTrafficHandler(_handler_InsteonTrafficDetected); _handler.PartyDetected += new InsteonHandler.PartyHandler(_handler_PartyDetected); //log.InfoFormat("Setting up random devices, handler has {0} devices", _handler.AllDevices.Count); //if (_handler.AllDevices.ContainsKey("22AEB1")) // entry // _randomDevices.Add(_handler.AllDevices["22AEB1"]); //if (_handler.AllDevices.ContainsKey("1FB523")) // stairs // _randomDevices.Add(_handler.AllDevices["1FB523"]); //if (_handler.AllDevices.ContainsKey("192A4D")) // kitchen multi // _randomDevices.Add(_handler.AllDevices["192A4D"]); //if (_handler.AllDevices.ContainsKey("1BBECC")) // living room // _randomDevices.Add(_handler.AllDevices["1BBECC"]); //if (_handler.AllDevices.ContainsKey("22A60C")) // front bedroom // _randomDevices.Add(_handler.AllDevices["22A60C"]); //log.InfoFormat("Finished adding {0} random devices.", _randomDevices.Count); Thread serviceStartThread = new Thread(delegate() { // ive confused myself a little while im running 2 versions of these threads _wcfHostThread = new Thread(new ThreadStart(HostService)); _wcfHostThread.Start(); //_iisExpressThread = new Thread(new ThreadStart(RunIISExpress)); //_iisExpressThread.Start(); SetServiceState(State.SERVICE_RUNNING); }); serviceStartThread.Start(); serviceStartThread.Join(); } catch (Exception ex) { log.Error("Error occurred while Starting Application."); log.Error(ex.Message); log.Error(ex.StackTrace); } log.Info("Finished Starting Insteon Service."); }