/// <summary> /// Initializes a new instance of the <see cref="ConcurrencyCommandBase"/> class. /// </summary> /// <param name="execute">The execute.</param> /// <param name="canExecuteSubject">The can execute subject.</param> /// <param name="completed">The completed.</param> /// <param name="error">The error.</param> /// <param name="cancel">The cancel.</param> /// <exception cref="ArgumentNullException">canExecuteSubject</exception> protected ConcurrencyCommandBase( [NotNull] Action <T, CancellationToken> execute, [NotNull] ICanExecuteSubject canExecuteSubject, [CanBeNull] Action completed = null, [CanBeNull] Action <Exception> error = null, [CanBeNull] Action cancel = null) { this.execute = execute; if (canExecuteSubject == null) { throw new ArgumentNullException(nameof(canExecuteSubject)); } this.canExecute = (t) => canExecuteSubject.CanExecute(); this.completed = completed; this.error = error; this.cancel = cancel; this.cancelCommand = new DirectCommand(this.Cancel, () => this.IsExecuting); }
/// <summary> /// Initializes a new instance of the <see cref="ConcurrencyCommandBase"/> class. /// </summary> /// <param name="execute">The execute.</param> /// <param name="canExecuteSubject">The can execute subject.</param> /// <param name="completed">The completed.</param> /// <param name="error">The error.</param> /// <param name="cancel">The cancel.</param> /// <exception cref="ArgumentNullException">canExecuteSubject</exception> protected ConcurrencyAsyncCommandBase( [NotNull] Func <T, CancellationToken, Task> execute, [NotNull] ICanExecuteSubject canExecuteSubject, [CanBeNull] Func <Task> completed = null, [CanBeNull] Func <Exception, Task> error = null, [CanBeNull] Func <Task> cancel = null) { this.execute = execute; if (canExecuteSubject == null) { throw new ArgumentNullException(nameof(canExecuteSubject)); } this.canExecute = _ => canExecuteSubject.CanExecute(); this.completed = completed; this.error = error; this.cancel = cancel; this.Dispatcher = Dispatcher.CurrentDispatcher; this.cancelCommand = new DirectCommand(this.Cancel, () => this.IsExecuting); }