Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SystemInterface/Diagnostics/IProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public interface IProcess
/// </summary>
IProcessStartInfo StartInfo { get; set; }

/// <summary>
/// Immediately stops the associated process.
/// </summary>
void Kill();

/// <summary>
/// Instructs the ProcessInstance component to wait indefinitely for the associated process to exit.
/// </summary>
Expand Down
31 changes: 31 additions & 0 deletions SystemInterface/Diagnostics/IProcessFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Diagnostics;

namespace SystemInterface.Diagnostics
{
/// <summary>
/// Interface for wrapping static methods of the <see cref="Process"/> class.
/// </summary>
public interface IProcessFactory
{
/// <summary>
/// Gets a wrapped System.Diagnostics.Process component and associates it with the currently active process.
/// </summary>
/// <returns>A wrapped System.Diagnostics.Process component associated with the process resource that is running the calling application.</returns>
IProcess GetCurrentProcess();

/// <summary>
/// Returns a wrapped System.Diagnostics.Process component, given the identifier of a process on the local computer.
/// </summary>
/// <param name="processId">The system-unique identifier of a process resource.</param>
/// <returns>A wrapped System.Diagnostics.Process component that is associated with the local process resource identified by the processId parameter.</returns>
IProcess GetProcessById(int processId);

/// <summary>
/// Returns a wrapped System.Diagnostics.Process component, given the identifier of a process on on the network.
/// </summary>
/// <param name="processId">The system-unique identifier of a process resource.</param>
/// <param name="machineName">The name of a computer on the network.</param>
/// <returns>A wrapped System.Diagnostics.Process component that is associated with a remote process resource identified by the processId parameter.</returns>
IProcess GetProcessById(int processId, string machineName);
}
}
1 change: 1 addition & 0 deletions SystemInterface/SystemInterface.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Diagnostics\IFileVersionInfo.cs" />
<Compile Include="Diagnostics\IFileVersionInfoFactory.cs" />
<Compile Include="Diagnostics\IProcess.cs" />
<Compile Include="Diagnostics\IProcessFactory.cs" />
<Compile Include="Diagnostics\IProcessStartInfo.cs" />
<Compile Include="Diagnostics\ITraceSource.cs" />
<Compile Include="Globalization\ICultureInfo.cs" />
Expand Down
35 changes: 35 additions & 0 deletions SystemWrapper/Diagnostics/ProcessFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Diagnostics;
using SystemInterface.Diagnostics;

namespace SystemWrapper.Diagnostics
{
/// <summary>
/// Wrapper implementation of static methods from the <see cref="Process"/> class.
/// </summary>
public class ProcessFactory : IProcessFactory
{
/// <inheritdoc />
public IProcess GetCurrentProcess()
{
var process = Process.GetCurrentProcess();

return new ProcessWrap(process);
}

/// <inheritdoc />
public IProcess GetProcessById(int processId)
{
var process = Process.GetProcessById(processId);

return new ProcessWrap(process);
}

/// <inheritdoc />
public IProcess GetProcessById(int processId, string machineName)
{
var process = Process.GetProcessById(processId, machineName);

return new ProcessWrap(process);
}
}
}
30 changes: 27 additions & 3 deletions SystemWrapper/Diagnostics/ProcessWrap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
using SystemInterface.Diagnostics;
using SystemInterface.IO;
Expand All @@ -22,12 +21,28 @@ public ProcessWrap()
Initialize();
}

/// <summary>
/// Initializes a new instance of the <see cref="T:SystemWrapper.Diagnostics.ProcessWrap"/> class.
/// </summary>
/// <param name="process"><see cref="T:System.Diagnostics.Process"/> object used to initialize
/// <see cref="T:SystemWrapper.Diagnostics.ProcessWrap"/> class
/// </param>
internal ProcessWrap(Process process)
{
Initialize(process);
}

/// <summary>
/// Initializes a new instance of the <see cref="T:SystemWrapper.Diagnostics.ProcessWrap"/> class.
/// </summary>
public void Initialize()
{
ProcessInstance = new Process();
Initialize(new Process());
}

private void Initialize(Process process)
{
ProcessInstance = process;
}

#endregion Constructors and Initializers
Expand Down Expand Up @@ -56,14 +71,23 @@ public bool Start()
/// <inheritdoc />
public IProcessStartInfo StartInfo
{
get { return this._startInfo ?? (this._startInfo = new ProcessStartInfoWrap(ProcessInstance.StartInfo)); }
get
{
return this._startInfo ?? (this._startInfo = new ProcessStartInfoWrap(ProcessInstance.StartInfo));
}
set
{
this._startInfo = value;
ProcessInstance.StartInfo = _startInfo.ProcessStartInfoInstance;
}
}

/// <inheritdoc />
public void Kill()
{
ProcessInstance.Kill();
}

/// <inheritdoc />
public IStreamReader StandardOutput
{
Expand Down
1 change: 1 addition & 0 deletions SystemWrapper/SystemWrapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<Compile Include="DateTimeWrap.cs" />
<Compile Include="Diagnostics\FileVersionInfoWrap.cs" />
<Compile Include="Diagnostics\FileVersionInfoFactory.cs" />
<Compile Include="Diagnostics\ProcessFactory.cs" />
<Compile Include="Diagnostics\ProcessStartInfoWrap.cs" />
<Compile Include="Diagnostics\ProcessWrap.cs" />
<Compile Include="Diagnostics\TraceSourceWrap.cs" />
Expand Down