Esempio n. 1
0
        public void Execute(params string[] parameters)
        {
            var fileName = "";

            try
            {
                fileName = ParameterParser.ProcessSaveOrLoadParams(this, parameters);

                using (var sr = new StreamReader(fileName))
                {
                    var jsonString = sr.ReadToEnd();
                    var values     = JsonConvert.DeserializeObject <List <object> >(jsonString);
                    foreach (var value in values)
                    {
                        ConvertValueToCommands(value);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine($"По указанному пути ({fileName}) файл не найден!");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        public override void Execute(params string[] parameters)
        {
            try
            {
                var shapeIndex = 2;

                float[] args;

                if (shapeIndex < parameters.Length - 1 || shapeIndex > parameters.Length)
                {
                    throw new ArgumentException("Неверное число параметров. Помощь по команде:\n" +
                                                Description);
                }

                args = ParameterParser.ParseToFloat(shapeIndex == parameters.Length
                    ? parameters.Take(parameters.Length).ToArray()
                    : parameters.Take(parameters.Length - 1).ToArray());

                var shapes = GetShapes(parameters, shapeIndex + 1);
                var point  = new PointF(args[0], args[1]);

                foreach (var shape in shapes)
                {
                    shape.Transform(Transformation.Translate(point));
                    picture.Update();
                }

                UpdateHistory();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 3
0
        protected void ProcessDrawParams(string[] rawParams, out float[] arguments)
        {
            if (rawParams.Length != ArgumentsNumber)
            {
                throw new ArgumentException(
                          "Вы ввели неверное количество параметров.\n" +
                          $"Для команды {Name} ({string.Join(", ", Synonyms)}) " +
                          $"нужно {ArgumentsNumber} параметра: \n{NameParams()}.");
            }

            arguments = ParameterParser.ParseToFloat(rawParams);

            const int maxValue = 1000000000;

            foreach (var arg in arguments)
            {
                if (arg > maxValue)
                {
                    throw new ArgumentException(
                              $"Неверный параметр: '{arg}' \n" +
                              "Вы ввели слишком большое число! " +
                              $"Попробуйте меньше, чем {maxValue}");
                }
            }
        }
Esempio n. 4
0
        public void Execute(params string[] parameters)
        {
            string fileName;

            try
            {
                fileName = ParameterParser.ProcessSaveOrLoadParams(this, parameters);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            var sb = new StringBuilder();

            sb.AppendLine("[");
            for (var i = 0; i < picture.shapes.Count; i++)
            {
                var shape = picture.shapes[i];
                sb.AppendLine(ConvertShapeToCommand(shape));
                if (i != picture.shapes.Count - 1)
                {
                    sb.AppendLine(",");
                }
            }
            sb.AppendLine("]");

            using (var sw = new StreamWriter(fileName))
            {
                sw.Write(sb.ToString());
            }
        }
Esempio n. 5
0
        public Ellipse(float x, float y, float width, float height, float rotateAngle, string uid)
        {
            ParameterParser.CheckWidthAndHeight(width, height);
            Center = new PointF
            {
                X = x,
                Y = y
            };

            Size = new SizeF
            {
                Height = height,
                Width  = width
            };

            RotateAngle = rotateAngle;
            UID         = uid;
        }
Esempio n. 6
0
        public Circle(float x, float y, float radius, string uid)
        {
            ParameterParser.CheckRadius(radius);
            var center = new PointF
            {
                X = x,
                Y = y
            };

            var size = new SizeF
            {
                Height = radius * 2,
                Width  = radius * 2
            };

            Center      = center;
            Size        = size;
            RotateAngle = 0;
            Radius      = radius;
            UID         = uid;
        }