/// <summary> /// Establish a connection between the source and destination. /// Update Connection Manager to be aware of this. /// Update Channel Manager about the assignment of a source and a destination. /// Establish threads of execution. /// </summary> private void take_Button_Click(object sender, EventArgs e) { //check for no values if (String.IsNullOrEmpty(src_PortNum.Text) || String.IsNullOrEmpty(src_IPAddr.Text) || String.IsNullOrEmpty(dest_PortNum.Text) || String.IsNullOrEmpty(dest_IPAddr.Text)) { MessageBox.Show("No Empty fields allowed!", "Empty Field Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //convert to integers int src_PortNumber = Convert.ToInt32(src_PortNum.Text); int dest_PortNumber = Convert.ToInt32(dest_PortNum.Text); if (cn_mngr.Connect(src_IPAddr.Text, src_PortNumber, dest_IPAddr.Text, dest_PortNumber)) { //update button image take_Button.BackgroundImage = global::Simple_Switcher.Properties.Resources.stop_Z; //also make fields not editable src_IPAddr.ReadOnly = true; dest_IPAddr.ReadOnly = true; src_Name.ReadOnly = true; dest_Name.ReadOnly = true; src_PortNum.ReadOnly = true; dest_PortNum.ReadOnly = true; } else { if (cn_mngr.Is_Connected(src_IPAddr.Text, src_PortNumber, dest_IPAddr.Text, dest_PortNumber)) { //disconnect it cn_mngr.Disconnect(src_IPAddr.Text, src_PortNumber, dest_IPAddr.Text, dest_PortNumber); //update button image take_Button.BackgroundImage = global::Simple_Switcher.Properties.Resources.take; //make fields editable src_IPAddr.ReadOnly = false; dest_IPAddr.ReadOnly = false; src_Name.ReadOnly = false; dest_Name.ReadOnly = false; src_PortNum.ReadOnly = false; dest_PortNum.ReadOnly = false; } } }
private void selectorButton_MouseDown(object sender, MouseEventArgs e) { Button button_Sender = (Button)sender; //mouse offset mouse_offset = button_Sender.PointToClient(new Point(MousePosition.X, MousePosition.Y)); //assuming user has let go of the button //get the x,y pos to determine where you are and what info to get int x_id = 0; int y_id = 0; for (int i = 0; i < x_crosspoints.Length; i++) { // if (x_crosspoints[i] - 20 <= button_Sender.Location.X && x_crosspoints[i] + 20 >= button_Sender.Location.X) { x_id = i; } } for (int i = 0; i < y_crosspoints.Length; i++) { // if (y_crosspoints[i] - 20 <= button_Sender.Location.Y && y_crosspoints[i] + 20 >= button_Sender.Location.Y) { y_id = i; } } //make sure the button is situated at a crosspoint and not moving if (button_Sender.Location.X != x_crosspoints[x_id] - (button_Sender.Width / 2)) { return; } //create the connection or disconnect if (e.Button == MouseButtons.Right) { //get information convert to integers string src_IPAddress = ch_mngr.get_Channel_Information("Sources", in_combobox_array[x_id].SelectedIndex, 1); string dest_IPAddress = ch_mngr.get_Channel_Information("Destinations", out_combobox_array[y_id].SelectedIndex, 1); int src_PortNumber = Convert.ToInt32(ch_mngr.get_Channel_Information("Sources", in_combobox_array[x_id].SelectedIndex, 2)); int dest_PortNumber = Convert.ToInt32(ch_mngr.get_Channel_Information("Destinations", out_combobox_array[y_id].SelectedIndex, 2)); //attempt a connection if (cn_mngr.Connect(src_IPAddress, src_PortNumber, dest_IPAddress, dest_PortNumber) && button_Sender.BackColor != Color.Red) { //update button image button_Sender.BackColor = Color.Red; //disable comboboxes in_combobox_array[x_id].Enabled = false; out_combobox_array[y_id].Enabled = false; } else { //if already connected then disconnect if (cn_mngr.Is_Connected(src_IPAddress, src_PortNumber, dest_IPAddress, dest_PortNumber)) { //disconnect it if (cn_mngr.Disconnect(src_IPAddress, src_PortNumber, dest_IPAddress, dest_PortNumber)) { //update button image button_Sender.BackColor = Color.Transparent; //enable comboboxes in_combobox_array[x_id].Enabled = true; out_combobox_array[y_id].Enabled = true; } else { //notify user of failure to end MessageBox.Show("Socket Failed to Disconnect", "Failure to disconnect", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }//end if right click else if (button_Sender.BackColor == Color.Red && e.Button == MouseButtons.Left) { //set to global integers to store selector_lastpos[y_id, 0] = ch_mngr.get_Channel_Information("Sources", in_combobox_array[x_id].SelectedIndex, 1); selector_lastpos[y_id, 1] = ch_mngr.get_Channel_Information("Sources", in_combobox_array[x_id].SelectedIndex, 2); selector_lastpos[y_id, 2] = ch_mngr.get_Channel_Information("Destinations", out_combobox_array[y_id].SelectedIndex, 1); selector_lastpos[y_id, 3] = ch_mngr.get_Channel_Information("Destinations", out_combobox_array[y_id].SelectedIndex, 2); selector_lastpos[y_id, 4] = x_id.ToString(); selector_lastpos[y_id, 5] = y_id.ToString(); } }