Class ExecuteProcessWorker
A worker that launches an external process, e.g. an executable, a batch script, or a document.
On successful completion, the exit code from the process is stored in ExitCode.
By default, a zero exit code will give the worker a Succeeded status,
any other exit code will give it an Error
status.
See the Process and ProcessStartInfo classes for background information.
Implements
Inherited Members
Namespace: actionETL
Assembly: actionETL.dll
Syntax
public class ExecuteProcessWorker : WorkerBase<ExecuteProcessWorker>, IDisposeOnFinished
Constructors
ExecuteProcessWorker(WorkerParent, String, ProcessStartInfo)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, ProcessStartInfo processStartInfo)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
ProcessStartInfo | processStartInfo | Use a ProcessStartInfo overload to customize how the process is launched. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, Func<Boolean>, ProcessStartInfo)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, ProcessStartInfo processStartInfo)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
ProcessStartInfo | processStartInfo | Use a ProcessStartInfo overload to customize how the process is launched. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, Func<Boolean>, String)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, string fileName)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
String | fileName | Name of the file to launch. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, Func<Boolean>, String, String)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, string fileName, string arguments)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
String | fileName | Name of the file to launch. |
String | arguments | Command line arguments. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, Func<Boolean>, String, String, String, SecureString, String)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, Func<bool> isStartableFunc, string fileName, string arguments, string userName, SecureString password, string domain)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
Func<Boolean> | isStartableFunc | Function to calculate the worker start constraint; it should return |
String | fileName | Name of the file to launch. |
String | arguments | Command line arguments. |
String | userName | Name of the user. |
SecureString | password | The password. |
String | domain | The domain. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, String)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, string fileName)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
String | fileName | Name of the file to launch. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, String, String)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, string fileName, string arguments)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
String | fileName | Name of the file to launch. |
String | arguments | Command line arguments. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
ExecuteProcessWorker(WorkerParent, String, String, String, String, SecureString, String)
Initializes a new instance of the ExecuteProcessWorker worker that launches an external process, e.g. an executable, a batch script, or a document.
Declaration
public ExecuteProcessWorker(WorkerParent workerParent, string workerName, string fileName, string arguments, string userName, SecureString password, string domain)
Parameters
Type | Name | Description |
---|---|---|
WorkerParent | workerParent | The parent worker or worker system that the new child worker will be added to. Cannot be |
String | workerName | Name of the worker.
Set to a prefix plus a trailing
While less useful, set to
The name cannot otherwise contain |
String | fileName | Name of the file to launch. |
String | arguments | Command line arguments. |
String | userName | Name of the user. |
SecureString | password | The password. |
String | domain | The domain. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ArgumentNullException |
|
InvalidOperationException |
|
Properties
ExitCode
Gets the exit code specified by the process. Only available after the worker has completed.
Each process defines the meaning of its exit codes;
by default a zero exit code will give the worker a Succeeded status,
any other will give it an Error
status.
Also see ExitCodeOutcomeStatusFunc.
Note: This property is thread-safe.
Declaration
public int ExitCode { get; }
Property Value
Type | Description |
---|---|
Int32 | The exit code. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException |
|
ExitCodeOutcomeStatusFunc
Gets or sets the callback that takes the exit code and returns the OutcomeStatus
for the worker.
Can only be set before the worker is started.
Do use ExecuteProcessWorkerExitCodeFailure as the category when returning a failure status.
The default callback converts a 0
exit code into Succeeded,
and any other exit code into an Error
status.
Also see ExitCode.
Note: This property is thread-safe.
Declaration
public Func<int, OutcomeStatus> ExitCodeOutcomeStatusFunc { get; set; }
Property Value
Type | Description |
---|---|
Func<Int32, OutcomeStatus> |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | ExitCodeOutcomeStatusFunc |
InvalidOperationException | Cannot set the value after the worker has started. |
StandardErrorAction
Gets or sets a callback to process each text line the started process sends to StandardError. This setting is mutually exclusive with StandardErrorLines.
Defaults to null
. Can only be set before the worker starts running.
For each call to the callback, the string
parameter contains a single line of text.
After the final line, a null or empty string might be sent, therefore always check the line
with String.IsNullOrEmpty()
before using it.
Note: This property is thread-safe.
Declaration
public Action<Process, string> StandardErrorAction { get; set; }
Property Value
Type | Description |
---|---|
Action<Process, String> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cannot set the value after the worker has started running. |
StandardErrorLines
Gets or sets the standard error lines collection, e.g. a List<string>
,
to store ErrorOutput lines in.
This setting is mutually exclusive with StandardErrorAction.
Defaults to null
. Can only be set before the worker has started.
Note that accessing the items in the collection while the worker is running is only
supported if the collection is thread-safe.
Note: This property is thread-safe.
Declaration
public ICollection<string> StandardErrorLines { get; set; }
Property Value
Type | Description |
---|---|
ICollection<String> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cannot set the value after the worker has started running. |
StandardInputAction
Gets or sets a callback that writes data to the input stream of the started process. Can only be set before the worker starts running. This setting is mutually exclusive with StandardInputString.
Call StreamWriter.Close
to close the stream after all data has been written.
Note: This property is thread-safe.
Declaration
public Action<StreamWriter> StandardInputAction { get; set; }
Property Value
Type | Description |
---|---|
Action<StreamWriter> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cannot set the value after the worker has started running. |
StandardInputString
Gets or sets a string that will be sent to the standard input of the process. Can only be set before the worker starts running. This setting is mutually exclusive with StandardInputAction.
Note: This property is thread-safe.
Declaration
public string StandardInputString { get; set; }
Property Value
Type | Description |
---|---|
String |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cannot set the value after the worker has started running. |
StandardOutputAction
Gets or sets a callback to process each text line the started process sends to StandardOutput. This setting is mutually exclusive with StandardOutputLines.
Defaults to null
. Can only be set before the worker starts running.
For each call to the callback, the string
parameter contains a single line of text.
After the final line, a null or empty string might be sent, therefore always check the line
with String.IsNullOrEmpty()
before using it.
Note: This property is thread-safe.
Declaration
public Action<Process, string> StandardOutputAction { get; set; }
Property Value
Type | Description |
---|---|
Action<Process, String> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cannot set the value after the worker has started running. |
StandardOutputLines
Gets or sets the standard output lines collection, e.g. a List<string>
,
to store ErrorOutput lines in.
This setting is mutually exclusive with StandardOutputAction.
Defaults to null
. Can only be set before the worker has started.
Note that accessing the items in the collection while the worker is running is only
supported if the collection is thread-safe.
Note: This property is thread-safe.
Declaration
public ICollection<string> StandardOutputLines { get; set; }
Property Value
Type | Description |
---|---|
ICollection<String> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Cannot set the value after the worker has started running. |
Methods
RunAsync()
This method can be overridden to add custom functionality to the derived worker that runs before
and after the main processing. In this case, the base class base.RunAsync()
must
be called for the worker to function correctly.
Typically, this worker is used without overriding this method.
Declaration
protected override Task<OutcomeStatus> RunAsync()
Returns
Type | Description |
---|---|
Task<OutcomeStatus> | A |