Example #1
0
        private List <ArgumentOption> GetArgumentOptions()
        {
            var result          = new List <ArgumentOption>();
            int?key             = null;
            var argumentsParser = new ArgumentsParser(_arguments.Take(_arguments.Length - 2).ToArray());

            while (argumentsParser.HasNext)
            {
                switch (argumentsParser.GetNextAsString())
                {
                case "--encrypt":
                    key = argumentsParser.HasNext ? argumentsParser.GetNextAsInt() : null;
                    if (key == null)
                    {
                        throw new ApplicationException("Invalid command");
                    }
                    result.Add(new ArgumentOption(ArgumentType.Output, "--encrypt", key));
                    break;

                case "--decrypt":
                    key = argumentsParser.HasNext ? argumentsParser.GetNextAsInt() : null;
                    if (key == null)
                    {
                        throw new ApplicationException("Invalid command");
                    }
                    result.Add(new ArgumentOption(ArgumentType.Input, "--decrypt", key));
                    break;

                case "--compress":
                    result.Add(new ArgumentOption(ArgumentType.Output, "--compress"));
                    break;

                case "--decompress":
                    result.Add(new ArgumentOption(ArgumentType.Input, "--decompress"));
                    break;

                default:
                    throw new ApplicationException("Invalid command");
                }
            }

            return(result);
        }
Example #2
0
        private void ResizeImageCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

            if (argumentsParser.NextArgumentsCount != 3)
            {
                throw new MenuException();
            }

            int?position = argumentsParser.GetNextAsInt();
            int?weight   = argumentsParser.GetNextAsInt();
            int?height   = argumentsParser.GetNextAsInt();

            if (position == null || weight == null || height == null)
            {
                throw new MenuException();
            }

            ICommand command = new ResizeImageCommand(position.Value, weight.Value, height.Value, _document);

            command.Execute();
        }
Example #3
0
        private void InsertImageCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

            if (argumentsParser.NextArgumentsCount != 4)
            {
                throw new MenuException();
            }

            int?position = GetPosition(argumentsParser.GetNextAsString());
            int?weight   = argumentsParser.GetNextAsInt();
            int?height   = argumentsParser.GetNextAsInt();

            if (weight == null || height == null)
            {
                throw new MenuException();
            }
            string path = argumentsParser.GetNextAsString();

            ICommand command = new InsertImageCommand(path, weight.Value, height.Value, _document, position);

            command.Execute();
        }
Example #4
0
        private void AddBalls(string args)
        {
            var argumentsParser = new ArgumentsParser(args);

            if (argumentsParser.NextArgumentsCount < 1)
            {
                throw new MenuException();
            }

            int?ballsCount = argumentsParser.GetNextAsInt();

            if (ballsCount == null || ballsCount < 0)
            {
                throw new MenuException();
            }

            _machine.AddBalls(( uint )ballsCount.Value);
        }
Example #5
0
        public void DeleteItemCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

            if (argumentsParser.NextArgumentsCount != 1)
            {
                throw new MenuException();
            }

            int?position = argumentsParser.GetNextAsInt();

            if (position == null)
            {
                throw new MenuException();
            }

            ICommand command = new DeleteItemCommand(position.Value, _document);

            command.Execute();
        }
Example #6
0
        private void ReplaceTextCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

            if (argumentsParser.NextArgumentsCount < 2)
            {
                throw new MenuException();
            }

            int?position = argumentsParser.GetNextAsInt();

            if (position == null)
            {
                throw new MenuException();
            }
            string text = argumentsParser.GetNextsAsString(' ');

            ICommand command = new ReplaceTextCommand(position.Value, text, _document);

            command.Execute();
        }