Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivatableCanExecuteObserverCommand" /> class.
        /// </summary>
        /// <param name="execute">The execute.</param>
        /// <param name="autoActivate">if set to <c>true</c> [automatic activate].</param>
        /// <param name="canExecuteSubject">The can execute subject.</param>
        /// <param name="observers">The observers.</param>
        /// <exception cref="ArgumentNullException">canExecuteSubject
        /// or
        /// observers</exception>
        public ActivatableConcurrencyCanExecuteObserverCommand(
            [NotNull] Action <T, CancellationToken> execute,
            bool autoActivate,
            [NotNull] ICanExecuteSubject canExecuteSubject,
            [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
            : base(execute, canExecuteSubject)
        {
            if (canExecuteSubject == null)
            {
                throw new ArgumentNullException(nameof(canExecuteSubject));
            }

            if (observers == null)
            {
                throw new ArgumentNullException(nameof(observers));
            }

            this.observers.Add(canExecuteSubject);

            this.observers.AddIfNotContains(observers);

            if (autoActivate)
            {
                this.Activate();
            }
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActivatableConcurrencyAsyncCanExecuteObserverCommand{T}" /> class.
 /// </summary>
 /// <param name="execute">The execute.</param>
 /// <param name="canExecuteSubject">The can execute subject.</param>
 /// <param name="observers">The observers.</param>
 public ActivatableConcurrencyAsyncCanExecuteObserverCommand(
     [NotNull] Func <T, CancellationToken, Task> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject,
     [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
     : this(execute, false, canExecuteSubject, observers)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActivatableCanExecuteObserverCommand{T}" /> class.
 /// </summary>
 /// <param name="execute">The execute.</param>
 /// <param name="canExecuteSubject">The can execute subject.</param>
 /// <param name="observers">The observers.</param>
 public ActivatableCanExecuteObserverCommand(
     [NotNull] Action <T> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject,
     [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
     : this(execute, false, canExecuteSubject, observers)
 {
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ActivatableConcurrencyAsyncCanExecuteObserverCommand{T}" /> class.
        /// </summary>
        /// <param name="execute">The execute.</param>
        /// <param name="autoActivate">if set to <c>true</c> [automatic activate].</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>
        /// <param name="observers">The observers.</param>
        /// <exception cref="ArgumentNullException">
        ///     canExecuteSubject
        ///     or
        ///     observers is null.
        /// </exception>
        public ActivatableConcurrencyAsyncCanExecuteObserverCommand(
            [NotNull] Func <T, CancellationToken, Task> execute,
            bool autoActivate,
            [NotNull] ICanExecuteSubject canExecuteSubject,
            [CanBeNull] Func <Task> completed,
            [CanBeNull] Func <Exception, Task> error,
            [CanBeNull] Func <Task> cancel,
            [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
            : base(execute, canExecuteSubject, completed, error, cancel)
        {
            if (canExecuteSubject == null)
            {
                throw new ArgumentNullException(nameof(canExecuteSubject));
            }

            if (observers == null)
            {
                throw new ArgumentNullException(nameof(observers));
            }

            this.observers.Add(canExecuteSubject);

            this.observers.AddIfNotContains(observers);

            if (autoActivate)
            {
                this.Activate();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcurrencyCanExecuteObserverCommand{T}" /> 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>
        /// <param name="observers">The observers.</param>
        /// <exception cref="ArgumentNullException">canExecuteSubject
        /// or
        /// observers is null.</exception>
        public ConcurrencyCanExecuteObserverCommand(
            [NotNull] Action <T, CancellationToken> execute,
            [NotNull] ICanExecuteSubject canExecuteSubject,
            [CanBeNull] Action completed,
            [CanBeNull] Action <Exception> error,
            [CanBeNull] Action cancel,
            [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
            : base(execute, canExecuteSubject, completed, error, cancel)
        {
            if (canExecuteSubject == null)
            {
                throw new ArgumentNullException(nameof(canExecuteSubject));
            }

            if (observers == null)
            {
                throw new ArgumentNullException(nameof(observers));
            }

            this.observers.Add(canExecuteSubject);

            this.observers.AddIfNotContains(observers);

            this.Subscribe();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivatableConcurrencyCanExecuteObserverCommand{T}"/> 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>
 public ActivatableConcurrencyCanExecuteObserverCommand(
     [NotNull] Action <T, CancellationToken> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject,
     [CanBeNull] Action completed,
     [CanBeNull] Action <Exception> error,
     [CanBeNull] Action cancel)
     : this(execute, false, canExecuteSubject, completed, error, cancel)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActivatableConcurrencyAsyncCanExecuteObserverCommand{T}" /> 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>
 public ActivatableConcurrencyAsyncCanExecuteObserverCommand(
     [NotNull] Func <T, CancellationToken, Task> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject,
     [CanBeNull] Func <Task> completed,
     [CanBeNull] Func <Exception, Task> error,
     [CanBeNull] Func <Task> cancel)
     : this(execute, false, canExecuteSubject, completed, error, cancel)
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivatableConcurrencyCanExecuteObserverCommand{T}"/> 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>
 /// <param name="observers">The observers.</param>
 public ActivatableConcurrencyCanExecuteObserverCommand(
     [NotNull] Action <T, CancellationToken> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject,
     [CanBeNull] Action completed,
     [CanBeNull] Action <Exception> error,
     [CanBeNull] Action cancel,
     [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
     : this(execute, false, canExecuteSubject, completed, error, cancel, observers)
 {
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ConcurrencyAsyncCommandBase{T}" /> 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 is null.</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.cancelCommand = new DirectCommand(this.Cancel, () => this.IsExecuting);
        }
Ejemplo n.º 10
0
        /// <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 is null.</exception>
        protected ConcurrencyCommandBase(
            [NotNull] Action <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    = canExecuteSubject.CanExecute;
            this.completed     = completed;
            this.error         = error;
            this.cancel        = cancel;
            this.cancelCommand = new DirectCommand(this.Cancel, () => this.IsExecuting);
        }
Ejemplo n.º 11
0
        public AsyncCommandBuilder ObservesCanExecute([NotNull] Expression <Func <bool> > canExecute, bool fallback)
        {
            if (canExecute == null)
            {
                throw new ArgumentNullException(nameof(canExecute));
            }

            if (this.canExecuteSubject != null)
            {
                throw new CommandBuilderException(ExceptionStrings.CanExecuteExpressionAlreadyDefined);
            }

            if (this.canExecuteFunction != null)
            {
                throw new CommandBuilderException(ExceptionStrings.CanExecuteFunctionAlreadyDefined);
            }

            this.canExecuteSubject = CanExecuteObserver.Create(canExecute, fallback);
            return(this);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CanExecuteObserverCommand{T}" /> class.
        /// </summary>
        /// <param name="execute">The execute.</param>
        /// <param name="canExecuteSubject">The can execute subject.</param>
        /// <param name="observers">The observers.</param>
        /// <exception cref="ArgumentNullException">
        ///     observer
        ///     or
        ///     observer is null.
        /// </exception>
        /// <exception cref="ArgumentException">propertyObserver is null.</exception>
        public CanExecuteObserverCommand(
            [NotNull] Action <T> execute,
            [NotNull] ICanExecuteSubject canExecuteSubject,
            [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
            : base(execute, canExecuteSubject)
        {
            if (canExecuteSubject == null)
            {
                throw new ArgumentNullException(nameof(observers));
            }

            if (observers == null)
            {
                throw new ArgumentNullException(nameof(observers));
            }

            this.observers.Add(canExecuteSubject);
            this.observers.AddIfNotContains(observers);
            this.Subscribe();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivatableCanExecuteObserverCommand" /> class.
        /// </summary>
        /// <param name="execute">The execute.</param>
        /// <param name="autoActivate">if set to <c>true</c> [automatic activate].</param>
        /// <param name="canExecuteSubject">The can execute subject.</param>
        /// <param name="observers">The observers.</param>
        /// <exception cref="ArgumentNullException">canExecuteSubject
        /// or
        /// observers</exception>
        public ConcurrencyAsyncCanExecuteObserverCommand(
            [NotNull] Func <CancellationToken, Task> execute,
            [NotNull] ICanExecuteSubject canExecuteSubject,
            [NotNull][ItemNotNull] params ICanExecuteChangedSubject[] observers)
            : base(execute, canExecuteSubject)
        {
            if (canExecuteSubject == null)
            {
                throw new ArgumentNullException(nameof(canExecuteSubject));
            }

            if (observers == null)
            {
                throw new ArgumentNullException(nameof(observers));
            }

            this.observers.Add(canExecuteSubject);

            this.observers.AddIfNotContains(observers);

            Subscribe();
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActivatableConcurrencyCanExecuteObserverCommand" /> class.
 /// </summary>
 /// <param name="execute">The execute.</param>
 /// <param name="canExecuteSubject">The can execute subject.</param>
 public ActivatableConcurrencyCanExecuteObserverCommand(
     [NotNull] Action <CancellationToken> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject)
     : this(execute, false, canExecuteSubject)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActivatableConcurrencyAsyncCanExecuteObserverCommand{T}" /> class.
 /// </summary>
 /// <param name="execute">The execute.</param>
 /// <param name="canExecuteSubject">The can execute subject.</param>
 public ActivatableConcurrencyAsyncCanExecuteObserverCommand(
     [NotNull] Func <T, CancellationToken, Task> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject)
     : this(execute, false, canExecuteSubject)
 {
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ActivatableCanExecuteObserverCommand{T}" /> class.
 /// </summary>
 /// <param name="execute">The execute.</param>
 /// <param name="canExecuteSubject">The can execute subject.</param>
 public ActivatableCanExecuteObserverCommand(
     [NotNull] Action <T> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject)
     : this(execute, false, canExecuteSubject)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     Determines whether this instance can execute the specified can execute.
 /// </summary>
 /// <param name="canExecute">The can execute.</param>
 /// <returns>
 ///     The Async CanExecute Command Builder.
 /// </returns>
 IAsyncCanExecuteBuilder IAsyncCommandBuilder.CanExecute(ICanExecuteSubject canExecute)
 {
     this.canExecuteSubject = canExecute;
     return(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivatableCanExecuteObserverCommand" /> class.
 /// </summary>
 /// <param name="execute">The execute.</param>
 /// <param name="canExecuteSubject">The can execute subject.</param>
 public ActivatableAsyncCanExecuteObserverCommand(
     [NotNull] Func <T, Task> execute,
     [NotNull] ICanExecuteSubject canExecuteSubject)
     : this(execute, false, canExecuteSubject)
 {
 }