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

Loading…
Cancel
Save