Пример #1
0
        /// <summary>
        /// プロセス実行
        /// </summary>
        /// <param name="filePath">ファイル名</param>
        /// <param name="args">引数</param>
        /// <param name="outputDataReceived"></param>
        public static void Start(string filePath, string args, CallbackOutput outputDataReceived)
        {
            using (var process = new Process())
            {
                // ファイルとパラメータを追加
                process.StartInfo.FileName  = filePath;
                process.StartInfo.Arguments = args;

                // 実行環境を設定
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.CreateNoWindow         = true;

                // 実行プロセスコンソール出力のイベントを追加
                process.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
                {
                    // 値なしの場合は終了
                    if (string.IsNullOrEmpty(e.Data))
                    {
                        return;
                    }

                    // 出力内容をコールバックメソッドに渡す
                    outputDataReceived(e.Data);
                });

                // プロセス実行
                process.Start();

                // 実行プロセスコンソール出力のイベントを開始
                process.BeginOutputReadLine();

                // プロセス終了まで待つ
                process.WaitForExit();

                // 閉じる
                process.Close();
            }
        }
Пример #2
0
        public static void Run(string sourceFileName, VsText.ITextSnapshot snapshot)
        {
            if (string.IsNullOrWhiteSpace(sourceFileName))
            {
                return;
            }

            Log.Debug("Running background FEC for file '{0}'.", sourceFileName);

            var counter = 10;

            while (counter > 0)
            {
                if (!ProbeCompiler.Instance.Mutex.WaitOne(1000))
                {
                    Log.Debug("Waiting for other compile/FEC operation to complete...");
                    counter--;
                    if (counter == 0)
                    {
                        Log.Debug("Ran out of retries when waiting for compile/FEC operation to complete.");
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            try
            {
                var first       = true;
                var reportError = new Action <ErrorTask>(task =>
                {
                    if (first)
                    {
                        first = false;
                        //ErrorTaskProvider.Instance.RemoveAllForFile(sourceFileName);
                        ErrorTaskProvider.Instance.RemoveAllForSource(ErrorTaskSource.BackgroundFec, sourceFileName);
                    }
                    if (task != null)
                    {
                        ErrorTaskProvider.Instance.Add(task);
                    }
                });

                var output = new CallbackOutput(line =>
                {
                    var index = line.IndexOf(": error :");
                    if (index >= 0)
                    {
                        Log.Debug("Background FEC error: {0}", line);

                        string fileName;
                        int lineNum;
                        if (ProbeCompiler.ParseFileNameAndLine(line.Substring(0, index), out fileName, out lineNum))
                        {
                            var message = line.Substring(index + ": error :".Length).Trim();
                            var task    = new ErrorTask(fileName, lineNum - 1, -1, message, ErrorType.Error, ErrorTaskSource.BackgroundFec, sourceFileName, snapshot);
                            reportError(task);
                        }
                        return;
                    }

                    index = line.IndexOf(": warning :");
                    if (index >= 0)
                    {
                        Log.Debug("Background FEC warning: {0}", line);

                        string fileName;
                        int lineNum;
                        if (ProbeCompiler.ParseFileNameAndLine(line.Substring(0, index), out fileName, out lineNum))
                        {
                            var message = line.Substring(index + ": warning :".Length).Trim();
                            var task    = new ErrorTask(fileName, lineNum - 1, -1, message, ErrorType.Warning, ErrorTaskSource.BackgroundFec, sourceFileName, snapshot);
                            reportError(task);
                        }
                        return;
                    }
                });

                var workingDir = ProbeToolsPackage.TempDir;

                var runner = new ProcessRunner();
                runner.CaptureOutput = true;
                runner.CaptureError  = true;

                var exitCode = runner.CaptureProcess("fec.exe", string.Concat("\"", sourceFileName, "\""), workingDir, output);
                if (exitCode == 0)
                {
                    if (first)
                    {
                        reportError(null);
                    }
                    Log.Debug("Background FEC completed successfully.");
                }
                else
                {
                    Log.Write(LogLevel.Warning, "FEC.exe returned exit code {0} when running background FEC for file '{1}'.", exitCode, sourceFileName);
                }
            }
            catch (Exception ex)
            {
                Log.WriteEx(ex);
            }
            finally
            {
                ProbeCompiler.Instance.Mutex.ReleaseMutex();
            }
        }