The CompositeCommand composes one or more ICommands.
Inheritance: ICommand
Exemple #1
0
 /// <summary>
 /// Constructor estático.
 /// </summary>
 static EditionCommands()
 {
     activateRecordCommand = new CompositeCommand();
     deleteRecordCommand = new CompositeCommand();
     editRecordCommand = new CompositeCommand();
     getRecordsCommand = new CompositeCommand();
     newRecordCommand = new CompositeCommand();
     saveRecordCommand = new CompositeCommand();
 }
        public void ShouldSetAndGetStockTraderRiCommands()
        {
            var cancelAllOrdersCommand = new CompositeCommand();
            var cancelOrderCommand = new CompositeCommand();
            var submitAllOrdersCommand = new CompositeCommand();
            var submitOrderCommand = new CompositeCommand();
            StockTraderRICommands.CancelAllOrdersCommand = cancelAllOrdersCommand;
            StockTraderRICommands.CancelOrderCommand = cancelOrderCommand;
            StockTraderRICommands.SubmitAllOrdersCommand = submitAllOrdersCommand;
            StockTraderRICommands.SubmitOrderCommand = submitOrderCommand;
            
            Assert.AreEqual(cancelAllOrdersCommand, StockTraderRICommands.CancelAllOrdersCommand);
            Assert.AreEqual(cancelOrderCommand, StockTraderRICommands.CancelOrderCommand);
            Assert.AreEqual(submitAllOrdersCommand, StockTraderRICommands.SubmitAllOrdersCommand);
            Assert.AreEqual(submitOrderCommand, StockTraderRICommands.SubmitOrderCommand);

            var stockTraderRiCommandProxy = new StockTraderRICommandProxy();

            Assert.AreEqual(StockTraderRICommands.CancelAllOrdersCommand, stockTraderRiCommandProxy.CancelAllOrdersCommand);
            Assert.AreEqual(StockTraderRICommands.CancelOrderCommand, stockTraderRiCommandProxy.CancelOrderCommand);
            Assert.AreEqual(StockTraderRICommands.SubmitAllOrdersCommand, stockTraderRiCommandProxy.SubmitAllOrdersCommand);
            Assert.AreEqual(StockTraderRICommands.SubmitOrderCommand, stockTraderRiCommandProxy.SubmitOrderCommand);
        }
 public SelfUnregisterableCommand(CompositeCommand command)
 {
     Command = command;
 }
        public void RegisteringCommandTwiceThrows()
        {
            var compositeCommand = new CompositeCommand();
            var duplicateCommand = new TestCommand();
            compositeCommand.RegisterCommand(duplicateCommand);

            compositeCommand.RegisterCommand(duplicateCommand);
        }
        public void RegisteringCommandInItselfThrows()
        {
            var compositeCommand = new CompositeCommand();

            compositeCommand.RegisterCommand(compositeCommand);
        }
        public void ShouldIgnoreChangesToIsActiveDuringExecution()
        {
            var firstCommand = new MockActiveAwareCommand { IsActive = true };
            var secondCommand = new MockActiveAwareCommand { IsActive = true };

            // During execution set the second command to inactive, this should not affect the currently
            // executed selection.  
            firstCommand.ExecuteAction += new Action<object>((object parameter) => secondCommand.IsActive = false);

            var compositeCommand = new CompositeCommand(true);

            compositeCommand.RegisterCommand(firstCommand);
            compositeCommand.RegisterCommand(secondCommand);

            compositeCommand.Execute(null);

            Assert.IsTrue(secondCommand.WasExecuted);
        }
        public void ShouldNotMonitorActivityIfUseActiveMonitoringFalse()
        {
            var mockCommand = new MockActiveAwareCommand();
            mockCommand.IsValid = true;
            mockCommand.IsActive = true;
            var nonActiveAwareCompositeCommand = new CompositeCommand(false);
            bool canExecuteChangedRaised = false;
            nonActiveAwareCompositeCommand.RegisterCommand(mockCommand);
            nonActiveAwareCompositeCommand.CanExecuteChanged += delegate
            {
                canExecuteChangedRaised = true;
            };

            mockCommand.IsActive = false;

            Assert.IsFalse(canExecuteChangedRaised);

            nonActiveAwareCompositeCommand.Execute(null);

            Assert.IsTrue(mockCommand.WasExecuted);
        }
        public void ActivityCausesActiveAwareCommandToRequeryCanExecute()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            activeAwareCommand.RegisterCommand(command);
            command.IsActive = true;

            bool globalCanExecuteChangeFired = false;
            activeAwareCommand.CanExecuteChanged += delegate
                                                        {
                                                            globalCanExecuteChangeFired = true;
                                                        };

            Assert.IsFalse(globalCanExecuteChangeFired);
            command.IsActive = false;
            Assert.IsTrue(globalCanExecuteChangeFired);
        }
        public void DispatchCommandShouldIgnoreInactiveCommandsInCanExecuteVote()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand commandOne = new MockActiveAwareCommand() { IsActive = false, IsValid = false };
            MockActiveAwareCommand commandTwo = new MockActiveAwareCommand() { IsActive = true, IsValid = true };

            activeAwareCommand.RegisterCommand(commandOne);
            activeAwareCommand.RegisterCommand(commandTwo);

            Assert.IsTrue(activeAwareCommand.CanExecute(null));
        }
        public void DispatchCommandDoesNotIncludeInactiveRegisteredCommandInVoting()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            activeAwareCommand.RegisterCommand(command);
            command.IsValid = true;
            command.IsActive = false;

            Assert.IsFalse(activeAwareCommand.CanExecute(null), "Registered Click is inactive so should not participate in CanExecute vote");

            command.IsActive = true;

            Assert.IsTrue(activeAwareCommand.CanExecute(null));

            command.IsValid = false;

            Assert.IsFalse(activeAwareCommand.CanExecute(null));

        }
        public void MultiDispatchCommandDoesNotExecutesInactiveRegisteredCommands()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand(true);
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            command.IsActive = false;
            activeAwareCommand.RegisterCommand(command);

            activeAwareCommand.Execute(null);

            Assert.IsFalse(command.WasExecuted);
        }
        public void MultiDispatchCommandExecutesActiveRegisteredCommands()
        {
            CompositeCommand activeAwareCommand = new CompositeCommand();
            MockActiveAwareCommand command = new MockActiveAwareCommand();
            command.IsActive = true;
            activeAwareCommand.RegisterCommand(command);

            activeAwareCommand.Execute(null);

            Assert.IsTrue(command.WasExecuted);
        }
