Show / Hide Table of Contents

Interface ITaskHandler

Used to run and track ITasks and ask the user questions. Specific implementations provide different kinds of user interfaces.

Namespace: NanoByte.Common.Tasks
Assembly: NanoByte.Common.dll
Syntax
public interface ITaskHandler
Remarks

Implementations of this interface are thread-safe.

Properties

CancellationToken

Used to signal when the user wants to cancel the entire current process (and any ITasks it includes).

Declaration
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

The detail level of messages displayed to the user.

Declaration
Verbosity Verbosity { get; set; }
Property Value
Type Description
Verbosity

Methods

Ask(String, Nullable<Boolean>, String)

Asks the user a Yes/No/Cancel question.

Declaration
bool Ask(string question, Nullable<bool> defaultAnswer = null, string alternateMessage = null)
Parameters
Type Name Description
String question

The question and comprehensive information to help the user make an informed decision.

Nullable<Boolean> defaultAnswer

The default answer to preselect. May be chosen automatically if the user cannot be asked. null if the user must make the choice themselves.

String alternateMessage

A message to output with Warn(String, Exception) when the defaultAnswer is used instead of asking the user.

Returns
Type Description
Boolean

true if the user answered with 'Yes'; false if the user answered with 'No'.

Exceptions
Type Condition
OperationCanceledException

Throw if the user answered with 'Cancel' or if no answer can be obtained.

Error(Exception)

Displays an error message to the user.

Declaration
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
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
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
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
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
OperationCanceledException

The user canceled the task.

IOException

The task ended with IOError.

WebException

The task ended with WebError.

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
TaskHandlerExtensions.OutputLow(ITaskHandler, String, String)
TaskHandlerExtensions.OutputLow<T>(ITaskHandler, String, IEnumerable<T>)
TaskHandlerExtensions.OutputLow<T>(ITaskHandler, String, NamedCollection<T>)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher