예제 #1
0
        public void InvalidateCommands_AutomaticByPropertyChange()
        {
            bool canExecuteChangedTriggered = false;
            var  canExecuteChangedEvent     = new ManualResetEvent(false);

            var viewModel = new TestViewModel();

            viewModel.SetInvalidateCommandsOnPropertyChanged(true);

            ICatelCommand command = viewModel.GenerateData;

            command.CanExecuteChanged += delegate
            {
                canExecuteChangedTriggered = true;
                canExecuteChangedEvent.Set();
            };

            // By default, command can be executed
            Assert.IsTrue(viewModel.GenerateData.CanExecute(null));

            viewModel.FirstName = "first name";

            Assert.IsFalse(viewModel.GenerateData.CanExecute(null));
#if NET
            canExecuteChangedEvent.WaitOne(1000, false);
#else
            canExecuteChangedEvent.WaitOne(1000);
#endif
            Assert.IsTrue(canExecuteChangedTriggered);
        }
예제 #2
0
        /// <summary>
        /// Unregisters a command with the specified command name.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="command">The command.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">The specified command is not created using the <see cref="CreateCommand"/> method.</exception>
        public void UnregisterCommand(string commandName, ICatelCommand command)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);
            Argument.IsNotNull("command", command);

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            lock (_lockObject)
            {
                Log.Debug("Unregistering command from '{0}'", commandName);

                if (!_commands.ContainsKey(commandName))
                {
                    string error = string.Format("Command '{0}' is not yet created using the CreateCommand method", commandName);
                    Log.Error(error);
                    throw new InvalidOperationException(error);
                }

                _commands[commandName].UnregisterCommand(command);

                InvalidateCommands();
            }
        }
예제 #3
0
        /// <summary>
        /// Uninitializes this binding.
        /// </summary>
        protected override void Uninitialize()
        {
            if (_eventHandler != null)
            {
                _eventInfo.RemoveEventHandler(_element, _eventHandler);
                _eventHandler = null;
            }

            if (_canExecuteChangedHandler != null)
            {
                _command.CanExecuteChanged -= _canExecuteChangedHandler;
                _canExecuteChangedHandler   = null;
            }

            if (_commandBindingParameterValueChangedHandler != null)
            {
                _commandParameterBinding.ValueChanged      -= _commandBindingParameterValueChangedHandler;
                _commandBindingParameterValueChangedHandler = null;
            }

            _element                 = null;
            _eventInfo               = null;
            _enabledPropertyInfo     = null;
            _command                 = null;
            _commandParameterBinding = null;

            // TODO: call commandParameterBinding.ClearBinding();?
        }
예제 #4
0
        protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
        {
            base.OnViewModelCommandExecuted(viewModel, command, commandParameter);

            if (viewModel != null && command.Tag != null)
            {
                switch (command.Tag.ToString())
                {
                case "saveSettings":
                    var settingsViewModel = viewModel as SettingsWindowViewModel;
                    folderToWatch = settingsViewModel.FolderToWatch;
                    folderWatcher.ChangeWatcherFolder(folderToWatch);
                    CheckMessagesWithWaiting();
                    break;

                case "quitting":
                    var param = commandParameter as CancelEventArgs;
                    if (!param.Cancel)
                    {
                        new FinalSaveCommand().Save(Messages);
                    }

                    break;
                }
            }
        }
