Add ProcessBuilder and remove IProcessBridge.Start()
MODIFY
WalletWasabi.Gui/CrashReport/CrashReporter.cs
WalletWasabi.Gui/CrashReport/CrashReporter.cs
@@ -31,8 +31,8 @@ namespace WalletWasabi.Gui.CrashReport
var args = $"crashreport -attempt=\"{Attempts + 1}\" -exception=\"{Base64ExceptionString}\"";
- ProcessBridge processBridge = new ProcessBridge(Process.GetCurrentProcess().MainModule.FileName);
- processBridge.Start(args, openConsole: false);
+ Process p = ProcessBuilder.BuildProcessInstance(Process.GetCurrentProcess().MainModule.FileName, args);
+ p.Start();
}
catch (Exception ex)
{

MODIFY
WalletWasabi.Tests/UnitTests/Hwi/HwiProcessBridgeMock.cs
WalletWasabi.Tests/UnitTests/Hwi/HwiProcessBridgeMock.cs
@@ -262,10 +262,5 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
return extPubKey != null;
}
-
- public Process Start(string arguments, bool openConsole)
- {
- throw new NotImplementedException();
- }
}
}

MODIFY
WalletWasabi/BitcoinCore/Processes/BitcoindRpcProcessBridge.cs
WalletWasabi/BitcoinCore/Processes/BitcoindRpcProcessBridge.cs
@@ -40,7 +40,9 @@ namespace WalletWasabi.BitcoinCore.Processes
public async Task StartAsync(CancellationToken cancel)
{
var ptcv = PrintToConsole ? 1 : 0;
- _process = new ProcessAsync(CreateProcessInstance($"{NetworkTranslator.GetCommandLineArguments(Network)} -datadir={DataDir} -printtoconsole={ptcv}", openConsole: false));
+ string processPath = MicroserviceHelpers.GetBinaryPath("bitcoind");
+ string args = $"{NetworkTranslator.GetCommandLineArguments(Network)} -datadir={DataDir} -printtoconsole={ptcv}";
+ _process = new ProcessAsync(ProcessBuilder.BuildProcessInstance(processPath, args));
_process.Start();
await PidFile.WriteFileAsync(_process.Id).ConfigureAwait(false);

MODIFY
WalletWasabi/Microservices/IProcessBridge.cs
WalletWasabi/Microservices/IProcessBridge.cs
@@ -10,7 +10,5 @@ namespace WalletWasabi.Microservices
public interface IProcessBridge
{
Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel);
-
- Process Start(string arguments, bool openConsole);
}
}

MODIFY
WalletWasabi/Microservices/ProcessBridge.cs
WalletWasabi/Microservices/ProcessBridge.cs
@@ -2,11 +2,9 @@ using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
-using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Helpers;
-using WalletWasabi.Logging;
namespace WalletWasabi.Microservices
{
@@ -24,30 +22,10 @@ namespace WalletWasabi.Microservices
public string ProcessPath { get; }
- public Process Start(string arguments, bool openConsole)
- {
- var process = CreateProcessInstance(arguments, openConsole);
- try
- {
- process.Start();
- }
- catch
- {
- Logger.LogInfo($"{nameof(process.StartInfo.FileName)}: {process.StartInfo.FileName}");
- Logger.LogInfo($"{nameof(process.StartInfo.Arguments)}: {process.StartInfo.Arguments}");
- Logger.LogInfo($"{nameof(process.StartInfo.RedirectStandardOutput)}: {process.StartInfo.RedirectStandardOutput}");
- Logger.LogInfo($"{nameof(process.StartInfo.UseShellExecute)}: {process.StartInfo.UseShellExecute}");
- Logger.LogInfo($"{nameof(process.StartInfo.CreateNoWindow)}: {process.StartInfo.CreateNoWindow}");
- Logger.LogInfo($"{nameof(process.StartInfo.WindowStyle)}: {process.StartInfo.WindowStyle}");
- throw;
- }
- return process;
- }
-
public async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel)
{
// "using" makes sure the process exits at the end of this method.
- using var process = new ProcessAsync(CreateProcessInstance(arguments, openConsole));
+ using var process = new ProcessAsync(ProcessBuilder.BuildProcessInstance(ProcessPath, arguments, openConsole));
process.Start();
@@ -56,33 +34,5 @@ namespace WalletWasabi.Microservices
string responseString = openConsole ? string.Empty : await process.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
return (responseString, exitCode: process.ExitCode);
}
-
- protected Process CreateProcessInstance(string arguments, bool openConsole)
- {
- ProcessWindowStyle windowStyle;
- if (openConsole)
- {
- if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- throw new PlatformNotSupportedException($"{RuntimeInformation.OSDescription} is not supported.");
- }
-
- windowStyle = ProcessWindowStyle.Normal;
- }
- else
- {
- 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;
-
- return p;
- }
}
}

ADD
WalletWasabi/Microservices/ProcessBuilder.cs
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace WalletWasabi.Microservices
+{
+ public class ProcessBuilder
+ {
+ public static Process BuildProcessInstance(string processPath, string arguments, bool openConsole = false)
+ {
+ ProcessWindowStyle windowStyle;
+ if (openConsole)
+ {
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ throw new PlatformNotSupportedException($"{RuntimeInformation.OSDescription} is not supported.");
+ }
+
+ windowStyle = ProcessWindowStyle.Normal;
+ }
+ else
+ {
+ 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;
+
+ return p;
+ }
+ }
+}

Add ProcessBuilder and remove IProcessBridge.Start()