コード例 #1
0
        public IHgResult Execute(HgArguments hgArguments)
        {
            var startInfo = new ProcessStartInfo(_executableName, hgArguments.ToString())
                            {
                                CreateNoWindow = true,
                                ErrorDialog = false,
                                RedirectStandardError = true,
                                RedirectStandardOutput = true,
                                UseShellExecute = false,
                            };
            using (var process = new Process { StartInfo = startInfo, })
            {
                var errorBuilder = new StringBuilder();
                var outBuilder = new StringBuilder();

                process.ErrorDataReceived += (sender, e) => errorBuilder.AppendLine(e.Data);
                process.OutputDataReceived += (sender, e) => outBuilder.AppendLine(e.Data);

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

                process.WaitForExit();

                return new HgResult(process.ExitCode != 0, outBuilder.ToString().Trim(), errorBuilder.ToString().Trim());
            }
        }
コード例 #2
0
 public IHgResult Execute(HgArguments hgArguments)
 {
     if (hgArguments == null)
     {
         throw new ArgumentNullException("hgArguments");
     }
     _processExecutor.ProcessOutput += HandleProcessOutput;
     try
     {
         var processInfo = new ProcessInfo("hg", hgArguments.ToString());
         var result = _processExecutor.Execute(processInfo);
         return new CruiseControlHgResult(result);
     }
     finally
     {
         _processExecutor.ProcessOutput -= HandleProcessOutput;
     }
 }
コード例 #3
0
ファイル: Hg.cs プロジェクト: davidsidlinger/ccnet-hg-nosuck
        private IHgResult ExecuteNonInteractive(HgArguments hgArguments,
		                                        string attemptedAction,
		                                        bool throwOnProcessFailure = true)
        {
            Debug.Assert(hgArguments != null);
            Debug.Assert(!string.IsNullOrEmpty(attemptedAction));

            var result = _processExecutor.Execute(hgArguments);
            if (throwOnProcessFailure && result.Failed)
            {
                var message = string.Format(CultureInfo.CurrentCulture,
                                            "Error occurred while attempting to {0}.\nStandard Output:\n{1}\nStandard Error:\n{2}",
                                            attemptedAction,
                                            result.StandardOutput,
                                            result.StandardError);
                throw new HgSourceControlException(message);
            }
            return result;
        }