private void LoadShedUnit(List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, lfa.pmgmt.data.DTO.Schedule.Unit unit, int status) { if (unit.IsActive) { string deviceAddress = string.Empty; SwitchbankUpdate mySwitchbankUpdate = null; BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8]; for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.NoChange; foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices) { lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device(); deviceDAO.ConnectionString = _connectionString; string deviceName = unitDevice.Name; int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id); deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId); string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId); if (status == 0) { bool switchOn = unitDevice.DeviceOn; if (switchOn) { status = 1; } else { status = 2; } } SetSwitchState(deviceSwitch, status, mySwitchStates,unitDevice.Id.ToString()); } try { mySwitchbankUpdate = new SwitchbankUpdate( mySwitchStates[0], mySwitchStates[1], mySwitchStates[2], mySwitchStates[3], mySwitchStates[4], mySwitchStates[5], mySwitchStates[6], mySwitchStates[7]); //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 3", System.Diagnostics.EventLogEntryType.Warning); SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate); lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus(); currentStatusDAO.ConnectionString = _connectionString; currentStatusDAO.Insert(unit.Name, "OK"); } catch(System.Net.Sockets.SocketException) { System.Threading.Thread.Sleep(200); try { mySwitchbankUpdate = new SwitchbankUpdate( mySwitchStates[0], mySwitchStates[1], mySwitchStates[2], mySwitchStates[3], mySwitchStates[4], mySwitchStates[5], mySwitchStates[6], mySwitchStates[7]); //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 3", System.Diagnostics.EventLogEntryType.Warning); SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate); lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus(); currentStatusDAO.ConnectionString = _connectionString; currentStatusDAO.Insert(unit.Name, "OK"); } catch (System.Net.Sockets.SocketException ex) { lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log(); logDAO.ConnectionString = _connectionString; logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now); lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus(); currentStatusDAO.ConnectionString = _connectionString; currentStatusDAO.Insert(unit.Name, "ERR"); } } } else { try { //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 4", System.Diagnostics.EventLogEntryType.Warning); SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2); lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus(); currentStatusDAO.ConnectionString = _connectionString; currentStatusDAO.Insert(unit.Name, "OK"); } catch(System.Net.Sockets.SocketException) { System.Threading.Thread.Sleep(200); try { //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 4", System.Diagnostics.EventLogEntryType.Warning); SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2); lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus(); currentStatusDAO.ConnectionString = _connectionString; currentStatusDAO.Insert(unit.Name, "OK"); } catch (System.Net.Sockets.SocketException ex) { lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log(); logDAO.ConnectionString = _connectionString; logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now); lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus(); currentStatusDAO.ConnectionString = _connectionString; currentStatusDAO.Insert(unit.Name, "ERR"); } } } }
private void LoadShedUnit(List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, lfa.pmgmt.data.DTO.Schedule.Unit unit) { int status = 0; foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices) { lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device(); deviceDAO.ConnectionString = _connectionString; string deviceName = unitDevice.Name; int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id); string deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId); string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId); bool switchOn = unitDevice.DeviceOn; if (switchOn) { status = 1; } else { status = 2; } SendSwitchState(deviceAddress, defaultPort, deviceSwitch, status); } }