/// <summary> /// Will execute the command on a background thread. /// </summary> /// <param name="builder">The builder.</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder OnBackgroundThread(this IDynamicCommandBuilder builder) => builder.WithStrategy(new BackgroundCommandStrategy());
/// <summary> /// Will attach the <see cref="ICommand.CanExecute(object)"/> to the specified <see cref="IDynamicProperty"/>. /// </summary> /// <param name="builder">The builder.</param> /// <param name="canExecute"><see cref="IDynamicProperty"/> that affects the CanExecute</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder WithCanExecute(this IDynamicCommandBuilder builder, IDynamicProperty <bool> canExecute) => builder.WithStrategy(new CanExecuteCommandStrategy(canExecute));
/// <summary> /// Will cancel the previous command execution when executing the command. /// </summary> /// <param name="builder">The builder.</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder CancelPrevious(this IDynamicCommandBuilder builder) => builder.WithStrategy(new CancelPreviousCommandStrategy());
/// <summary> /// Will disable the command while it's executing. /// </summary> /// <param name="builder">The builder.</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder DisableWhileExecuting(this IDynamicCommandBuilder builder) => builder.WithStrategy(new DisableWhileExecutingCommandStrategy());
/// <summary> /// Will catch any exception thrown by the execution of the command and delegate it to the specified error handler. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorHandler">Error handler</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder CatchErrors(this IDynamicCommandBuilder builder, Func <CancellationToken, IDynamicCommand, Exception, Task> errorHandler) => builder.WithStrategy(new ErrorHandlerCommandStrategy(new DynamicCommandErrorHandler(errorHandler)));
/// <summary> /// Will catch any exception thrown by the execution of the command and delegate it to the specified error handler. /// </summary> /// <param name="builder">The builder.</param> /// <param name="errorHandler">Error handler</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder CatchErrors(this IDynamicCommandBuilder builder, IDynamicCommandErrorHandler errorHandler) => builder.WithStrategy(new ErrorHandlerCommandStrategy(errorHandler));
/// <summary> /// Will add logs to the command execution. /// </summary> /// <param name="builder">The builder.</param> /// <param name="logger">Optional; the desired logger. If null is passed, a new one will be created using <see cref="DynamicMvvmConfiguration.LoggerFactory"/>.</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder WithLogs(this IDynamicCommandBuilder builder, ILogger logger = null) => builder.WithStrategy(new LoggerCommandStrategy(logger ?? typeof(IDynamicCommand).Log()));
/// <summary> /// Will lock the command execution. /// </summary> /// <param name="builder">The builder.</param> /// <returns><see cref="IDynamicCommandBuilder"/></returns> public static IDynamicCommandBuilder Locked(this IDynamicCommandBuilder builder) => builder.WithStrategy(new LockCommandStrategy());