Exemplo 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);
            }

            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,
                };

                if (r.ExitCode < 0)
                {
                    throw new ProcessException(r);
                }

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

                return(localTemplateFolder);
            }
        }
Exemplo n.º 2
0
        private async Task <ProcessOutputResult> RunPythonScript(string interpreterPath, string script, string parameters, bool showWindow = false)
        {
            ProcessOutput output    = null;
            var           arguments = string.Format("\"{0}\" {1}", script, parameters);

            if (showWindow)
            {
                output = ProcessOutput.RunVisible(interpreterPath, arguments);
            }
            else
            {
                output = ProcessOutput.RunHiddenAndCapture(interpreterPath, arguments);
            }

            using (output) {
                await output;

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

                // All our python scripts will return 0 if successful
                if (r.ExitCode != 0)
                {
                    throw new ProcessException(r);
                }

                return(r);
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        private static async Task <ProcessOutputResult> WaitForOutput(string interpreterPath, ProcessOutput output)
        {
            using (output) {
                await output;

                var r = new ProcessOutputResult()
                {
                    ExeFileName         = interpreterPath,
                    ExitCode            = output.ExitCode,
                    StandardOutputLines = output.StandardOutputLines?.ToArray(),
                    StandardErrorLines  = output.StandardErrorLines?.ToArray(),
                };

                // All our python scripts will return 0 if successful
                if (r.ExitCode != 0)
                {
                    throw new ProcessException(r);
                }

                return(r);
            }
        }
Exemplo n.º 5
0
        public async Task <Tuple <string, ProcessOutputResult> > CloneAsync(string repoUrl, string targetParentFolderPath)
        {
            Directory.CreateDirectory(targetParentFolderPath);

            string localTemplateFolder = GetClonedFolder(repoUrl, targetParentFolderPath);

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

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

            using (output) {
                await output;

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

                if (r.ExitCode < 0)
                {
                    throw new ProcessException(r);
                }

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

                return(Tuple.Create(localTemplateFolder, r));
            }
        }
Exemplo n.º 6
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);
            }

            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,
                };

                if (r.ExitCode < 0) {
                    throw new ProcessException(r);
                }

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

                return localTemplateFolder;
            }
        }
Exemplo n.º 7
0
 public ProcessException(ProcessOutputResult result) :
     base(Strings.ProcessExitCodeMessage.FormatUI(result.ExeFileName, result.ExitCode))
 {
     Result = result;
 }
Exemplo n.º 8
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, GetEnvironment(), 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);
            }
        }
Exemplo n.º 9
0
 public ProcessException(ProcessOutputResult result) :
     base(string.Format(CultureInfo.CurrentUICulture, Strings.ProcessExitCodeMessage, result.ExeFileName, result.ExitCode))
 {
     Result = result;
 }
Exemplo n.º 10
0
 public ProcessException(ProcessOutputResult result)
 {
     Result = result;
 }
Exemplo n.º 11
0
 public ProcessException(ProcessOutputResult result) :
     base(string.Format(CultureInfo.CurrentUICulture, Strings.ProcessExitCodeMessage, result.ExeFileName, result.ExitCode)) {
     Result = result;
 }
Exemplo n.º 12
0
        private static async Task<ProcessOutputResult> WaitForOutput(string interpreterPath, ProcessOutput output) {
            using (output) {
                await output;

                var r = new ProcessOutputResult() {
                    ExeFileName = interpreterPath,
                    ExitCode = output.ExitCode,
                    StandardOutputLines = output.StandardOutputLines?.ToArray(),
                    StandardErrorLines = output.StandardErrorLines?.ToArray(),
                };

                // All our python scripts will return 0 if successful
                if (r.ExitCode != 0) {
                    throw new ProcessException(r);
                }

                return r;
            }
        }