//-------------------------------------------------------------------
        // Command Registration
        //-------------------------------------------------------------------
        #region Command Registration
        /// <summary>
        /// Register a command with the CommandSequence
        /// Commands are composed in the same order that they are registered
        /// </summary>
        /// <param name="cmd">Command to register with this CommandSequence</param>
        public void RegisterCommand(ICommand cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentException(nameof(cmd));
            }

            if (cmd == this)
            {
                throw new ArgumentException("Cannot register a CommandSequence with itself");
            }

            lock (this.registeredCommands)
            {
                CommandSequence seq = cmd as CommandSequence;
                if (seq == null)
                {
                    this.AddCommand(cmd);
                }
                else
                {
                    // If the command is itself a CommandSequence then we crack it open
                    // and add the individual commands within it. This enables composing
                    // commands with other CommandSequences. Flattening is required in
                    // the case when multiple command sequences share the same queue
                    foreach (ICommand subcmd in seq.registeredCommands)
                    {
                        this.AddCommand(subcmd);
                    }
                }
            }

            this.OnCanExecuteChanged();
        }
示例#2
0
        /// <summary>
        /// Perform additional initialization on a device that has been newly added to the collection of connected devices
        /// </summary>
        /// <param name="dpvm">The device that has been added</param>
        private void OnDeviceAdded(DevicePortalViewModel dpvm)
        {
            dpvm.PropertyChanged += this.DevicePropertyChanged;

            CommandSequence cmdSeq = dpvm.CreateCommandSequence();

            cmdSeq.RegisterCommand(dpvm.ReestablishConnectionCommand);
            cmdSeq.RegisterCommand(dpvm.RefreshDeviceNameCommand);
            cmdSeq.RegisterCommand(dpvm.StartListeningForSystemPerfCommand);
            cmdSeq.Execute(null);
        }