public static void ExecuteCommand(string command) { Console.WriteLine("ExecuteCommand method initializing..."); if (command.Equals(commExit)) { Console.WriteLine("Call to exit program."); Application.Exit(); } if (commNamesByKeyPress.Contains(command)) { int index = Array.IndexOf(commNamesByKeyPress, command); String[] keyPresses; keyPresses = commKeyPress[index].Split('+'); for (int i = 0; keyPresses.Length > i; i++) { Console.WriteLine(keyPresses[i]); CommanderRobot.RobotKeyPress(keyPresses[i]); } for (int i = 0; keyPresses.Length > i; i++) { CommanderRobot.RobotKeyRelease(keyPresses[i]); } } if (commNamesByApps.Contains(command)) { CommanderRobot.RobotExecApp(command); } }
private void SaveCommChanges(object sender, EventArgs e) { String[] commNamesByKeyPress = new String[ListCommByKeyPress.RowCount - 1]; String[] commByKeyPress = new String[ListCommByKeyPress.RowCount - 1]; String[] commNamesByApp = new String[ListCommByApps.RowCount - 1]; String[] commAppsPath = new String[ListCommByApps.RowCount - 1]; String commInit = commInitField.Text; /* Validation Start */ if (string.IsNullOrEmpty(commInit) || string.IsNullOrWhiteSpace(commInit)) { Console.WriteLine("commInitField triggered an error..."); MessageBox.Show("CommInit symbol cannot be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); commInitField.Text = CommanderFunctions.commInit; commInitField.Focus(); return; } for (int i = 0; ListCommByKeyPress.Rows.Count - 1 > i; i++) { var validateName = ListCommByKeyPress.Rows[i].Cells[0].Value; var validateComm = ListCommByKeyPress.Rows[i].Cells[1].Value; if (validateName == null || string.IsNullOrWhiteSpace(validateName.ToString()) || validateComm == null || string.IsNullOrWhiteSpace(validateComm.ToString())) { Console.WriteLine("commListKeyPress triggered an error..."); MessageBox.Show("One of the fields are empty.\nMake sure that no field are empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ListCommByKeyPress.CurrentCell = ListCommByKeyPress.Rows[i].Cells[0]; return; } if (CommanderRobot.KeysCheck(validateComm)) { Console.WriteLine("Keys entered correctly"); } else { Console.WriteLine("At least one unrecognized key found."); MessageBox.Show("Found an unsupported key press. Please verify highlighted command instruction.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ListCommByKeyPress.CurrentCell = ListCommByKeyPress.Rows[i].Cells[0]; return; } } for (int i = 0; ListCommByApps.Rows.Count - 1 > i; i++) { var validateName = ListCommByApps.Rows[i].Cells[0].Value; var validateComm = ListCommByApps.Rows[i].Cells[1].Value; if (validateName == null || string.IsNullOrWhiteSpace(validateName.ToString()) || validateComm == null || string.IsNullOrWhiteSpace(validateComm.ToString())) { Console.WriteLine("commListKeyPress triggered an error..."); MessageBox.Show("One of the fields are empty.\nMake sure that no field are empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ListCommByApps.CurrentCell = ListCommByApps.Rows[i].Cells[0]; return; } } for (int i = 0; ListCommByKeyPress.Rows.Count - 1 > i; i++) { if (ListCommByKeyPress.Rows.Count > i + 1) { Console.WriteLine(i); for (int j = i + 1; ListCommByKeyPress.Rows.Count - 1 > j; j++) { Console.Write(ListCommByKeyPress.Rows[i].Cells[0].Value.ToString() + " - " + ListCommByKeyPress.Rows[j].Cells[0].Value.ToString()); if (!string.Equals(ListCommByKeyPress.Rows[i].Cells[0].Value.ToString(), ListCommByKeyPress.Rows[j].Cells[0].Value.ToString(), StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine(" : Accept"); } else { Console.WriteLine(" : False"); Console.WriteLine("Found repeated entry. Canceling method."); MessageBox.Show("Found two commands with the same name (ignoring case).\nPlease verify selected item and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ListCommByKeyPress.CurrentCell = ListCommByKeyPress.Rows[i].Cells[0]; return; } } for (int k = 0; ListCommByApps.Rows.Count - 1 > k; k++) { Console.Write(ListCommByKeyPress.Rows[i].Cells[0].Value.ToString() + " - " + ListCommByApps.Rows[k].Cells[0].Value.ToString()); if (!string.Equals(ListCommByKeyPress.Rows[i].Cells[0].Value.ToString(), ListCommByApps.Rows[k].Cells[0].Value.ToString(), StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine(" : Accept"); } else { Console.WriteLine(" : False"); Console.WriteLine("Found repeated entry. Canceling method."); MessageBox.Show("Found two commands with the same name (ignoring case).\nPlease verify selected item and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ListCommByKeyPress.CurrentCell = ListCommByKeyPress.Rows[i].Cells[0]; ListCommByApps.CurrentCell = ListCommByApps.Rows[k].Cells[0]; return; } } } } for (int i = 0; ListCommByApps.Rows.Count - 1 > i; i++) { Console.WriteLine("new : " + i); for (int j = i + 1; ListCommByApps.Rows.Count - 1 > j; j++) { Console.Write(ListCommByApps.Rows[i].Cells[0].Value.ToString() + " - " + ListCommByApps.Rows[j].Cells[0].Value.ToString()); if (!string.Equals(ListCommByApps.Rows[i].Cells[0].Value.ToString(), ListCommByApps.Rows[j].Cells[0].Value.ToString(), StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine(" : Accept"); } else { Console.WriteLine(" : False"); Console.WriteLine("Found repeated entry. Canceling method."); MessageBox.Show("Found two commands with the same name (ignoring case).\nPlease verify selected item and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ListCommByApps.CurrentCell = ListCommByApps.Rows[i].Cells[0]; return; } } } /* Validation End*/ CommanderFunctions.commInit = commInit; CommanderFunctions.commNamesByKeyPress = new String[ListCommByKeyPress.Rows.Count - 1]; CommanderFunctions.commKeyPress = new String[ListCommByKeyPress.Rows.Count - 1]; CommanderFunctions.commNamesByApps = new String[ListCommByApps.Rows.Count - 1]; CommanderFunctions.commAppsPath = new String[ListCommByApps.Rows.Count - 1]; commNamesByKeyPress = new String[ListCommByKeyPress.Rows.Count - 1]; commByKeyPress = new String[ListCommByKeyPress.Rows.Count - 1]; for (int i = 0; ListCommByKeyPress.Rows.Count - 1 > i; i++) { CommanderFunctions.commNamesByKeyPress[i] = ListCommByKeyPress.Rows[i].Cells[0].Value.ToString(); CommanderFunctions.commKeyPress[i] = ListCommByKeyPress.Rows[i].Cells[1].Value.ToString(); } Console.WriteLine("KeyPress command names: " + string.Join(", ", CommanderFunctions.commNamesByKeyPress)); Console.WriteLine("KeyPress commands: " + string.Join(", ", CommanderFunctions.commKeyPress)); commNamesByApp = new String[ListCommByApps.Rows.Count - 1]; commAppsPath = new String[ListCommByApps.Rows.Count - 1]; for (int i = 0; ListCommByApps.Rows.Count - 1 > i; i++) { CommanderFunctions.commNamesByApps[i] = ListCommByApps.Rows[i].Cells[0].Value.ToString(); CommanderFunctions.commAppsPath[i] = ListCommByApps.Rows[i].Cells[1].Value.ToString(); } Console.WriteLine("App command names: " + string.Join(", ", CommanderFunctions.commNamesByApps)); Console.WriteLine("App commands: " + string.Join(", ", CommanderFunctions.commAppsPath)); SaveCommFiles(); }