/// <summary> /// Constructor of the Comm inbound service. /// </summary> /// <param name="communicator"></param> public Inbound(Communicator communicator) { DebugOutput.Print("Prepared the Communicator for reading. ", communicator.Id.ToString()); _communicator = communicator; Start(); UpdateActiveDeviceList(); }
public CommunicatorModifier(Communicator communicator) { InitializeComponent(); //Fill the combobox options with the enum values as given in the models. cbCommType.DataSource = Enum.GetValues(typeof (Models.ValueType)); cbValueType.DataSource = Enum.GetValues(typeof (Models.ValueType)); cbCommType.DataSource = Enum.GetValues(typeof (Models.ValueType)); _communicator = communicator; }
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(); // } //} }
private void bSaveAction_Click(object sender, EventArgs e) { var ruleSelected = _rule != null; var destinationSelected = add_cbCommunicatorDestination.SelectedItem != null; var outputEntered = add_tOutputValue.Text != ""; if (!(ruleSelected && destinationSelected && outputEntered)) { DebugOutput.Print("Unable to save - not all data has been entered!"); return; } _communicator = (Models.Communicator)add_cbCommunicatorDestination.SelectedItem; var newAction = new Models.Action() { Rule = _rule, RuleId = _rule.Id, Communicator =_communicator, CommunicatorId = _communicator.Id, OutputValue = add_tOutputValue.Text, Enabled = add_cActionEnabled.Checked }; var controller = new ActionController(); var action = controller.CreateAction(newAction); if (action != null) { DebugOutput.Print("Successfully created a new Action."); this.Close(); } }
private void add_cbCommType_SelectedIndexChanged(object sender, EventArgs e) { add_tcInnerPages = new CustomTabControl(); var specalism = (CommunicatorType) add_cbCommType.SelectedItem; switch (specalism) { case CommunicatorType.FlatFile: _communicator = new FileCommunicator(); add_tcInnerPagesSourceSetting.SelectedTab = pFlatFile; break; case CommunicatorType.Serial: _communicator = new SerialCommunicator(); add_tcInnerPagesSourceSetting.SelectedTab = pSerial; break; case CommunicatorType.Database: _communicator = new DatabaseCommunicator(); add_tcInnerPagesSourceSetting.SelectedTab = pDatabase; break; default: break; } }
private void add_bSaveSource_Click(object sender, EventArgs e) { if (_communicator is DatabaseCommunicator) { _communicator = new DatabaseCommunicator() { DbType = (DatabaseType) add_cbDatabaseType.SelectedItem, ValueType = (Models.ValueType) add_cbValueType.SelectedItem, ConnectionString = add_tConnectionString.Text, Query = add_tQuery.Text, StartChar = GetStartChar(), EndChar = GetEndChar(), Device = _device, //Id = GetNextIdNumber(), Inbound = add_rbCommInbound.Checked, Type = CommunicatorType.Database, Action = null }; } else if (_communicator is SerialCommunicator) { _communicator = new SerialCommunicator() { StartChar = GetStartChar(), EndChar = GetEndChar(), ValueType = (Models.ValueType) add_cbValueType.SelectedItem, BaudRate = Convert.ToInt32(add_tBaudRate.Text), ComPort = add_cbComPort.SelectedItem.ToString(), DataBits = Convert.ToByte(add_tDataBits.Text), IsDTR = add_cbDtr.Checked, IsRTS = add_cbRts.Checked, Device = _device, Inbound = add_rbCommInbound.Checked, Type = CommunicatorType.Serial, Action = null //Id = GetNextIdNumber() }; } else if (_communicator is FileCommunicator) { _communicator = new FileCommunicator() { FilePath = add_tFilePath.Text, ValueType = (Models.ValueType) add_cbValueType.SelectedItem, StartChar = GetStartChar(), EndChar = GetEndChar(), Device = _device, Type = CommunicatorType.FlatFile, Inbound = add_rbCommInbound.Checked, Action = null //Id = GetNextIdNumber() }; } _communicator.Device = _device; var _controller = new CommunicatorController(); var Id = _controller.SaveCommunicator(_communicator); if (Id != null) _communicator.Id = (int) Id; DebugOutput.Print($"a new Communicator was created with ID {_communicator.Id.ToString()}"); this.Close(); }
private void UpdateCommunicatorObject() { /* * Preparing all of the standard (abstract) Communicator fields */ //Id does not update _communicator.StartChar = Convert.ToInt32(tStart.Text); _communicator.EndChar = Convert.ToInt32(tEnd.Text); _communicator.LastReadTime = Convert.ToDateTime(tLastReadTime.Text); //CommType does not update _communicator.ValueType = (Models.ValueType)cbValueType.SelectedItem; _communicator.Inbound = rbInbound.Checked; /* * Preparing FileCommunicator fields */ if (_communicator is FileCommunicator) { var temp = (FileCommunicator)_communicator; temp.FilePath = tFilePath.Text; //Store this in the global variable. _communicator = temp; } else if (_communicator is SerialCommunicator) { var temp = (SerialCommunicator)_communicator; temp.ComPort = cbComPort.SelectedItem.ToString(); temp.BaudRate = Convert.ToInt32(tBaudRate.Text); temp.DataBits = Convert.ToByte(tDataBits.Text); temp.IsDTR = cbDtr.Checked; temp.IsRTS = cbRts.Checked; //Store this in the global variable. _communicator = temp; } else if (_communicator is DatabaseCommunicator) { var temp = (DatabaseCommunicator)_communicator; temp.ConnectionString = tConnectionString.Text; temp.Query = tQuery.Text; temp.DbType = (Models.DatabaseType)cbDatabaseType.SelectedItem; //Store this in the global variable. _communicator = temp; } }
private void modrules_bSetAction_Click(object sender, EventArgs e) { //Save the Rule as it stands. modrules_tSave.PerformClick(); var controller = new ActionController(); if (controller.RetrieveActionsForRule(_rule.Id).Any()) { //Get the actual Action. var action = controller.RetrieveActionsForRule(_rule.Id).FirstOrDefault(); _action = action; //Load the values required. modact_cEnabled.Checked = action.Enabled; modact_tValue.Text = action.OutputValue; modact_tRule.Text = _rule.ToString(); //Download the required communicator var commController = new CommunicatorController(); var comm = commController.GetAllCommunicators().FirstOrDefault(c => c.Id == action.CommunicatorId); if (comm != null) { _communicator = comm; _action.Communicator = comm; modact_tComm.Text = comm.ToString(); } else { modact_tComm.Text = ""; } //Actions exist. pTabPanel.SelectedTab = pModifyActions; } else { var db = new DataBoard(_communicator,_selectedDevice); db.GoToActionPage(_rule); db.ShowDialog(); _action = db.GetAction(); DebugOutput.Print("Changes made in the Data Manager are saved."); } }
private void modcomms_bSaveComm_Click(object sender, EventArgs e) { //Collect the selected item and store globally _communicator = (Communicator)modcomms_lbComms.SelectedItem; /* * Preparing all of the standard (abstract) Communicator fields */ //Id does not update _communicator.StartChar = Convert.ToInt32(modcomms_tStart.Text); _communicator.EndChar = Convert.ToInt32(modcomms_tEnd.Text); _communicator.LastReadTime = Convert.ToDateTime(modcomms_tLastReadTime.Text); //CommType does not update _communicator.ValueType = (Models.ValueType)modcomms_cbValueType.SelectedItem; _communicator.Inbound = modcomms_rbInbound.Checked; /* * Preparing FileCommunicator fields */ if (_communicator is FileCommunicator) { var temp = (FileCommunicator)_communicator; temp.FilePath = modcomms_tFilePath.Text; //Store this in the global variable. _communicator = temp; } else if (_communicator is SerialCommunicator) { var temp = (SerialCommunicator)_communicator; temp.ComPort = modcomms_cbComPort.SelectedItem.ToString(); temp.BaudRate = Convert.ToInt32(modcomms_tBaudRate.Text); temp.DataBits = Convert.ToByte(modcomms_tDataBits.Text); temp.IsDTR = modcomms_cbDtr.Checked; temp.IsRTS = modcomms_cbRts.Checked; //Store this in the global variable. _communicator = temp; } else if (_communicator is DatabaseCommunicator) { var temp = (DatabaseCommunicator)_communicator; temp.ConnectionString = modcomms_tConnectionString.Text; temp.Query = modcomms_tQuery.Text; temp.DbType = (Models.DatabaseType)modcomms_cbDatabaseType.SelectedItem; //Store this in the global variable. _communicator = temp; } //Save the Communicator var controller = new CommunicatorController(); controller.SaveCommunicator(_communicator); //Inform user. DebugOutput.Print("Successfully updated Communicator settings for ", _communicator.ToString()); }
private void modify_bComms_Click(object sender, EventArgs e) { try { //Loads the relevant communicators. var controller = new CommunicatorController(); modcomms_lbComms.Items.Clear(); modcomms_lbComms.Items.AddRange( controller.GetAllCommunicators().Where(c => c.Device.Id == _selectedDevice.Id).ToArray()); if (modcomms_lbComms.Items.Count > 0) { //Select the first element modcomms_lbComms.SelectedItem = modcomms_lbComms.Items[0]; //Shows the modify tab. pTabPanel.SelectedTab = pModifyCommunicators; } else { var msg = System.Windows.Forms.MessageBox.Show( "There are no Communicators for this Device.", "No Communicators Available", MessageBoxButtons.OK, MessageBoxIcon.Hand); // -------- Create new communicator ---------- //Create and display the DataBoard form. var window = new DataBoard(null, _selectedDevice); window.GoToCommunicatorPage(); window.ShowDialog(); //Get the Comm object created. _communicator = window.GetCommunicator(); } } catch (Exception ex) { DebugOutput.Print("Could not load/store/update information for selected Device", ex.Message); } }
private void add_bAddSource_Click(object sender, EventArgs e) { //Save the new Device. add_bSaveNewDevice.PerformClick(); //Create and display the DataBoard form. var window = new DataBoard(_communicator, _selectedDevice); window.GoToCommunicatorPage(); window.ShowDialog(); //Get the Comm object created. _communicator = window.GetCommunicator(); //Update the labels. UpdateStartLabels(); }
private void modcomms_bAddNewComm_Click(object sender, EventArgs e) { //Create and display the DataBoard form. var window = new DataBoard(_communicator, _selectedDevice); window.GoToCommunicatorPage(); window.ShowDialog(); //Get the Comm object created. _communicator = window.GetCommunicator(); //Return to Device list modcomms_bBack.PerformClick(); }
private void bSave_Click(object sender, EventArgs e) { if (_communicator is DatabaseCommunicator) { _communicator = new DatabaseCommunicator() { DbType = (DatabaseType)cbDBType.SelectedItem, ValueType = (Models.ValueType)cbValueType.SelectedItem, ConnectionString = tConnString.Text, Query = tQuery.Text, StartChar = GetStartChar(), EndChar = GetEndChar(), Device = _device, //Id = GetNextIdNumber(), Inbound = _inbound, Type = CommunicatorType.Database, Action = null }; } else if (_communicator is SerialCommunicator) { _communicator =new SerialCommunicator() { StartChar = GetStartChar(), EndChar = GetEndChar(), ValueType = (Models.ValueType)cbValueType.SelectedItem, BaudRate = Convert.ToInt32(tBaud.Text), ComPort = cbComPort.SelectedItem.ToString(), DataBits = Convert.ToByte(tBit.Text), IsDTR = cDTR.Checked, IsRTS = cRTS.Checked, Device = _device, Inbound = _inbound, Type = CommunicatorType.Serial, Action = null //Id = GetNextIdNumber() }; } else if (_communicator is FileCommunicator) { _communicator =new FileCommunicator() { FilePath = tFilePath.Text, ValueType = (Models.ValueType)cbValueType.SelectedItem, StartChar = GetStartChar(), EndChar = GetEndChar(), Device = _device, Type = CommunicatorType.FlatFile, Inbound = _inbound, Action = null //Id = GetNextIdNumber() }; } var Id = _controller.SaveCommunicator(_communicator); if (Id != null) _communicator.Id = (int)Id; System.Windows.Forms.MessageBox.Show("New communicator created; ID: " + Id); this.Close(); }
private void CheckCommunicatorIsSerial() { if (_communicator is SerialCommunicator) { return; } _communicator = new SerialCommunicator(); }
private void CheckCommunicatorIsFlatFile() { if (_communicator is FileCommunicator) { return; } _communicator = new FileCommunicator(); }
private void CheckCommunicatorIsDatabase() { if (_communicator is DatabaseCommunicator) { return; } _communicator = new DatabaseCommunicator(); }