rdt-client/server/RdtClient.Service/Wrappers/Process.cs
Cucumberrbob fd073b4762
Add interfaces for TorrentData, Downloads, Process, ProcessFactory
Making them interfaces lets us dependency inject them, allowing a given class to be tested.
2025-02-17 21:57:29 +00:00

44 lines
1 KiB
C#

using System.Diagnostics;
namespace RdtClient.Service.Wrappers;
public class Process : IProcess
{
private readonly System.Diagnostics.Process _process = new();
public ProcessStartInfo StartInfo
{
get => _process.StartInfo;
set => _process.StartInfo = value;
}
public event EventHandler<String?>? OutputDataReceived;
public event EventHandler<String?>? ErrorDataReceived;
public void Dispose()
{
_process.Dispose();
}
public void BeginOutputReadLine()
{
_process.OutputDataReceived += (sender, args) => OutputDataReceived?.Invoke(sender, args.Data);
_process.BeginOutputReadLine();
}
public void BeginErrorReadLine()
{
_process.ErrorDataReceived += (sender, args) => ErrorDataReceived?.Invoke(sender, args.Data);
_process.BeginErrorReadLine();
}
public Boolean WaitForExit(Int32 milliseconds)
{
return _process.WaitForExit(milliseconds);
}
public void Start()
{
_process.Start();
}
}