Beispiel #1
1
        internal static void Main(string[] args)
        {
            var commandProducer = new CommandProducer();
            var scene           = new Scene();

            using (var source = new StreamReader("../../Data/commands.txt", Encoding.UTF8))
            {
                string input;
                var    numberLine = 0;
                while ((input = source.ReadLine()) != null)
                {
                    if (input.Trim().Length == 0)
                    {
                        break;
                    }

                    numberLine++;

                    try
                    {
                        if (input.Trim()[0] == '#')
                        {
                            continue;
                        }

                        commandProducer.AppendLine(input);

                        if (commandProducer.IsCommandReady)
                        {
                            var command = commandProducer.GetCommand();
                            command.Apply(scene);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Произошла ошибка" + "в строке - " + numberLine + ": " + ex.Message);
                    }
                }
            }

            Console.ReadLine();
        }
Beispiel #2
0
        internal static void Main(string[] args)
        {
            //arg = .\TestInputs\trees.txt

            /*
             * Main Application Loop
             */

            Console.WriteLine("Starting scene application...");

            var commandProducer = new CommandProducer();
            var scene           = new Scene();

            bool readCommandsFromFile = args.Length > 0;

            IEnumerable <string> commands = readCommandsFromFile ?
                                            ReadCommandsFromFile(args[0]) :
                                            ReadCommandsFromUserInput();

            bool drawSceneOnEveryCommand = !readCommandsFromFile;

            foreach (string commandLine in commands)//console input
            {
                try
                {
                    if (commandLine != String.Empty)
                    {
                        commandProducer.AppendLine(commandLine);

                        if (commandProducer.IsCommandReady)
                        {
                            var command = commandProducer.GetCommand();
                            command.Apply(scene);

                            Console.WriteLine(command.FriendlyResultMessage);

                            if (drawSceneOnEveryCommand)
                            {
                                DrawScene(scene);
                            }
                        }
                    }
                }
                catch (BadFormatException)
                {
                    Console.WriteLine("bad format");
                }
                catch (BadRectanglePoint)
                {
                    Console.WriteLine("bad rectangle point");
                }
                catch (BadCircleRadius)
                {
                    Console.WriteLine("bad circle radius");
                }
                catch (BadPolygonPoint)
                {
                    Console.WriteLine("bad polygon point");
                }
                catch (BadPolygonPointNumber)
                {
                    Console.WriteLine("bad polygon point number");
                }
                catch (BadName)
                {
                    Console.WriteLine("bad name");
                }
                catch (NameDoesAlreadyExist)
                {
                    Console.WriteLine("name does already exist");
                }
                catch (UnexpectedEndOfPolygon)
                {
                    Console.WriteLine("unexpected end of polygon");
                }
                finally
                {
                    commandProducer.currentBuilder = null;
                }
            }

            if (!drawSceneOnEveryCommand) //rendering all scene elements
            {
                DrawScene(scene);
            }

            Console.WriteLine("Commands processing complete.");
        }