Esempio n. 1
0
        public async Task<string> CloneAsync(string repoUrl, string targetParentFolderPath) {
            Directory.CreateDirectory(targetParentFolderPath);

            string localTemplateFolder = GetClonedFolder(repoUrl, targetParentFolderPath);

            if (Directory.Exists(localTemplateFolder)) {
                ShellUtils.DeleteDirectory(localTemplateFolder);
            }

            // Ensure we always capture the output, because we need to check for errors in stderr
            var stdOut = new List<string>();
            var stdErr = new List<string>();

            Redirector redirector;
            if (_redirector != null) {
                redirector = new TeeRedirector(_redirector, new ListRedirector(stdOut, stdErr));
            } else {
                redirector = new ListRedirector(stdOut, stdErr);
            }

            var arguments = new string[] { "clone", repoUrl };
            using (var output = ProcessOutput.Run(_gitExeFilePath, arguments, targetParentFolderPath, null, false, redirector)) {
                await output;

                var r = new ProcessOutputResult() {
                    ExeFileName = _gitExeFilePath,
                    ExitCode = output.ExitCode,
                    StandardOutputLines = stdOut.ToArray(),
                    StandardErrorLines = stdErr.ToArray(),
                };

                if (output.ExitCode < 0 || HasFatalError(stdErr)) {
                    if (Directory.Exists(localTemplateFolder)) {
                        // Don't leave a failed clone on disk
                        try {
                            ShellUtils.DeleteDirectory(localTemplateFolder);
                        } catch (Exception ex) when (!ex.IsCriticalException()) {
                        }
                    }

                    throw new ProcessException(r);
                }

                if (!Directory.Exists(localTemplateFolder)) {
                    throw new ProcessException(r);
                }

                return localTemplateFolder;
            }
        }
Esempio n. 2
0
        private static async Task<ProcessOutputResult> RunPythonScript(Redirector redirector, string interpreterPath, string script, string parameters) {
            var outputLines = new List<string>();
            var errorLines = new List<string>();

            ProcessOutput output = null;
            var arguments = string.Format("\"{0}\" {1}", script, parameters);
            var listRedirector = new ListRedirector(outputLines, errorLines);
            var outerRedirector = new TeeRedirector(redirector, listRedirector);

            output = ProcessOutput.Run(interpreterPath, new string[] { arguments }, null, null, false, outerRedirector);

            var result = await WaitForOutput(interpreterPath, output);
            result.StandardOutputLines = outputLines.ToArray();
            result.StandardErrorLines = errorLines.ToArray();

            return result;
        }