From 13e401c8ddda4a0947acbdce64856e4f9cd73249 Mon Sep 17 00:00:00 2001 From: Michal Wereda Date: Fri, 17 Mar 2017 21:17:06 +0100 Subject: [PATCH 1/3] Process Kill method implemented --- SystemInterface/Diagnostics/IProcess.cs | 5 +++++ SystemWrapper/Diagnostics/ProcessWrap.cs | 6 ++++++ 2 files changed, 11 insertions(+) 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/SystemWrapper/Diagnostics/ProcessWrap.cs b/SystemWrapper/Diagnostics/ProcessWrap.cs index 422def4..33a93ad 100644 --- a/SystemWrapper/Diagnostics/ProcessWrap.cs +++ b/SystemWrapper/Diagnostics/ProcessWrap.cs @@ -64,6 +64,12 @@ public IProcessStartInfo StartInfo } } + /// + public void Kill() + { + ProcessInstance.Kill(); + } + /// public IStreamReader StandardOutput { From 6deee6c809381de0e55c7c9447e7e6761fcc1621 Mon Sep 17 00:00:00 2001 From: Michal Wereda Date: Fri, 17 Mar 2017 21:33:11 +0100 Subject: [PATCH 2/3] ProcessWrap extended with GetProcessById methods --- SystemInterface/Diagnostics/IProcess.cs | 21 +++++++++++++++++++++ SystemWrapper/Diagnostics/ProcessWrap.cs | 24 ++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/SystemInterface/Diagnostics/IProcess.cs b/SystemInterface/Diagnostics/IProcess.cs index 499128e..588d701 100644 --- a/SystemInterface/Diagnostics/IProcess.cs +++ b/SystemInterface/Diagnostics/IProcess.cs @@ -78,6 +78,27 @@ public interface IProcess [MonitoringDescription("ProcessStandardOutput"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)] IStreamReader StandardOutput { get; } + /// + /// Gets a new System.Diagnostics.Process component and associates it with the currently active process. + /// + /// A new System.Diagnostics.Process component associated with the process resource that is running the calling application. + Process GetCurrentProcess(); + + /// + /// Returns a new System.Diagnostics.Process component, given the identifier of a process on the local computer. + /// + /// The system-unique identifier of a process resource. + /// A System.Diagnostics.Process component that is associated with the local process resource identified by the processId parameter. + Process GetProcessById(int processId); + + /// + /// Returns a new 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 System.Diagnostics.Process component that is associated with a remote process resource identified by the processId parameter. + Process GetProcessById(int processId, string machineName); + /* // Events diff --git a/SystemWrapper/Diagnostics/ProcessWrap.cs b/SystemWrapper/Diagnostics/ProcessWrap.cs index 33a93ad..6807dc8 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; @@ -56,7 +55,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; @@ -96,5 +98,23 @@ public bool WaitForInputIdle() { return ProcessInstance.WaitForInputIdle(); } + + /// + public Process GetCurrentProcess() + { + return Process.GetCurrentProcess(); + } + + /// + public Process GetProcessById(int processId) + { + return Process.GetProcessById(processId); + } + + /// + public Process GetProcessById(int processId, string machineName) + { + return Process.GetProcessById(processId, machineName); + } } } \ No newline at end of file From d1d9632926b96172a9021bd3e171c8e3e4abff33 Mon Sep 17 00:00:00 2001 From: Michal Wereda Date: Sun, 19 Mar 2017 19:51:04 +0100 Subject: [PATCH 3/3] IProcessFactory introduced --- SystemInterface/Diagnostics/IProcess.cs | 21 ----------- .../Diagnostics/IProcessFactory.cs | 31 ++++++++++++++++ SystemInterface/SystemInterface.csproj | 1 + SystemWrapper/Diagnostics/ProcessFactory.cs | 35 ++++++++++++++++++ SystemWrapper/Diagnostics/ProcessWrap.cs | 36 +++++++++---------- SystemWrapper/SystemWrapper.csproj | 1 + 6 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 SystemInterface/Diagnostics/IProcessFactory.cs create mode 100644 SystemWrapper/Diagnostics/ProcessFactory.cs diff --git a/SystemInterface/Diagnostics/IProcess.cs b/SystemInterface/Diagnostics/IProcess.cs index 588d701..499128e 100644 --- a/SystemInterface/Diagnostics/IProcess.cs +++ b/SystemInterface/Diagnostics/IProcess.cs @@ -78,27 +78,6 @@ public interface IProcess [MonitoringDescription("ProcessStandardOutput"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)] IStreamReader StandardOutput { get; } - /// - /// Gets a new System.Diagnostics.Process component and associates it with the currently active process. - /// - /// A new System.Diagnostics.Process component associated with the process resource that is running the calling application. - Process GetCurrentProcess(); - - /// - /// Returns a new System.Diagnostics.Process component, given the identifier of a process on the local computer. - /// - /// The system-unique identifier of a process resource. - /// A System.Diagnostics.Process component that is associated with the local process resource identified by the processId parameter. - Process GetProcessById(int processId); - - /// - /// Returns a new 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 System.Diagnostics.Process component that is associated with a remote process resource identified by the processId parameter. - Process GetProcessById(int processId, string machineName); - /* // Events 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 6807dc8..bcc6e42 100644 --- a/SystemWrapper/Diagnostics/ProcessWrap.cs +++ b/SystemWrapper/Diagnostics/ProcessWrap.cs @@ -21,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 @@ -98,23 +114,5 @@ public bool WaitForInputIdle() { return ProcessInstance.WaitForInputIdle(); } - - /// - public Process GetCurrentProcess() - { - return Process.GetCurrentProcess(); - } - - /// - public Process GetProcessById(int processId) - { - return Process.GetProcessById(processId); - } - - /// - public Process GetProcessById(int processId, string machineName) - { - return Process.GetProcessById(processId, machineName); - } } } \ No newline at end of file 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 @@ +