public static GetSolutionDir ( DTE dte ) : void | ||
dte | DTE | |
Результат | void |
/// <summary> /// Execute a Git command and return the output /// </summary> /// <param name="commands">Git command to be executed</param> /// <returns>Git output</returns> public static string StartProcessGitResult(EnvHelper envHelper, string commands) { if (string.IsNullOrEmpty(envHelper.GetSolutionDir())) return string.Empty; var output = string.Empty; var error = string.Empty; var proc = new Process { StartInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c cd /D \"{envHelper.GetSolutionDir()}\" && \"{envHelper.GetGit()}\" {commands}", UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; proc.Start(); while (!proc.StandardOutput.EndOfStream) { output += proc.StandardOutput.ReadLine() + ";"; } while (!proc.StandardError.EndOfStream) { error += proc.StandardError.ReadLine(); } return string.IsNullOrEmpty(output) ? error : output.TrimEnd(';'); }
/// <summary> /// Execute a Git command and return true if output is non-empty /// </summary> /// <param name="commands">Git command to be executed</param> /// <param name="showAlert">Show an alert dialog when error output is non-empty</param> /// <returns>True if output is non-empty</returns> public static bool StartProcessGit(EnvHelper envHelper, string commands, bool showAlert = true) { if (string.IsNullOrEmpty(envHelper.GetSolutionDir())) { return(false); } var output = string.Empty; var error = string.Empty; var proc = new Process { StartInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c cd /D \"{envHelper.GetSolutionDir()}\" && \"{envHelper.GetGit()}\" {commands}", UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; proc.Start(); while (!proc.StandardOutput.EndOfStream) { output = proc.StandardOutput.ReadLine(); } while (!proc.StandardError.EndOfStream) { error += proc.StandardError.ReadLine(); } if (!string.IsNullOrEmpty(output)) { return(true); } if (!string.IsNullOrEmpty(error) && showAlert) { MessageBox.Show(error, "TGit error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
public static Process StartProcessGui(DTE dte, EnvHelper envHelper, string application, string args, string title, string branchName = "", OutputBox outputBox = null, OptionPageGrid options = null, string pushCommand = "") { var dialogResult = DialogResult.OK; if (!StartProcessGit(envHelper, "config user.name") || !StartProcessGit(envHelper, "config user.email")) { dialogResult = new Credentials(envHelper).ShowDialog(); } if (dialogResult == DialogResult.OK) { try { var process = new Process { StartInfo = { WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, FileName = application, Arguments = args, WorkingDirectory = envHelper.GetSolutionDir() }, EnableRaisingEvents = true }; process.Exited += process_Exited; process.OutputDataReceived += OutputDataHandler; process.ErrorDataReceived += OutputDataHandler; if (outputBox == null) { _outputBox = new OutputBox(branchName, options, pushCommand, dte, envHelper); _outputBox.Show(); } else { _outputBox = outputBox; } process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); if (!string.IsNullOrEmpty(title)) { _outputBox.Text = title; } _outputBox.Show(); return process; } catch (Exception e) { MessageBox.Show(e.Message, $"'{application}' not found", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return null; }