Class CliTaskHandler
Informs the user about the progress of tasks and ask questions using console output.
[MustDisposeResource]
public class CliTaskHandler : TaskHandlerBase, ITaskHandler
- Inheritance
-
CliTaskHandler
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
This class is thread-safe.
Constructors
CliTaskHandler()
Creates a new CLI task handler. Registers a Handler and a CancelKeyPress handler.
public CliTaskHandler()
Properties
CredentialProvider
Used to ask the user or a keyring for NetworkCredentials for specific Uris; can be null
.
protected override ICredentialProvider CredentialProvider { get; }
Property Value
IsInteractive
Indicates whether the user can provide input.
protected override bool IsInteractive { get; }
Property Value
Methods
AskInteractive(string, bool)
Asks the user a Yes/No/Cancel question.
protected override bool AskInteractive(string question, bool defaultAnswer)
Parameters
question
stringThe question and comprehensive information to help the user make an informed decision.
defaultAnswer
boolThe default answer to preselect.
Returns
- bool
true
if the user answered with 'Yes';false
if the user answered with 'No'.
Exceptions
- OperationCanceledException
Throw if the user answered with 'Cancel'.
DisplayLogEntry(LogSeverity, string)
protected override void DisplayLogEntry(LogSeverity severity, string message)
Parameters
severity
LogSeveritymessage
string
Dispose()
Unregisters the Handler and the CancelKeyPress handler.
public override void Dispose()
Error(Exception)
Displays an error message to the user.
public override void Error(Exception exception)
Parameters
exception
ExceptionThe exception representing the error that occurred.
GetLogColor(LogSeverity)
Determines the color to use for a log entry based on the LogSeverity.
protected static ConsoleColor GetLogColor(LogSeverity severity)
Parameters
severity
LogSeverity
Returns
Output(string, string)
Displays multi-line text to the user.
public override void Output(string title, string message)
Parameters
title
stringA title for the message.
message
stringThe 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.
RunTask(ITask)
Runs an ITask and tracks its progress. Returns once the task has been completed.
public override void RunTask(ITask task)
Parameters
task
ITaskThe task to be run. (Run(CancellationToken, ICredentialProvider?, IProgress<TaskSnapshot>?) or equivalent is called on it.)
Exceptions
- OperationCanceledException
The user canceled the task.
- IOException
The task ended with IOError.
- WebException
The task ended with WebError.