예제 #5
0
        public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
        {
            base.OnCommandExecuted(viewModel, commandName, command, commandParameter);

            var viewModelName = viewModel != null ? viewModel.GetType().Name : string.Empty;

            _analyticsService.SendCommandAsync(viewModelName, commandName);
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandExecutedEventArgs"/> class.
        /// </summary>
        /// <param name="command">The command that just has been executed.</param>
        /// <param name="commandParameter">The command parameter that was used for the execution.</param>
        /// <param name="commandPropertyName">The property name under which the command is registered.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        public CommandExecutedEventArgs(ICatelCommand command, object commandParameter = null, string commandPropertyName = null)
        {
            Argument.IsNotNull("command", command);

            Command             = command;
            CommandParameter    = commandParameter;
            CommandPropertyName = commandPropertyName;
        }
 protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command,
                                                    object commandParameter)
 {
     if (command.Tag != null && command.Tag.ToString().Equals("saveSettings"))
     {
         SelectedIndexTab = 0;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandExecutedEventArgs"/> class.
        /// </summary>
        /// <param name="command">The command that just has been executed.</param>
        /// <param name="commandParameter">The command parameter that was used for the execution.</param>
        /// <param name="commandPropertyName">The property name under which the command is registered.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        public CommandExecutedEventArgs(ICatelCommand command, object commandParameter = null, string commandPropertyName = null)
        {
            Argument.IsNotNull("command", command);

            Command = command;
            CommandParameter = commandParameter;
            CommandPropertyName = commandPropertyName;
        }
예제 #9
0
        /// <summary>
        /// Registers the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="viewModel">The view model. If specified, the command will automatically be unregistered when the view model is closed.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <remarks>
        /// Note that if the view model is not specified, the command must be unregistered manually in order to prevent memory leaks.
        /// </remarks>
        public void RegisterCommand(ICatelCommand command, IViewModel viewModel = null)
        {
            Argument.IsNotNull("command", command);

            lock (_lock)
            {
                _commandInfo.Add(new CommandInfo(this, command, viewModel));

                Log.Debug("Registered command in CompositeCommand");
            }
        }
예제 #10
0
            public CommandInfo(CompositeCommand compositeCommand, ICatelCommand command, IViewModel viewModel)
            {
                _compositeCommand = compositeCommand;

                Command = command;
                ViewModel = viewModel;

                if (viewModel != null)
                {
                    viewModel.Closed += OnViewModelClosed;
                }
            }
예제 #11
0
파일: TestAuditor.cs 프로젝트: yicong/Catel
        public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
        {
            if (OnCommandExecutedCalled)
            {
                return;
            }

            OnCommandExecutedCalled           = true;
            OnCommandExecutedViewModel        = viewModel;
            OnCommandExecutedCommandName      = commandName;
            OnCommandExecutedCommand          = command;
            OnCommandExecutedCommandParameter = commandParameter;
        }
예제 #12
0
파일: TestAuditor.cs 프로젝트: pars87/Catel
        public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
        {
            if (OnCommandExecutedCalled)
            {
                return;
            }

            OnCommandExecutedCalled = true;
            OnCommandExecutedViewModel = viewModel;
            OnCommandExecutedCommandName = commandName;
            OnCommandExecutedCommand = command;
            OnCommandExecutedCommandParameter = commandParameter;
        }
예제 #13
0
        /// <inheritdoc />
        /// <summary>Handles commands from child ViewModels (Add query, ...)</summary>
        protected override void OnViewModelCommandExecuted(
            IViewModel viewModel, ICatelCommand command, object commandParameter)
        {
            switch (command.Tag as string)
            {
            case "AddQuery":
                ShowQueryBuilder();
                break;

            case "EditQuery":
                ShowQueryBuilder(commandParameter as FilterScheme);
                break;
            }
        }
예제 #14
0
        /// <summary>
        /// Registers the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="viewModel">The view model. If specified, the command will automatically be unregistered when the view model is closed.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <remarks>
        /// Note that if the view model is not specified, the command must be unregistered manually in order to prevent memory leaks.
        /// </remarks>
        public void RegisterCommand(ICatelCommand command, IViewModel viewModel = null)
        {
            Argument.IsNotNull(() => command);

            lock (_lock)
            {
                var commandInfo = new CommandInfo(this, command, viewModel);

                _commandInfo.Add(commandInfo);
                command.CanExecuteChanged += OnCommandCanExecuteChanged;

                Log.Debug("Registered command in CompositeCommand");
            }
        }
예제 #15
0
        /// <summary>
        /// Unregisters the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        public void UnregisterCommand(ICatelCommand command)
        {
            Argument.IsNotNull("command", command);

            lock (_lock)
            {
                for (int i = _commandInfo.Count - 1; i >= 0; i--)
                {
                    var commandInfo = _commandInfo[i];

                    if (ReferenceEquals(commandInfo.Command, command))
                    {
                        _commandInfo.RemoveAt(i);

                        Log.Debug("Unregistered command from CompositeCommand");
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Registers a command with the specified
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="command">The command.</param>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">The specified command is not created using the <see cref="CreateCommand"/> method.</exception>
        public void RegisterCommand(string commandName, ICatelCommand command, IViewModel viewModel = null)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);
            Argument.IsNotNull("command", command);

            lock (_lockObject)
            {
                Log.Debug("Registering command to '{0}'", commandName);

                if (!_commands.ContainsKey(commandName))
                {
                    string error = string.Format("Command '{0}' is not yet created using the CreateCommand method", commandName);
                    Log.Error(error);
                    throw new InvalidOperationException(error);
                }

                _commands[commandName].RegisterCommand(command, viewModel);
            }
        }
예제 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandBinding"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="eventName">Name of the event.</param>
        /// <param name="command">The command.</param>
        /// <param name="commandParameterBinding">The command parameter binding.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="element"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="eventName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        public CommandBinding(object element, string eventName, ICatelCommand command, Binding commandParameterBinding = null)
        {
            Argument.IsNotNull("element", element);
            Argument.IsNotNullOrWhitespace("eventName", eventName);
            Argument.IsNotNull("command", command);

            _element = element;
            _command = command;
            _commandParameterBinding = commandParameterBinding;

            var elementType = _element.GetType();

            _eventInfo = elementType.GetEventEx(eventName);
            if (_eventInfo == null)
            {
                Log.ErrorAndThrowException <InvalidOperationException>("Event '{0}.{1}' not found, cannot create command binding", elementType.Name, eventName);
            }

            _enabledPropertyInfo = elementType.GetPropertyEx("Enabled");

            _eventHandler = delegate
            {
                var commandParameter = _commandParameterBinding.GetBindingValue();
                if (_command.CanExecute(commandParameter))
                {
                    _command.Execute(commandParameter);
                }
            };
            _eventInfo.AddEventHandler(element, _eventHandler);

            _canExecuteChangedHandler  = (sender, e) => UpdateEnabledState();
            command.CanExecuteChanged += _canExecuteChangedHandler;

            if (commandParameterBinding != null)
            {
                _commandBindingParameterValueChangedHandler = (sender, e) => UpdateEnabledState();
                commandParameterBinding.ValueChanged       += _commandBindingParameterValueChangedHandler;
            }

            UpdateEnabledState();
        }
예제 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandBinding"/> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="eventName">Name of the event.</param>
        /// <param name="command">The command.</param>
        /// <param name="commandParameterBinding">The command parameter binding.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="element"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="eventName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        public CommandBinding(object element, string eventName, ICatelCommand command, Binding commandParameterBinding = null)
        {
            Argument.IsNotNull("element", element);
            Argument.IsNotNullOrWhitespace("eventName", eventName);
            Argument.IsNotNull("command", command);

            _element = element;
            _command = command;
            _commandParameterBinding = commandParameterBinding;

            var elementType = _element.GetType();
            _eventInfo = elementType.GetEventEx(eventName);
            if (_eventInfo == null)
            {
                throw Log.ErrorAndCreateException<InvalidOperationException>("Event '{0}.{1}' not found, cannot create command binding", elementType.Name, eventName);
            }

            _enabledPropertyInfo = elementType.GetPropertyEx("Enabled");

            _eventHandler = delegate
            {
                var commandParameter = _commandParameterBinding.GetBindingValue();
                if (_command.CanExecute(commandParameter))
                {
                    _command.Execute(commandParameter);
                }
            };
            _eventInfo.AddEventHandler(element, _eventHandler);

            _canExecuteChangedHandler = (sender, e) => UpdateEnabledState();
            command.CanExecuteChanged += _canExecuteChangedHandler;

            if (commandParameterBinding != null)
            {
                _commandBindingParameterValueChangedHandler = (sender, e) => UpdateEnabledState();
                commandParameterBinding.ValueChanged += _commandBindingParameterValueChangedHandler;
            }

            UpdateEnabledState();
        }
예제 #19
0
        /// <summary>
        /// Called when a command for a view model type that the current view model is interested in has been executed. This can
        /// be accomplished by decorating the view model with the <see cref="InterestedInAttribute"/>.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="command">The command that has been executed.</param>
        /// <param name="commandParameter">The command parameter used during the execution.</param>
        protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
        {
            if (viewModel is InterestingViewModel)
            {
                string tag = (command.Tag is string) ? (string)command.Tag : string.Empty;

                if (tag == "test")
                {
                    CommandHasBeenExecuted = true;

                    if ((commandParameter is string) && (((string)commandParameter) == "parameter"))
                    {
                        CommandHasBeenExecutedWithParameter = true;
                    }
                }

                if (tag == "unregistered")
                {
                    NotRegisteredCommandHasBeenExecuted = true;

                    if ((commandParameter is string) && (((string)commandParameter) == "parameter"))
                    {
                        NotRegisteredCommandHasBeenExecutedWithParameter = true;
                    }
                }

                if (tag == "registered")
                {
                    RegisteredCommandHasBeenExecuted = true;

                    if ((commandParameter is string) && (((string)commandParameter) == "parameter"))
                    {
                        RegisteredCommandHasBeenExecutedWithParameter = true;
                    }
                }
            }
        }
예제 #20
0
 public void IncludeCommand(ICatelCommand command)
 {
     command.CanExecuteChanged += (sender, e) => { };
 }
예제 #21
0
 /// <summary>
 /// Called when a command of a view model has just been executed.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <param name="commandName">Name of the command, which is the name of the command property.</param>
 /// <param name="command">The command that has been executed.</param>
 /// <param name="commandParameter">The command parameter.</param>
 public virtual void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter) { }
예제 #22
0
 /// <summary>
 /// Called when a command for a view model type that the current view model is interested in has been executed. This can
 /// be accomplished by decorating the view model with the <see cref="InterestedInAttribute"/>.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <param name="command">The command that has been executed.</param>
 /// <param name="commandParameter">The command parameter used during the execution.</param>
 protected virtual void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
 {
 }
예제 #23
0
        /// <summary>
        /// Registers a command with the specified
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="command">The command.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">The specified command is not created using the <see cref="CreateCommand"/> method.</exception>
        public void UnregisterCommand(string commandName, ICatelCommand command)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);
            Argument.IsNotNull("command", command);

            lock (_lockObject)
            {
                Log.Debug("Unregistering command from '{0}'", commandName);

                if (!_commands.ContainsKey(commandName))
                {
                    string error = string.Format("Command '{0}' is not yet created using the CreateCommand method", commandName);
                    Log.Error(error);
                    throw new InvalidOperationException(error);
                }

                _commands[commandName].UnregisterCommand(command);
            }
        }
예제 #24
0
        /// <summary>
        /// Called when a command for a view model type that the current view model is interested in has been executed. This can
        /// be accomplished by decorating the view model with the <see cref="InterestedInAttribute"/>.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="command">The command that has been executed.</param>
        /// <param name="commandParameter">The command parameter used during the execution.</param>
        /// <remarks>
        /// This method should only be called by Catel so the <see cref="ManagedViewModel"/> can invoke it. This method is only used as a pass-through
        /// to the actual <see cref="OnViewModelCommandExecuted"/> method.
        /// </remarks>
        void INotifyableViewModel.ViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
        {
            Log.Debug("A view model ('{0}') the current view model ('{1}') is interested in has executed a command with tag '{2}'",
                viewModel.GetType(), GetType(), ObjectToStringHelper.ToString(command.Tag));

            OnViewModelCommandExecuted(viewModel, command, commandParameter);
        }
예제 #25
0
 public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
 {
     //https://catelproject.atlassian.net/wiki/display/CTL/Commands+authentication?src=search
     return(true);
 }
 protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
 {
     AddCommand(viewModel.GetType());
 }
 public void IncludeCommand(ICatelCommand command)
 {
     command.CanExecuteChanged += (sender, e) => { };
 }
예제 #28
0
        /// <summary>
        /// Uninitializes this binding.
        /// </summary>
        protected override void Uninitialize()
        {
            if (_eventHandler != null)
            {
                _eventInfo.RemoveEventHandler(_element, _eventHandler);
                _eventHandler = null;
            }

            if (_canExecuteChangedHandler != null)
            {
                _command.CanExecuteChanged -= _canExecuteChangedHandler;
                _canExecuteChangedHandler = null;
            }

            if (_commandBindingParameterValueChangedHandler != null)
            {
                _commandParameterBinding.ValueChanged -= _commandBindingParameterValueChangedHandler;
                _commandBindingParameterValueChangedHandler = null;
            }

            _element = null;
            _eventInfo = null;
            _enabledPropertyInfo = null;
            _command = null;
            _commandParameterBinding = null;

            // TODO: call commandParameterBinding.ClearBinding();?
        }
예제 #29
0
        /// <summary>
        /// Adds a new command binding to the element.
        /// </summary>
        /// <param name="bindingContext">The binding context.</param>
        /// <param name="element">The element.</param>
        /// <param name="eventName">Name of the event.</param>
        /// <param name="command">The command.</param>
        /// <param name="commandParameterBinding">The command parameter binding.</param>
        /// <returns>Catel.MVVM.CommandBinding.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="element"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">The <paramref name="eventName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        public static CommandBinding AddCommandBinding(this BindingContext bindingContext, object element, string eventName, ICatelCommand command, Binding commandParameterBinding = null)
        {
            var commandBinding = new CommandBinding(element, eventName, command, commandParameterBinding);

            bindingContext.AddCommandBinding(commandBinding);

            return(commandBinding);
        }
예제 #30
0
 protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
 {
     AddCommand(viewModel.GetType());
 }
예제 #31
0
 /// <summary>
 /// Must be called when a command of a view model has just been executed.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <param name="commandName">Name of the command, which is the name of the command property.</param>
 /// <param name="command">The command that has been executed.</param>
 /// <param name="commandParameter">The command parameter.</param>
 internal static void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
 {
     lock (_instance._auditors)
     {
         foreach (var auditor in _instance._auditors)
         {
             auditor.OnCommandExecuted(viewModel, commandName, command, commandParameter);
         }
     }
 }
예제 #32
0
        /// <summary>
        /// Registers the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="viewModel">The view model. If specified, the command will automatically be unregistered when the view model is closed.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <remarks>
        /// Note that if the view model is not specified, the command must be unregistered manually in order to prevent memory leaks.
        /// </remarks>
        public void RegisterCommand(ICatelCommand command, IViewModel viewModel = null)
        {
            Argument.IsNotNull(() => command);

            lock (_lock)
            {
                var commandInfo = new CommandInfo(this, command, viewModel);

                _commandInfo.Add(commandInfo);
                command.CanExecuteChanged += OnCommandCanExecuteChanged;

                Log.Debug("Registered command in CompositeCommand");
            }
        }
예제 #33
0
        /// <summary>
        /// Called when a command for a view model type that the current view model is interested in has been executed. This can
        /// be accomplished by decorating the view model with the <see cref="InterestedInAttribute"/>.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="command">The command that has been executed.</param>
        /// <param name="commandParameter">The command parameter used during the execution.</param>
        protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
        {
            if (viewModel is InterestingViewModel)
            {
                string tag = (command.Tag is string) ? (string) command.Tag : string.Empty;

                if (tag == "test")
                {
                    CommandHasBeenExecuted = true;

                    if ((commandParameter is string) && (((string) commandParameter) == "parameter"))
                    {
                        CommandHasBeenExecutedWithParameter = true;
                    }
                }

                if (tag == "unregistered")
                {
                    NotRegisteredCommandHasBeenExecuted = true;

                    if ((commandParameter is string) && (((string) commandParameter) == "parameter"))
                    {
                        NotRegisteredCommandHasBeenExecutedWithParameter = true;
                    }
                }

                if (tag == "registered")
                {
                    RegisteredCommandHasBeenExecuted = true;

                    if ((commandParameter is string) && (((string) commandParameter) == "parameter"))
                    {
                        RegisteredCommandHasBeenExecutedWithParameter = true;
                    }
                }
            }
        }
예제 #34
0
 /// <summary>
 /// Must be called when a command of a view model has just been executed.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <param name="commandName">Name of the command, which is the name of the command property.</param>
 /// <param name="command">The command that has been executed.</param>
 /// <param name="commandParameter">The command parameter.</param>
 internal static void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
 {
     lock (_instance._auditors)
     {
         foreach (var auditor in _instance._auditors)
         {
             auditor.OnCommandExecuted(viewModel, commandName, command, commandParameter);
         }
     }
 }
예제 #35
0
        /// <summary>
        /// Registers a command with the specified command name.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="command">The command.</param>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentException">The <paramref name="commandName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="command"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">The specified command is not created using the <see cref="CreateCommand"/> method.</exception>
        public void RegisterCommand(string commandName, ICatelCommand command, IViewModel viewModel = null)
        {
            Argument.IsNotNullOrWhitespace("commandName", commandName);
            Argument.IsNotNull("command", command);

            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            lock (_lockObject)
            {
                Log.Debug("Registering command to '{0}'", commandName);

                if (!_commands.ContainsKey(commandName))
                {
                    string error = string.Format("Command '{0}' is not yet created using the CreateCommand method", commandName);
                    Log.Error(error);
                    throw new InvalidOperationException(error);
                }

                _commands[commandName].RegisterCommand(command, viewModel);

                InvalidateCommands();
            }
        }
예제 #36
0
 public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
 {
     _appTracker.TrackEvent(ApplicationTrackerCategories.Command, string.Format("{0}.{1}", viewModel.GetType().Name, commandName));
 }
 public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
 {
     return true;
 }
예제 #38
0
 /// <summary>
 /// Called when a command of a view model has just been executed.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <param name="commandName">Name of the command, which is the name of the command property.</param>
 /// <param name="command">The command that has been executed.</param>
 /// <param name="commandParameter">The command parameter.</param>
 public virtual void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
 {
 }
        public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
        {
            //podemos identificar el comando con la propiedad tag de ICatelCommand

            return true;
        }
예제 #40
0
        public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
        {
            base.OnCommandExecuted(viewModel, commandName, command, commandParameter);

            var viewModelName = viewModel != null?viewModel.GetType().Name : string.Empty;

            _analyticsService.SendCommandAsync(viewModelName, commandName);
        }
 public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
 {
     return(true);
 }
예제 #42
0
 public override void OnCommandExecuted(IViewModel viewModel, string commandName, ICatelCommand command, object commandParameter)
 {
     _appTracker.TrackEvent(ApplicationTrackerCategories.Command, string.Format("{0}.{1}", viewModel.GetType().Name, commandName));
 }
예제 #43
0
        public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
        {
            //podemos identificar el comando con la propiedad tag de ICatelCommand

            return(true);
        }