Class ServiceTaskHandler
Uses ILogger<TCategoryName>, ICredentialProvider and CancellationTokenSource from IServiceProvider if available. Executes tasks silently and suppresses any questions.
Implements
Namespace: NanoByte.Common.Tasks
Assembly: NanoByte.Common.dll
Syntax
public class ServiceTaskHandler : Object, ITaskHandler
Remarks
This class is thread-safe.
Constructors
ServiceTaskHandler(IServiceProvider)
Creates a new service task handler.
Registers a Handler if provider
provides ILogger<TCategoryName>.
Declaration
public ServiceTaskHandler(IServiceProvider provider)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | provider | The DI container to check for ILogger<TCategoryName>, ICredentialProvider and CancellationTokenSource. |
Properties
CancellationToken
Used to signal when the user wants to cancel the entire current process (and any ITasks it includes).
Declaration
public CancellationToken CancellationToken { get; }
Property Value
Type | Description |
---|---|
CancellationToken |
Remarks
Once this has been signalled this ITaskHandler cannot be reused, since any subsequently started ITasks will be cancelled immediately.
Verbosity
Always returns Batch.
Declaration
public Verbosity Verbosity { get; set; }
Property Value
Type | Description |
---|---|
Verbosity |
Methods
Ask(String, Nullable<Boolean>, String)
Returns defaultAnswer
if specified or false
otherwise.
Declaration
public bool Ask(string question, Nullable<bool> defaultAnswer = null, string alternateMessage = null)
Parameters
Type | Name | Description |
---|---|---|
String | question | |
Nullable<Boolean> | defaultAnswer | |
String | alternateMessage |
Returns
Type | Description |
---|---|
Boolean |
Dispose()
Unregisters the Handler.
Declaration
public virtual void Dispose()
Error(Exception)
Displays an error message to the user.
Declaration
public void Error(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception | The exception representing the error that occurred. |
Output(String, String)
Displays multi-line text to the user.
Declaration
public void Output(string title, string message)
Parameters
Type | Name | Description |
---|---|---|
String | title | A title for the message. |
String | message | The string to display. Trailing linebreaks are appropriately handled or ignored. |
Remarks
Implementations may close the UI as a side effect. Therefore this should be your last call on the handler.
Output<T>(String, NamedCollection<T>)
Displays tree-like data to the user.
Declaration
public void Output<T>(string title, NamedCollection<T> data)
where T : INamed
Parameters
Type | Name | Description |
---|---|---|
String | title | A title for the data.INamed |
NamedCollection<T> | data | The data to display. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
Implementations may close the UI as a side effect. Therefore this should be your last call on the handler.
Output<T>(String, IEnumerable<T>)
Displays tabular data to the user.
Declaration
public void Output<T>(string title, IEnumerable<T> data)
Parameters
Type | Name | Description |
---|---|---|
String | title | A title for the data. |
IEnumerable<T> | data | The data to display. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
Implementations may close the UI as a side effect. Therefore this should be your last call on the handler.
RunTask(ITask)
Runs an ITask and tracks its progress. Returns once the task has been completed.
Declaration
public void RunTask(ITask task)
Parameters
Type | Name | Description |
---|---|---|
ITask | task | The task to be run. (Run(CancellationToken, ICredentialProvider, IProgress<TaskSnapshot>) or equivalent is called on it.) |
Exceptions
Type | Condition |
---|---|
System.OperationCanceledException | The user canceled the task. |
IOException | The task ended with IOError. |
WebException | The task ended with WebError. |