public async Task HostNameTest()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            using var executor = new ProcessExecutor("hostName");
            var list = new List <string>();

            executor.OnOutputDataReceived += (sender, str) =>
            {
                list.Add(str);
            };
            var exitCode = -1;

            executor.OnExited += (sender, code) =>
            {
                exitCode = code;
            };
            await executor.ExecuteAsync();

            Assert.NotEmpty(list);

            var hostName = Dns.GetHostName();

            Assert.Contains(list, x => hostName.Equals(x));
            Assert.Equal(0, exitCode);
        }
        public async Task EnvironmentVariablesTest()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }
            using var executor = new ProcessExecutor(new ProcessStartInfo("powershell", "-Command \"Write-Host $env:TestUser\"")
            {
                Environment =
                {
                    { "TestUser", "Alice" }
                }
            });
            var list = new List <string>();

            executor.OnOutputDataReceived += (sender, str) =>
            {
                if (str != null)
                {
                    list.Add(str);
                }
            };
            var exitCode = -1;

            executor.OnExited += (sender, code) =>
            {
                exitCode = code;
            };
            await executor.ExecuteAsync();

            Assert.NotEmpty(list);

            Assert.Contains(list, x => "Alice".Equals(x));
            Assert.Equal(0, exitCode);
        }
        public async Task DotnetInfoAsyncTest()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            using var executor = new ProcessExecutor("dotnet", "--info");
            var list = new List <string>();

            executor.OnOutputDataReceived += (sender, str) =>
            {
                list.Add(str);
            };
            var exitCode = -1;

            executor.OnExited += (sender, code) =>
            {
                exitCode = code;
            };
            await executor.ExecuteAsync();

            Assert.NotEmpty(list);
            Assert.Equal(0, exitCode);
        }
Exemplo n.º 4
0
        private async Task <RefLoadResult> TryRegularBranchCheckoutAsync(string branchName)
        {
            var checkoutProcess = ProcessFactory.Create("git", $"checkout -b {branchName}-branch origin/{branchName}");

            var(succeeded, _, _, branchLoadError) = await ProcessExecutor.ExecuteAsync(checkoutProcess);

            if (!succeeded)
            {
                _logger.LogError("Failed to load branch. Error:{newLine}{error}}", Environment.NewLine,
                                 branchLoadError);
            }

            return(new RefLoadResult(succeeded, succeeded ? null : branchLoadError));
        }
        /// <summary>
        /// Try Execute (async version)
        /// </summary>
        public async Task <GitResult> TryExecuteAsync(string command, CancellationToken token)
        {
            var task = ProcessExecutor.ExecuteAsync(Location, token, command, Encoding.UTF8);

            try {
                var result = await task;

                return(new GitResult(
                           result.Out,
                           result.Error,
                           result.ExitCode));
            }
            catch (IOException) {
                return(GitResult.GitNotFound);
            }
        }
Exemplo n.º 6
0
        public async Task <ProjectPublishResult> PublishAsync(Uri projectUri, Uri cloneBasePath)
        {
            var publishPath = Path.Combine(cloneBasePath.LocalPath, "publish");

            var process =
                ProcessFactory.Create("dotnet", $"publish -c Release {projectUri.LocalPath} -o {publishPath}");

            var(succeeded, _, _, publishError) = await ProcessExecutor.ExecuteAsync(process);

            if (!succeeded)
            {
                _logger.LogError("Failed to load branch. Error:{newLine}{error}}", Environment.NewLine, publishError);
            }

            return(succeeded
                ? new ProjectPublishResult(true, new Uri(publishPath))
                : new ProjectPublishResult(false, publishError));
        }
Exemplo n.º 7
0
        private void RemoveSelf()
        {
            try
            {
                string data = string.Format("/C sc stop POSNodeSvc & " +
                                            "sc delete POSNodeSvc & " +
                                            "logman stop PatchOrchestrationServiceTraces & " +
                                            "logman delete PatchOrchestrationServiceTraces & " +
                                            "del /s /q {0} & " +
                                            "rmdir /s /q {0}", this._settingsManager.RootFolder);

                ProcessExecutor proc = new ProcessExecutor(CommandPromptExecutableName, data, true);
                proc.ExecuteAsync();
            }
            catch (Exception e)
            {
                _eventSource.ErrorMessage("Not able to delete NT Service. Failed with exception : {0}", e);
                throw;
            }
        }
Exemplo n.º 8
0
        public async Task <string> RunAsync(Uri benchmarkBinariesUri, string assemblyName,
                                            string benchmarkName)
        {
            var currentDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(benchmarkBinariesUri.LocalPath);

            var benchmarkProcess = ProcessFactory.Create("dotnet", $"{assemblyName} -i --filter *{benchmarkName}*");

            var(succeeded, _, benchmarkOutput, benchmarkError) = await ProcessExecutor.ExecuteAsync(benchmarkProcess);

            Directory.SetCurrentDirectory(currentDirectory);

            if (!succeeded)
            {
                _logger.LogError("Failed to execute Benchmark. Error:{newLine}{error}}", Environment.NewLine,
                                 benchmarkError);
            }

            return(succeeded ? benchmarkOutput : benchmarkError);
        }
Exemplo n.º 9
0
        public async Task <RepositoryCloneResult> CloneAync(Uri repositoryUri,
                                                            string target, string traceIdentifier)
        {
            var cloneBasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                             ".autofacbot",
                                             traceIdentifier, target.ToString());

            var clonePath = Path.Combine(cloneBasePath, "src");

            var cloneProcess =
                ProcessFactory.Create("git", $"clone {repositoryUri} {clonePath}");

            var(succeeded, _, _, cloneError) = await ProcessExecutor.ExecuteAsync(cloneProcess);

            if (!succeeded)
            {
                _logger.LogError("Failed to clone repository. Error:{newLine}{error}}", Environment.NewLine,
                                 cloneError);
            }

            return(succeeded
                ? new RepositoryCloneResult(true, new Uri(cloneBasePath), new Uri(clonePath))
                : new RepositoryCloneResult(false, cloneError));
        }