-
Notifications
You must be signed in to change notification settings - Fork 59
Extended ProcessWrap with GetProcessById, GetCurrentProcess() and Kill methods #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mwereda
wants to merge
4
commits into
jozefizso:master
Choose a base branch
from
mwereda:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -73,6 +78,27 @@ public interface IProcess | |
| [MonitoringDescription("ProcessStandardOutput"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)] | ||
| IStreamReader StandardOutput { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a new System.Diagnostics.Process component and associates it with the currently active process. | ||
| /// </summary> | ||
| /// <returns>A new System.Diagnostics.Process component associated with the process resource that is running the calling application.</returns> | ||
| Process GetCurrentProcess(); | ||
|
|
||
| /// <summary> | ||
| /// Returns a new 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 System.Diagnostics.Process component that is associated with the local process resource identified by the processId parameter.</returns> | ||
| Process GetProcessById(int processId); | ||
|
||
|
|
||
| /// <summary> | ||
| /// Returns a new 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 System.Diagnostics.Process component that is associated with a remote process resource identified by the processId parameter.</returns> | ||
| Process GetProcessById(int processId, string machineName); | ||
|
||
|
|
||
| /* | ||
|
|
||
| // Events | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return the
IProcessinterface to allow proper mocking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation of this method calls static Process.GetCurrentProcess which returns object of Process class. If we would like to return IProcess we would have to return here ProcessWrap instance or any other class implementing IProcess that would have to be created.
This would make the code a little bit more complicated. Although there are benefits for returning IProcess here, I believe that in majority of cases current implementation should be enough.
If someone would see benefits for himself having IProcess being returned I'm happy to implement it. For our needs it's enough to just return Process object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this library is test-ability of the code and easy mocking. If the return value cannot be mocked, there is no point in implementing this API in this library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed approach. I introduced IProcessFactory that is responsible for creating IProcess object. So basically all Process static methods are placed there.
Now we are able to return IProcess instead of Process