Browse Source

Refactor core process extensions (#789)

* refactored ProcessExtensions.cs use of language feature using added in csharp 8.0

* refactored ProcessExtensions.cs removed nested if

* refactored ProcessExtensions.cs removed nested if

* refactored ProcessExtensions.cs removed duplicated quilifer

* refactored ProcessExtensions.cs removed conditional access qualifier can not be null at this point

* refactored ProcessExtensions.cs removed var value is not used

* refactored ProcessExtensions.cs applied again quiliers missed that it is a extension

* added both missing nit nit: prefer braces around ifs
pull/804/head
sirh3e 6 years ago
committed by GitHub
parent
commit
1f22ae5023
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      src/Microsoft.Tye.Core/ProcessExtensions.cs

40
src/Microsoft.Tye.Core/ProcessExtensions.cs

@ -27,7 +27,7 @@ namespace Microsoft.Tye
"taskkill",
$"/T /F /PID {pid}",
timeout,
out var _);
out _);
}
else
{
@ -51,26 +51,28 @@ namespace Microsoft.Tye
timeout,
out var stdout);
if (!string.IsNullOrEmpty(stdout))
if (string.IsNullOrEmpty(stdout))
{
using (var reader = new StringReader(stdout))
return;
}
using var reader = new StringReader(stdout);
while (true)
{
var text = reader.ReadLine();
if (text == null)
{
while (true)
{
var text = reader.ReadLine();
if (text == null)
{
return;
}
return;
}
if (int.TryParse(text, out var id))
{
children.Add(id);
// Recursively get the children
GetAllChildIdsUnix(id, children, timeout);
}
}
if (!int.TryParse(text, out var id))
{
continue;
}
children.Add(id);
// Recursively get the children
GetAllChildIdsUnix(id, children, timeout);
}
}
catch (Win32Exception ex) when (ex.Message.Contains("No such file or directory"))
@ -106,12 +108,12 @@ namespace Microsoft.Tye
UseShellExecute = false,
};
var process = System.Diagnostics.Process.Start(startInfo);
var process = Process.Start(startInfo);
stdout = null;
if (process?.WaitForExit((int)timeout.TotalMilliseconds) == true)
{
stdout = process?.StandardOutput.ReadToEnd();
stdout = process.StandardOutput.ReadToEnd();
}
else
{

Loading…
Cancel
Save