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(); } }
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_activeCommands.Contains(command)) { var requirements = command.GetRequirements(); var currentCommands = requirements.Select(subsystem => subsystem.GetCurrentCommand()) .Where(x => x != null); // If there are any non-interruptible commands on the subsystems required for this command if (currentCommands.Any(cmd => !cmd.Interruptible)) { return; } m_adding = true; foreach (var subsystem in requirements) { if (subsystem.GetCurrentCommand() != null) { subsystem.GetCurrentCommand().Cancel(); Remove(subsystem.GetCurrentCommand()); } subsystem.SetCurrentCommand(command); } m_adding = false; m_activeCommands.Add(command); m_runningCommandsChanged = true; command.StartRunning(); } }
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(); } }
/// <inheritdoc/> internal override void _Execute() { Entry entry = null; Command cmd = null; bool firstRun = false; if (m_currentCommandIndex == -1) { firstRun = true; m_currentCommandIndex = 0; } while (m_currentCommandIndex < m_commands.Count()) { if (cmd != null) { if (entry.IsTimedOut()) { cmd._Cancel(); } if (cmd.Run()) { break; } else { cmd.Removed(); m_currentCommandIndex++; firstRun = true; cmd = null; continue; } } entry = m_commands[m_currentCommandIndex]; cmd = null; switch (entry.state) { case Entry.IN_SEQUENCE: cmd = entry.command; if (firstRun) { cmd.StartRunning(); CancelConflicts(cmd); } firstRun = false; break; case Entry.BRANCH_PEER: m_currentCommandIndex++; entry.command.Start(); break; case Entry.BRANCH_CHILD: m_currentCommandIndex++; CancelConflicts(entry.command); entry.command.StartRunning(); m_children.Add(entry); break; } } for (int i = 0; i < m_children.Count; i++) { entry = m_children[i]; Command child = entry.command; if (entry.IsTimedOut()) { child._Cancel(); } if (!child.Run()) { child.Removed(); m_children.RemoveAt(i--); } } }