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); }
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(); }
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(); }
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); }
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(); }
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(); }