Пример #1
0
        public Processing(TextReader reader, bool interactive)
        {
            try
            {
                AllComm  = new Dictionary <string, ICommand>();
                Commands = new List <ICommand>
                {
                    { new ExitCommand(this) },
                    { new HelpCommand() },
                    { new TestCommand() },
                    { new RandCommand() },
                    { new SeqCommand() },
                    { new IterCommand() },
                    { new Clear() }
                };

                Interactive = interactive;

                if (interactive)
                {
                    return;
                }
                string str;

                while ((str = reader.ReadLine()) != null)
                {
                    CurrListComm.Add(str.Replace("\n", ""));
                }
                if (CurrListComm.Count == 0)
                {
                    throw new InvalidDataException();
                }
            }
            catch (InvalidDataException)
            {
                Console.WriteLine("Пустой файл.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #2
0
        /// <summary>
        /// Запуск программы
        /// </summary>
        public void Run()
        {
            AddCommands();

            List <string> .Enumerator commandsFormFile = new List <string> .Enumerator();

            if (!Interactive)
            {
                commandsFormFile = CurrListComm.GetEnumerator();
            }

            while (isRunning)
            {
                string currStr;

                if (Interactive)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("> ");
                    currStr = Console.ReadLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    commandsFormFile.MoveNext();
                    currStr = commandsFormFile.Current;
                }

                var comParam = Parser.ParseComm(currStr);

                ICommand currComm = null;
                if (comParam != null)
                {
                    currComm = FindCommand(comParam.Name);
                }

                if (currComm != null)
                {
                    currComm.Execute(comParam.Params);
                }
            }
        }