public SetDeviceCommunicators(Device device) { InitializeComponent(); localisedDevice = device; this.Text = "Settings for " + localisedDevice.Name; }
private void cbDevices_SelectedIndexChanged(object sender, EventArgs e) { bStart.Enabled = false; cbCommunicators.Items.Clear(); selectedDevice = (Device)cbDevices.SelectedItem; var commList = commCont.GetAllCommunicators().Where(comm => comm.Device.Id == selectedDevice.Id); foreach (var comm in commList) { cbCommunicators.Items.Add(comm); } }
public DataBoard(Communicator _comm, Device _dev) { InitializeComponent(); _communicator = _comm; _device = _dev; if (_device == null) { //Cannot handle an unknown device! this.Close(); } //if (_communicator == null) //{ // var devController = new DeviceController(); // _communicator = devController.GetCommunicatorsForDevice(_device.Id).FirstOrDefault(c=>c.Inbound); // if (_communicator == null) // { // System.Windows.Forms.MessageBox.Show("No communicators exist - you cannot create a rule!"); // this.Close(); // } //} }
public static void AddActiveDevice(Device device) { ActiveDevices.Add(device); }
/// <summary> /// Takes a Device object and posts it to the SQL Server database. /// This, in turn, casuses the next avaliable Mongo instance to be updated also. /// </summary> /// <param name="device"></param> /// <returns></returns> public Device SaveDevice(Device device) { bool devExists = _repo.RetrieveDevice(device.Id) != null; try { if (devExists) { AllDevices[AllDevices.FindIndex(d => d.Id == device.Id)] = device; return _repo.UpdateDevice(device); } else { AllDevices.Add(device); return _repo.CreateDevice(device); } } catch (Exception e) { DebugOutput.Print("Device creation failed.", e.Message); return null; } }
private void add_cbRule_SelectedIndexChanged(object sender, EventArgs e) { var devController = new DeviceController(); var commController = new CommunicatorController(); _rule = (Models.Rule)add_cbRule.SelectedItem; _rule.Device = devController.RetrieveDevice(_rule.DeviceId); _device = _rule.Device; //add_cbCommunicatorDestination.Items.AddRange(commController.GetAllCommunicators().Where(com=>com.Device.Id==_rule.DeviceId && com.Inbound==false).ToArray()); }
private void bSave_Click(object sender, EventArgs e) { bool enabled = rbTrue.Checked && !rbFalse.Checked; _device = _controller.GetDeviceObject(Convert.ToInt32(tId.Text), tName.Text, tLocation.Text, tCustodian.Text, enabled); if (_controller.SaveDevice(_device) == null) { MessageBox.Show("There was an error saving the Device..."); } }
private void modify_bSave_Click(object sender, EventArgs e) { try { //Update the global object with any updates values. _selectedDevice.Name = modify_tDevName.Text; _selectedDevice.Custodian = modify_tCustodian.Text; _selectedDevice.Location = modify_tLocation.Text; _selectedDevice.Enabled = modify_rbTrue.Checked; //Create new Device Controller. var controller = new DeviceController(); //Save the Device. var savedDevice = controller.SaveDevice(_selectedDevice); //If the updated device is null or has been corupted (i.e. wrong device info), error! if (savedDevice == null || savedDevice.Id != _selectedDevice.Id) { MessageBox.Show("There was an error saving the Device...", _selectedDevice.ToString()); } else { //Updated the global variable with a database replica. //(Should not change the object properties). _selectedDevice = savedDevice; //Inform the user DebugOutput.Print("Device was updated successfully. ", _selectedDevice.ToString()); } } catch (Exception ex) { DebugOutput.Print("Could not save data for selected object. ", ex.Message); } }
private void add_bSaveNewDevice_Click(object sender, EventArgs e) { var _controller = new DeviceController(); bool enabled = add_rbTrue.Checked && !add_rbFalse.Checked; _selectedDevice = _controller.GetDeviceObject(Convert.ToInt32(add_tId.Text), add_tName.Text, add_tLocation.Text, add_tCustodian.Text, enabled); var newDevice = _controller.SaveDevice(_selectedDevice); _selectedDevice = newDevice; if (newDevice== null) { MessageBox.Show("There was an error saving the Device..."); } }
private void stop_lbDevice_SelectedIndexChanged(object sender, EventArgs e) { try { var selectedDevice = (Device) stop_lbDevice.SelectedItem; //stop_tId.Text = selectedDevice.Id.ToString(); //Removed. stop_tDevName.Text = selectedDevice.Name; stop_tLocation.Text = selectedDevice.Location; stop_tCustodian.Text = selectedDevice.Custodian; //Load the values from MongoDb var max = 10000; //Max number of records to display var controller = new ValueController(); stop_lbValues.Items.Clear(); //Only add upto the first 'max' values. var allValues = controller.GetValuesForDevice(selectedDevice); if (allValues != null && allValues.Any()) { var vals = allValues.Take(max).ToArray(); var distinct = new List<string>(); foreach (var val in vals.Where(val => !distinct.Contains(val.ToString()))) { distinct.Add(val.ToString()); } stop_lbValues.Items.AddRange(distinct.ToArray()); } //Allow global access _selectedDevice = selectedDevice; } catch (Exception ex) { DebugOutput.Print("Could not load data for selected object. ", ex.Message); } }
private void start_lbDevice_SelectedIndexChanged(object sender, EventArgs e) { try { var selectedDevice = (Device) start_lbDevice.SelectedItem; start_tId.Text = selectedDevice.Id.ToString(); start_tDevName.Text = selectedDevice.Name; start_tLocation.Text = selectedDevice.Location; start_tCustodian.Text = selectedDevice.Custodian; start_bStart.Enabled = selectedDevice.Enabled; //Disallow starting if already started. if (Inbound.GetStartedDevices().Where(dev => dev.Id == selectedDevice.Id).Any()) start_bStart.Enabled = false; //Allow global access _selectedDevice = selectedDevice; } catch (Exception ex) { DebugOutput.Print("Could not load data for selected object. ",ex.Message); } }
private void alarm_lbAlarms_SelectedIndexChanged(object sender, EventArgs e) { //Resetting the form. alarm_bRule.Enabled = false; alarm_bDevice.Enabled = false; alarm_tDateTime.Text = ""; alarm_rbTrue.Checked = false; alarm_rbFalse.Checked = false; alarm_tValue.Text = ""; alarm_tDevice.Text = ""; try { var selected = (Alarm) alarm_lbAlarms.SelectedItem; alarm_tDateTime.Text = selected.TimeStamp.ToString(); alarm_rbTrue.Checked = selected.Accepted; alarm_rbFalse.Checked = !selected.Accepted; //Get Value information. if (selected.ValueId > 0) { var controller = new ValueController(); _value = controller.GetValueById(selected.ValueId); selected.Value = _value; alarm_tValue.Text = selected.Value.StringValue; } //Get Rule information. if (selected.RuleId > 0) { var controller = new RuleController(); _rule = controller.RetrieveRuleById(selected.RuleId); alarm_bRule.Enabled = true; } //Get Device information. if (selected.DeviceId > 0) { var controller = new DeviceController(); _selectedDevice = controller.RetrieveDevice(selected.DeviceId); selected.Device = _selectedDevice; alarm_tDevice.Text = _selectedDevice.ToString(); alarm_bDevice.Enabled = true; } } catch { DebugOutput.Print("Attempted to load an alarm and failed..."); } }
public AddCommunicator(Device device, bool inbound) { InitializeComponent(); _device = device; _inbound = inbound; }
public static void StartDeviceProcess(Device device) { //TODO break here and add dthe start logic! ActiveDevices.Add(device); }
private void modify_lbDeviceList_SelectedIndexChanged(object sender, EventArgs e) { try { var selectedDevice = (Device) modify_lbDeviceList.SelectedItem; _selectedDevice = selectedDevice; modify_tId.Text = selectedDevice.Id.ToString(); modify_tDevName.Text = selectedDevice.Name; modify_tCustodian.Text = selectedDevice.Custodian; modify_tLocation.Text = selectedDevice.Location; var enabled = (selectedDevice.Enabled) ? modify_rbTrue.Checked = true : modify_rbFalse.Checked = true; DebugOutput.Print("Now reviewing device: ", selectedDevice.Name); } catch (Exception exception) { DebugOutput.Print("Error reviewing the selected device. ", exception.Message); } }
public AddRule(Device device) { InitializeComponent(); _device = device; }
public ICollection<Value> GetValuesForDevice(Device device) { var repo = new MongoRepository(); return repo.GetAllValuesForDevice(device.Id); }