Esempio n. 1
0
        private void SaveCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

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

            _document.Save(argumentsParser.GetNextAsString());
        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        private void InsertParagraphCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

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

            int?   position = GetPosition(argumentsParser.GetNextAsString());
            string text     = argumentsParser.GetNextsAsString(' ');

            ICommand command = new InsertParagraphCommand(text, _document, position);

            command.Execute();
        }
Esempio n. 4
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);
        }