Пример #1
0
        public void Execute(string exe, string args, string workDir, bool showWindow)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            bool buildPaneIsActive = false;

            EnvDTE.OutputWindow     outputWin = getOutputWindow();
            EnvDTE.OutputWindowPane pane      = getOutputPane(_outputPane);
            if (outputWin != null && pane != null)
            {
                if (!buildPaneIsActive)
                {
                    outputWin.Parent.Activate();
                    pane.Activate();
                    buildPaneIsActive = true;
                }
                pane.Clear();
            }

            ProcessStartInfo si = new ProcessStartInfo();

            si.FileName               = exe;
            si.Arguments              = args;
            si.UseShellExecute        = false;
            si.RedirectStandardOutput = true;
            si.CreateNoWindow         = !showWindow;
            si.WorkingDirectory       = workDir;

            Process proc = new Process();

            proc.StartInfo           = si;
            proc.OutputDataReceived += new DataReceivedEventHandler(OnOutputDataReceived);
            proc.Start();
            proc.BeginOutputReadLine();
        }
Пример #2
0
        void Compile(string cl, string args, VCFile file)
        {
            Process process = new Process();

            process.StartInfo.FileName               = cl;
            process.StartInfo.Arguments              = args;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.WorkingDirectory       = Path.GetDirectoryName(m_dte.Solution.FullName);

            EnvDTE.Window           window       = m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
            EnvDTE.OutputWindow     outputWindow = (EnvDTE.OutputWindow)window.Object;
            EnvDTE.OutputWindowPane buildPane    = outputWindow.OutputWindowPanes.Item(BuildPaneName);
            buildPane.Clear();
            buildPane.Activate();

            process.OutputDataReceived += (sender, eventArgs) => BuildOutputReceived(buildPane, eventArgs);

            process.Start();
            process.BeginOutputReadLine();

            OnCompilationStart();
            System.Threading.Tasks.Task.Run(() => BuildTask(process, file));
        }
Пример #3
0
        // 这个弹出框需要server参数,麻烦,用winform方便
        //public static void Info(IServiceProvider server, string msg, string title = "插件-信息提示")
        //{
        //    VsShellUtilities.ShowMessageBox(
        //       server,
        //       msg,
        //       title,
        //       OLEMSGICON.OLEMSGICON_INFO,
        //       OLEMSGBUTTON.OLEMSGBUTTON_OK,
        //       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        //}

        /// <summary>
        /// 在vs的输出窗口的标题为"web发布插件"的窗口里输出文本内容
        /// </summary>
        /// <param name="msg">文本</param>
        /// <param name="clear">是否清空原有信息</param>
        public static void VsOutWind(string msg, bool clear = false)
        {
            //ThreadHelper.ThrowIfNotOnUIThread();
            // 输出窗口集合
            EnvDTE.OutputWindowPanes panels =
                EnvVar._dte.ToolWindows.OutputWindow.OutputWindowPanes;
            // 输出窗口固定的自定义项标题
            string title = EnvVar.Name;

            try
            {
                // If the pane exists already, write to it.
                panels.Item(title);
            }
            catch (ArgumentException)
            {
                // Create a new pane and write to it.
                panels.Add(title);
            }
            EnvDTE.OutputWindowPane panel = panels.Item(title);
            // 清空消息
            if (clear)
            {
                panel.Clear();
            }
            // 激活输出窗口的该面板
            panel.Activate();
            // 输出消息
            panel.OutputString(msg);

            // 显示(激活) vs"输出"窗口
            string winCaption = "输出";

            EnvVar._dte.Windows.Item(winCaption).Activate();
        }
Пример #4
0
 protected void ClearOutput()
 {
     EnvDTE.OutputWindowPane pane = GetOutputPane();
     if (pane != null)
     {
         pane.Clear();
     }
 }
Пример #5
0
        /// <summary>
        /// 输出信息到VS的"输出"窗口,如果"输出"窗口未打开,则打开后再输出
        /// </summary>
        /// <param name="msg"></param>
        internal static void OutPutMsg(string msg, bool clear = false)
        {
            EnvDTE.OutputWindowPanes panels =
                _dte.ToolWindows.OutputWindow.OutputWindowPanes;

            // 输出窗口中的一个自定义项的标题
            string title = "发布插件 消息";

            //
            EnvDTE.OutputWindowPane panel = null;
            foreach (EnvDTE.OutputWindowPane item in panels)
            {
                if (item.Name == title)
                {
                    panel = item;
                    break;
                }
            }
            if (panel == null)
            {
                panel = panels.Add(title);
            }
            // 清空消息
            if (clear)
            {
                panel.Clear();
            }
            // 激活输出窗口的该面板
            panel.Activate();
            // 输出消息
            panel.OutputString(msg);

            // 显示(激活) vs"输出"窗口
            string winCaption = "输出";

            _dte.Windows.Item(winCaption).Activate();
        }
Пример #6
0
        /// [exec start process]
        public void StartProcess(string exePath, string args, string workDir, bool enableBoostParsing)
        {
            try
            {
                // Ensure executable exists
                if (!System.IO.File.Exists(exePath))
                {
                    WriteLine(1, "Executable not found: " + exePath);
                    m_mainEvents.OnTestTerminated(Result.Failed, exePath, false, new TimeSpan(0), "Executable not found: " + exePath);
                    return;
                }

                // Ensure output pane exists
                if (m_outputPane == null)
                {
                    EnvDTE.OutputWindow ow = dte.ToolWindows.OutputWindow;
                    m_outputPane = ow.OutputWindowPanes.Add("Run UnitTest");
                }
                m_outputPane.Activate();
                m_outputPane.Clear();

                // -----  Prepare process data  -----
                m_process = new System.Diagnostics.Process();
                m_process.StartInfo.FileName         = exePath;
                m_process.StartInfo.WorkingDirectory = workDir;
                m_process.StartInfo.Arguments        = args.Trim();
                boostProcessOutputParser.Clear();
                boostProcessOutputParser.EnableParsing = enableBoostParsing;

                if (m_getNotificationWhenProcessTerminates)
                {
                    // Remark: Method Executor.Process_Exited will be called
                    // from some system thread when the process has terminated.
                    // Synchronization will be needed!
                    m_process.Exited += new System.EventHandler(Process_Exited);
                    m_process.EnableRaisingEvents = true;
                }

                if (m_catchStdOutAndStdErr)
                {
                    m_process.StartInfo.UseShellExecute        = false;
                    m_process.StartInfo.RedirectStandardOutput = true;
                    m_process.StartInfo.RedirectStandardError  = true;
                    m_process.StartInfo.CreateNoWindow         = true;
                    m_process.OutputDataReceived += new System.Diagnostics.
                                                    DataReceivedEventHandler(boostProcessOutputParser.StandardOutputReceiver);
                    m_process.ErrorDataReceived += new System.Diagnostics.
                                                   DataReceivedEventHandler(boostProcessOutputParser.StandardErrorReceiver);
                }

                // -----  Start the new process and start redirection of output  -----
                m_process.Start();
                if (m_catchStdOutAndStdErr)
                {
                    m_process.BeginOutputReadLine();
                    m_process.BeginErrorReadLine();
                }

                WriteLine(2, "Started " + m_process.StartInfo.FileName);
            }
            catch (Exception e)
            {
                string info = "EXCEPTION: Could not start executable " + exePath + " " + e.ToString();
                WriteLine(1, info);
                m_mainEvents.OnTestTerminated(Result.Failed, exePath, false, new TimeSpan(0), info);
            }
        }