public bool RunApplication(AppStats app, int index) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.FileName = app.appPath; try { using (Process exeProcess = Process.Start(startInfo)) { while (!exeProcess.StandardOutput.EndOfStream) { string line = exeProcess.StandardOutput.ReadLine(); if (line.Contains("**")) { appList[index].taskData += line.Replace("**", ""); } else { appList[index].jsonData += line; } } } } catch (Exception) { throw; } return(true); }
private void AddAppButton_Click(object sender, EventArgs e) { if (_isNew) { if (!string.IsNullOrEmpty(appNameTextBox.Text) && !string.IsNullOrEmpty(pathTextBox.Text) && !string.IsNullOrEmpty(redColorText.Text) && !string.IsNullOrEmpty(greenColorText.Text) && !string.IsNullOrEmpty(blueColorText.Text)) { AppStats newApp = new AppStats(); newApp.appName = appNameTextBox.Text; newApp.appPath = pathTextBox.Text; newApp.isEnabled = enabledTaskCheck.Checked; newApp.appColor = Color.FromArgb(Convert.ToInt32(redColorText.Text), Convert.ToInt32(greenColorText.Text), Convert.ToInt32(blueColorText.Text)); if (!string.IsNullOrEmpty(dayComboBox.Text) && !string.IsNullOrEmpty(hourComboBox.Text)) { newApp.days = dayComboBox.Text; newApp.hour = Convert.ToInt32(hourComboBox.Text); newApp.appTime = null; newApp.appInterval = null; } else { newApp.appTime = timeComboBox.Text; newApp.appInterval = intervalComboBox.Text; newApp.days = null; } appList.Add(newApp); Save_Apps_to_JSON(); Load_App_Buttons(); } } else { if (!string.IsNullOrEmpty(appNameTextBox.Text) && !string.IsNullOrEmpty(pathTextBox.Text) && !string.IsNullOrEmpty(redColorText.Text) && !string.IsNullOrEmpty(greenColorText.Text) && !string.IsNullOrEmpty(blueColorText.Text)) { appList[globalIndex].appName = appNameTextBox.Text; appList[globalIndex].appPath = pathTextBox.Text; appList[globalIndex].appTime = timeComboBox.Text; appList[globalIndex].appInterval = intervalComboBox.Text; appList[globalIndex].hour = Convert.ToInt32(hourComboBox.Text); appList[globalIndex].days = dayComboBox.Text; appList[globalIndex].jsonData = dataTextOutput.Text; appList[globalIndex].taskData = taskCompletedTextBox.Text; appList[globalIndex].isEnabled = enabledTaskCheck.Checked; string red_string = redColorText.Text; string blue_string = blueColorText.Text; string green_string = greenColorText.Text; int red = 0; int blue = 0; int green = 0; if (!string.IsNullOrEmpty(red_string) && Regex.IsMatch(red_string, "^[0-9]+$")) { red = Convert.ToInt32(red_string); } if (!string.IsNullOrEmpty(green_string) && Regex.IsMatch(green_string, "^[0-9]+$")) { green = Convert.ToInt32(green_string); } if (!string.IsNullOrEmpty(blue_string) && Regex.IsMatch(blue_string, "^[0-9]+$")) { blue = Convert.ToInt32(blue_string); } if (red > 255) { red = 0; } if (green > 255) { green = 0; } if (blue > 255) { blue = 0; } ColorPanel.BackColor = Color.FromArgb(red, green, blue); Save_Apps_to_JSON(); Load_App_Buttons(); } } }