Exemple #1
0
        private void _Add(Command command)
        {
            if (command == null)
            {
                return;
            }
            if (m_adding)
            {
                Console.Error.WriteLine($"WARNING: Cannot start command from cancel method. Ignoring: {command}");
            }
            if (!m_commandTable.ContainsKey(command))
            {
                IEnumerable <Subsystem> requirements = command.GetRequirements();
                if (requirements.Any(subsystem => subsystem.GetCurrentCommand() != null && !subsystem.GetCurrentCommand().Interruptible))
                {
                    return;
                }

                m_adding     = true;
                requirements = command.GetRequirements();
                foreach (var subsystem in requirements)
                {
                    if (subsystem.GetCurrentCommand() != null)
                    {
                        subsystem.GetCurrentCommand().Cancel();
                        Remove(subsystem.GetCurrentCommand());
                    }
                    subsystem.SetCurrentCommand(command);
                }
                m_adding = false;

                LinkedListElement element = new LinkedListElement();
                element.SetData(command);
                if (m_firstCommand == null)
                {
                    m_firstCommand = m_lastCommand = element;
                }
                else
                {
                    m_lastCommand.Add(element);
                    m_lastCommand = element;
                }
                m_commandTable.Add(command, element);
                m_runningCommandsChanged = true;
                command.StartRunning();
            }
        }