Exemplo n.º 1
0
        public void Execute(params string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Введите номера фигур, которые нужно удалить");
                return;
            }

            int[] parameters = new int[args.Length];
            try
            {
                parameters = Array.ConvertAll(args, Int32.Parse);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Произошла ошибка при попытке распарсить аргументы: {e.Message}");
                return;
            }

            Array.Sort(parameters);
            Array.Reverse(parameters);
            foreach (var index in parameters)
            {
                if (index >= picture.ShapesCount || index < 0)
                {
                    Console.WriteLine("На холсте нет фигуры с индексов {0}", index);
                    continue;
                }
                picture.RemoveAt(index);
                Console.WriteLine("Фигура с индексом {0} была успешно удалена.", index);
            }
        }
Exemplo n.º 2
0
 public void Execute(params string[] parameters)
 {
     if (parameters.Length == 0)
     {
         Console.WriteLine("Введите номера фигур, которые нужно удалить");
         return;
     }
     int[] args = Array.ConvertAll(parameters, new Converter <string, Int32>(Int32.Parse));
     Array.Sort(args);
     Array.Reverse(args);
     foreach (var index in args)
     {
         picture.RemoveAt(index);
     }
 }
Exemplo n.º 3
0
        public void Execute(params string[] parameters)
        {
            if (parameters.Length < 2)
            {
                Console.WriteLine("Не был введён цвет, или индексы фигур");
                return;
            }
            var color = ColorTranslator.FromHtml(parameters[0]);

            for (int i = 1; i < parameters.Length; i++)
            {
                int index = Int32.Parse(parameters[i]);
                var shape = picture.GetShape(index);
                shape.Format.Color = color;
                picture.RemoveAt(index);
                picture.Add(index, shape);
            }
        }
Exemplo n.º 4
0
        public void Execute(params string[] parameters)
        {
            if (parameters.Length < 2)
            {
                Console.WriteLine("Не была введена ширина, или индексы фигур");
                return;
            }
            uint width = (uint)Int32.Parse(parameters[0]);

            for (int i = 1; i < parameters.Length; i++)
            {
                int index = Int32.Parse(parameters[i]);
                var shape = picture.GetShape(index);
                shape.Format.Width = width;
                picture.RemoveAt(index);
                picture.Add(index, shape);
            }
        }
Exemplo n.º 5
0
        public void Execute(params string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Не была введена ширина, или индексы фигур");
                return;
            }

            uint width;

            try
            {
                width = (uint)Int32.Parse(args[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Произошла ошибка при попытке распарсить ширину `{0}` : {1}",
                                  args[0], e.Message);
                return;
            }

            for (int i = 1; i < args.Length; i++)
            {
                int index = 0;
                try
                {
                    index = Int32.Parse(args[i]);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Произошла ошибка при попытке распарсить индекс '{args[i]}': {e.Message}");
                    return;
                }
                if (index < 0 || index >= picture.ShapesCount)
                {
                    Console.WriteLine($"Фигуры с индексом '{index}' не существует!");
                    return;
                }
                var shape = picture.GetShape(index);
                shape.Format.Width = width;
                picture.RemoveAt(index);
                picture.Add(index, shape);
            }
        }
Exemplo n.º 6
0
        public void Execute(params string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Не был введён цвет, или индексы фигур");
                return;
            }

            Color color = Color.Black;

            try
            {
                color = ColorTranslator.FromHtml(args[0]);
            }
            catch (Exception)
            {
                Console.WriteLine($"Произошла ошибка при попытке распарсить цвет");
                return;
            }

            for (int i = 1; i < args.Length; i++)
            {
                int index = 0;
                try
                {
                    index = Int32.Parse(args[i]);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Произошла ошибка при попытке распарсить индекс '{args[i]}': {e.Message}");
                    return;
                }
                if (index < 0 || index >= picture.ShapesCount)
                {
                    Console.WriteLine($"Фигуры с индексом '{index}' не существует!");
                    return;
                }
                var shape = picture.GetShape(index);
                shape.Format.Color = color;
                picture.RemoveAt(index);
                picture.Add(index, shape);
            }
        }
Exemplo n.º 7
0
        public void Execute(params string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(Description);
            }

            int number;
            var parameters = new List <int>();

            for (int i = 0; i < args.Length; i++)
            {
                if (int.TryParse(args[i], out number) && (number >= 0))
                {
                    parameters.Add(number);
                }
                else if (number < 0)
                {
                    Console.WriteLine($"Аргументы не могут быть отрицательными, {args[i]}");
                }
                else
                {
                    Console.WriteLine($"Ошибка преобразования в число, {args[i]}");
                }
            }

            parameters.Sort();
            parameters.Reverse();
            IEnumerable <int> param = parameters.Distinct();

            try
            {
                foreach (var a in param)
                {
                    picture.RemoveAt(a);
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine($"Вы пытаетесь удалить несуществующую фигуру + {e.Message}");
            }
        }