private static void vccProcess_OutputDataReceived(object sender, DataReceivedEventArgs e) { //// Write Output from VCC to Verification Outputpane if (e != null && e.Data != null) { VSIntegration.WriteToPane(e.Data); Match match; if ((match = VCCErrorRegEx.Match(e.Data)).Success) { //// Add error to error list VSIntegration.AddErrorToErrorList( match.Groups["path"].Value, match.Groups["errormessage"].Value, Int32.Parse(match.Groups["line"].Value), Microsoft.VisualStudio.Shell.TaskErrorCategory.Error); } else if ((match = VCCWarningRegEx.Match(e.Data)).Success) { //// Add warning to error list VSIntegration.AddErrorToErrorList( match.Groups["path"].Value, match.Groups["errormessage"].Value, Int32.Parse(match.Groups["line"].Value), Microsoft.VisualStudio.Shell.TaskErrorCategory.Warning); } } }
/// <summary> /// Cancels the running VCC Process, if it exists /// </summary> internal static void Cancel() { if (VCCRunning) { int vccProcess_Id = vccProcess.Id; try { vccProcess.Kill(); }//try catch { VSIntegration.WriteToPane("Canceling VCC failed."); }//catch foreach (Process subProcess in Process.GetProcesses()) { if (GetParentProcess(subProcess.Id) == vccProcess_Id) { try { subProcess.Kill(); } catch { VSIntegration.WriteToPane("Canceling a subprocess of VCC failed."); } } //if } //foreach } //if } //method
internal static void LaunchVCC(string arguments) { var vccPath = VccPath; arguments += " "; arguments += VSIntegration.CurrentCompilerSettings.ToVccOptions(); var clPath = GetCLPath(VSIntegration.CurrentPlatform); if (clPath != null) { arguments += String.Format(" /clpath:\"{0}\"", clPath); } VSIntegration.ClearErrorsAndMarkers(); VSIntegration.UpdateStatus("Verifying...", true); //// Prepare VCC-Process, execute it and read its Output ProcessStartInfo psi = new ProcessStartInfo(string.Format("\"{0}\"", vccPath), arguments) { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }; vccProcess = new Process { StartInfo = psi }; //// Clear Verification Outputpane VSIntegration.ClearAndShowPane(); VSIntegration.WriteToPane("=== VCC started. ==="); //// Write Commandline-Command to Verification Outputpane VSIntegration.WriteToPane(string.Format("Command Line: \"{0}\" {1}\n", vccPath, arguments)); //// Get notified when VCC sends Output or Error Data vccProcess.OutputDataReceived += vccProcess_OutputDataReceived; vccProcess.ErrorDataReceived += vccProcess_OutputDataReceived; //// Get notified when VCC-Process finishes. vccProcess.EnableRaisingEvents = true; vccProcess.Exited += vccProcess_Exited; //// Finally start the process try { vccProcess.Start(); vccProcess.BeginOutputReadLine(); vccProcess.BeginErrorReadLine(); //// When the process was started, remember the cmdlinearguments VSPackagePackage.LastAction = arguments; } catch (Exception) { vccProcess = null; VSIntegration.WriteToPane("Executing\n" + vccPath + "\nfailed.\n" + "You can specify the folder in which the VCC executable is located in Tools/Options/Vcc."); VSIntegration.WriteToPane("=== Verification failed. ==="); VSIntegration.UpdateStatus("Verification failed.", false); } }
private static void vccProcess_Exited(object sender, EventArgs e) { if (vccProcess != null) { if (VSPackagePackage.Instance.OptionPage.ShowNotifications && new IntPtr(VSIntegration.DTE.MainWindow.HWnd) != GetForegroundWindow()) { if (vccProcess.ExitCode == 0) { notifyIcon.Value.ShowBalloonTip(4000, "Verification succeeded!", "Verification run completed successfully.", ToolTipIcon.Info); } else { notifyIcon.Value.ShowBalloonTip(4000, "Verification failed!", "Verification run completed with errors.", ToolTipIcon.Error); } } switch (vccProcess.ExitCode) { case -1: vccProcess.CancelOutputRead(); vccProcess.CancelErrorRead(); vccProcess = null; VSIntegration.WriteToPane("\n=== VCC was canceled. ==="); VSIntegration.UpdateStatus("Verification canceled.", false); break; case 0: Thread.Sleep(1000); VSIntegration.WriteToPane("\n=== Verification succeeded. ==="); VSIntegration.UpdateStatus("Verification succeeded.", false); break; case 2: Thread.Sleep(1000); VSIntegration.WriteToPane("Incorrect commandline arguments were used."); VSIntegration.WriteToPane("\n=== Verification failed. ===\n"); VSIntegration.UpdateStatus("Verification failed.", false); break; case 1: case 3: Thread.Sleep(1000); VSIntegration.WriteToPane("\n=== Verification failed. ==="); VSIntegration.UpdateStatus("Verification failed.", false); break; default: Thread.Sleep(1000); VSIntegration.WriteToPane("\n=== VCC finished with unknown exitcode. ==="); VSIntegration.WriteToPane(vccProcess.ExitCode.ToString()); break; } } }