Exemple #13
0
        /// <summary>
        /// Called when [apply template].
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate ();
            _btnSave = GetTemplateChild ( "Part_SaveButton" ) as Button;
            _btnNext = GetTemplateChild ( "Part_NextButton" ) as Button;
            _btnCancel = GetTemplateChild ( "Part_CancelButton" ) as Button;
            _focusElement = GetTemplateChild ( "Part_Focus" ) as Grid;
            _contentPresenter = GetTemplateChild ( "PART_ContentPresenter" ) as ContentPresenter;
            _maximizeGrid = GetTemplateChild ( "PART_MaximizeGrid" ) as Grid;
            _rootGrid = GetTemplateChild ( "PART_RootGrid" ) as Grid;

            _saveCompositeCommand = new CompositeCommand ();
            _saveCompositeCommand.RegisterCommand ( new DelegateCommand ( ExecuteSaveCommand ) );
            if ( SaveCommand != null )
            {
                _saveCompositeCommand.RegisterCommand ( SaveCommand );
                if ( !_afterSaveCommandIntialized )
                {
                    _afterSaveCommandIntialized = true;
                    _saveCompositeCommand.RegisterCommand ( new DelegateCommand ( AfterSaveCommandExecute ) );
                }
            }
            _btnSave.Command = _saveCompositeCommand;
            var contentBinding = new Binding ();
            contentBinding.Source = this;
            contentBinding.Path = new PropertyPath ( PropertyUtil.ExtractPropertyName ( () => Content ) );
            _btnSave.SetBinding ( ButtonBase.CommandParameterProperty, contentBinding );
            _btnNext.Click += NextClicked;
            _btnCancel.Click += CancelClick;
            LostFocus += Content_LostFocus;
            _focusElement.MouseLeftButtonDown += Content_MouseLeftButtonDown;
            AddHandler ( MouseLeftButtonDownEvent, new MouseButtonEventHandler ( EditableExpander_MouseLeftButtonDown ), true );
            MouseLeftButtonDown += EditableExpander_MouseLeftButtonDown;

            if ( IsExpanded )
            {
                VisualStateManager.GoToState ( this, "RevealState", true );
            }

            if ( UsingEditableContentTemplate () )
            {
                ContentTemplate = EditableContentTemplate;
            }

            _templateApplied = true;

            UpdateContentPresenter();

            if ( IsEditing )
            {
                TurnOnEditing ();
            }
            else
            {
                TurnOffEditing ();
            }
        }
        public void RegisteringCommandTwiceThrows()
        {
            var compositeCommand = new CompositeCommand();
            var duplicateCommand = new TestCommand();
            compositeCommand.RegisterCommand(duplicateCommand);

            Assert.ThrowsException<InvalidOperationException>(() => compositeCommand.RegisterCommand(duplicateCommand));
        }
        public void RegisteringCommandInItselfThrows()
        {
            var compositeCommand = new CompositeCommand();

            Assert.ThrowsException<ArgumentException>(() => compositeCommand.RegisterCommand(compositeCommand));
        }
Exemple #16
0
        /// <summary>
        /// Constructor estático.
        /// Static constructor.
        /// </summary>
        static EditionCommands()
        {
            activateRecordCommand           = new CompositeCommand();
            deleteRecordCommand             = new CompositeCommand();
            editRecordCommand               = new CompositeCommand();
            getRecordsCommand               = new CompositeCommand();
            newRecordCommand                = new CompositeCommand();
            saveRecordCommand               = new CompositeCommand();

            getFirstPageRecordsCommand      = new CompositeCommand();
            getNextPageRecordsCommand       = new CompositeCommand();
            getPreviousPageRecordsCommand   = new CompositeCommand();
            getLastPageRecordsCommand       = new CompositeCommand();
        }