Clean up API a bit more.
MODIFY
WalletWasabi.Gui/CrashReport/CrashReporter.cs
WalletWasabi.Gui/CrashReport/CrashReporter.cs
@@ -31,7 +31,8 @@ namespace WalletWasabi.Gui.CrashReport
var args = $"crashreport -attempt=\"{Attempts + 1}\" -exception=\"{Base64ExceptionString}\"";
- using Process p = ProcessBuilder.BuildProcessInstance(Process.GetCurrentProcess().MainModule.FileName, args);
+ ProcessStartInfo startInfo = ProcessStartInfoFactory.Make(Process.GetCurrentProcess().MainModule.FileName, args);
+ using Process p = Process.Start(startInfo);
p.Start();
p.WaitForExit();
}

MODIFY
WalletWasabi.Tests/UnitTests/BitcoinCore/NodeBuildingTests.cs
WalletWasabi.Tests/UnitTests/BitcoinCore/NodeBuildingTests.cs
@@ -88,7 +88,7 @@ namespace WalletWasabi.Tests.UnitTests.BitcoinCore
public async Task GetVersionTestsAsync()
{
using var cts = new CancellationTokenSource(7000);
- Version version = await CoreNode.GetVersionAsync(cts.Token);
+ Version version = await CoreNode.GetVersionAsync(cts.Token).ConfigureAwait(false);
Assert.Equal(WalletWasabi.Helpers.Constants.BitcoinCoreVersion, version);
}
}

MODIFY
WalletWasabi/BitcoinCore/CoreNode.cs
WalletWasabi/BitcoinCore/CoreNode.cs
@@ -199,8 +199,8 @@ namespace WalletWasabi.BitcoinCore
var invoker = new ProcessInvoker();
var arguments = "-version";
- var process = ProcessBuilder.BuildProcessInstance(MicroserviceHelpers.GetBinaryPath("bitcoind"), arguments);
- var (responseString, exitCode) = await invoker.SendCommandAsync(process, cancel).ConfigureAwait(false);
+ ProcessStartInfo processStartInfo = ProcessStartInfoFactory.Make(MicroserviceHelpers.GetBinaryPath("bitcoind"), arguments);
+ var (responseString, exitCode) = await invoker.SendCommandAsync(processStartInfo, cancel).ConfigureAwait(false);
if (exitCode != 0)
{

MODIFY
WalletWasabi/BitcoinCore/Processes/BitcoindRpcProcessBridge.cs
WalletWasabi/BitcoinCore/Processes/BitcoindRpcProcessBridge.cs
@@ -42,7 +42,7 @@ namespace WalletWasabi.BitcoinCore.Processes
var ptcv = PrintToConsole ? 1 : 0;
string processPath = MicroserviceHelpers.GetBinaryPath("bitcoind");
string args = $"{NetworkTranslator.GetCommandLineArguments(Network)} -datadir=\"{DataDir}\" -printtoconsole={ptcv}";
- _process = new ProcessAsync(ProcessBuilder.BuildProcessInstance(processPath, args));
+ _process = new ProcessAsync(ProcessStartInfoFactory.Make(processPath, args));
_process.Start();
await PidFile.WriteFileAsync(_process.Id).ConfigureAwait(false);

MODIFY
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
using System;
+using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@@ -19,9 +20,9 @@ namespace WalletWasabi.Hwi.ProcessBridge
public async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel, Action<StreamWriter> standardInputWriter = null)
{
- var process = ProcessBuilder.BuildProcessInstance(ProcessPath, arguments, openConsole);
+ ProcessStartInfo startInfo = ProcessStartInfoFactory.Make(ProcessPath, arguments, openConsole);
- (string rawResponse, int exitCode) = await ProcessInvoker.SendCommandAsync(process, cancel, standardInputWriter).ConfigureAwait(false);
+ (string rawResponse, int exitCode) = await ProcessInvoker.SendCommandAsync(startInfo, cancel, standardInputWriter).ConfigureAwait(false);
string response;

MODIFY
WalletWasabi/Microservices/ProcessAsync.cs
WalletWasabi/Microservices/ProcessAsync.cs
@@ -43,7 +43,7 @@ namespace WalletWasabi.Microservices
public int Id => Process.Id;
/// <inheritdoc cref="Process.StandardInput"/>
- public StreamWriter StreamWriter => Process.StandardInput;
+ public StreamWriter StandardInput => Process.StandardInput;
/// <inheritdoc cref="Process.StandardOutput"/>
public StreamReader StandardOutput => Process.StandardOutput;

MODIFY
WalletWasabi/Microservices/ProcessInvoker.cs
WalletWasabi/Microservices/ProcessInvoker.cs
using System;
-using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -10,33 +8,33 @@ namespace WalletWasabi.Microservices
{
public class ProcessInvoker
{
- public async Task<(string response, int exitCode)> SendCommandAsync(Process process, CancellationToken cancel, Action<StreamWriter> standardInputWriter = null)
+ public async Task<(string response, int exitCode)> SendCommandAsync(ProcessStartInfo startInfo, CancellationToken token, Action<StreamWriter> standardInputWriter = null)
{
// "using" makes sure the process exits at the end of this method.
- using var processAsync = new ProcessAsync(process);
+ using var processAsync = new ProcessAsync(startInfo);
if (standardInputWriter is { })
{
processAsync.StartInfo.RedirectStandardInput = true;
}
- process.Start();
+ processAsync.Start();
if (standardInputWriter is { })
{
- standardInputWriter(process.StandardInput);
- process.StandardInput.Close();
+ standardInputWriter(processAsync.StandardInput);
+ processAsync.StandardInput.Close();
}
- Task<string> readPipeTask = process.StartInfo.UseShellExecute
+ Task<string> readPipeTask = processAsync.StartInfo.UseShellExecute
? Task.FromResult(string.Empty)
- : process.StandardOutput.ReadToEndAsync();
+ : processAsync.StandardOutput.ReadToEndAsync();
- await processAsync.WaitForExitAsync(cancel);
+ await processAsync.WaitForExitAsync(token);
string output = await readPipeTask.ConfigureAwait(false);
- return (output, exitCode: process.ExitCode);
+ return (output, exitCode: processAsync.ExitCode);
}
}
}

RENAME
WalletWasabi/Microservices/ProcessBuilder.cs
WalletWasabi/Microservices/ProcessStartInfoFactory.cs
using System;
-using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
-using System.Text;
namespace WalletWasabi.Microservices
{
- public class ProcessBuilder
+ public class ProcessStartInfoFactory
{
- public static Process BuildProcessInstance(string processPath, string arguments, bool openConsole = false)
+ public static ProcessStartInfo Make(string processPath, string arguments, bool openConsole = false)
{
ProcessWindowStyle windowStyle;
if (openConsole)
@@ -25,13 +23,13 @@ namespace WalletWasabi.Microservices
windowStyle = ProcessWindowStyle.Hidden;
}
- var p = new Process();
- p.StartInfo.FileName = processPath;
- p.StartInfo.Arguments = arguments;
- p.StartInfo.RedirectStandardOutput = !openConsole;
- p.StartInfo.UseShellExecute = openConsole;
- p.StartInfo.CreateNoWindow = !openConsole;
- p.StartInfo.WindowStyle = windowStyle;
+ var p = new ProcessStartInfo(fileName: processPath, arguments);
+ p.FileName = processPath;
+ p.Arguments = arguments;
+ p.RedirectStandardOutput = !openConsole;
+ p.UseShellExecute = openConsole;
+ p.CreateNoWindow = !openConsole;
+ p.WindowStyle = windowStyle;
return p;
}

Clean up API a bit more.