diff --git a/SystemInterface/Diagnostics/IProcess.cs b/SystemInterface/Diagnostics/IProcess.cs index a3ca7fe..499128e 100644 --- a/SystemInterface/Diagnostics/IProcess.cs +++ b/SystemInterface/Diagnostics/IProcess.cs @@ -45,6 +45,11 @@ public interface IProcess /// IProcessStartInfo StartInfo { get; set; } + /// + /// Immediately stops the associated process. + /// + void Kill(); + /// /// Instructs the ProcessInstance component to wait indefinitely for the associated process to exit. /// diff --git a/SystemInterface/Diagnostics/IProcessFactory.cs b/SystemInterface/Diagnostics/IProcessFactory.cs new file mode 100644 index 0000000..256787d --- /dev/null +++ b/SystemInterface/Diagnostics/IProcessFactory.cs @@ -0,0 +1,31 @@ +using System.Diagnostics; + +namespace SystemInterface.Diagnostics +{ + /// + /// Interface for wrapping static methods of the class. + /// + public interface IProcessFactory + { + /// + /// Gets a wrapped System.Diagnostics.Process component and associates it with the currently active process. + /// + /// A wrapped System.Diagnostics.Process component associated with the process resource that is running the calling application. + IProcess GetCurrentProcess(); + + /// + /// Returns a wrapped System.Diagnostics.Process component, given the identifier of a process on the local computer. + /// + /// The system-unique identifier of a process resource. + /// A wrapped System.Diagnostics.Process component that is associated with the local process resource identified by the processId parameter. + IProcess GetProcessById(int processId); + + /// + /// Returns a wrapped System.Diagnostics.Process component, given the identifier of a process on on the network. + /// + /// The system-unique identifier of a process resource. + /// The name of a computer on the network. + /// A wrapped System.Diagnostics.Process component that is associated with a remote process resource identified by the processId parameter. + IProcess GetProcessById(int processId, string machineName); + } +} diff --git a/SystemInterface/SystemInterface.csproj b/SystemInterface/SystemInterface.csproj index a11850b..7fa873a 100644 --- a/SystemInterface/SystemInterface.csproj +++ b/SystemInterface/SystemInterface.csproj @@ -93,6 +93,7 @@ + diff --git a/SystemWrapper/Diagnostics/ProcessFactory.cs b/SystemWrapper/Diagnostics/ProcessFactory.cs new file mode 100644 index 0000000..f0feed8 --- /dev/null +++ b/SystemWrapper/Diagnostics/ProcessFactory.cs @@ -0,0 +1,35 @@ +using System.Diagnostics; +using SystemInterface.Diagnostics; + +namespace SystemWrapper.Diagnostics +{ + /// + /// Wrapper implementation of static methods from the class. + /// + public class ProcessFactory : IProcessFactory + { + /// + public IProcess GetCurrentProcess() + { + var process = Process.GetCurrentProcess(); + + return new ProcessWrap(process); + } + + /// + public IProcess GetProcessById(int processId) + { + var process = Process.GetProcessById(processId); + + return new ProcessWrap(process); + } + + /// + public IProcess GetProcessById(int processId, string machineName) + { + var process = Process.GetProcessById(processId, machineName); + + return new ProcessWrap(process); + } + } +} diff --git a/SystemWrapper/Diagnostics/ProcessWrap.cs b/SystemWrapper/Diagnostics/ProcessWrap.cs index 422def4..bcc6e42 100644 --- a/SystemWrapper/Diagnostics/ProcessWrap.cs +++ b/SystemWrapper/Diagnostics/ProcessWrap.cs @@ -1,4 +1,3 @@ -using System; using System.Diagnostics; using SystemInterface.Diagnostics; using SystemInterface.IO; @@ -22,12 +21,28 @@ public ProcessWrap() Initialize(); } + /// + /// Initializes a new instance of the class. + /// + /// object used to initialize + /// class + /// + internal ProcessWrap(Process process) + { + Initialize(process); + } + /// /// Initializes a new instance of the class. /// public void Initialize() { - ProcessInstance = new Process(); + Initialize(new Process()); + } + + private void Initialize(Process process) + { + ProcessInstance = process; } #endregion Constructors and Initializers @@ -56,7 +71,10 @@ public bool Start() /// 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; @@ -64,6 +82,12 @@ public IProcessStartInfo StartInfo } } + /// + public void Kill() + { + ProcessInstance.Kill(); + } + /// public IStreamReader StandardOutput { diff --git a/SystemWrapper/SystemWrapper.csproj b/SystemWrapper/SystemWrapper.csproj index e53bf1d..b993085 100644 --- a/SystemWrapper/SystemWrapper.csproj +++ b/SystemWrapper/SystemWrapper.csproj @@ -102,6 +102,7 @@ +