private void TerminateProcessTree(int pid)
        {
            try
            {
                var process = Process.GetProcessById(pid);

                process.CloseMainWindow();

                process.Kill();

                // Enumerate all child processes and terminate them.
                var searcher = new ManagementObjectSearcher($"select * from Win32_Process where ParentProcessId={pid}");
                var result   = searcher.Get();
                foreach (var item in result)
                {
                    int childPid = Convert.ToInt32(item["ProcessId"]);
                    TerminateProcessTree(childPid);
                }

                process.WaitForExit();
            }
            catch (Exception ex)
            {
                Utility.LogException(new List <Exception> {
                    ex
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Load test cases.
        /// </summary>
        /// <param name="filterExpression">The filter expression. If it is null, no filter will be used.</param>
        /// <returns>The test case list.</returns>
        public List <TestCase> LoadTestCases(string filterExpression = null)
        {
            try
            {
                string tempPath = Path.GetTempFileName();

                File.Delete(tempPath);

                Directory.CreateDirectory(tempPath);

                StringBuilder args = ConstructVstestArgsForDiscovery(filterExpression, tempPath);

                vstestProcess = new Process()
                {
                    StartInfo = new ProcessStartInfo()
                    {
                        WorkingDirectory = WorkingDirectory,
                        FileName         = EnginePath,
                        UseShellExecute  = false,
                        CreateNoWindow   = true,
                        Arguments        = "test " + args,
                    }
                };

                vstestProcess.Start();
                vstestProcess.WaitForExit();

                string infoPath = Path.Combine(tempPath, "TestCaseInfo.json");

                var content = File.ReadAllText(infoPath);

                var infos = System.Text.Json.JsonSerializer.Deserialize <TestCaseInfo[]>(content);

                var result = infos.Select(info => new TestCase
                {
                    FullName    = info.FullName,
                    Name        = info.Name,
                    Category    = info.Category.ToList(),
                    ToolTipOnUI = info.ToolTipOnUI,
                    Description = info.Description,
                }).ToList();

                Directory.Delete(tempPath, true);

                return(result);
            }
            catch (Exception e)
            {
                Utility.LogException(new List <Exception> {
                    e
                });

                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Load all test cases.
        /// </summary>
        /// <returns>The test case list.</returns>
        private List <TestCase> LoadAllTestCases()
        {
            try
            {
                return(LoadDlls(TestAssemblies.ToArray()).ToList());
            }
            catch (Exception e)
            {
                Utility.LogException(new List <Exception> {
                    e
                });

                throw;
            }
        }
Exemple #4
0
        private void TerminateProcessTree(int pid)
        {
            try
            {
                var process = Process.GetProcessById(pid);

                process.CloseMainWindow();

                process.Kill();

                process.WaitForExit();
            }
            catch (Exception ex)
            {
                Utility.LogException(new List <Exception> {
                    ex
                });
            }
        }