Esempio n. 1
0
        /// <summary>
        /// Processes command in the command line control.
        /// </summary>
        public void ProcessCommand()
        {
            this.commandHistory.Add(this.commandLineTextBox.Text);

            IEnumerable <string> commands = CommunicationHelper.ParseRoboScript(this.commandLineTextBox.Text);

            var notSentCommands = new List <string>();

            foreach (string command in commands)
            {
                // Пустышки в сторону!
                if (command.Trim().Equals(string.Empty))
                {
                    continue;
                }

                // Если есть ошибка, то все последующие команды не посылаются роботу.
                if (notSentCommands.Count > 0)
                {
                    notSentCommands.Add(command);
                }
                else
                {
                    bool sendResult = this.SendMessageToRobot(false, command);

                    if (sendResult)
                    {
                        this.historyBox.AppendTextSentToRobot(this.communicationHelper.LastSentMessage);
                    }
                    else
                    {
                        this.historyBox.AppendTextSentToRobot(string.Format("Ошибка в {0}: {1}", command, this.communicationHelper.LastErrorMessage));
                        notSentCommands.Add(command);
                    }
                }
            }

            // В поле ввода команд оставляем только неотправленные команды.
            if (notSentCommands.Count > 0)
            {
                this.commandLineTextBox.Text = GenerateCommandLine(notSentCommands);
            }
            else
            {
                this.commandLineTextBox.Text = string.Empty;
            }
        }